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