]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - lib/action.php
Minor labeling things for StatusNet to GNU social migration
[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('GNUSOCIAL')) { exit(1); }
32
33 /**
34  * Base class for all actions
35  *
36  * This is the base class for all actions in the package. An action is
37  * more or less a "view" in an MVC framework.
38  *
39  * Actions are responsible for extracting and validating parameters; using
40  * model classes to read and write to the database; and doing ouput.
41  *
42  * @category Output
43  * @package  StatusNet
44  * @author   Evan Prodromou <evan@status.net>
45  * @author   Sarven Capadisli <csarven@status.net>
46  * @license  http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
47  * @link     http://status.net/
48  *
49  * @see      HTMLOutputter
50  */
51 class Action extends HTMLOutputter // lawsuit
52 {
53     // This should be protected/private in the future
54     public $args = array();
55
56     // Action properties, set per-class
57     protected $action = false;
58     protected $ajax   = false;
59     protected $menus  = true;
60     protected $needLogin = false;
61     protected $needPost = false;
62
63     // The currently scoped profile (normally Profile::current; from $this->auth_user for API)
64     protected $scoped = null;
65
66     // Related to front-end user representation
67     protected $format = null;
68     protected $error  = null;
69     protected $msg    = null;
70
71     /**
72      * Constructor
73      *
74      * Just wraps the HTMLOutputter constructor.
75      *
76      * @param string  $output URI to output to, default = stdout
77      * @param boolean $indent Whether to indent output, default true
78      *
79      * @see XMLOutputter::__construct
80      * @see HTMLOutputter::__construct
81      */
82     function __construct($output='php://output', $indent=null)
83     {
84         parent::__construct($output, $indent);
85     }
86
87     function getError()
88     {
89         return $this->error;
90     }
91
92     function getInfo()
93     {
94         return $this->msg;
95     }
96
97     static public function run(array $args=array(), $output='php://output', $indent=null) {
98         $class = get_called_class();
99         $action = new $class($output, $indent);
100         $action->execute($args);
101         return $action;
102     }
103
104     public function execute(array $args=array()) {
105         // checkMirror stuff
106         if (common_config('db', 'mirror') && $this->isReadOnly($args)) {
107             if (is_array(common_config('db', 'mirror'))) {
108                 // "load balancing", ha ha
109                 $arr = common_config('db', 'mirror');
110                 $k = array_rand($arr);
111                 $mirror = $arr[$k];
112             } else {
113                 $mirror = common_config('db', 'mirror');
114             }
115
116             // everyone else uses the mirror
117             common_config_set('db', 'database', $mirror);
118         }
119
120         if ($this->prepare($args)) {
121             $this->handle($args);
122         }
123     }
124
125     /**
126      * For initializing members of the class.
127      *
128      * @param array $argarray misc. arguments
129      *
130      * @return boolean true
131      */
132     protected function prepare(array $args=array())
133     {
134         if ($this->needPost && !$this->isPost()) {
135             // TRANS: Client error. POST is a HTTP command. It should not be translated.
136             $this->clientError(_('This method requires a POST.'), 405);
137         }
138
139         $this->args = common_copy_args($args);
140
141         $this->action = $this->trimmed('action');
142
143         if ($this->ajax || $this->boolean('ajax')) {
144             // check with StatusNet::isAjax()
145             StatusNet::setAjax(true);
146         }
147
148         if ($this->needLogin) {
149             $this->checkLogin(); // if not logged in, this redirs/excepts
150         }
151
152         $this->updateScopedProfile();
153
154         return true;
155     }
156
157     function updateScopedProfile() {
158         $this->scoped = Profile::current();
159         return $this->scoped;
160     }
161
162     /**
163      * Show page, a template method.
164      *
165      * @return nothing
166      */
167     function showPage()
168     {
169         if (Event::handle('StartShowHTML', array($this))) {
170             $this->startHTML();
171             $this->flush();
172             Event::handle('EndShowHTML', array($this));
173         }
174         if (Event::handle('StartShowHead', array($this))) {
175             $this->showHead();
176             $this->flush();
177             Event::handle('EndShowHead', array($this));
178         }
179         if (Event::handle('StartShowBody', array($this))) {
180             $this->showBody();
181             Event::handle('EndShowBody', array($this));
182         }
183         if (Event::handle('StartEndHTML', array($this))) {
184             $this->endHTML();
185             Event::handle('EndEndHTML', array($this));
186         }
187     }
188
189     function endHTML()
190     {
191         global $_startTime;
192
193         if (isset($_startTime)) {
194             $endTime = microtime(true);
195             $diff = round(($endTime - $_startTime) * 1000);
196             $this->raw("<!-- ${diff}ms -->");
197         }
198
199         return parent::endHTML();
200     }
201
202     /**
203      * Show head, a template method.
204      *
205      * @return nothing
206      */
207     function showHead()
208     {
209         // XXX: attributes (profile?)
210         $this->elementStart('head');
211         if (Event::handle('StartShowHeadElements', array($this))) {
212             if (Event::handle('StartShowHeadTitle', array($this))) {
213                 $this->showTitle();
214                 Event::handle('EndShowHeadTitle', array($this));
215             }
216             $this->showShortcutIcon();
217             $this->showStylesheets();
218             $this->showOpenSearch();
219             $this->showFeeds();
220             $this->showDescription();
221             $this->extraHead();
222             Event::handle('EndShowHeadElements', array($this));
223         }
224         $this->elementEnd('head');
225     }
226
227     /**
228      * Show title, a template method.
229      *
230      * @return nothing
231      */
232     function showTitle()
233     {
234         $this->element('title', null,
235                        // TRANS: Page title. %1$s is the title, %2$s is the site name.
236                        sprintf(_('%1$s - %2$s'),
237                                $this->title(),
238                                common_config('site', 'name')));
239     }
240
241     /**
242      * Returns the page title
243      *
244      * SHOULD overload
245      *
246      * @return string page title
247      */
248
249     function title()
250     {
251         // TRANS: Page title for a page without a title set.
252         return _('Untitled page');
253     }
254
255     /**
256      * Show themed shortcut icon
257      *
258      * @return nothing
259      */
260     function showShortcutIcon()
261     {
262         if (is_readable(INSTALLDIR . '/theme/' . common_config('site', 'theme') . '/favicon.ico')) {
263             $this->element('link', array('rel' => 'shortcut icon',
264                                          'href' => Theme::path('favicon.ico')));
265         } else {
266             // favicon.ico should be HTTPS if the rest of the page is
267             $this->element('link', array('rel' => 'shortcut icon',
268                                          'href' => common_path('favicon.ico', StatusNet::isHTTPS())));
269         }
270
271         if (common_config('site', 'mobile')) {
272             if (is_readable(INSTALLDIR . '/theme/' . common_config('site', 'theme') . '/apple-touch-icon.png')) {
273                 $this->element('link', array('rel' => 'apple-touch-icon',
274                                              'href' => Theme::path('apple-touch-icon.png')));
275             } else {
276                 $this->element('link', array('rel' => 'apple-touch-icon',
277                                              'href' => common_path('apple-touch-icon.png')));
278             }
279         }
280     }
281
282     /**
283      * Show stylesheets
284      *
285      * @return nothing
286      */
287     function showStylesheets()
288     {
289         if (Event::handle('StartShowStyles', array($this))) {
290
291             // Use old name for StatusNet for compatibility on events
292
293             if (Event::handle('StartShowStylesheets', array($this))) {
294                 $this->primaryCssLink(null, 'screen, projection, tv, print');
295                 Event::handle('EndShowStylesheets', array($this));
296             }
297
298             $this->cssLink('js/extlib/jquery-ui/css/smoothness/jquery-ui.css');
299
300             if (Event::handle('StartShowUAStyles', array($this))) {
301                 $this->comment('[if IE]><link rel="stylesheet" type="text/css" '.
302                                'href="'.Theme::path('css/ie.css', 'base').'?version='.GNUSOCIAL_VERSION.'" /><![endif]');
303                 foreach (array(6,7) as $ver) {
304                     if (file_exists(Theme::file('css/ie'.$ver.'.css', 'base'))) {
305                         // Yes, IE people should be put in jail.
306                         $this->comment('[if lte IE '.$ver.']><link rel="stylesheet" type="text/css" '.
307                                        'href="'.Theme::path('css/ie'.$ver.'.css', 'base').'?version='.GNUSOCIAL_VERSION.'" /><![endif]');
308                     }
309                 }
310                 if (file_exists(Theme::file('css/ie.css'))) {
311                     $this->comment('[if IE]><link rel="stylesheet" type="text/css" '.
312                                'href="'.Theme::path('css/ie.css', null).'?version='.GNUSOCIAL_VERSION.'" /><![endif]');
313                 }
314                 Event::handle('EndShowUAStyles', array($this));
315             }
316
317             Event::handle('EndShowStyles', array($this));
318
319             if (common_config('custom_css', 'enabled')) {
320                 $css = common_config('custom_css', 'css');
321                 if (Event::handle('StartShowCustomCss', array($this, &$css))) {
322                     if (trim($css) != '') {
323                         $this->style($css);
324                     }
325                     Event::handle('EndShowCustomCss', array($this));
326                 }
327             }
328         }
329     }
330
331     function primaryCssLink($mainTheme=null, $media=null)
332     {
333         $theme = new Theme($mainTheme);
334
335         // Some themes may have external stylesheets, such as using the
336         // Google Font APIs to load webfonts.
337         foreach ($theme->getExternals() as $url) {
338             $this->cssLink($url, $mainTheme, $media);
339         }
340
341         // If the currently-selected theme has dependencies on other themes,
342         // we'll need to load their display.css files as well in order.
343         $baseThemes = $theme->getDeps();
344         foreach ($baseThemes as $baseTheme) {
345             $this->cssLink('css/display.css', $baseTheme, $media);
346         }
347         $this->cssLink('css/display.css', $mainTheme, $media);
348
349         // Additional styles for RTL languages
350         if (is_rtl(common_language())) {
351             if (file_exists(Theme::file('css/rtl.css'))) {
352                 $this->cssLink('css/rtl.css', $mainTheme, $media);
353             }
354         }
355     }
356
357     /**
358      * Show javascript headers
359      *
360      * @return nothing
361      */
362     function showScripts()
363     {
364         if (Event::handle('StartShowScripts', array($this))) {
365             if (Event::handle('StartShowJQueryScripts', array($this))) {
366                 if (common_config('site', 'minify')) {
367                     $this->script('extlib/jquery.min.js');
368                     $this->script('extlib/jquery.form.min.js');
369                     $this->script('extlib/jquery-ui/jquery-ui.min.js');
370                     $this->script('extlib/jquery.cookie.min.js');
371                     $this->inlineScript('if (typeof window.JSON !== "object") { $.getScript("'.common_path('js/extlib/json2.min.js', StatusNet::isHTTPS()).'"); }');
372                     $this->script('extlib/jquery.infieldlabel.min.js');
373                 } else {
374                     $this->script('extlib/jquery.js');
375                     $this->script('extlib/jquery.form.js');
376                     $this->script('extlib/jquery-ui/jquery-ui.js');
377                     $this->script('extlib/jquery.cookie.js');
378                     $this->inlineScript('if (typeof window.JSON !== "object") { $.getScript("'.common_path('js/extlib/json2.js', StatusNet::isHTTPS()).'"); }');
379                     $this->script('extlib/jquery.infieldlabel.js');
380                 }
381
382                 Event::handle('EndShowJQueryScripts', array($this));
383             }
384             if (Event::handle('StartShowStatusNetScripts', array($this)) &&
385                 Event::handle('StartShowLaconicaScripts', array($this))) {
386                 if (common_config('site', 'minify')) {
387                     $this->script('util.min.js');
388                 } else {
389                     $this->script('util.js');
390                     $this->script('xbImportNode.js');
391                     $this->script('geometa.js');
392                 }
393                 // This route isn't available in single-user mode.
394                 // Not sure why, but it causes errors here.
395                 $this->inlineScript('var _peopletagAC = "' .
396                                     common_local_url('peopletagautocomplete') . '";');
397                 $this->showScriptMessages();
398                 // Anti-framing code to avoid clickjacking attacks in older browsers.
399                 // This will show a blank page if the page is being framed, which is
400                 // consistent with the behavior of the 'X-Frame-Options: SAMEORIGIN'
401                 // header, which prevents framing in newer browser.
402                 if (common_config('javascript', 'bustframes')) {
403                     $this->inlineScript('if (window.top !== window.self) { document.write = ""; window.top.location = window.self.location; setTimeout(function () { document.body.innerHTML = ""; }, 1); window.self.onload = function () { document.body.innerHTML = ""; }; }');
404                 }
405                 Event::handle('EndShowStatusNetScripts', array($this));
406                 Event::handle('EndShowLaconicaScripts', array($this));
407             }
408             Event::handle('EndShowScripts', array($this));
409         }
410     }
411
412     /**
413      * Exports a map of localized text strings to JavaScript code.
414      *
415      * Plugins can add to what's exported by hooking the StartScriptMessages or EndScriptMessages
416      * events and appending to the array. Try to avoid adding strings that won't be used, as
417      * they'll be added to HTML output.
418      */
419     function showScriptMessages()
420     {
421         $messages = array();
422
423         if (Event::handle('StartScriptMessages', array($this, &$messages))) {
424             // Common messages needed for timeline views etc...
425
426             // TRANS: Localized tooltip for '...' expansion button on overlong remote messages.
427             $messages['showmore_tooltip'] = _m('TOOLTIP', 'Show more');
428
429             // TRANS: Inline reply form submit button: submits a reply comment.
430             $messages['reply_submit'] = _m('BUTTON', 'Reply');
431
432             // TRANS: Placeholder text for inline reply form. Clicking in this box will turn it into a mini notice form.
433             $messages['reply_placeholder'] = _m('Write a reply...');
434
435             $messages = array_merge($messages, $this->getScriptMessages());
436
437             Event::handle('EndScriptMessages', array($this, &$messages));
438         }
439
440         if (!empty($messages)) {
441             $this->inlineScript('SN.messages=' . json_encode($messages));
442         }
443
444         return $messages;
445     }
446
447     /**
448      * If the action will need localizable text strings, export them here like so:
449      *
450      * return array('pool_deepend' => _('Deep end'),
451      *              'pool_shallow' => _('Shallow end'));
452      *
453      * The exported map will be available via SN.msg() to JS code:
454      *
455      *   $('#pool').html('<div class="deepend"></div><div class="shallow"></div>');
456      *   $('#pool .deepend').text(SN.msg('pool_deepend'));
457      *   $('#pool .shallow').text(SN.msg('pool_shallow'));
458      *
459      * Exports a map of localized text strings to JavaScript code.
460      *
461      * Plugins can add to what's exported on any action by hooking the StartScriptMessages or
462      * EndScriptMessages events and appending to the array. Try to avoid adding strings that won't
463      * be used, as they'll be added to HTML output.
464      */
465     function getScriptMessages()
466     {
467         return array();
468     }
469
470     /**
471      * Show OpenSearch headers
472      *
473      * @return nothing
474      */
475     function showOpenSearch()
476     {
477         $this->element('link', array('rel' => 'search',
478                                      'type' => 'application/opensearchdescription+xml',
479                                      'href' =>  common_local_url('opensearch', array('type' => 'people')),
480                                      'title' => common_config('site', 'name').' People Search'));
481         $this->element('link', array('rel' => 'search', 'type' => 'application/opensearchdescription+xml',
482                                      'href' =>  common_local_url('opensearch', array('type' => 'notice')),
483                                      'title' => common_config('site', 'name').' Notice Search'));
484     }
485
486     /**
487      * Show feed headers
488      *
489      * MAY overload
490      *
491      * @return nothing
492      */
493     function showFeeds()
494     {
495         $feeds = $this->getFeeds();
496
497         if ($feeds) {
498             foreach ($feeds as $feed) {
499                 $this->element('link', array('rel' => $feed->rel(),
500                                              'href' => $feed->url,
501                                              'type' => $feed->mimeType(),
502                                              'title' => $feed->title));
503             }
504         }
505     }
506
507     /**
508      * Show description.
509      *
510      * SHOULD overload
511      *
512      * @return nothing
513      */
514     function showDescription()
515     {
516         // does nothing by default
517     }
518
519     /**
520      * Show extra stuff in <head>.
521      *
522      * MAY overload
523      *
524      * @return nothing
525      */
526     function extraHead()
527     {
528         // does nothing by default
529     }
530
531     /**
532      * Show body.
533      *
534      * Calls template methods
535      *
536      * @return nothing
537      */
538     function showBody()
539     {
540         $this->elementStart('body', (common_current_user()) ? array('id' => strtolower($this->trimmed('action')),
541                                                                     'class' => 'user_in')
542                             : array('id' => strtolower($this->trimmed('action'))));
543         $this->elementStart('div', array('id' => 'wrap'));
544         if (Event::handle('StartShowHeader', array($this))) {
545             $this->showHeader();
546             $this->flush();
547             Event::handle('EndShowHeader', array($this));
548         }
549         $this->showCore();
550         $this->flush();
551         if (Event::handle('StartShowFooter', array($this))) {
552             $this->showFooter();
553             $this->flush();
554             Event::handle('EndShowFooter', array($this));
555         }
556         $this->elementEnd('div');
557         $this->showScripts();
558         $this->elementEnd('body');
559     }
560
561     /**
562      * Show header of the page.
563      *
564      * Calls template methods
565      *
566      * @return nothing
567      */
568     function showHeader()
569     {
570         $this->elementStart('div', array('id' => 'header'));
571         $this->showLogo();
572         $this->showPrimaryNav();
573         if (Event::handle('StartShowSiteNotice', array($this))) {
574             $this->showSiteNotice();
575
576             Event::handle('EndShowSiteNotice', array($this));
577         }
578
579         $this->elementEnd('div');
580     }
581
582     /**
583      * Show configured logo.
584      *
585      * @return nothing
586      */
587     function showLogo()
588     {
589         $this->elementStart('address', array('id' => 'site_contact',
590                                              'class' => 'vcard'));
591         if (Event::handle('StartAddressData', array($this))) {
592             if (common_config('singleuser', 'enabled')) {
593                 $user = User::singleUser();
594                 $url = common_local_url('showstream',
595                                         array('nickname' => $user->nickname));
596             } else if (common_logged_in()) {
597                 $cur = common_current_user();
598                 $url = common_local_url('all', array('nickname' => $cur->nickname));
599             } else {
600                 $url = common_local_url('public');
601             }
602
603             $this->elementStart('a', array('class' => 'url home bookmark',
604                                            'href' => $url));
605
606             if (StatusNet::isHTTPS()) {
607                 $logoUrl = common_config('site', 'ssllogo');
608                 if (empty($logoUrl)) {
609                     // if logo is an uploaded file, try to fall back to HTTPS file URL
610                     $httpUrl = common_config('site', 'logo');
611                     if (!empty($httpUrl)) {
612                         $f = File::getKV('url', $httpUrl);
613                         if (!empty($f) && !empty($f->filename)) {
614                             // this will handle the HTTPS case
615                             $logoUrl = File::url($f->filename);
616                         }
617                     }
618                 }
619             } else {
620                 $logoUrl = common_config('site', 'logo');
621             }
622
623             if (empty($logoUrl) && file_exists(Theme::file('logo.png'))) {
624                 // This should handle the HTTPS case internally
625                 $logoUrl = Theme::path('logo.png');
626             }
627
628             if (!empty($logoUrl)) {
629                 $this->element('img', array('class' => 'logo photo',
630                                             'src' => $logoUrl,
631                                             'alt' => common_config('site', 'name')));
632             }
633
634             $this->text(' ');
635             $this->element('span', array('class' => 'fn org'), common_config('site', 'name'));
636             $this->elementEnd('a');
637
638             Event::handle('EndAddressData', array($this));
639         }
640         $this->elementEnd('address');
641     }
642
643     /**
644      * Show primary navigation.
645      *
646      * @return nothing
647      */
648     function showPrimaryNav()
649     {
650         $this->elementStart('div', array('id' => 'site_nav_global_primary'));
651
652         $user = common_current_user();
653
654         if (!empty($user) || !common_config('site', 'private')) {
655             $form = new SearchForm($this);
656             $form->show();
657         }
658
659         $pn = new PrimaryNav($this);
660         $pn->show();
661         $this->elementEnd('div');
662     }
663
664     /**
665      * Show site notice.
666      *
667      * @return nothing
668      */
669     function showSiteNotice()
670     {
671         // Revist. Should probably do an hAtom pattern here
672         $text = common_config('site', 'notice');
673         if ($text) {
674             $this->elementStart('div', array('id' => 'site_notice',
675                                             'class' => 'system_notice'));
676             $this->raw($text);
677             $this->elementEnd('div');
678         }
679     }
680
681     /**
682      * Show notice form.
683      *
684      * MAY overload if no notice form needed... or direct message box????
685      *
686      * @return nothing
687      */
688     function showNoticeForm()
689     {
690         // TRANS: Tab on the notice form.
691         $tabs = array('status' => _m('TAB','Status'));
692
693         $this->elementStart('div', 'input_forms');
694
695         if (Event::handle('StartShowEntryForms', array(&$tabs))) {
696             $this->elementStart('ul', array('class' => 'nav',
697                                             'id' => 'input_form_nav'));
698
699             foreach ($tabs as $tag => $title) {
700                 $attrs = array('id' => 'input_form_nav_'.$tag,
701                                'class' => 'input_form_nav_tab');
702
703                 if ($tag == 'status') {
704                     // We're actually showing the placeholder form,
705                     // but we special-case the 'Status' tab as if
706                     // it were a small version of it.
707                     $attrs['class'] .= ' current';
708                 }
709                 $this->elementStart('li', $attrs);
710
711                 $this->element('a',
712                                array('href' => 'javascript:SN.U.switchInputFormTab("'.$tag.'")'),
713                                $title);
714                 $this->elementEnd('li');
715             }
716
717             $this->elementEnd('ul');
718
719             $attrs = array('class' => 'input_form current',
720                            'id' => 'input_form_placeholder');
721             $this->elementStart('div', $attrs);
722             $form = new NoticePlaceholderForm($this);
723             $form->show();
724             $this->elementEnd('div');
725
726             foreach ($tabs as $tag => $title) {
727                 $attrs = array('class' => 'input_form',
728                                'id' => 'input_form_'.$tag);
729
730                 $this->elementStart('div', $attrs);
731
732                 $form = null;
733
734                 if (Event::handle('StartMakeEntryForm', array($tag, $this, &$form))) {
735                     if ($tag == 'status') {
736                         $options = $this->noticeFormOptions();
737                         $form = new NoticeForm($this, $options);
738                     }
739                     Event::handle('EndMakeEntryForm', array($tag, $this, $form));
740                 }
741
742                 if (!empty($form)) {
743                     $form->show();
744                 }
745
746                 $this->elementEnd('div');
747             }
748         }
749
750         $this->elementEnd('div');
751     }
752
753     function noticeFormOptions()
754     {
755         return array();
756     }
757
758     /**
759      * Show anonymous message.
760      *
761      * SHOULD overload
762      *
763      * @return nothing
764      */
765     function showAnonymousMessage()
766     {
767         // needs to be defined by the class
768     }
769
770     /**
771      * Show core.
772      *
773      * Shows local navigation, content block and aside.
774      *
775      * @return nothing
776      */
777     function showCore()
778     {
779         $this->elementStart('div', array('id' => 'core'));
780         $this->elementStart('div', array('id' => 'aside_primary_wrapper'));
781         $this->elementStart('div', array('id' => 'content_wrapper'));
782         $this->elementStart('div', array('id' => 'site_nav_local_views_wrapper'));
783         if (Event::handle('StartShowLocalNavBlock', array($this))) {
784             $this->showLocalNavBlock();
785             $this->flush();
786             Event::handle('EndShowLocalNavBlock', array($this));
787         }
788         if (Event::handle('StartShowContentBlock', array($this))) {
789             $this->showContentBlock();
790             $this->flush();
791             Event::handle('EndShowContentBlock', array($this));
792         }
793         if (Event::handle('StartShowAside', array($this))) {
794             $this->showAside();
795             $this->flush();
796             Event::handle('EndShowAside', array($this));
797         }
798         $this->elementEnd('div');
799         $this->elementEnd('div');
800         $this->elementEnd('div');
801         $this->elementEnd('div');
802     }
803
804     /**
805      * Show local navigation block.
806      *
807      * @return nothing
808      */
809     function showLocalNavBlock()
810     {
811         // Need to have this ID for CSS; I'm too lazy to add it to
812         // all menus
813         $this->elementStart('div', array('id' => 'site_nav_local_views'));
814         // Cheat cheat cheat!
815         $this->showLocalNav();
816         $this->elementEnd('div');
817     }
818
819     /**
820      * If there's a logged-in user, show a bit of login context
821      *
822      * @return nothing
823      */
824     function showProfileBlock()
825     {
826         if (common_logged_in()) {
827             $block = new DefaultProfileBlock($this);
828             $block->show();
829         }
830     }
831
832     /**
833      * Show local navigation.
834      *
835      * SHOULD overload
836      *
837      * @return nothing
838      */
839     function showLocalNav()
840     {
841         $nav = new DefaultLocalNav($this);
842         $nav->show();
843     }
844
845     /**
846      * Show menu for an object (group, profile)
847      *
848      * This block will only show if a subclass has overridden
849      * the showObjectNav() method.
850      *
851      * @return nothing
852      */
853     function showObjectNavBlock()
854     {
855         $rmethod = new ReflectionMethod($this, 'showObjectNav');
856         $dclass = $rmethod->getDeclaringClass()->getName();
857
858         if ($dclass != 'Action') {
859             // Need to have this ID for CSS; I'm too lazy to add it to
860             // all menus
861             $this->elementStart('div', array('id' => 'site_nav_object',
862                                              'class' => 'section'));
863             $this->showObjectNav();
864             $this->elementEnd('div');
865         }
866     }
867
868     /**
869      * Show object navigation.
870      *
871      * If there are things to do with this object, show it here.
872      *
873      * @return nothing
874      */
875     function showObjectNav()
876     {
877         /* Nothing here. */
878     }
879
880     /**
881      * Show content block.
882      *
883      * @return nothing
884      */
885     function showContentBlock()
886     {
887         $this->elementStart('div', array('id' => 'content'));
888         if (common_logged_in()) {
889             if (Event::handle('StartShowNoticeForm', array($this))) {
890                 $this->showNoticeForm();
891                 Event::handle('EndShowNoticeForm', array($this));
892             }
893         }
894         if (Event::handle('StartShowPageTitle', array($this))) {
895             $this->showPageTitle();
896             Event::handle('EndShowPageTitle', array($this));
897         }
898         $this->showPageNoticeBlock();
899         $this->elementStart('div', array('id' => 'content_inner'));
900         // show the actual content (forms, lists, whatever)
901         $this->showContent();
902         $this->elementEnd('div');
903         $this->elementEnd('div');
904     }
905
906     /**
907      * Show page title.
908      *
909      * @return nothing
910      */
911     function showPageTitle()
912     {
913         $this->element('h1', null, $this->title());
914     }
915
916     /**
917      * Show page notice block.
918      *
919      * Only show the block if a subclassed action has overrided
920      * Action::showPageNotice(), or an event handler is registered for
921      * the StartShowPageNotice event, in which case we assume the
922      * 'page_notice' definition list is desired.  This is to prevent
923      * empty 'page_notice' definition lists from being output everywhere.
924      *
925      * @return nothing
926      */
927     function showPageNoticeBlock()
928     {
929         $rmethod = new ReflectionMethod($this, 'showPageNotice');
930         $dclass = $rmethod->getDeclaringClass()->getName();
931
932         if ($dclass != 'Action' || Event::hasHandler('StartShowPageNotice')) {
933
934             $this->elementStart('div', array('id' => 'page_notice',
935                                             'class' => 'system_notice'));
936             if (Event::handle('StartShowPageNotice', array($this))) {
937                 $this->showPageNotice();
938                 Event::handle('EndShowPageNotice', array($this));
939             }
940             $this->elementEnd('div');
941         }
942     }
943
944     /**
945      * Show page notice.
946      *
947      * SHOULD overload (unless there's not a notice)
948      *
949      * @return nothing
950      */
951     function showPageNotice()
952     {
953     }
954
955     /**
956      * Show content.
957      *
958      * MUST overload (unless there's not a notice)
959      *
960      * @return nothing
961      */
962     function showContent()
963     {
964     }
965
966     /**
967      * Show Aside.
968      *
969      * @return nothing
970      */
971     function showAside()
972     {
973         $this->elementStart('div', array('id' => 'aside_primary',
974                                          'class' => 'aside'));
975         $this->showProfileBlock();
976         if (Event::handle('StartShowObjectNavBlock', array($this))) {
977             $this->showObjectNavBlock();
978             Event::handle('EndShowObjectNavBlock', array($this));
979         }
980         if (Event::handle('StartShowSections', array($this))) {
981             $this->showSections();
982             Event::handle('EndShowSections', array($this));
983         }
984         if (Event::handle('StartShowExportData', array($this))) {
985             $this->showExportData();
986             Event::handle('EndShowExportData', array($this));
987         }
988         $this->elementEnd('div');
989     }
990
991     /**
992      * Show export data feeds.
993      *
994      * @return void
995      */
996     function showExportData()
997     {
998         $feeds = $this->getFeeds();
999         if ($feeds) {
1000             $fl = new FeedList($this);
1001             $fl->show($feeds);
1002         }
1003     }
1004
1005     /**
1006      * Show sections.
1007      *
1008      * SHOULD overload
1009      *
1010      * @return nothing
1011      */
1012     function showSections()
1013     {
1014         // for each section, show it
1015     }
1016
1017     /**
1018      * Show footer.
1019      *
1020      * @return nothing
1021      */
1022     function showFooter()
1023     {
1024         $this->elementStart('div', array('id' => 'footer'));
1025         if (Event::handle('StartShowInsideFooter', array($this))) {
1026             $this->showSecondaryNav();
1027             $this->showLicenses();
1028             Event::handle('EndShowInsideFooter', array($this));
1029         }
1030         $this->elementEnd('div');
1031     }
1032
1033     /**
1034      * Show secondary navigation.
1035      *
1036      * @return nothing
1037      */
1038     function showSecondaryNav()
1039     {
1040         $sn = new SecondaryNav($this);
1041         $sn->show();
1042     }
1043
1044     /**
1045      * Show licenses.
1046      *
1047      * @return nothing
1048      */
1049     function showLicenses()
1050     {
1051         $this->showGNUsocialLicense();
1052         $this->showContentLicense();
1053     }
1054
1055     /**
1056      * Show GNU social license.
1057      *
1058      * @return nothing
1059      */
1060     function showGNUsocialLicense()
1061     {
1062         if (common_config('site', 'broughtby')) {
1063             // TRANS: First sentence of the GNU social site license. Used if 'broughtby' is set.
1064             // TRANS: Text between [] is a link description, text between () is the link itself.
1065             // TRANS: Make sure there is no whitespace between "]" and "(".
1066             // TRANS: "%%site.broughtby%%" is the value of the variable site.broughtby
1067             $instr = _('**%%site.name%%** is a social network, courtesy of [%%site.broughtby%%](%%site.broughtbyurl%%).');
1068         } else {
1069             // TRANS: First sentence of the GNU social site license. Used if 'broughtby' is not set.
1070             $instr = _('**%%site.name%%** is a social network.');
1071         }
1072         $instr .= ' ';
1073         // TRANS: Second sentence of the GNU social site license. Mentions the GNU social source code license.
1074         // TRANS: Make sure there is no whitespace between "]" and "(".
1075         // TRANS: [%1$s](%2$s) is a link description followed by the link itself
1076         // TRANS: %3$s is the version of GNU social that is being used.
1077         $instr .= sprintf(_('It runs on [%1$s](%2$s), version %3$s, available under the [GNU Affero General Public License](http://www.fsf.org/licensing/licenses/agpl-3.0.html).'), GNUSOCIAL_ENGINE, GNUSOCIAL_ENGINE_URL, GNUSOCIAL_VERSION);
1078         $output = common_markup_to_html($instr);
1079         $this->raw($output);
1080         // do it
1081     }
1082
1083     /**
1084      * Show content license.
1085      *
1086      * @return nothing
1087      */
1088     function showContentLicense()
1089     {
1090         if (Event::handle('StartShowContentLicense', array($this))) {
1091             switch (common_config('license', 'type')) {
1092             case 'private':
1093                 // TRANS: Content license displayed when license is set to 'private'.
1094                 // TRANS: %1$s is the site name.
1095                 $this->element('p', null, sprintf(_('Content and data of %1$s are private and confidential.'),
1096                                                   common_config('site', 'name')));
1097                 // fall through
1098             case 'allrightsreserved':
1099                 if (common_config('license', 'owner')) {
1100                     // TRANS: Content license displayed when license is set to 'allrightsreserved'.
1101                     // TRANS: %1$s is the copyright owner.
1102                     $this->element('p', null, sprintf(_('Content and data copyright by %1$s. All rights reserved.'),
1103                                                       common_config('license', 'owner')));
1104                 } else {
1105                     // TRANS: Content license displayed when license is set to 'allrightsreserved' and no owner is set.
1106                     $this->element('p', null, _('Content and data copyright by contributors. All rights reserved.'));
1107                 }
1108                 break;
1109             case 'cc': // fall through
1110             default:
1111                 $this->elementStart('p');
1112
1113                 $image    = common_config('license', 'image');
1114                 $sslimage = common_config('license', 'sslimage');
1115
1116                 if (StatusNet::isHTTPS()) {
1117                     if (!empty($sslimage)) {
1118                         $url = $sslimage;
1119                     } else if (preg_match('#^http://i.creativecommons.org/#', $image)) {
1120                         // CC support HTTPS on their images
1121                         $url = preg_replace('/^http/', 'https', $image);
1122                     } else {
1123                         // Better to show mixed content than no content
1124                         $url = $image;
1125                     }
1126                 } else {
1127                     $url = $image;
1128                 }
1129
1130                 $this->element('img', array('id' => 'license_cc',
1131                                             'src' => $url,
1132                                             'alt' => common_config('license', 'title'),
1133                                             'width' => '80',
1134                                             'height' => '15'));
1135                 $this->text(' ');
1136                 // TRANS: license message in footer.
1137                 // TRANS: %1$s is the site name, %2$s is a link to the license URL, with a licence name set in configuration.
1138                 $notice = _('All %1$s content and data are available under the %2$s license.');
1139                 $link = "<a class=\"license\" rel=\"external license\" href=\"" .
1140                         htmlspecialchars(common_config('license', 'url')) .
1141                         "\">" .
1142                         htmlspecialchars(common_config('license', 'title')) .
1143                         "</a>";
1144                 $this->raw(sprintf(htmlspecialchars($notice),
1145                                    htmlspecialchars(common_config('site', 'name')),
1146                                    $link));
1147                 $this->elementEnd('p');
1148                 break;
1149             }
1150
1151             Event::handle('EndShowContentLicense', array($this));
1152         }
1153     }
1154
1155     /**
1156      * Return last modified, if applicable.
1157      *
1158      * MAY override
1159      *
1160      * @return string last modified http header
1161      */
1162     function lastModified()
1163     {
1164         // For comparison with If-Last-Modified
1165         // If not applicable, return null
1166         return null;
1167     }
1168
1169     /**
1170      * Return etag, if applicable.
1171      *
1172      * MAY override
1173      *
1174      * @return string etag http header
1175      */
1176     function etag()
1177     {
1178         return null;
1179     }
1180
1181     /**
1182      * Return true if read only.
1183      *
1184      * MAY override
1185      *
1186      * @param array $args other arguments
1187      *
1188      * @return boolean is read only action?
1189      */
1190     function isReadOnly($args)
1191     {
1192         return false;
1193     }
1194
1195     /**
1196      * Returns query argument or default value if not found
1197      *
1198      * @param string $key requested argument
1199      * @param string $def default value to return if $key is not provided
1200      *
1201      * @return boolean is read only action?
1202      */
1203     function arg($key, $def=null)
1204     {
1205         if (array_key_exists($key, $this->args)) {
1206             return $this->args[$key];
1207         } else {
1208             return $def;
1209         }
1210     }
1211
1212     /**
1213      * Returns trimmed query argument or default value if not found
1214      *
1215      * @param string $key requested argument
1216      * @param string $def default value to return if $key is not provided
1217      *
1218      * @return boolean is read only action?
1219      */
1220     function trimmed($key, $def=null)
1221     {
1222         $arg = $this->arg($key, $def);
1223         return is_string($arg) ? trim($arg) : $arg;
1224     }
1225
1226     /**
1227      * Handler method
1228      *
1229      * @return boolean is read only action?
1230      */
1231     protected function handle()
1232     {
1233         header('Vary: Accept-Encoding,Cookie');
1234
1235         $lm   = $this->lastModified();
1236         $etag = $this->etag();
1237
1238         if ($etag) {
1239             header('ETag: ' . $etag);
1240         }
1241
1242         if ($lm) {
1243             header('Last-Modified: ' . date(DATE_RFC1123, $lm));
1244             if ($this->isCacheable()) {
1245                 header( 'Expires: ' . gmdate( 'D, d M Y H:i:s', 0 ) . ' GMT' );
1246                 header( "Cache-Control: private, must-revalidate, max-age=0" );
1247                 header( "Pragma:");
1248             }
1249         }
1250
1251         $checked = false;
1252         if ($etag) {
1253             $if_none_match = (array_key_exists('HTTP_IF_NONE_MATCH', $_SERVER)) ?
1254               $_SERVER['HTTP_IF_NONE_MATCH'] : null;
1255             if ($if_none_match) {
1256                 // If this check fails, ignore the if-modified-since below.
1257                 $checked = true;
1258                 if ($this->_hasEtag($etag, $if_none_match)) {
1259                     header('HTTP/1.1 304 Not Modified');
1260                     // Better way to do this?
1261                     exit(0);
1262                 }
1263             }
1264         }
1265
1266         if (!$checked && $lm && array_key_exists('HTTP_IF_MODIFIED_SINCE', $_SERVER)) {
1267             $if_modified_since = $_SERVER['HTTP_IF_MODIFIED_SINCE'];
1268             $ims = strtotime($if_modified_since);
1269             if ($lm <= $ims) {
1270                 header('HTTP/1.1 304 Not Modified');
1271                 // Better way to do this?
1272                 exit(0);
1273             }
1274         }
1275     }
1276
1277     /**
1278      * Is this action cacheable?
1279      *
1280      * If the action returns a last-modified
1281      *
1282      * @param array $argarray is ignored since it's now passed in in prepare()
1283      *
1284      * @return boolean is read only action?
1285      */
1286     function isCacheable()
1287     {
1288         return true;
1289     }
1290
1291     /**
1292      * Has etag? (private)
1293      *
1294      * @param string $etag          etag http header
1295      * @param string $if_none_match ifNoneMatch http header
1296      *
1297      * @return boolean
1298      */
1299     function _hasEtag($etag, $if_none_match)
1300     {
1301         $etags = explode(',', $if_none_match);
1302         return in_array($etag, $etags) || in_array('*', $etags);
1303     }
1304
1305     /**
1306      * Boolean understands english (yes, no, true, false)
1307      *
1308      * @param string $key query key we're interested in
1309      * @param string $def default value
1310      *
1311      * @return boolean interprets yes/no strings as boolean
1312      */
1313     function boolean($key, $def=false)
1314     {
1315         $arg = strtolower($this->trimmed($key));
1316
1317         if (is_null($arg)) {
1318             return $def;
1319         } else if (in_array($arg, array('true', 'yes', '1', 'on'))) {
1320             return true;
1321         } else if (in_array($arg, array('false', 'no', '0'))) {
1322             return false;
1323         } else {
1324             return $def;
1325         }
1326     }
1327
1328     /**
1329      * Integer value of an argument
1330      *
1331      * @param string $key      query key we're interested in
1332      * @param string $defValue optional default value (default null)
1333      * @param string $maxValue optional max value (default null)
1334      * @param string $minValue optional min value (default null)
1335      *
1336      * @return integer integer value
1337      */
1338     function int($key, $defValue=null, $maxValue=null, $minValue=null)
1339     {
1340         $arg = strtolower($this->trimmed($key));
1341
1342         if (is_null($arg) || !is_integer($arg)) {
1343             return $defValue;
1344         }
1345
1346         if (!is_null($maxValue)) {
1347             $arg = min($arg, $maxValue);
1348         }
1349
1350         if (!is_null($minValue)) {
1351             $arg = max($arg, $minValue);
1352         }
1353
1354         return $arg;
1355     }
1356
1357     /**
1358      * Server error
1359      *
1360      * @param string  $msg  error message to display
1361      * @param integer $code http error code, 500 by default
1362      *
1363      * @return nothing
1364      */
1365     function serverError($msg, $code=500, $format=null)
1366     {
1367         if ($format === null) {
1368             $format = $this->format;
1369         }
1370
1371         common_debug("Server error '{$code}' on '{$this->action}': {$msg}", __FILE__);
1372
1373         if (!array_key_exists($code, ServerErrorAction::$status)) {
1374             $code = 500;
1375         }
1376
1377         $status_string = ServerErrorAction::$status[$code];
1378
1379         switch ($format) {
1380         case 'xml':
1381             header("HTTP/1.1 {$code} {$status_string}");
1382             $this->initDocument('xml');
1383             $this->elementStart('hash');
1384             $this->element('error', null, $msg);
1385             $this->element('request', null, $_SERVER['REQUEST_URI']);
1386             $this->elementEnd('hash');
1387             $this->endDocument('xml');
1388             break;
1389         case 'json':
1390             if (!isset($this->callback)) {
1391                 header("HTTP/1.1 {$code} {$status_string}");
1392             }
1393             $this->initDocument('json');
1394             $error_array = array('error' => $msg, 'request' => $_SERVER['REQUEST_URI']);
1395             print(json_encode($error_array));
1396             $this->endDocument('json');
1397             break;
1398         default:
1399             throw new ServerException($msg, $code);
1400         }
1401
1402         exit((int)$code);
1403     }
1404
1405     /**
1406      * Client error
1407      *
1408      * @param string  $msg    error message to display
1409      * @param integer $code   http error code, 400 by default
1410      * @param string  $format error format (json, xml, text) for ApiAction
1411      *
1412      * @return nothing
1413      * @throws ClientException always
1414      */
1415     function clientError($msg, $code=400, $format=null)
1416     {
1417         // $format is currently only relevant for an ApiAction anyway
1418         if ($format === null) {
1419             $format = $this->format;
1420         }
1421
1422         common_debug("User error '{$code}' on '{$this->action}': {$msg}", __FILE__);
1423
1424         if (!array_key_exists($code, ClientErrorAction::$status)) {
1425             $code = 400;
1426         }
1427         
1428         $status_string = ClientErrorAction::$status[$code];
1429
1430         switch ($format) {
1431         case 'xml':
1432             header("HTTP/1.1 {$code} {$status_string}");
1433             $this->initDocument('xml');
1434             $this->elementStart('hash');
1435             $this->element('error', null, $msg);
1436             $this->element('request', null, $_SERVER['REQUEST_URI']);
1437             $this->elementEnd('hash');
1438             $this->endDocument('xml');
1439             break;
1440         case 'json':
1441             if (!isset($this->callback)) {
1442                 header("HTTP/1.1 {$code} {$status_string}");
1443             }
1444             $this->initDocument('json');
1445             $error_array = array('error' => $msg, 'request' => $_SERVER['REQUEST_URI']);
1446             $this->text(json_encode($error_array));
1447             $this->endDocument('json');
1448             break;
1449         case 'text':
1450             header("HTTP/1.1 {$code} {$status_string}");
1451             header('Content-Type: text/plain; charset=utf-8');
1452             echo $msg;
1453             break;
1454         default:
1455             throw new ClientException($msg, $code);
1456         }
1457         exit((int)$code);
1458     }
1459
1460     /**
1461      * If not logged in, take appropriate action (redir or exception)
1462      *
1463      * @param boolean $redir Redirect to login if not logged in
1464      *
1465      * @return boolean true if logged in (never returns if not)
1466      */
1467     public function checkLogin($redir=true)
1468     {
1469         if (common_logged_in()) {
1470             return true;
1471         }
1472
1473         if ($redir==true) {
1474             common_set_returnto($_SERVER['REQUEST_URI']);
1475             common_redirect(common_local_url('login'));
1476         }
1477
1478         // TRANS: Error message displayed when trying to perform an action that requires a logged in user.
1479         $this->clientError(_('Not logged in.'), 403);
1480     }
1481
1482     /**
1483      * Returns the current URL
1484      *
1485      * @return string current URL
1486      */
1487     function selfUrl()
1488     {
1489         list($action, $args) = $this->returnToArgs();
1490         return common_local_url($action, $args);
1491     }
1492
1493     /**
1494      * Returns arguments sufficient for re-constructing URL
1495      *
1496      * @return array two elements: action, other args
1497      */
1498     function returnToArgs()
1499     {
1500         $action = $this->trimmed('action');
1501         $args   = $this->args;
1502         unset($args['action']);
1503         if (common_config('site', 'fancy')) {
1504             unset($args['p']);
1505         }
1506         if (array_key_exists('submit', $args)) {
1507             unset($args['submit']);
1508         }
1509         foreach (array_keys($_COOKIE) as $cookie) {
1510             unset($args[$cookie]);
1511         }
1512         return array($action, $args);
1513     }
1514
1515     /**
1516      * Generate a menu item
1517      *
1518      * @param string  $url         menu URL
1519      * @param string  $text        menu name
1520      * @param string  $title       title attribute, null by default
1521      * @param boolean $is_selected current menu item, false by default
1522      * @param string  $id          element id, null by default
1523      *
1524      * @return nothing
1525      */
1526     function menuItem($url, $text, $title=null, $is_selected=false, $id=null, $class=null)
1527     {
1528         // Added @id to li for some control.
1529         // XXX: We might want to move this to htmloutputter.php
1530         $lattrs  = array();
1531         $classes = array();
1532         if ($class !== null) {
1533             $classes[] = trim($class);
1534         }
1535         if ($is_selected) {
1536             $classes[] = 'current';
1537         }
1538
1539         if (!empty($classes)) {
1540             $lattrs['class'] = implode(' ', $classes);
1541         }
1542
1543         if (!is_null($id)) {
1544             $lattrs['id'] = $id;
1545         }
1546
1547         $this->elementStart('li', $lattrs);
1548         $attrs['href'] = $url;
1549         if ($title) {
1550             $attrs['title'] = $title;
1551         }
1552         $this->element('a', $attrs, $text);
1553         $this->elementEnd('li');
1554     }
1555
1556     /**
1557      * Generate pagination links
1558      *
1559      * @param boolean $have_before is there something before?
1560      * @param boolean $have_after  is there something after?
1561      * @param integer $page        current page
1562      * @param string  $action      current action
1563      * @param array   $args        rest of query arguments
1564      *
1565      * @return nothing
1566      */
1567     // XXX: The messages in this pagination method only tailor to navigating
1568     //      notices. In other lists, "Previous"/"Next" type navigation is
1569     //      desirable, but not available.
1570     function pagination($have_before, $have_after, $page, $action, $args=null)
1571     {
1572         // Does a little before-after block for next/prev page
1573         if ($have_before || $have_after) {
1574             $this->elementStart('ul', array('class' => 'nav',
1575                                             'id' => 'pagination'));
1576         }
1577         if ($have_before) {
1578             $pargs   = array('page' => $page-1);
1579             $this->elementStart('li', array('class' => 'nav_prev'));
1580             $this->element('a', array('href' => common_local_url($action, $args, $pargs),
1581                                       'rel' => 'prev'),
1582                            // TRANS: Pagination message to go to a page displaying information more in the
1583                            // TRANS: present than the currently displayed information.
1584                            _('After'));
1585             $this->elementEnd('li');
1586         }
1587         if ($have_after) {
1588             $pargs   = array('page' => $page+1);
1589             $this->elementStart('li', array('class' => 'nav_next'));
1590             $this->element('a', array('href' => common_local_url($action, $args, $pargs),
1591                                       'rel' => 'next'),
1592                            // TRANS: Pagination message to go to a page displaying information more in the
1593                            // TRANS: past than the currently displayed information.
1594                            _('Before'));
1595             $this->elementEnd('li');
1596         }
1597         if ($have_before || $have_after) {
1598             $this->elementEnd('ul');
1599         }
1600     }
1601
1602     /**
1603      * An array of feeds for this action.
1604      *
1605      * Returns an array of potential feeds for this action.
1606      *
1607      * @return array Feed object to show in head and links
1608      */
1609     function getFeeds()
1610     {
1611         return null;
1612     }
1613
1614     /**
1615      * Check the session token.
1616      *
1617      * Checks that the current form has the correct session token,
1618      * and throw an exception if it does not.
1619      *
1620      * @return void
1621      */
1622     // XXX: Finding this type of check with the same message about 50 times.
1623     //      Possible to refactor?
1624     function checkSessionToken()
1625     {
1626         // CSRF protection
1627         $token = $this->trimmed('token');
1628         if (empty($token) || $token != common_session_token()) {
1629             // TRANS: Client error text when there is a problem with the session token.
1630             $this->clientError(_('There was a problem with your session token.'));
1631         }
1632     }
1633
1634     /**
1635      * Check if the current request is a POST
1636      *
1637      * @return boolean true if POST; otherwise false.
1638      */
1639
1640     function isPost()
1641     {
1642         return ($_SERVER['REQUEST_METHOD'] == 'POST');
1643     }
1644 }