4 Copyright 1999,2000,2001,2002,2004 $ThePhpWikiProgrammingTeam
6 This file is part of PhpWiki.
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.
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.
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
24 * http://sourceforge.net/tracker/?func=detail&aid=537380&group_id=6121&atid=306121
26 * Submitted By: Cuthbert Cat (cuthbertcat)
28 * This is a quick mod of BackLinks to do the job recursively. If your
29 * site is categorized correctly, and all the categories are listed in
30 * CategoryCategory, then a RecBackLinks there will produce a contents
31 * page for the entire site.
33 * The list is as deep as the recursion level.
35 * direction: Get BackLinks or forward links (links listed on the page)
37 * firstreversed: If true, get BackLinks for the first page and forward
38 * links for the rest. Only applicable when direction = 'forward'.
40 * excludeunknown: If true (default) then exclude any mentioned pages
41 * which don't exist yet. Only applicable when direction = 'forward'.
43 require_once('lib/PageList.php');
45 class WikiPlugin_SiteMap
54 function getDescription () {
55 return _("Recursively get BackLinks or links");
58 function getVersion() {
59 return preg_replace("/[Revision: $]/", '',
63 function getDefaultArguments() {
64 return array('exclude' => '',
67 'page' => '[pagename]',
68 'description' => $this->getDescription(),
71 'direction' => 'back',
72 'firstreversed' => false,
73 'excludeunknown' => true,
74 'includepages' => '' // to be used only from the IncludeSiteMap plugin
77 // info arg allows multiple columns
78 // info=mtime,hits,summary,version,author,locked,minor
79 // exclude arg allows multiple pagenames
80 // exclude=HomePage,RecentChanges
82 // Fixme: overcome limitation if two SiteMap plugins are in the same page!
83 // static $VisitedPages still holds it
84 function recursivelyGetBackLinks($startpage, $pagearr, $level = '*',
86 static $VisitedPages = array();
88 $startpagename = $startpage->getName();
89 //trigger_error("DEBUG: recursivelyGetBackLinks( $startpagename , $level )");
90 if ($level == $reclimit)
92 if (in_array($startpagename, $VisitedPages))
94 array_push($VisitedPages, $startpagename);
95 $pagelinks = $startpage->getLinks();
96 while ($link = $pagelinks->next()) {
97 $linkpagename = $link->getName();
98 if (($linkpagename != $startpagename)
99 and (!$this->ExcludedPages or !preg_match("/".$this->ExcludedPages."/", $linkpagename)))
101 $pagearr[$level . " [$linkpagename]"] = $link;
102 $pagearr = $this->recursivelyGetBackLinks($link, $pagearr,
110 function recursivelyGetLinks($startpage, $pagearr, $level = '*',
112 static $VisitedPages = array();
114 $startpagename = $startpage->getName();
115 //trigger_error("DEBUG: recursivelyGetLinks( $startpagename , $level )");
116 if ($level == $reclimit)
118 if (in_array($startpagename, $VisitedPages))
120 array_push($VisitedPages, $startpagename);
121 $reversed = (($this->firstreversed)
122 && ($startpagename == $this->initialpage));
123 //trigger_error("DEBUG: \$reversed = $reversed");
124 $pagelinks = $startpage->getLinks($reversed);
125 while ($link = $pagelinks->next()) {
126 $linkpagename = $link->getName();
127 if (($linkpagename != $startpagename) and
128 (!$this->ExcludedPages or !preg_match("/$this->ExcludedPages/", $linkpagename)))
130 if (!$this->excludeunknown or $this->dbi->isWikiPage($linkpagename)) {
131 $pagearr[$level . " [$linkpagename]"] = $link;
132 $pagearr = $this->recursivelyGetLinks($link, $pagearr,
142 function run($dbi, $argstr, &$request, $basepage) {
143 include_once('lib/BlockParser.php');
145 $args = $this->getArgs($argstr, $request, false);
149 $this->_pagename = $page;
150 $out = ''; // get rid of this
152 if (empty($exclude)) $exclude = array();
155 $this->ExcludedPages = empty($exclude) ? "" : ("^(?:" . join("|", $exclude) . ")");
156 $this->_default_limit = str_pad('', 3, '*');
157 if (is_numeric($reclimit)) {
162 $limit = str_pad('', $reclimit + 2, '*');
166 //Fixme: override given arg
167 $description = $this->getDescription();
169 $out = $this->getDescription() ." ". sprintf(_("(max. recursion level: %d)"),
170 $reclimit) . ":\n\n";
171 $html->pushContent(TransformText($out, 1.0, $page));
173 $pagelist = new PageList($info, $exclude);
174 $p = $dbi->getPage($page);
177 if ($direction == 'back') {
178 $pagearr = $this->recursivelyGetBackLinks($p, $pagearr, "*",
183 $this->initialpage = $page;
184 $this->firstreversed = $firstreversed;
185 $this->excludeunknown = $excludeunknown;
186 $pagearr = $this->recursivelyGetLinks($p, $pagearr, "*", $limit);
190 if (!empty($includepages)) {
191 // disallow direct usage, only via child class IncludeSiteMap
192 if (!isa($this,"WikiPlugin_IncludeSiteMap"))
194 if (!is_string($includepages))
195 $includepages = ' '; // avoid plugin loader problems
196 $loader = new WikiPluginLoader();
197 $plugin = $loader->getPlugin('IncludePage',false);
201 while (list($key, $link) = each($pagearr)) {
202 if (!empty($includepages)) {
203 $a = substr_count($key, '*');
204 $indenter = str_pad($nothing, $a);
205 //$request->setArg('IncludePage', 1);
206 // quote linkname, by Stefan Schorn
207 $plugin_args = 'page=\'' . $link->getName() . '\' ' . $includepages;
208 $pagehtml = $plugin->run($dbi, $plugin_args, $request, $basepage);
209 $html->pushContent($pagehtml);
210 //$html->pushContent( HTML(TransformText($indenter, 1.0, $page), $pagehtml));
211 //$out .= $indenter . $pagehtml . "\n";
217 if (empty($includepages)) {
218 return TransformText($out, 2.0, $page);
230 // c-hanging-comment-ender-p: nil
231 // indent-tabs-mode: nil