Tout Pratique 5d50494bf6 recette
2015-11-17 10:12:52 +01:00

125 lines
4.8 KiB
PHP

<?php
class Tools extends ToolsCore
{
public static function getPath($id_category, $path = '', $link_on_the_item = false, $category_type = 'products', Context $context = null)
{
if (!$context)
$context = Context::getContext();
$id_category = (int)$id_category;
if ($id_category == 1 && $category_type != 'categoriescms' && $category_type != 'postcms')
return '<span class="navigation_end">'.$path.'</span>';
$pipe = Configuration::get('PS_NAVIGATION_PIPE');
if (empty($pipe))
$pipe = '>';
$full_path = '';
if ($category_type === 'products')
{
$interval = Category::getInterval($id_category);
$id_root_category = $context->shop->getCategory();
$interval_root = Category::getInterval($id_root_category);
if ($interval)
{
$sql = 'SELECT c.id_category, cl.name, cl.link_rewrite
FROM '._DB_PREFIX_.'category c
LEFT JOIN '._DB_PREFIX_.'category_lang cl ON (cl.id_category = c.id_category'.Shop::addSqlRestrictionOnLang('cl').')
'.Shop::addSqlAssociation('category', 'c').'
WHERE c.nleft <= '.$interval['nleft'].'
AND c.nright >= '.$interval['nright'].'
AND c.nleft >= '.$interval_root['nleft'].'
AND c.nright <= '.$interval_root['nright'].'
AND cl.id_lang = '.(int)$context->language->id.'
AND c.active = 1
AND c.level_depth > '.(int)$interval_root['level_depth'].'
ORDER BY c.level_depth ASC';
$categories = Db::getInstance()->executeS($sql);
// add store link
$link = $context->link->getHomeStoreLink();
$full_path .='<a href="'.$link.'" title="Boutique" data-gg="">Boutique</a><span class="navigation-pipe">></span>';
$n = 1;
$n_categories = count($categories);
foreach ($categories as $category)
{
$full_path .=
(($n < $n_categories || $link_on_the_item) ? '<a href="'.Tools::safeOutput($context->link->getCategoryLink((int)$category['id_category'], $category['link_rewrite'])).'" title="'.htmlentities($category['name'], ENT_NOQUOTES, 'UTF-8').'" data-gg="">' : '<span>').
htmlentities($category['name'], ENT_NOQUOTES, 'UTF-8').
(($n < $n_categories || $link_on_the_item) ? '</a>' : '</span>').
(($n++ != $n_categories || !empty($path)) ? '<span class="navigation-pipe">'.$pipe.'</span>' : '');
}
if (isset($path) && $path) {
$path = '<span>'.$path.'</span>';
}
return $full_path.$path;
}
}
elseif ($category_type === 'categoriescms')
{
require_once _PS_MODULE_DIR_.'cmsps/classes/CmsPsCategory.php';
$category = new CmsPsCategory($id_category, $context->language->id);
if(!empty($path)) {
$full_path = '<a href="'.Tools::safeOutput($context->link->getCategoryCmsLink((int)$id_category)).'" data-gg="">'
.htmlentities($category->title, ENT_NOQUOTES, 'UTF-8').'</a>';
$full_path.= '<span class="navigation-pipe">></span>';
} else {
$full_path = '<span>'.htmlentities($category->title, ENT_NOQUOTES, 'UTF-8').'</span>';
}
if ($category->id_parent != 0) {
return Tools::getPath($category->id_parent, $full_path, $link_on_the_item, $category_type);
} else {
return $full_path.$path;
}
}
elseif ($category_type === 'postcms')
{
require_once _PS_MODULE_DIR_.'cmsps/classes/CmsPsPost.php';
require_once _PS_MODULE_DIR_.'cmsps/classes/CmsPsCategory.php';
$post = new CmsPsPost($id_category, $context->language->id);
$category = new CmsPsCategory($post->id_category, $context->language->id);
$full_path = '<a href="'.Tools::safeOutput($context->link->getCategoryCmsLink((int)$category->id)).'" data-gg="">'
.htmlentities($category->title, ENT_NOQUOTES, 'UTF-8').
'</a>';
if ($path == '') {
$full_path.= '<span class="navigation-pipe">></span><span>'.$post->title.'</span>';
}
if ($category->id_parent != 0) {
return Tools::getPath($category->id_parent, $full_path, $link_on_the_item, 'categoriescms');
} else {
return $full_path.$path;
}
}
elseif ($category_type === 'CMS')
{
$category = new CMSCategory($id_category, $context->language->id);
if (!Validate::isLoadedObject($category))
die(Tools::displayError());
$category_link = $context->link->getCMSCategoryLink($category);
if ($path != $category->name)
$full_path .= '<a href="'.Tools::safeOutput($category_link).'" data-gg="">'.htmlentities($category->name, ENT_NOQUOTES, 'UTF-8').'</a><span class="navigation-pipe">'.$pipe.'</span>'.$path;
else
$full_path = ($link_on_the_item ? '<a href="'.Tools::safeOutput($category_link).'" data-gg="">' : '').htmlentities($path, ENT_NOQUOTES, 'UTF-8').($link_on_the_item ? '</a>' : '');
return Tools::getPath($category->id_parent, $full_path, $link_on_the_item, $category_type);
}
}
public static function encryptOld($passwd)
{
$old_cookiekey = 'OMpLSFgIVRfv81Ti9ib4oYk6VBFOOr099tyRugfNQK3QV0UjIPrEu4r2';
return md5($old_cookiekey.$passwd);
}
}