[ Index ]

PHP Cross Reference of Joomla 2.5.4 DE

title

Body

[close]

/includes/ -> menu.php (source)

   1  <?php
   2  /**
   3   * @copyright    Copyright (C) 2005 - 2012 Open Source Matters, Inc. All rights reserved.
   4   * @license        GNU General Public License version 2 or later; see LICENSE.txt
   5   */
   6  
   7  // No direct access.
   8  defined('_JEXEC') or die;
   9  
  10  /**
  11   * JMenu class
  12   *
  13   * @package        Joomla.Site
  14   * @subpackage    Application
  15   * @since        1.5
  16   */
  17  class JMenuSite extends JMenu
  18  {
  19      /**
  20       * Loads the entire menu table into memory.
  21       *
  22       * @return array
  23       */
  24  	public function load()
  25      {
  26          // Initialise variables.
  27          $db        = JFactory::getDbo();
  28          $app    = JApplication::getInstance('site');
  29          $query    = $db->getQuery(true);
  30  
  31          $query->select('m.id, m.menutype, m.title, m.alias, m.note, m.path AS route, m.link, m.type, m.level, m.language');
  32          $query->select('m.browserNav, m.access, m.params, m.home, m.img, m.template_style_id, m.component_id, m.parent_id');
  33          $query->select('e.element as component');
  34          $query->from('#__menu AS m');
  35          $query->leftJoin('#__extensions AS e ON m.component_id = e.extension_id');
  36          $query->where('m.published = 1');
  37          $query->where('m.parent_id > 0');
  38          $query->where('m.client_id = 0');
  39          $query->order('m.lft');
  40  
  41          // Set the query
  42          $db->setQuery($query);
  43          if (!($this->_items = $db->loadObjectList('id'))) {
  44              JError::raiseWarning(500, JText::sprintf('JERROR_LOADING_MENUS', $db->getErrorMsg()));
  45              return false;
  46          }
  47  
  48          foreach($this->_items as &$item) {
  49              // Get parent information.
  50              $parent_tree = array();
  51              if (isset($this->_items[$item->parent_id])) {
  52                  $parent_tree  = $this->_items[$item->parent_id]->tree;
  53              }
  54  
  55              // Create tree.
  56              $parent_tree[] = $item->id;
  57              $item->tree = $parent_tree;
  58  
  59              // Create the query array.
  60              $url = str_replace('index.php?', '', $item->link);
  61              $url = str_replace('&amp;', '&', $url);
  62  
  63              parse_str($url, $item->query);
  64          }
  65      }
  66  
  67      /**
  68       * Gets menu items by attribute
  69       *
  70       * @param    string    $attributes    The field name
  71       * @param    string    $values        The value of the field
  72       * @param    boolean    $firstonly    If true, only returns the first item found
  73       *
  74       * @return    array
  75       */
  76  	public function getItems($attributes, $values, $firstonly = false)
  77      {
  78          $attributes = (array) $attributes;
  79          $values     = (array) $values;
  80          $app        = JApplication::getInstance('site');
  81  
  82          if ($app->isSite())
  83          {
  84              // Filter by language if not set
  85              if (($key = array_search('language', $attributes)) === false)
  86              {
  87                  if ($app->getLanguageFilter())
  88                  {
  89                      $attributes[]     = 'language';
  90                      $values[]         = array(JFactory::getLanguage()->getTag(), '*');
  91                  }
  92              }
  93              elseif ($values[$key] === null)
  94              {
  95                  unset($attributes[$key]);
  96                  unset($values[$key]);
  97              }
  98  
  99              // Filter by access level if not set
 100              if (($key = array_search('access', $attributes)) === false)
 101              {
 102                  $attributes[] = 'access';
 103                  $values[] = JFactory::getUser()->getAuthorisedViewLevels();
 104              }
 105              elseif ($values[$key] === null)
 106              {
 107                  unset($attributes[$key]);
 108                  unset($values[$key]);
 109              }
 110          }
 111  
 112          return parent::getItems($attributes, $values, $firstonly);
 113      }
 114  
 115      /**
 116       * Get menu item by id
 117       *
 118       * @param    string    $language    The language code.
 119       *
 120       * @return    object    The item object
 121       * @since    1.5
 122       */
 123  	public function getDefault($language = '*')
 124      {
 125          if (array_key_exists($language, $this->_default) && JApplication::getInstance('site')->getLanguageFilter()) {
 126              return $this->_items[$this->_default[$language]];
 127          }
 128          elseif (array_key_exists('*', $this->_default)) {
 129              return $this->_items[$this->_default['*']];
 130          }
 131          else {
 132              return 0;
 133          }
 134      }
 135  
 136  }


Generated: Tue Apr 3 11:40:28 2012 Cross-referenced by PHPXref 0.7.1