Source for file helper.php

Documentation is available at helper.php

  1. <?php
  2. /**
  3.  * @package     Joomla.Site
  4.  * @subpackage  mod_menu
  5.  *
  6.  * @copyright   Copyright (C) 2005 - 2013 Open Source Matters, Inc. All rights reserved.
  7.  * @license     GNU General Public License version 2 or later; see LICENSE.txt
  8.  */
  9.  
  10. defined('_JEXEC'or die;
  11.  
  12. /**
  13.  * Helper for mod_menu
  14.  *
  15.  * @package     Joomla.Site
  16.  * @subpackage  mod_menu
  17.  * @since       1.5
  18.  */
  19. {
  20.     /**
  21.      * Get a list of the menu items.
  22.      *
  23.      * @param  JRegistry   $params  The module options.
  24.      *
  25.      * @return  array 
  26.      *
  27.      * @since   1.5
  28.      */
  29.     public static function getList(&$params)
  30.     {
  31.         $app JFactory::getApplication();
  32.         $menu $app->getMenu();
  33.  
  34.         // Get active menu item
  35.         $base self::getBase($params);
  36.         $user JFactory::getUser();
  37.         $levels $user->getAuthorisedViewLevels();
  38.         asort($levels);
  39.         $key 'menu_items' $params implode(','$levels'.' $base->id;
  40.         $cache JFactory::getCache('mod_menu''');
  41.         if (!($items $cache->get($key)))
  42.         {
  43.             $path    $base->tree;
  44.             $start   = (int) $params->get('startLevel');
  45.             $end     = (int) $params->get('endLevel');
  46.             $showAll $params->get('showAllChildren');
  47.             $items   $menu->getItems('menutype'$params->get('menutype'));
  48.  
  49.             $lastitem 0;
  50.  
  51.             if ($items)
  52.             {
  53.                 foreach ($items as $i => $item)
  54.                 {
  55.                     if (($start && $start $item->level)
  56.                         || ($end && $item->level $end)
  57.                         || (!$showAll && $item->level && !in_array($item->parent_id$path))
  58.                         || ($start && !in_array($item->tree[$start 2]$path)))
  59.                     {
  60.                         unset($items[$i]);
  61.                         continue;
  62.                     }
  63.  
  64.                     $item->deeper     false;
  65.                     $item->shallower  false;
  66.                     $item->level_diff 0;
  67.  
  68.                     if (isset($items[$lastitem]))
  69.                     {
  70.                         $items[$lastitem]->deeper     ($item->level $items[$lastitem]->level);
  71.                         $items[$lastitem]->shallower  ($item->level $items[$lastitem]->level);
  72.                         $items[$lastitem]->level_diff ($items[$lastitem]->level $item->level);
  73.                     }
  74.  
  75.                     $item->parent = (boolean) $menu->getItems('parent_id'(int) $item->idtrue);
  76.  
  77.                     $lastitem     $i;
  78.                     $item->active false;
  79.                     $item->flink  $item->link;
  80.  
  81.                     // Reverted back for CMS version 2.5.6
  82.                     switch ($item->type)
  83.                     {
  84.                         case 'separator':
  85.                         case 'heading':
  86.                             // No further action needed.
  87.                             continue;
  88.  
  89.                         case 'url':
  90.                             if ((strpos($item->link'index.php?'=== 0&& (strpos($item->link'Itemid='=== false))
  91.                             {
  92.                                 // If this is an internal Joomla link, ensure the Itemid is set.
  93.                                 $item->flink $item->link '&Itemid=' $item->id;
  94.                             }
  95.                             break;
  96.  
  97.                         case 'alias':
  98.                             // If this is an alias use the item id stored in the parameters to make the link.
  99.                             $item->flink 'index.php?Itemid=' $item->params->get('aliasoptions');
  100.                             break;
  101.  
  102.                         default:
  103.                             $router $app::getRouter();
  104.                             if ($router->getMode(== JROUTER_MODE_SEF)
  105.                             {
  106.                                 $item->flink 'index.php?Itemid=' $item->id;
  107.                             }
  108.                             else
  109.                             {
  110.                                 $item->flink .= '&Itemid=' $item->id;
  111.                             }
  112.                             break;
  113.                     }
  114.  
  115.                     if (strcasecmp(substr($item->flink04)'http'&& (strpos($item->flink'index.php?'!== false))
  116.                     {
  117.                         $item->flink JRoute::_($item->flinktrue$item->params->get('secure'));
  118.                     }
  119.                     else
  120.                     {
  121.                         $item->flink JRoute::_($item->flink);
  122.                     }
  123.  
  124.                     // We prevent the double encoding because for some reason the $item is shared for menu modules and we get double encoding
  125.                     // when the cause of that is found the argument should be removed
  126.                     $item->title        htmlspecialchars($item->titleENT_COMPAT'UTF-8'false);
  127.                     $item->anchor_css   htmlspecialchars($item->params->get('menu-anchor_css''')ENT_COMPAT'UTF-8'false);
  128.                     $item->anchor_title htmlspecialchars($item->params->get('menu-anchor_title''')ENT_COMPAT'UTF-8'false);
  129.                     $item->menu_image   $item->params->get('menu_image'''htmlspecialchars($item->params->get('menu_image''')ENT_COMPAT'UTF-8'false'';
  130.                 }
  131.  
  132.                 if (isset($items[$lastitem]))
  133.                 {
  134.                     $items[$lastitem]->deeper     (($start?$start:1$items[$lastitem]->level);
  135.                     $items[$lastitem]->shallower  (($start?$start:1$items[$lastitem]->level);
  136.                     $items[$lastitem]->level_diff ($items[$lastitem]->level ($start?$start:1));
  137.                 }
  138.             }
  139.  
  140.             $cache->store($items$key);
  141.         }
  142.         return $items;
  143.     }
  144.  
  145.     /**
  146.      * Get base menu item.
  147.      *
  148.      * @param   JRegistry  $params  The module options.
  149.      *
  150.      * @return   object 
  151.      *
  152.      * @since    3.0.2
  153.      */
  154.     public static function getBase(&$params)
  155.     {
  156.  
  157.         // Get base menu item from parameters
  158.         if ($params->get('base'))
  159.         {
  160.             $base JFactory::getApplication()->getMenu()->getItem($params->get('base'));
  161.         }
  162.         else
  163.         {
  164.             $base false;
  165.         }
  166.  
  167.         // Use active menu item if no base found
  168.         if (!$base)
  169.         {
  170.             $base self::getActive($params);
  171.         }
  172.  
  173.         return $base;
  174.     }
  175.  
  176.     /**
  177.      * Get active menu item.
  178.      *
  179.      * @param   JRegistry  $params  The module options.
  180.      *
  181.      * @return  object 
  182.      *
  183.      * @since    3.0.2
  184.      */
  185.     public static function getActive(&$params)
  186.     {
  187.         $menu JFactory::getApplication()->getMenu();
  188.  
  189.         return $menu->getActive($menu->getActive($menu->getDefault();
  190.     }
  191.  
  192. }

Documentation generated on Tue, 19 Nov 2013 15:04:17 +0100 by phpDocumentor 1.4.3