2 rcs_id('$Id: UnfoldSubpages.php,v 1.1 2002-09-01 16:33:19 rurban 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
25 * UnfoldSubpages: Lists the content of all SubPages of the current page.
26 * This is e.g. useful for the CalendarPlugin, to see all entries at once.
27 * Usage: <?plugin UnfoldSubpages words=50 ?>
28 * Author: Reini Urban <rurban@x-ray.at>
31 class WikiPlugin_UnfoldSubpages
35 return _("UnfoldSubpages");
38 function getDefaultArguments() {
39 return array( //'header' => '', // expandable string
40 'quiet' => false, // no header
42 'sortby' => 'pagename',
43 'pages' => '', // maximum number of pages to include
44 'sections' => false, // maximum number of sections per page to include
45 'words' => false, // maximum number of words per page to include
46 'lines' => false, // maximum number of lines per page to include
47 'bytes' => false, // maximum number of bytes per page to include
48 'section' => false, // named section per page only
49 'sectionhead' => false // when including a named section show the heading
54 function firstNWordsOfContent( $n, $content ) {
57 foreach ($content as $line) {
58 $words = explode(' ', $line);
59 if ($wordcount + count($words) > $n) {
60 $new[] = implode(' ', array_slice($words, 0, $n - $wordcount))
61 . sprintf(_("... first $d words"), $n);
64 $wordcount += count($words);
71 function extractSection ($section, $content, $page, $quiet, $sectionhead) {
72 $qsection = preg_replace('/\s+/', '\s+', preg_quote($section, '/'));
74 if (preg_match("/ ^(!{1,})\\s*$qsection" // section header
75 . " \\s*$\\n?" // possible blank lines
76 . " ( (?: ^.*\\n? )*? )" // some lines
77 . " (?= ^\\1 | \\Z)/xm", // sec header (same or higher level) (or EOF)
78 implode("\n", $content),
80 // Strip trailing blanks lines and ---- <hr>s
81 $text = preg_replace("/\\s*^-{4,}\\s*$/m", "", $match[2]);
83 $text = $match[1] . $section ."\n". $text;
84 return explode("\n", $text);
87 $mesg = $page ." ". $section;
90 return array(sprintf(_("<%s: no such section>"), $mesg));
93 function run($dbi, $argstr, $request) {
94 $pagename = $request->getArg('pagename');
95 $subpages = explodePageList($pagename . SUBPAGE_SEPARATOR . '*');
97 return $this->error(_("The current page has no subpages defined."));
99 include_once('lib/BlockParser.php');
100 extract($this->getArgs($argstr, $request));
102 foreach ($subpages as $page) {
103 // A page cannot include itself. Avoid doublettes.
104 static $included_pages = array();
105 if (in_array($page, $included_pages)) {
106 $content->pushContent(HTML::p(sprintf(_("recursive inclusion of page %s ignored"), $page)));
110 $p = $dbi->getPage($page);
111 $r = $p->getCurrentRevision();
112 $c = $r->getContent();
115 $c = $this->extractSection($section, $c, $page, $quiet, $sectionhead);
117 $c = array_slice($c, 0, $lines) . sprintf(_(" ... first $d lines"), $bytes);
119 $c = $this->firstNWordsOfContent($words, $c);
121 if (strlen($c) > $bytes)
122 $c = substr($c,0,$bytes) . sprintf(_(" ... first $d bytes"), $bytes);
125 array_push($included_pages, $page);
126 $ct = TransformText(implode("\n", $c), $r->get('markup'));
127 array_pop($included_pages);
128 $content->pushContent(HTML(HTML::p(array('class' => $quiet ? '' : 'transclusion-title'),
129 fmt("Included from %s:",WikiLink($page))),
130 HTML::div(array('class' => $quiet ? '' : 'transclusion'),
138 // - line & word limit doesn't work if the included page itself
146 // c-hanging-comment-ender-p: nil
147 // indent-tabs-mode: nil