[ Index ]

PHP Cross Reference of Joomla 2.5.4 DE

title

Body

[close]

/administrator/components/com_menus/helpers/ -> menus.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   * Menus component helper.
  12   *
  13   * @package        Joomla.Administrator
  14   * @subpackage    com_menus
  15   * @since        1.6
  16   */
  17  class MenusHelper
  18  {
  19      /**
  20       * Defines the valid request variables for the reverse lookup.
  21       */
  22      protected static $_filter = array('option', 'view', 'layout');
  23  
  24      /**
  25       * Configure the Linkbar.
  26       *
  27       * @param    string    The name of the active view.
  28       */
  29  	public static function addSubmenu($vName)
  30      {
  31          JSubMenuHelper::addEntry(
  32              JText::_('COM_MENUS_SUBMENU_MENUS'),
  33              'index.php?option=com_menus&view=menus',
  34              $vName == 'menus'
  35          );
  36          JSubMenuHelper::addEntry(
  37              JText::_('COM_MENUS_SUBMENU_ITEMS'),
  38              'index.php?option=com_menus&view=items',
  39              $vName == 'items'
  40          );
  41      }
  42  
  43      /**
  44       * Gets a list of the actions that can be performed.
  45       *
  46       * @param    int        The menu ID.
  47       *
  48       * @return    JObject
  49       * @since    1.6
  50       */
  51  	public static function getActions($parentId = 0)
  52      {
  53          $user    = JFactory::getUser();
  54          $result    = new JObject;
  55  
  56          if (empty($parentId)) {
  57              $assetName = 'com_menus';
  58          } else {
  59              $assetName = 'com_menus.item.'.(int) $parentId;
  60          }
  61  
  62          $actions = array(
  63              'core.admin', 'core.manage', 'core.create', 'core.edit', 'core.edit.state', 'core.delete'
  64          );
  65  
  66          foreach ($actions as $action) {
  67              $result->set($action,    $user->authorise($action, $assetName));
  68          }
  69  
  70          return $result;
  71      }
  72  
  73      /**
  74       * Gets a standard form of a link for lookups.
  75       *
  76       * @param    mixed    A link string or array of request variables.
  77       *
  78       * @return    mixed    A link in standard option-view-layout form, or false if the supplied response is invalid.
  79       */
  80  	public static function getLinkKey($request)
  81      {
  82          if (empty($request)) {
  83              return false;
  84          }
  85  
  86          // Check if the link is in the form of index.php?...
  87          if (is_string($request))
  88          {
  89              $args = array();
  90              if (strpos($request, 'index.php') === 0) {
  91                  parse_str(parse_url(htmlspecialchars_decode($request), PHP_URL_QUERY), $args);
  92              }
  93              else {
  94                  parse_str($request, $args);
  95              }
  96              $request = $args;
  97          }
  98  
  99          // Only take the option, view and layout parts.
 100          foreach ($request as $name => $value)
 101          {
 102              if (!in_array($name, self::$_filter))
 103              {
 104                  // Remove the variables we want to ignore.
 105                  unset($request[$name]);
 106              }
 107          }
 108  
 109          ksort($request);
 110  
 111          return 'index.php?'.http_build_query($request, '', '&');
 112      }
 113  
 114      /**
 115       * Get the menu list for create a menu module
 116       *
 117       * @return        array    The menu array list
 118       * @since        1.6
 119       */
 120  	public static function getMenuTypes()
 121      {
 122          $db = JFactory::getDbo();
 123          $db->setQuery('SELECT a.menutype FROM #__menu_types AS a');
 124          return $db->loadColumn();
 125      }
 126  
 127      /**
 128       * Get a list of menu links for one or all menus.
 129       *
 130       * @param    string    An option menu to filter the list on, otherwise all menu links are returned as a grouped array.
 131       * @param    int        An optional parent ID to pivot results around.
 132       * @param    int        An optional mode. If parent ID is set and mode=2, the parent and children are excluded from the list.
 133       * @param    array    An optional array of states
 134       */
 135  	public static function getMenuLinks($menuType = null, $parentId = 0, $mode = 0, $published=array(), $languages=array())
 136      {
 137          $db = JFactory::getDbo();
 138          $query = $db->getQuery(true);
 139  
 140          $query->select('a.id AS value, a.title AS text, a.level, a.menutype, a.type, a.template_style_id, a.checked_out');
 141          $query->from('#__menu AS a');
 142          $query->join('LEFT', $db->quoteName('#__menu').' AS b ON a.lft > b.lft AND a.rgt < b.rgt');
 143  
 144          // Filter by the type
 145          if ($menuType) {
 146              $query->where('(a.menutype = '.$db->quote($menuType).' OR a.parent_id = 0)');
 147          }
 148  
 149          if ($parentId) {
 150              if ($mode == 2) {
 151                  // Prevent the parent and children from showing.
 152                  $query->join('LEFT', '#__menu AS p ON p.id = '.(int) $parentId);
 153                  $query->where('(a.lft <= p.lft OR a.rgt >= p.rgt)');
 154              }
 155          }
 156  
 157          if (!empty($languages)) {
 158              if (is_array($languages)) {
 159                  $languages = '(' . implode(',', array_map(array($db, 'quote'), $languages)) . ')';
 160              }
 161              $query->where('a.language IN ' . $languages);
 162          }
 163  
 164          if (!empty($published)) {
 165              if (is_array($published)) $published = '(' . implode(',', $published) .')';
 166              $query->where('a.published IN ' . $published);
 167          }
 168  
 169          $query->where('a.published != -2');
 170          $query->group('a.id, a.title, a.level, a.menutype, a.type, a.template_style_id, a.checked_out, a.lft');
 171          $query->order('a.lft ASC');
 172  
 173          // Get the options.
 174          $db->setQuery($query);
 175  
 176          $links = $db->loadObjectList();
 177  
 178          // Check for a database error.
 179          if ($error = $db->getErrorMsg()) {
 180              JError::raiseWarning(500, $error);
 181              return false;
 182          }
 183  
 184          // Pad the option text with spaces using depth level as a multiplier.
 185          foreach ($links as &$link) {
 186              $link->text = str_repeat('- ', $link->level).$link->text;
 187          }
 188  
 189          if (empty($menuType)) {
 190              // If the menutype is empty, group the items by menutype.
 191              $query->clear();
 192              $query->select('*');
 193              $query->from('#__menu_types');
 194              $query->where('menutype <> '.$db->quote(''));
 195              $query->order('title, menutype');
 196              $db->setQuery($query);
 197  
 198              $menuTypes = $db->loadObjectList();
 199  
 200              // Check for a database error.
 201              if ($error = $db->getErrorMsg()) {
 202                  JError::raiseWarning(500, $error);
 203                  return false;
 204              }
 205  
 206              // Create a reverse lookup and aggregate the links.
 207              $rlu = array();
 208              foreach ($menuTypes as &$type) {
 209                  $rlu[$type->menutype] = &$type;
 210                  $type->links = array();
 211              }
 212  
 213              // Loop through the list of menu links.
 214              foreach ($links as &$link) {
 215                  if (isset($rlu[$link->menutype])) {
 216                      $rlu[$link->menutype]->links[] = &$link;
 217  
 218                      // Cleanup garbage.
 219                      unset($link->menutype);
 220                  }
 221              }
 222  
 223              return $menuTypes;
 224          } else {
 225              return $links;
 226          }
 227      }
 228  	static public function getAssociations($pk)
 229      {
 230          $associations = array();
 231          $db = JFactory::getDbo();
 232          $query = $db->getQuery(true);
 233          $query->from('#__menu as m');
 234          $query->innerJoin('#__associations as a ON a.id=m.id AND a.context='.$db->quote('com_menus.item'));
 235          $query->innerJoin('#__associations as a2 ON a.key=a2.key');
 236          $query->innerJoin('#__menu as m2 ON a2.id=m2.id');
 237          $query->where('m.id='.(int)$pk);
 238          $query->select('m2.language, m2.id');
 239          $db->setQuery($query);
 240          $menuitems = $db->loadObjectList('language');
 241          // Check for a database error.
 242          if ($error = $db->getErrorMsg()) {
 243              JError::raiseWarning(500, $error);
 244              return false;
 245          }
 246          foreach ($menuitems as $tag=>$item) {
 247              $associations[$tag] = $item->id;
 248          }
 249          return $associations;
 250      }
 251  }


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