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