Advertisement
Patrykc

Tools.php

Jul 9th, 2015
267
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 3.10 KB | None | 0 0
  1. <?php
  2.  
  3. class Tools extends ToolsCore
  4. {
  5.  
  6.  
  7. public static function getPath($id_category, $path = '', $link_on_the_item = false, $category_type = 'products', Context $context = null)
  8.     {
  9.         if (!$context)
  10.             $context = Context::getContext();
  11.  
  12.         $id_category = (int)$id_category;
  13.         if ($id_category == 1)
  14.             return '<span class="navigation_end">'.$path.'</span>';
  15.  
  16.         $pipe = Configuration::get('PS_NAVIGATION_PIPE');
  17.         if (empty($pipe))
  18.             $pipe = '>';
  19.  
  20.         $full_path = '';
  21.         if ($category_type === 'products')
  22.         {
  23.             $interval = Category::getInterval($id_category);
  24.             $id_root_category = $context->shop->getCategory();
  25.             $interval_root = Category::getInterval($id_root_category);
  26.             if ($interval)
  27.             {
  28.                 $sql = 'SELECT c.id_category, cl.name, cl.link_rewrite
  29.                         FROM '._DB_PREFIX_.'category c
  30.                         LEFT JOIN '._DB_PREFIX_.'category_lang cl ON (cl.id_category = c.id_category'.Shop::addSqlRestrictionOnLang('cl').')
  31.                         WHERE c.nleft <= '.$interval['nleft'].'
  32.                             AND c.nright >= '.$interval['nright'].'
  33.                             AND c.nleft >= '.$interval_root['nleft'].'
  34.                             AND c.nright <= '.$interval_root['nright'].'
  35.                             AND cl.id_lang = '.(int)$context->language->id.'
  36.                             AND c.active = 1
  37.                             AND c.level_depth > '.(int)$interval_root['level_depth'].'
  38.                         ORDER BY c.level_depth ASC';
  39.                 $categories = Db::getInstance()->executeS($sql);
  40.  
  41.                 $n = 1;
  42.                 $n_categories = count($categories);
  43.                 foreach ($categories as $category)
  44.                 {
  45.                     $full_path .=
  46.                     (($n < $n_categories || $link_on_the_item) ? '<div itemscope itemtype="http://data-vocabulary.org/Breadcrumb"><span itemprop="title"><a itemprop="url" href="'.Tools::safeOutput($context->link->getCategoryLink((int)$category['id_category'], $category['link_rewrite'])).'" title="'.htmlentities($category['name'], ENT_NOQUOTES, 'UTF-8').'">' : '').
  47.                     htmlentities($category['name'], ENT_NOQUOTES, 'UTF-8').
  48.                     (($n < $n_categories || $link_on_the_item) ? '</span></a></div>' : '').
  49.                     (($n++ != $n_categories || !empty($path)) ? '<span class="navigation-pipe">'.$pipe.'</span>' : '');
  50.                 }
  51.  
  52.                 return $full_path.$path;
  53.                
  54.             }
  55.         }
  56.         else if ($category_type === 'CMS')
  57.         {
  58.             $category = new CMSCategory($id_category, $context->language->id);
  59.             if (!Validate::isLoadedObject($category))
  60.                 die(Tools::displayError());
  61.             $category_link = $context->link->getCMSCategoryLink($category);
  62.  
  63.             if ($path != $category->name)
  64.                 $full_path .= '<div itemscope itemtype="http://data-vocabulary.org/Breadcrumb"><span itemprop="title"><a itemprop="url" href="'.Tools::safeOutput($category_link).'">'.htmlentities($category->name, ENT_NOQUOTES, 'UTF-8').'</span></a></div><span class="navigation-pipe">'.$pipe.'</span>'.$path;
  65.             else
  66.                 $full_path = ($link_on_the_item ? '<div itemscope itemtype="http://data-vocabulary.org/Breadcrumb"><span itemprop="title"><a itemprop="url" href="'.Tools::safeOutput($category_link).'">' : '').htmlentities($path, ENT_NOQUOTES, 'UTF-8').($link_on_the_item ? '</span></a></div>' : '');
  67.  
  68.             return Tools::getPath($category->id_parent, $full_path, $link_on_the_item, $category_type);
  69.         }
  70.     }
  71.  
  72.  
  73. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement