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
55 function getDescription()
57 return _("Recursively get BackLinks or links");
60 function getDefaultArguments()
62 return array('exclude' => '',
65 'page' => '[pagename]',
66 'description' => $this->getDescription(),
69 'direction' => 'back',
70 'firstreversed' => false,
71 'excludeunknown' => true,
72 'includepages' => '', // only for IncludeSiteMap and IncludeTree
73 'category' => '', // optional category filter (comma-delimited)
74 'dtree' => false, // optional for IncludeTree
78 // info arg allows multiple columns
79 // info=mtime,hits,summary,version,author,locked,minor
80 // exclude arg allows multiple pagenames
81 // exclude=HomePage,RecentChanges
83 // Fixme: overcome limitation if two SiteMap plugins are in the same page!
84 // static $VisitedPages still holds it
85 function recursivelyGetBackLinks($startpage, $pagearr, $level = '*',
88 static $VisitedPages = array();
90 $startpagename = $startpage->getName();
91 //trigger_error("DEBUG: recursivelyGetBackLinks( $startpagename , $level )");
92 if ($level == $reclimit)
94 if (in_array($startpagename, $VisitedPages))
96 array_push($VisitedPages, $startpagename);
97 $pagelinks = $startpage->getLinks();
98 while ($link = $pagelinks->next()) {
99 $linkpagename = $link->getName();
100 if (($linkpagename != $startpagename)
101 and (!$this->ExcludedPages or !preg_match("/" . $this->ExcludedPages . "/", $linkpagename))
103 $pagearr[$level . " [$linkpagename]"] = $link;
104 $pagearr = $this->recursivelyGetBackLinks($link, $pagearr,
112 function recursivelyGetLinks($startpage, $pagearr, $level = '*',
115 static $VisitedPages = array();
117 $startpagename = $startpage->getName();
118 //trigger_error("DEBUG: recursivelyGetLinks( $startpagename , $level )");
119 if ($level == $reclimit)
121 if (in_array($startpagename, $VisitedPages))
123 array_push($VisitedPages, $startpagename);
124 $reversed = (($this->firstreversed)
125 && ($startpagename == $this->initialpage));
126 //trigger_error("DEBUG: \$reversed = $reversed");
127 $pagelinks = $startpage->getLinks($reversed);
128 while ($link = $pagelinks->next()) {
129 $linkpagename = $link->getName();
130 if (($linkpagename != $startpagename) and
131 (!$this->ExcludedPages or !preg_match("/$this->ExcludedPages/", $linkpagename))
133 if (!$this->excludeunknown or $this->dbi->isWikiPage($linkpagename)) {
134 $pagearr[$level . " [$linkpagename]"] = $link;
135 $pagearr = $this->recursivelyGetLinks($link, $pagearr,
144 function run($dbi, $argstr, &$request, $basepage)
146 include_once 'lib/BlockParser.php';
148 $args = $this->getArgs($argstr, $request, false);
152 $this->_pagename = $page;
153 $out = ''; // get rid of this
155 if (empty($exclude)) $exclude = array();
158 $this->ExcludedPages = empty($exclude) ? "" : ("^(?:" . join("|", $exclude) . ")");
159 $this->_default_limit = str_pad('', 3, '*');
160 if (is_numeric($reclimit)) {
165 $limit = str_pad('', $reclimit + 2, '*');
169 //Fixme: override given arg
170 $description = $this->getDescription();
172 $out = $this->getDescription() . " " . sprintf(_("(max. recursion level: %d)"),
173 $reclimit) . ":\n\n";
174 $html->pushContent(TransformText($out, 1.0, $page));
176 $pagelist = new PageList($info, $exclude);
177 $p = $dbi->getPage($page);
180 if ($direction == 'back') {
181 $pagearr = $this->recursivelyGetBackLinks($p, $pagearr, "*", $limit);
184 $this->initialpage = $page;
185 $this->firstreversed = $firstreversed;
186 $this->excludeunknown = $excludeunknown;
187 $pagearr = $this->recursivelyGetLinks($p, $pagearr, "*", $limit);
191 if (!empty($includepages)) {
192 // disallow direct usage, only via child class IncludeSiteMap
193 if (!isa($this, "WikiPlugin_IncludeSiteMap") and !isa($this, "WikiPlugin_IncludeTree"))
195 if (!is_string($includepages))
196 $includepages = ' '; // avoid plugin loader problems
197 $loader = new WikiPluginLoader();
198 $plugin = $loader->getPlugin(!empty($dtree) ? 'DynamicIncludePage' : 'IncludePage', false);
202 while (list($key, $link) = each($pagearr)) {
203 if (!empty($includepages)) {
204 $a = substr_count($key, '*');
205 $indenter = str_pad($nothing, $a);
206 //$request->setArg('IncludePage', 1);
207 // quote linkname, by Stefan Schorn
208 $plugin_args = 'page=\'' . $link->getName() . '\' ' . $includepages;
209 $pagehtml = $plugin->run($dbi, $plugin_args, $request, $basepage);
210 $html->pushContent($pagehtml);
211 //$html->pushContent( HTML(TransformText($indenter, 1.0, $page), $pagehtml));
212 //$out .= $indenter . $pagehtml . "\n";
217 if (empty($includepages)) {
218 return TransformText($out, 2.0, $page);
229 // c-hanging-comment-ender-p: nil
230 // indent-tabs-mode: nil