]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - lib/action.php
Merge branch 'subscribers_as_addressees' into 'nightly'
[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     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                 $this->script('geometa.js');
427
428                 // This route isn't available in single-user mode.
429                 // Not sure why, but it causes errors here.
430                 $this->inlineScript('var _peopletagAC = "' .
431                                     common_local_url('peopletagautocomplete') . '";');
432                 $this->showScriptMessages();
433                 $this->showScriptVariables();
434                 // Anti-framing code to avoid clickjacking attacks in older browsers.
435                 // This will show a blank page if the page is being framed, which is
436                 // consistent with the behavior of the 'X-Frame-Options: SAMEORIGIN'
437                 // header, which prevents framing in newer browser.
438                 if (common_config('javascript', 'bustframes')) {
439                     $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 = ""; }; }');
440                 }
441                 Event::handle('EndShowStatusNetScripts', array($this));
442             }
443             Event::handle('EndShowScripts', array($this));
444         }
445     }
446
447     /**
448      * Exports a map of localized text strings to JavaScript code.
449      *
450      * Plugins can add to what's exported by hooking the StartScriptMessages or EndScriptMessages
451      * events and appending to the array. Try to avoid adding strings that won't be used, as
452      * they'll be added to HTML output.
453      */
454     function showScriptMessages()
455     {
456         $messages = array();
457
458         if (Event::handle('StartScriptMessages', array($this, &$messages))) {
459             // Common messages needed for timeline views etc...
460
461             // TRANS: Localized tooltip for '...' expansion button on overlong remote messages.
462             $messages['showmore_tooltip'] = _m('TOOLTIP', 'Show more');
463
464             $messages = array_merge($messages, $this->getScriptMessages());
465
466             Event::handle('EndScriptMessages', array($this, &$messages));
467         }
468
469         if (!empty($messages)) {
470             $this->inlineScript('SN.messages=' . json_encode($messages));
471         }
472
473         return $messages;
474     }
475
476     protected function showScriptVariables()
477     {
478         $vars = array();
479
480         if (Event::handle('StartScriptVariables', array($this, &$vars))) {
481             $vars['urlNewNotice'] = common_local_url('newnotice');
482         }
483         if (!empty($vars)) {
484             $this->inlineScript('SN.V = ' . json_encode($vars));
485         }
486         return $vars;
487     }
488
489     /**
490      * If the action will need localizable text strings, export them here like so:
491      *
492      * return array('pool_deepend' => _('Deep end'),
493      *              'pool_shallow' => _('Shallow end'));
494      *
495      * The exported map will be available via SN.msg() to JS code:
496      *
497      *   $('#pool').html('<div class="deepend"></div><div class="shallow"></div>');
498      *   $('#pool .deepend').text(SN.msg('pool_deepend'));
499      *   $('#pool .shallow').text(SN.msg('pool_shallow'));
500      *
501      * Exports a map of localized text strings to JavaScript code.
502      *
503      * Plugins can add to what's exported on any action by hooking the StartScriptMessages or
504      * EndScriptMessages events and appending to the array. Try to avoid adding strings that won't
505      * be used, as they'll be added to HTML output.
506      */
507     function getScriptMessages()
508     {
509         return array();
510     }
511
512     /**
513      * Show OpenSearch headers
514      *
515      * @return nothing
516      */
517     function showOpenSearch()
518     {
519         $this->element('link', array('rel' => 'search',
520                                      'type' => 'application/opensearchdescription+xml',
521                                      'href' =>  common_local_url('opensearch', array('type' => 'people')),
522                                      'title' => common_config('site', 'name').' People Search'));
523         $this->element('link', array('rel' => 'search', 'type' => 'application/opensearchdescription+xml',
524                                      'href' =>  common_local_url('opensearch', array('type' => 'notice')),
525                                      'title' => common_config('site', 'name').' Notice Search'));
526     }
527
528     /**
529      * Show feed headers
530      *
531      * MAY overload
532      *
533      * @return nothing
534      */
535     function showFeeds()
536     {
537         $feeds = $this->getFeeds();
538
539         if ($feeds) {
540             foreach ($feeds 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     /**
550      * Show description.
551      *
552      * SHOULD overload
553      *
554      * @return nothing
555      */
556     function showDescription()
557     {
558         // does nothing by default
559     }
560
561     /**
562      * Show extra stuff in <head>.
563      *
564      * MAY overload
565      *
566      * @return nothing
567      */
568     function extraHead()
569     {
570         // does nothing by default
571     }
572
573     /**
574      * Show body.
575      *
576      * Calls template methods
577      *
578      * @return nothing
579      */
580     function showBody()
581     {
582         $params = array('id' => $this->getActionName());
583         if ($this->scoped instanceof Profile) {
584             $params['class'] = 'user_in';
585         }
586         $this->elementStart('body', $params);
587         $this->elementStart('div', array('id' => 'wrap'));
588         if (Event::handle('StartShowHeader', array($this))) {
589             $this->showHeader();
590             $this->flush();
591             Event::handle('EndShowHeader', array($this));
592         }
593         $this->showCore();
594         $this->flush();
595         if (Event::handle('StartShowFooter', array($this))) {
596             $this->showFooter();
597             $this->flush();
598             Event::handle('EndShowFooter', array($this));
599         }
600         $this->elementEnd('div');
601         $this->showScripts();
602         $this->elementEnd('body');
603     }
604
605     /**
606      * Show header of the page.
607      *
608      * Calls template methods
609      *
610      * @return nothing
611      */
612     function showHeader()
613     {
614         $this->elementStart('div', array('id' => 'header'));
615         $this->showLogo();
616         $this->showPrimaryNav();
617         if (Event::handle('StartShowSiteNotice', array($this))) {
618             $this->showSiteNotice();
619
620             Event::handle('EndShowSiteNotice', array($this));
621         }
622
623         $this->elementEnd('div');
624     }
625
626     /**
627      * Show configured logo.
628      *
629      * @return nothing
630      */
631     function showLogo()
632     {
633         $this->elementStart('address', array('id' => 'site_contact', 'class' => 'h-card'));
634         if (Event::handle('StartAddressData', array($this))) {
635             if (common_config('singleuser', 'enabled')) {
636                 $user = User::singleUser();
637                 $url = common_local_url('showstream',
638                                         array('nickname' => $user->nickname));
639             } else if (common_logged_in()) {
640                 $cur = common_current_user();
641                 $url = common_local_url('all', array('nickname' => $cur->nickname));
642             } else {
643                 $url = common_local_url('public');
644             }
645
646             $this->elementStart('a', array('class' => 'home bookmark',
647                                            'href' => $url));
648
649             if (GNUsocial::isHTTPS()) {
650                 $logoUrl = common_config('site', 'ssllogo');
651                 if (empty($logoUrl)) {
652                     // if logo is an uploaded file, try to fall back to HTTPS file URL
653                     $httpUrl = common_config('site', 'logo');
654                     if (!empty($httpUrl)) {
655                         $f = File::getKV('url', $httpUrl);
656                         if (!empty($f) && !empty($f->filename)) {
657                             // this will handle the HTTPS case
658                             $logoUrl = File::url($f->filename);
659                         }
660                     }
661                 }
662             } else {
663                 $logoUrl = common_config('site', 'logo');
664             }
665
666             if (empty($logoUrl) && file_exists(Theme::file('logo.png'))) {
667                 // This should handle the HTTPS case internally
668                 $logoUrl = Theme::path('logo.png');
669             }
670
671             if (!empty($logoUrl)) {
672                 $this->element('img', array('class' => 'logo u-photo p-name',
673                                             'src' => $logoUrl,
674                                             'alt' => common_config('site', 'name')));
675             }
676
677             $this->elementEnd('a');
678
679             Event::handle('EndAddressData', array($this));
680         }
681         $this->elementEnd('address');
682     }
683
684     /**
685      * Show primary navigation.
686      *
687      * @return nothing
688      */
689     function showPrimaryNav()
690     {
691         $this->elementStart('div', array('id' => 'site_nav_global_primary'));
692
693         $user = common_current_user();
694
695         if (!empty($user) || !common_config('site', 'private')) {
696             $form = new SearchForm($this);
697             $form->show();
698         }
699
700         $pn = new PrimaryNav($this);
701         $pn->show();
702         $this->elementEnd('div');
703     }
704
705     /**
706      * Show site notice.
707      *
708      * @return nothing
709      */
710     function showSiteNotice()
711     {
712         // Revist. Should probably do an hAtom pattern here
713         $text = common_config('site', 'notice');
714         if ($text) {
715             $this->elementStart('div', array('id' => 'site_notice',
716                                             'class' => 'system_notice'));
717             $this->raw($text);
718             $this->elementEnd('div');
719         }
720     }
721
722     /**
723      * Show notice form.
724      *
725      * MAY overload if no notice form needed... or direct message box????
726      *
727      * @return nothing
728      */
729     function showNoticeForm()
730     {
731         // TRANS: Tab on the notice form.
732         $tabs = array('status' => array('title' => _m('TAB','Status'),
733                                         'href'  => common_local_url('newnotice')));
734
735         $this->elementStart('div', 'input_forms');
736
737         $this->element('label', array('for'=>'input_form_nav'), _m('TAB', 'Share your:'));
738
739         if (Event::handle('StartShowEntryForms', array(&$tabs))) {
740             $this->elementStart('ul', array('class' => 'nav',
741                                             'id' => 'input_form_nav'));
742
743             foreach ($tabs as $tag => $data) {
744                 $tag = htmlspecialchars($tag);
745                 $attrs = array('id' => 'input_form_nav_'.$tag,
746                                'class' => 'input_form_nav_tab');
747
748                 if ($tag == 'status') {
749                     $attrs['class'] .= ' current';
750                 }
751                 $this->elementStart('li', $attrs);
752
753                 $this->element('a',
754                                array('onclick' => 'return SN.U.switchInputFormTab("'.$tag.'");',
755                                      'href' => $data['href']),
756                                $data['title']);
757                 $this->elementEnd('li');
758             }
759
760             $this->elementEnd('ul');
761
762             foreach ($tabs as $tag => $data) {
763                 $attrs = array('class' => 'input_form',
764                                'id' => 'input_form_'.$tag);
765                 if ($tag == 'status') {
766                     $attrs['class'] .= ' current';
767                 }
768
769                 $this->elementStart('div', $attrs);
770
771                 $form = null;
772
773                 if (Event::handle('StartMakeEntryForm', array($tag, $this, &$form))) {
774                     if ($tag == 'status') {
775                         $options = $this->noticeFormOptions();
776                         $form = new NoticeForm($this, $options);
777                     }
778                     Event::handle('EndMakeEntryForm', array($tag, $this, $form));
779                 }
780
781                 if (!empty($form)) {
782                     $form->show();
783                 }
784
785                 $this->elementEnd('div');
786             }
787         }
788
789         $this->elementEnd('div');
790     }
791
792     function noticeFormOptions()
793     {
794         return array();
795     }
796
797     /**
798      * Show anonymous message.
799      *
800      * SHOULD overload
801      *
802      * @return nothing
803      */
804     function showAnonymousMessage()
805     {
806         // needs to be defined by the class
807     }
808
809     /**
810      * Show core.
811      *
812      * Shows local navigation, content block and aside.
813      *
814      * @return nothing
815      */
816     function showCore()
817     {
818         $this->elementStart('div', array('id' => 'core'));
819         $this->elementStart('div', array('id' => 'aside_primary_wrapper'));
820         $this->elementStart('div', array('id' => 'content_wrapper'));
821         $this->elementStart('div', array('id' => 'site_nav_local_views_wrapper'));
822         if (Event::handle('StartShowLocalNavBlock', array($this))) {
823             $this->showLocalNavBlock();
824             $this->flush();
825             Event::handle('EndShowLocalNavBlock', array($this));
826         }
827         if (Event::handle('StartShowContentBlock', array($this))) {
828             $this->showContentBlock();
829             $this->flush();
830             Event::handle('EndShowContentBlock', array($this));
831         }
832         if (Event::handle('StartShowAside', array($this))) {
833             $this->showAside();
834             $this->flush();
835             Event::handle('EndShowAside', array($this));
836         }
837         $this->elementEnd('div');
838         $this->elementEnd('div');
839         $this->elementEnd('div');
840         $this->elementEnd('div');
841     }
842
843     /**
844      * Show local navigation block.
845      *
846      * @return nothing
847      */
848     function showLocalNavBlock()
849     {
850         // Need to have this ID for CSS; I'm too lazy to add it to
851         // all menus
852         $this->elementStart('div', array('id' => 'site_nav_local_views'));
853         // Cheat cheat cheat!
854         $this->showLocalNav();
855         $this->elementEnd('div');
856     }
857
858     /**
859      * If there's a logged-in user, show a bit of login context
860      *
861      * @return nothing
862      */
863     function showProfileBlock()
864     {
865         if (common_logged_in()) {
866             $block = new DefaultProfileBlock($this);
867             $block->show();
868         }
869     }
870
871     /**
872      * Show local navigation.
873      *
874      * SHOULD overload
875      *
876      * @return nothing
877      */
878     function showLocalNav()
879     {
880         $nav = new DefaultLocalNav($this);
881         $nav->show();
882     }
883
884     /**
885      * Show menu for an object (group, profile)
886      *
887      * This block will only show if a subclass has overridden
888      * the showObjectNav() method.
889      *
890      * @return nothing
891      */
892     function showObjectNavBlock()
893     {
894         $rmethod = new ReflectionMethod($this, 'showObjectNav');
895         $dclass = $rmethod->getDeclaringClass()->getName();
896
897         if ($dclass != 'Action') {
898             // Need to have this ID for CSS; I'm too lazy to add it to
899             // all menus
900             $this->elementStart('div', array('id' => 'site_nav_object',
901                                              'class' => 'section'));
902             $this->showObjectNav();
903             $this->elementEnd('div');
904         }
905     }
906
907     /**
908      * Show object navigation.
909      *
910      * If there are things to do with this object, show it here.
911      *
912      * @return nothing
913      */
914     function showObjectNav()
915     {
916         /* Nothing here. */
917     }
918
919     /**
920      * Show content block.
921      *
922      * @return nothing
923      */
924     function showContentBlock()
925     {
926         $this->elementStart('div', array('id' => 'content'));
927         if (common_logged_in()) {
928             if (Event::handle('StartShowNoticeForm', array($this))) {
929                 $this->showNoticeForm();
930                 Event::handle('EndShowNoticeForm', array($this));
931             }
932         }
933         if (Event::handle('StartShowPageTitle', array($this))) {
934             $this->showPageTitle();
935             Event::handle('EndShowPageTitle', array($this));
936         }
937         $this->showPageNoticeBlock();
938         $this->elementStart('div', array('id' => 'content_inner'));
939         // show the actual content (forms, lists, whatever)
940         $this->showContent();
941         $this->elementEnd('div');
942         $this->elementEnd('div');
943     }
944
945     /**
946      * Show page title.
947      *
948      * @return nothing
949      */
950     function showPageTitle()
951     {
952         $this->element('h1', null, $this->title());
953     }
954
955     /**
956      * Show page notice block.
957      *
958      * Only show the block if a subclassed action has overrided
959      * Action::showPageNotice(), or an event handler is registered for
960      * the StartShowPageNotice event, in which case we assume the
961      * 'page_notice' definition list is desired.  This is to prevent
962      * empty 'page_notice' definition lists from being output everywhere.
963      *
964      * @return nothing
965      */
966     function showPageNoticeBlock()
967     {
968         $rmethod = new ReflectionMethod($this, 'showPageNotice');
969         $dclass = $rmethod->getDeclaringClass()->getName();
970
971         if ($dclass != 'Action' || Event::hasHandler('StartShowPageNotice')) {
972
973             $this->elementStart('div', array('id' => 'page_notice',
974                                             'class' => 'system_notice'));
975             if (Event::handle('StartShowPageNotice', array($this))) {
976                 $this->showPageNotice();
977                 Event::handle('EndShowPageNotice', array($this));
978             }
979             $this->elementEnd('div');
980         }
981     }
982
983     /**
984      * Show page notice.
985      *
986      * SHOULD overload (unless there's not a notice)
987      *
988      * @return nothing
989      */
990     function showPageNotice()
991     {
992     }
993
994     /**
995      * Show content.
996      *
997      * MUST overload (unless there's not a notice)
998      *
999      * @return nothing
1000      */
1001     protected function showContent()
1002     {
1003     }
1004
1005     /**
1006      * Show Aside.
1007      *
1008      * @return nothing
1009      */
1010     function showAside()
1011     {
1012         $this->elementStart('div', array('id' => 'aside_primary',
1013                                          'class' => 'aside'));
1014         $this->showProfileBlock();
1015         if (Event::handle('StartShowObjectNavBlock', array($this))) {
1016             $this->showObjectNavBlock();
1017             Event::handle('EndShowObjectNavBlock', array($this));
1018         }
1019         if (Event::handle('StartShowSections', array($this))) {
1020             $this->showSections();
1021             Event::handle('EndShowSections', array($this));
1022         }
1023         if (Event::handle('StartShowExportData', array($this))) {
1024             $this->showExportData();
1025             Event::handle('EndShowExportData', array($this));
1026         }
1027         $this->elementEnd('div');
1028     }
1029
1030     /**
1031      * Show export data feeds.
1032      *
1033      * @return void
1034      */
1035     function showExportData()
1036     {
1037         $feeds = $this->getFeeds();
1038         if ($feeds) {
1039             $fl = new FeedList($this);
1040             $fl->show($feeds);
1041         }
1042     }
1043
1044     /**
1045      * Show sections.
1046      *
1047      * SHOULD overload
1048      *
1049      * @return nothing
1050      */
1051     function showSections()
1052     {
1053         // for each section, show it
1054     }
1055
1056     /**
1057      * Show footer.
1058      *
1059      * @return nothing
1060      */
1061     function showFooter()
1062     {
1063         $this->elementStart('div', array('id' => 'footer'));
1064         if (Event::handle('StartShowInsideFooter', array($this))) {
1065             $this->showSecondaryNav();
1066             $this->showLicenses();
1067             Event::handle('EndShowInsideFooter', array($this));
1068         }
1069         $this->elementEnd('div');
1070     }
1071
1072     /**
1073      * Show secondary navigation.
1074      *
1075      * @return nothing
1076      */
1077     function showSecondaryNav()
1078     {
1079         $sn = new SecondaryNav($this);
1080         $sn->show();
1081     }
1082
1083     /**
1084      * Show licenses.
1085      *
1086      * @return nothing
1087      */
1088     function showLicenses()
1089     {
1090         $this->showGNUsocialLicense();
1091         $this->showContentLicense();
1092     }
1093
1094     /**
1095      * Show GNU social license.
1096      *
1097      * @return nothing
1098      */
1099     function showGNUsocialLicense()
1100     {
1101         if (common_config('site', 'broughtby')) {
1102             // TRANS: First sentence of the GNU social site license. Used if 'broughtby' is set.
1103             // TRANS: Text between [] is a link description, text between () is the link itself.
1104             // TRANS: Make sure there is no whitespace between "]" and "(".
1105             // TRANS: "%%site.broughtby%%" is the value of the variable site.broughtby
1106             $instr = _('**%%site.name%%** is a social network, courtesy of [%%site.broughtby%%](%%site.broughtbyurl%%).');
1107         } else {
1108             // TRANS: First sentence of the GNU social site license. Used if 'broughtby' is not set.
1109             $instr = _('**%%site.name%%** is a social network.');
1110         }
1111         $instr .= ' ';
1112         // TRANS: Second sentence of the GNU social site license. Mentions the GNU social source code license.
1113         // TRANS: Make sure there is no whitespace between "]" and "(".
1114         // TRANS: [%1$s](%2$s) is a link description followed by the link itself
1115         // TRANS: %3$s is the version of GNU social that is being used.
1116         $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);
1117         $output = common_markup_to_html($instr);
1118         $this->raw($output);
1119         // do it
1120     }
1121
1122     /**
1123      * Show content license.
1124      *
1125      * @return nothing
1126      */
1127     function showContentLicense()
1128     {
1129         if (Event::handle('StartShowContentLicense', array($this))) {
1130             switch (common_config('license', 'type')) {
1131             case 'private':
1132                 // TRANS: Content license displayed when license is set to 'private'.
1133                 // TRANS: %1$s is the site name.
1134                 $this->element('p', null, sprintf(_('Content and data of %1$s are private and confidential.'),
1135                                                   common_config('site', 'name')));
1136                 // fall through
1137             case 'allrightsreserved':
1138                 if (common_config('license', 'owner')) {
1139                     // TRANS: Content license displayed when license is set to 'allrightsreserved'.
1140                     // TRANS: %1$s is the copyright owner.
1141                     $this->element('p', null, sprintf(_('Content and data copyright by %1$s. All rights reserved.'),
1142                                                       common_config('license', 'owner')));
1143                 } else {
1144                     // TRANS: Content license displayed when license is set to 'allrightsreserved' and no owner is set.
1145                     $this->element('p', null, _('Content and data copyright by contributors. All rights reserved.'));
1146                 }
1147                 break;
1148             case 'cc': // fall through
1149             default:
1150                 $this->elementStart('p');
1151
1152                 $image    = common_config('license', 'image');
1153                 $sslimage = common_config('license', 'sslimage');
1154
1155                 if (GNUsocial::isHTTPS()) {
1156                     if (!empty($sslimage)) {
1157                         $url = $sslimage;
1158                     } else if (preg_match('#^http://i.creativecommons.org/#', $image)) {
1159                         // CC support HTTPS on their images
1160                         $url = preg_replace('/^http/', 'https', $image);
1161                     } else {
1162                         // Better to show mixed content than no content
1163                         $url = $image;
1164                     }
1165                 } else {
1166                     $url = $image;
1167                 }
1168
1169                 $this->element('img', array('id' => 'license_cc',
1170                                             'src' => $url,
1171                                             'alt' => common_config('license', 'title'),
1172                                             'width' => '80',
1173                                             'height' => '15'));
1174                 $this->text(' ');
1175                 // TRANS: license message in footer.
1176                 // TRANS: %1$s is the site name, %2$s is a link to the license URL, with a licence name set in configuration.
1177                 $notice = _('All %1$s content and data are available under the %2$s license.');
1178                 $link = sprintf('<a class="license" rel="external license" href="%1$s">%2$s</a>',
1179                                 htmlspecialchars(common_config('license', 'url')),
1180                                 htmlspecialchars(common_config('license', 'title')));
1181                 $this->raw(@sprintf(htmlspecialchars($notice),
1182                                    htmlspecialchars(common_config('site', 'name')),
1183                                    $link));
1184                 $this->elementEnd('p');
1185                 break;
1186             }
1187
1188             Event::handle('EndShowContentLicense', array($this));
1189         }
1190     }
1191
1192     /**
1193      * Return last modified, if applicable.
1194      *
1195      * MAY override
1196      *
1197      * @return string last modified http header
1198      */
1199     function lastModified()
1200     {
1201         // For comparison with If-Last-Modified
1202         // If not applicable, return null
1203         return null;
1204     }
1205
1206     /**
1207      * Return etag, if applicable.
1208      *
1209      * MAY override
1210      *
1211      * @return string etag http header
1212      */
1213     function etag()
1214     {
1215         return null;
1216     }
1217
1218     /**
1219      * Return true if read only.
1220      *
1221      * MAY override
1222      *
1223      * @param array $args other arguments
1224      *
1225      * @return boolean is read only action?
1226      */
1227     function isReadOnly($args)
1228     {
1229         return false;
1230     }
1231
1232     /**
1233      * Returns query argument or default value if not found
1234      *
1235      * @param string $key requested argument
1236      * @param string $def default value to return if $key is not provided
1237      *
1238      * @return boolean is read only action?
1239      */
1240     function arg($key, $def=null)
1241     {
1242         if (array_key_exists($key, $this->args)) {
1243             return $this->args[$key];
1244         } else {
1245             return $def;
1246         }
1247     }
1248
1249     /**
1250      * Returns trimmed query argument or default value if not found
1251      *
1252      * @param string $key requested argument
1253      * @param string $def default value to return if $key is not provided
1254      *
1255      * @return boolean is read only action?
1256      */
1257     function trimmed($key, $def=null)
1258     {
1259         $arg = $this->arg($key, $def);
1260         return is_string($arg) ? trim($arg) : $arg;
1261     }
1262
1263     /**
1264      * Handler method
1265      *
1266      * @return boolean is read only action?
1267      */
1268     protected function handle()
1269     {
1270         header('Vary: Accept-Encoding,Cookie');
1271
1272         $lm   = $this->lastModified();
1273         $etag = $this->etag();
1274
1275         if ($etag) {
1276             header('ETag: ' . $etag);
1277         }
1278
1279         if ($lm) {
1280             header('Last-Modified: ' . date(DATE_RFC1123, $lm));
1281             if ($this->isCacheable()) {
1282                 header( 'Expires: ' . gmdate( 'D, d M Y H:i:s', 0 ) . ' GMT' );
1283                 header( "Cache-Control: private, must-revalidate, max-age=0" );
1284                 header( "Pragma:");
1285             }
1286         }
1287
1288         $checked = false;
1289         if ($etag) {
1290             $if_none_match = (array_key_exists('HTTP_IF_NONE_MATCH', $_SERVER)) ?
1291               $_SERVER['HTTP_IF_NONE_MATCH'] : null;
1292             if ($if_none_match) {
1293                 // If this check fails, ignore the if-modified-since below.
1294                 $checked = true;
1295                 if ($this->_hasEtag($etag, $if_none_match)) {
1296                     header('HTTP/1.1 304 Not Modified');
1297                     // Better way to do this?
1298                     exit(0);
1299                 }
1300             }
1301         }
1302
1303         if (!$checked && $lm && array_key_exists('HTTP_IF_MODIFIED_SINCE', $_SERVER)) {
1304             $if_modified_since = $_SERVER['HTTP_IF_MODIFIED_SINCE'];
1305             $ims = strtotime($if_modified_since);
1306             if ($lm <= $ims) {
1307                 header('HTTP/1.1 304 Not Modified');
1308                 // Better way to do this?
1309                 exit(0);
1310             }
1311         }
1312     }
1313
1314     /**
1315      * Is this action cacheable?
1316      *
1317      * If the action returns a last-modified
1318      *
1319      * @param array $argarray is ignored since it's now passed in in prepare()
1320      *
1321      * @return boolean is read only action?
1322      */
1323     function isCacheable()
1324     {
1325         return true;
1326     }
1327
1328     /**
1329      * Has etag? (private)
1330      *
1331      * @param string $etag          etag http header
1332      * @param string $if_none_match ifNoneMatch http header
1333      *
1334      * @return boolean
1335      */
1336     function _hasEtag($etag, $if_none_match)
1337     {
1338         $etags = explode(',', $if_none_match);
1339         return in_array($etag, $etags) || in_array('*', $etags);
1340     }
1341
1342     /**
1343      * Boolean understands english (yes, no, true, false)
1344      *
1345      * @param string $key query key we're interested in
1346      * @param string $def default value
1347      *
1348      * @return boolean interprets yes/no strings as boolean
1349      */
1350     function boolean($key, $def=false)
1351     {
1352         $arg = strtolower($this->trimmed($key));
1353
1354         if (is_null($arg)) {
1355             return $def;
1356         } else if (in_array($arg, array('true', 'yes', '1', 'on'))) {
1357             return true;
1358         } else if (in_array($arg, array('false', 'no', '0'))) {
1359             return false;
1360         } else {
1361             return $def;
1362         }
1363     }
1364
1365     /**
1366      * This is a cheap hack to avoid a bug in DB_DataObject
1367      * where '' is non-type-aware compared to 0, which means it
1368      * will always be true for values like false and 0 too...
1369      *
1370      * Upstream bug is::
1371      * https://pear.php.net/bugs/bug.php?id=20291
1372      */
1373     function booleanintstring($key, $def=false)
1374     {
1375         return $this->boolean($key, $def) ? '1' : '0';
1376     }
1377
1378     /**
1379      * Integer value of an argument
1380      *
1381      * @param string $key      query key we're interested in
1382      * @param string $defValue optional default value (default null)
1383      * @param string $maxValue optional max value (default null)
1384      * @param string $minValue optional min value (default null)
1385      *
1386      * @return integer integer value
1387      */
1388     function int($key, $defValue=null, $maxValue=null, $minValue=null)
1389     {
1390         $arg = intval($this->arg($key));
1391
1392         if (!is_numeric($this->arg($key)) || $arg != $this->arg($key)) {
1393             return $defValue;
1394         }
1395
1396         if (!is_null($maxValue)) {
1397             $arg = min($arg, $maxValue);
1398         }
1399
1400         if (!is_null($minValue)) {
1401             $arg = max($arg, $minValue);
1402         }
1403
1404         return $arg;
1405     }
1406
1407     /**
1408      * Server error
1409      *
1410      * @param string  $msg  error message to display
1411      * @param integer $code http error code, 500 by default
1412      *
1413      * @return nothing
1414      */
1415     function serverError($msg, $code=500, $format=null)
1416     {
1417         if ($format === null) {
1418             $format = $this->format;
1419         }
1420
1421         common_debug("Server error '{$code}' on '{$this->action}': {$msg}", __FILE__);
1422
1423         if (!array_key_exists($code, ServerErrorAction::$status)) {
1424             $code = 500;
1425         }
1426
1427         $status_string = ServerErrorAction::$status[$code];
1428
1429         switch ($format) {
1430         case 'xml':
1431             header("HTTP/1.1 {$code} {$status_string}");
1432             $this->initDocument('xml');
1433             $this->elementStart('hash');
1434             $this->element('error', null, $msg);
1435             $this->element('request', null, $_SERVER['REQUEST_URI']);
1436             $this->elementEnd('hash');
1437             $this->endDocument('xml');
1438             break;
1439         case 'json':
1440             if (!isset($this->callback)) {
1441                 header("HTTP/1.1 {$code} {$status_string}");
1442             }
1443             $this->initDocument('json');
1444             $error_array = array('error' => $msg, 'request' => $_SERVER['REQUEST_URI']);
1445             print(json_encode($error_array));
1446             $this->endDocument('json');
1447             break;
1448         default:
1449             throw new ServerException($msg, $code);
1450         }
1451
1452         exit((int)$code);
1453     }
1454
1455     /**
1456      * Client error
1457      *
1458      * @param string  $msg    error message to display
1459      * @param integer $code   http error code, 400 by default
1460      * @param string  $format error format (json, xml, text) for ApiAction
1461      *
1462      * @return nothing
1463      * @throws ClientException always
1464      */
1465     function clientError($msg, $code=400, $format=null)
1466     {
1467         // $format is currently only relevant for an ApiAction anyway
1468         if ($format === null) {
1469             $format = $this->format;
1470         }
1471
1472         common_debug("User error '{$code}' on '{$this->action}': {$msg}", __FILE__);
1473
1474         if (!array_key_exists($code, ClientErrorAction::$status)) {
1475             $code = 400;
1476         }
1477         
1478         $status_string = ClientErrorAction::$status[$code];
1479
1480         switch ($format) {
1481         case 'xml':
1482             header("HTTP/1.1 {$code} {$status_string}");
1483             $this->initDocument('xml');
1484             $this->elementStart('hash');
1485             $this->element('error', null, $msg);
1486             $this->element('request', null, $_SERVER['REQUEST_URI']);
1487             $this->elementEnd('hash');
1488             $this->endDocument('xml');
1489             break;
1490         case 'json':
1491             if (!isset($this->callback)) {
1492                 header("HTTP/1.1 {$code} {$status_string}");
1493             }
1494             $this->initDocument('json');
1495             $error_array = array('error' => $msg, 'request' => $_SERVER['REQUEST_URI']);
1496             $this->text(json_encode($error_array));
1497             $this->endDocument('json');
1498             break;
1499         case 'text':
1500             header("HTTP/1.1 {$code} {$status_string}");
1501             header('Content-Type: text/plain; charset=utf-8');
1502             echo $msg;
1503             break;
1504         default:
1505             throw new ClientException($msg, $code);
1506         }
1507         exit((int)$code);
1508     }
1509
1510     /**
1511      * If not logged in, take appropriate action (redir or exception)
1512      *
1513      * @param boolean $redir Redirect to login if not logged in
1514      *
1515      * @return boolean true if logged in (never returns if not)
1516      */
1517     public function checkLogin($redir=true)
1518     {
1519         if (common_logged_in()) {
1520             return true;
1521         }
1522
1523         if ($redir==true) {
1524             common_set_returnto($_SERVER['REQUEST_URI']);
1525             common_redirect(common_local_url('login'));
1526         }
1527
1528         // TRANS: Error message displayed when trying to perform an action that requires a logged in user.
1529         $this->clientError(_('Not logged in.'), 403);
1530     }
1531
1532     /**
1533      * Returns the current URL
1534      *
1535      * @return string current URL
1536      */
1537     function selfUrl()
1538     {
1539         list($action, $args) = $this->returnToArgs();
1540         return common_local_url($action, $args);
1541     }
1542
1543     /**
1544      * Returns arguments sufficient for re-constructing URL
1545      *
1546      * @return array two elements: action, other args
1547      */
1548     function returnToArgs()
1549     {
1550         $action = $this->getActionName();
1551         $args   = $this->args;
1552         unset($args['action']);
1553         if (common_config('site', 'fancy')) {
1554             unset($args['p']);
1555         }
1556         if (array_key_exists('submit', $args)) {
1557             unset($args['submit']);
1558         }
1559         foreach (array_keys($_COOKIE) as $cookie) {
1560             unset($args[$cookie]);
1561         }
1562         return array($action, $args);
1563     }
1564
1565     /**
1566      * Generate a menu item
1567      *
1568      * @param string  $url         menu URL
1569      * @param string  $text        menu name
1570      * @param string  $title       title attribute, null by default
1571      * @param boolean $is_selected current menu item, false by default
1572      * @param string  $id          element id, null by default
1573      *
1574      * @return nothing
1575      */
1576     function menuItem($url, $text, $title=null, $is_selected=false, $id=null, $class=null)
1577     {
1578         // Added @id to li for some control.
1579         // XXX: We might want to move this to htmloutputter.php
1580         $lattrs  = array();
1581         $classes = array();
1582         if ($class !== null) {
1583             $classes[] = trim($class);
1584         }
1585         if ($is_selected) {
1586             $classes[] = 'current';
1587         }
1588
1589         if (!empty($classes)) {
1590             $lattrs['class'] = implode(' ', $classes);
1591         }
1592
1593         if (!is_null($id)) {
1594             $lattrs['id'] = $id;
1595         }
1596
1597         $this->elementStart('li', $lattrs);
1598         $attrs['href'] = $url;
1599         if ($title) {
1600             $attrs['title'] = $title;
1601         }
1602         $this->element('a', $attrs, $text);
1603         $this->elementEnd('li');
1604     }
1605
1606     /**
1607      * Generate pagination links
1608      *
1609      * @param boolean $have_before is there something before?
1610      * @param boolean $have_after  is there something after?
1611      * @param integer $page        current page
1612      * @param string  $action      current action
1613      * @param array   $args        rest of query arguments
1614      *
1615      * @return nothing
1616      */
1617     // XXX: The messages in this pagination method only tailor to navigating
1618     //      notices. In other lists, "Previous"/"Next" type navigation is
1619     //      desirable, but not available.
1620     function pagination($have_before, $have_after, $page, $action, $args=null)
1621     {
1622         // Does a little before-after block for next/prev page
1623         if ($have_before || $have_after) {
1624             $this->elementStart('ul', array('class' => 'nav',
1625                                             'id' => 'pagination'));
1626         }
1627         if ($have_before) {
1628             $pargs   = array('page' => $page-1);
1629             $this->elementStart('li', array('class' => 'nav_prev'));
1630             $this->element('a', array('href' => common_local_url($action, $args, $pargs),
1631                                       'rel' => 'prev'),
1632                            // TRANS: Pagination message to go to a page displaying information more in the
1633                            // TRANS: present than the currently displayed information.
1634                            _('After'));
1635             $this->elementEnd('li');
1636         }
1637         if ($have_after) {
1638             $pargs   = array('page' => $page+1);
1639             $this->elementStart('li', array('class' => 'nav_next'));
1640             $this->element('a', array('href' => common_local_url($action, $args, $pargs),
1641                                       'rel' => 'next'),
1642                            // TRANS: Pagination message to go to a page displaying information more in the
1643                            // TRANS: past than the currently displayed information.
1644                            _('Before'));
1645             $this->elementEnd('li');
1646         }
1647         if ($have_before || $have_after) {
1648             $this->elementEnd('ul');
1649         }
1650     }
1651
1652     /**
1653      * An array of feeds for this action.
1654      *
1655      * Returns an array of potential feeds for this action.
1656      *
1657      * @return array Feed object to show in head and links
1658      */
1659     function getFeeds()
1660     {
1661         return null;
1662     }
1663
1664     /**
1665      * Check the session token.
1666      *
1667      * Checks that the current form has the correct session token,
1668      * and throw an exception if it does not.
1669      *
1670      * @return void
1671      */
1672     // XXX: Finding this type of check with the same message about 50 times.
1673     //      Possible to refactor?
1674     function checkSessionToken()
1675     {
1676         // CSRF protection
1677         $token = $this->trimmed('token');
1678         if (empty($token) || $token != common_session_token()) {
1679             // TRANS: Client error text when there is a problem with the session token.
1680             $this->clientError(_('There was a problem with your session token.'));
1681         }
1682     }
1683
1684     /**
1685      * Check if the current request is a POST
1686      *
1687      * @return boolean true if POST; otherwise false.
1688      */
1689
1690     function isPost()
1691     {
1692         return ($_SERVER['REQUEST_METHOD'] == 'POST');
1693     }
1694 }