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