2 rcs_id('$Id: SiteMap.php,v 1.9 2004-02-12 13:05:50 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
52 function getDescription () {
53 return sprintf(_("Recursively get BackLinks or links for %s"),
57 function getVersion() {
58 return preg_replace("/[Revision: $]/", '',
62 function getDefaultArguments() {
63 return array('exclude' => '',
66 'page' => '[pagename]',
67 'description' => $this->getDescription(),
70 'direction' => 'back',
71 'firstreversed' => false,
72 'excludeunknown' => true,
73 'includepages' => '' // this doesn't yet work as expected
76 // info arg allows multiple columns
77 // info=mtime,hits,summary,version,author,locked,minor
78 // exclude arg allows multiple pagenames
79 // exclude=HomePage,RecentChanges
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 && !preg_match("/$this->ExcludedPages/", $linkpagename)) {
97 $pagearr[$level . " [$linkpagename]"] = $link;
98 $pagearr = $this->recursivelyGetBackLinks($link, $pagearr,
106 function recursivelyGetLinks($startpage, $pagearr, $level = '*',
108 static $VisitedPages = array();
110 $startpagename = $startpage->getName();
111 //trigger_error("DEBUG: recursivelyGetLinks( $startpagename , $level )");
112 if ($level == $reclimit)
114 if (in_array($startpagename, $VisitedPages))
116 array_push($VisitedPages, $startpagename);
117 $reversed = (($this->firstreversed)
118 && ($startpagename == $this->initialpage));
119 //trigger_error("DEBUG: \$reversed = $reversed");
120 $pagelinks = $startpage->getLinks($reversed);
121 while ($link = $pagelinks->next()) {
122 $linkpagename = $link->getName();
123 if (($linkpagename != $startpagename)
124 && !preg_match("/$this->ExcludedPages/", $linkpagename)) {
125 if (!$this->excludeunknown
126 || $this->dbi->isWikiPage($linkpagename)) {
127 $pagearr[$level . " [$linkpagename]"] = $link;
128 $pagearr = $this->recursivelyGetLinks($link, $pagearr,
138 function run($dbi, $argstr, $request) {
139 include_once('lib/BlockParser.php');
141 $args = $this->getArgs($argstr, $request, false);
146 $exclude = $exclude ? explode(",", $exclude) : array();
149 $this->ExcludedPages = "^(?:" . join("|", $exclude) . ")";
150 $this->_default_limit = str_pad('', 3, '*');
151 if (is_numeric($reclimit)) {
156 $limit = str_pad('', $reclimit + 2, '*');
161 $out .= $description ." ". sprintf(_("(max. recursion level: %d)"),
162 $reclimit) . ":\n\n";
163 $pagelist = new PageList($info, $exclude);
164 $p = $dbi->getPage($page);
167 if ($direction == 'back') {
168 $pagearr = $this->recursivelyGetBackLinks($p, $pagearr, "*",
173 $this->initialpage = $page;
174 $this->firstreversed = $firstreversed;
175 $this->excludeunknown = $excludeunknown;
176 $pagearr = $this->recursivelyGetLinks($p, $pagearr, "*", $limit);
180 while (list($key, $link) = each($pagearr)) {
181 if (!empty($includepages)) { // this doesn't work as expected
182 $a = substr_count($key, '*');
183 $indenter = str_pad($nothing, $a);
184 $out .= $indenter . '<?plugin IncludePage page=' . $link->getName();
185 if (is_string($includepages))
186 $out .= " " . $includepages; // args
187 $out .= " ?>" . "\n";
193 return TransformText($out, 1.0, $page /*cached or not cached?...*/);
197 // $Log: not supported by cvs2svn $
198 // Revision 1.8 2004/01/24 23:24:07 rurban
199 // Patch by Alec Thomas, allows Perl regular expressions in SiteMap exclude lists.
200 // exclude=WikiWikiWeb,(?:Category|Topic).*
201 // It is backwards compatible unless old exclude lists, and therefore Wiki
202 // page names, contain regular expression characters.
204 // Revision 1.7 2003/02/21 04:12:06 dairiki
205 // Minor fixes for new cached markup.
207 // Revision 1.6 2003/01/18 22:08:01 carstenklapp
209 // Reformatting & tabs to spaces;
210 // Added copyleft, getVersion, getDescription, rcs_id.
218 // c-hanging-comment-ender-p: nil
219 // indent-tabs-mode: nil