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 * Load related modules when needed
59 * @param string $cls Name of the class to be loaded
61 * @return boolean hook value; true means continue processing, false means stop.
64 function onAutoload($cls)
66 $dir = dirname(__FILE__);
71 include_once $dir . '/' . strtolower(mb_substr($cls, 0, -6)) . '.php';
73 case 'User_greeting_count':
74 include_once $dir . '/'.$cls.'.php';
82 * Modify the default menu
84 * @param Action $action The current action handler. Use this to
87 * @return boolean hook value; true means continue processing, false means stop.
92 function onStartPrimaryNav($action)
94 $user = common_current_user();
97 $action->menuItem(common_local_url('all',
98 array('nickname' => $user->nickname)),
100 _m('Friends timeline'),
103 $action->menuItem(common_local_url('showstream',
104 array('nickname' => $user->nickname)),
109 $action->menuItem(common_local_url('public'),
111 _m('Everyone on this site'),
114 $action->menuItem(common_local_url('profilesettings'),
116 _m('Change your personal settings'),
119 if ($user->hasRight(Right::CONFIGURESITE)) {
120 $action->menuItem(common_local_url('siteadminpanel'),
122 _m('Site configuration'),
126 $action->menuItem(common_local_url('logout'),
128 _m('Logout from the site'),
132 $action->menuItem(common_local_url('public'),
134 _m('Everyone on this site'),
137 $action->menuItem(common_local_url('login'),
139 _m('Login to the site'),
144 if (!empty($user) || !common_config('site', 'private')) {
145 $action->menuItem(common_local_url('noticesearch'),
147 _m('Search the site'),
152 Event::handle('EndPrimaryNav', array($action));
157 function onStartPersonalGroupNav($menu)
161 // FIXME: we should probably pass this in
163 $action = $menu->action->trimmed('action');
164 $nickname = $menu->action->trimmed('nickname');
167 $user = User::staticGet('nickname', $nickname);
168 $user_profile = $user->getProfile();
169 $name = $user_profile->getBestName();
171 // @fixme can this happen? is this valid?
172 $user_profile = false;
176 $menu->out->menuItem(common_local_url('all', array('nickname' =>
179 sprintf(_('%s and friends'), $name),
180 $action == 'all', 'nav_timeline_personal');
181 $menu->out->menuItem(common_local_url('replies', array('nickname' =>
184 sprintf(_('Replies to %s'), $name),
185 $action == 'replies', 'nav_timeline_replies');
186 $menu->out->menuItem(common_local_url('showfavorites', array('nickname' =>
189 sprintf(_('%s\'s favorite notices'), ($user_profile) ? $name : _('User')),
190 $action == 'showfavorites', 'nav_timeline_favorites');
192 $cur = common_current_user();
194 if ($cur && $cur->id == $user->id &&
195 !common_config('singleuser', 'enabled')) {
197 $menu->out->menuItem(common_local_url('inbox', array('nickname' =>
200 _('Your incoming messages'),
202 $menu->out->menuItem(common_local_url('outbox', array('nickname' =>
205 _('Your sent messages'),
206 $action == 'outbox');
208 Event::handle('EndPersonalGroupNav', array($menu));
212 function onStartSubGroupNav($menu)
214 $cur = common_current_user();
215 $action = $menu->action->trimmed('action');
217 $profile = $menu->user->getProfile();
219 $menu->out->menuItem(common_local_url('showstream', array('nickname' =>
220 $menu->user->nickname)),
222 (empty($profile)) ? $menu->user->nickname : $profile->getBestName(),
223 $action == 'showstream',
225 $menu->out->menuItem(common_local_url('subscriptions',
227 $menu->user->nickname)),
229 sprintf(_('People %s subscribes to'),
230 $menu->user->nickname),
231 $action == 'subscriptions',
232 'nav_subscriptions');
233 $menu->out->menuItem(common_local_url('subscribers',
235 $menu->user->nickname)),
237 sprintf(_('People subscribed to %s'),
238 $menu->user->nickname),
239 $action == 'subscribers',
241 $menu->out->menuItem(common_local_url('usergroups',
243 $menu->user->nickname)),
245 sprintf(_('Groups %s is a member of'),
246 $menu->user->nickname),
247 $action == 'usergroups',
249 if (common_config('invite', 'enabled') && !is_null($cur) && $menu->user->id === $cur->id) {
250 $menu->out->menuItem(common_local_url('invite'),
252 sprintf(_('Invite friends and colleagues to join you on %s'),
253 common_config('site', 'name')),
258 Event::handle('EndSubGroupNav', array($menu));
262 function onStartShowLocalNavBlock($action)
264 $actionName = $action->trimmed('action');
266 if ($actionName == 'showstream') {
267 $action->elementStart('dl', array('id' => 'site_nav_local_views'));
268 // TRANS: DT element for local views block. String is hidden in default CSS.
269 $action->element('dt', null, _('Local views'));
270 $action->elementStart('dd');
271 $nav = new SubGroupNav($action, $action->user);
273 $action->elementEnd('dd');
274 $action->elementEnd('dl');
275 Event::handle('EndShowLocalNavBlock', array($action));
282 function onStartAccountSettingsNav($action)
284 $this->_settingsMenu($action);
288 function onStartConnectSettingsNav($action)
290 $this->_settingsMenu($action);
294 private function _settingsMenu($action)
296 $actionName = $action->trimmed('action');
298 $action->menuItem(common_local_url('profilesettings'),
300 _('Change your profile settings'),
301 $actionName == 'profilesettings');
303 $action->menuItem(common_local_url('avatarsettings'),
305 _('Upload an avatar'),
306 $actionName == 'avatarsettings');
308 $action->menuItem(common_local_url('passwordsettings'),
310 _('Change your password'),
311 $actionName == 'passwordsettings');
313 $action->menuItem(common_local_url('emailsettings'),
315 _('Change email handling'),
316 $actionName == 'emailsettings');
318 $action->menuItem(common_local_url('userdesignsettings'),
320 _('Design your profile'),
321 $actionName == 'userdesignsettings');
323 $action->menuItem(common_local_url('othersettings'),
326 $actionName == 'othersettings');
328 Event::handle('EndAccountSettingsNav', array($action));
330 if (common_config('xmpp', 'enabled')) {
331 $action->menuItem(common_local_url('imsettings'),
333 _('Updates by instant messenger (IM)'),
334 $actionName == 'imsettings');
337 if (common_config('sms', 'enabled')) {
338 $action->menuItem(common_local_url('smssettings'),
341 $actionName == 'smssettings');
344 $action->menuItem(common_local_url('oauthconnectionssettings'),
346 _('Authorized connected applications'),
347 $actionName == 'oauthconnectionsettings');
349 Event::handle('EndConnectSettingsNav', array($action));
352 function onEndShowStyles($action)
354 if (($this->showCSS ||
355 in_array(common_config('site', 'theme'),
356 array('default', 'identica', 'h4ck3r'))) &&
357 ($action instanceof AccountSettingsAction ||
358 $action instanceof ConnectSettingsAction)) {
359 $action->cssLink(common_path('plugins/NewMenu/newmenu.css'));
364 function onStartAddressData($action)
366 if (common_config('singleuser', 'enabled')) {
367 $user = User::singleUser();
368 $url = common_local_url('showstream',
369 array('nickname' => $user->nickname));
370 } else if (common_logged_in()) {
371 $cur = common_current_user();
372 $url = common_local_url('all', array('nickname' => $cur->nickname));
374 $url = common_local_url('public');
377 $action->elementStart('a', array('class' => 'url home bookmark',
380 if (StatusNet::isHTTPS()) {
381 $logoUrl = common_config('site', 'ssllogo');
382 if (empty($logoUrl)) {
383 // if logo is an uploaded file, try to fall back to HTTPS file URL
384 $httpUrl = common_config('site', 'logo');
385 if (!empty($httpUrl)) {
386 $f = File::staticGet('url', $httpUrl);
387 if (!empty($f) && !empty($f->filename)) {
388 // this will handle the HTTPS case
389 $logoUrl = File::url($f->filename);
394 $logoUrl = common_config('site', 'logo');
397 if (empty($logoUrl) && file_exists(Theme::file('logo.png'))) {
398 // This should handle the HTTPS case internally
399 $logoUrl = Theme::path('logo.png');
402 if (!empty($logoUrl)) {
403 $action->element('img', array('class' => 'logo photo',
405 'alt' => common_config('site', 'name')));
409 $action->element('span', array('class' => 'fn org'), common_config('site', 'name'));
410 $action->elementEnd('a');
412 Event::handle('EndAddressData', array($action));
417 * Return version information for this plugin
419 * @param array &$versions Version info; add to this array
421 * @return boolean hook value
424 function onPluginVersion(&$versions)
426 $versions[] = array('name' => 'NewMenu',
427 'version' => STATUSNET_VERSION,
428 'author' => 'Evan Prodromou',
429 'homepage' => 'http://status.net/wiki/Plugin:NewMenu',
431 _m('A preview of the new menu '.
432 'layout in StatusNet 1.0.'));