3
define('HORDE_MENU_POS_LAST', 999);
5
define('HORDE_MENU_MASK_NONE', 0);
6
define('HORDE_MENU_MASK_HELP', 1);
7
define('HORDE_MENU_MASK_LOGIN', 2);
8
define('HORDE_MENU_MASK_PREFS', 4);
9
define('HORDE_MENU_MASK_PROBLEM', 8);
10
define('HORDE_MENU_MASK_ALL', 15);
13
* The Menu:: class provides standardized methods for creating menus in
16
* $Horde: framework/Horde/Horde/Menu.php,v 1.35.2.3 2005/01/03 17:48:53 jan Exp $
18
* Copyright 1999-2005 Chuck Hagenbuch <chuck@horde.org>
19
* Copyright 1999-2005 Jon Parise <jon@horde.org>
21
* See the enclosed file COPYING for license information (LGPL). If you
22
* did not receive this file, see http://www.fsf.org/copyleft/lgpl.html.
24
* @author Chuck Hagenbuch <chuck@horde.org>
25
* @author Jon Parise <jon@horde.org>
27
* @package Horde_Framework
39
* Mask defining what general Horde links are shown in this Menu.
50
function Menu($mask = HORDE_MENU_MASK_ALL)
55
/* Location of the menufile. */
56
$this->_menufile = $GLOBALS['registry']->get('fileroot') . '/config/menu.php';
60
* Add an item to the menu array.
62
* @param string $url String containing the value for the hyperlink.
63
* @param string $text String containing the label for this menu
65
* @param string $icon String containing the filename of the image
66
* icon to display for this menu item.
67
* @param string $icon_path If the icon lives in a non-default directory,
69
* @param string $target If the link needs to open in another frame or
70
* window, what is its name?
71
* @param string $onclick Onclick javascript, if desired.
72
* @param string $class CSS class for the menu item.
74
* @return integer The id (NOT guaranteed to be an array index) of the
75
* item just added to the menu.
77
function add($url, $text, $icon = '', $icon_path = null,
78
$target = '', $onclick = null, $class = null)
80
$pos = count($this->_menu);
81
if (!$pos || ($pos - 1 != max(array_keys($this->_menu)))) {
82
$pos = count($this->_menu);
90
'icon_path' => $icon_path,
92
'onclick' => $onclick,
100
* Add an item to the menu array.
102
* @param string $url String containing the value for
104
* @param string $text String containing the label for
106
* @param optional string $icon String containing the filename of
107
* the image icon to display for this
109
* @param optional string $icon_path If the icon lives in a non-default
110
* directory, where is it?
111
* @param optional string $target If the link needs to open in
112
* another frame or window, what is
114
* @param optional string $onclick Onclick javascript, if desired.
115
* @param optional string $class CSS class for the menu item.
117
* @return integer The id (NOT guaranteed to be an array index) of the item
118
* just added to the menu.
120
function addArray($item)
122
$pos = count($this->_menu);
123
if (!$pos || ($pos - 1 != max(array_keys($this->_menu)))) {
124
$pos = count($this->_menu);
127
$this->_menu[$pos] = $item;
132
function setPosition($id, $pos)
134
if (!isset($this->_menu[$id]) || isset($this->_menu[$pos])) {
138
$item = $this->_menu[$id];
139
unset($this->_menu[$id]);
140
$this->_menu[$pos] = $item;
146
* Return the unordered list representing the list of menu
147
* items. Styling is done through CSS.
151
* @return string An unordered list of menu elements that can be entirely styled with CSS.
155
global $conf, $registry, $prefs;
157
$graphics = $registry->getImageDir('horde');
158
$app = $registry->getApp();
160
if ($this->_mask !== HORDE_MENU_MASK_NONE) {
161
/* Add any custom menu items. */
162
$this->addSiteLinks();
164
/* Add any app menu items. */
165
$this->addAppLinks();
168
/* Add settings link. */
169
if ($this->_mask & HORDE_MENU_MASK_PREFS && $url = Horde::getServiceLink('options', $app)) {
170
$this->add($url, _("_Options"), 'prefs.png', $graphics);
173
/* Add problem link. */
174
if ($this->_mask & HORDE_MENU_MASK_PROBLEM && $problem_link = Horde::getServiceLink('problem', $app)) {
175
$this->add($problem_link, _("Problem"), 'problem.png', $graphics);
179
require_once 'Horde/Help.php';
180
if ($this->_mask & HORDE_MENU_MASK_HELP && $help_link = Horde::getServiceLink('help', $app)) {
181
$this->add($help_link, _("_Help"), 'help_index.png', $graphics);
185
if ($this->_mask & HORDE_MENU_MASK_LOGIN) {
186
/* If the sidebar isn't always shown, but is sometimes
187
* shown, then logout links should be to the parent
190
if ($conf['menu']['always'] || $prefs->getValue('show_sidebar')) {
191
$auth_target = '_parent';
194
if (Auth::getAuth()) {
195
if ($logout_link = Horde::getServiceLink('logout', $app, !$prefs->getValue('show_sidebar'))) {
196
$this->add($logout_link, _("_Log out"), 'logout.png', $graphics, $auth_target, null, '__noselection');
199
if ($login_link = Horde::getServiceLink('login', $app)) {
200
$this->add($login_link, _("_Log in"), 'login.png', $graphics, $auth_target, null, '__noselection');
205
/* No need to return an empty list if there are no menu
207
if (!count($this->_menu)) {
211
/* Sort to match explicitly set positions. */
214
$menu_view = $prefs->getValue('menu_view');
216
foreach ($this->_menu as $m) {
217
/* Item class and selected indication. */
218
if (!isset($m['class'])) {
219
/* Try to match the item's path against the current
220
* script filename as well as other possible URLs to
222
if (Menu::isSelected($m['url'])) {
223
$m['class'] = 'current';
225
} elseif ($m['class'] === '__noselection') {
231
if ($menu_view == 'icon' || $menu_view == 'both') {
232
if (!isset($m['icon_path'])) {
233
$m['icon_path'] = null;
235
$icon = Horde::img($m['icon'], Horde::stripAccessKey($m['text']), '', $m['icon_path']);
239
$accesskey = Horde::getAccessKey($m['text']);
240
$link = Horde::link($m['url'], Horde::stripAccessKey($m['text']),
241
isset($m['class']) ? $m['class'] : '',
242
isset($m['target']) ? $m['target'] : '',
243
isset($m['onclick']) ? $m['onclick'] : '',
246
$output .= sprintf("<li>%s%s<br />%s</a></li>\n",
247
$link, $icon, ($menu_view != 'icon') ? Horde::highlightAccessKey($m['text'], $accesskey) : '');
250
return $output . '</ul>';
254
* Any links to other Horde applications defined in an application's
255
* config file by the $conf['menu']['apps'] array are added to the menu
260
function addAppLinks()
262
global $conf, $registry;
264
if (isset($conf['menu']['apps']) && is_array($conf['menu']['apps'])) {
265
foreach ($conf['menu']['apps'] as $app) {
266
if ($registry->get('status', $app) != 'inactive' && $registry->hasPermission($app, PERMS_SHOW)) {
267
$url = $registry->getInitialPage($app);
268
if (!is_a($url, 'PEAR_Error')) {
269
$this->add(Horde::url($url), $registry->get('name', $app), $registry->get('icon', $app), '');
277
* Add any other links found in $this->_menufile to be included in
282
function addSiteLinks()
284
if (@is_readable($this->_menufile)) {
285
include $this->_menufile;
286
if (isset($_menu) && is_array($_menu)) {
287
foreach ($_menu as $menuitem) {
288
$this->addArray($menuitem);
295
* Checks to see if the current url matches the given url.
299
* @return boolean Whether the given URL is the current location.
301
function isSelected($url)
303
$server_url = parse_url($_SERVER['PHP_SELF']);
304
$check_url = parse_url($url);
306
/* Try to match the item's path against the current script
307
filename as well as other possible URLs to this script. */
308
if (isset($check_url['path']) &&
309
(($check_url['path'] == $server_url['path']) ||
310
($check_url['path'] . 'index.php' == $server_url['path']) ||
311
($check_url['path'] . '/index.php' == $server_url['path']))) {