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