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