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