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