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