From: Geoffrey T. D. <da...@us...> - 2001-12-17 16:40:46
|
Update of /cvsroot/phpwiki/phpwiki/lib/plugin In directory usw-pr-cvs1:/tmp/cvs-serv30623/lib/plugin Modified Files: IncludePage.php Log Message: Added plugin argument 'section', which allows one to include a particular named section of a file. Index: IncludePage.php =================================================================== RCS file: /cvsroot/phpwiki/phpwiki/lib/plugin/IncludePage.php,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -r1.4 -r1.5 *** IncludePage.php 2001/12/16 18:33:25 1.4 --- IncludePage.php 2001/12/17 16:40:43 1.5 *************** *** 21,25 **** 'quiet' => false, // if set, inclusion appears as normal content 'words' => false, // maximum number of words to include ! 'lines' => false // maximum number of lines to include ); } --- 21,26 ---- 'quiet' => false, // if set, inclusion appears as normal content 'words' => false, // maximum number of words to include ! 'lines' => false, // maximum number of lines to include ! 'section'=> false // include a named section ); } *************** *** 42,45 **** --- 43,63 ---- } + function extractSection ($section, $content) { + $qsection = preg_replace('/\s+/', '\s+', preg_quote($section, '/')); + + if (preg_match("/ ^(!{1,})\\s*$qsection" // section header + . " \\s*$\\n?" // possible blank lines + . " ( (?: ^.*\\n? )*? )" // some lines + . " (?= ^\\1 | \\Z)/xm", // sec header (same or higher level) (or EOF) + implode("\n", $content), + $match)) { + // Strip trailing blanks lines and ---- <hr>s + $text = preg_replace("/\\s*^-{4,}\\s*$/m", "", $match[2]); + return explode("\n", $text); + } + return array(sprintf(_("<%s: no such section>"), $section)); + } + + function error($msg) { // FIXME: better error reporting? *************** *** 76,80 **** $c = $r->getContent(); ! if ($lines) $c = array_slice($c, 0, $lines); --- 94,100 ---- $c = $r->getContent(); ! ! if ($section) ! $c = $this->extractSection($section, $c); if ($lines) $c = array_slice($c, 0, $lines); |