]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - lib/action.php
Merge branch '0.7.x' into 0.8.x
[quix0rs-gnu-social.git] / lib / action.php
1 <?php
2 /**
3  * Laconica, 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   Laconica
24  * @author    Evan Prodromou <evan@controlyourself.ca>
25  * @author    Sarven Capadisli <csarven@controlyourself.ca>
26  * @copyright 2008 Control Yourself, Inc.
27  * @license   http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
28  * @link      http://laconi.ca/
29  */
30
31 if (!defined('LACONICA')) {
32     exit(1);
33 }
34
35 require_once INSTALLDIR.'/lib/noticeform.php';
36 require_once INSTALLDIR.'/lib/htmloutputter.php';
37
38 /**
39  * Base class for all actions
40  *
41  * This is the base class for all actions in the package. An action is
42  * more or less a "view" in an MVC framework.
43  *
44  * Actions are responsible for extracting and validating parameters; using
45  * model classes to read and write to the database; and doing ouput.
46  *
47  * @category Output
48  * @package  Laconica
49  * @author   Evan Prodromou <evan@controlyourself.ca>
50  * @author   Sarven Capadisli <csarven@controlyourself.ca>
51  * @license  http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
52  * @link     http://laconi.ca/
53  *
54  * @see      HTMLOutputter
55  */
56 class Action extends HTMLOutputter // lawsuit
57 {
58     var $args;
59
60     /**
61      * Constructor
62      *
63      * Just wraps the HTMLOutputter constructor.
64      *
65      * @param string  $output URI to output to, default = stdout
66      * @param boolean $indent Whether to indent output, default true
67      *
68      * @see XMLOutputter::__construct
69      * @see HTMLOutputter::__construct
70      */
71     function __construct($output='php://output', $indent=true)
72     {
73         parent::__construct($output, $indent);
74     }
75
76     /**
77      * For initializing members of the class.
78      *
79      * @param array $argarray misc. arguments
80      *
81      * @return boolean true
82      */
83     function prepare($argarray)
84     {
85         $this->args =& common_copy_args($argarray);
86         return true;
87     }
88
89     /**
90      * Show page, a template method.
91      *
92      * @return nothing
93      */
94     function showPage()
95     {
96         if (Event::handle('StartShowHTML', array($this))) {
97             $this->startHTML();
98             Event::handle('EndShowHTML', array($this));
99         }
100         $this->showHead();
101         $this->showBody();
102         $this->endHTML();
103     }
104
105     /**
106      * Show head, a template method.
107      *
108      * @return nothing
109      */
110     function showHead()
111     {
112         // XXX: attributes (profile?)
113         $this->elementStart('head');
114         $this->showTitle();
115         $this->showStylesheets();
116         $this->showScripts();
117         $this->showOpenSearch();
118         $this->showFeeds();
119         $this->showDescription();
120         $this->extraHead();
121         $this->elementEnd('head');
122     }
123
124     /**
125      * Show title, a template method.
126      *
127      * @return nothing
128      */
129     function showTitle()
130     {
131         $this->element('title', null,
132                        sprintf(_("%s - %s"),
133                                $this->title(),
134                                common_config('site', 'name')));
135     }
136
137     /**
138      * Returns the page title
139      *
140      * SHOULD overload
141      *
142      * @return string page title
143      */
144
145     function title()
146     {
147         return _("Untitled page");
148     }
149
150     /**
151      * Show stylesheets
152      *
153      * @return nothing
154      */
155     function showStylesheets()
156     {
157         if (Event::handle('StartShowStyles', array($this))) {
158             if (Event::handle('StartShowLaconicaStyles', array($this))) {
159                 $this->element('link', array('rel' => 'stylesheet',
160                                              'type' => 'text/css',
161                                              'href' => theme_path('css/display.css', 'base') . '?version=' . LACONICA_VERSION,
162                                              'media' => 'screen, projection, tv'));
163                 $this->element('link', array('rel' => 'stylesheet',
164                                              'type' => 'text/css',
165                                              'href' => theme_path('css/display.css', null) . '?version=' . LACONICA_VERSION,
166                                              'media' => 'screen, projection, tv'));
167                 if (common_config('site', 'mobile')) {
168                     $this->element('link', array('rel' => 'stylesheet',
169                                                  'type' => 'text/css',
170                                                  'href' => theme_path('css/mobile.css', 'base') . '?version=' . LACONICA_VERSION,
171                                                  // TODO: "handheld" CSS for other mobile devices
172                                                  'media' => 'only screen and (max-device-width: 480px)')); // Mobile WebKit
173                 }
174                 $this->element('link', array('rel' => 'stylesheet',
175                                              'type' => 'text/css',
176                                              'href' => theme_path('css/print.css', 'base') . '?version=' . LACONICA_VERSION,
177                                              'media' => 'print'));
178                 Event::handle('EndShowLaconicaStyles', array($this));
179             }
180             if (Event::handle('StartShowUAStyles', array($this))) {
181                 $this->comment('[if IE]><link rel="stylesheet" type="text/css" '.
182                                'href="'.theme_path('css/ie.css', 'base').'?version='.LACONICA_VERSION.'" /><![endif]');
183                 foreach (array(6,7) as $ver) {
184                     if (file_exists(theme_file('css/ie'.$ver.'.css', 'base'))) {
185                         // Yes, IE people should be put in jail.
186                         $this->comment('[if lte IE '.$ver.']><link rel="stylesheet" type="text/css" '.
187                                        'href="'.theme_path('css/ie'.$ver.'.css', 'base').'?version='.LACONICA_VERSION.'" /><![endif]');
188                     }
189                 }
190                 $this->comment('[if IE]><link rel="stylesheet" type="text/css" '.
191                                'href="'.theme_path('css/ie.css', null).'?version='.LACONICA_VERSION.'" /><![endif]');
192                 Event::handle('EndShowUAStyles', array($this));
193             }
194             Event::handle('EndShowStyles', array($this));
195         }
196     }
197
198     /**
199      * Show javascript headers
200      *
201      * @return nothing
202      */
203     function showScripts()
204     {
205         if (Event::handle('StartShowScripts', array($this))) {
206             if (Event::handle('StartShowJQueryScripts', array($this))) {
207                 $this->element('script', array('type' => 'text/javascript',
208                                                'src' => common_path('js/jquery.min.js')),
209                                ' ');
210                 $this->element('script', array('type' => 'text/javascript',
211                                                'src' => common_path('js/jquery.form.js')),
212                                ' ');
213                 Event::handle('EndShowJQueryScripts', array($this));
214             }
215             if (Event::handle('StartShowLaconicaScripts', array($this))) {
216                 $this->element('script', array('type' => 'text/javascript',
217                                                'src' => common_path('js/xbImportNode.js')),
218                                ' ');
219                 $this->element('script', array('type' => 'text/javascript',
220                                                'src' => common_path('js/util.js?version='.LACONICA_VERSION)),
221                                ' ');
222                 // Frame-busting code to avoid clickjacking attacks.
223                 $this->element('script', array('type' => 'text/javascript'),
224                                'if (window.top !== window.self) { window.top.location.href = window.self.location.href; }');
225                 Event::handle('EndShowLaconicaScripts', array($this));
226             }
227             Event::handle('EndShowScripts', array($this));
228         }
229     }
230
231     /**
232      * Show OpenSearch headers
233      *
234      * @return nothing
235      */
236     function showOpenSearch()
237     {
238         $this->element('link', array('rel' => 'search',
239                                      'type' => 'application/opensearchdescription+xml',
240                                      'href' =>  common_local_url('opensearch', array('type' => 'people')),
241                                      'title' => common_config('site', 'name').' People Search'));
242         $this->element('link', array('rel' => 'search', 'type' => 'application/opensearchdescription+xml',
243                                      'href' =>  common_local_url('opensearch', array('type' => 'notice')),
244                                      'title' => common_config('site', 'name').' Notice Search'));
245     }
246
247     /**
248      * Show feed headers
249      *
250      * MAY overload
251      *
252      * @return nothing
253      */
254
255     function showFeeds()
256     {
257         $feeds = $this->getFeeds();
258
259         if ($feeds) {
260             foreach ($feeds as $feed) {
261                 $this->element('link', array('rel' => $feed->rel(),
262                                              'href' => $feed->url,
263                                              'type' => $feed->mimeType(),
264                                              'title' => $feed->title));
265             }
266         }
267     }
268
269     /**
270      * Show description.
271      *
272      * SHOULD overload
273      *
274      * @return nothing
275      */
276     function showDescription()
277     {
278         // does nothing by default
279     }
280
281     /**
282      * Show extra stuff in <head>.
283      *
284      * MAY overload
285      *
286      * @return nothing
287      */
288     function extraHead()
289     {
290         // does nothing by default
291     }
292
293     /**
294      * Show body.
295      *
296      * Calls template methods
297      *
298      * @return nothing
299      */
300     function showBody()
301     {
302         $this->elementStart('body', array('id' => $this->trimmed('action')));
303         $this->elementStart('div', array('id' => 'wrap'));
304         if (Event::handle('StartShowHeader', array($this))) {
305             $this->showHeader();
306             Event::handle('EndShowHeader', array($this));
307         }
308         $this->showCore();
309         if (Event::handle('StartShowFooter', array($this))) {
310             $this->showFooter();
311             Event::handle('EndShowFooter', array($this));
312         }
313         $this->elementEnd('div');
314         $this->elementEnd('body');
315     }
316
317     /**
318      * Show header of the page.
319      *
320      * Calls template methods
321      *
322      * @return nothing
323      */
324     function showHeader()
325     {
326         $this->elementStart('div', array('id' => 'header'));
327         $this->showLogo();
328         $this->showPrimaryNav();
329         $this->showSiteNotice();
330         if (common_logged_in()) {
331             $this->showNoticeForm();
332         } else {
333             $this->showAnonymousMessage();
334         }
335         $this->elementEnd('div');
336     }
337
338     /**
339      * Show configured logo.
340      *
341      * @return nothing
342      */
343     function showLogo()
344     {
345         $this->elementStart('address', array('id' => 'site_contact',
346                                              'class' => 'vcard'));
347         $this->elementStart('a', array('class' => 'url home bookmark',
348                                        'href' => common_local_url('public')));
349         if (common_config('site', 'logo') || file_exists(theme_file('logo.png'))) {
350             $this->element('img', array('class' => 'logo photo',
351                                         'src' => (common_config('site', 'logo')) ? common_config('site', 'logo') : theme_path('logo.png'),
352                                         'alt' => common_config('site', 'name')));
353         }
354         $this->element('span', array('class' => 'fn org'), common_config('site', 'name'));
355         $this->elementEnd('a');
356         $this->elementEnd('address');
357     }
358
359     /**
360      * Show primary navigation.
361      *
362      * @return nothing
363      */
364     function showPrimaryNav()
365     {
366         $user = common_current_user();
367
368         $this->elementStart('dl', array('id' => 'site_nav_global_primary'));
369         $this->element('dt', null, _('Primary site navigation'));
370         $this->elementStart('dd');
371         $this->elementStart('ul', array('class' => 'nav'));
372         if (Event::handle('StartPrimaryNav', array($this))) {
373             if ($user) {
374                 $this->menuItem(common_local_url('all', array('nickname' => $user->nickname)),
375                                 _('Home'), _('Personal profile and friends timeline'), false, 'nav_home');
376             }
377             $this->menuItem(common_local_url('peoplesearch'),
378                             _('Search'), _('Search for people or text'), false, 'nav_search');
379             if ($user) {
380                 $this->menuItem(common_local_url('profilesettings'),
381                                 _('Account'), _('Change your email, avatar, password, profile'), false, 'nav_account');
382
383                 if (common_config('xmpp', 'enabled')) {
384                     $this->menuItem(common_local_url('imsettings'),
385                                     _('Connect'), _('Connect to IM, SMS, Twitter'), false, 'nav_connect');
386                 } else {
387                     $this->menuItem(common_local_url('smssettings'),
388                                     _('Connect'), _('Connect to SMS, Twitter'), false, 'nav_connect');
389                 }
390                 $this->menuItem(common_local_url('logout'),
391                                 _('Logout'), _('Logout from the site'), false, 'nav_logout');
392             } else {
393                 $this->menuItem(common_local_url('login'),
394                                 _('Login'), _('Login to the site'), false, 'nav_login');
395                 if (!common_config('site', 'closed')) {
396                     $this->menuItem(common_local_url('register'),
397                                     _('Register'), _('Create an account'), false, 'nav_register');
398                 }
399                 $this->menuItem(common_local_url('openidlogin'),
400                                 _('OpenID'), _('Login with OpenID'), false, 'nav_openid');
401             }
402             $this->menuItem(common_local_url('doc', array('title' => 'help')),
403                             _('Help'), _('Help me!'), false, 'nav_help');
404             Event::handle('EndPrimaryNav', array($this));
405         }
406         $this->elementEnd('ul');
407         $this->elementEnd('dd');
408         $this->elementEnd('dl');
409     }
410
411     /**
412      * Show site notice.
413      *
414      * @return nothing
415      */
416     function showSiteNotice()
417     {
418         // Revist. Should probably do an hAtom pattern here
419         $text = common_config('site', 'notice');
420         if ($text) {
421             $this->elementStart('dl', array('id' => 'site_notice',
422                                             'class' => 'system_notice'));
423             $this->element('dt', null, _('Site notice'));
424             $this->elementStart('dd', null);
425             $this->raw($text);
426             $this->elementEnd('dd');
427             $this->elementEnd('dl');
428         }
429     }
430
431     /**
432      * Show notice form.
433      *
434      * MAY overload if no notice form needed... or direct message box????
435      *
436      * @return nothing
437      */
438     function showNoticeForm()
439     {
440         $notice_form = new NoticeForm($this);
441         $notice_form->show();
442     }
443
444     /**
445      * Show anonymous message.
446      *
447      * SHOULD overload
448      *
449      * @return nothing
450      */
451     function showAnonymousMessage()
452     {
453         // needs to be defined by the class
454     }
455
456     /**
457      * Show core.
458      *
459      * Shows local navigation, content block and aside.
460      *
461      * @return nothing
462      */
463     function showCore()
464     {
465         $this->elementStart('div', array('id' => 'core'));
466         if (Event::handle('StartShowLocalNavBlock', array($this))) {
467             $this->showLocalNavBlock();
468             Event::handle('EndShowLocalNavBlock', array($this));
469         }
470         if (Event::handle('StartShowContentBlock', array($this))) {
471             $this->showContentBlock();
472             Event::handle('EndShowContentBlock', array($this));
473         }
474         $this->showAside();
475         $this->elementEnd('div');
476     }
477
478     /**
479      * Show local navigation block.
480      *
481      * @return nothing
482      */
483     function showLocalNavBlock()
484     {
485         $this->elementStart('dl', array('id' => 'site_nav_local_views'));
486         $this->element('dt', null, _('Local views'));
487         $this->elementStart('dd');
488         $this->showLocalNav();
489         $this->elementEnd('dd');
490         $this->elementEnd('dl');
491     }
492
493     /**
494      * Show local navigation.
495      *
496      * SHOULD overload
497      *
498      * @return nothing
499      */
500     function showLocalNav()
501     {
502         // does nothing by default
503     }
504
505     /**
506      * Show content block.
507      *
508      * @return nothing
509      */
510     function showContentBlock()
511     {
512         $this->elementStart('div', array('id' => 'content'));
513         $this->showPageTitle();
514         $this->showPageNoticeBlock();
515         $this->elementStart('div', array('id' => 'content_inner'));
516         // show the actual content (forms, lists, whatever)
517         $this->showContent();
518         $this->elementEnd('div');
519         $this->elementEnd('div');
520     }
521
522     /**
523      * Show page title.
524      *
525      * @return nothing
526      */
527     function showPageTitle()
528     {
529         $this->element('h1', null, $this->title());
530     }
531
532     /**
533      * Show page notice block.
534      *
535      * @return nothing
536      */
537     function showPageNoticeBlock()
538     {
539         $this->elementStart('dl', array('id' => 'page_notice',
540                                         'class' => 'system_notice'));
541         $this->element('dt', null, _('Page notice'));
542         $this->elementStart('dd');
543         $this->showPageNotice();
544         $this->elementEnd('dd');
545         $this->elementEnd('dl');
546     }
547
548     /**
549      * Show page notice.
550      *
551      * SHOULD overload (unless there's not a notice)
552      *
553      * @return nothing
554      */
555     function showPageNotice()
556     {
557     }
558
559     /**
560      * Show content.
561      *
562      * MUST overload (unless there's not a notice)
563      *
564      * @return nothing
565      */
566     function showContent()
567     {
568     }
569
570     /**
571      * Show Aside.
572      *
573      * @return nothing
574      */
575
576     function showAside()
577     {
578         $this->elementStart('div', array('id' => 'aside_primary',
579                                          'class' => 'aside'));
580         $this->showExportData();
581         if (Event::handle('StartShowSections', array($this))) {
582             $this->showSections();
583             Event::handle('EndShowSections', array($this));
584         }
585         $this->elementEnd('div');
586     }
587
588     /**
589      * Show export data feeds.
590      *
591      * @return void
592      */
593
594     function showExportData()
595     {
596         $feeds = $this->getFeeds();
597         if ($feeds) {
598             $fl = new FeedList($this);
599             $fl->show($feeds);
600         }
601     }
602
603     /**
604      * Show sections.
605      *
606      * SHOULD overload
607      *
608      * @return nothing
609      */
610     function showSections()
611     {
612         // for each section, show it
613     }
614
615     /**
616      * Show footer.
617      *
618      * @return nothing
619      */
620     function showFooter()
621     {
622         $this->elementStart('div', array('id' => 'footer'));
623         $this->showSecondaryNav();
624         $this->showLicenses();
625         $this->elementEnd('div');
626     }
627
628     /**
629      * Show secondary navigation.
630      *
631      * @return nothing
632      */
633     function showSecondaryNav()
634     {
635         $this->elementStart('dl', array('id' => 'site_nav_global_secondary'));
636         $this->element('dt', null, _('Secondary site navigation'));
637         $this->elementStart('dd', null);
638         $this->elementStart('ul', array('class' => 'nav'));
639         if (Event::handle('StartSecondaryNav', array($this))) {
640             $this->menuItem(common_local_url('doc', array('title' => 'help')),
641                             _('Help'));
642             $this->menuItem(common_local_url('doc', array('title' => 'about')),
643                             _('About'));
644             $this->menuItem(common_local_url('doc', array('title' => 'faq')),
645                             _('FAQ'));
646             $this->menuItem(common_local_url('doc', array('title' => 'privacy')),
647                             _('Privacy'));
648             $this->menuItem(common_local_url('doc', array('title' => 'source')),
649                             _('Source'));
650             $this->menuItem(common_local_url('doc', array('title' => 'contact')),
651                             _('Contact'));
652             $this->menuItem(common_local_url('doc', array('title' => 'badge')),
653                             _('Badge'));
654             Event::handle('EndSecondaryNav', array($this));
655         }
656         $this->elementEnd('ul');
657         $this->elementEnd('dd');
658         $this->elementEnd('dl');
659     }
660
661     /**
662      * Show licenses.
663      *
664      * @return nothing
665      */
666     function showLicenses()
667     {
668         $this->elementStart('dl', array('id' => 'licenses'));
669         $this->showLaconicaLicense();
670         $this->showContentLicense();
671         $this->elementEnd('dl');
672     }
673
674     /**
675      * Show Laconica license.
676      *
677      * @return nothing
678      */
679     function showLaconicaLicense()
680     {
681         $this->element('dt', array('id' => 'site_laconica_license'), _('Laconica software license'));
682         $this->elementStart('dd', null);
683         if (common_config('site', 'broughtby')) {
684             $instr = _('**%%site.name%%** is a microblogging service brought to you by [%%site.broughtby%%](%%site.broughtbyurl%%). ');
685         } else {
686             $instr = _('**%%site.name%%** is a microblogging service. ');
687         }
688         $instr .= sprintf(_('It runs the [Laconica](http://laconi.ca/) microblogging software, version %s, available under the [GNU Affero General Public License](http://www.fsf.org/licensing/licenses/agpl-3.0.html).'), LACONICA_VERSION);
689         $output = common_markup_to_html($instr);
690         $this->raw($output);
691         $this->elementEnd('dd');
692         // do it
693     }
694
695     /**
696      * Show content license.
697      *
698      * @return nothing
699      */
700     function showContentLicense()
701     {
702         $this->element('dt', array('id' => 'site_content_license'), _('Laconica software license'));
703         $this->elementStart('dd', array('id' => 'site_content_license_cc'));
704         $this->elementStart('p');
705         $this->element('img', array('id' => 'license_cc',
706                                     'src' => common_config('license', 'image'),
707                                     'alt' => common_config('license', 'title')));
708         //TODO: This is dirty: i18n
709         $this->text(_('All '.common_config('site', 'name').' content and data are available under the '));
710         $this->element('a', array('class' => 'license',
711                                   'rel' => 'external license',
712                                   'href' => common_config('license', 'url')),
713                        common_config('license', 'title'));
714         $this->text(_('license.'));
715         $this->elementEnd('p');
716         $this->elementEnd('dd');
717     }
718
719     /**
720      * Return last modified, if applicable.
721      *
722      * MAY override
723      *
724      * @return string last modified http header
725      */
726     function lastModified()
727     {
728         // For comparison with If-Last-Modified
729         // If not applicable, return null
730         return null;
731     }
732
733     /**
734      * Return etag, if applicable.
735      *
736      * MAY override
737      *
738      * @return string etag http header
739      */
740     function etag()
741     {
742         return null;
743     }
744
745     /**
746      * Return true if read only.
747      *
748      * MAY override
749      *
750      * @return boolean is read only action?
751      */
752     function isReadOnly()
753     {
754         return false;
755     }
756
757     /**
758      * Returns query argument or default value if not found
759      *
760      * @param string $key requested argument
761      * @param string $def default value to return if $key is not provided
762      *
763      * @return boolean is read only action?
764      */
765     function arg($key, $def=null)
766     {
767         if (array_key_exists($key, $this->args)) {
768             return $this->args[$key];
769         } else {
770             return $def;
771         }
772     }
773
774     /**
775      * Returns trimmed query argument or default value if not found
776      *
777      * @param string $key requested argument
778      * @param string $def default value to return if $key is not provided
779      *
780      * @return boolean is read only action?
781      */
782     function trimmed($key, $def=null)
783     {
784         $arg = $this->arg($key, $def);
785         return is_string($arg) ? trim($arg) : $arg;
786     }
787
788     /**
789      * Handler method
790      *
791      * @param array $argarray is ignored since it's now passed in in prepare()
792      *
793      * @return boolean is read only action?
794      */
795     function handle($argarray=null)
796     {
797         $lm   = $this->lastModified();
798         $etag = $this->etag();
799         if ($etag) {
800             header('ETag: ' . $etag);
801         }
802         if ($lm) {
803             header('Last-Modified: ' . date(DATE_RFC1123, $lm));
804             if (array_key_exists('HTTP_IF_MODIFIED_SINCE', $_SERVER)) {
805                 $if_modified_since = $_SERVER['HTTP_IF_MODIFIED_SINCE'];
806                 $ims = strtotime($if_modified_since);
807                 if ($lm <= $ims) {
808                     $if_none_match = (array_key_exists('HTTP_IF_NONE_MATCH', $_SERVER)) ?
809                       $_SERVER['HTTP_IF_NONE_MATCH'] : null;
810                     if (!$if_none_match ||
811                         !$etag ||
812                         $this->_hasEtag($etag, $if_none_match)) {
813                         header('HTTP/1.1 304 Not Modified');
814                         // Better way to do this?
815                         exit(0);
816                     }
817                 }
818             }
819         }
820     }
821
822     /**
823      * HasĀ etag? (private)
824      *
825      * @param string $etag          etag http header
826      * @param string $if_none_match ifNoneMatch http header
827      *
828      * @return boolean
829      */
830
831     function _hasEtag($etag, $if_none_match)
832     {
833         $etags = explode(',', $if_none_match);
834         return in_array($etag, $etags) || in_array('*', $etags);
835     }
836
837     /**
838      * Boolean understands english (yes, no, true, false)
839      *
840      * @param string $key query key we're interested in
841      * @param string $def default value
842      *
843      * @return boolean interprets yes/no strings as boolean
844      */
845     function boolean($key, $def=false)
846     {
847         $arg = strtolower($this->trimmed($key));
848
849         if (is_null($arg)) {
850             return $def;
851         } else if (in_array($arg, array('true', 'yes', '1'))) {
852             return true;
853         } else if (in_array($arg, array('false', 'no', '0'))) {
854             return false;
855         } else {
856             return $def;
857         }
858     }
859
860     /**
861      * Server error
862      *
863      * @param string  $msg  error message to display
864      * @param integer $code http error code, 500 by default
865      *
866      * @return nothing
867      */
868
869     function serverError($msg, $code=500)
870     {
871         $action = $this->trimmed('action');
872         common_debug("Server error '$code' on '$action': $msg", __FILE__);
873         throw new ServerException($msg, $code);
874     }
875
876     /**
877      * Client error
878      *
879      * @param string  $msg  error message to display
880      * @param integer $code http error code, 400 by default
881      *
882      * @return nothing
883      */
884
885     function clientError($msg, $code=400)
886     {
887         $action = $this->trimmed('action');
888         common_debug("User error '$code' on '$action': $msg", __FILE__);
889         throw new ClientException($msg, $code);
890     }
891
892     /**
893      * Returns the current URL
894      *
895      * @return string current URL
896      */
897     function selfUrl()
898     {
899         $action = $this->trimmed('action');
900         $args   = $this->args;
901         unset($args['action']);
902         foreach (array_keys($_COOKIE) as $cookie) {
903             unset($args[$cookie]);
904         }
905         return common_local_url($action, $args);
906     }
907
908     /**
909      * Generate a menu item
910      *
911      * @param string  $url         menu URL
912      * @param string  $text        menu name
913      * @param string  $title       title attribute, null by default
914      * @param boolean $is_selected current menu item, false by default
915      * @param string  $id          element id, null by default
916      *
917      * @return nothing
918      */
919     function menuItem($url, $text, $title=null, $is_selected=false, $id=null)
920     {
921         // Added @id to li for some control.
922         // XXX: We might want to move this to htmloutputter.php
923         $lattrs = array();
924         if ($is_selected) {
925             $lattrs['class'] = 'current';
926         }
927
928         (is_null($id)) ? $lattrs : $lattrs['id'] = $id;
929
930         $this->elementStart('li', $lattrs);
931         $attrs['href'] = $url;
932         if ($title) {
933             $attrs['title'] = $title;
934         }
935         $this->element('a', $attrs, $text);
936         $this->elementEnd('li');
937     }
938
939     /**
940      * Generate pagination links
941      *
942      * @param boolean $have_before is there something before?
943      * @param boolean $have_after  is there something after?
944      * @param integer $page        current page
945      * @param string  $action      current action
946      * @param array   $args        rest of query arguments
947      *
948      * @return nothing
949      */
950     function pagination($have_before, $have_after, $page, $action, $args=null)
951     {
952         // Does a little before-after block for next/prev page
953         if ($have_before || $have_after) {
954             $this->elementStart('div', array('class' => 'pagination'));
955             $this->elementStart('dl', null);
956             $this->element('dt', null, _('Pagination'));
957             $this->elementStart('dd', null);
958             $this->elementStart('ul', array('class' => 'nav'));
959         }
960         if ($have_before) {
961             $pargs   = array('page' => $page-1);
962             $this->elementStart('li', array('class' => 'nav_prev'));
963             $this->element('a', array('href' => common_local_url($action, $args, $pargs),
964                                       'rel' => 'prev'),
965                            _('After'));
966             $this->elementEnd('li');
967         }
968         if ($have_after) {
969             $pargs   = array('page' => $page+1);
970             $this->elementStart('li', array('class' => 'nav_next'));
971             $this->element('a', array('href' => common_local_url($action, $args, $pargs),
972                                       'rel' => 'next'),
973                            _('Before'));
974             $this->elementEnd('li');
975         }
976         if ($have_before || $have_after) {
977             $this->elementEnd('ul');
978             $this->elementEnd('dd');
979             $this->elementEnd('dl');
980             $this->elementEnd('div');
981         }
982     }
983
984     /**
985      * An array of feeds for this action.
986      *
987      * Returns an array of potential feeds for this action.
988      *
989      * @return array Feed object to show in head and links
990      */
991
992     function getFeeds()
993     {
994         return null;
995     }
996 }