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