Source for file helper.php

Documentation is available at helper.php

  1. <?php
  2. /**
  3.  * @package     Joomla.Administrator
  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.Administrator
  16.  * @subpackage  mod_menu
  17.  * @since       1.5
  18.  */
  19. abstract class ModMenuHelper
  20. {
  21.     /**
  22.      * Get a list of the available menus.
  23.      *
  24.      * @return  array  An array of the available menus (from the menu types table).
  25.      *
  26.      * @since   1.6
  27.      */
  28.     public static function getMenus()
  29.     {
  30.         $db        JFactory::getDbo();
  31.         $query    $db->getQuery(true)
  32.             ->select('a.*, SUM(b.home) AS home')
  33.             ->from('#__menu_types AS a')
  34.             ->join('LEFT''#__menu AS b ON b.menutype = a.menutype AND b.home != 0')
  35.             ->select('b.language')
  36.             ->join('LEFT''#__languages AS l ON l.lang_code = language')
  37.             ->select('l.image')
  38.             ->select('l.sef')
  39.             ->select('l.title_native')
  40.             ->where('(b.client_id = 0 OR b.client_id IS NULL)');
  41.  
  42.         // Sqlsrv change
  43.         $query->group('a.id, a.menutype, a.description, a.title, b.menutype,b.language,l.image,l.sef,l.title_native');
  44.  
  45.         $db->setQuery($query);
  46.  
  47.         $result $db->loadObjectList();
  48.  
  49.         return $result;
  50.     }
  51.  
  52.     /**
  53.      * Get a list of the authorised, non-special components to display in the components menu.
  54.      *
  55.      * @param   boolean  $authCheck      An optional switch to turn off the auth check (to support custom layouts 'grey out' behaviour).
  56.      *
  57.      * @return  array  A nest array of component objects and submenus
  58.      *
  59.      * @since   1.6
  60.      */
  61.     public static function getComponents($authCheck true)
  62.     {
  63.         $lang    JFactory::getLanguage();
  64.         $user    JFactory::getUser();
  65.         $db        JFactory::getDbo();
  66.         $query    $db->getQuery(true);
  67.         $result    array();
  68.  
  69.         // Prepare the query.
  70.         $query->select('m.id, m.title, m.alias, m.link, m.parent_id, m.img, e.element')
  71.             ->from('#__menu AS m');
  72.  
  73.         // Filter on the enabled states.
  74.         $query->join('LEFT''#__extensions AS e ON m.component_id = e.extension_id')
  75.             ->where('m.client_id = 1')
  76.             ->where('e.enabled = 1')
  77.             ->where('m.id > 1');
  78.  
  79.         // Order by lft.
  80.         $query->order('m.lft');
  81.  
  82.         $db->setQuery($query);
  83.  
  84.         // Component list
  85.         $components    $db->loadObjectList();
  86.  
  87.         // Parse the list of extensions.
  88.         foreach ($components as &$component)
  89.         {
  90.             // Trim the menu link.
  91.             $component->link trim($component->link);
  92.  
  93.             if ($component->parent_id == 1)
  94.             {
  95.                 // Only add this top level if it is authorised and enabled.
  96.                 if ($authCheck == false || ($authCheck && $user->authorise('core.manage'$component->element)))
  97.                 {
  98.                     // Root level.
  99.                     $result[$component->id$component;
  100.  
  101.                     if (!isset($result[$component->id]->submenu))
  102.                     {
  103.                         $result[$component->id]->submenu array();
  104.                     }
  105.  
  106.                     // If the root menu link is empty, add it in.
  107.                     if (empty($component->link))
  108.                     {
  109.                         $component->link 'index.php?option=' $component->element;
  110.                     }
  111.  
  112.                     if (!empty($component->element))
  113.                     {
  114.                         // Load the core file then
  115.                         // Load extension-local file.
  116.                         $lang->load($component->element '.sys'JPATH_BASEnullfalsetrue)
  117.                     ||    $lang->load($component->element '.sys'JPATH_ADMINISTRATOR '/components/' $component->elementnullfalsetrue);
  118.                     }
  119.  
  120.                     $component->text $lang->hasKey($component->titleJText::_($component->title$component->alias;
  121.                 }
  122.             }
  123.             else
  124.             {
  125.                 // Sub-menu level.
  126.                 if (isset($result[$component->parent_id]))
  127.                 {
  128.                     // Add the submenu link if it is defined.
  129.                     if (isset($result[$component->parent_id]->submenu&& !empty($component->link))
  130.                     {
  131.                         $component->text $lang->hasKey($component->titleJText::_($component->title$component->alias;
  132.                         $result[$component->parent_id]->submenu[&$component;
  133.                     }
  134.                 }
  135.             }
  136.         }
  137.  
  138.         $result JArrayHelper::sortObjects($result'text'1truetrue);
  139.  
  140.         return $result;
  141.     }
  142. }

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