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