2 rcs_id('$Id: SiteMap.php,v 1.7 2003-02-21 04:12:06 dairiki 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
75 // info arg allows multiple columns
76 // info=mtime,hits,summary,version,author,locked,minor
77 // exclude arg allows multiple pagenames
78 // exclude=HomePage,RecentChanges
80 function recursivelyGetBackLinks($startpage, $pagearr, $level = '*',
82 static $VisitedPages = array();
84 $startpagename = $startpage->getName();
85 //trigger_error("DEBUG: recursivelyGetBackLinks( $startpagename , $level )");
86 if ($level == $reclimit)
88 if (in_array($startpagename, $VisitedPages))
90 array_push($VisitedPages, $startpagename);
91 $pagelinks = $startpage->getLinks();
92 while ($link = $pagelinks->next()) {
93 $linkpagename = $link->getName();
94 if (($linkpagename != $startpagename)
95 && !in_array($linkpagename, $this->ExcludedPages)) {
96 $pagearr[$level . " [$linkpagename]"] = $link;
97 $pagearr = $this->recursivelyGetBackLinks($link, $pagearr,
105 function recursivelyGetLinks($startpage, $pagearr, $level = '*',
107 static $VisitedPages = array();
109 $startpagename = $startpage->getName();
110 //trigger_error("DEBUG: recursivelyGetLinks( $startpagename , $level )");
111 if ($level == $reclimit)
113 if (in_array($startpagename, $VisitedPages))
115 array_push($VisitedPages, $startpagename);
116 $reversed = (($this->firstreversed)
117 && ($startpagename == $this->initialpage));
118 //trigger_error("DEBUG: \$reversed = $reversed");
119 $pagelinks = $startpage->getLinks($reversed);
120 while ($link = $pagelinks->next()) {
121 $linkpagename = $link->getName();
122 if (($linkpagename != $startpagename)
123 && !in_array($linkpagename, $this->ExcludedPages)) {
124 if (!$this->excludeunknown
125 || $this->dbi->isWikiPage($linkpagename)) {
126 $pagearr[$level . " [$linkpagename]"] = $link;
127 $pagearr = $this->recursivelyGetLinks($link, $pagearr,
137 function run($dbi, $argstr, $request) {
138 include_once('lib/BlockParser.php');
140 $args = $this->getArgs($argstr, $request, false);
145 $exclude = $exclude ? explode(",", $exclude) : array();
148 $this->ExcludedPages = $exclude;
149 $this->_default_limit = str_pad('', 3, '*');
150 if (is_numeric($reclimit)) {
155 $limit = str_pad('', $reclimit + 2, '*');
160 $out .= $description ." ". sprintf(_("(max. recursion level: %d)"),
161 $reclimit) . ":\n\n";
162 $pagelist = new PageList($info, $exclude);
163 $p = $dbi->getPage($page);
166 if ($direction == 'back') {
167 $pagearr = $this->recursivelyGetBackLinks($p, $pagearr, "*",
172 $this->initialpage = $page;
173 $this->firstreversed = $firstreversed;
174 $this->excludeunknown = $excludeunknown;
175 $pagearr = $this->recursivelyGetLinks($p, $pagearr, "*", $limit);
179 while (list($key, $link) = each($pagearr)) {
182 return TransformText($out, 1, $page /*dunno if this last arg is right...*/);
186 // $Log: not supported by cvs2svn $
187 // Revision 1.6 2003/01/18 22:08:01 carstenklapp
189 // Reformatting & tabs to spaces;
190 // Added copyleft, getVersion, getDescription, rcs_id.
198 // c-hanging-comment-ender-p: nil
199 // indent-tabs-mode: nil