2 rcs_id('$Id: SiteMap.php,v 1.11 2004-03-24 19:39:03 rurban Exp $');
4 Copyright 1999, 2000, 2001, 2002 $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: $]/", '',
60 "\$Revision: 1.11 $");
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 && !preg_match("/$this->ExcludedPages/", $linkpagename)) {
100 $pagearr[$level . " [$linkpagename]"] = $link;
101 $pagearr = $this->recursivelyGetBackLinks($link, $pagearr,
109 function recursivelyGetLinks($startpage, $pagearr, $level = '*',
111 static $VisitedPages = array();
113 $startpagename = $startpage->getName();
114 //trigger_error("DEBUG: recursivelyGetLinks( $startpagename , $level )");
115 if ($level == $reclimit)
117 if (in_array($startpagename, $VisitedPages))
119 array_push($VisitedPages, $startpagename);
120 $reversed = (($this->firstreversed)
121 && ($startpagename == $this->initialpage));
122 //trigger_error("DEBUG: \$reversed = $reversed");
123 $pagelinks = $startpage->getLinks($reversed);
124 while ($link = $pagelinks->next()) {
125 $linkpagename = $link->getName();
126 if (($linkpagename != $startpagename)
127 && !preg_match("/$this->ExcludedPages/", $linkpagename)) {
128 if (!$this->excludeunknown
129 || $this->dbi->isWikiPage($linkpagename)) {
130 $pagearr[$level . " [$linkpagename]"] = $link;
131 $pagearr = $this->recursivelyGetLinks($link, $pagearr,
141 function run($dbi, $argstr, &$request, $basepage) {
142 include_once('lib/BlockParser.php');
144 $args = $this->getArgs($argstr, $request, false);
148 $this->_pagename = $page;
149 $out = ''; // get rid of this
151 $exclude = $exclude ? explode(",", $exclude) : array();
154 $this->ExcludedPages = "^(?:" . join("|", $exclude) . ")";
155 $this->_default_limit = str_pad('', 3, '*');
156 if (is_numeric($reclimit)) {
161 $limit = str_pad('', $reclimit + 2, '*');
165 //Fixme: override given arg
166 $description = $this->getDescription();
168 $out = $this->getDescription() ." ". sprintf(_("(max. recursion level: %d)"),
169 $reclimit) . ":\n\n";
170 $html->pushContent(TransformText($out, 1.0, $page));
172 $pagelist = new PageList($info, $exclude);
173 $p = $dbi->getPage($page);
176 if ($direction == 'back') {
177 $pagearr = $this->recursivelyGetBackLinks($p, $pagearr, "*",
182 $this->initialpage = $page;
183 $this->firstreversed = $firstreversed;
184 $this->excludeunknown = $excludeunknown;
185 $pagearr = $this->recursivelyGetLinks($p, $pagearr, "*", $limit);
189 if (!empty($includepages)) {
190 // disallow direct usage, only via child class IncludeSiteMap
191 if (!isa($this,"WikiPlugin_IncludeSiteMap"))
193 if (!is_string($includepages))
194 $includepages = ' '; // avoid plugin loader problems
195 $loader = new WikiPluginLoader();
196 $plugin = $loader->getPlugin('IncludePage',false);
200 while (list($key, $link) = each($pagearr)) {
201 if (!empty($includepages)) {
202 $a = substr_count($key, '*');
203 $indenter = str_pad($nothing, $a);
204 //$request->setArg('IncludePage', 1);
205 $plugin_args = 'page=' . $link->getName() . ' ' . $includepages;
206 $pagehtml = $plugin->run($dbi, $plugin_args, $request, $basepage);
207 $html->pushContent($pagehtml);
208 //$html->pushContent( HTML(TransformText($indenter, 1.0, $page), $pagehtml));
209 //$out .= $indenter . $pagehtml . "\n";
215 if (empty($includepages)) {
216 return TransformText($out, 1.0, $page);
223 // $Log: not supported by cvs2svn $
224 // Revision 1.10 2004/02/17 12:11:36 rurban
225 // added missing 4th basepage arg at plugin->run() to almost all plugins. This caused no harm so far, because it was silently dropped on normal usage. However on plugin internal ->run invocations it failed. (InterWikiSearch, IncludeSiteMap, ...)
227 // Revision 1.9 2004/02/12 13:05:50 rurban
228 // Rename functional for PearDB backend
229 // some other minor changes
230 // SiteMap comes with a not yet functional feature request: includepages (tbd)
232 // Revision 1.8 2004/01/24 23:24:07 rurban
233 // Patch by Alec Thomas, allows Perl regular expressions in SiteMap exclude lists.
234 // exclude=WikiWikiWeb,(?:Category|Topic).*
235 // It is backwards compatible unless old exclude lists, and therefore Wiki
236 // page names, contain regular expression characters.
238 // Revision 1.7 2003/02/21 04:12:06 dairiki
239 // Minor fixes for new cached markup.
241 // Revision 1.6 2003/01/18 22:08:01 carstenklapp
243 // Reformatting & tabs to spaces;
244 // Added copyleft, getVersion, getDescription, rcs_id.
252 // c-hanging-comment-ender-p: nil
253 // indent-tabs-mode: nil