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 getDefaultArguments() {
59 return array('exclude' => '',
62 'page' => '[pagename]',
63 'description' => $this->getDescription(),
66 'direction' => 'back',
67 'firstreversed' => false,
68 'excludeunknown' => true,
69 'includepages' => '', // only for IncludeSiteMap and IncludeTree
70 'category' => '', // optional category filter (comma-delimited)
71 'dtree' => false, // optional for IncludeTree
74 // info arg allows multiple columns
75 // info=mtime,hits,summary,version,author,locked,minor
76 // exclude arg allows multiple pagenames
77 // exclude=HomePage,RecentChanges
79 // Fixme: overcome limitation if two SiteMap plugins are in the same page!
80 // static $VisitedPages still holds it
81 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 = '*',
109 static $VisitedPages = array();
111 $startpagename = $startpage->getName();
112 //trigger_error("DEBUG: recursivelyGetLinks( $startpagename , $level )");
113 if ($level == $reclimit)
115 if (in_array($startpagename, $VisitedPages))
117 array_push($VisitedPages, $startpagename);
118 $reversed = (($this->firstreversed)
119 && ($startpagename == $this->initialpage));
120 //trigger_error("DEBUG: \$reversed = $reversed");
121 $pagelinks = $startpage->getLinks($reversed);
122 while ($link = $pagelinks->next()) {
123 $linkpagename = $link->getName();
124 if (($linkpagename != $startpagename) and
125 (!$this->ExcludedPages or !preg_match("/$this->ExcludedPages/", $linkpagename)))
127 if (!$this->excludeunknown or $this->dbi->isWikiPage($linkpagename)) {
128 $pagearr[$level . " [$linkpagename]"] = $link;
129 $pagearr = $this->recursivelyGetLinks($link, $pagearr,
139 function run($dbi, $argstr, &$request, $basepage) {
140 include_once('lib/BlockParser.php');
142 $args = $this->getArgs($argstr, $request, false);
146 $this->_pagename = $page;
147 $out = ''; // get rid of this
149 if (empty($exclude)) $exclude = array();
152 $this->ExcludedPages = empty($exclude) ? "" : ("^(?:" . join("|", $exclude) . ")");
153 $this->_default_limit = str_pad('', 3, '*');
154 if (is_numeric($reclimit)) {
159 $limit = str_pad('', $reclimit + 2, '*');
163 //Fixme: override given arg
164 $description = $this->getDescription();
166 $out = $this->getDescription() ." ". sprintf(_("(max. recursion level: %d)"),
167 $reclimit) . ":\n\n";
168 $html->pushContent(TransformText($out, 1.0, $page));
170 $pagelist = new PageList($info, $exclude);
171 $p = $dbi->getPage($page);
174 if ($direction == 'back') {
175 $pagearr = $this->recursivelyGetBackLinks($p, $pagearr, "*", $limit);
179 $this->initialpage = $page;
180 $this->firstreversed = $firstreversed;
181 $this->excludeunknown = $excludeunknown;
182 $pagearr = $this->recursivelyGetLinks($p, $pagearr, "*", $limit);
186 if (!empty($includepages)) {
187 // disallow direct usage, only via child class IncludeSiteMap
188 if (!isa($this,"WikiPlugin_IncludeSiteMap") and !isa($this,"WikiPlugin_IncludeTree"))
190 if (!is_string($includepages))
191 $includepages = ' '; // avoid plugin loader problems
192 $loader = new WikiPluginLoader();
193 $plugin = $loader->getPlugin($dtree ? 'DynamicIncludePage' : 'IncludePage', false);
197 while (list($key, $link) = each($pagearr)) {
198 if (!empty($includepages)) {
199 $a = substr_count($key, '*');
200 $indenter = str_pad($nothing, $a);
201 //$request->setArg('IncludePage', 1);
202 // quote linkname, by Stefan Schorn
203 $plugin_args = 'page=\'' . $link->getName() . '\' ' . $includepages;
204 $pagehtml = $plugin->run($dbi, $plugin_args, $request, $basepage);
205 $html->pushContent($pagehtml);
206 //$html->pushContent( HTML(TransformText($indenter, 1.0, $page), $pagehtml));
207 //$out .= $indenter . $pagehtml . "\n";
213 if (empty($includepages)) {
214 return TransformText($out, 2.0, $page);
225 // c-hanging-comment-ender-p: nil
226 // indent-tabs-mode: nil