]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - lib/action.php
Merge commit 'origin/0.9.x' into 0.9.x
[quix0rs-gnu-social.git] / lib / action.php
1 <?php
2 /**
3  * StatusNet, the distributed open-source microblogging tool
4  *
5  * Base class for all actions (~views)
6  *
7  * PHP version 5
8  *
9  * LICENCE: This program is free software: you can redistribute it and/or modify
10  * it under the terms of the GNU Affero General Public License as published by
11  * the Free Software Foundation, either version 3 of the License, or
12  * (at your option) any later version.
13  *
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17  * GNU Affero General Public License for more details.
18  *
19  * You should have received a copy of the GNU Affero General Public License
20  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
21  *
22  * @category  Action
23  * @package   StatusNet
24  * @author    Evan Prodromou <evan@status.net>
25  * @author    Sarven Capadisli <csarven@status.net>
26  * @copyright 2008 StatusNet, Inc.
27  * @license   http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
28  * @link      http://status.net/
29  */
30
31 if (!defined('STATUSNET') && !defined('LACONICA')) {
32     exit(1);
33 }
34
35 require_once INSTALLDIR.'/lib/noticeform.php';
36 require_once INSTALLDIR.'/lib/htmloutputter.php';
37
38 /**
39  * Base class for all actions
40  *
41  * This is the base class for all actions in the package. An action is
42  * more or less a "view" in an MVC framework.
43  *
44  * Actions are responsible for extracting and validating parameters; using
45  * model classes to read and write to the database; and doing ouput.
46  *
47  * @category Output
48  * @package  StatusNet
49  * @author   Evan Prodromou <evan@status.net>
50  * @author   Sarven Capadisli <csarven@status.net>
51  * @license  http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
52  * @link     http://status.net/
53  *
54  * @see      HTMLOutputter
55  */
56 class Action extends HTMLOutputter // lawsuit
57 {
58     var $args;
59
60     /**
61      * Constructor
62      *
63      * Just wraps the HTMLOutputter constructor.
64      *
65      * @param string  $output URI to output to, default = stdout
66      * @param boolean $indent Whether to indent output, default true
67      *
68      * @see XMLOutputter::__construct
69      * @see HTMLOutputter::__construct
70      */
71     function __construct($output='php://output', $indent=null)
72     {
73         parent::__construct($output, $indent);
74     }
75
76     /**
77      * For initializing members of the class.
78      *
79      * @param array $argarray misc. arguments
80      *
81      * @return boolean true
82      */
83     function prepare($argarray)
84     {
85         $this->args =& common_copy_args($argarray);
86         return true;
87     }
88
89     /**
90      * Show page, a template method.
91      *
92      * @return nothing
93      */
94     function showPage()
95     {
96         if (Event::handle('StartShowHTML', array($this))) {
97             $this->startHTML();
98             Event::handle('EndShowHTML', array($this));
99         }
100         if (Event::handle('StartShowHead', array($this))) {
101             $this->showHead();
102             Event::handle('EndShowHead', array($this));
103         }
104         if (Event::handle('StartShowBody', array($this))) {
105             $this->showBody();
106             Event::handle('EndShowBody', array($this));
107         }
108         if (Event::handle('StartEndHTML', array($this))) {
109             $this->endHTML();
110             Event::handle('EndEndHTML', array($this));
111         }
112     }
113
114     /**
115      * Show head, a template method.
116      *
117      * @return nothing
118      */
119     function showHead()
120     {
121         // XXX: attributes (profile?)
122         $this->elementStart('head');
123         if (Event::handle('StartShowHeadElements', array($this))) {
124             $this->showTitle();
125             $this->showShortcutIcon();
126             $this->showStylesheets();
127             $this->showOpenSearch();
128             $this->showFeeds();
129             $this->showDescription();
130             $this->extraHead();
131             Event::handle('EndShowHeadElements', array($this));
132         }
133         $this->elementEnd('head');
134     }
135
136     /**
137      * Show title, a template method.
138      *
139      * @return nothing
140      */
141     function showTitle()
142     {
143         $this->element('title', null,
144                        // TRANS: Page title. %1$s is the title, %2$s is the site name.
145                        sprintf(_("%1\$s - %2\$s"),
146                                $this->title(),
147                                common_config('site', 'name')));
148     }
149
150     /**
151      * Returns the page title
152      *
153      * SHOULD overload
154      *
155      * @return string page title
156      */
157
158     function title()
159     {
160         // TRANS: Page title for a page without a title set.
161         return _("Untitled page");
162     }
163
164     /**
165      * Show themed shortcut icon
166      *
167      * @return nothing
168      */
169     function showShortcutIcon()
170     {
171         if (is_readable(INSTALLDIR . '/theme/' . common_config('site', 'theme') . '/favicon.ico')) {
172             $this->element('link', array('rel' => 'shortcut icon',
173                                          'href' => Theme::path('favicon.ico')));
174         } else {
175             $this->element('link', array('rel' => 'shortcut icon',
176                                          'href' => common_path('favicon.ico')));
177         }
178
179         if (common_config('site', 'mobile')) {
180             if (is_readable(INSTALLDIR . '/theme/' . common_config('site', 'theme') . '/apple-touch-icon.png')) {
181                 $this->element('link', array('rel' => 'apple-touch-icon',
182                                              'href' => Theme::path('apple-touch-icon.png')));
183             } else {
184                 $this->element('link', array('rel' => 'apple-touch-icon',
185                                              'href' => common_path('apple-touch-icon.png')));
186             }
187         }
188     }
189
190     /**
191      * Show stylesheets
192      *
193      * @return nothing
194      */
195     function showStylesheets()
196     {
197         if (Event::handle('StartShowStyles', array($this))) {
198
199             // Use old name for StatusNet for compatibility on events
200
201             if (Event::handle('StartShowStatusNetStyles', array($this)) &&
202                 Event::handle('StartShowLaconicaStyles', array($this))) {
203                 $this->cssLink('css/display.css',null, 'screen, projection, tv, print');
204                 Event::handle('EndShowStatusNetStyles', array($this));
205                 Event::handle('EndShowLaconicaStyles', array($this));
206             }
207
208             if (Event::handle('StartShowUAStyles', array($this))) {
209                 $this->comment('[if IE]><link rel="stylesheet" type="text/css" '.
210                                'href="'.Theme::path('css/ie.css', 'base').'?version='.STATUSNET_VERSION.'" /><![endif]');
211                 foreach (array(6,7) as $ver) {
212                     if (file_exists(Theme::file('css/ie'.$ver.'.css', 'base'))) {
213                         // Yes, IE people should be put in jail.
214                         $this->comment('[if lte IE '.$ver.']><link rel="stylesheet" type="text/css" '.
215                                        'href="'.Theme::path('css/ie'.$ver.'.css', 'base').'?version='.STATUSNET_VERSION.'" /><![endif]');
216                     }
217                 }
218                 $this->comment('[if IE]><link rel="stylesheet" type="text/css" '.
219                                'href="'.Theme::path('css/ie.css', null).'?version='.STATUSNET_VERSION.'" /><![endif]');
220                 Event::handle('EndShowUAStyles', array($this));
221             }
222
223             if (Event::handle('StartShowDesign', array($this))) {
224
225                 $user = common_current_user();
226
227                 if (empty($user) || $user->viewdesigns) {
228                     $design = $this->getDesign();
229
230                     if (!empty($design)) {
231                         $design->showCSS($this);
232                     }
233                 }
234
235                 Event::handle('EndShowDesign', array($this));
236             }
237             Event::handle('EndShowStyles', array($this));
238             
239             if (common_config('custom_css', 'enabled')) {
240                 $css = common_config('custom_css', 'css');
241                 if (Event::handle('StartShowCustomCss', array($this, &$css))) {
242                     if (trim($css) != '') {
243                         $this->style($css);
244                     }
245                     Event::handle('EndShowCustomCss', array($this));
246                 }
247             }
248         }
249     }
250
251     /**
252      * Show javascript headers
253      *
254      * @return nothing
255      */
256     function showScripts()
257     {
258         if (Event::handle('StartShowScripts', array($this))) {
259             if (Event::handle('StartShowJQueryScripts', array($this))) {
260                 $this->script('jquery.min.js');
261                 $this->script('jquery.form.js');
262                 $this->script('jquery.cookie.js');
263                 $this->inlineScript('if (typeof window.JSON !== "object") { $.getScript("'.common_path('js/json2.js').'"); }');
264                 $this->script('jquery.joverlay.min.js');
265                 Event::handle('EndShowJQueryScripts', array($this));
266             }
267             if (Event::handle('StartShowStatusNetScripts', array($this)) &&
268                 Event::handle('StartShowLaconicaScripts', array($this))) {
269                 $this->script('xbImportNode.js');
270                 $this->script('util.js');
271                 $this->script('geometa.js');
272                 // Frame-busting code to avoid clickjacking attacks.
273                 $this->inlineScript('if (window.top !== window.self) { window.top.location.href = window.self.location.href; }');
274                 Event::handle('EndShowStatusNetScripts', array($this));
275                 Event::handle('EndShowLaconicaScripts', array($this));
276             }
277             Event::handle('EndShowScripts', array($this));
278         }
279     }
280
281     /**
282      * Show OpenSearch headers
283      *
284      * @return nothing
285      */
286     function showOpenSearch()
287     {
288         $this->element('link', array('rel' => 'search',
289                                      'type' => 'application/opensearchdescription+xml',
290                                      'href' =>  common_local_url('opensearch', array('type' => 'people')),
291                                      'title' => common_config('site', 'name').' People Search'));
292         $this->element('link', array('rel' => 'search', 'type' => 'application/opensearchdescription+xml',
293                                      'href' =>  common_local_url('opensearch', array('type' => 'notice')),
294                                      'title' => common_config('site', 'name').' Notice Search'));
295     }
296
297     /**
298      * Show feed headers
299      *
300      * MAY overload
301      *
302      * @return nothing
303      */
304
305     function showFeeds()
306     {
307         $feeds = $this->getFeeds();
308
309         if ($feeds) {
310             foreach ($feeds as $feed) {
311                 $this->element('link', array('rel' => $feed->rel(),
312                                              'href' => $feed->url,
313                                              'type' => $feed->mimeType(),
314                                              'title' => $feed->title));
315             }
316         }
317     }
318
319     /**
320      * Show description.
321      *
322      * SHOULD overload
323      *
324      * @return nothing
325      */
326     function showDescription()
327     {
328         // does nothing by default
329     }
330
331     /**
332      * Show extra stuff in <head>.
333      *
334      * MAY overload
335      *
336      * @return nothing
337      */
338     function extraHead()
339     {
340         // does nothing by default
341     }
342
343     /**
344      * Show body.
345      *
346      * Calls template methods
347      *
348      * @return nothing
349      */
350     function showBody()
351     {
352         $this->elementStart('body', (common_current_user()) ? array('id' => $this->trimmed('action'),
353                                                                     'class' => 'user_in')
354                             : array('id' => $this->trimmed('action')));
355         $this->elementStart('div', array('id' => 'wrap'));
356         if (Event::handle('StartShowHeader', array($this))) {
357             $this->showHeader();
358             Event::handle('EndShowHeader', array($this));
359         }
360         $this->showCore();
361         if (Event::handle('StartShowFooter', array($this))) {
362             $this->showFooter();
363             Event::handle('EndShowFooter', array($this));
364         }
365         $this->elementEnd('div');
366         $this->showScripts();
367         $this->elementEnd('body');
368     }
369
370     /**
371      * Show header of the page.
372      *
373      * Calls template methods
374      *
375      * @return nothing
376      */
377     function showHeader()
378     {
379         $this->elementStart('div', array('id' => 'header'));
380         $this->showLogo();
381         $this->showPrimaryNav();
382         if (Event::handle('StartShowSiteNotice', array($this))) {
383             $this->showSiteNotice();
384
385             Event::handle('EndShowSiteNotice', array($this));
386         }
387         if (common_logged_in()) {
388             $this->showNoticeForm();
389         } else {
390             $this->showAnonymousMessage();
391         }
392         $this->elementEnd('div');
393     }
394
395     /**
396      * Show configured logo.
397      *
398      * @return nothing
399      */
400     function showLogo()
401     {
402         $this->elementStart('address', array('id' => 'site_contact',
403                                              'class' => 'vcard'));
404         if (Event::handle('StartAddressData', array($this))) {
405             if (common_config('singleuser', 'enabled')) {
406                 $url = common_local_url('showstream',
407                                         array('nickname' => common_config('singleuser', 'nickname')));
408             } else {
409                 $url = common_local_url('public');
410             }
411             $this->elementStart('a', array('class' => 'url home bookmark',
412                                            'href' => $url));
413             if (common_config('site', 'logo') || file_exists(Theme::file('logo.png'))) {
414                 $this->element('img', array('class' => 'logo photo',
415                                             'src' => (common_config('site', 'logo')) ? common_config('site', 'logo') : Theme::path('logo.png'),
416                                             'alt' => common_config('site', 'name')));
417             }
418             $this->text(' ');
419             $this->element('span', array('class' => 'fn org'), common_config('site', 'name'));
420             $this->elementEnd('a');
421             Event::handle('EndAddressData', array($this));
422         }
423         $this->elementEnd('address');
424     }
425
426     /**
427      * Show primary navigation.
428      *
429      * @return nothing
430      */
431     function showPrimaryNav()
432     {
433         $user = common_current_user();
434         $this->elementStart('dl', array('id' => 'site_nav_global_primary'));
435         // TRANS: DT element for primary navigation menu. String is hidden in default CSS.
436         $this->element('dt', null, _('Primary site navigation'));
437         $this->elementStart('dd');
438         $this->elementStart('ul', array('class' => 'nav'));
439         if (Event::handle('StartPrimaryNav', array($this))) {
440             if ($user) {
441                 // TRANS: Tooltip for main menu option "Personal"
442                 $tooltip = _m('TOOLTIP', 'Personal profile and friends timeline');
443                 $this->menuItem(common_local_url('all', array('nickname' => $user->nickname)),
444                                 // TRANS: Main menu option when logged in for access to personal profile and friends timeline
445                                 _m('MENU', 'Personal'), $tooltip, false, 'nav_home');
446                 // TRANS: Tooltip for main menu option "Account"
447                 $tooltip = _m('TOOLTIP', 'Change your email, avatar, password, profile');
448                 $this->menuItem(common_local_url('profilesettings'),
449                                 // TRANS: Main menu option when logged in for access to user settings
450                                 _('Account'), $tooltip, false, 'nav_account');
451                 // TRANS: Tooltip for main menu option "Services"
452                 $tooltip = _m('TOOLTIP', 'Connect to services');
453                 $this->menuItem(common_local_url('oauthconnectionssettings'),
454                                 // TRANS: Main menu option when logged in and connection are possible for access to options to connect to other services
455                                 _('Connect'), $tooltip, false, 'nav_connect');
456                 if ($user->hasRight(Right::CONFIGURESITE)) {
457                     // TRANS: Tooltip for menu option "Admin"
458                     $tooltip = _m('TOOLTIP', 'Change site configuration');
459                     $this->menuItem(common_local_url('siteadminpanel'),
460                                     // TRANS: Main menu option when logged in and site admin for access to site configuration
461                                     _m('MENU', 'Admin'), $tooltip, false, 'nav_admin');
462                 }
463                 if (common_config('invite', 'enabled')) {
464                     // TRANS: Tooltip for main menu option "Invite"
465                     $tooltip = _m('TOOLTIP', 'Invite friends and colleagues to join you on %s');
466                     $this->menuItem(common_local_url('invite'),
467                                     // TRANS: Main menu option when logged in and invitations are allowed for inviting new users
468                                     _m('MENU', 'Invite'),
469                                     sprintf($tooltip,
470                                             common_config('site', 'name')),
471                                     false, 'nav_invitecontact');
472                 }
473                 // TRANS: Tooltip for main menu option "Logout"
474                 $tooltip = _m('TOOLTIP', 'Logout from the site');
475                 $this->menuItem(common_local_url('logout'),
476                                 // TRANS: Main menu option when logged in to log out the current user
477                                 _m('MENU', 'Logout'), $tooltip, false, 'nav_logout');
478             }
479             else {
480                 if (!common_config('site', 'closed') && !common_config('site', 'inviteonly')) {
481                     // TRANS: Tooltip for main menu option "Register"
482                     $tooltip = _m('TOOLTIP', 'Create an account');
483                     $this->menuItem(common_local_url('register'),
484                                     // TRANS: Main menu option when not logged in to register a new account
485                                     _m('MENU', 'Register'), $tooltip, false, 'nav_register');
486                 }
487                 // TRANS: Tooltip for main menu option "Login"
488                 $tooltip = _m('TOOLTIP', 'Login to the site');
489                 // TRANS: Main menu option when not logged in to log in
490                 $this->menuItem(common_local_url('login'),
491                                 _m('MENU', 'Login'), $tooltip, false, 'nav_login');
492             }
493             // TRANS: Tooltip for main menu option "Help"
494             $tooltip = _m('TOOLTIP', 'Help me!');
495             // TRANS: Main menu option for help on the StatusNet site
496             $this->menuItem(common_local_url('doc', array('title' => 'help')),
497                             _m('MENU', 'Help'), $tooltip, false, 'nav_help');
498             if ($user || !common_config('site', 'private')) {
499                 // TRANS: Tooltip for main menu option "Search"
500                 $tooltip = _m('TOOLTIP', 'Search for people or text');
501                 // TRANS: Main menu option when logged in or when the StatusNet instance is not private
502                 $this->menuItem(common_local_url('peoplesearch'),
503                                 _m('MENU', 'Search'), $tooltip, false, 'nav_search');
504             }
505             Event::handle('EndPrimaryNav', array($this));
506         }
507         $this->elementEnd('ul');
508         $this->elementEnd('dd');
509         $this->elementEnd('dl');
510     }
511
512     /**
513      * Show site notice.
514      *
515      * @return nothing
516      */
517     function showSiteNotice()
518     {
519         // Revist. Should probably do an hAtom pattern here
520         $text = common_config('site', 'notice');
521         if ($text) {
522             $this->elementStart('dl', array('id' => 'site_notice',
523                                             'class' => 'system_notice'));
524             // TRANS: DT element for site notice. String is hidden in default CSS.
525             $this->element('dt', null, _('Site notice'));
526             $this->elementStart('dd', null);
527             $this->raw($text);
528             $this->elementEnd('dd');
529             $this->elementEnd('dl');
530         }
531     }
532
533     /**
534      * Show notice form.
535      *
536      * MAY overload if no notice form needed... or direct message box????
537      *
538      * @return nothing
539      */
540     function showNoticeForm()
541     {
542         $notice_form = new NoticeForm($this);
543         $notice_form->show();
544     }
545
546     /**
547      * Show anonymous message.
548      *
549      * SHOULD overload
550      *
551      * @return nothing
552      */
553     function showAnonymousMessage()
554     {
555         // needs to be defined by the class
556     }
557
558     /**
559      * Show core.
560      *
561      * Shows local navigation, content block and aside.
562      *
563      * @return nothing
564      */
565     function showCore()
566     {
567         $this->elementStart('div', array('id' => 'core'));
568         if (Event::handle('StartShowLocalNavBlock', array($this))) {
569             $this->showLocalNavBlock();
570             Event::handle('EndShowLocalNavBlock', array($this));
571         }
572         if (Event::handle('StartShowContentBlock', array($this))) {
573             $this->showContentBlock();
574             Event::handle('EndShowContentBlock', array($this));
575         }
576         if (Event::handle('StartShowAside', array($this))) {
577             $this->showAside();
578             Event::handle('EndShowAside', array($this));
579         }
580         $this->elementEnd('div');
581     }
582
583     /**
584      * Show local navigation block.
585      *
586      * @return nothing
587      */
588     function showLocalNavBlock()
589     {
590         $this->elementStart('dl', array('id' => 'site_nav_local_views'));
591         // TRANS: DT element for local views block. String is hidden in default CSS.
592         $this->element('dt', null, _('Local views'));
593         $this->elementStart('dd');
594         $this->showLocalNav();
595         $this->elementEnd('dd');
596         $this->elementEnd('dl');
597     }
598
599     /**
600      * Show local navigation.
601      *
602      * SHOULD overload
603      *
604      * @return nothing
605      */
606     function showLocalNav()
607     {
608         // does nothing by default
609     }
610
611     /**
612      * Show content block.
613      *
614      * @return nothing
615      */
616     function showContentBlock()
617     {
618         $this->elementStart('div', array('id' => 'content'));
619         $this->showPageTitle();
620         $this->showPageNoticeBlock();
621         $this->elementStart('div', array('id' => 'content_inner'));
622         // show the actual content (forms, lists, whatever)
623         $this->showContent();
624         $this->elementEnd('div');
625         $this->elementEnd('div');
626     }
627
628     /**
629      * Show page title.
630      *
631      * @return nothing
632      */
633     function showPageTitle()
634     {
635         $this->element('h1', null, $this->title());
636     }
637
638     /**
639      * Show page notice block.
640      *
641      * Only show the block if a subclassed action has overrided
642      * Action::showPageNotice(), or an event handler is registered for
643      * the StartShowPageNotice event, in which case we assume the
644      * 'page_notice' definition list is desired.  This is to prevent
645      * empty 'page_notice' definition lists from being output everywhere.
646      *
647      * @return nothing
648      */
649     function showPageNoticeBlock()
650     {
651         $rmethod = new ReflectionMethod($this, 'showPageNotice');
652         $dclass = $rmethod->getDeclaringClass()->getName();
653
654         if ($dclass != 'Action' || Event::hasHandler('StartShowPageNotice')) {
655
656             $this->elementStart('dl', array('id' => 'page_notice',
657                                             'class' => 'system_notice'));
658             // TRANS: DT element for page notice. String is hidden in default CSS.
659             $this->element('dt', null, _('Page notice'));
660             $this->elementStart('dd');
661             if (Event::handle('StartShowPageNotice', array($this))) {
662                 $this->showPageNotice();
663                 Event::handle('EndShowPageNotice', array($this));
664             }
665             $this->elementEnd('dd');
666             $this->elementEnd('dl');
667         }
668     }
669
670     /**
671      * Show page notice.
672      *
673      * SHOULD overload (unless there's not a notice)
674      *
675      * @return nothing
676      */
677     function showPageNotice()
678     {
679     }
680
681     /**
682      * Show content.
683      *
684      * MUST overload (unless there's not a notice)
685      *
686      * @return nothing
687      */
688     function showContent()
689     {
690     }
691
692     /**
693      * Show Aside.
694      *
695      * @return nothing
696      */
697
698     function showAside()
699     {
700         $this->elementStart('div', array('id' => 'aside_primary',
701                                          'class' => 'aside'));
702         if (Event::handle('StartShowExportData', array($this))) {
703             $this->showExportData();
704             Event::handle('EndShowExportData', array($this));
705         }
706         if (Event::handle('StartShowSections', array($this))) {
707             $this->showSections();
708             Event::handle('EndShowSections', array($this));
709         }
710         $this->elementEnd('div');
711     }
712
713     /**
714      * Show export data feeds.
715      *
716      * @return void
717      */
718
719     function showExportData()
720     {
721         $feeds = $this->getFeeds();
722         if ($feeds) {
723             $fl = new FeedList($this);
724             $fl->show($feeds);
725         }
726     }
727
728     /**
729      * Show sections.
730      *
731      * SHOULD overload
732      *
733      * @return nothing
734      */
735     function showSections()
736     {
737         // for each section, show it
738     }
739
740     /**
741      * Show footer.
742      *
743      * @return nothing
744      */
745     function showFooter()
746     {
747         $this->elementStart('div', array('id' => 'footer'));
748         $this->showSecondaryNav();
749         $this->showLicenses();
750         $this->elementEnd('div');
751     }
752
753     /**
754      * Show secondary navigation.
755      *
756      * @return nothing
757      */
758     function showSecondaryNav()
759     {
760         $this->elementStart('dl', array('id' => 'site_nav_global_secondary'));
761         // TRANS: DT element for secondary navigation menu. String is hidden in default CSS.
762         $this->element('dt', null, _('Secondary site navigation'));
763         $this->elementStart('dd', null);
764         $this->elementStart('ul', array('class' => 'nav'));
765         if (Event::handle('StartSecondaryNav', array($this))) {
766             $this->menuItem(common_local_url('doc', array('title' => 'help')),
767                             // TRANS: Secondary navigation menu option leading to help on StatusNet.
768                             _('Help'));
769             $this->menuItem(common_local_url('doc', array('title' => 'about')),
770                             // TRANS: Secondary navigation menu option leading to text about StatusNet site.
771                             _('About'));
772             $this->menuItem(common_local_url('doc', array('title' => 'faq')),
773                             // TRANS: Secondary navigation menu option leading to Frequently Asked Questions.
774                             _('FAQ'));
775             $bb = common_config('site', 'broughtby');
776             if (!empty($bb)) {
777                 $this->menuItem(common_local_url('doc', array('title' => 'tos')),
778                                 // TRANS: Secondary navigation menu option leading to Terms of Service.
779                                 _('TOS'));
780             }
781             $this->menuItem(common_local_url('doc', array('title' => 'privacy')),
782                             // TRANS: Secondary navigation menu option leading to privacy policy.
783                             _('Privacy'));
784             $this->menuItem(common_local_url('doc', array('title' => 'source')),
785                             // TRANS: Secondary navigation menu option.
786                             _('Source'));
787             $this->menuItem(common_local_url('version'),
788                             // TRANS: Secondary navigation menu option leading to version information on the StatusNet site.
789                             _('Version'));
790             $this->menuItem(common_local_url('doc', array('title' => 'contact')),
791                             // TRANS: Secondary navigation menu option leading to contact information on the StatusNet site.
792                             _('Contact'));
793             $this->menuItem(common_local_url('doc', array('title' => 'badge')),
794                             _('Badge'));
795             Event::handle('EndSecondaryNav', array($this));
796         }
797         $this->elementEnd('ul');
798         $this->elementEnd('dd');
799         $this->elementEnd('dl');
800     }
801
802     /**
803      * Show licenses.
804      *
805      * @return nothing
806      */
807     function showLicenses()
808     {
809         $this->elementStart('dl', array('id' => 'licenses'));
810         $this->showStatusNetLicense();
811         $this->showContentLicense();
812         $this->elementEnd('dl');
813     }
814
815     /**
816      * Show StatusNet license.
817      *
818      * @return nothing
819      */
820     function showStatusNetLicense()
821     {
822         // TRANS: DT element for StatusNet software license.
823         $this->element('dt', array('id' => 'site_statusnet_license'), _('StatusNet software license'));
824         $this->elementStart('dd', null);
825         if (common_config('site', 'broughtby')) {
826             // TRANS: First sentence of the StatusNet site license. Used if 'broughtby' is set.
827             $instr = _('**%%site.name%%** is a microblogging service brought to you by [%%site.broughtby%%](%%site.broughtbyurl%%).');
828         } else {
829             // TRANS: First sentence of the StatusNet site license. Used if 'broughtby' is not set.
830             $instr = _('**%%site.name%%** is a microblogging service.');
831         }
832         $instr .= ' ';
833         // TRANS: Second sentence of the StatusNet site license. Mentions the StatusNet source code license.
834         $instr .= sprintf(_('It runs the [StatusNet](http://status.net/) microblogging software, version %s, available under the [GNU Affero General Public License](http://www.fsf.org/licensing/licenses/agpl-3.0.html).'), STATUSNET_VERSION);
835         $output = common_markup_to_html($instr);
836         $this->raw($output);
837         $this->elementEnd('dd');
838         // do it
839     }
840
841     /**
842      * Show content license.
843      *
844      * @return nothing
845      */
846     function showContentLicense()
847     {
848         if (Event::handle('StartShowContentLicense', array($this))) {
849             // TRANS: DT element for StatusNet site content license.
850             $this->element('dt', array('id' => 'site_content_license'), _('Site content license'));
851             $this->elementStart('dd', array('id' => 'site_content_license_cc'));
852
853             switch (common_config('license', 'type')) {
854             case 'private':
855                 // TRANS: Content license displayed when license is set to 'private'.
856                 // TRANS: %1$s is the site name.
857                 $this->element('p', null, sprintf(_('Content and data of %1$s are private and confidential.'),
858                                                   common_config('site', 'name')));
859                 // fall through
860             case 'allrightsreserved':
861                 if (common_config('license', 'owner')) {
862                     // TRANS: Content license displayed when license is set to 'allrightsreserved'.
863                     // TRANS: %1$s is the copyright owner.
864                     $this->element('p', null, sprintf(_('Content and data copyright by %1$s. All rights reserved.'),
865                                                       common_config('license', 'owner')));
866                 } else {
867                     // TRANS: Content license displayed when license is set to 'allrightsreserved' and no owner is set.
868                     $this->element('p', null, _('Content and data copyright by contributors. All rights reserved.'));
869                 }
870                 break;
871             case 'cc': // fall through
872             default:
873                 $this->elementStart('p');
874                 $this->element('img', array('id' => 'license_cc',
875                                             'src' => common_config('license', 'image'),
876                                             'alt' => common_config('license', 'title'),
877                                             'width' => '80',
878                                             'height' => '15'));
879                 $this->text(' ');
880                 // TRANS: license message in footer. %1$s is the site name, %2$s is a link to the license URL, with a licence name set in configuration.
881                 $notice = _('All %1$s content and data are available under the %2$s license.');
882                 $link = "<a class=\"license\" rel=\"external license\" href=\"" .
883                         htmlspecialchars(common_config('license', 'url')) .
884                         "\">" .
885                         htmlspecialchars(common_config('license', 'title')) .
886                         "</a>";
887                 $this->raw(sprintf(htmlspecialchars($notice),
888                                    htmlspecialchars(common_config('site', 'name')),
889                                    $link));
890                 $this->elementEnd('p');
891                 break;
892             }
893
894             $this->elementEnd('dd');
895             Event::handle('EndShowContentLicense', array($this));
896         }
897     }
898
899     /**
900      * Return last modified, if applicable.
901      *
902      * MAY override
903      *
904      * @return string last modified http header
905      */
906     function lastModified()
907     {
908         // For comparison with If-Last-Modified
909         // If not applicable, return null
910         return null;
911     }
912
913     /**
914      * Return etag, if applicable.
915      *
916      * MAY override
917      *
918      * @return string etag http header
919      */
920     function etag()
921     {
922         return null;
923     }
924
925     /**
926      * Return true if read only.
927      *
928      * MAY override
929      *
930      * @param array $args other arguments
931      *
932      * @return boolean is read only action?
933      */
934
935     function isReadOnly($args)
936     {
937         return false;
938     }
939
940     /**
941      * Returns query argument or default value if not found
942      *
943      * @param string $key requested argument
944      * @param string $def default value to return if $key is not provided
945      *
946      * @return boolean is read only action?
947      */
948     function arg($key, $def=null)
949     {
950         if (array_key_exists($key, $this->args)) {
951             return $this->args[$key];
952         } else {
953             return $def;
954         }
955     }
956
957     /**
958      * Returns trimmed query argument or default value if not found
959      *
960      * @param string $key requested argument
961      * @param string $def default value to return if $key is not provided
962      *
963      * @return boolean is read only action?
964      */
965     function trimmed($key, $def=null)
966     {
967         $arg = $this->arg($key, $def);
968         return is_string($arg) ? trim($arg) : $arg;
969     }
970
971     /**
972      * Handler method
973      *
974      * @param array $argarray is ignored since it's now passed in in prepare()
975      *
976      * @return boolean is read only action?
977      */
978     function handle($argarray=null)
979     {
980         header('Vary: Accept-Encoding,Cookie');
981         $lm   = $this->lastModified();
982         $etag = $this->etag();
983         if ($etag) {
984             header('ETag: ' . $etag);
985         }
986         if ($lm) {
987             header('Last-Modified: ' . date(DATE_RFC1123, $lm));
988             if (array_key_exists('HTTP_IF_MODIFIED_SINCE', $_SERVER)) {
989                 $if_modified_since = $_SERVER['HTTP_IF_MODIFIED_SINCE'];
990                 $ims = strtotime($if_modified_since);
991                 if ($lm <= $ims) {
992                     $if_none_match = (array_key_exists('HTTP_IF_NONE_MATCH', $_SERVER)) ?
993                       $_SERVER['HTTP_IF_NONE_MATCH'] : null;
994                     if (!$if_none_match ||
995                         !$etag ||
996                         $this->_hasEtag($etag, $if_none_match)) {
997                         header('HTTP/1.1 304 Not Modified');
998                         // Better way to do this?
999                         exit(0);
1000                     }
1001                 }
1002             }
1003         }
1004     }
1005
1006     /**
1007      * HasĀ etag? (private)
1008      *
1009      * @param string $etag          etag http header
1010      * @param string $if_none_match ifNoneMatch http header
1011      *
1012      * @return boolean
1013      */
1014
1015     function _hasEtag($etag, $if_none_match)
1016     {
1017         $etags = explode(',', $if_none_match);
1018         return in_array($etag, $etags) || in_array('*', $etags);
1019     }
1020
1021     /**
1022      * Boolean understands english (yes, no, true, false)
1023      *
1024      * @param string $key query key we're interested in
1025      * @param string $def default value
1026      *
1027      * @return boolean interprets yes/no strings as boolean
1028      */
1029     function boolean($key, $def=false)
1030     {
1031         $arg = strtolower($this->trimmed($key));
1032
1033         if (is_null($arg)) {
1034             return $def;
1035         } else if (in_array($arg, array('true', 'yes', '1', 'on'))) {
1036             return true;
1037         } else if (in_array($arg, array('false', 'no', '0'))) {
1038             return false;
1039         } else {
1040             return $def;
1041         }
1042     }
1043
1044     /**
1045      * Integer value of an argument
1046      *
1047      * @param string $key      query key we're interested in
1048      * @param string $defValue optional default value (default null)
1049      * @param string $maxValue optional max value (default null)
1050      * @param string $minValue optional min value (default null)
1051      *
1052      * @return integer integer value
1053      */
1054
1055     function int($key, $defValue=null, $maxValue=null, $minValue=null)
1056     {
1057         $arg = strtolower($this->trimmed($key));
1058
1059         if (is_null($arg) || !is_integer($arg)) {
1060             return $defValue;
1061         }
1062
1063         if (!is_null($maxValue)) {
1064             $arg = min($arg, $maxValue);
1065         }
1066
1067         if (!is_null($minValue)) {
1068             $arg = max($arg, $minValue);
1069         }
1070
1071         return $arg;
1072     }
1073
1074     /**
1075      * Server error
1076      *
1077      * @param string  $msg  error message to display
1078      * @param integer $code http error code, 500 by default
1079      *
1080      * @return nothing
1081      */
1082
1083     function serverError($msg, $code=500)
1084     {
1085         $action = $this->trimmed('action');
1086         common_debug("Server error '$code' on '$action': $msg", __FILE__);
1087         throw new ServerException($msg, $code);
1088     }
1089
1090     /**
1091      * Client error
1092      *
1093      * @param string  $msg  error message to display
1094      * @param integer $code http error code, 400 by default
1095      *
1096      * @return nothing
1097      */
1098
1099     function clientError($msg, $code=400)
1100     {
1101         $action = $this->trimmed('action');
1102         common_debug("User error '$code' on '$action': $msg", __FILE__);
1103         throw new ClientException($msg, $code);
1104     }
1105
1106     /**
1107      * Returns the current URL
1108      *
1109      * @return string current URL
1110      */
1111
1112     function selfUrl()
1113     {
1114         list($action, $args) = $this->returnToArgs();
1115         return common_local_url($action, $args);
1116     }
1117
1118     /**
1119      * Returns arguments sufficient for re-constructing URL
1120      *
1121      * @return array two elements: action, other args
1122      */
1123
1124     function returnToArgs()
1125     {
1126         $action = $this->trimmed('action');
1127         $args   = $this->args;
1128         unset($args['action']);
1129         if (common_config('site', 'fancy')) {
1130             unset($args['p']);
1131         }
1132         if (array_key_exists('submit', $args)) {
1133             unset($args['submit']);
1134         }
1135         foreach (array_keys($_COOKIE) as $cookie) {
1136             unset($args[$cookie]);
1137         }
1138         return array($action, $args);
1139     }
1140
1141     /**
1142      * Generate a menu item
1143      *
1144      * @param string  $url         menu URL
1145      * @param string  $text        menu name
1146      * @param string  $title       title attribute, null by default
1147      * @param boolean $is_selected current menu item, false by default
1148      * @param string  $id          element id, null by default
1149      *
1150      * @return nothing
1151      */
1152     function menuItem($url, $text, $title=null, $is_selected=false, $id=null)
1153     {
1154         // Added @id to li for some control.
1155         // XXX: We might want to move this to htmloutputter.php
1156         $lattrs = array();
1157         if ($is_selected) {
1158             $lattrs['class'] = 'current';
1159         }
1160
1161         (is_null($id)) ? $lattrs : $lattrs['id'] = $id;
1162
1163         $this->elementStart('li', $lattrs);
1164         $attrs['href'] = $url;
1165         if ($title) {
1166             $attrs['title'] = $title;
1167         }
1168         $this->element('a', $attrs, $text);
1169         $this->elementEnd('li');
1170     }
1171
1172     /**
1173      * Generate pagination links
1174      *
1175      * @param boolean $have_before is there something before?
1176      * @param boolean $have_after  is there something after?
1177      * @param integer $page        current page
1178      * @param string  $action      current action
1179      * @param array   $args        rest of query arguments
1180      *
1181      * @return nothing
1182      */
1183     // XXX: The messages in this pagination method only tailor to navigating
1184     //      notices. In other lists, "Previous"/"Next" type navigation is
1185     //      desirable, but not available.
1186     function pagination($have_before, $have_after, $page, $action, $args=null)
1187     {
1188         // Does a little before-after block for next/prev page
1189         if ($have_before || $have_after) {
1190             $this->elementStart('dl', 'pagination');
1191             // TRANS: DT element for pagination (previous/next, etc.).
1192             $this->element('dt', null, _('Pagination'));
1193             $this->elementStart('dd', null);
1194             $this->elementStart('ul', array('class' => 'nav'));
1195         }
1196         if ($have_before) {
1197             $pargs   = array('page' => $page-1);
1198             $this->elementStart('li', array('class' => 'nav_prev'));
1199             $this->element('a', array('href' => common_local_url($action, $args, $pargs),
1200                                       'rel' => 'prev'),
1201                            // TRANS: Pagination message to go to a page displaying information more in the
1202                            // TRANS: present than the currently displayed information.
1203                            _('After'));
1204             $this->elementEnd('li');
1205         }
1206         if ($have_after) {
1207             $pargs   = array('page' => $page+1);
1208             $this->elementStart('li', array('class' => 'nav_next'));
1209             $this->element('a', array('href' => common_local_url($action, $args, $pargs),
1210                                       'rel' => 'next'),
1211                            // TRANS: Pagination message to go to a page displaying information more in the
1212                            // TRANS: past than the currently displayed information.
1213                            _('Before'));
1214             $this->elementEnd('li');
1215         }
1216         if ($have_before || $have_after) {
1217             $this->elementEnd('ul');
1218             $this->elementEnd('dd');
1219             $this->elementEnd('dl');
1220         }
1221     }
1222
1223     /**
1224      * An array of feeds for this action.
1225      *
1226      * Returns an array of potential feeds for this action.
1227      *
1228      * @return array Feed object to show in head and links
1229      */
1230
1231     function getFeeds()
1232     {
1233         return null;
1234     }
1235
1236     /**
1237      * A design for this action
1238      *
1239      * @return Design a design object to use
1240      */
1241
1242     function getDesign()
1243     {
1244         return Design::siteDesign();
1245     }
1246
1247     /**
1248      * Check the session token.
1249      *
1250      * Checks that the current form has the correct session token,
1251      * and throw an exception if it does not.
1252      *
1253      * @return void
1254      */
1255
1256     // XXX: Finding this type of check with the same message about 50 times.
1257     //      Possible to refactor?
1258     function checkSessionToken()
1259     {
1260         // CSRF protection
1261         $token = $this->trimmed('token');
1262         if (empty($token) || $token != common_session_token()) {
1263             $this->clientError(_('There was a problem with your session token.'));
1264         }
1265     }
1266 }