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 along
19 * with PhpWiki; if not, write to the Free Software Foundation, Inc.,
20 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 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
50 function getDescription()
52 return _("Recursively get BackLinks or links.");
55 function getDefaultArguments()
57 return array('exclude' => '',
60 'page' => '[pagename]',
61 'description' => $this->getDescription(),
64 'direction' => 'back',
65 'firstreversed' => false,
66 'excludeunknown' => true,
67 'includepages' => '', // only for IncludeSiteMap and IncludeTree
68 'category' => '', // optional category filter (comma-delimited)
69 'dtree' => false, // optional for IncludeTree
73 // info arg allows multiple columns
74 // info=mtime,hits,summary,version,author,locked,minor
75 // exclude arg allows multiple pagenames
76 // exclude=HomePage,RecentChanges
78 // Fixme: overcome limitation if two SiteMap plugins are in the same page!
79 // static $VisitedPages still holds it
80 function recursivelyGetBackLinks($startpage, $pagearr, $level = '*',
83 static $VisitedPages = array();
85 $startpagename = $startpage->getName();
86 //trigger_error("DEBUG: recursivelyGetBackLinks( $startpagename , $level )");
87 if ($level == $reclimit)
89 if (in_array($startpagename, $VisitedPages))
91 array_push($VisitedPages, $startpagename);
92 $pagelinks = $startpage->getLinks();
93 while ($link = $pagelinks->next()) {
94 $linkpagename = $link->getName();
95 if (($linkpagename != $startpagename)
96 and (!$this->ExcludedPages or !preg_match("/" . $this->ExcludedPages . "/", $linkpagename))
98 $pagearr[$level . " [$linkpagename]"] = $link;
99 $pagearr = $this->recursivelyGetBackLinks($link, $pagearr,
107 function recursivelyGetLinks($startpage, $pagearr, $level = '*',
110 static $VisitedPages = array();
112 $startpagename = $startpage->getName();
113 //trigger_error("DEBUG: recursivelyGetLinks( $startpagename , $level )");
114 if ($level == $reclimit)
116 if (in_array($startpagename, $VisitedPages))
118 array_push($VisitedPages, $startpagename);
119 $reversed = (($this->firstreversed)
120 && ($startpagename == $this->initialpage));
121 //trigger_error("DEBUG: \$reversed = $reversed");
122 $pagelinks = $startpage->getLinks($reversed);
123 while ($link = $pagelinks->next()) {
124 $linkpagename = $link->getName();
125 if (($linkpagename != $startpagename) and
126 (!$this->ExcludedPages or !preg_match("/$this->ExcludedPages/", $linkpagename))
128 if (!$this->excludeunknown or $this->dbi->isWikiPage($linkpagename)) {
129 $pagearr[$level . " [$linkpagename]"] = $link;
130 $pagearr = $this->recursivelyGetLinks($link, $pagearr,
139 function run($dbi, $argstr, &$request, $basepage)
141 include_once 'lib/BlockParser.php';
143 $args = $this->getArgs($argstr, $request, false);
147 $this->_pagename = $page;
148 $out = ''; // get rid of this
150 if (empty($exclude)) $exclude = array();
153 $this->ExcludedPages = empty($exclude) ? "" : ("^(?:" . join("|", $exclude) . ")");
154 $this->_default_limit = str_pad('', 3, '*');
155 if (is_numeric($reclimit)) {
160 $limit = str_pad('', $reclimit + 2, '*');
164 //Fixme: override given arg
166 $out = $this->getDescription() . " " . sprintf(_("(max. recursion level: %d)"),
167 $reclimit) . ":\n\n";
168 $html->pushContent(TransformText($out, $page));
170 $pagelist = new PageList($info, $exclude);
171 $p = $dbi->getPage($page);
174 if ($direction == 'back') {
175 $pagearr = $this->recursivelyGetBackLinks($p, $pagearr, "*", $limit);
178 $this->initialpage = $page;
179 $this->firstreversed = $firstreversed;
180 $this->excludeunknown = $excludeunknown;
181 $pagearr = $this->recursivelyGetLinks($p, $pagearr, "*", $limit);
185 if (!empty($includepages)) {
186 // disallow direct usage, only via child class IncludeSiteMap
187 if (!isa($this, "WikiPlugin_IncludeSiteMap") and !isa($this, "WikiPlugin_IncludeTree"))
189 if (!is_string($includepages))
190 $includepages = ' '; // avoid plugin loader problems
191 $loader = new WikiPluginLoader();
192 $plugin = $loader->getPlugin(!empty($dtree) ? 'DynamicIncludePage' : 'IncludePage', false);
196 while (list($key, $link) = each($pagearr)) {
197 if (!empty($includepages)) {
198 $a = substr_count($key, '*');
199 $indenter = str_pad($nothing, $a);
200 //$request->setArg('IncludePage', 1);
201 // quote linkname, by Stefan Schorn
202 $plugin_args = 'page=\'' . $link->getName() . '\' ' . $includepages;
203 $pagehtml = $plugin->run($dbi, $plugin_args, $request, $basepage);
204 $html->pushContent($pagehtml);
209 if (empty($includepages)) {
210 return TransformText($out, $page);
221 // c-hanging-comment-ender-p: nil
222 // indent-tabs-mode: nil