public function renderContent($args, $setting) { $t = array('name' => '', 'html' => ''); $setting = array_merge($t, $setting); $nb = $setting['itemstab'] ? (int) $setting['itemstab'] : 6; $catids = $setting['categories'] ? $setting['categories'] : array(); $orderby = $setting['orderby'] ? $setting['orderby'] : 'position'; $orderway = $setting['orderway'] ? $setting['orderway'] : 'ASC'; $items_page = $setting['itemspage'] ? (int) $setting['itemspage'] : 3; $columns_page = $setting['columns'] ? (int) $setting['columns'] : 3; $categories = array(); foreach ($catids as $catid) { $category = new Category($catid, (int) Context::getContext()->language->id); if ($category->id) { $categories[$catid]['id'] = $category->id; $categories[$catid]['name'] = $category->name; $categories[$catid]['link'] = $category->getLink(); $products = $category->getProducts((int) Context::getContext()->language->id, 1, $nb, $orderby, $orderway); Context::getContext()->controller->addColorsToProductList($products); $categories[$catid]['products'] = $products; } } $setting['leocategories'] = $categories; $setting['itemsperpage'] = $items_page; $setting['columnspage'] = $columns_page; $setting['scolumn'] = 12 / $columns_page; $setting['myTab'] = 'leocategorytab' . rand(20, rand()); $output = array('type' => 'categoriestabs', 'data' => $setting); return $output; }
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; }
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="' . $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 generateCategoriesMenu($categories) { $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'); } $html .= '<li' . ($this->page_name == 'category' && (int) Tools::getValue('id_category') == (int) $category['id_category'] ? ' class="sfHoverForce"' : '') . '>'; $html .= '<a href="' . $link . '" title="' . $category['name'] . '">' . $category['name'] . '</a>'; if (isset($category['children']) && !empty($category['children'])) { $html .= '<ul>'; $html .= $this->generateCategoriesMenu($category['children']); if ((int) $category['level_depth'] == 2) { $files = scandir(_PS_CAT_IMG_DIR_); if (count($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; }
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) . '" title="' . $category->name . '">' . $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']); } if ($category->level_depth == 2) { $files = scandir(_PS_CAT_IMG_DIR_); $this->_menu .= '<li id="category-thumbnail">'; foreach ($files as $file) { if (preg_match('/' . $category->id . '-([0-9])?_thumb.jpg/i', $file) === 1) { $this->_menu .= '<div><img src="' . Tools::getShopDomain(true, true) . __PS_BASE_URI__ . basename(_PS_IMG_DIR_) . '/' . basename(_PS_CAT_IMG_DIR_) . '/' . $file . '" alt="' . $category->name . '" class="imgm" /></div>'; } } $this->_menu .= '</li>'; } $this->_menu .= '</ul>'; } $this->_menu .= '</li>'; } }
private function getCategory($id_category, $id_lang) { global $page_name; $categorie = new Category($id_category, $id_lang); if (is_null($categorie->id)) { return; } $selected = $page_name == 'category' && (int) Tools::getValue('id_category') == $id_category ? ' class="sfHoverForce"' : ''; $this->_menu .= '<li' . $selected . '>'; if (count(explode('.', $categorie->name)) > 1) { $name = str_replace('.', '', strstr($categorie->name, '.')); } else { $name = $categorie->name; } $this->_menu .= '<a href="' . $categorie->getLink() . '">' . $name . '</a>'; $childrens = Category::getChildren($id_category, $id_lang); if (count($childrens)) { $this->_menu .= '<ul>'; foreach ($childrens as $children) { $this->getCategory($children['id_category'], $id_lang); } $this->_menu .= '</ul>'; } $this->_menu .= '</li>'; }
protected function generateCategoriesMenu($categories, $is_children = 0) { $nodes = []; foreach ($categories as $key => $category) { $node = $this->makeNode([]); if ($category['level_depth'] > 1) { $cat = new Category($category['id_category']); $link = $cat->getLink(); } else { $link = $this->context->link->getPageLink('index'); } $node['url'] = $link; $node['type'] = 'category'; $node['page_identifier'] = 'category-' . $category['id_category']; /* Whenever a category is not active we shouldnt display it to customer */ if ((bool) $category['active'] === false) { continue; } $current = $this->page_name == 'category' && (int) Tools::getValue('id_category') == (int) $category['id_category']; $node['current'] = $current; $node['label'] = $category['name']; $node['image_urls'] = []; if (isset($category['children']) && !empty($category['children'])) { $node['children'] = $this->generateCategoriesMenu($category['children'], 1); $files = scandir(_PS_CAT_IMG_DIR_); if (count(preg_grep('/^' . $category['id_category'] . '-([0-9])?_thumb.jpg/i', $files)) > 0) { foreach ($files as $file) { if (preg_match('/^' . $category['id_category'] . '-([0-9])?_thumb.jpg/i', $file) === 1) { $image_url = $this->context->link->getMediaLink(_THEME_CAT_DIR_ . $file); $node['image_urls'][] = $image_url; } } } } $nodes[] = $node; } return $nodes; }
private function getCatMobileOption($id_category, $id_lang = false, $id_shop = false, $child = 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="active"' : ''; /* $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->_mmenu .= '<option value="' . htmlentities($category_link) . '">'; if ($child == 1) { $this->_mmenu .= ' – '; } $this->_mmenu .= $category->name; $this->_mmenu .= '</option>'; if (count($children)) { foreach ($children as $child) { $this->getCatMobileOption((int) $child['id_category'], (int) $id_lang, (int) $child['id_shop'], $child = 1); } } //} }
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="' . $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>'; } }
private function getCategory($id_category, $id_lang) { global $page_name; $categorie = new Category($id_category, $id_lang); if (is_null($categorie->id)) { return; } $selected = $page_name == 'category' && (int) Tools::getValue('id_category') == $id_category ? ' class="sfHoverForce"' : ''; $this->_menu .= '<li' . $selected . '>'; if (count(explode('.', $categorie->name)) > 1) { $name = str_replace('.', '', strstr($categorie->name, '.')); } else { $name = $categorie->name; } if ($id_category == 1) { $this->_menu .= '<a href="' . _PS_BASE_URL_ . __PS_BASE_URI__ . '"><span>' . htmlentities($name) . '</span></a>'; } else { $this->_menu .= '<a href="' . $categorie->getLink() . '"><span>' . htmlentities($name) . '</span></a>'; } }
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 generateCategoriesMenu($categories, $activeCategories = array(), $is_child_item = false) { $html = ''; $class = $is_child_item ? $this->_subItemClass : $this->_itemClass; $head = $is_child_item ? $this->_subItemHead : $this->_itemHead; $tail = $is_child_item ? $this->_subItemTail : $this->_itemTail; foreach ($categories as $key => $category) { $currentId = (int) $category['id_category']; if ($category['level_depth'] > 1) { $cat = new Category($currentId); $link = Tools::HtmlEntitiesUTF8($cat->getLink()); } else { $link = $this->context->link->getPageLink('index'); } $selected = ''; foreach ($activeCategories as $activeCategory) { if ($currentId === (int) $activeCategory['id_category']) { $selected = ' active'; } } $html .= $head . '<li class="' . $class . '">'; $html .= '<a href="' . $link . '" title="' . $category['name'] . '"' . (empty($selected) ? '' : 'class="' . $selected . '"') . '><span>' . $category['name'] . '</span></a>'; if (isset($category['children']) && !empty($category['children']) && ($this->_showAll !== 'one level' || $this->_showAllResponsive !== 'one level')) { $html .= $this->_subMenuHead . '<ul class="' . $this->_subMenuClass . $selected . '">'; $html .= $this->generateCategoriesMenu($category['children'], $activeCategories, true); if ((int) $category['level_depth'] == 2) { $files = scandir(_PS_CAT_IMG_DIR_); if (count($files) > 0) { $html .= $this->_subItemHead . '<li id="category-thumbnail" class="' . $this->_subItemClass . '">'; 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>' . $this->_subItemTail; } } $html .= '</ul>' . $this->_subMenuTail; } $html .= '</li>' . $tail; } return $html; }
public static function getCategories($id_category, $id_lang, $ignore = array(), $maxLevel = 0, $currLevel = 0) { $results = array(); $currLevel++; $categorie = new Category($id_category, $id_lang); if (is_null($categorie->id)) { return $results; } if (count(explode('.', $categorie->name)) > 1) { $title = str_replace('.', '', strstr($categorie->name, '.')); } else { $title = $categorie->name; } $link = $categorie->getLink(); $childrens = array(); $_childrens = Category::getChildren($id_category, $id_lang); if (count($_childrens)) { foreach ($_childrens as $children) { $id_category = $children['id_category']; $children = self::getCategories($id_category, $id_lang, $ignore, $maxLevel, $currLevel); if (!in_array($id_category, $ignore)) { if (isset($children[0])) { $childrens[] = $children[0]; } } } } if (!in_array($categorie->id, $ignore) && !($currLevel > $maxLevel && $maxLevel != 0)) { if (count(explode('.', $title)) > 1) { $title = str_replace('.', '', strstr($title, '.')); } $results[] = array('id' => $categorie->id, 'id_menu' => '', 'type' => 'category', 'title' => $title, 'logged' => null, 'css' => '', 'new_window' => false, 'level' => $currLevel, 'numProducts' => Configuration::get('MENU_CATEGORIES_NUM') ? self::getNumProductsByCategory($categorie->id) : 0, 'link' => $link, 'childrens' => $childrens); } return $results; }
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 ? ' active ' : ''; $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 class="' . $selected; $add_data = ''; if ($category->level_depth == 1) { $this->_menu .= 'dropdown">'; $add_data = ' class="dropdown-toggle" data-toggle="dropdown"'; } elseif ($category->level_depth > 1 && count($children)) { $this->_menu .= 'dropdown-submenu">'; } else { $this->_menu .= '">'; } $this->_menu .= '<a' . $add_data . ' href="' . $category_link . '">' . $category->name; if (count($children)) { $this->_menu .= '<b class="caret"></b>'; } $this->_menu .= '</a>'; if (count($children)) { $this->_menu .= '<ul class="dropdown-menu">'; foreach ($children as $child) { $this->getCategory((int) $child['id_category'], (int) $id_lang, (int) $child['id_shop']); } $this->_menu .= '</ul>'; } $this->_menu .= '</li>'; } }
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; } }
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; }