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