]> CyberLeo.Net >> Repos - SourceForge/phpwiki.git/blob - lib/plugin/PrevNext.php
renamed global $Theme to $WikiTheme (gforge nameclash)
[SourceForge/phpwiki.git] / lib / plugin / PrevNext.php
1 <?php // -*-php-*-
2 rcs_id('$Id: PrevNext.php,v 1.4 2004-06-14 11:31:39 rurban Exp $');
3 /**
4  Copyright 1999, 2000, 2001, 2002 $ThePhpWikiProgrammingTeam
5
6  This file is part of PhpWiki.
7
8  PhpWiki is free software; you can redistribute it and/or modify
9  it under the terms of the GNU General Public License as published by
10  the Free Software Foundation; either version 2 of the License, or
11  (at your option) any later version.
12
13  PhpWiki is distributed in the hope that it will be useful,
14  but WITHOUT ANY WARRANTY; without even the implied warranty of
15  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16  GNU General Public License for more details.
17
18  You should have received a copy of the GNU General Public License
19  along with PhpWiki; if not, write to the Free Software
20  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
21  */
22
23 /**
24  * Usage: <?plugin PrevNext prev=PrevLink next=NextLink ?>
25  * See also PageGroup which automatically tries to extract the various links
26  *
27  */
28 class WikiPlugin_PrevNext
29 extends WikiPlugin
30 {
31     function getName() {
32         return _("PrevNext");
33     }
34
35     function getDescription() {
36         return sprintf(_("Easy navigation buttons for %s"),'[pagename]');
37     }
38
39     function getVersion() {
40         return preg_replace("/[Revision: $]/", '',
41                             "\$Revision: 1.4 $");
42     }
43
44     function getDefaultArguments() {
45         return array(
46                      'prev'    => '',
47                      'next'    => '',
48                      'up'      => '',
49                      'contents' => '',
50                      'index'   => '',
51                      'up'      => '',
52                      'first'   => '',
53                      'last'    => '',
54                      'order'   => '',
55                      'style'   => 'button', // or 'text'
56                      'class'   => 'wikiaction'
57                      );
58     }
59
60     function run($dbi, $argstr, &$request, $basepage) {
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         $links = HTML();
84         if ($style == 'text') {
85             if (!$sep)
86                 $sep = " | "; // force some kind of separator
87             $links->pushcontent(" [ ");
88         }
89         $last_is_text = false;
90         $this_is_first = true;
91         foreach ($directions as $dir => $label) {
92             // if ($last_is_text) $links->pushContent($sep);
93             if (!empty($args[$dir])) {
94                 $url = $args[$dir];
95                 if ($style == 'button') {
96                     // localized version: _("Previous").gif
97                     if ($imgurl = $WikiTheme->getButtonURL($label)) {
98                         if ($last_is_text)
99                             $links->pushContent($sep);
100                         $links->pushcontent(new ImageButton($label, $url,
101                                                             false, $imgurl));
102                         $last_is_text = false;
103                         // generic version: prev.gif
104                     } elseif ($imgurl = $WikiTheme->getButtonURL($dir)) {
105                         if ($last_is_text)
106                             $links->pushContent($sep);
107                         $links->pushContent(new ImageButton($label, $url,
108                                                             false, $imgurl));
109                         $last_is_text = false;
110                     } else { // text only
111                         if (! $this_is_first)
112                             $links->pushContent($sep);
113                         $links->pushContent(new Button($label, $url, $class));
114                         $last_is_text = true;
115                     }
116                 } else {
117                     if (! $this_is_first)
118                         $links->pushContent($sep);
119                     $links->pushContent(new Button($label, $url, $class));
120                     $last_is_text = true;
121                 }
122                 $this_is_first = false;
123             }
124         }
125         if ($style == 'text')
126             $links->pushcontent(" ] ");
127         return $links;
128     }
129 }
130
131 // $Log: not supported by cvs2svn $
132 // Revision 1.3  2004/02/17 12:11:36  rurban
133 // added missing 4th basepage arg at plugin->run() to almost all plugins. This caused no harm so far, because it was silently dropped on normal usage. However on plugin internal ->run invocations it failed. (InterWikiSearch, IncludeSiteMap, ...)
134 //
135 // Revision 1.2  2003/01/18 22:01:43  carstenklapp
136 // Code cleanup:
137 // Reformatting & tabs to spaces;
138 // Added copyleft, getVersion, getDescription, rcs_id.
139 //
140
141 // Local Variables:
142 // mode: php
143 // tab-width: 8
144 // c-basic-offset: 4
145 // c-hanging-comment-ender-p: nil
146 // indent-tabs-mode: nil
147 // End:
148 ?>