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
54 public $loadCSS = false;
57 * Modify the default menu
59 * @param Action $action The current action handler. Use this to
62 * @return boolean hook value; true means continue processing, false means stop.
67 function onStartPrimaryNav($action)
69 $user = common_current_user();
72 $action->menuItem(common_local_url('all',
73 array('nickname' => $user->nickname)),
75 _m('Friends timeline'),
78 $action->menuItem(common_local_url('showstream',
79 array('nickname' => $user->nickname)),
84 $action->menuItem(common_local_url('public'),
86 _m('Everyone on this site'),
89 $action->menuItem(common_local_url('profilesettings'),
91 _m('Change your personal settings'),
94 if ($user->hasRight(Right::CONFIGURESITE)) {
95 $action->menuItem(common_local_url('siteadminpanel'),
97 _m('Site configuration'),
101 $action->menuItem(common_local_url('logout'),
103 _m('Logout from the site'),
107 $action->menuItem(common_local_url('public'),
109 _m('Everyone on this site'),
112 $action->menuItem(common_local_url('login'),
114 _m('Login to the site'),
119 if (!empty($user) || !common_config('site', 'private')) {
120 $action->menuItem(common_local_url('noticesearch'),
122 _m('Search the site'),
127 Event::handle('EndPrimaryNav', array($action));
132 function onStartPersonalGroupNav($menu)
136 // FIXME: we should probably pass this in
138 $action = $menu->action->trimmed('action');
139 $nickname = $menu->action->trimmed('nickname');
142 $user = User::staticGet('nickname', $nickname);
143 $user_profile = $user->getProfile();
144 $name = $user_profile->getBestName();
146 // @fixme can this happen? is this valid?
147 $user_profile = false;
151 $menu->out->menuItem(common_local_url('all', array('nickname' =>
154 sprintf(_('%s and friends'), $name),
155 $action == 'all', 'nav_timeline_personal');
156 $menu->out->menuItem(common_local_url('replies', array('nickname' =>
159 sprintf(_('Replies to %s'), $name),
160 $action == 'replies', 'nav_timeline_replies');
161 $menu->out->menuItem(common_local_url('showfavorites', array('nickname' =>
164 sprintf(_('%s\'s favorite notices'), ($user_profile) ? $name : _('User')),
165 $action == 'showfavorites', 'nav_timeline_favorites');
167 $cur = common_current_user();
169 if ($cur && $cur->id == $user->id &&
170 !common_config('singleuser', 'enabled')) {
172 $menu->out->menuItem(common_local_url('inbox', array('nickname' =>
175 _('Your incoming messages'),
177 $menu->out->menuItem(common_local_url('outbox', array('nickname' =>
180 _('Your sent messages'),
181 $action == 'outbox');
183 Event::handle('EndPersonalGroupNav', array($menu));
187 function onStartSubGroupNav($menu)
189 $cur = common_current_user();
190 $action = $menu->action->trimmed('action');
192 $profile = $menu->user->getProfile();
194 $menu->out->menuItem(common_local_url('showstream', array('nickname' =>
195 $menu->user->nickname)),
197 (empty($profile)) ? $menu->user->nickname : $profile->getBestName(),
198 $action == 'showstream',
200 $menu->out->menuItem(common_local_url('subscriptions',
202 $menu->user->nickname)),
204 sprintf(_('People %s subscribes to'),
205 $menu->user->nickname),
206 $action == 'subscriptions',
207 'nav_subscriptions');
208 $menu->out->menuItem(common_local_url('subscribers',
210 $menu->user->nickname)),
212 sprintf(_('People subscribed to %s'),
213 $menu->user->nickname),
214 $action == 'subscribers',
216 $menu->out->menuItem(common_local_url('usergroups',
218 $menu->user->nickname)),
220 sprintf(_('Groups %s is a member of'),
221 $menu->user->nickname),
222 $action == 'usergroups',
224 if (common_config('invite', 'enabled') && !is_null($cur) && $menu->user->id === $cur->id) {
225 $menu->out->menuItem(common_local_url('invite'),
227 sprintf(_('Invite friends and colleagues to join you on %s'),
228 common_config('site', 'name')),
233 Event::handle('EndSubGroupNav', array($menu));
237 function onStartShowLocalNavBlock($action)
239 $actionName = $action->trimmed('action');
241 if ($actionName == 'showstream') {
242 $action->elementStart('dl', array('id' => 'site_nav_local_views'));
243 // TRANS: DT element for local views block. String is hidden in default CSS.
244 $action->element('dt', null, _('Local views'));
245 $action->elementStart('dd');
246 $nav = new SubGroupNav($action, $action->user);
248 $action->elementEnd('dd');
249 $action->elementEnd('dl');
250 Event::handle('EndShowLocalNavBlock', array($action));
257 function onStartAccountSettingsNav($action)
259 $this->_settingsMenu($action);
263 function onStartConnectSettingsNav($action)
265 $this->_settingsMenu($action);
269 private function _settingsMenu($action)
271 $actionName = $action->trimmed('action');
273 $action->menuItem(common_local_url('profilesettings'),
275 _('Change your profile settings'),
276 $actionName == 'profilesettings');
278 $action->menuItem(common_local_url('avatarsettings'),
280 _('Upload an avatar'),
281 $actionName == 'avatarsettings');
283 $action->menuItem(common_local_url('passwordsettings'),
285 _('Change your password'),
286 $actionName == 'passwordsettings');
288 $action->menuItem(common_local_url('emailsettings'),
290 _('Change email handling'),
291 $actionName == 'emailsettings');
293 $action->menuItem(common_local_url('userdesignsettings'),
295 _('Design your profile'),
296 $actionName == 'userdesignsettings');
298 $action->menuItem(common_local_url('othersettings'),
301 $actionName == 'othersettings');
303 Event::handle('EndAccountSettingsNav', array($action));
305 if (common_config('xmpp', 'enabled')) {
306 $action->menuItem(common_local_url('imsettings'),
308 _('Updates by instant messenger (IM)'),
309 $actionName == 'imsettings');
312 if (common_config('sms', 'enabled')) {
313 $action->menuItem(common_local_url('smssettings'),
316 $actionName == 'smssettings');
319 $action->menuItem(common_local_url('oauthconnectionssettings'),
321 _('Authorized connected applications'),
322 $actionName == 'oauthconnectionsettings');
324 Event::handle('EndConnectSettingsNav', array($action));
327 function onEndShowStyles($action)
329 if (($this->showCSS ||
330 in_array(common_config('site', 'theme'),
331 array('default', 'identica', 'h4ck3r'))) &&
332 ($action instanceof AccountSettingsAction ||
333 $action instanceof ConnectSettingsAction)) {
334 $action->cssLink(common_path('plugins/NewMenu/newmenu.css'));
339 function onStartAddressData($action)
341 if (common_config('singleuser', 'enabled')) {
342 $user = User::singleUser();
343 $url = common_local_url('showstream',
344 array('nickname' => $user->nickname));
345 } else if (common_logged_in()) {
346 $cur = common_current_user();
347 $url = common_local_url('all', array('nickname' => $cur->nickname));
349 $url = common_local_url('public');
352 $action->elementStart('a', array('class' => 'url home bookmark',
355 if (StatusNet::isHTTPS()) {
356 $logoUrl = common_config('site', 'ssllogo');
357 if (empty($logoUrl)) {
358 // if logo is an uploaded file, try to fall back to HTTPS file URL
359 $httpUrl = common_config('site', 'logo');
360 if (!empty($httpUrl)) {
361 $f = File::staticGet('url', $httpUrl);
362 if (!empty($f) && !empty($f->filename)) {
363 // this will handle the HTTPS case
364 $logoUrl = File::url($f->filename);
369 $logoUrl = common_config('site', 'logo');
372 if (empty($logoUrl) && file_exists(Theme::file('logo.png'))) {
373 // This should handle the HTTPS case internally
374 $logoUrl = Theme::path('logo.png');
377 if (!empty($logoUrl)) {
378 $action->element('img', array('class' => 'logo photo',
380 'alt' => common_config('site', 'name')));
384 $action->element('span', array('class' => 'fn org'), common_config('site', 'name'));
385 $action->elementEnd('a');
387 Event::handle('EndAddressData', array($action));
392 * Return version information for this plugin
394 * @param array &$versions Version info; add to this array
396 * @return boolean hook value
399 function onPluginVersion(&$versions)
401 $versions[] = array('name' => 'NewMenu',
402 'version' => STATUSNET_VERSION,
403 'author' => 'Evan Prodromou',
404 'homepage' => 'http://status.net/wiki/Plugin:NewMenu',
406 _m('A preview of the new menu '.
407 'layout in StatusNet 1.0.'));