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
36 function getDescription() {
37 return sprintf(_("Easy navigation buttons for %s"),'[pagename]');
40 function getDefaultArguments() {
50 'style' => 'button', // or 'text'
51 'align' => 'left', // or 'right', or 'center'
52 'class' => 'wikiaction'
56 function run($dbi, $argstr, &$request, $basepage) {
58 $args = $this->getArgs($argstr, $request);
60 $directions = array ('first' => _("First"),
61 'prev' => _("Previous"),
65 'contents' => _("Contents"),
68 if ($order) { // reorder the buttons: comma-delimited
69 $new_directions = array();
70 foreach (explode(',', $order) as $o) {
71 $new_directions[$o] = $directions[$o];
73 $directions = $new_directions;
74 unset ($new_directions); // free memory
78 $sep = $WikiTheme->getButtonSeparator();
79 if ($align == 'center') {
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));
89 if ($style == 'text') {
91 $sep = " | "; // force some kind of separator
93 if ($align == 'center') {
94 $tr->pushContent(HTML::td(array('align' => $align), " [ "));
95 } elseif ($align == 'right') {
96 $td->pushcontent(" [ ");
98 $links->pushcontent(" [ ");
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])) {
107 if ($style == 'button') {
108 // localized version: _("Previous").gif
109 if ($imgurl = $WikiTheme->getButtonURL($label)) {
111 if ($align == 'center') {
112 $tr->pushContent(HTML::td(array('align' => $align), $sep));
113 } elseif ($align == 'right') {
114 $td->pushcontent($sep);
116 $links->pushcontent($sep);
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));
124 $links->pushcontent(new ImageButton($label, $url, false, $imgurl));
126 $last_is_text = false;
127 // generic version: prev.gif
128 } elseif ($imgurl = $WikiTheme->getButtonURL($dir)) {
130 if ($align == 'center') {
131 $tr->pushContent(HTML::td(array('align' => $align), $sep));
132 } elseif ($align == 'right') {
133 $td->pushcontent($sep);
135 $links->pushcontent($sep);
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));
143 $links->pushcontent(new ImageButton($label, $url, false, $imgurl));
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);
153 $links->pushcontent($sep);
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));
161 $links->pushcontent(new Button($label, $url, $class));
163 $last_is_text = true;
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);
172 $links->pushcontent($sep);
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));
180 $links->pushcontent(new Button($label, $url, $class));
182 $last_is_text = true;
184 $this_is_first = false;
187 if ($style == 'text') {
188 if ($align == 'center') {
189 $tr->pushContent(HTML::td(array('align' => $align), " ] "));
190 } elseif ($align == 'right') {
191 $td->pushcontent(" ] ");
193 $links->pushcontent(" ] ");
204 // c-hanging-comment-ender-p: nil
205 // indent-tabs-mode: nil