2 rcs_id('$Id: UnfoldSubpages.php,v 1.7 2003-02-21 04:12:06 dairiki Exp $');
4 Copyright 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 * UnfoldSubpages: Lists the content of all SubPages of the current page.
25 * This is e.g. useful for the CalendarPlugin, to see all entries at once.
26 * Usage: <?plugin UnfoldSubpages words=50 ?>
27 * Author: Reini Urban <rurban@x-ray.at>
29 class WikiPlugin_UnfoldSubpages
33 return _("UnfoldSubpages");
36 function getDescription () {
37 return _("Includes the content of all SubPages of the current page.");
40 function getVersion() {
41 return preg_replace("/[Revision: $]/", '',
45 function getDefaultArguments() {
46 return array(//'header' => '', // expandable string
47 'quiet' => false, // no header
49 'sortby' => 'pagename',
50 'pages' => '', // maximum number of pages
52 'sections' => false, // maximum number of
53 // sections per page to
55 'smalltitle' => false, // if set, hide
56 // transclusion-title,
57 // just have a small link
58 // at the start of the
60 'words' => false, // maximum number of words
61 // per page to include
62 'lines' => false, // maximum number of lines
63 // per page to include
64 'bytes' => false, // maximum number of bytes
65 // per page to include
66 'section' => false, // named section per page
68 'sectionhead' => false // when including a named
75 function firstNWordsOfContent($n, $content) {
78 foreach ($content as $line) {
79 $words = explode(' ', $line);
80 if ($wordcount + count($words) > $n) {
81 $new[] = implode(' ', array_slice($words, 0, $n - $wordcount))
82 . sprintf(_("... first %d words"), $n);
86 $wordcount += count($words);
93 function extractSection ($section, $content, $page, $quiet, $sectionhead) {
94 $qsection = preg_replace('/\s+/', '\s+', preg_quote($section, '/'));
96 if (preg_match("/ ^(!{1,})\\s*$qsection" // section header
97 . " \\s*$\\n?" // possible blank lines
98 . " ( (?: ^.*\\n? )*? )" // some lines
99 . " (?= ^\\1 | \\Z)/xm", // sec header (same
102 implode("\n", $content),
104 // Strip trailing blanks lines and ---- <hr>s
105 $text = preg_replace("/\\s*^-{4,}\\s*$/m", "", $match[2]);
107 $text = $match[1] . $section ."\n". $text;
108 return explode("\n", $text);
111 $mesg = $page ." ". $section;
114 return array(sprintf(_("<%s: no such section>"), $mesg));
117 function run($dbi, $argstr, $request) {
118 include_once('lib/BlockParser.php');
120 $pagename = $request->getArg('pagename');
121 $subpages = explodePageList($pagename . SUBPAGE_SEPARATOR . '*');
123 return $this->error(_("The current page has no subpages defined."));
125 include_once('lib/BlockParser.php');
126 extract($this->getArgs($argstr, $request));
128 $subpages = array_reverse($subpages);
130 $subpages = array_slice ($subpages, 0, $pages);
132 foreach ($subpages as $page) {
133 // A page cannot include itself. Avoid doublettes.
134 static $included_pages = array();
135 if (in_array($page, $included_pages)) {
136 $content->pushContent(HTML::p(sprintf(_("recursive inclusion of page %s ignored"),
140 // trap any remaining nonexistant subpages
141 if ($dbi->isWikiPage($page)) {
142 $p = $dbi->getPage($page);
143 $r = $p->getCurrentRevision();
144 $c = $r->getContent();
147 $c = $this->extractSection($section, $c, $page, $quiet,
150 $c = array_slice($c, 0, $lines)
151 . sprintf(_(" ... first %d lines"), $bytes);
153 $c = $this->firstNWordsOfContent($words, $c);
155 if (strlen($c) > $bytes)
156 $c = substr($c, 0, $bytes)
157 . sprintf(_(" ... first %d bytes"), $bytes);
160 array_push($included_pages, $page);
162 $pname = array_pop(explode("/", $page)); // get last subpage name
163 // Use _("%s: %s") instead of .": ". for French punctuation
164 $ct = TransformText(sprintf(_("%s: %s"), "[$pname|$page]",
166 $r->get('markup'), $page);
169 $ct = TransformText(implode("\n", $c), $r->get('markup'), $page);
171 array_pop($included_pages);
173 $content->pushContent(HTML::p(array('class' => $quiet ?
174 '' : 'transclusion-title'),
175 fmt("Included from %s:",
178 $content->pushContent(HTML(HTML::div(array('class' => $quiet ?
179 '' : 'transclusion'),
187 // $Log: not supported by cvs2svn $
188 // Revision 1.6 2003/02/11 09:34:34 rurban
189 // fix by Steven D. Brewer <sbrewer@bio.umass.edu> to respect the $pages argument
191 // Revision 1.5 2003/01/18 22:11:44 carstenklapp
193 // Reformatting & tabs to spaces;
194 // Added copyleft, getVersion, getDescription, rcs_id.
196 // Revision 1.4 2003/01/05 02:37:30 carstenklapp
197 // New: Implemented 'smalltitle' argument and date sorting fix from
198 // Cuthbert Cat's sf patch 655095. Added getVersion & getDescription;
201 // Revision 1.3 2003/01/04 22:46:07 carstenklapp
202 // Workaround: when page has no subpages avoid include of nonexistant pages.
206 // - line & word limit doesn't work if the included page itself
214 // c-hanging-comment-ender-p: nil
215 // indent-tabs-mode: nil