示例#1
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>';
     }
 }
 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;
     }
 }
示例#3
0
 protected function generateCMSCategoriesMenu($id_cms_category, $id_lang)
 {
     $category = new CMSCategory($id_cms_category, $id_lang);
     $rawSubCategories = $this->getCMSCategories(false, $id_cms_category, $id_lang);
     $rawSubPages = $this->getCMSPages($id_cms_category);
     $subCategories = array_map(function ($category) use($id_lang) {
         return $this->generateCMSCategoriesMenu($category['id_cms_category'], $id_lang);
     }, $rawSubCategories);
     $subPages = array_map(function ($page) use($id_lang) {
         return $this->makeNode(['type' => 'cms-page', 'page_identifier' => 'cms-page-' . $page['id_cms'], 'label' => $page['meta_title'], 'url' => $this->context->link->getCMSLink(new CMS($page['id_cms'], $id_lang), null, null, $id_lang)]);
     }, $rawSubPages);
     $node = $this->makeNode(['type' => 'cms-category', 'page_identifier' => 'cms-category-' . $id_cms_category, 'label' => $category->name, 'url' => $category->getLink(), 'children' => array_merge($subCategories, $subPages)]);
     return $node;
 }
示例#4
0
 public function extractElementInfo()
 {
     switch ($this->type) {
         case 'external':
             $this->link = $this->external;
             break;
     }
     if ($this->element) {
         switch ($this->type) {
             case 'cms_category':
                 $title = $this->element->name;
                 $this->link = $this->element->getLink();
                 if ($this->display_cms_cat_childs && !self::isAdmin()) {
                     foreach (CmsCategory::getChildren($this->element->id, self::getIdLang()) as $children) {
                         $obj = new CmsCategory($children['id_cms_category'], self::getIdLang());
                         $child = new self(array('type' => 'cms_category', 'id_cms_category' => $obj->id, 'element' => $obj, 'display_cms_cat_childs' => $this->display_cms_cat_childs));
                         $this->childrens[] = $child;
                     }
                     foreach ($this->getCMSPages($this->element->id) as $page) {
                         $obj = new CMS($page['id_cms'], self::getIdLang());
                         $child = new self(array('type' => 'cms', 'id_cms' => $obj->id, 'element' => $obj, 'display_cms_cat_childs' => $this->display_cms_cat_childs));
                         $this->childrens[] = $child;
                     }
                 }
                 break;
             case 'product_category':
                 $title = $this->element->name;
                 $link = $this->element->getLink();
                 if ($this->display_prod_cat_childs && !self::isAdmin()) {
                     /** @var $this->element CategoryCore */
                     foreach (Category::getChildren($this->element->id, self::getIdLang()) as $children) {
                         $obj = new Category($children['id_category'], self::getIdLang());
                         $child = new self(array('type' => 'product_category', 'id_category' => $obj->id, 'title' => $obj->name, 'link' => $obj->getLink(), 'display_prod_cat_childs' => $this->display_prod_cat_childs));
                         $this->childrens[] = $child;
                     }
                 }
                 break;
             case 'product':
                 $link = $this->element->getLink();
                 $title = $this->element->name;
                 break;
             case 'internal':
                 $link = self::getClassLink()->getPageLink($this->element->page);
                 $title = $this->element->title;
                 break;
             case 'cms':
                 $link = self::getClassLink()->getCMSLink($this->element, null);
                 $title = $this->element->meta_title;
                 break;
             case 'manufacturer':
                 $link = $this->element->getLink();
                 $title = $this->element->name;
                 break;
             case 'supplier':
                 $link = $this->element->getLink();
                 $title = $this->element->name;
                 break;
             case 'attachment':
                 $link = self::getClassLink()->getPageLink('attachment', NULL, "id_attachment=" . $this->id_attachment);
                 $title = $this->element->name;
                 break;
         }
     }
     //        if(self::isSSL())
     //            $this->link = str_replace('http://','https://',$this->link);
     if (empty($this->link)) {
         $this->link = @$link;
     }
     if (empty($this->title)) {
         $this->title = @$title;
     }
     if (is_array($this->title)) {
         $this->title = $this->title[self::getIdLang()];
     }
     if ($this->has_anchor) {
         $this->link .= '#' . $this->anchor;
     }
 }