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