public function main() { $this->loadLanguage('common/header'); $cache_name = 'admin_menu'; //$this->data['menu_items'] = $this->cache->get($cache_name); if (!$this->data['menu_items']) { $menu = new ADataset('menu', 'admin'); $this->data['menu_items'] = $menu->getRows(); // need to resort by sort_order property and exlude disabled extension items $enabled_extension = $this->extensions->getEnabledExtensions(); $offset = 0; // it needs for process repeating order numbers $tmp = array(); foreach ($this->data['menu_items'] as $i => $item) { if ($i > 0) { if ($this->data['menu_items'][$i - 1]['parent_id'] != $item['parent_id']) { $offset = 0; } } //checks for disabled extension if ($item['item_type'] == 'extension') { // looks for this name in enabled extensions list. if is not there - skip it if (!$this->_find_itemId_in_extensions($item['item_id'], $enabled_extension)) { continue; } else { // if all fine - loads language of extension for menu item text show if (strpos($item['item_url'], 'http') === false) { $this->loadLanguage($item['item_id'] . '/' . $item['item_id'], 'silent'); $item['language'] = $item['item_id'] . '/' . $item['item_id']; } } } if (isset($tmp[$item['parent_id']][$item['sort_order']])) { $offset++; } $tmp[$item['parent_id']][$item['sort_order'] + $offset] = $item; } $this->data['menu_items'] = array(); foreach ($tmp as $item) { ksort($item); $this->data['menu_items'] = array_merge($this->data['menu_items'], $item); } unset($tmp); // now set menu array $this->cache->set($cache_name, $this->data['menu_items']); } $this->view->assign('menu_html', renderAdminMenu($this->_buildMenuArray($this->data['menu_items']), 0, $this->request->get_or_post('rt'))); $this->processTemplate('common/menu.tpl'); //use to update data before render $this->extensions->hk_UpdateData($this, __FUNCTION__); }
function renderAdminMenu($menu, $level = 0, $current_rt = '') { $result = ''; if ($level) { $result .= "<ul class=\"children child{$level}\">\r\n"; } foreach ($menu as $item) { $id = empty($item['id']) ? '' : ' id="menu_' . $item['id'] . '" '; // li ID $class = $level != 0 ? empty($item['children']) ? '' : ' class="parent" ' : ' class="top" '; //a class $href = empty($item['href']) ? '' : ' href="' . $item['href'] . '" '; //a href $onclick = empty($item['onclick']) ? '' : ' onclick="' . $item['onclick'] . '" '; //a href $child_class = "level{$level} "; if (!empty($item['children'])) { $child_class .= 'nav-parent '; } if ($item['rt'] && $current_rt == $item['rt']) { $child_class .= 'active '; } if ($child_class) { $child_class = ' class="' . $child_class . '"'; } $result .= '<li' . $id . $child_class . '>'; $result .= '<a ' . $class . $href . $onclick . '>'; //check icon rl type html, image or none. if (is_html($item['icon'])) { $result .= $item['icon']; } else { if ($item['icon']) { $result .= '<img class="menu_image" src="' . HTTPS_DIR_RESOURCE . $item['icon'] . '" alt="" />'; } else { $result .= '<i class="fa fa-caret-right"></i> '; } } $result .= '<span class="menu_text">' . $item['text'] . '</span></a>'; //if children build inner clild trees if (!empty($item['children'])) { $result .= "\r\n" . renderAdminMenu($item['children'], $level + 1, $current_rt); } $result .= "</li>\r\n"; } if ($level) { $result .= "</ul>\r\n"; } return $result; }
function renderAdminMenu($menu, $level = 0) { $result = ''; if ($level) { $result .= "<ul>\r\n"; } foreach ($menu as $item) { $id = empty($item['id']) ? '' : ' id="menu_' . $item['id'] . '" '; // li ID $class = $level != 0 ? empty($item['children']) ? '' : ' class="parent" ' : ' class="top" '; //a class $href = empty($item['href']) ? '' : ' href="' . $item['href'] . '" '; //a href $onclick = empty($item['onclick']) ? '' : ' onclick="' . $item['onclick'] . '" '; //a href $result .= '<li' . $id . '>'; $result .= '<a' . $class . $href . $onclick . '>' . $item['text'] . '</a>'; if (!empty($item['children'])) { $result .= "\r\n" . renderAdminMenu($item['children'], $level + 1); } $result .= "</li>\r\n"; } if ($level) { $result .= "</ul>\r\n"; } return $result; }