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