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
20 along with PhpWiki; if not, write to the Free Software
21 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
25 * Usage: <?plugin 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 getVersion() {
41 return preg_replace("/[Revision: $]/", '',
45 function getDefaultArguments() {
55 'style' => 'button', // or 'text'
56 'align' => 'left', // or 'right', or 'center'
57 'class' => 'wikiaction'
61 function run($dbi, $argstr, &$request, $basepage) {
63 $args = $this->getArgs($argstr, $request);
65 $directions = array ('first' => _("First"),
66 'prev' => _("Previous"),
70 'contents' => _("Contents"),
73 if ($order) { // reorder the buttons: comma-delimited
74 $new_directions = array();
75 foreach (explode(',', $order) as $o) {
76 $new_directions[$o] = $directions[$o];
78 $directions = $new_directions;
79 unset ($new_directions); // free memory
83 $sep = $WikiTheme->getButtonSeparator();
84 if ($align == 'center') {
86 $links = HTML::table(array('cellpadding' => 0, 'cellspacing' => 0, 'width' => '100%'), $tr);
87 } else if ($align == 'right') {
88 $td = HTML::td(array('align' => $align));
89 $links = HTML::table(array('cellpadding' => 0, 'cellspacing' => 0, 'width' => '100%'), HTML::tr($td));
94 if ($style == 'text') {
96 $sep = " | "; // force some kind of separator
98 if ($align == 'center') {
99 $tr->pushContent(HTML::td(array('align' => $align), " [ "));
100 } else if ($align == 'right') {
101 $td->pushcontent(" [ ");
103 $links->pushcontent(" [ ");
106 $last_is_text = false;
107 $this_is_first = true;
108 foreach ($directions as $dir => $label) {
109 // if ($last_is_text) $links->pushContent($sep);
110 if (!empty($args[$dir])) {
112 if ($style == 'button') {
113 // localized version: _("Previous").gif
114 if ($imgurl = $WikiTheme->getButtonURL($label)) {
116 if ($align == 'center') {
117 $tr->pushContent(HTML::td(array('align' => $align), $sep));
118 } else if ($align == 'right') {
119 $td->pushcontent($sep);
121 $links->pushcontent($sep);
124 if ($align == 'center') {
125 $tr->pushContent(HTML::td(array('align' => $align), new ImageButton($label, $url, false, $imgurl)));
126 } else if ($align == 'right') {
127 $td->pushContent(new ImageButton($label, $url, false, $imgurl));
129 $links->pushcontent(new ImageButton($label, $url, false, $imgurl));
131 $last_is_text = false;
132 // generic version: prev.gif
133 } elseif ($imgurl = $WikiTheme->getButtonURL($dir)) {
135 if ($align == 'center') {
136 $tr->pushContent(HTML::td(array('align' => $align), $sep));
137 } else if ($align == 'right') {
138 $td->pushcontent($sep);
140 $links->pushcontent($sep);
143 if ($align == 'center') {
144 $tr->pushContent(HTML::td(array('align' => $align), new ImageButton($label, $url, false, $imgurl)));
145 } else if ($align == 'right') {
146 $td->pushContent(new ImageButton($label, $url, false, $imgurl));
148 $links->pushcontent(new ImageButton($label, $url, false, $imgurl));
150 $last_is_text = false;
151 } else { // text only
152 if (! $this_is_first) {
153 if ($align == 'center') {
154 $tr->pushContent(HTML::td(array('align' => $align), $sep));
155 } else if ($align == 'right') {
156 $td->pushcontent($sep);
158 $links->pushcontent($sep);
161 if ($align == 'center') {
162 $tr->pushContent(HTML::td(array('align' => $align), new Button($label, $url, $class)));
163 } else if ($align == 'right') {
164 $td->pushContent(new Button($label, $url, $class));
166 $links->pushcontent(new Button($label, $url, $class));
168 $last_is_text = true;
171 if (! $this_is_first) {
172 if ($align == 'center') {
173 $tr->pushContent(HTML::td(array('align' => $align), $sep));
174 } else if ($align == 'right') {
175 $td->pushcontent($sep);
177 $links->pushcontent($sep);
180 if ($align == 'center') {
181 $tr->pushContent(HTML::td(array('align' => $align), new Button($label, $url, $class)));
182 } else if ($align == 'right') {
183 $td->pushContent(new Button($label, $url, $class));
185 $links->pushcontent(new Button($label, $url, $class));
187 $last_is_text = true;
189 $this_is_first = false;
192 if ($style == 'text') {
193 if ($align == 'center') {
194 $tr->pushContent(HTML::td(array('align' => $align), " ] "));
195 } else if ($align == 'right') {
196 $td->pushcontent(" ] ");
198 $links->pushcontent(" ] ");
209 // c-hanging-comment-ender-p: nil
210 // indent-tabs-mode: nil