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