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