PageRenderTime 51ms CodeModel.GetById 19ms RepoModel.GetById 1ms app.codeStats 0ms

/horde-3.3.13/services/portal/sidebar.php

#
PHP | 271 lines | 178 code | 37 blank | 56 comment | 48 complexity | 331d2b5abc2427639f9ef8c3eb8e7a1a MD5 | raw file
Possible License(s): LGPL-2.0
  1. <?php
  2. /**
  3. * $Horde: horde/services/portal/sidebar.php,v 1.4.2.20 2009/01/06 15:27:33 jan Exp $
  4. *
  5. * Copyright 1999-2009 The Horde Project (http://www.horde.org/)
  6. *
  7. * See the enclosed file COPYING for license information (LGPL). If you
  8. * did not receive this file, see http://www.fsf.org/copyleft/lgpl.html.
  9. *
  10. * @author Michael Pawlowsky <mikep@clearskymedia.ca>
  11. * @author Chuck Hagenbuch <chuck@horde.org>
  12. */
  13. /**
  14. * Determine if the current user can see an application.
  15. *
  16. * @param string $app The application name.
  17. * @param array $params The application's parameters.
  18. * @param array $hasChildren Reference to an array to set children flags in.
  19. */
  20. function canSee($app, $params, &$hasChildren)
  21. {
  22. global $registry;
  23. static $cache = array();
  24. static $isAdmin;
  25. static $user;
  26. // If we have a cached value for this application, return it now.
  27. if (isset($cache[$app])) {
  28. return $cache[$app];
  29. }
  30. // Initialize variables we'll keep using in successive calls on
  31. // the first call.
  32. if (is_null($isAdmin)) {
  33. $isAdmin = Auth::isAdmin();
  34. $user = Auth::getAuth();
  35. }
  36. // Check if the current user has permisson to see this application, and if
  37. // the application is active. Headings are visible to everyone (but get
  38. // filtered out later if they have no children). Administrators always see
  39. // all applications except those marked 'inactive'. Anyone with SHOW
  40. // permissions can see an application, but READ is needed to actually use
  41. // the application. You can use this distinction to show applications to
  42. // guests that they need to log in to use. If you don't want them to see
  43. // apps they can't use, then don't give guests SHOW permissions to
  44. // anything.
  45. if (// Don't show applications that aren't installed, even if they're
  46. // configured.
  47. (isset($params['fileroot']) && !is_dir($params['fileroot'])) ||
  48. // Don't show blocks of applications that aren't installed.
  49. ($params['status'] == 'block' &&
  50. !is_dir($registry->get('fileroot', $params['app']))) ||
  51. // Filter out entries that are disabled, hidden or shouldn't show up
  52. // in the menu.
  53. $params['status'] == 'notoolbar' || $params['status'] == 'hidden' ||
  54. $params['status'] == 'inactive') {
  55. $cache[$app] = false;
  56. } elseif (// Headings can always be seen.
  57. ($params['status'] == 'heading') ||
  58. // Admins see everything that makes it to this point.
  59. ($isAdmin ||
  60. // Users who have SHOW permissions to active or block entries
  61. // see them.
  62. ($registry->hasPermission($app, PERMS_SHOW) &&
  63. ($params['status'] == 'active' ||
  64. $params['status'] == 'block')))) {
  65. $cache[$app] = true;
  66. // Note that the parent node, if any, has children.
  67. if (isset($params['menu_parent'])) {
  68. $hasChildren[$params['menu_parent']] = true;
  69. }
  70. } else {
  71. // Catch anything that fell through, and don't show it.
  72. $cache[$app] = false;
  73. }
  74. return $cache[$app];
  75. }
  76. /**
  77. * Builds the menu structure depending on application permissions.
  78. */
  79. function buildMenu()
  80. {
  81. global $conf, $registry;
  82. $apps = array();
  83. $children = array();
  84. foreach ($registry->applications as $app => $params) {
  85. if (canSee($app, $params, $children)) {
  86. $apps[$app] = $params;
  87. }
  88. }
  89. $menu = array();
  90. foreach ($apps as $app => $params) {
  91. // Filter out all headings without children.
  92. if ($params['status'] == 'heading' && empty($children[$app])) {
  93. continue;
  94. }
  95. $menu[$app] = $params;
  96. }
  97. // Add the administration menu if the user is an admin.
  98. if (Auth::isAdmin()) {
  99. $menu['administration'] = array('name' => _("Administration"),
  100. 'icon' => $registry->getImageDir() . '/administration.png',
  101. 'status' => 'heading');
  102. $list = $registry->callByPackage('horde', 'admin_list');
  103. if (!is_a($list, 'PEAR_Error')) {
  104. foreach ($list as $method => $vals) {
  105. $name = Horde::stripAccessKey($vals['name']);
  106. $icon = isset($vals['icon']) ? $registry->getImageDir() . '/' . $vals['icon'] : $registry->get('icon');
  107. $menu['administration_' . $method] = array(
  108. 'name' => $name,
  109. 'icon' => $icon,
  110. 'status' => 'active',
  111. 'menu_parent' => 'administration',
  112. 'url' => Horde::url($registry->applicationWebPath($vals['link'])),
  113. );
  114. }
  115. }
  116. }
  117. if (Horde::showService('options') &&
  118. $conf['prefs']['driver'] != '' && $conf['prefs']['driver'] != 'none') {
  119. $menu['options'] = array('name' => _("Options"),
  120. 'status' => 'active',
  121. 'icon' => $registry->getImageDir() . '/prefs.png');
  122. /* Get a list of configurable applications. */
  123. $prefs_apps = array();
  124. foreach ($registry->applications as $application => $params) {
  125. if ($params['status'] == 'heading' ||
  126. $params['status'] == 'block' ||
  127. !file_exists($registry->get('fileroot', $application) . '/config/prefs.php')) {
  128. continue;
  129. }
  130. /* Check if the current user has permission to see this
  131. * application, and if the application is active.
  132. * Administrators always see all applications. */
  133. if ((Auth::isAdmin() && $params['status'] != 'inactive') ||
  134. ($registry->hasPermission($application) &&
  135. ($params['status'] == 'active'))) {
  136. $prefs_apps[$application] = _($params['name']);
  137. }
  138. }
  139. if (!empty($prefs_apps['horde'])) {
  140. $menu['options_' . 'horde'] = array('name' => _("Global Options"),
  141. 'status' => 'active',
  142. 'menu_parent' => 'options',
  143. 'icon' => $registry->get('icon', 'horde'),
  144. 'url' => Horde::applicationUrl('services/prefs.php?app=horde'));
  145. unset($prefs_apps['horde']);
  146. }
  147. asort($prefs_apps);
  148. foreach ($prefs_apps as $app => $name) {
  149. $menu['options_' . $app] = array('name' => $name,
  150. 'status' => 'active',
  151. 'menu_parent' => 'options',
  152. 'icon' => $registry->get('icon', $app),
  153. 'url' => Horde::applicationUrl('services/prefs.php?app=' . $app));
  154. }
  155. }
  156. if (Auth::isAuthenticated()) {
  157. $menu['logout'] = array('name' => _("Log out"),
  158. 'status' => 'active',
  159. 'icon' => $registry->getImageDir() . '/logout.png',
  160. 'url' => Horde::getServiceLink('logout', 'horde', true),
  161. 'target' => '_parent');
  162. } else {
  163. $menu['login'] = array('name' => _("Log in"),
  164. 'status' => 'active',
  165. 'icon' => $registry->getImageDir() . '/login.png',
  166. 'url' => Horde::getServiceLink('login', 'horde', true, false));
  167. }
  168. return $menu;
  169. }
  170. @define('AUTH_HANDLER', true);
  171. @define('HORDE_BASE', dirname(__FILE__) . '/../..');
  172. require_once HORDE_BASE . '/lib/base.php';
  173. require_once 'Horde/Tree.php';
  174. require_once 'Horde/Block.php';
  175. require_once 'Horde/Block/Collection.php';
  176. if (!Auth::getAuth() && !$conf['menu']['always']) {
  177. Horde::authenticationFailureRedirect();
  178. }
  179. $is_mozbar = (bool)Util::getFormData('mozbar');
  180. // Set up the tree.
  181. $tree = &Horde_Tree::singleton('horde_menu', 'javascript');
  182. $tree->setOption(array('target' => $is_mozbar ? '_content' : 'horde_main'));
  183. $menu = buildMenu();
  184. foreach ($menu as $app => $params) {
  185. if ($params['status'] == 'block') {
  186. if ($registry->get('status', $params['app']) == 'inactive') {
  187. continue;
  188. }
  189. $block = &Horde_Block_Collection::getBlock($params['app'], $params['blockname']);
  190. if (is_a($block, 'PEAR_Error')) {
  191. Horde::logMessage($block, __FILE__, __LINE__, PEAR_LOG_ERR);
  192. continue;
  193. }
  194. $block->buildTree($tree, 0,
  195. isset($params['menu_parent']) ? $params['menu_parent'] : null);
  196. } else {
  197. // Need to run the name through gettext since the user's
  198. // locale may not have been loaded when registry.php was
  199. // parsed.
  200. $name = _($params['name']);
  201. // Headings have no webroot; they're just containers for other
  202. // menu items.
  203. if (isset($params['url'])) {
  204. $url = $params['url'];
  205. } elseif ($params['status'] == 'heading' || !isset($params['webroot'])) {
  206. $url = null;
  207. } else {
  208. $url = Horde::url($params['webroot'] . '/' . (isset($params['initial_page']) ? $params['initial_page'] : ''));
  209. }
  210. $node_params = array('url' => $url,
  211. 'target' => isset($params['target']) ? $params['target'] : null,
  212. 'icon' => isset($params['icon']) ? $params['icon'] : $registry->get('icon', $app),
  213. 'icondir' => '',
  214. );
  215. $tree->addNode($app, !empty($params['menu_parent']) ? $params['menu_parent'] : null, $name, 0, false, $node_params);
  216. }
  217. }
  218. // If we're serving a request to the JS update client, just render the
  219. // updated node javascript.
  220. if (Util::getFormData('httpclient')) {
  221. header('Content-Type: text/javascript; charset=' . NLS::getCharset());
  222. echo $tree->renderNodeDefinitions();
  223. exit;
  224. }
  225. $rtl = isset($nls['rtl'][$language]);
  226. $htmlId = 'sidebar-frame';
  227. $bodyClass = 'sidebar';
  228. if ($browser->hasQuirk('scrollbar_in_way')) {
  229. $bodyClass .= ' scrollbar-quirk';
  230. }
  231. Horde::addScriptFile('prototype.js', 'horde', true);
  232. Horde::addScriptFile('sidebar.js', 'horde', true);
  233. require HORDE_TEMPLATES . '/common-header.inc';
  234. require HORDE_TEMPLATES . '/portal/sidebar.inc';