]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - plugins/NewMenu/NewMenuPlugin.php
Merge remote branch 'gitorious/testing' into testing
[quix0rs-gnu-social.git] / plugins / NewMenu / NewMenuPlugin.php
1 <?php
2 /**
3  * StatusNet - the distributed open-source microblogging tool
4  * Copyright (C) 2010, StatusNet, Inc.
5  *
6  * Do a different menu layout
7  *
8  * PHP version 5
9  *
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.
14  *
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.
19  *
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/>.
22  *
23  * @category  Sample
24  * @package   StatusNet
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/
30  */
31
32 if (!defined('STATUSNET')) {
33     // This check helps protect against security problems;
34     // your code file can't be executed directly from the web.
35     exit(1);
36 }
37
38 /**
39  * Somewhat different menu navigation
40  *
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.
43  *
44  * @category  NewMenu
45  * @package   StatusNet
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/
51  */
52 class NewMenuPlugin extends Plugin
53 {
54     public $loadCSS = false;
55
56     /**
57      * Modify the default menu
58      *
59      * @param Action $action The current action handler. Use this to
60      *                       do any output.
61      *
62      * @return boolean hook value; true means continue processing, false means stop.
63      *
64      * @see Action
65      */
66
67     function onStartPrimaryNav($action)
68     {
69         $user = common_current_user();
70
71         if (!empty($user)) {
72             $action->menuItem(common_local_url('all', 
73                                                array('nickname' => $user->nickname)),
74                               _m('Home'),
75                               _m('Friends timeline'),
76                               false,
77                               'nav_home');
78             $action->menuItem(common_local_url('showstream', 
79                                                array('nickname' => $user->nickname)),
80                               _m('Profile'),
81                               _m('Your profile'),
82                               false,
83                               'nav_profile');
84             $action->menuItem(common_local_url('public'),
85                               _m('Public'),
86                               _m('Everyone on this site'),
87                               false,
88                               'nav_public');
89             $action->menuItem(common_local_url('profilesettings'),
90                               _m('Settings'),
91                               _m('Change your personal settings'),
92                               false,
93                               'nav_account');
94             if ($user->hasRight(Right::CONFIGURESITE)) {
95                 $action->menuItem(common_local_url('siteadminpanel'),
96                                   _m('Admin'), 
97                                   _m('Site configuration'),
98                                   false,
99                                   'nav_admin');
100             }
101             $action->menuItem(common_local_url('logout'),
102                               _m('Logout'), 
103                               _m('Logout from the site'),
104                               false,
105                               'nav_logout');
106         } else {
107             $action->menuItem(common_local_url('public'),
108                               _m('Public'),
109                               _m('Everyone on this site'),
110                               false,
111                               'nav_public');
112             $action->menuItem(common_local_url('login'),
113                               _m('Login'), 
114                               _m('Login to the site'),
115                               false,
116                               'nav_login');
117         }
118
119         if (!empty($user) || !common_config('site', 'private')) {
120             $action->menuItem(common_local_url('noticesearch'),
121                               _m('Search'),
122                               _m('Search the site'),
123                               false,
124                               'nav_search');
125         }
126
127         Event::handle('EndPrimaryNav', array($action));
128
129         return false;
130     }
131
132     function onStartPersonalGroupNav($menu)
133     {
134         $user = null;
135
136         // FIXME: we should probably pass this in
137
138         $action = $menu->action->trimmed('action');
139         $nickname = $menu->action->trimmed('nickname');
140
141         if ($nickname) {
142             $user = User::staticGet('nickname', $nickname);
143             $user_profile = $user->getProfile();
144             $name = $user_profile->getBestName();
145         } else {
146             // @fixme can this happen? is this valid?
147             $user_profile = false;
148             $name = $nickname;
149         }
150
151         $menu->out->menuItem(common_local_url('all', array('nickname' =>
152                                                            $nickname)),
153                              _('Home'),
154                              sprintf(_('%s and friends'), $name),
155                              $action == 'all', 'nav_timeline_personal');
156         $menu->out->menuItem(common_local_url('replies', array('nickname' =>
157                                                                $nickname)),
158                              _('Replies'),
159                              sprintf(_('Replies to %s'), $name),
160                              $action == 'replies', 'nav_timeline_replies');
161         $menu->out->menuItem(common_local_url('showfavorites', array('nickname' =>
162                                                                      $nickname)),
163                              _('Favorites'),
164                              sprintf(_('%s\'s favorite notices'), ($user_profile) ? $name : _('User')),
165                              $action == 'showfavorites', 'nav_timeline_favorites');
166
167         $cur = common_current_user();
168
169         if ($cur && $cur->id == $user->id &&
170             !common_config('singleuser', 'enabled')) {
171
172             $menu->out->menuItem(common_local_url('inbox', array('nickname' =>
173                                                                  $nickname)),
174                                  _('Inbox'),
175                                  _('Your incoming messages'),
176                                  $action == 'inbox');
177             $menu->out->menuItem(common_local_url('outbox', array('nickname' =>
178                                                                   $nickname)),
179                                  _('Outbox'),
180                                  _('Your sent messages'),
181                                  $action == 'outbox');
182         }
183         Event::handle('EndPersonalGroupNav', array($menu));
184         return false;
185     }
186
187     function onStartSubGroupNav($menu)
188     {
189         $cur = common_current_user();
190         $action = $menu->action->trimmed('action');
191
192         $profile = $menu->user->getProfile();
193
194         $menu->out->menuItem(common_local_url('showstream', array('nickname' =>
195                                                                   $menu->user->nickname)),
196                              _('Profile'),
197                              (empty($profile)) ? $menu->user->nickname : $profile->getBestName(),
198                              $action == 'showstream',
199                              'nav_profile');
200         $menu->out->menuItem(common_local_url('subscriptions',
201                                               array('nickname' =>
202                                                     $menu->user->nickname)),
203                              _('Subscriptions'),
204                              sprintf(_('People %s subscribes to'),
205                                      $menu->user->nickname),
206                              $action == 'subscriptions',
207                              'nav_subscriptions');
208         $menu->out->menuItem(common_local_url('subscribers',
209                                               array('nickname' =>
210                                                     $menu->user->nickname)),
211                              _('Subscribers'),
212                              sprintf(_('People subscribed to %s'),
213                                      $menu->user->nickname),
214                              $action == 'subscribers',
215                              'nav_subscribers');
216         $menu->out->menuItem(common_local_url('usergroups',
217                                               array('nickname' =>
218                                                     $menu->user->nickname)),
219                              _('Groups'),
220                              sprintf(_('Groups %s is a member of'),
221                                      $menu->user->nickname),
222                              $action == 'usergroups',
223                              'nav_usergroups');
224         if (common_config('invite', 'enabled') && !is_null($cur) && $menu->user->id === $cur->id) {
225             $menu->out->menuItem(common_local_url('invite'),
226                                  _('Invite'),
227                                  sprintf(_('Invite friends and colleagues to join you on %s'),
228                                          common_config('site', 'name')),
229                                  $action == 'invite',
230                                  'nav_invite');
231         }
232
233         Event::handle('EndSubGroupNav', array($menu));
234         return false;
235     }
236
237     function onStartShowLocalNavBlock($action)
238     {
239         $actionName = $action->trimmed('action');
240         
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);
247             $nav->show();
248             $action->elementEnd('dd');
249             $action->elementEnd('dl');
250             Event::handle('EndShowLocalNavBlock', array($action));
251             return false;
252         }
253
254         return true;
255     }
256
257     function onStartAccountSettingsNav($action)
258     {
259         $this->_settingsMenu($action);
260         return false;
261     }
262
263     function onStartConnectSettingsNav($action)
264     {
265         $this->_settingsMenu($action);
266         return false;
267     }
268
269     private function _settingsMenu($action)
270     {
271         $actionName = $action->trimmed('action');
272
273         $action->menuItem(common_local_url('profilesettings'),
274                           _('Profile'),
275                           _('Change your profile settings'),
276                           $actionName == 'profilesettings');
277
278         $action->menuItem(common_local_url('avatarsettings'),
279                           _('Avatar'),
280                           _('Upload an avatar'),
281                           $actionName == 'avatarsettings');
282
283         $action->menuItem(common_local_url('passwordsettings'),
284                           _('Password'),
285                           _('Change your password'),
286                           $actionName == 'passwordsettings');
287
288         $action->menuItem(common_local_url('emailsettings'),
289                           _('Email'),
290                           _('Change email handling'),
291                           $actionName == 'emailsettings');
292
293         $action->menuItem(common_local_url('userdesignsettings'),
294                           _('Design'),
295                           _('Design your profile'),
296                           $actionName == 'userdesignsettings');
297
298         $action->menuItem(common_local_url('othersettings'),
299                           _('Other'),
300                           _('Other options'),
301                           $actionName == 'othersettings');
302
303         Event::handle('EndAccountSettingsNav', array($action));
304         
305         if (common_config('xmpp', 'enabled')) {
306             $action->menuItem(common_local_url('imsettings'),
307                               _m('IM'),
308                               _('Updates by instant messenger (IM)'),
309                               $actionName == 'imsettings');
310         }
311
312         if (common_config('sms', 'enabled')) {
313             $action->menuItem(common_local_url('smssettings'),
314                               _m('SMS'),
315                               _('Updates by SMS'),
316                               $actionName == 'smssettings');
317         }
318
319         $action->menuItem(common_local_url('oauthconnectionssettings'),
320                           _('Connections'),
321                           _('Authorized connected applications'),
322                           $actionName == 'oauthconnectionsettings');
323
324         Event::handle('EndConnectSettingsNav', array($action));
325     }
326
327     function onEndShowStyles($action)
328     {
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'));
335         }
336         return true;
337     }
338
339     function onStartAddressData($action)
340     {
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));
348         } else {
349             $url = common_local_url('public');
350         }
351
352         $action->elementStart('a', array('class' => 'url home bookmark',
353                                          'href' => $url));
354
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);
365                     }
366                 }
367             }
368         } else {
369             $logoUrl = common_config('site', 'logo');
370         }
371
372         if (empty($logoUrl) && file_exists(Theme::file('logo.png'))) {
373             // This should handle the HTTPS case internally
374             $logoUrl = Theme::path('logo.png');
375         }
376
377         if (!empty($logoUrl)) {
378             $action->element('img', array('class' => 'logo photo',
379                                           'src' => $logoUrl,
380                                           'alt' => common_config('site', 'name')));
381         }
382
383         $action->text(' ');
384         $action->element('span', array('class' => 'fn org'), common_config('site', 'name'));
385         $action->elementEnd('a');
386
387         Event::handle('EndAddressData', array($action));
388         return false;
389     }
390
391     /**
392      * Return version information for this plugin
393      *
394      * @param array &$versions Version info; add to this array
395      *
396      * @return boolean hook value
397      */
398
399     function onPluginVersion(&$versions)
400     {
401         $versions[] = array('name' => 'NewMenu',
402                             'version' => STATUSNET_VERSION,
403                             'author' => 'Evan Prodromou',
404                             'homepage' => 'http://status.net/wiki/Plugin:NewMenu',
405                             'description' =>
406                             _m('A preview of the new menu '.
407                                'layout in StatusNet 1.0.'));
408         return true;
409     }
410 }