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

/administrator/modules/mod_menu/helper.php

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