Source for file site.php

Documentation is available at site.php

  1. <?php
  2. /**
  3.  * @package     Joomla.Libraries
  4.  * @subpackage  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.  * JMenu class
  14.  *
  15.  * @package     Joomla.Libraries
  16.  * @subpackage  Menu
  17.  * @since       1.5
  18.  */
  19. class JMenuSite extends JMenu
  20. {
  21.     /**
  22.      * Loads the entire menu table into memory.
  23.      *
  24.      * @return  array 
  25.      *
  26.      * @since   1.5
  27.      */
  28.     public function load()
  29.     {
  30.         $db    JFactory::getDbo();
  31.         $query $db->getQuery(true)
  32.             ->select('m.id, m.menutype, m.title, m.alias, m.note, m.path AS route, m.link, m.type, m.level, m.language')
  33.             ->select($db->quoteName('m.browserNav'', m.access, m.params, m.home, m.img, m.template_style_id, m.component_id, m.parent_id')
  34.             ->select('e.element as component')
  35.             ->from('#__menu AS m')
  36.             ->join('LEFT''#__extensions AS e ON m.component_id = e.extension_id')
  37.             ->where('m.published = 1')
  38.             ->where('m.parent_id > 0')
  39.             ->where('m.client_id = 0')
  40.             ->order('m.lft');
  41.  
  42.         // Set the query
  43.         $db->setQuery($query);
  44.  
  45.         try
  46.         {
  47.             $this->_items = $db->loadObjectList('id');
  48.         }
  49.         catch (RuntimeException $e)
  50.         {
  51.             JError::raiseWarning(500JText::sprintf('JERROR_LOADING_MENUS'$e->getMessage()));
  52.             return false;
  53.         }
  54.  
  55.         foreach ($this->_items as &$item)
  56.         {
  57.             // Get parent information.
  58.             $parent_tree array();
  59.  
  60.             if (isset($this->_items[$item->parent_id]))
  61.             {
  62.                 $parent_tree  $this->_items[$item->parent_id]->tree;
  63.             }
  64.  
  65.             // Create tree.
  66.             $parent_tree[$item->id;
  67.             $item->tree $parent_tree;
  68.  
  69.             // Create the query array.
  70.             $url str_replace('index.php?'''$item->link);
  71.             $url str_replace('&amp;''&'$url);
  72.  
  73.             parse_str($url$item->query);
  74.         }
  75.     }
  76.  
  77.     /**
  78.      * Gets menu items by attribute
  79.      *
  80.      * @param   string   $attributes  The field name
  81.      * @param   string   $values      The value of the field
  82.      * @param   boolean  $firstonly   If true, only returns the first item found
  83.      *
  84.      * @return  array 
  85.      *
  86.      * @since   1.6
  87.      */
  88.     public function getItems($attributes$values$firstonly false)
  89.     {
  90.         $attributes = (array) $attributes;
  91.         $values     = (array) $values;
  92.         $app        JApplication::getInstance('site');
  93.  
  94.         if ($app->isSite())
  95.         {
  96.             // Filter by language if not set
  97.             if (($key array_search('language'$attributes)) === false)
  98.             {
  99.                 if (JLanguageMultilang::isEnabled())
  100.                 {
  101.                     $attributes[]     'language';
  102.                     $values[]         array(JFactory::getLanguage()->getTag()'*');
  103.                 }
  104.             }
  105.             elseif ($values[$key=== null)
  106.             {
  107.                 unset($attributes[$key]);
  108.                 unset($values[$key]);
  109.             }
  110.  
  111.             // Filter by access level if not set
  112.             if (($key array_search('access'$attributes)) === false)
  113.             {
  114.                 $attributes['access';
  115.                 $values[JFactory::getUser()->getAuthorisedViewLevels();
  116.             }
  117.             elseif ($values[$key=== null)
  118.             {
  119.                 unset($attributes[$key]);
  120.                 unset($values[$key]);
  121.             }
  122.         }
  123.  
  124.         // Reset arrays or we get a notice if some values were unset
  125.         $attributes array_values($attributes);
  126.         $values array_values($values);
  127.  
  128.         return parent::getItems($attributes$values$firstonly);
  129.     }
  130.  
  131.     /**
  132.      * Get menu item by id
  133.      *
  134.      * @param   string  $language  The language code.
  135.      *
  136.      * @return  object  The item object
  137.      *
  138.      * @since   1.6
  139.      */
  140.     public function getDefault($language '*')
  141.     {
  142.         if (array_key_exists($language$this->_default&& JApplication::getInstance('site')->getLanguageFilter())
  143.         {
  144.             return $this->_items[$this->_default[$language]];
  145.         }
  146.         elseif (array_key_exists('*'$this->_default))
  147.         {
  148.             return $this->_items[$this->_default['*']];
  149.         }
  150.         else
  151.         {
  152.             return 0;
  153.         }
  154.     }
  155. }

Documentation generated on Tue, 19 Nov 2013 15:13:50 +0100 by phpDocumentor 1.4.3