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