]> CyberLeo.Net >> Repos - SourceForge/phpwiki.git/blob - lib/plugin/PrevNext.php
Update getDescription
[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 getName()
33     {
34         return _("PrevNext");
35     }
36
37     function getDescription()
38     {
39         return sprintf(_("Easy navigation buttons for %s."), '[pagename]');
40     }
41
42     function getDefaultArguments()
43     {
44         return array(
45             'prev' => '',
46             'next' => '',
47             'contents' => '',
48             'index' => '',
49             'up' => '',
50             'first' => '',
51             'last' => '',
52             'order' => '',
53             'style' => 'button', // or 'text'
54             'align' => 'left', // or 'right', or 'center'
55             'class' => 'wikiaction'
56         );
57     }
58
59     function run($dbi, $argstr, &$request, $basepage)
60     {
61
62         $args = $this->getArgs($argstr, $request);
63         extract($args);
64         $directions = array('first' => _("First"),
65             'prev' => _("Previous"),
66             'next' => _("Next"),
67             'last' => _("Last"),
68             'up' => _("Up"),
69             'contents' => _("Contents"),
70             'index' => _("Index")
71         );
72         if ($order) { // reorder the buttons: comma-delimited
73             $new_directions = array();
74             foreach (explode(',', $order) as $o) {
75                 $new_directions[$o] = $directions[$o];
76             }
77             $directions = $new_directions;
78             unset ($new_directions); // free memory
79         }
80
81         global $WikiTheme;
82         $sep = $WikiTheme->getButtonSeparator();
83         if ($align == 'center') {
84             $tr = HTML::tr();
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));
89         } else {
90             $links = HTML();
91         }
92
93         if ($style == 'text') {
94             if (!$sep) {
95                 $sep = " | "; // force some kind of separator
96             }
97             if ($align == 'center') {
98                 $tr->pushContent(HTML::td(array('align' => $align), " [ "));
99             } elseif ($align == 'right') {
100                 $td->pushcontent(" [ ");
101             } else {
102                 $links->pushcontent(" [ ");
103             }
104         }
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])) {
110                 $url = $args[$dir];
111                 if ($style == 'button') {
112                     // localized version: _("Previous").gif
113                     if ($imgurl = $WikiTheme->getButtonURL($label)) {
114                         if ($last_is_text) {
115                             if ($align == 'center') {
116                                 $tr->pushContent(HTML::td(array('align' => $align), $sep));
117                             } elseif ($align == 'right') {
118                                 $td->pushcontent($sep);
119                             } else {
120                                 $links->pushcontent($sep);
121                             }
122                         }
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));
127                         } else {
128                             $links->pushcontent(new ImageButton($label, $url, false, $imgurl));
129                         }
130                         $last_is_text = false;
131                         // generic version: prev.gif
132                     } elseif ($imgurl = $WikiTheme->getButtonURL($dir)) {
133                         if ($last_is_text) {
134                             if ($align == 'center') {
135                                 $tr->pushContent(HTML::td(array('align' => $align), $sep));
136                             } elseif ($align == 'right') {
137                                 $td->pushcontent($sep);
138                             } else {
139                                 $links->pushcontent($sep);
140                             }
141                         }
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));
146                         } else {
147                             $links->pushcontent(new ImageButton($label, $url, false, $imgurl));
148                         }
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);
156                             } else {
157                                 $links->pushcontent($sep);
158                             }
159                         }
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));
164                         } else {
165                             $links->pushcontent(new Button($label, $url, $class));
166                         }
167                         $last_is_text = true;
168                     }
169                 } else {
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);
175                         } else {
176                             $links->pushcontent($sep);
177                         }
178                     }
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));
183                     } else {
184                         $links->pushcontent(new Button($label, $url, $class));
185                     }
186                     $last_is_text = true;
187                 }
188                 $this_is_first = false;
189             }
190         }
191         if ($style == 'text') {
192             if ($align == 'center') {
193                 $tr->pushContent(HTML::td(array('align' => $align), " ] "));
194             } elseif ($align == 'right') {
195                 $td->pushcontent(" ] ");
196             } else {
197                 $links->pushcontent(" ] ");
198             }
199         }
200         return $links;
201     }
202 }
203
204 // Local Variables:
205 // mode: php
206 // tab-width: 8
207 // c-basic-offset: 4
208 // c-hanging-comment-ender-p: nil
209 // indent-tabs-mode: nil
210 // End: