]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - lib/action.php
Selector to allow styles when a user is logged in.
[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', (common_current_user()) ? array('id' => $this->trimmed('action'),
303                                                                     'class' => 'user_in')
304                                                             : array('id' => $this->trimmed('action')));
305         $this->elementStart('div', array('id' => 'wrap'));
306         if (Event::handle('StartShowHeader', array($this))) {
307             $this->showHeader();
308             Event::handle('EndShowHeader', array($this));
309         }
310         $this->showCore();
311         if (Event::handle('StartShowFooter', array($this))) {
312             $this->showFooter();
313             Event::handle('EndShowFooter', array($this));
314         }
315         $this->elementEnd('div');
316         $this->elementEnd('body');
317     }
318
319     /**
320      * Show header of the page.
321      *
322      * Calls template methods
323      *
324      * @return nothing
325      */
326     function showHeader()
327     {
328         $this->elementStart('div', array('id' => 'header'));
329         $this->showLogo();
330         $this->showPrimaryNav();
331         $this->showSiteNotice();
332         if (common_logged_in()) {
333             $this->showNoticeForm();
334         } else {
335             $this->showAnonymousMessage();
336         }
337         $this->elementEnd('div');
338     }
339
340     /**
341      * Show configured logo.
342      *
343      * @return nothing
344      */
345     function showLogo()
346     {
347         $this->elementStart('address', array('id' => 'site_contact',
348                                              'class' => 'vcard'));
349         $this->elementStart('a', array('class' => 'url home bookmark',
350                                        'href' => common_local_url('public')));
351         if (common_config('site', 'logo') || file_exists(theme_file('logo.png'))) {
352             $this->element('img', array('class' => 'logo photo',
353                                         'src' => (common_config('site', 'logo')) ? common_config('site', 'logo') : theme_path('logo.png'),
354                                         'alt' => common_config('site', 'name')));
355         }
356         $this->element('span', array('class' => 'fn org'), common_config('site', 'name'));
357         $this->elementEnd('a');
358         $this->elementEnd('address');
359     }
360
361     /**
362      * Show primary navigation.
363      *
364      * @return nothing
365      */
366     function showPrimaryNav()
367     {
368         $user = common_current_user();
369
370         $this->elementStart('dl', array('id' => 'site_nav_global_primary'));
371         $this->element('dt', null, _('Primary site navigation'));
372         $this->elementStart('dd');
373         $this->elementStart('ul', array('class' => 'nav'));
374         if (Event::handle('StartPrimaryNav', array($this))) {
375             if ($user) {
376                 $this->menuItem(common_local_url('all', array('nickname' => $user->nickname)),
377                                 _('Home'), _('Personal profile and friends timeline'), false, 'nav_home');
378             }
379             $this->menuItem(common_local_url('peoplesearch'),
380                             _('Search'), _('Search for people or text'), false, 'nav_search');
381             if ($user) {
382                 $this->menuItem(common_local_url('profilesettings'),
383                                 _('Account'), _('Change your email, avatar, password, profile'), false, 'nav_account');
384
385                 if (common_config('xmpp', 'enabled')) {
386                     $this->menuItem(common_local_url('imsettings'),
387                                     _('Connect'), _('Connect to IM, SMS, Twitter'), false, 'nav_connect');
388                 } else {
389                     $this->menuItem(common_local_url('smssettings'),
390                                     _('Connect'), _('Connect to SMS, Twitter'), false, 'nav_connect');
391                 }
392                 $this->menuItem(common_local_url('logout'),
393                                 _('Logout'), _('Logout from the site'), false, 'nav_logout');
394             } else {
395                 $this->menuItem(common_local_url('login'),
396                                 _('Login'), _('Login to the site'), false, 'nav_login');
397                 if (!common_config('site', 'closed')) {
398                     $this->menuItem(common_local_url('register'),
399                                     _('Register'), _('Create an account'), false, 'nav_register');
400                 }
401                 $this->menuItem(common_local_url('openidlogin'),
402                                 _('OpenID'), _('Login with OpenID'), false, 'nav_openid');
403             }
404             $this->menuItem(common_local_url('doc', array('title' => 'help')),
405                             _('Help'), _('Help me!'), false, 'nav_help');
406             Event::handle('EndPrimaryNav', array($this));
407         }
408         $this->elementEnd('ul');
409         $this->elementEnd('dd');
410         $this->elementEnd('dl');
411     }
412
413     /**
414      * Show site notice.
415      *
416      * @return nothing
417      */
418     function showSiteNotice()
419     {
420         // Revist. Should probably do an hAtom pattern here
421         $text = common_config('site', 'notice');
422         if ($text) {
423             $this->elementStart('dl', array('id' => 'site_notice',
424                                             'class' => 'system_notice'));
425             $this->element('dt', null, _('Site notice'));
426             $this->elementStart('dd', null);
427             $this->raw($text);
428             $this->elementEnd('dd');
429             $this->elementEnd('dl');
430         }
431     }
432
433     /**
434      * Show notice form.
435      *
436      * MAY overload if no notice form needed... or direct message box????
437      *
438      * @return nothing
439      */
440     function showNoticeForm()
441     {
442         $notice_form = new NoticeForm($this);
443         $notice_form->show();
444     }
445
446     /**
447      * Show anonymous message.
448      *
449      * SHOULD overload
450      *
451      * @return nothing
452      */
453     function showAnonymousMessage()
454     {
455         // needs to be defined by the class
456     }
457
458     /**
459      * Show core.
460      *
461      * Shows local navigation, content block and aside.
462      *
463      * @return nothing
464      */
465     function showCore()
466     {
467         $this->elementStart('div', array('id' => 'core'));
468         if (Event::handle('StartShowLocalNavBlock', array($this))) {
469             $this->showLocalNavBlock();
470             Event::handle('EndShowLocalNavBlock', array($this));
471         }
472         if (Event::handle('StartShowContentBlock', array($this))) {
473             $this->showContentBlock();
474             Event::handle('EndShowContentBlock', array($this));
475         }
476         $this->showAside();
477         $this->elementEnd('div');
478     }
479
480     /**
481      * Show local navigation block.
482      *
483      * @return nothing
484      */
485     function showLocalNavBlock()
486     {
487         $this->elementStart('dl', array('id' => 'site_nav_local_views'));
488         $this->element('dt', null, _('Local views'));
489         $this->elementStart('dd');
490         $this->showLocalNav();
491         $this->elementEnd('dd');
492         $this->elementEnd('dl');
493     }
494
495     /**
496      * Show local navigation.
497      *
498      * SHOULD overload
499      *
500      * @return nothing
501      */
502     function showLocalNav()
503     {
504         // does nothing by default
505     }
506
507     /**
508      * Show content block.
509      *
510      * @return nothing
511      */
512     function showContentBlock()
513     {
514         $this->elementStart('div', array('id' => 'content'));
515         $this->showPageTitle();
516         $this->showPageNoticeBlock();
517         $this->elementStart('div', array('id' => 'content_inner'));
518         // show the actual content (forms, lists, whatever)
519         $this->showContent();
520         $this->elementEnd('div');
521         $this->elementEnd('div');
522     }
523
524     /**
525      * Show page title.
526      *
527      * @return nothing
528      */
529     function showPageTitle()
530     {
531         $this->element('h1', null, $this->title());
532     }
533
534     /**
535      * Show page notice block.
536      *
537      * @return nothing
538      */
539     function showPageNoticeBlock()
540     {
541         $this->elementStart('dl', array('id' => 'page_notice',
542                                         'class' => 'system_notice'));
543         $this->element('dt', null, _('Page notice'));
544         $this->elementStart('dd');
545         $this->showPageNotice();
546         $this->elementEnd('dd');
547         $this->elementEnd('dl');
548     }
549
550     /**
551      * Show page notice.
552      *
553      * SHOULD overload (unless there's not a notice)
554      *
555      * @return nothing
556      */
557     function showPageNotice()
558     {
559     }
560
561     /**
562      * Show content.
563      *
564      * MUST overload (unless there's not a notice)
565      *
566      * @return nothing
567      */
568     function showContent()
569     {
570     }
571
572     /**
573      * Show Aside.
574      *
575      * @return nothing
576      */
577
578     function showAside()
579     {
580         $this->elementStart('div', array('id' => 'aside_primary',
581                                          'class' => 'aside'));
582         $this->showExportData();
583         if (Event::handle('StartShowSections', array($this))) {
584             $this->showSections();
585             Event::handle('EndShowSections', array($this));
586         }
587         $this->elementEnd('div');
588     }
589
590     /**
591      * Show export data feeds.
592      *
593      * @return void
594      */
595
596     function showExportData()
597     {
598         $feeds = $this->getFeeds();
599         if ($feeds) {
600             $fl = new FeedList($this);
601             $fl->show($feeds);
602         }
603     }
604
605     /**
606      * Show sections.
607      *
608      * SHOULD overload
609      *
610      * @return nothing
611      */
612     function showSections()
613     {
614         // for each section, show it
615     }
616
617     /**
618      * Show footer.
619      *
620      * @return nothing
621      */
622     function showFooter()
623     {
624         $this->elementStart('div', array('id' => 'footer'));
625         $this->showSecondaryNav();
626         $this->showLicenses();
627         $this->elementEnd('div');
628     }
629
630     /**
631      * Show secondary navigation.
632      *
633      * @return nothing
634      */
635     function showSecondaryNav()
636     {
637         $this->elementStart('dl', array('id' => 'site_nav_global_secondary'));
638         $this->element('dt', null, _('Secondary site navigation'));
639         $this->elementStart('dd', null);
640         $this->elementStart('ul', array('class' => 'nav'));
641         if (Event::handle('StartSecondaryNav', array($this))) {
642             $this->menuItem(common_local_url('doc', array('title' => 'help')),
643                             _('Help'));
644             $this->menuItem(common_local_url('doc', array('title' => 'about')),
645                             _('About'));
646             $this->menuItem(common_local_url('doc', array('title' => 'faq')),
647                             _('FAQ'));
648             $this->menuItem(common_local_url('doc', array('title' => 'privacy')),
649                             _('Privacy'));
650             $this->menuItem(common_local_url('doc', array('title' => 'source')),
651                             _('Source'));
652             $this->menuItem(common_local_url('doc', array('title' => 'contact')),
653                             _('Contact'));
654             $this->menuItem(common_local_url('doc', array('title' => 'badge')),
655                             _('Badge'));
656             Event::handle('EndSecondaryNav', array($this));
657         }
658         $this->elementEnd('ul');
659         $this->elementEnd('dd');
660         $this->elementEnd('dl');
661     }
662
663     /**
664      * Show licenses.
665      *
666      * @return nothing
667      */
668     function showLicenses()
669     {
670         $this->elementStart('dl', array('id' => 'licenses'));
671         $this->showLaconicaLicense();
672         $this->showContentLicense();
673         $this->elementEnd('dl');
674     }
675
676     /**
677      * Show Laconica license.
678      *
679      * @return nothing
680      */
681     function showLaconicaLicense()
682     {
683         $this->element('dt', array('id' => 'site_laconica_license'), _('Laconica software license'));
684         $this->elementStart('dd', null);
685         if (common_config('site', 'broughtby')) {
686             $instr = _('**%%site.name%%** is a microblogging service brought to you by [%%site.broughtby%%](%%site.broughtbyurl%%). ');
687         } else {
688             $instr = _('**%%site.name%%** is a microblogging service. ');
689         }
690         $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);
691         $output = common_markup_to_html($instr);
692         $this->raw($output);
693         $this->elementEnd('dd');
694         // do it
695     }
696
697     /**
698      * Show content license.
699      *
700      * @return nothing
701      */
702     function showContentLicense()
703     {
704         $this->element('dt', array('id' => 'site_content_license'), _('Laconica software license'));
705         $this->elementStart('dd', array('id' => 'site_content_license_cc'));
706         $this->elementStart('p');
707         $this->element('img', array('id' => 'license_cc',
708                                     'src' => common_config('license', 'image'),
709                                     'alt' => common_config('license', 'title')));
710         //TODO: This is dirty: i18n
711         $this->text(_('All '.common_config('site', 'name').' content and data are available under the '));
712         $this->element('a', array('class' => 'license',
713                                   'rel' => 'external license',
714                                   'href' => common_config('license', 'url')),
715                        common_config('license', 'title'));
716         $this->text(_('license.'));
717         $this->elementEnd('p');
718         $this->elementEnd('dd');
719     }
720
721     /**
722      * Return last modified, if applicable.
723      *
724      * MAY override
725      *
726      * @return string last modified http header
727      */
728     function lastModified()
729     {
730         // For comparison with If-Last-Modified
731         // If not applicable, return null
732         return null;
733     }
734
735     /**
736      * Return etag, if applicable.
737      *
738      * MAY override
739      *
740      * @return string etag http header
741      */
742     function etag()
743     {
744         return null;
745     }
746
747     /**
748      * Return true if read only.
749      *
750      * MAY override
751      *
752      * @return boolean is read only action?
753      */
754     function isReadOnly()
755     {
756         return false;
757     }
758
759     /**
760      * Returns query argument or default value if not found
761      *
762      * @param string $key requested argument
763      * @param string $def default value to return if $key is not provided
764      *
765      * @return boolean is read only action?
766      */
767     function arg($key, $def=null)
768     {
769         if (array_key_exists($key, $this->args)) {
770             return $this->args[$key];
771         } else {
772             return $def;
773         }
774     }
775
776     /**
777      * Returns trimmed query argument or default value if not found
778      *
779      * @param string $key requested argument
780      * @param string $def default value to return if $key is not provided
781      *
782      * @return boolean is read only action?
783      */
784     function trimmed($key, $def=null)
785     {
786         $arg = $this->arg($key, $def);
787         return is_string($arg) ? trim($arg) : $arg;
788     }
789
790     /**
791      * Handler method
792      *
793      * @param array $argarray is ignored since it's now passed in in prepare()
794      *
795      * @return boolean is read only action?
796      */
797     function handle($argarray=null)
798     {
799         $lm   = $this->lastModified();
800         $etag = $this->etag();
801         if ($etag) {
802             header('ETag: ' . $etag);
803         }
804         if ($lm) {
805             header('Last-Modified: ' . date(DATE_RFC1123, $lm));
806             if (isset($_SERVER['HTTP_IF_MODIFIED_SINCE'])) {
807                 $ims = strtotime($_SERVER['HTTP_IF_MODIFIED_SINCE']);
808                 if ($lm <= $ims) {
809                     $if_none_match = $_SERVER['HTTP_IF_NONE_MATCH'];
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 }