]> CyberLeo.Net >> Repos - SourceForge/phpwiki.git/blob - lib/plugin/PageTrail.php
new experimental plugin by Paul Pearson <wandrer@glcomputers.com>,
[SourceForge/phpwiki.git] / lib / plugin / PageTrail.php
1 <?php // -*-php-*-
2 rcs_id('$Id: PageTrail.php,v 1.1 2002-09-27 13:27:17 rurban Exp $');
3 /**
4  * A simple PageTrail WikiPlugin.
5  * Put this at the end of each page to store the trail.
6  *
7  * Usage:
8  * <?plugin PageTrail?>
9  * <?plugin PageTrail numberlinks=5?>
10  * <?plugin PageTrail invisible=1?>  
11  */
12
13 // Constants are defined before the class.
14 if (!defined('THE_END'))
15     define('THE_END', "!");
16
17 class WikiPlugin_PageTrail
18 extends WikiPlugin
19 {
20     // Four required functions in a WikiPlugin.
21     var $def_numberlinks = 5;
22
23     function getName () {
24         return _("PageTrail");
25     }
26
27     function getDescription () {
28         return _("PageTrail Plugin");
29
30     }
31     // default values
32     function getDefaultArguments() {
33         return array('numberlinks' => $this->def_numberlinks, 
34                      'invisible' => false,
35                      );
36     }
37
38     function run($dbi, $argstr, $request) {
39         extract($this->getArgs($argstr, $request));
40
41         if ($numberlinks > 10 || $numberlinks < 0) { $numberlinks = $this->def_numberlinks; }
42
43         // Get name of the current page we are on
44         $thispage = $request->getArg('pagename');
45         $thiscookie = $request->cookies->get("Wiki_PageTrail");
46         $Pages = explode(':',$thiscookie);
47         array_unshift($Pages, $thispage);
48         $request->cookies->set("Wiki_PageTrail",implode(':',$Pages));
49
50         if (! $invisible) {
51             $numberlinks = min(count($Pages)-1, $numberlinks);
52             $html = HTML::tt(fmt('%s', WikiLink($Pages[$numberlinks-1]), 'auto'));
53             for ($i = $numberlinks-2; $i >= 0; $i--) {
54                 if (!empty($Pages[$i]))
55                     $html->pushContent(fmt(' ==> %s', WikiLink($Pages[$i], 'auto')));
56             }
57             $html->pushContent(THE_END);
58             return $html;
59         } else 
60             return HTML();
61     }
62 };
63
64 // For emacs users
65 // Local Variables:
66 // mode: php
67 // tab-width: 8
68 // c-basic-offset: 4
69 // c-hanging-comment-ender-p: nil
70 // indent-tabs-mode: nil
71 // End:
72 ?>