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