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