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