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