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