]> CyberLeo.Net >> Repos - SourceForge/phpwiki.git/blob - lib/plugin/PageTrail.php
Use real list instead of middot
[SourceForge/phpwiki.git] / lib / plugin / PageTrail.php
1 <?php
2
3 /**
4  * Copyright 1999,2000,2001,2002,2005 $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 along
19  * with PhpWiki; if not, write to the Free Software Foundation, Inc.,
20  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
21  */
22
23 /**
24  * A simple PageTrail WikiPlugin.
25  * Put this at the begin/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  * <<PageTrail>>
31  * <<PageTrail numberlinks=5>>
32  * <<PageTrail invisible=1>>
33  */
34
35 if (!defined('PAGETRAIL_ARROW'))
36     define('PAGETRAIL_ARROW', " => ");
37
38 class WikiPlugin_PageTrail
39     extends WikiPlugin
40 {
41     public $def_numberlinks = 5;
42
43     function getDescription()
44     {
45         return _("Display PageTrail.");
46     }
47
48     // default values
49     function getDefaultArguments()
50     {
51         return array('numberlinks' => $this->def_numberlinks,
52             'invisible' => false,
53             'duplicates' => false,
54         );
55     }
56
57     /**
58      * @param WikiDB $dbi
59      * @param string $argstr
60      * @param WikiRequest $request
61      * @param string $basepage
62      * @return mixed
63      */
64     function run($dbi, $argstr, &$request, $basepage)
65     {
66         extract($this->getArgs($argstr, $request));
67
68         if ($numberlinks > 10 || $numberlinks < 0) {
69             $numberlinks = $this->def_numberlinks;
70         }
71
72         // Get name of the current page we are on
73         $thispage = $request->getArg('pagename');
74         $Pages = $request->session->get("PageTrail");
75         if (!is_array($Pages)) {
76             $Pages = array();
77         }
78
79         if (!isset($Pages[0]) or ($duplicates || ($thispage != $Pages[0]))) {
80             array_unshift($Pages, $thispage);
81             $request->session->set("PageTrail", $Pages);
82         }
83
84         $numberlinks = min(count($Pages), $numberlinks);
85         if (!$invisible and $numberlinks) {
86             $html = HTML::div(array('class' => 'pagetrail'));
87             $html->pushContent(WikiLink($Pages[$numberlinks - 1], 'auto'));
88             for ($i = $numberlinks - 2; $i >= 0; $i--) {
89                 if (!empty($Pages[$i]))
90                     $html->pushContent(PAGETRAIL_ARROW,
91                         WikiLink($Pages[$i], 'auto'));
92             }
93             return $html;
94         } else {
95             return HTML();
96         }
97     }
98 }
99
100 // Local Variables:
101 // mode: php
102 // tab-width: 8
103 // c-basic-offset: 4
104 // c-hanging-comment-ender-p: nil
105 // indent-tabs-mode: nil
106 // End: