]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - plugins/NewMenu/NewMenuPlugin.php
change 'Everyone' to 'Public'
[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     /**
55      * Load related modules when needed
56      *
57      * @param string $cls Name of the class to be loaded
58      *
59      * @return boolean hook value; true means continue processing, false means stop.
60      */
61
62     function onAutoload($cls)
63     {
64         $dir = dirname(__FILE__);
65
66         switch ($cls)
67         {
68         case 'HelloAction':
69             include_once $dir . '/' . strtolower(mb_substr($cls, 0, -6)) . '.php';
70             return false;
71         case 'User_greeting_count':
72             include_once $dir . '/'.$cls.'.php';
73             return false;
74         default:
75             return true;
76         }
77     }
78
79     /**
80      * Modify the default menu
81      *
82      * @param Action $action The current action handler. Use this to
83      *                       do any output.
84      *
85      * @return boolean hook value; true means continue processing, false means stop.
86      *
87      * @see Action
88      */
89
90     function onStartPrimaryNav($action)
91     {
92         $user = common_current_user();
93
94         if (!empty($user)) {
95             $action->menuItem(common_local_url('all', 
96                                                array('nickname' => $user->nickname)),
97                               _m('Home'),
98                               _m('Friends timeline'),
99                               false,
100                               'nav_home');
101             $action->menuItem(common_local_url('showstream', 
102                                                array('nickname' => $user->nickname)),
103                               _m('Profile'),
104                               _m('Your profile'),
105                               false,
106                               'nav_profile');
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('profilesettings'),
113                               _m('Settings'),
114                               _m('Change your personal settings'),
115                               false,
116                               'nav_account');
117             if ($user->hasRight(Right::CONFIGURESITE)) {
118                 $action->menuItem(common_local_url('siteadminpanel'),
119                                   _m('Admin'), 
120                                   _m('Site configuration'),
121                                   false,
122                                   'nav_admin');
123             }
124             $action->menuItem(common_local_url('logout'),
125                               _m('Logout'), 
126                               _m('Logout from the site'),
127                               false,
128                               'nav_logout');
129         } else {
130             $action->menuItem(common_local_url('public'),
131                               _m('Everyone'),
132                               _m('Everyone on this site'),
133                               false,
134                               'nav_public');
135             $action->menuItem(common_local_url('login'),
136                               _m('Login'), 
137                               _m('Login to the site'),
138                               false,
139                               'nav_login');
140         }
141
142         $action->menuItem(common_local_url('doc', 
143                                            array('title' => 'help')),
144                           _m('Help'),
145                           _m('Help using this site'),
146                           false,
147                           'nav_help');
148
149         if (!empty($user) || !common_config('site', 'private')) {
150             $action->menuItem(common_local_url('noticesearch'),
151                               _m('Search'),
152                               _m('Search the site'),
153                               false,
154                               'nav_search');
155         }
156
157         Event::handle('EndPrimaryNav', array($action));
158
159         return false;
160     }
161
162     function onStartPersonalGroupNav($menu)
163     {
164         $user = null;
165
166         // FIXME: we should probably pass this in
167
168         $action = $menu->action->trimmed('action');
169         $nickname = $menu->action->trimmed('nickname');
170
171         if ($nickname) {
172             $user = User::staticGet('nickname', $nickname);
173             $user_profile = $user->getProfile();
174             $name = $user_profile->getBestName();
175         } else {
176             // @fixme can this happen? is this valid?
177             $user_profile = false;
178             $name = $nickname;
179         }
180
181         $menu->out->menuItem(common_local_url('all', array('nickname' =>
182                                                            $nickname)),
183                              _('Home'),
184                              sprintf(_('%s and friends'), $name),
185                              $action == 'all', 'nav_timeline_personal');
186         $menu->out->menuItem(common_local_url('replies', array('nickname' =>
187                                                                $nickname)),
188                              _('Replies'),
189                              sprintf(_('Replies to %s'), $name),
190                              $action == 'replies', 'nav_timeline_replies');
191         $menu->out->menuItem(common_local_url('showfavorites', array('nickname' =>
192                                                                      $nickname)),
193                              _('Favorites'),
194                              sprintf(_('%s\'s favorite notices'), ($user_profile) ? $name : _('User')),
195                              $action == 'showfavorites', 'nav_timeline_favorites');
196
197         $cur = common_current_user();
198
199         if ($cur && $cur->id == $user->id &&
200             !common_config('singleuser', 'enabled')) {
201
202             $menu->out->menuItem(common_local_url('inbox', array('nickname' =>
203                                                                  $nickname)),
204                                  _('Inbox'),
205                                  _('Your incoming messages'),
206                                  $action == 'inbox');
207             $menu->out->menuItem(common_local_url('outbox', array('nickname' =>
208                                                                   $nickname)),
209                                  _('Outbox'),
210                                  _('Your sent messages'),
211                                  $action == 'outbox');
212         }
213         Event::handle('EndPersonalGroupNav', array($menu));
214         return false;
215     }
216
217     function onStartSubGroupNav($menu)
218     {
219         $cur = common_current_user();
220         $action = $menu->action->trimmed('action');
221
222         $profile = $menu->user->getProfile();
223
224         $menu->out->menuItem(common_local_url('showstream', array('nickname' =>
225                                                                   $menu->user->nickname)),
226                              _('Profile'),
227                              (empty($profile)) ? $menu->user->nickname : $profile->getBestName(),
228                              $action == 'showstream',
229                              'nav_profile');
230         $menu->out->menuItem(common_local_url('subscriptions',
231                                               array('nickname' =>
232                                                     $menu->user->nickname)),
233                              _('Subscriptions'),
234                              sprintf(_('People %s subscribes to'),
235                                      $menu->user->nickname),
236                              $action == 'subscriptions',
237                              'nav_subscriptions');
238         $menu->out->menuItem(common_local_url('subscribers',
239                                               array('nickname' =>
240                                                     $menu->user->nickname)),
241                              _('Subscribers'),
242                              sprintf(_('People subscribed to %s'),
243                                      $menu->user->nickname),
244                              $action == 'subscribers',
245                              'nav_subscribers');
246         $menu->out->menuItem(common_local_url('usergroups',
247                                               array('nickname' =>
248                                                     $menu->user->nickname)),
249                              _('Groups'),
250                              sprintf(_('Groups %s is a member of'),
251                                      $menu->user->nickname),
252                              $action == 'usergroups',
253                              'nav_usergroups');
254         if (common_config('invite', 'enabled') && !is_null($cur) && $menu->user->id === $cur->id) {
255             $menu->out->menuItem(common_local_url('invite'),
256                                  _('Invite'),
257                                  sprintf(_('Invite friends and colleagues to join you on %s'),
258                                          common_config('site', 'name')),
259                                  $action == 'invite',
260                                  'nav_invite');
261         }
262
263         Event::handle('EndSubGroupNav', array($menu));
264         return false;
265     }
266
267     function onStartShowLocalNavBlock($action)
268     {
269         $actionName = $action->trimmed('action');
270         
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);
277             $nav->show();
278             $action->elementEnd('dd');
279             $action->elementEnd('dl');
280             Event::handle('EndShowLocalNavBlock', array($action));
281             return false;
282         }
283
284         return true;
285     }
286
287     function onStartAccountSettingsNav(&$action)
288     {
289         $this->_settingsMenu($action);
290         return false;
291     }
292
293     function onStartConnectSettingsNav(&$action)
294     {
295         $this->_settingsMenu($action);
296         return false;
297     }
298
299     private function _settingsMenu(&$action)
300     {
301         $actionName = $action->trimmed('action');
302
303         $action->menuItem(common_local_url('profilesettings'),
304                           _('Profile'),
305                           _('Change your profile settings'),
306                           $actionName == 'profilesettings');
307
308         $action->menuItem(common_local_url('avatarsettings'),
309                           _('Avatar'),
310                           _('Upload an avatar'),
311                           $actionName == 'avatarsettings');
312
313         $action->menuItem(common_local_url('passwordsettings'),
314                           _('Password'),
315                           _('Change your password'),
316                           $actionName == 'passwordsettings');
317
318         $action->menuItem(common_local_url('emailsettings'),
319                           _('Email'),
320                           _('Change email handling'),
321                           $actionName == 'emailsettings');
322
323         $action->menuItem(common_local_url('userdesignsettings'),
324                           _('Design'),
325                           _('Design your profile'),
326                           $actionName == 'userdesignsettings');
327
328         $action->menuItem(common_local_url('othersettings'),
329                           _('Other'),
330                           _('Other options'),
331                           $actionName == 'othersettings');
332
333         Event::handle('EndAccountSettingsNav', array(&$action));
334         
335         if (common_config('xmpp', 'enabled')) {
336             $action->menuItem(common_local_url('imsettings'),
337                               _m('IM'),
338                               _('Updates by instant messenger (IM)'),
339                               $actionName == 'imsettings');
340         }
341
342         if (common_config('sms', 'enabled')) {
343             $action->menuItem(common_local_url('smssettings'),
344                               _m('SMS'),
345                               _('Updates by SMS'),
346                               $actionName == 'smssettings');
347         }
348
349         $action->menuItem(common_local_url('oauthconnectionssettings'),
350                           _('Connections'),
351                           _('Authorized connected applications'),
352                           $actionName == 'oauthconnectionsettings');
353
354         Event::handle('EndConnectSettingsNav', array(&$action));
355     }
356
357     /**
358      * Return version information for this plugin
359      *
360      * @param array &$versions Version info; add to this array
361      *
362      * @return boolean hook value
363      */
364
365     function onPluginVersion(&$versions)
366     {
367         $versions[] = array('name' => 'NewMenu',
368                             'version' => STATUSNET_VERSION,
369                             'author' => 'Evan Prodromou',
370                             'homepage' => 'http://status.net/wiki/Plugin:NewMenu',
371                             'description' =>
372                             _m('A preview of the new menu '.
373                                'layout in StatusNet 1.0.'));
374         return true;
375     }
376 }