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