]> CyberLeo.Net >> Repos - SourceForge/phpwiki.git/blob - lib/plugin/PageTrail.php
patch #680562 "PageTrail Duplicates Patch (1.3.4)"
[SourceForge/phpwiki.git] / lib / plugin / PageTrail.php
1 <?php // -*-php-*-
2 rcs_id('$Id: PageTrail.php,v 1.4 2004-02-27 02:49:40 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  * A simple PageTrail WikiPlugin.
25  * Put this at the end of each page to store the trail,
26  * or better in a template (body or bottom) to support it for all pages.
27  * But Cache should be turned off then.
28  *
29  * Usage:
30  * <?plugin PageTrail?>
31  * <?plugin PageTrail numberlinks=5?>
32  * <?plugin PageTrail invisible=1?>
33  */
34
35 if (!defined('PAGETRAIL_ARROW'))
36     define('PAGETRAIL_ARROW', " ==> ");
37
38 class WikiPlugin_PageTrail
39 extends WikiPlugin
40 {
41     // Four required functions in a WikiPlugin.
42     var $def_numberlinks = 5;
43
44     function getName () {
45         return _("PageTrail");
46     }
47
48     function getDescription () {
49         return _("PageTrail Plugin");
50
51     }
52
53     function getVersion() {
54         return preg_replace("/[Revision: $]/", '',
55                             "\$Revision: 1.4 $");
56     }
57
58     // default values
59     function getDefaultArguments() {
60         return array('numberlinks' => $this->def_numberlinks,
61                      'invisible' => false,
62                      'duplicates' => false,
63                      );
64     }
65
66     function run($dbi, $argstr, &$request, $basepage) {
67         extract($this->getArgs($argstr, $request));
68
69         if ($numberlinks > 10 || $numberlinks < 0) {
70             $numberlinks = $this->def_numberlinks;
71         }
72
73         // Get name of the current page we are on
74         $thispage = $request->getArg('pagename');
75         $thiscookie = $request->cookies->get("Wiki_PageTrail");
76         $Pages = explode(':', $thiscookie);
77
78         if ($duplicates || ($thispage != $Pages[0])) {
79             array_unshift($Pages, $thispage);
80             $request->cookies->set("Wiki_PageTrail",implode(':',$Pages));
81         }
82
83         if (! $invisible) {
84             $numberlinks = min(count($Pages)-1, $numberlinks);
85             $html = HTML::tt(WikiLink($Pages[$numberlinks-1], 'auto'));
86             for ($i = $numberlinks - 2; $i >= 0; $i--) {
87                 if (!empty($Pages[$i]))
88                     $html->pushContent(PAGETRAIL_ARROW, WikiLink($Pages[$i],
89                                                                  'auto'));
90             }
91             return $html;
92         } else
93             return HTML();
94     }
95 };
96
97 // $Log: not supported by cvs2svn $
98 // Revision 1.3  2004/02/17 12:11:36  rurban
99 // 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, ...)
100 //
101 // Revision 1.2  2003/01/18 22:22:36  carstenklapp
102 // defined constant for arrow, eliminate use of fmt()
103 //
104
105 // For emacs users
106 // Local Variables:
107 // mode: php
108 // tab-width: 8
109 // c-basic-offset: 4
110 // c-hanging-comment-ender-p: nil
111 // indent-tabs-mode: nil
112 // End:
113 ?>