PageRenderTime 48ms CodeModel.GetById 25ms RepoModel.GetById 0ms app.codeStats 0ms

/administrator/modules/mod_menu/helper.php

https://github.com/joebushi/joomla
PHP | 128 lines | 71 code | 19 blank | 38 comment | 12 complexity | 5f1e31a37da1c2c753872f4036250de6 MD5 | raw file
Possible License(s): LGPL-2.1, Apache-2.0
  1. <?php
  2. /**
  3. * @version $Id:mod_menu.php 2463 2006-02-18 06:05:38Z webImagery $
  4. * @copyright Copyright (C) 2005 - 2010 Open Source Matters, Inc. All rights reserved.
  5. * @license GNU General Public License version 2 or later; see LICENSE.txt
  6. */
  7. // no direct access
  8. defined('_JEXEC') or die;
  9. // Include dependancies.
  10. jimport('joomla.database.query');
  11. /**
  12. * @package Joomla.Administrator
  13. * @subpackage mod_menu
  14. */
  15. abstract class ModMenuHelper
  16. {
  17. /**
  18. * Get a list of the available menus.
  19. *
  20. * @return array An array of the available menus (from the menu types table).
  21. */
  22. public static function getMenus()
  23. {
  24. $db = &JFactory::getDbo();
  25. $query = new JQuery;
  26. $query->select('a.*, SUM(b.home) AS home');
  27. $query->from('#__menu_types AS a');
  28. $query->leftJoin('#__menu AS b ON b.menutype = a.menutype');
  29. $query->group('a.id');
  30. $db->setQuery($query);
  31. $result = $db->loadObjectList();
  32. return $result;
  33. }
  34. /**
  35. * Get a list of the authorised, non-special components to display in the components menu.
  36. *
  37. * @param array An optional array of components to exclude from the list.
  38. * @param boolean An optional switch to turn off the auth check (to support custom layouts 'grey out' behaviour).
  39. *
  40. * @return array A nest array of component objects and submenus
  41. */
  42. function getComponents($authCheck = true)
  43. {
  44. // Initialise variables.
  45. $lang = &JFactory::getLanguage();
  46. $user = &JFactory::getUser();
  47. $db = &JFactory::getDbo();
  48. $query = new JQuery;
  49. $result = array();
  50. $langs = array();
  51. // Prepare the query.
  52. $query->select('m.id, m.title, m.alias, m.link, m.parent_id, m.img, e.element');
  53. $query->from('#__menu AS m');
  54. // Filter on the enabled states.
  55. $query->leftJoin('#__extensions AS e ON m.component_id = e.extension_id');
  56. $query->where('m.menutype = "_adminmenu"');
  57. $query->where('e.enabled = 1');
  58. $query->where('m.id > 1');
  59. // Order by lft.
  60. $query->order('m.lft');
  61. $db->setQuery($query);
  62. $components = $db->loadObjectList(); // component list
  63. // Parse the list of extensions.
  64. foreach ($components as &$component)
  65. {
  66. // Trim the menu link.
  67. $component->link = trim($component->link);
  68. if ($component->parent_id == 1)
  69. {
  70. // Only add this top level if it is authorised and enabled.
  71. if ($authCheck == false || ($authCheck && $user->authorize('core.manage', $component->element)))
  72. {
  73. // Root level.
  74. $result[$component->id] = $component;
  75. if (!isset($result[$component->id]->submenu)) {
  76. $result[$component->id]->submenu = array();
  77. }
  78. // If the root menu link is empty, add it in.
  79. if (empty($component->link)) {
  80. $component->link = 'index.php?option='.$component->element;
  81. }
  82. if (!empty($component->element)) {
  83. $langs[$component->element.'.menu'] = true;
  84. }
  85. }
  86. }
  87. else
  88. {
  89. // Sub-menu level.
  90. if (isset($result[$component->parent_id]))
  91. {
  92. // Add the submenu link if it is defined.
  93. if (isset($result[$component->parent_id]->submenu) && !empty($component->link)) {
  94. $result[$component->parent_id]->submenu[] = &$component;
  95. }
  96. }
  97. }
  98. }
  99. // Load additional language files.
  100. foreach (array_keys($langs) as $langName)
  101. {
  102. // Load extension-local file.
  103. $lang->load('menu', JPATH_ADMINISTRATOR.'/components/'.str_replace('.menu', '', $langName));
  104. // Load the core file.
  105. $lang->load($langName);
  106. }
  107. return $result;
  108. }
  109. }