PageRenderTime 45ms CodeModel.GetById 19ms RepoModel.GetById 0ms app.codeStats 0ms

/aamenu/code/trunk/administrator/modules/mod_aamenu/helper.php

https://bitbucket.org/eddieajau/the-art-of-joomla-archive
PHP | 366 lines | 255 code | 47 blank | 64 comment | 36 complexity | 6199543598c4ae0b7cff0b81389494db MD5 | raw file
  1. <?php
  2. /**
  3. * @version $Id: helper.php 269 2010-09-01 00:23:48Z eddieajau $
  4. * @copyright Copyright (C) 2005 - 2008 Open Source Matters. All rights reserved.
  5. * @copyright Copyright (C) 2009 New Life in IT Pty Ltd. All rights reserved.
  6. * @license GNU General Public License <http://www.gnu.org/copyleft/gpl.html>
  7. * @link http://www.theartofjoomla.com
  8. */
  9. // no direct access
  10. defined('_JEXEC') or die;
  11. require_once(dirname(__FILE__).DS.'menu.php');
  12. /**
  13. * @package TAOJ.AAMenu
  14. * @subpackage mod_aamenu
  15. */
  16. class modAAMenuHelper
  17. {
  18. function _addComponent(&$row, &$subs, &$lang, &$menu)
  19. {
  20. $text = $lang->hasKey($row->option) ? JText::_($row->option) : $row->name;
  21. $link = $row->admin_menu_link ? "index.php?$row->admin_menu_link" : "index.php?option=$row->option";
  22. if (array_key_exists($row->id, $subs)) {
  23. $menu->addChild(new JMenuNode2($text, $link, $row->admin_menu_img), true);
  24. foreach ($subs[$row->id] as $sub) {
  25. $key = $row->option.'.'.$sub->name;
  26. $text = $lang->hasKey($key) ? JText::_($key) : $sub->name;
  27. $link = $sub->admin_menu_link ? "index.php?$sub->admin_menu_link" : null;
  28. $menu->addChild(new JMenuNode2($text, $link, $sub->admin_menu_img));
  29. }
  30. $menu->getParent();
  31. } else {
  32. $menu->addChild(new JMenuNode2($text, $link, $row->admin_menu_img));
  33. }
  34. }
  35. /**
  36. * Show the menu
  37. * @param string The current user type
  38. */
  39. function buildMenu()
  40. {
  41. global $mainframe;
  42. $lang = & JFactory::getLanguage();
  43. $user = & JFactory::getUser();
  44. $db = & JFactory::getDBO();
  45. $usertype = $user->get('usertype');
  46. // Do some tag preprocessing
  47. $config = JComponentHelper::getParams('com_aamenu');
  48. $tags = explode("\n", $config->get('tags'));
  49. $query = 'SELECT a.*, c.name' .
  50. ' FROM #__taoj_aamenu_tags AS a' .
  51. ' INNER JOIN #__components AS c ON c.id = a.component_id' .
  52. ' WHERE tag <> '.$db->Quote('') .
  53. ' ORDER BY a.ordering, c.name';
  54. $db->setQuery($query);
  55. $allTags = $db->loadObjectList('component_id');
  56. $rlu = array();
  57. $custom = array();
  58. foreach ($allTags as $k => $v)
  59. {
  60. $rlu[$v->tag][] = &$allTags[$k];
  61. $custom[] = $v->component_id;
  62. }
  63. // cache some acl checks
  64. $canCheckin = $user->authorize('com_checkin', 'manage');
  65. $canConfig = $user->authorize('com_config', 'manage');
  66. $manageTemplates = $user->authorize('com_templates', 'manage');
  67. $manageTrash = $user->authorize('com_trash', 'manage');
  68. $manageMenuMan = $user->authorize('com_menus', 'manage');
  69. $manageLanguages = $user->authorize('com_languages', 'manage');
  70. $installModules = $user->authorize('com_installer', 'module');
  71. $editAllModules = $user->authorize('com_modules', 'manage');
  72. $installPlugins = $user->authorize('com_installer', 'plugin');
  73. $editAllPlugins = $user->authorize('com_plugins', 'manage');
  74. $installComponents = $user->authorize('com_installer', 'component');
  75. $editAllComponents = $user->authorize('com_components', 'manage');
  76. $canMassMail = $user->authorize('com_massmail', 'manage');
  77. $canManageUsers = $user->authorize('com_users', 'manage');
  78. // Menu Types
  79. require_once(JPATH_ADMINISTRATOR.DS.'components'.DS.'com_menus'.DS.'helpers'.DS.'helper.php');
  80. $menuTypes = MenusHelper::getMenuTypelist();
  81. /*
  82. * Get the menu object
  83. */
  84. $menu = new JAdminCSSMenu2;
  85. /*
  86. * Site SubMenu
  87. */
  88. $menu->addChild(new JMenuNode2(JText::_('Site')), true);
  89. $menu->addChild(new JMenuNode2(JText::_('Control Panel'), 'index.php', 'class:cpanel'));
  90. $menu->addSeparator();
  91. if ($canManageUsers) {
  92. $menu->addChild(new JMenuNode2(JText::_('User Manager'), 'index.php?option=com_users&task=view', 'class:user'));
  93. }
  94. $menu->addChild(new JMenuNode2(JText::_('Media Manager'), 'index.php?option=com_media', 'class:media'));
  95. $menu->addSeparator();
  96. if ($canConfig) {
  97. $menu->addChild(new JMenuNode2(JText::_('Configuration'), 'index.php?option=com_config', 'class:config'));
  98. $menu->addSeparator();
  99. }
  100. $menu->addChild(new JMenuNode2(JText::_('Logout'), 'index.php?option=com_login&task=logout', 'class:logout'));
  101. $menu->getParent();
  102. /*
  103. * Menus SubMenu
  104. */
  105. $menu->addChild(new JMenuNode2(JText::_('Menus')), true);
  106. if ($manageMenuMan) {
  107. $menu->addChild(new JMenuNode2(JText::_('Menu Manager'), 'index.php?option=com_menus', 'class:menu'));
  108. }
  109. if ($manageTrash) {
  110. $menu->addChild(new JMenuNode2(JText::_('Menu Trash'), 'index.php?option=com_trash&task=viewMenu', 'class:trash'));
  111. }
  112. if($manageTrash || $manageMenuMan) {
  113. $menu->addSeparator();
  114. }
  115. /*
  116. * SPLIT HR
  117. */
  118. if (count($menuTypes)) {
  119. foreach ($menuTypes as $menuType) {
  120. $menu->addChild(
  121. new JMenuNode2(
  122. $menuType->title.($menuType->home ? ' *' : ''),
  123. 'index.php?option=com_menus&task=view&menutype='
  124. .$menuType->menutype,
  125. 'class:menu'
  126. )
  127. );
  128. }
  129. }
  130. $menu->getParent();
  131. /*
  132. * Content SubMenu
  133. */
  134. $menu->addChild(new JMenuNode2(JText::_('Content')), true);
  135. $menu->addChild(new JMenuNode2(JText::_('Article Manager'), 'index.php?option=com_content', 'class:article'));
  136. if ($manageTrash) {
  137. $menu->addChild(new JMenuNode2(JText::_('Article Trash'), 'index.php?option=com_trash&task=viewContent', 'class:trash'));
  138. }
  139. $menu->addSeparator();
  140. $menu->addChild(new JMenuNode2(JText::_('Section Manager'), 'index.php?option=com_sections&scope=content', 'class:section'));
  141. $menu->addChild(new JMenuNode2(JText::_('Category Manager'), 'index.php?option=com_categories&section=com_content', 'class:category'));
  142. $menu->addSeparator();
  143. $menu->addChild(new JMenuNode2(JText::_('Frontpage Manager'), 'index.php?option=com_frontpage', 'class:frontpage'));
  144. $menu->getParent();
  145. /*
  146. * Components SubMenu
  147. */
  148. if ($editAllComponents)
  149. {
  150. $menu->addChild(new JMenuNode2(JText::_('Components')), true);
  151. $query = 'SELECT *' .
  152. ' FROM #__components' .
  153. ' WHERE '.$db->NameQuote('option').' <> "com_frontpage"' .
  154. ' AND '.$db->NameQuote('option').' <> "com_media"' .
  155. ' AND enabled = 1' .
  156. ' ORDER BY ordering, name';
  157. $db->setQuery($query);
  158. $comps = $db->loadObjectList('id'); // component list
  159. $subs = array(); // sub menus
  160. $langs = array(); // additional language files to load
  161. // first pass to collect sub-menu items
  162. foreach ($comps as $row)
  163. {
  164. if ($row->parent)
  165. {
  166. if (!array_key_exists($row->parent, $subs)) {
  167. $subs[$row->parent] = array ();
  168. }
  169. $subs[$row->parent][] = $row;
  170. $langs[$row->option.'.menu'] = true;
  171. } elseif (trim($row->admin_menu_link)) {
  172. $langs[$row->option.'.menu'] = true;
  173. }
  174. }
  175. // Load additional language files
  176. if (array_key_exists('.menu', $langs)) {
  177. unset($langs['.menu']);
  178. }
  179. foreach ($langs as $lang_name => $nothing) {
  180. $lang->load($lang_name);
  181. }
  182. foreach ($comps as $row)
  183. {
  184. if ($editAllComponents | $user->authorize('administration', 'edit', 'components', $row->option))
  185. {
  186. if ($row->parent == 0 && (trim($row->admin_menu_link) || array_key_exists($row->id, $subs)))
  187. {
  188. if (!in_array($row->id, $custom))
  189. {
  190. modAAMenuHelper::_addComponent($row, $subs, $lang, $menu);
  191. }
  192. }
  193. }
  194. }
  195. $menu->getParent();
  196. //
  197. // Custom menus
  198. //
  199. if (count($tags))
  200. {
  201. foreach ($tags as $tag)
  202. {
  203. $reParent = false;
  204. if (isset($rlu[$tag]))
  205. {
  206. $menu->addChild(new JMenuNode2(JText::_($tag)), true);
  207. foreach ($rlu[$tag] as $comp)
  208. {
  209. $row = &$comps[$comp->component_id];
  210. modAAMenuHelper::_addComponent($row, $subs, $lang, $menu);
  211. $reParent = true;
  212. }
  213. }
  214. if ($reParent)
  215. {
  216. $menu->getParent();
  217. }
  218. }
  219. }
  220. }
  221. /*
  222. * Extensions SubMenu
  223. */
  224. if ($installModules)
  225. {
  226. $menu->addChild(new JMenuNode2(JText::_('Extensions')), true);
  227. $menu->addChild(new JMenuNode2(JText::_('Install/Uninstall'), 'index.php?option=com_installer', 'class:install'));
  228. $menu->addSeparator();
  229. if ($editAllModules) {
  230. $menu->addChild(new JMenuNode2(JText::_('Module Manager'), 'index.php?option=com_modules', 'class:module'));
  231. }
  232. if ($editAllPlugins) {
  233. $menu->addChild(new JMenuNode2(JText::_('Plugin Manager'), 'index.php?option=com_plugins', 'class:plugin'));
  234. }
  235. if ($manageTemplates) {
  236. $menu->addChild(new JMenuNode2(JText::_('Template Manager'), 'index.php?option=com_templates', 'class:themes'));
  237. }
  238. if ($manageLanguages) {
  239. $menu->addChild(new JMenuNode2(JText::_('Language Manager'), 'index.php?option=com_languages', 'class:language'));
  240. }
  241. $menu->getParent();
  242. }
  243. /*
  244. * System SubMenu
  245. */
  246. if ($canConfig || $canCheckin)
  247. {
  248. $menu->addChild(new JMenuNode2(JText::_('Tools')), true);
  249. if ($canConfig) {
  250. $menu->addChild(new JMenuNode2(JText::_('Read Messages'), 'index.php?option=com_messages', 'class:messages'));
  251. $menu->addChild(new JMenuNode2(JText::_('Write Message'), 'index.php?option=com_messages&task=add', 'class:messages'));
  252. $menu->addSeparator();
  253. }
  254. if ($canMassMail) {
  255. $menu->addChild(new JMenuNode2(JText::_('Mass Mail'), 'index.php?option=com_massmail', 'class:massmail'));
  256. $menu->addSeparator();
  257. }
  258. if ($canCheckin) {
  259. $menu->addChild(new JMenuNode2(JText::_('Global Checkin'), 'index.php?option=com_checkin', 'class:checkin'));
  260. $menu->addSeparator();
  261. }
  262. $menu->addChild(new JMenuNode2(JText::_('Clean Cache'), 'index.php?option=com_cache', 'class:config'));
  263. $menu->addChild(new JMenuNode2(JText::_('Purge Expired Cache'), 'index.php?option=com_cache&task=purgeadmin', 'class:config'));
  264. $menu->getParent();
  265. }
  266. /*
  267. * Help SubMenu
  268. */
  269. $menu->addChild(new JMenuNode2(JText::_('Help')), true);
  270. $menu->addChild(new JMenuNode2(JText::_('Joomla! Help'), 'index.php?option=com_admin&task=help', 'class:help'));
  271. $menu->addChild(new JMenuNode2(JText::_('System Info'), 'index.php?option=com_admin&task=sysinfo', 'class:info'));
  272. $menu->getParent();
  273. $menu->renderMenu('menu', '');
  274. }
  275. /**
  276. * Show an disbaled version of the menu, used in edit pages
  277. *
  278. * @param string The current user type
  279. */
  280. function buildDisabledMenu()
  281. {
  282. $lang =& JFactory::getLanguage();
  283. $user =& JFactory::getUser();
  284. $usertype = $user->get('usertype');
  285. $canConfig = $user->authorize('com_config', 'manage');
  286. $installModules = $user->authorize('com_installer', 'module');
  287. $editAllModules = $user->authorize('com_modules', 'manage');
  288. $installPlugins = $user->authorize('com_installer', 'plugin');
  289. $editAllPlugins = $user->authorize('com_plugins', 'manage');
  290. $installComponents = $user->authorize('com_installer', 'component');
  291. $editAllComponents = $user->authorize('com_components', 'manage');
  292. $canMassMail = $user->authorize('com_massmail', 'manage');
  293. $canManageUsers = $user->authorize('com_users', 'manage');
  294. $text = JText::_('Menu inactive for this Page', true);
  295. // Get the menu object
  296. $menu = new JAdminCSSMenu2;
  297. // Site SubMenu
  298. $menu->addChild(new JMenuNode2(JText::_('Site'), null, 'disabled'));
  299. // Menus SubMenu
  300. $menu->addChild(new JMenuNode2(JText::_('Menus'), null, 'disabled'));
  301. // Content SubMenu
  302. $menu->addChild(new JMenuNode2(JText::_('Content'), null, 'disabled'));
  303. // Components SubMenu
  304. if ($installComponents) {
  305. $menu->addChild(new JMenuNode2(JText::_('Components'), null, 'disabled'));
  306. }
  307. // Extensions SubMenu
  308. if ($installModules) {
  309. $menu->addChild(new JMenuNode2(JText::_('Extensions'), null, 'disabled'));
  310. }
  311. // System SubMenu
  312. if ($canConfig) {
  313. $menu->addChild(new JMenuNode2(JText::_('Tools'), null, 'disabled'));
  314. }
  315. // Help SubMenu
  316. $menu->addChild(new JMenuNode2(JText::_('Help'), null, 'disabled'));
  317. $menu->renderMenu('menu', 'disabled');
  318. }
  319. }