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
37 function getDescription()
39 return sprintf(_("Easy navigation buttons for %s."), '[pagename]');
42 function getDefaultArguments()
53 'style' => 'button', // or 'text'
54 'align' => 'left', // or 'right', or 'center'
55 'class' => 'wikiaction'
59 function run($dbi, $argstr, &$request, $basepage)
62 $args = $this->getArgs($argstr, $request);
64 $directions = array('first' => _("First"),
65 'prev' => _("Previous"),
69 'contents' => _("Contents"),
72 if ($order) { // reorder the buttons: comma-delimited
73 $new_directions = array();
74 foreach (explode(',', $order) as $o) {
75 $new_directions[$o] = $directions[$o];
77 $directions = $new_directions;
78 unset ($new_directions); // free memory
82 $sep = $WikiTheme->getButtonSeparator();
83 if ($align == 'center') {
85 $links = HTML::table(array('cellpadding' => 0, 'cellspacing' => 0, 'width' => '100%'), $tr);
86 } elseif ($align == 'right') {
87 $td = HTML::td(array('align' => $align));
88 $links = HTML::table(array('cellpadding' => 0, 'cellspacing' => 0, 'width' => '100%'), HTML::tr($td));
93 if ($style == 'text') {
95 $sep = " | "; // force some kind of separator
97 if ($align == 'center') {
98 $tr->pushContent(HTML::td(array('align' => $align), " [ "));
99 } elseif ($align == 'right') {
100 $td->pushcontent(" [ ");
102 $links->pushcontent(" [ ");
105 $last_is_text = false;
106 $this_is_first = true;
107 foreach ($directions as $dir => $label) {
108 // if ($last_is_text) $links->pushContent($sep);
109 if (!empty($args[$dir])) {
111 if ($style == 'button') {
112 // localized version: _("Previous").gif
113 if ($imgurl = $WikiTheme->getButtonURL($label)) {
115 if ($align == 'center') {
116 $tr->pushContent(HTML::td(array('align' => $align), $sep));
117 } elseif ($align == 'right') {
118 $td->pushcontent($sep);
120 $links->pushcontent($sep);
123 if ($align == 'center') {
124 $tr->pushContent(HTML::td(array('align' => $align), new ImageButton($label, $url, false, $imgurl)));
125 } elseif ($align == 'right') {
126 $td->pushContent(new ImageButton($label, $url, false, $imgurl));
128 $links->pushcontent(new ImageButton($label, $url, false, $imgurl));
130 $last_is_text = false;
131 // generic version: prev.gif
132 } elseif ($imgurl = $WikiTheme->getButtonURL($dir)) {
134 if ($align == 'center') {
135 $tr->pushContent(HTML::td(array('align' => $align), $sep));
136 } elseif ($align == 'right') {
137 $td->pushcontent($sep);
139 $links->pushcontent($sep);
142 if ($align == 'center') {
143 $tr->pushContent(HTML::td(array('align' => $align), new ImageButton($label, $url, false, $imgurl)));
144 } elseif ($align == 'right') {
145 $td->pushContent(new ImageButton($label, $url, false, $imgurl));
147 $links->pushcontent(new ImageButton($label, $url, false, $imgurl));
149 $last_is_text = false;
150 } else { // text only
151 if (!$this_is_first) {
152 if ($align == 'center') {
153 $tr->pushContent(HTML::td(array('align' => $align), $sep));
154 } elseif ($align == 'right') {
155 $td->pushcontent($sep);
157 $links->pushcontent($sep);
160 if ($align == 'center') {
161 $tr->pushContent(HTML::td(array('align' => $align), new Button($label, $url, $class)));
162 } elseif ($align == 'right') {
163 $td->pushContent(new Button($label, $url, $class));
165 $links->pushcontent(new Button($label, $url, $class));
167 $last_is_text = true;
170 if (!$this_is_first) {
171 if ($align == 'center') {
172 $tr->pushContent(HTML::td(array('align' => $align), $sep));
173 } elseif ($align == 'right') {
174 $td->pushcontent($sep);
176 $links->pushcontent($sep);
179 if ($align == 'center') {
180 $tr->pushContent(HTML::td(array('align' => $align), new Button($label, $url, $class)));
181 } elseif ($align == 'right') {
182 $td->pushContent(new Button($label, $url, $class));
184 $links->pushcontent(new Button($label, $url, $class));
186 $last_is_text = true;
188 $this_is_first = false;
191 if ($style == 'text') {
192 if ($align == 'center') {
193 $tr->pushContent(HTML::td(array('align' => $align), " ] "));
194 } elseif ($align == 'right') {
195 $td->pushcontent(" ] ");
197 $links->pushcontent(" ] ");
208 // c-hanging-comment-ender-p: nil
209 // indent-tabs-mode: nil