function createMenuJ15($menu, $submenu) { jimport( 'joomla.utilities.string' ); jimport( 'joomla.application.component.helper' ); kimport('kunena.factory'); $config = KunenaFactory::getConfig(); $component_id = JComponentHelper::getComponent('com_kunena')->id; // First fix all broken menu items $query = "UPDATE #__menu SET componentid={$this->db->quote($component_id)} WHERE type = 'component' AND link LIKE '%option=com_kunena%'"; $this->db->setQuery ( $query ); $this->db->query (); if ($this->db->getErrorNum ()) throw new KunenaInstallerException ( $this->db->getErrorMsg (), $this->db->getErrorNum () ); // Find out if menu exists $query = "SELECT id FROM `#__menu_types` WHERE `menutype`='kunenamenu';"; $this->db->setQuery ( $query ); $moduleid = ( int ) $this->db->loadResult (); if ($this->db->getErrorNum ()) throw new KunenaInstallerException ( $this->db->getErrorMsg (), $this->db->getErrorNum () ); // Do not touch existing menu if ($moduleid) { return; } // Create new Joomla menu for Kunena if (! $moduleid) { // Create a menu type for the Kunena menu $query = "REPLACE INTO `#__menu_types` (`id`, `menutype`, `title`, `description`) VALUES ($moduleid, 'kunenamenu', {$this->db->Quote( JText::_ ( 'COM_KUNENA_MENU_TITLE' ))} , {$this->db->Quote(JText::_ ( 'COM_KUNENA_MENU_TITLE_DESC' ))} )"; $this->db->setQuery ( $query ); $this->db->query (); if ($this->db->getErrorNum ()) throw new KunenaInstallerException ( $this->db->getErrorMsg (), $this->db->getErrorNum () ); // Now get the menu id again, we need it, in order to publish the menu module $query = "SELECT id FROM `#__menu_types` WHERE `menutype`='kunenamenu';"; $this->db->setQuery ( $query ); $moduleid = ( int ) $this->db->loadResult (); if ($this->db->getErrorNum ()) throw new KunenaInstallerException ( $this->db->getErrorMsg (), $this->db->getErrorNum () ); } // Forum $query = "SELECT id FROM `#__menu` WHERE `link`={$this->db->quote($menu['link'])} AND `menutype`='kunenamenu';"; $this->db->setQuery ( $query ); $parentid = ( int ) $this->db->loadResult (); if ($this->db->getErrorNum ()) throw new KunenaInstallerException ( $this->db->getErrorMsg (), $this->db->getErrorNum () ); if (! $parentid) { $params = new JParameter(''); $params->bind($menu['params']); $query = "REPLACE INTO `#__menu` (`id`, `menutype`, `name`, `alias`, `link`, `type`, `published`, `parent`, `componentid`, `sublevel`, `ordering`, `checked_out`, `checked_out_time`, `pollid`, `browserNav`, `access`, `utaccess`, `params`, `lft`, `rgt`, `home`) VALUES ($parentid, 'kunenamenu', {$this->db->quote($menu['name'])}, {$this->db->quote($menu['alias'])}, {$this->db->quote($menu['link'])}, 'component', 1, 0, $component_id, 0, 1, 0, '0000-00-00 00:00:00', 0, 0, {$menu['access']}, 0, {$this->db->quote($params->toString('INI'))}, 0, 0, 0);"; $this->db->setQuery ( $query ); $this->db->query (); if ($this->db->getErrorNum ()) throw new KunenaInstallerException ( $this->db->getErrorMsg (), $this->db->getErrorNum () ); $parentid = ( int ) $this->_db->insertId (); } // Submenu (shown in Kunena) $defaultmenu = 0; $ordering = 0; foreach ($submenu as $menuitem) { $ordering++; // $query = "SELECT id FROM `#__menu` WHERE `link`={$this->db->quote($menuitem['link'])} AND `menutype`='kunenamenu';"; // $this->db->setQuery ( $query ); // $id = ( int ) $this->db->loadResult (); // if ($this->db->getErrorNum ()) // throw new KunenaInstallerException ( $this->db->getErrorMsg (), $this->db->getErrorNum () ); $id = 0; if (! $id) { $params = new JParameter(''); $params->bind($menuitem['params']); $query = "REPLACE INTO `#__menu` (`id`, `menutype`, `name`, `alias`, `link`, `type`, `published`, `parent`, `componentid`, `sublevel`, `ordering`, `checked_out`, `checked_out_time`, `pollid`, `browserNav`, `access`, `utaccess`, `params`, `lft`, `rgt`, `home`) VALUES ($id, 'kunenamenu', {$this->db->quote($menuitem['name'])}, {$this->db->quote($menuitem['alias'])}, {$this->db->quote($menuitem['link'])},'component', 1, $parentid, $component_id, 1, $ordering, 0, '0000-00-00 00:00:00', 0, 0, {$menuitem['access']}, 0, {$this->db->quote($params->toString('INI'))}, 0, 0, 0);"; $this->db->setQuery ( $query ); $this->db->query (); if ($this->db->getErrorNum ()) throw new KunenaInstallerException ( $this->db->getErrorMsg (), $this->db->getErrorNum () ); $id = ( int ) $this->_db->insertId (); if (!$defaultmenu || (isset($menuitem['default']) && $config->fbdefaultpage == $menuitem['default'])) { $defaultmenu = $id; } } } if ($defaultmenu) { $query = "UPDATE `#__menu` SET `link`={$this->db->quote($menu['link']."&defaultmenu=$defaultmenu")} WHERE id={$parentid}"; $this->db->setQuery ( $query ); $this->db->query (); if ($this->db->getErrorNum ()) throw new KunenaInstallerException ( $this->db->getErrorMsg (), $this->db->getErrorNum () ); } $query = "SELECT id FROM `#__modules` WHERE `position`='kunena_menu';"; $this->db->setQuery ( $query ); $moduleid = ( int ) $this->db->loadResult (); if ($this->db->getErrorNum ()) throw new KunenaInstallerException ( $this->db->getErrorMsg (), $this->db->getErrorNum () ); // Check if it exists, if not create it if (! $moduleid) { // Create a module for the Kunena menu $query = "REPLACE INTO `#__modules` (`id`, `title`, `content`, `ordering`, `position`, `checked_out`, `checked_out_time`, `published`, `module`, `numnews`, `access`, `showtitle`, `params`, `iscore`, `client_id`, `control`) VALUES ($moduleid, {$this->db->quote(JText::_ ( 'COM_KUNENA_MENU_TITLE' ))}, '', 0, 'kunena_menu', 0, '0000-00-00 00:00:00', 1, 'mod_mainmenu', 0, 0, 0, 'menutype=kunenamenu\nmenu_style=list\nstartLevel=1\nendLevel=2\nshowAllChildren=1\nwindow_open=\nshow_whitespace=0\ncache=1\ntag_id=\nclass_sfx=\nmoduleclass_sfx=\nmaxdepth=10\nmenu_images=0\nmenu_images_align=0\nmenu_images_link=0\nexpand_menu=0\nactivate_parent=0\nfull_active_id=0\nindent_image=0\nindent_image1=\nindent_image2=\nindent_image3=\nindent_image4=\nindent_image5=\nindent_image6=\nspacer=\nend_spacer=\n\n', 0, 0, '');"; $this->db->setQuery ( $query ); $this->db->query (); if ($this->db->getErrorNum ()) throw new KunenaInstallerException ( $this->db->getErrorMsg (), $this->db->getErrorNum () ); // Now get the module id again, we need it, in order to publish the menu module $query = "SELECT id FROM `#__modules` WHERE `position`='kunena_menu';"; $this->db->setQuery ( $query ); $moduleid = ( int ) $this->db->loadResult (); if ($this->db->getErrorNum ()) throw new KunenaInstallerException ( $this->db->getErrorMsg (), $this->db->getErrorNum () ); // Now publish the module $query = "REPLACE INTO `#__modules_menu` (`moduleid`, `menuid`) VALUES ($moduleid, 0);"; $this->db->setQuery ( $query ); $this->db->query (); if ($this->db->getErrorNum ()) throw new KunenaInstallerException ( $this->db->getErrorMsg (), $this->db->getErrorNum () ); } // Finally add forum menu link to default menu $jmenu = JMenu::getInstance('site'); $dmenu = $jmenu->getDefault(); $query = "SELECT id, name, type, link, published FROM `#__menu` WHERE `alias` IN ('forum', 'kunenaforum', {$this->db->quote(JText::_ ( 'COM_KUNENA_MENU_FORUM_ALIAS' ))}) AND `menutype`={$this->db->quote($dmenu->menutype)}"; $this->db->setQuery ( $query, 0, 1 ); $menualias = $this->db->loadObject (); if ($this->db->getErrorNum ()) throw new KunenaInstallerException ( $this->db->getErrorMsg (), $this->db->getErrorNum () ); // We do not want to replace users own menu items (just alias or deprecated link to Kunena) if (!$menualias || $menualias->type == 'menulink' || $menualias->link == 'index.php?option=com_kunena') { $id = $menualias ? intval($menualias->id) : 0; // Keep state (default=unpublished) and name (default=Forum) $published = $menualias ? intval($menualias->published) : 0; $name = $menualias ? $menualias->name : $menu['name']; $query = "REPLACE INTO `#__menu` (`id`, `menutype`, `name`, `alias`, `link`, `type`, `published`, `parent`, `componentid`, `sublevel`, `checked_out`, `checked_out_time`, `pollid`, `browserNav`, `access`, `utaccess`, `params`, `lft`, `rgt`, `home`) VALUES ($id, {$this->db->quote($dmenu->menutype)}, {$this->db->quote($name)}, 'kunenaforum', 'index.php?Itemid={$parentid}', 'menulink', {$published}, 0, 0, 0, 0, '0000-00-00 00:00:00', 0, 0, {$menu['access']}, 0, 'menu_item=$parentid{$menu['params']}\r\n\r\n', 0, 0, 0);"; $this->db->setQuery ( $query ); $this->db->query (); if ($this->db->getErrorNum ()) throw new KunenaInstallerException ( $this->db->getErrorMsg (), $this->db->getErrorNum () ); } require_once (JPATH_ADMINISTRATOR . '/components/com_menus/helpers/helper.php'); MenusHelper::cleanCache (); }
/** * Delete menu items by type */ function deleteByType($type = '') { if (!$type) { return false; } $db =& $this->getDBO(); $query = 'DELETE FROM #__menu' . ' WHERE menutype = ' . $db->Quote($type); $db->setQuery($query); if (!$db->query()) { $this->setError($menuTable->getErrorMsg()); return false; } // clean cache MenusHelper::cleanCache(); return true; }
/** * Delete one or more menu items * @param mixed int or array of id values */ function delete($ids) { JArrayHelper::toInteger($ids); $db =& $this->getDBO(); if (count($ids)) { // Delete associated module and template mappings $where = 'WHERE menuid = ' . implode(' OR menuid = ', $ids); $query = 'DELETE FROM #__modules_menu ' . $where; $db->setQuery($query); if (!$db->query()) { $this->setError($menuTable->getErrorMsg()); return false; } // Set any alias menu types to not point to missing menu items $query = 'UPDATE #__menu SET link = 0 WHERE type = \'menulink\' AND (link = ' . implode(' OR id = ', $ids) . ')'; $db->setQuery($query); if (!$db->query()) { $this->setError($db->getErrorMsg()); return false; } // Delete the menu items $where = 'WHERE id = ' . implode(' OR id = ', $ids); $query = 'DELETE FROM #__menu ' . $where; $db->setQuery($query); if (!$db->query()) { $this->setError($db->getErrorMsg()); return false; } } // clean cache MenusHelper::cleanCache(); return true; }