Example #1
0
 protected function generateCategoriesMenu($categories, $is_children = 0)
 {
     $html = '';
     foreach ($categories as $key => $category) {
         if ($category['level_depth'] > 1) {
             $cat = new Category($category['id_category']);
             $link = Tools::HtmlEntitiesUTF8($cat->getLink());
         } else {
             $link = $this->context->link->getPageLink('index');
         }
         /* Whenever a category is not active we shouldnt display it to customer */
         if ((bool) $category['active'] === false) {
             continue;
         }
         $html .= '<li' . ($this->page_name == 'category' && (int) Tools::getValue('id_category') == (int) $category['id_category'] ? ' class="sfHoverForce ' . Tools::link_rewrite($category['name']) . '"' : ' class="' . Tools::link_rewrite($category['name']) . '"') . '>';
         $html .= '<a href="' . $link . '" title="' . $category['name'] . '"><img src="/themes/aphrodinet/img/menu-icon-' . strtolower($category['name']) . '.png" /><br/>' . $category['name'] . '</a>';
         if (isset($category['children']) && !empty($category['children'])) {
             $html .= '<ul>';
             $html .= $this->generateCategoriesMenu($category['children'], 1);
             if ((int) $category['level_depth'] > 1 && !$is_children) {
                 $files = scandir(_PS_CAT_IMG_DIR_);
                 if (count(preg_grep('/^' . $category['id_category'] . '-([0-9])?_thumb.jpg/i', $files)) > 0) {
                     $html .= '<li class="category-thumbnail">';
                     foreach ($files as $file) {
                         if (preg_match('/^' . $category['id_category'] . '-([0-9])?_thumb.jpg/i', $file) === 1) {
                             $html .= '<div><img src="' . $this->context->link->getMediaLink(_THEME_CAT_DIR_ . $file) . '" alt="' . Tools::SafeOutput($category['name']) . '" title="' . Tools::SafeOutput($category['name']) . '" class="imgm" /></div>';
                         }
                     }
                     $html .= '</li>';
                 }
             }
             $html .= '</ul>';
         }
         $html .= '</li>';
     }
     return $html;
 }
Example #2
0
 protected function getCMSMenuItems($parent, $depth = 1, $id_lang = false)
 {
     $id_lang = $id_lang ? (int) $id_lang : (int) Context::getContext()->language->id;
     if ($depth > 3) {
         return;
     }
     $categories = $this->getCMSCategories(false, (int) $parent, (int) $id_lang);
     $pages = $this->getCMSPages((int) $parent);
     if (count($categories) || count($pages)) {
         $this->_menu .= '<ul>';
         foreach ($categories as $category) {
             $cat = new CMSCategory((int) $category['id_cms_category'], (int) $id_lang);
             $this->_menu .= '<li>';
             $this->_menu .= '<a href="' . Tools::HtmlEntitiesUTF8($cat->getLink()) . '">' . $category['name'] . '</a>';
             $this->getCMSMenuItems($category['id_cms_category'], (int) $depth + 1);
             $this->_menu .= '</li>';
         }
         foreach ($pages as $page) {
             $cms = new CMS($page['id_cms'], (int) $id_lang);
             $links = $cms->getLinks((int) $id_lang, array((int) $cms->id));
             $selected = $this->page_name == 'cms' && (int) Tools::getValue('id_cms') == $page['id_cms'] ? ' class="sfHoverForce"' : '';
             $this->_menu .= '<li ' . $selected . '>';
             $this->_menu .= '<a href="' . $links[0]['link'] . '">' . $cms->meta_title . '</a>';
             $this->_menu .= '</li>';
         }
         $this->_menu .= '</ul>';
     }
 }
Example #3
0
 public static function generationUrl()
 {
     $value = Tools::getValue('value');
     $response = '';
     if ($value) {
         $langId = Context::getContext()->language->id;
         $shopId = Context::getContext()->shop->id;
         $arr = explode('-', $value);
         switch ($arr[0]) {
             case 'PRD':
                 $product = new Product((int) $arr[1], true, (int) $langId);
                 $response = Tools::HtmlEntitiesUTF8($product->getLink());
                 break;
             case 'CAT':
                 $response = Tools::HtmlEntitiesUTF8(Context::getContext()->link->getCategoryLink((int) $arr[1], null, $langId));
                 break;
             case 'CMS_CAT':
                 $response = Tools::HtmlEntitiesUTF8(Context::getContext()->link->getCMSCategoryLink((int) $arr[1], null, $langId));
                 break;
             case 'CMS':
                 $response = Tools::HtmlEntitiesUTF8(Context::getContext()->link->getCMSLink((int) $arr[1], null, $langId));
                 break;
             case 'ALLMAN':
                 $response = Tools::HtmlEntitiesUTF8(Context::getContext()->link->getPageLink('manufacturer'), true, $langId);
                 break;
             case 'MAN':
                 $man = new Manufacturer((int) $arr[1], $langId);
                 $response = Tools::HtmlEntitiesUTF8(Context::getContext()->link->getManufacturerLink($man->id, $man->link_rewrite, $langId));
                 break;
             case 'ALLSUP':
                 $response = Tools::HtmlEntitiesUTF8(Context::getContext()->link->getPageLink('supplier'), true, $langId);
                 break;
             case 'SUP':
                 $sup = new Supplier((int) $arr[1], $langId);
                 $response = Tools::HtmlEntitiesUTF8(Context::getContext()->link->getSupplierLink($sup->id, $sup->link_rewrite, $langId));
                 break;
             case 'PAG':
                 $pag = Meta::getMetaByPage($arr[1], $langId);
                 $response = Tools::HtmlEntitiesUTF8(Context::getContext()->link->getPageLink($pag['page'], true, $langId));
                 break;
             case 'SHO':
                 $shop = new Shop((int) $key);
                 $response = $shop->getBaseURL();
                 break;
             default:
                 $response = '#';
                 break;
         }
     } else {
         $response = '#';
     }
     die(Tools::jsonEncode($response));
 }
Example #4
0
 protected function generateUrl($value, $default = "#", $prefix = '')
 {
     $response = $default;
     if ($prefix) {
         $value .= $prefix;
     }
     if ($value) {
         $langId = $this->context->language->id;
         $shopId = $this->context->shop->id;
         $arr = explode('|', $value);
         switch ($arr[0]) {
             case 'PRD':
                 $product = new Product((int) $arr[1], true, (int) $langId);
                 $response = Tools::HtmlEntitiesUTF8($product->getLink());
                 break;
             case 'CAT':
                 $response = Tools::HtmlEntitiesUTF8($this->context->link->getCategoryLink((int) $arr[1], null, $langId));
                 break;
             case 'CMS_CAT':
                 $response = Tools::HtmlEntitiesUTF8($this->context->link->getCMSCategoryLink((int) $arr[1], null, $langId));
                 break;
             case 'CMS':
                 $response = Tools::HtmlEntitiesUTF8($this->context->link->getCMSLink((int) $arr[1], null, $langId));
                 break;
             case 'ALLMAN':
                 $response = Tools::HtmlEntitiesUTF8($this->context->link->getPageLink('manufacturer'), true, $langId);
                 break;
             case 'MAN':
                 $man = new Manufacturer((int) $arr[1], $langId);
                 $response = Tools::HtmlEntitiesUTF8($this->context->link->getManufacturerLink($man->id, $man->link_rewrite, $langId));
                 break;
             case 'ALLSUP':
                 $response = Tools::HtmlEntitiesUTF8($this->context->link->getPageLink('supplier'), true, $langId);
                 break;
             case 'SUP':
                 $sup = new Supplier((int) $arr[1], $langId);
                 $response = Tools::HtmlEntitiesUTF8($this->context->link->getSupplierLink($sup->id, $sup->link_rewrite, $langId));
                 break;
             case 'SHO':
                 $shop = new Shop((int) $key);
                 $response = $shop->getBaseURL();
                 break;
             case 'PAG':
                 $pag = Meta::getMetaByPage($arr[1], $langId);
                 if (strpos($pag['page'], 'module-') === false) {
                     $response = Tools::HtmlEntitiesUTF8($this->context->link->getPageLink($pag['page'], true, $langId));
                 } else {
                     $page = explode('-', $pag['page']);
                     Context::getContext()->link->getModuleLink($page[1], $page[2]);
                     $response = Tools::HtmlEntitiesUTF8($this->context->link->getModuleLink($page[1], $page[2]));
                 }
                 break;
             default:
                 break;
         }
     }
     return $response;
 }
Example #5
0
 public function hookFooter($params)
 {
     $user_groups = $this->context->customer->isLogged() ? $this->context->customer->getGroups() : array(Configuration::get('PS_UNIDENTIFIED_GROUP'));
     $block1_id = Configuration::get('FOOTER_1_CAT_BLOCK', 0);
     $id_lang = (int) $this->context->language->id;
     if ($block1_id != 0) {
         $category1 = Category::getNestedCategories($block1_id, $id_lang, true, $user_groups);
         $category1 = $category1[$block1_id];
     } else {
         $category1 = null;
     }
     $block2_ids = json_decode(Configuration::get('FOOTER_2_CAT_BLOCK', '[]'));
     if (!empty($block2_ids)) {
         $categories = array();
         foreach ($block2_ids as $key => $id) {
             if ($id != 0) {
                 if ($key == 3) {
                     $sql_limit = 'LIMIT 0, 4';
                 } else {
                     $sql_limit = '';
                 }
                 $temp = Category::getNestedCategories($id, $id_lang, true, $user_groups, true, '', '', $sql_limit);
                 $categories2[] = $temp[$id];
             }
         }
     } else {
         $categories2 = array();
     }
     $block3_id = Configuration::get('FOOTER_3_CAT_BLOCK', 0);
     if ($block3_id != 0) {
         $sql_limit = 'LIMIT 0, 6';
         $category3 = Category::getNestedCategories($block3_id, $id_lang, true, $user_groups, true, '', '', $sql_limit);
         $category3 = $category3[$block3_id];
     } else {
         $category3 = null;
     }
     $block4_id = Configuration::get('FOOTER_4_CMS_BLOCK', 0);
     if ($block4_id != 0) {
         $sql_limit = 'LIMIT 0, 10';
         $category4 = new CMSCategory((int) $block4_id, (int) $id_lang);
         if (count($category4)) {
             $category['link'] = Tools::HtmlEntitiesUTF8($category4->getLink());
             $category['name'] = $category4->name;
             $pages = $this->getCMSPages($category4->id);
             foreach ($pages as $page) {
                 $cms = new CMS($page['id_cms'], (int) $id_lang);
                 $links = $cms->getLinks((int) $id_lang, array((int) $cms->id));
                 $page['link'] = $links[0]['link'];
                 $category['pages'][] = $page;
             }
             $category4 = $category;
         } else {
             $category4 = null;
         }
     } else {
         $category4 = null;
     }
     $this->smarty->assign('category1', $category1);
     $this->smarty->assign('categories2', $categories2);
     $this->smarty->assign('category3', $category3);
     $this->smarty->assign('category4', $category4);
     $this->smarty->assign('footer_category', new Category());
     $display = $this->display(__FILE__, 'footer.tpl');
     return $display;
 }
Example #6
0
	protected function generateCategoriesMenu($categories, $is_children = 0, $iteration = 0)
    {
        $html = '';

        foreach ($categories as $key => $category) {
            if ($category['level_depth'] > 1) {
                $cat = new Category($category['id_category']);
                $link = Tools::HtmlEntitiesUTF8($cat->getLink());
            } else {
                $link = $this->context->link->getPageLink('index');
            }

            /* Whenever a category is not active we shouldnt display it to customer */
            if ((bool)$category['active'] === false) {
                continue;
            }

            $coWidth = $iteration ? "col-md-2" : "";

            $html .= '<li class="'.$coWidth.(($this->page_name == 'category'
                && (int)Tools::getValue('id_category') == (int)$category['id_category']) ? ' sfHoverForce' : '').'">';
            $html .= '<a href="'.$link.'" title="'.$category['name'].'">';
            if ($iteration && $category['link_rewrite']) {
            	$html .= '<img src="'.$this->context->link->getCatImageLink($category['link_rewrite'], $category['id_category']).'" alt="'.$category['name'].'" />';
            	$html .= '<span>'.$category['name'].'</span><i></i>';
            } else {
            	$html .= '<span>'.$category['name'].'</span><i></i>';
            }

            $html .= '</a>';

            if (isset($category['children']) && !empty($category['children'])) {
                $html .= '<ul>';
                $html .= $this->generateCategoriesMenu($category['children'], 1);

                if ((int)$category['level_depth'] > 1 && !$is_children) {
                    $files = scandir(_PS_CAT_IMG_DIR_);

                    if (count(preg_grep('/^'.$category['id_category'].'-([0-9])?_thumb.jpg/i', $files)) > 0) {
                        $html .= '<li class="category-thumbnail">';

                        foreach ($files as $file) {
                            if (preg_match('/^'.$category['id_category'].'-([0-9])?_thumb.jpg/i', $file) === 1) {
                                $html .= '<div><img src="'.$this->context->link->getMediaLink(_THEME_CAT_DIR_.$file)
                                .'" alt="'.Tools::SafeOutput($category['name']).'" title="'
                                .Tools::SafeOutput($category['name']).'" class="imgm" /></div>';
                            }
                        }

                        $html .= '</li>';
                    }
                }

                $html .= '</ul>';
            }

            $html .= '</li>';
        }
        
        if ($iteration == 2) {
            $html .= '<li class="center-li col-md-4"></li>';
        }

        return $html;
    }
 private function getCMSMenuItems(&$menu, $parent, $depth = 1, $id_lang = false)
 {
     $category_id = (int) Tools::getValue('id_cms_category', false);
     $page_id = (int) Tools::getValue('id_cms', false);
     $is_category = $this->page_name == 'cms' && $category_id;
     $is_page = $this->page_name == 'cms' && $page_id;
     $id_lang = $id_lang ? (int) $id_lang : (int) Context::getContext()->language->id;
     $activeCategories = array();
     if ($is_page) {
         $parent_category = $this->getCmsParentCategory($page_id);
         $activeCategories = $this->getActiveCMSMenuItemPath($parent_category, $id_lang);
     } else {
         if ($is_category) {
             $activeCategories = $this->getActiveCMSMenuItemPath($category_id, $id_lang);
         }
     }
     $categories = $this->getCMSCategories(false, (int) $parent, (int) $id_lang);
     $pages = $this->getCMSPages((int) $parent);
     if ((count($categories) || count($pages)) && ($this->_showAll !== 'one level' || $this->_showAllResponsive !== 'one level')) {
         $pageMenu = '';
         foreach ($pages as $page) {
             $cms = new CMS($page['id_cms'], (int) $id_lang);
             $links = $cms->getLinks((int) $id_lang, array((int) $cms->id));
             $selected = $this->page_name == 'cms' && (int) Tools::getValue('id_cms') == $page['id_cms'] ? ' class="active"' : '';
             $pageMenu .= $this->_subItemHead . '<li class="' . $this->_subItemClass . '">';
             $pageMenu .= '<a href="' . $links[0]['link'] . '"' . $selected . '><span>' . $cms->meta_title . '</span></a>';
             $pageMenu .= '</li>' . $this->_subItemTail;
         }
         $catMenu = '';
         foreach ($categories as $category) {
             $currentId = (int) $category['id_cms_category'];
             $catSelect = '';
             foreach ($activeCategories as $activeCategory) {
                 if ($currentId === (int) $activeCategory['id_cms_category']) {
                     $catSelect = ' class="active"';
                 }
             }
             $cat = new CMSCategory((int) $category['id_cms_category'], (int) $id_lang);
             $catMenu .= $this->_subItemHead . '<li class="' . $this->_subItemClass . '">';
             $catMenu .= '<a href="' . Tools::HtmlEntitiesUTF8($cat->getLink()) . '"' . $catSelect . '><span>' . $category['name'] . '</span></a>';
             $this->getCMSMenuItems($catMenu, $category['id_cms_category'], (int) $depth + 1, $id_lang);
             $catMenu .= '</li>' . $this->_subItemTail;
         }
         $menu .= $this->_subMenuHead . '<ul class="' . $this->_subMenuClass . (empty($catMenu) ? '' : ' active') . '">';
         $menu .= $catMenu;
         $menu .= $pageMenu;
         $menu .= '</ul>' . $this->_subMenuTail;
     }
 }
 public function getMenuCustomerLink($lang_id = NULL)
 {
     $menu_items = $this->getMenuItems();
     $id_lang = (int) $this->context->language->id;
     $id_shop = (int) Shop::getContextShopID();
     foreach ($menu_items as $item) {
         if (!$item) {
             continue;
         }
         preg_match($this->pattern, $item, $value);
         $id = (int) substr($item, strlen($value[1]), strlen($item));
         switch (substr($item, 0, strlen($value[1]))) {
             case 'CAT':
                 $this->_menuLink .= $this->drawCustomMenuItem($id, 0, false, 0, $lang_id);
                 break;
             case 'PRD':
                 $selected = $this->page_name == 'product' && Tools::getValue('id_product') == $id ? ' class="sfHover"' : '';
                 $product = new Product((int) $id, true, (int) $id_lang);
                 if (!is_null($product->id)) {
                     $this->_menuLink .= '<div id ="pt_menu_product" class ="pt_menu"><div class="parentMenu" ><a href="' . Tools::HtmlEntitiesUTF8($product->getLink()) . '"><span>' . $product->name . '</span></a></div></div>' . PHP_EOL;
                 }
                 break;
             case 'CMS':
                 $selected = $this->page_name == 'cms' && Tools::getValue('id_cms') == $id ? ' class="sfHover"' : '';
                 $cms = CMS::getLinks((int) $id_lang, array($id));
                 if (count($cms)) {
                     $this->_menuLink .= '<div id ="pt_menu_cms" class ="pt_menu"><div class="parentMenu" ><a href="' . Tools::HtmlEntitiesUTF8($cms[0]['link']) . '"><span>' . $cms[0]['meta_title'] . '</span></a></div></div>' . PHP_EOL;
                 }
                 break;
             case 'CMS_CAT':
                 $category = new CMSCategory((int) $id, (int) $id_lang);
                 if (Validate::isLoadedObject($category)) {
                     $this->_menuLink .= '<div id ="pt_menu_cms" class ="pt_menu"><div class="parentMenu" ><a href="' . Tools::HtmlEntitiesUTF8($category->getLink()) . '"><span>' . $category->name . '</span></a>';
                 }
                 $this->_menuLink .= '</div>' . PHP_EOL;
                 $this->_menuLink .= $this->getCMSMenuItems($category->id);
                 // Case to handle the option to show all Manufacturers
             // Case to handle the option to show all Manufacturers
             case 'ALLMAN':
                 $link = new Link();
                 $this->_menuLink .= '<div id ="pt_menu_allsub" class ="pt_menu"><div class="parentMenu" ><a href="' . $link->getPageLink('manufacturer') . '" ><span>' . $this->l('All manufacturers') . '</span></a></div>' . PHP_EOL;
                 $manufacturers = Manufacturer::getManufacturers();
                 $this->_menuLink .= '<div class ="popup" style ="display:none">';
                 foreach ($manufacturers as $key => $manufacturer) {
                     $this->_menuLink .= '<div class ="block1"><div class="column col1"><div class="itemSubMenu level3"><a href="' . $link->getManufacturerLink((int) $manufacturer['id_manufacturer'], $manufacturer['link_rewrite']) . '">' . $manufacturer['name'] . '</a></div></div></div>' . PHP_EOL;
                 }
                 $this->_menuLink .= '</div></div>';
                 break;
             case 'MAN':
                 $selected = $this->page_name == 'manufacturer' && Tools::getValue('id_manufacturer') == $id ? ' class="sfHover"' : '';
                 $manufacturer = new Manufacturer((int) $id, (int) $id_lang);
                 if (!is_null($manufacturer->id)) {
                     if (intval(Configuration::get('PS_REWRITING_SETTINGS'))) {
                         $manufacturer->link_rewrite = Tools::link_rewrite($manufacturer->name);
                     } else {
                         $manufacturer->link_rewrite = 0;
                     }
                     $link = new Link();
                     $this->_menuLink .= '<div id ="pt_menu_man" class ="pt_menu"><div class="parentMenu" ><a href="' . Tools::HtmlEntitiesUTF8($link->getManufacturerLink((int) $id, $manufacturer->link_rewrite)) . '"><span>' . $manufacturer->name . '</span></a></div></div>' . PHP_EOL;
                 }
                 break;
                 // Case to handle the option to show all Suppliers
             // Case to handle the option to show all Suppliers
             case 'ALLSUP':
                 $link = new Link();
                 $this->_menuLink .= '<div id ="pt_menu_allsub" class ="pt_menu"><div class="parentMenu" ><a href="' . $link->getPageLink('supplier') . '" ><span>' . $this->l('All suppliers') . '</span></a></div>' . PHP_EOL;
                 $suppliers = Supplier::getSuppliers();
                 $this->_menuLink .= '<div class ="popup" style ="display:none">';
                 foreach ($suppliers as $key => $supplier) {
                     $this->_menuLink .= '<div class ="block1"><div class="column col1"><div class="itemSubMenu level3"><a href="' . $link->getSupplierLink((int) $supplier['id_supplier'], $supplier['link_rewrite']) . '">' . $supplier['name'] . '</a></div></div></div>' . PHP_EOL;
                 }
                 $this->_menuLink .= '</div></div>';
                 break;
             case 'SUP':
                 $selected = $this->page_name == 'supplier' && Tools::getValue('id_supplier') == $id ? ' class="sfHover"' : '';
                 $supplier = new Supplier((int) $id, (int) $id_lang);
                 if (!is_null($supplier->id)) {
                     $link = new Link();
                     $this->_menuLink .= '<div id ="pt_menu_sub" class ="pt_menu"><div class="parentMenu" ><a href="' . Tools::HtmlEntitiesUTF8($link->getSupplierLink((int) $id, $supplier->link_rewrite)) . '"><span>' . $supplier->name . '</span></a></div></div>' . PHP_EOL;
                 }
                 break;
             case 'SHOP':
                 $selected = $this->page_name == 'index' && $this->context->shop->id == $id ? ' class="sfHover"' : '';
                 $shop = new Shop((int) $id);
                 if (Validate::isLoadedObject($shop)) {
                     $link = new Link();
                     $this->_menuLink .= '<div id ="pt_menu_sub" class ="pt_menu"><div class="parentMenu" ><a href="' . Tools::HtmlEntitiesUTF8($shop->getBaseURL()) . '"><span>' . $supplier->name . '</span></a></div></div>' . PHP_EOL;
                 }
                 break;
             case 'LNK':
                 $link = VegaTopLinks::get((int) $id, (int) $id_lang, (int) $id_shop);
                 if (count($link)) {
                     if (!isset($link[0]['label']) || $link[0]['label'] == '') {
                         $default_language = Configuration::get('PS_LANG_DEFAULT');
                         $link = VegaTopLinks::get($link[0]['id_linksvegatop'], $default_language, (int) Shop::getContextShopID());
                     }
                     $this->_menuLink .= '<div id ="pt_ver_menu_link" class ="pt_menu"><div class="parentMenu" ><a href="' . Tools::HtmlEntitiesUTF8($link[0]['link']) . '"' . ($link[0]['new_window'] ? ' target="_blank"' : '') . '><span>' . $link[0]['label'] . '</a></span></div></div>' . PHP_EOL;
                 }
                 break;
         }
     }
 }
 private function getCategory(&$menu, $id_category, $id_lang = false, $id_shop = false, $is_child_item = false)
 {
     $id_lang = $id_lang ? (int) $id_lang : (int) Context::getContext()->language->id;
     $category = new Category((int) $id_category, (int) $id_lang);
     if ($category->level_depth > 1) {
         $category_link = $category->getLink();
     } else {
         $category_link = $this->context->link->getPageLink('index');
     }
     if (is_null($category->id)) {
         return;
     }
     $children = Category::getChildren((int) $id_category, (int) $id_lang, true, (int) $id_shop);
     $selected = $this->page_name == 'category' && (int) Tools::getValue('id_category') == $id_category ? ' active' : '';
     $is_intersected = array_intersect($category->getGroups(), $this->user_groups);
     $class = $selected . ($is_child_item ? $this->_subItemClass : $this->_itemClass);
     $head = $is_child_item ? $this->_subItemHead : $this->_itemHead;
     $tail = $is_child_item ? $this->_subItemTail : $this->_itemTail;
     // filter the categories that the user is allowed to see and browse
     if (!empty($is_intersected)) {
         $menu .= $head . '<li class="' . $class . '">';
         $menu .= '<a href="' . Tools::HtmlEntitiesUTF8($category_link) . '"><span>' . $category->name . '</span></a>';
         if (count($children) && ($this->_showAll !== 'one level' || $this->_showAllResponsive !== 'one level')) {
             $menu .= $this->_subMenuHead . '<ul class="' . $this->_subMenuClass . '">';
             foreach ($children as $child) {
                 $this->getCategory($menu, (int) $child['id_category'], (int) $id_lang, (int) $child['id_shop'], true);
             }
             $menu .= '</ul>' . $this->_subMenuTail;
         }
         $menu .= '</li>' . $tail;
     }
 }
 private function getCategory($id_category, $id_lang = false, $id_shop = false)
 {
     $id_lang = $id_lang ? (int) $id_lang : (int) Context::getContext()->language->id;
     $category = new Category((int) $id_category, (int) $id_lang);
     if ($category->level_depth > 1) {
         $category_link = $category->getLink();
     } else {
         $category_link = $this->context->link->getPageLink('index');
     }
     if (is_null($category->id)) {
         return;
     }
     $children = Category::getChildren((int) $id_category, (int) $id_lang, true, (int) $id_shop);
     $selected = $this->page_name == 'category' && (int) Tools::getValue('id_category') == $id_category ? ' class="sfHoverForce"' : '';
     $is_intersected = array_intersect($category->getGroups(), $this->user_groups);
     // filter the categories that the user is allowed to see and browse
     if (!empty($is_intersected)) {
         $this->_menu .= '<li ' . $selected . '>';
         $this->_menu .= '<a href="' . Tools::HtmlEntitiesUTF8($category_link) . '">' . $category->name . '</a>';
         if (count($children)) {
             $this->_menu .= '<ul>';
             foreach ($children as $child) {
                 $this->getCategory((int) $child['id_category'], (int) $id_lang, (int) $child['id_shop']);
             }
             $this->_menu .= '</ul>';
         }
         $this->_menu .= '</li>';
     }
 }
Example #11
0
 private function generateCategoriesMenu2($categories, $subcats = false, $detph_limit, $current_depth, $subcat_limit, $subcat_count, $previus_depth = 0)
 {
     $return_categories = array();
     foreach ($categories as $key => $category) {
         if ($current_depth > $detph_limit) {
             return;
         }
         if ($subcat_count >= $subcat_limit) {
             return $return_categories;
         }
         if ($category['level_depth'] > 1) {
             $cat = new Category($category['id_category']);
             $link = Tools::HtmlEntitiesUTF8($cat->getLink());
         } else {
             $link = $this->context->link->getPageLink('index');
         }
         if ($subcats) {
             $return_categories[$key]['title'] = $category['name'];
             $return_categories[$key]['href'] = $link;
         } else {
             $return_categories['title'] = $category['name'];
             $return_categories['href'] = $link;
         }
         if (isset($category['children']) && !empty($category['children'])) {
             if ($subcats) {
                 $return_categories[$key]['children'] = $this->generateCategoriesMenu2($category['children'], true, $detph_limit, $current_depth + 1, $subcat_limit, 0, $current_depth);
             } else {
                 $return_categories['children'] = $this->generateCategoriesMenu2($category['children'], true, $detph_limit, $current_depth + 1, $subcat_limit, 0, $current_depth);
             }
         }
         $subcat_count++;
     }
     return $return_categories;
 }