]> CyberLeo.Net >> Repos - SourceForge/phpwiki.git/blob - lib/plugin/PrevNext.php
elseif
[SourceForge/phpwiki.git] / lib / plugin / PrevNext.php
1 <?php // -*-php-*-
2 // $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 along
20  * with PhpWiki; if not, write to the Free Software Foundation, Inc.,
21  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
22  */
23
24 /**
25  * Usage: <<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 getDefaultArguments() {
41         return array(
42                      'prev'    => '',
43                      'next'    => '',
44                      'contents' => '',
45                      'index'   => '',
46                      'up'      => '',
47                      'first'   => '',
48                      'last'    => '',
49                      'order'   => '',
50                      'style'   => 'button', // or 'text'
51                      'align'   => 'left', // or 'right', or 'center'
52                      'class'   => 'wikiaction'
53                      );
54     }
55
56     function run($dbi, $argstr, &$request, $basepage) {
57
58         $args = $this->getArgs($argstr, $request);
59         extract($args);
60         $directions = array ('first'    => _("First"),
61                              'prev'     => _("Previous"),
62                              'next'     => _("Next"),
63                              'last'     => _("Last"),
64                              'up'       => _("Up"),
65                              'contents'  => _("Contents"),
66                              'index'    => _("Index")
67                              );
68         if ($order) { // reorder the buttons: comma-delimited
69             $new_directions = array();
70             foreach (explode(',', $order) as $o) {
71                 $new_directions[$o] = $directions[$o];
72             }
73             $directions = $new_directions;
74             unset ($new_directions); // free memory
75         }
76
77         global $WikiTheme;
78         $sep = $WikiTheme->getButtonSeparator();
79         if ($align == 'center') {
80             $tr = HTML::tr();
81             $links = HTML::table(array('cellpadding' => 0, 'cellspacing' => 0, 'width' => '100%'), $tr);
82         } elseif ($align == 'right') {
83             $td = HTML::td(array('align' => $align));
84             $links = HTML::table(array('cellpadding' => 0, 'cellspacing' => 0, 'width' => '100%'), HTML::tr($td));
85         } else {
86             $links = HTML();
87         }
88
89         if ($style == 'text') {
90             if (!$sep) {
91                 $sep = " | "; // force some kind of separator
92             }
93             if ($align == 'center') {
94                 $tr->pushContent(HTML::td(array('align' => $align), " [ "));
95             } elseif ($align == 'right') {
96                 $td->pushcontent(" [ ");
97             } else {
98                 $links->pushcontent(" [ ");
99             }
100         }
101         $last_is_text = false;
102         $this_is_first = true;
103         foreach ($directions as $dir => $label) {
104             // if ($last_is_text) $links->pushContent($sep);
105             if (!empty($args[$dir])) {
106                 $url = $args[$dir];
107                 if ($style == 'button') {
108                     // localized version: _("Previous").gif
109                     if ($imgurl = $WikiTheme->getButtonURL($label)) {
110                         if ($last_is_text) {
111                             if ($align == 'center') {
112                                 $tr->pushContent(HTML::td(array('align' => $align), $sep));
113                             } elseif ($align == 'right') {
114                                 $td->pushcontent($sep);
115                             } else {
116                                 $links->pushcontent($sep);
117                             }
118                         }
119                         if ($align == 'center') {
120                             $tr->pushContent(HTML::td(array('align' => $align), new ImageButton($label, $url, false, $imgurl)));
121                         } elseif ($align == 'right') {
122                             $td->pushContent(new ImageButton($label, $url, false, $imgurl));
123                         } else {
124                             $links->pushcontent(new ImageButton($label, $url, false, $imgurl));
125                         }
126                         $last_is_text = false;
127                         // generic version: prev.gif
128                     } elseif ($imgurl = $WikiTheme->getButtonURL($dir)) {
129                         if ($last_is_text) {
130                             if ($align == 'center') {
131                                 $tr->pushContent(HTML::td(array('align' => $align), $sep));
132                             } elseif ($align == 'right') {
133                                 $td->pushcontent($sep);
134                             } else {
135                                 $links->pushcontent($sep);
136                             }
137                         }
138                         if ($align == 'center') {
139                             $tr->pushContent(HTML::td(array('align' => $align), new ImageButton($label, $url, false, $imgurl)));
140                         } elseif ($align == 'right') {
141                             $td->pushContent(new ImageButton($label, $url, false, $imgurl));
142                         } else {
143                             $links->pushcontent(new ImageButton($label, $url, false, $imgurl));
144                         }
145                         $last_is_text = false;
146                     } else { // text only
147                         if (! $this_is_first) {
148                             if ($align == 'center') {
149                                 $tr->pushContent(HTML::td(array('align' => $align), $sep));
150                             } elseif ($align == 'right') {
151                                 $td->pushcontent($sep);
152                             } else {
153                                 $links->pushcontent($sep);
154                             }
155                         }
156                         if ($align == 'center') {
157                             $tr->pushContent(HTML::td(array('align' => $align), new Button($label, $url, $class)));
158                         } elseif ($align == 'right') {
159                             $td->pushContent(new Button($label, $url, $class));
160                         } else {
161                             $links->pushcontent(new Button($label, $url, $class));
162                         }
163                         $last_is_text = true;
164                     }
165                 } else {
166                     if (! $this_is_first) {
167                         if ($align == 'center') {
168                             $tr->pushContent(HTML::td(array('align' => $align), $sep));
169                         } elseif ($align == 'right') {
170                             $td->pushcontent($sep);
171                         } else {
172                             $links->pushcontent($sep);
173                         }
174                     }
175                     if ($align == 'center') {
176                         $tr->pushContent(HTML::td(array('align' => $align), new Button($label, $url, $class)));
177                     } elseif ($align == 'right') {
178                         $td->pushContent(new Button($label, $url, $class));
179                     } else {
180                         $links->pushcontent(new Button($label, $url, $class));
181                     }
182                     $last_is_text = true;
183                 }
184                 $this_is_first = false;
185             }
186         }
187         if ($style == 'text') {
188             if ($align == 'center') {
189                 $tr->pushContent(HTML::td(array('align' => $align), " ] "));
190             } elseif ($align == 'right') {
191                 $td->pushcontent(" ] ");
192             } else {
193                 $links->pushcontent(" ] ");
194             }
195         }
196         return $links;
197     }
198 }
199
200 // Local Variables:
201 // mode: php
202 // tab-width: 8
203 // c-basic-offset: 4
204 // c-hanging-comment-ender-p: nil
205 // indent-tabs-mode: nil
206 // End:
207 ?>