]> CyberLeo.Net >> Repos - SourceForge/phpwiki.git/blob - lib/plugin/PrevNext.php
Normalize header
[SourceForge/phpwiki.git] / lib / plugin / PrevNext.php
1 <?php // -*-php-*-
2 rcs_id('$Id$');
3 /**
4  * Copyright 1999, 2000, 2001, 2002 $ThePhpWikiProgrammingTeam
5  * Copyright 2008 Marc-Etienne Vargenau, Alcatel-Lucent
6  *
7  * This file is part of PhpWiki.
8  *
9  * PhpWiki is free software; you can redistribute it and/or modify
10  * it under the terms of the GNU General Public License as published by
11  * the Free Software Foundation; either version 2 of the License, or
12  * (at your option) any later version.
13  *
14  * PhpWiki 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 General Public License for more details.
18  *
19  * You should have received a copy of the GNU General Public License
20  * along with PhpWiki; if not, write to the Free Software
21  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
22  */
23
24 /**
25  * Usage: <?plugin PrevNext prev=PrevLink next=NextLink ?>
26  * See also PageGroup which automatically tries to extract the various links
27  *
28  */
29 class WikiPlugin_PrevNext
30 extends WikiPlugin
31 {
32     function getName() {
33         return _("PrevNext");
34     }
35
36     function getDescription() {
37         return sprintf(_("Easy navigation buttons for %s"),'[pagename]');
38     }
39
40     function getVersion() {
41         return preg_replace("/[Revision: $]/", '',
42                             "\$Revision$");
43     }
44
45     function getDefaultArguments() {
46         return array(
47                      'prev'    => '',
48                      'next'    => '',
49                      'contents' => '',
50                      'index'   => '',
51                      'up'      => '',
52                      'first'   => '',
53                      'last'    => '',
54                      'order'   => '',
55                      'style'   => 'button', // or 'text'
56                      'align'   => 'left', // or 'right', or 'center'
57                      'class'   => 'wikiaction'
58                      );
59     }
60
61     function run($dbi, $argstr, &$request, $basepage) {
62
63         $args = $this->getArgs($argstr, $request);
64         extract($args);
65         $directions = array ('first'    => _("First"),
66                              'prev'     => _("Previous"),
67                              'next'     => _("Next"),
68                              'last'     => _("Last"),
69                              'up'       => _("Up"),
70                              'contents'  => _("Contents"),
71                              'index'    => _("Index")
72                              );
73         if ($order) { // reorder the buttons: comma-delimited
74             $new_directions = array();
75             foreach (explode(',', $order) as $o) {
76                 $new_directions[$o] = $directions[$o];
77             }
78             $directions = $new_directions;
79             unset ($new_directions); // free memory
80         }
81
82         global $WikiTheme;
83         $sep = $WikiTheme->getButtonSeparator();
84         if ($align == 'center') {
85             $tr = HTML::tr();
86             $links = HTML::table(array('cellpadding' => 0, 'cellspacing' => 0, 'width' => '100%'), $tr);
87         } else if ($align == 'right') {
88             $td = HTML::td(array('align' => $align));
89             $links = HTML::table(array('cellpadding' => 0, 'cellspacing' => 0, 'width' => '100%'), HTML::tr($td));
90         } else {
91             $links = HTML();
92         }
93
94         if ($style == 'text') {
95             if (!$sep) {
96                 $sep = " | "; // force some kind of separator
97             }
98             if ($align == 'center') {
99                 $tr->pushContent(HTML::td(array('align' => $align), " [ "));
100             } else if ($align == 'right') {
101                 $td->pushcontent(" [ ");
102             } else {
103                 $links->pushcontent(" [ ");
104             }
105         }
106         $last_is_text = false;
107         $this_is_first = true;
108         foreach ($directions as $dir => $label) {
109             // if ($last_is_text) $links->pushContent($sep);
110             if (!empty($args[$dir])) {
111                 $url = $args[$dir];
112                 if ($style == 'button') {
113                     // localized version: _("Previous").gif
114                     if ($imgurl = $WikiTheme->getButtonURL($label)) {
115                         if ($last_is_text) {
116                             if ($align == 'center') {
117                                 $tr->pushContent(HTML::td(array('align' => $align), $sep));
118                             } else if ($align == 'right') {
119                                 $td->pushcontent($sep);
120                             } else {
121                                 $links->pushcontent($sep);
122                             }
123                         }
124                         if ($align == 'center') {
125                             $tr->pushContent(HTML::td(array('align' => $align), new ImageButton($label, $url, false, $imgurl)));
126                         } else if ($align == 'right') {
127                             $td->pushContent(new ImageButton($label, $url, false, $imgurl));
128                         } else {
129                             $links->pushcontent(new ImageButton($label, $url, false, $imgurl));
130                         }
131                         $last_is_text = false;
132                         // generic version: prev.gif
133                     } elseif ($imgurl = $WikiTheme->getButtonURL($dir)) {
134                         if ($last_is_text) {
135                             if ($align == 'center') {
136                                 $tr->pushContent(HTML::td(array('align' => $align), $sep));
137                             } else if ($align == 'right') {
138                                 $td->pushcontent($sep);
139                             } else {
140                                 $links->pushcontent($sep);
141                             }
142                         }
143                         if ($align == 'center') {
144                             $tr->pushContent(HTML::td(array('align' => $align), new ImageButton($label, $url, false, $imgurl)));
145                         } else if ($align == 'right') {
146                             $td->pushContent(new ImageButton($label, $url, false, $imgurl));
147                         } else {
148                             $links->pushcontent(new ImageButton($label, $url, false, $imgurl));
149                         }
150                         $last_is_text = false;
151                     } else { // text only
152                         if (! $this_is_first) {
153                             if ($align == 'center') {
154                                 $tr->pushContent(HTML::td(array('align' => $align), $sep));
155                             } else if ($align == 'right') {
156                                 $td->pushcontent($sep);
157                             } else {
158                                 $links->pushcontent($sep);
159                             }
160                         }
161                         if ($align == 'center') {
162                             $tr->pushContent(HTML::td(array('align' => $align), new Button($label, $url, $class)));
163                         } else if ($align == 'right') {
164                             $td->pushContent(new Button($label, $url, $class));
165                         } else {
166                             $links->pushcontent(new Button($label, $url, $class));
167                         }
168                         $last_is_text = true;
169                     }
170                 } else {
171                     if (! $this_is_first) {
172                         if ($align == 'center') {
173                             $tr->pushContent(HTML::td(array('align' => $align), $sep));
174                         } else if ($align == 'right') {
175                             $td->pushcontent($sep);
176                         } else {
177                             $links->pushcontent($sep);
178                         }
179                     }
180                     if ($align == 'center') {
181                         $tr->pushContent(HTML::td(array('align' => $align), new Button($label, $url, $class)));
182                     } else if ($align == 'right') {
183                         $td->pushContent(new Button($label, $url, $class));
184                     } else {
185                         $links->pushcontent(new Button($label, $url, $class));
186                     }
187                     $last_is_text = true;
188                 }
189                 $this_is_first = false;
190             }
191         }
192         if ($style == 'text') {
193             if ($align == 'center') {
194                 $tr->pushContent(HTML::td(array('align' => $align), " ] "));
195             } else if ($align == 'right') {
196                 $td->pushcontent(" ] ");
197             } else {
198                 $links->pushcontent(" ] ");
199             }
200         }
201         return $links;
202     }
203 }
204
205 // Local Variables:
206 // mode: php
207 // tab-width: 8
208 // c-basic-offset: 4
209 // c-hanging-comment-ender-p: nil
210 // indent-tabs-mode: nil
211 // End:
212 ?>