2 rcs_id('$Id: UnfoldSubpages.php,v 1.17 2004-11-23 15:17:19 rurban Exp $');
4 Copyright 2002, 2004 $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 * Warning: Don't use it with non-existant sections!
27 * The section extractor is currently quite unstable.
28 * Usage: <?plugin UnfoldSubpages sortby=-mtime words=50 maxpages=5 ?>
29 * Author: Reini Urban <rurban@x-ray.at>
31 class WikiPlugin_UnfoldSubpages
35 return _("UnfoldSubpages");
38 function getDescription () {
39 return _("Includes the content of all SubPages of the current page.");
42 function getVersion() {
43 return preg_replace("/[Revision: $]/", '',
44 "\$Revision: 1.17 $");
47 function getDefaultArguments() {
50 PageList::supportedArgs(),
52 'pagename' => '[pagename]', // default: current page
53 //'header' => '', // expandable string
54 'quiet' => false, // print no header
55 'sortby' => 'pagename', // [+|-]pagename, [+|-]mtime, [+|-]hits
56 'maxpages' => false, // maximum number of pages to include
57 'sections' => false, // maximum number of sections per page to include
58 'smalltitle' => false, // if set, hide transclusion-title,
59 // just have a small link at the start of
61 'words' => false, // maximum number of words
62 // per page to include
63 'lines' => false, // maximum number of lines
64 // per page to include
65 'bytes' => false, // maximum number of bytes
66 // per page to include
67 'section' => false, // this named section per page only
68 'sectionhead' => false // when including a named
69 // section show the heading
73 function run($dbi, $argstr, &$request, $basepage) {
74 static $included_pages = false;
75 if (!$included_pages) $included_pages = array($basepage);
77 $args = $this->getArgs($argstr, $request);
79 $subpages = explodePageList($pagename . SUBPAGE_SEPARATOR . '*', false, $sortby, $limit, $exclude);
81 return $this->error(_("The current page has no subpages defined."));
85 $subpages = array_slice ($subpages, 0, $maxpages);
88 include_once('lib/BlockParser.php');
90 foreach ($subpages as $page) {
91 // A page cannot include itself. Avoid doublettes.
92 if (in_array($page, $included_pages)) {
93 $content->pushContent(HTML::p(sprintf(_("recursive inclusion of page %s ignored"),
97 // trap any remaining nonexistant subpages
98 if ($dbi->isWikiPage($page)) {
99 $p = $dbi->getPage($page);
100 $r = $p->getCurrentRevision();
101 $c = $r->getContent();
102 $ct = implode("\n", $c);
103 // trap recursive redirects
104 if (preg_match('/<'.'\?plugin\s+RedirectTo\s+page=(\w+)\s+\?'.'>/',$ct,$m)) {
105 if (in_array($m[1], $included_pages)) {
106 //$content->pushContent(HTML::p(sprintf(_("recursive inclusion of page %s ignored"),
107 // $page.' => '.$m[1])));
112 $c = extractSection($section, $c, $page, $quiet,
115 $c = array_slice($c, 0, $lines)
116 . sprintf(_(" ... first %d lines"), $bytes);
118 $c = firstNWordsOfContent($words, $c);
120 if (strlen($c) > $bytes)
121 $c = substr($c, 0, $bytes)
122 . sprintf(_(" ... first %d bytes"), $bytes);
125 array_push($included_pages, $page);
127 $pname = array_pop(explode("/", $page)); // get last subpage name
128 // Use _("%s: %s") instead of .": ". for French punctuation
129 $ct = TransformText(sprintf(_("%s: %s"), "[$pname|$page]",
131 $r->get('markup'), $page);
134 $ct = TransformText($ct, $r->get('markup'), $page);
136 array_pop($included_pages);
138 $content->pushContent(HTML::p(array('class' => $quiet ?
139 '' : 'transclusion-title'),
140 fmt("Included from %s:",
143 $content->pushContent(HTML(HTML::div(array('class' => $quiet ?
144 '' : 'transclusion'),
152 // $Log: not supported by cvs2svn $
153 // Revision 1.16 2004/09/25 16:35:09 rurban
154 // use stdlib firstNWordsOfContent, extractSection
156 // Revision 1.15 2004/07/03 14:48:18 rurban
157 // Tested new mysql 4.1.3-beta: binary search bug as fixed.
158 // => fixed action=upgrade,
159 // => version check in PearDB also (as in ADODB)
161 // Revision 1.14 2004/07/03 08:19:40 rurban
162 // trap recursive redirects
164 // Revision 1.13 2004/03/12 15:48:08 rurban
165 // fixed explodePageList: wrong sortby argument order in UnfoldSubpages
166 // simplified lib/stdlib.php:explodePageList
168 // Revision 1.12 2004/02/22 23:20:33 rurban
169 // fixed DumpHtmlToDir,
170 // enhanced sortby handling in PageList
171 // new button_heading th style (enabled),
172 // added sortby and limit support to the db backends and plugins
173 // for paging support (<<prev, next>> links on long lists)
175 // Revision 1.11 2004/02/17 12:11:36 rurban
176 // 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, ...)
178 // Revision 1.10 2004/01/27 12:10:45 rurban
179 // fixed UnfoldSubpages and added docs.
180 // new arguments: pagename, maxpages
181 // some arguments are deprecated: sort (use sortby), pages (use maxpages)
182 // fixed sortby, added docs
184 // Revision 1.9 2004/01/26 09:18:00 rurban
185 // * changed stored pref representation as before.
186 // the array of objects is 1) bigger and 2)
187 // less portable. If we would import packed pref
188 // objects and the object definition was changed, PHP would fail.
189 // This doesn't happen with an simple array of non-default values.
190 // * use $prefs->retrieve and $prefs->store methods, where retrieve
191 // understands the interim format of array of objects also.
192 // * simplified $prefs->get() and fixed $prefs->set()
193 // * added $user->_userid and class '_WikiUser' portability functions
194 // * fixed $user object ->_level upgrading, mostly using sessions.
195 // this fixes yesterdays problems with loosing authorization level.
196 // * fixed WikiUserNew::checkPass to return the _level
197 // * fixed WikiUserNew::isSignedIn
198 // * added explodePageList to class PageList, support sortby arg
199 // * fixed UserPreferences for WikiUserNew
200 // * fixed WikiPlugin for empty defaults array
201 // * UnfoldSubpages: added pagename arg, renamed pages arg,
202 // removed sort arg, support sortby arg
204 // Revision 1.8 2004/01/25 10:52:16 rurban
205 // added sortby support to explodePageList() and UnfoldSubpages
206 // fixes [ 758044 ] Plugin UnfoldSubpages does not sort (includes fix)
208 // Revision 1.7 2003/02/21 04:12:06 dairiki
209 // Minor fixes for new cached markup.
211 // Revision 1.6 2003/02/11 09:34:34 rurban
212 // fix by Steven D. Brewer <sbrewer@bio.umass.edu> to respect the $pages argument
214 // Revision 1.5 2003/01/18 22:11:44 carstenklapp
216 // Reformatting & tabs to spaces;
217 // Added copyleft, getVersion, getDescription, rcs_id.
219 // Revision 1.4 2003/01/05 02:37:30 carstenklapp
220 // New: Implemented 'smalltitle' argument and date sorting fix from
221 // Cuthbert Cat's sf patch 655095. Added getVersion & getDescription;
224 // Revision 1.3 2003/01/04 22:46:07 carstenklapp
225 // Workaround: when page has no subpages avoid include of nonexistant pages.
229 // - line & word limit doesn't work if the included page itself
237 // c-hanging-comment-ender-p: nil
238 // indent-tabs-mode: nil