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