]> CyberLeo.Net >> Repos - SourceForge/phpwiki.git/blob - lib/plugin/PrevNext.php
One "up" is enough
[SourceForge/phpwiki.git] / lib / plugin / PrevNext.php
1 <?php // -*-php-*-
2 rcs_id('$Id$');
3 /**
4  Copyright 1999, 2000, 2001, 2002 $ThePhpWikiProgrammingTeam
5
6  This file is part of PhpWiki.
7
8  PhpWiki is free software; you can redistribute it and/or modify
9  it under the terms of the GNU General Public License as published by
10  the Free Software Foundation; either version 2 of the License, or
11  (at your option) any later version.
12
13  PhpWiki is distributed in the hope that it will be useful,
14  but WITHOUT ANY WARRANTY; without even the implied warranty of
15  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16  GNU General Public License for more details.
17
18  You should have received a copy of the GNU General Public License
19  along with PhpWiki; if not, write to the Free Software
20  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
21  */
22
23 /**
24  * Usage: <?plugin PrevNext prev=PrevLink next=NextLink ?>
25  * See also PageGroup which automatically tries to extract the various links
26  *
27  */
28 class WikiPlugin_PrevNext
29 extends WikiPlugin
30 {
31     function getName() {
32         return _("PrevNext");
33     }
34
35     function getDescription() {
36         return sprintf(_("Easy navigation buttons for %s"),'[pagename]');
37     }
38
39     function getVersion() {
40         return preg_replace("/[Revision: $]/", '',
41                             "\$Revision$");
42     }
43
44     function getDefaultArguments() {
45         return array(
46                      'prev'    => '',
47                      'next'    => '',
48                      'contents' => '',
49                      'index'   => '',
50                      'up'      => '',
51                      'first'   => '',
52                      'last'    => '',
53                      'order'   => '',
54                      'style'   => 'button', // or 'text'
55                      'class'   => 'wikiaction'
56                      );
57     }
58
59     function run($dbi, $argstr, &$request, $basepage) {
60
61         $args = $this->getArgs($argstr, $request);
62         extract($args);
63         $directions = array ('first'    => _("First"),
64                              'prev'     => _("Previous"),
65                              'next'     => _("Next"),
66                              'last'     => _("Last"),
67                              'up'       => _("Up"),
68                              'contents'  => _("Contents"),
69                              'index'    => _("Index")
70                              );
71         if ($order) { // reorder the buttons: comma-delimited
72             $new_directions = array();
73             foreach (explode(',', $order) as $o) {
74                 $new_directions[$o] = $directions[$o];
75             }
76             $directions = $new_directions;
77             unset ($new_directions); // free memory
78         }
79
80         global $WikiTheme;
81         $sep = $WikiTheme->getButtonSeparator();
82         $links = HTML();
83         if ($style == 'text') {
84             if (!$sep)
85                 $sep = " | "; // force some kind of separator
86             $links->pushcontent(" [ ");
87         }
88         $last_is_text = false;
89         $this_is_first = true;
90         foreach ($directions as $dir => $label) {
91             // if ($last_is_text) $links->pushContent($sep);
92             if (!empty($args[$dir])) {
93                 $url = $args[$dir];
94                 if ($style == 'button') {
95                     // localized version: _("Previous").gif
96                     if ($imgurl = $WikiTheme->getButtonURL($label)) {
97                         if ($last_is_text)
98                             $links->pushContent($sep);
99                         $links->pushcontent(new ImageButton($label, $url,
100                                                             false, $imgurl));
101                         $last_is_text = false;
102                         // generic version: prev.gif
103                     } elseif ($imgurl = $WikiTheme->getButtonURL($dir)) {
104                         if ($last_is_text)
105                             $links->pushContent($sep);
106                         $links->pushContent(new ImageButton($label, $url,
107                                                             false, $imgurl));
108                         $last_is_text = false;
109                     } else { // text only
110                         if (! $this_is_first)
111                             $links->pushContent($sep);
112                         $links->pushContent(new Button($label, $url, $class));
113                         $last_is_text = true;
114                     }
115                 } else {
116                     if (! $this_is_first)
117                         $links->pushContent($sep);
118                     $links->pushContent(new Button($label, $url, $class));
119                     $last_is_text = true;
120                 }
121                 $this_is_first = false;
122             }
123         }
124         if ($style == 'text')
125             $links->pushcontent(" ] ");
126         return $links;
127     }
128 }
129
130 // Local Variables:
131 // mode: php
132 // tab-width: 8
133 // c-basic-offset: 4
134 // c-hanging-comment-ender-p: nil
135 // indent-tabs-mode: nil
136 // End:
137 ?>