4 * Copyright 1999, 2000, 2001, 2002 $ThePhpWikiProgrammingTeam
5 * Copyright 2008 Marc-Etienne Vargenau, Alcatel-Lucent
7 * This file is part of PhpWiki.
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.
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.
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.
25 * Usage: <<PrevNext prev=PrevLink next=NextLink >>
26 * See also PageGroup which automatically tries to extract the various links
29 class WikiPlugin_PrevNext
32 function getDescription()
34 return sprintf(_("Easy navigation buttons for %s."), '[pagename]');
37 function getDefaultArguments()
48 'style' => 'button', // or 'text'
49 'align' => 'left', // or 'right', or 'center'
50 'class' => 'wikiaction'
54 function run($dbi, $argstr, &$request, $basepage)
57 $args = $this->getArgs($argstr, $request);
59 $directions = array('first' => _("First"),
60 'prev' => _("Previous"),
64 'contents' => _("Contents"),
67 if ($order) { // reorder the buttons: comma-delimited
68 $new_directions = array();
69 foreach (explode(',', $order) as $o) {
70 $new_directions[$o] = $directions[$o];
72 $directions = $new_directions;
73 unset ($new_directions); // free memory
77 $sep = $WikiTheme->getButtonSeparator();
78 if ($align == 'center') {
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));
88 if ($style == 'text') {
90 $sep = " | "; // force some kind of separator
92 if ($align == 'center') {
93 $tr->pushContent(HTML::td(array('align' => $align), " [ "));
94 } elseif ($align == 'right') {
95 $td->pushcontent(" [ ");
97 $links->pushcontent(" [ ");
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])) {
106 if ($style == 'button') {
107 // localized version: _("Previous").gif
108 if ($imgurl = $WikiTheme->getButtonURL($label)) {
110 if ($align == 'center') {
111 $tr->pushContent(HTML::td(array('align' => $align), $sep));
112 } elseif ($align == 'right') {
113 $td->pushcontent($sep);
115 $links->pushcontent($sep);
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));
123 $links->pushcontent(new ImageButton($label, $url, false, $imgurl));
125 $last_is_text = false;
126 // generic version: prev.gif
127 } elseif ($imgurl = $WikiTheme->getButtonURL($dir)) {
129 if ($align == 'center') {
130 $tr->pushContent(HTML::td(array('align' => $align), $sep));
131 } elseif ($align == 'right') {
132 $td->pushcontent($sep);
134 $links->pushcontent($sep);
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));
142 $links->pushcontent(new ImageButton($label, $url, false, $imgurl));
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);
152 $links->pushcontent($sep);
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));
160 $links->pushcontent(new Button($label, $url, $class));
162 $last_is_text = true;
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);
171 $links->pushcontent($sep);
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));
179 $links->pushcontent(new Button($label, $url, $class));
181 $last_is_text = true;
183 $this_is_first = false;
186 if ($style == 'text') {
187 if ($align == 'center') {
188 $tr->pushContent(HTML::td(array('align' => $align), " ] "));
189 } elseif ($align == 'right') {
190 $td->pushcontent(" ] ");
192 $links->pushcontent(" ] ");
203 // c-hanging-comment-ender-p: nil
204 // indent-tabs-mode: nil