示例#1
1
/**
 * Method to add menu's item.
 *
 * @return boolean true on success false on failure.
 */
function addMenuItems()
{
    $db = JFactory::getDBO();
    // Get new component id.
    $component = JComponentHelper::getComponent('com_community');
    $component_id = 0;
    if (is_object($component) && isset($component->id)) {
        $component_id = $component->id;
    }
    $column_name = JOOMLA_MENU_NAME;
    $column_cid = JOOMLA_MENU_COMPONENT_ID;
    // Get the default menu type
    // 2 Joomla bugs occur in /Administrator mode
    // Bug 1: JFactory::getApplication('site') failed. It always return id = 'administrator'.
    // Bug 2: JMenu::getDefault('*') failed. JAdministrator::getLanguageFilter() doesn't exist.
    // If these 2 bugs are fixed, we can call the following syntax:
    // $defaultMenuType	= JFactory::getApplication('sites')->getMenu()->getDefault()->menutype;
    jimport('joomla.application.application');
    $defaultMenuType = JApplication::getInstance('site')->getMenu()->getDefault('workaround_joomla_bug')->menutype;
    $query = 'SELECT ' . $db->nameQuote('ordering') . ' ' . 'FROM ' . $db->nameQuote('#__menu') . ' ' . 'ORDER BY ' . $db->nameQuote('ordering') . ' DESC LIMIT 1';
    $db->setQuery($query);
    $order = $db->loadResult() + 1;
    // Update the existing menu items.
    $row = JTable::getInstance('menu', 'JTable');
    $row->menutype = $defaultMenuType;
    $row->{$column_name} = 'JomSocial';
    $row->alias = 'JomSocial';
    $row->link = 'index.php?option=com_community&view=frontpage';
    $row->type = 'component';
    $row->published = '1';
    $row->{$column_cid} = $component_id;
    $row->ordering = $order;
    $row->id = null;
    //new item
    if (!JOOMLA_LEGACY_VERSION) {
        $row->language = '*';
    }
    $row->check();
    if (!$row->store()) {
        // $row->getError()
        return false;
    }
    //for version 1.6 only. The parent_id is not updated correctly via JTable
    if (!JOOMLA_LEGACY_VERSION) {
        $query = 'UPDATE ' . $db->nameQuote('#__menu') . ' SET `parent_id` = ' . $db->quote(1) . ', `level` = ' . $db->quote(1) . ' WHERE `id` = ' . $db->quote($row->id);
        $db->setQuery($query);
        $db->query();
        if ($db->getErrorNum()) {
            return false;
        }
    }
    if (!addDefaultToolbarMenus()) {
        return false;
    }
    // update memu items with component id
    if (!updateMenuItems()) {
        return false;
    }
    return true;
}
示例#2
0
 function update_8()
 {
     $db = JFactory::getDBO();
     $result = new stdClass();
     $status = true;
     $errorCode = '';
     $html = '';
     // Menu system now is integrated with Joomla
     if (!$this->dbhelper->_isExistMenu()) {
         $query = 'INSERT INTO ' . $db->quoteName('#__menu_types') . ' (' . $db->quoteName('menutype') . ',' . $db->quoteName('title') . ',' . $db->quoteName('description') . ') VALUES ' . '( ' . $db->Quote('jomsocial') . ',' . $db->Quote('JomSocial toolbar') . ',' . $db->Quote('Toolbar items for JomSocial toolbar') . ')';
         $db->setQuery($query);
         $db->Query();
         $menuId = $db->insertid();
         // Create default toolbar menu's since the jomsocial toolbar menu doesn't exist.
         $status = addDefaultToolbarMenus();
     }
     $result->html = $html;
     $result->status = $status;
     if (!$status) {
         $result->errorCode = '8f';
     }
     return $result;
 }