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