3 * StatusNet - the distributed open-source microblogging tool
4 * Copyright (C) 2010, StatusNet, Inc.
6 * Do a different menu layout
10 * This program is free software: you can redistribute it and/or modify
11 * it under the terms of the GNU Affero General Public License as published by
12 * the Free Software Foundation, either version 3 of the License, or
13 * (at your option) any later version.
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU Affero General Public License for more details.
20 * You should have received a copy of the GNU Affero General Public License
21 * along with this program. If not, see <http://www.gnu.org/licenses/>.
25 * @author Brion Vibber <brionv@status.net>
26 * @author Evan Prodromou <evan@status.net>
27 * @copyright 2010 StatusNet, Inc.
28 * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html AGPL 3.0
29 * @link http://status.net/
32 if (!defined('STATUSNET')) {
33 // This check helps protect against security problems;
34 // your code file can't be executed directly from the web.
39 * Somewhat different menu navigation
41 * We have a new menu layout coming in StatusNet 1.0. This plugin gets
42 * some of the new navigation in, although third-level menus aren't enabled.
46 * @author Brion Vibber <brionv@status.net>
47 * @author Evan Prodromou <evan@status.net>
48 * @copyright 2010 StatusNet, Inc.
49 * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html AGPL 3.0
50 * @link http://status.net/
52 class NewMenuPlugin extends Plugin
55 * Load related modules when needed
57 * @param string $cls Name of the class to be loaded
59 * @return boolean hook value; true means continue processing, false means stop.
62 function onAutoload($cls)
64 $dir = dirname(__FILE__);
69 include_once $dir . '/' . strtolower(mb_substr($cls, 0, -6)) . '.php';
71 case 'User_greeting_count':
72 include_once $dir . '/'.$cls.'.php';
80 * Modify the default menu
82 * @param Action $action The current action handler. Use this to
85 * @return boolean hook value; true means continue processing, false means stop.
90 function onStartPrimaryNav($action)
92 $user = common_current_user();
95 $action->menuItem(common_local_url('all',
96 array('nickname' => $user->nickname)),
98 _m('Friends timeline'),
101 $action->menuItem(common_local_url('showstream',
102 array('nickname' => $user->nickname)),
107 $action->menuItem(common_local_url('public'),
109 _m('Everyone on this site'),
112 $action->menuItem(common_local_url('profilesettings'),
114 _m('Change your personal settings'),
117 if ($user->hasRight(Right::CONFIGURESITE)) {
118 $action->menuItem(common_local_url('siteadminpanel'),
120 _m('Site configuration'),
124 $action->menuItem(common_local_url('logout'),
126 _m('Logout from the site'),
130 $action->menuItem(common_local_url('public'),
132 _m('Everyone on this site'),
135 $action->menuItem(common_local_url('login'),
137 _m('Login to the site'),
142 $action->menuItem(common_local_url('doc',
143 array('title' => 'help')),
145 _m('Help using this site'),
149 if (!empty($user) || !common_config('site', 'private')) {
150 $action->menuItem(common_local_url('noticesearch'),
152 _m('Search the site'),
157 Event::handle('EndPrimaryNav', array($action));
162 function onStartPersonalGroupNav($menu)
166 // FIXME: we should probably pass this in
168 $action = $menu->action->trimmed('action');
169 $nickname = $menu->action->trimmed('nickname');
172 $user = User::staticGet('nickname', $nickname);
173 $user_profile = $user->getProfile();
174 $name = $user_profile->getBestName();
176 // @fixme can this happen? is this valid?
177 $user_profile = false;
181 $menu->out->menuItem(common_local_url('all', array('nickname' =>
184 sprintf(_('%s and friends'), $name),
185 $action == 'all', 'nav_timeline_personal');
186 $menu->out->menuItem(common_local_url('replies', array('nickname' =>
189 sprintf(_('Replies to %s'), $name),
190 $action == 'replies', 'nav_timeline_replies');
191 $menu->out->menuItem(common_local_url('showfavorites', array('nickname' =>
194 sprintf(_('%s\'s favorite notices'), ($user_profile) ? $name : _('User')),
195 $action == 'showfavorites', 'nav_timeline_favorites');
197 $cur = common_current_user();
199 if ($cur && $cur->id == $user->id &&
200 !common_config('singleuser', 'enabled')) {
202 $menu->out->menuItem(common_local_url('inbox', array('nickname' =>
205 _('Your incoming messages'),
207 $menu->out->menuItem(common_local_url('outbox', array('nickname' =>
210 _('Your sent messages'),
211 $action == 'outbox');
213 Event::handle('EndPersonalGroupNav', array($menu));
217 function onStartSubGroupNav($menu)
219 $cur = common_current_user();
220 $action = $menu->action->trimmed('action');
222 $profile = $menu->user->getProfile();
224 $menu->out->menuItem(common_local_url('showstream', array('nickname' =>
225 $menu->user->nickname)),
227 (empty($profile)) ? $menu->user->nickname : $profile->getBestName(),
228 $action == 'showstream',
230 $menu->out->menuItem(common_local_url('subscriptions',
232 $menu->user->nickname)),
234 sprintf(_('People %s subscribes to'),
235 $menu->user->nickname),
236 $action == 'subscriptions',
237 'nav_subscriptions');
238 $menu->out->menuItem(common_local_url('subscribers',
240 $menu->user->nickname)),
242 sprintf(_('People subscribed to %s'),
243 $menu->user->nickname),
244 $action == 'subscribers',
246 $menu->out->menuItem(common_local_url('usergroups',
248 $menu->user->nickname)),
250 sprintf(_('Groups %s is a member of'),
251 $menu->user->nickname),
252 $action == 'usergroups',
254 if (common_config('invite', 'enabled') && !is_null($cur) && $menu->user->id === $cur->id) {
255 $menu->out->menuItem(common_local_url('invite'),
257 sprintf(_('Invite friends and colleagues to join you on %s'),
258 common_config('site', 'name')),
263 Event::handle('EndSubGroupNav', array($menu));
267 function onStartShowLocalNavBlock($action)
269 $actionName = $action->trimmed('action');
271 if ($actionName == 'showstream') {
272 $action->elementStart('dl', array('id' => 'site_nav_local_views'));
273 // TRANS: DT element for local views block. String is hidden in default CSS.
274 $action->element('dt', null, _('Local views'));
275 $action->elementStart('dd');
276 $nav = new SubGroupNav($action, $action->user);
278 $action->elementEnd('dd');
279 $action->elementEnd('dl');
280 Event::handle('EndShowLocalNavBlock', array($action));
288 * Return version information for this plugin
290 * @param array &$versions Version info; add to this array
292 * @return boolean hook value
295 function onPluginVersion(&$versions)
297 $versions[] = array('name' => 'NewMenu',
298 'version' => STATUSNET_VERSION,
299 'author' => 'Evan Prodromou',
300 'homepage' => 'http://status.net/wiki/Plugin:NewMenu',
302 _m('A preview of the new menu '.
303 'layout in StatusNet 1.0.'));