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