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