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