Current Path : /var/www/html/clients/kampol.e-nk.ru/OLD/media/ |
Current File : /var/www/html/clients/kampol.e-nk.ru/OLD/media/bot_exmenu_nestedcategories.php |
<?php /** * @version 1.0.0 * @author Daniel Ecer * @package bot_exmenu_source_sql_query_1.0.0 * @copyright (C) 2005-2006 Daniel Ecer (de.siteof.de) * @license http://www.gnu.org/copyleft/gpl.html GNU/GPL */ // no direct access defined( '_VALID_MOS' ) or die( 'Restricted access' ); $_MAMBOTS->registerFunction('onLoadMenu', 'botExtendedMenuSourceNestegCategories_onLoadMenu'); function botExtendedMenuSourceNestegCategories_getRawUrlParameter($url, $paramName) { $i = strpos($url, '&'.$paramName.'='); $j = strpos($url, '?'.$paramName.'='); if (($j !== FALSE) && ($j < $i)) { $i = $j; } if ($i !== FALSE) { $i += 2 + strlen($paramName); $j = strpos($url, '&', $i); if ($j !== FALSE) { return substr($url, $i, $j - $i); } else { return substr($url, $i); } } return FALSE; } function botExtendedMenuSourceNestegCategories_onLoadMenu(&$menuLoader, $name = '') { global $database, $mosConfig_live_site, $option, $Itemid; global $mosConfig_lang, $mosConfig_mbf_content; $botName = 'bot_exmenu_nestedcategories'; // load parameters $database->setQuery('SELECT m.params FROM #__mambots AS m WHERE element = \''.$botName.'\' AND folder = \'exmenu\''); $rows = $database->loadObjectList(); foreach(array_keys($rows) as $key) { $row =& $rows[$key]; $params = new mosParameters($row->params); $params->def('source_name', 'sql_query'); if ($name != $params->get('source_name')) { continue; // this is not the intended plugin instance, skip to the next } // $current_level_begin = trim($params->get('current_level_begin', '1')); $query = "SELECT id, section FROM #__categories WHERE id=".$_REQUEST['id']; $database->setQuery($query); // echo $database->getQuery(); $database->loadObject($curitem); // print_r($curitem); $query = "SELECT name AS caption, id, parent_id FROM #__categories WHERE published = 1 AND section='".$curitem->section."'"; // if($current_level_begin) $query.="\n AND parent_id='".$_REQUEST['id']."'"; $mamblefish_enabled = $params->get('mamblefish_enabled', 0); $mamblefish_entity_name = $params->get('mamblefish_entity_name', 'menu'); $rootMenuNode =& $menuLoader->getRootMenuNode(); $database->setQuery($query); // echo $database->getQuery(); $rows = $database->loadObjectList(); if ($database->getErrorNum()) { trigger_error('database error:'.stripslashes($database->getErrorMsg()), E_USER_WARNING); return FALSE; } $menuNodeById = array(); $childMenuNodeListById = array(); $itemidMenuNode = NULL; $linkMenuNode = NULL; $componentMenuNode = NULL; $currentUrl = (isset($_SERVER['REQUEST_URI']) ? $_SERVER['REQUEST_URI'] : ''); if ($currentUrl != '') { if ((substr($currentUrl, 0, 1) != '/') && (strpos($currentUrl, ':') === FALSE)) { $currentUrl = '/'.$currentUrl; } $i = strpos($currentUrl, '&Itemid='); if ($i === FALSE) { $i = strpos($currentUrl, '?Itemid='); } $currentUrlArray = array(); if (substr($currentUrl, 0, 1) == '/') { $currentUrlArray[] = substr($currentUrl, 1); $currentUrlArray[] = $mosConfig_live_site.$currentUrl; } else { $currentUrlArray[] = $currentUrl; } if ($i !== FALSE) { if (substr($currentUrl, 0, 1) == '/') { $currentUrlArray[] = substr(substr($currentUrl, 0, $i), 1); $currentUrlArray[] = $mosConfig_live_site.substr($currentUrl, 0, $i); } else { $currentUrlArray[] = substr($currentUrl, 0, $i); } } } if (($mamblefish_enabled) && ($mosConfig_mbf_content)) { foreach(array_keys($rows) as $key) { $translatedObject = MambelFish::translate($rows[$key], $mamblefish_entity_name, $mosConfig_lang); $rows[$key] =& $translatedObject; } } foreach(array_keys($rows) as $key) { $row =& $rows[$key]; $row->itemid = $_REQUEST['Itemid']; $menuNode =& $menuLoader->getEmptyMenuNode(); $menuNode->name = $row->caption; $menuNode->link = 'index.php?option=com_content&task=blogcategory&id='.$row->id; $menuNode->type = 'content_blog_category'; if ($menuNode->type == '') { $menuNode->type = ($menuNode->link != '' ? 'url' : 'separator'); } $menuNode->id = $row->itemid; $id = $row->id; if ($id > 0) { $menuNodeById[$id] =& $menuNode; } $parentId = $row->parent_id; if ($parentId <= 0) { $parentId = 0; } if (!isset($childMenuNodeListById[$parentId])) { $childMenuNodeListById[$parentId] = array(); } $childMenuNodeListById[$parentId][] =& $menuNode; if (($Itemid > 0) && ($Itemid == $menuNode->id)) { $itemidMenuNode =& $menuNode; } if (($menuNode->link != '') && (in_array($menuNode->link, $currentUrlArray))) { $linkMenuNode =& $menuNode; } else if ($option == botExtendedMenuSourceNestegCategories_getRawUrlParameter($menuNode->link, 'option')) { $componentMenuNode =& $menuNode; } } $currentMenuNode = NULL; if (!is_null($linkMenuNode)) { $currentMenuNode =& $linkMenuNode; } else if (!is_null($itemidMenuNode)) { $currentMenuNode =& $itemidMenuNode; } else if (!is_null($componentMenuNode)) { $currentMenuNode =& $componentMenuNode; } if (!is_null($currentMenuNode)) { $currentMenuNode->setCurrent(TRUE); $menuNode =& $currentMenuNode->getParent(); while(!is_null($menuNode)) { $menuNode->setActive(TRUE); $t =& $menuNode->getParent(); $menuNode =& $t; } } $menuNodeById[0] =& $rootMenuNode; foreach(array_keys($childMenuNodeListById) as $id) { if (!isset($menuNodeById[$id])) { trigger_error('exmenu: parent with id '.$id.' not found', E_USER_NOTICE); continue; } $menuNode =& $menuNodeById[$id]; $menuNodeList =& $childMenuNodeListById[$id]; foreach(array_keys($menuNodeList) as $key) { $childMenuNode =& $menuNodeList[$key]; $menuNode->setExpanded(TRUE); $menuLoader->addMenuNode($menuNode, $childMenuNode); } } return TRUE; } return FALSE; } ?>