1: <?php
2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14:
15: class
16: {
17: 18: 19: 20: 21:
22: protected $_tree;
23:
24: 25: 26:
27: public function __construct()
28: {
29:
30: $this->_tree = $GLOBALS['injector']
31: ->getInstance('Horde_Core_Factory_Tree')
32: ->create('horde_menu', 'Javascript',
33: array('jsvar' => 'HordeSidebar.tree'));
34: }
35:
36: 37: 38: 39: 40:
41: public function isJavascript()
42: {
43: return $this->_tree instanceof Horde_Core_Tree_Javascript;
44: }
45:
46: 47: 48: 49: 50: 51:
52: public function getBaseTree()
53: {
54: return $this->_tree;
55: }
56:
57: 58: 59: 60: 61:
62: public function getTree()
63: {
64: global $registry;
65:
66: $isAdmin = $registry->isAdmin();
67: $menu = $children = array();
68:
69: foreach ($registry->listApps(array('active', 'admin', 'noadmin', 'heading', 'notoolbar', 'sidebar'), true, null) as $app => $params) {
70: 71: 72: 73: 74:
75: if ($params['status'] == 'heading' ||
76: (in_array($params['status'], array('active', 'admin', 'noadmin', 'sidebar')) &&
77: $registry->hasPermission((!empty($params['app']) ? $params['app'] : $app), Horde_Perms::SHOW) &&
78: !($isAdmin && $params['status'] == 'noadmin'))) {
79: $menu[$app] = $params;
80:
81: if (isset($params['menu_parent'])) {
82: $children[$params['menu_parent']] = true;
83: }
84: }
85: }
86:
87: foreach (array_keys($menu) as $key) {
88: if (($menu[$key]['status'] == 'heading') &&
89: !isset($children[$key])) {
90: unset($menu[$key]);
91: }
92: }
93:
94: 95:
96: $perms = $GLOBALS['injector']->getInstance('Horde_Perms');
97: $admin_item_count = 0;
98: try {
99: foreach ($registry->callByPackage('horde', 'admin_list') as $method => $val) {
100: if ($isAdmin ||
101: $perms->hasPermission('horde:administration:' . $method, $registry->getAuth(), Horde_Perms::SHOW)) {
102: $admin_item_count++;
103: $menu['administration_' . $method] = array(
104: 'icon' => $val['icon'],
105: 'menu_parent' => 'administration',
106: 'name' => Horde::stripAccessKey($val['name']),
107: 'status' => 'active',
108: 'url' => Horde::url($registry->applicationWebPath($val['link'], 'horde')),
109: );
110: }
111: }
112: } catch (Horde_Exception $e) {
113: }
114:
115: if ($admin_item_count) {
116: $menu['administration'] = array(
117: 'name' => Horde_Core_Translation::t("Administration"),
118: 'icon' => Horde_Themes::img('administration.png'),
119: 'status' => 'heading'
120: );
121: }
122:
123: if (Horde_Menu::showService('prefs') &&
124: !($GLOBALS['injector']->getInstance('Horde_Core_Factory_Prefs')->create() instanceof Horde_Prefs_Session)) {
125: $menu['prefs'] = array(
126: 'icon' => Horde_Themes::img('prefs.png'),
127: 'name' => Horde_Core_Translation::t("Preferences"),
128: 'status' => 'active'
129: );
130:
131:
132: $prefs_apps = $registry->listApps(array('active', 'admin'), true, Horde_Perms::READ);
133:
134: if (!empty($prefs_apps['horde'])) {
135: $menu['prefs_' . 'horde'] = array(
136: 'icon' => $registry->get('icon', 'horde'),
137: 'menu_parent' => 'prefs',
138: 'name' => Horde_Core_Translation::t("Global Preferences"),
139: 'status' => 'active',
140: 'url' => Horde::getServiceLink('prefs', 'horde')
141: );
142: unset($prefs_apps['horde']);
143: }
144:
145: uasort($prefs_apps, array($this, '_sortByName'));
146: foreach ($prefs_apps as $app => $params) {
147: $menu['prefs_' . $app] = array(
148: 'icon' => $registry->get('icon', $app),
149: 'menu_parent' => 'prefs',
150: 'name' => $params['name'],
151: 'status' => 'active',
152: 'url' => Horde::getServiceLink('prefs', $app)
153: );
154: }
155: }
156:
157: if ($registry->getAuth()) {
158: $menu['logout'] = array(
159: 'icon' => Horde_Themes::img('logout.png'),
160: 'name' => Horde_Core_Translation::t("Log out"),
161: 'status' => 'active',
162: 'url' => Horde::getServiceLink('logout', 'horde')
163: );
164: } else {
165: $menu['login'] = array(
166: 'icon' => Horde_Themes::img('login.png'),
167: 'name' => Horde_Core_Translation::t("Log in"),
168: 'status' => 'active',
169: 'url' => Horde::getServiceLink('login', 'horde')
170: );
171: }
172:
173: foreach ($menu as $app => $params) {
174: switch ($params['status']) {
175: case 'sidebar':
176: try {
177: $registry->callAppMethod($params['app'], 'sidebarCreate', array('args' => array($this->_tree, empty($params['menu_parent']) ? null : $params['menu_parent'], isset($params['sidebar_params']) ? $params['sidebar_params'] : array())));
178: } catch (Horde_Exception $e) {
179: if ($e->getCode() != Horde_Registry::NOT_ACTIVE) {
180: Horde::logMessage($e, 'ERR');
181: }
182: }
183: break;
184:
185: default:
186:
187:
188:
189:
190: $name = _($params['name']);
191:
192:
193:
194: if (isset($params['url'])) {
195: $url = $params['url'];
196: } elseif (($params['status'] == 'heading') ||
197: !isset($params['webroot'])) {
198: $url = null;
199: } else {
200: $url = Horde::url($registry->getInitialPage($app), false, array('app' => $app));
201: }
202:
203: $this->_tree->addNode(
204: $app,
205: empty($params['menu_parent']) ? null : $params['menu_parent'],
206: $name,
207: 0,
208: false,
209: array(
210: 'icon' => strval((isset($params['icon']) ? $params['icon'] : $registry->get('icon', $app))),
211: 'target' => isset($params['target']) ? $params['target'] : null,
212: 'url' => $url
213: )
214: );
215: break;
216: }
217: }
218:
219: return $this->_tree;
220: }
221:
222: 223: 224: 225: 226: 227: 228: 229:
230: protected function _sortByName($a, $b)
231: {
232: return strcoll(_($a['name']), _($b['name']));
233: }
234: }
235: