[pmwiki-users] Include specific lines of text on a page
Hans
design5 at softflow.co.uk
Sat Jan 19 13:54:03 CST 2008
Saturday, January 19, 2008, 7:37:40 PM, Vince Administration wrote:
> Hans, here is a start. Your approach extracted a row containing a
> given string. The syntax below
>>> (:grep "regex" wikifilename/pattern . :)
> is meant to say
> :grep means extract
> "regex' means each line satisfying a criterion, so instead of just
> containing a given string, you could have
> wild cards, etc, like in php's search replace functions. The :pipe
> etc would just concatenate those.
Thanks! I also had an email from Peter where he explained his ideas to
me further. i then concocted another markup expression definition for
{(grep 'PATTERN' PAGENAME )}, where PAGENAME can take wiki wildcard
patterns. Here it is:
# {(grep TEXTPATTERN PAGENAME)}
$MarkupExpr['grep'] = 'Grep($pagename, @$args[0], @$args[1])';
function Grep($pagename, $expr, $src) {
if ($expr=='' || $src=='') return '';
$grp = PageVar($pagename, '$Group');
//check for group.name pattern
if (strstr($src,'.'))
$pat = $src;
else $pat = $grp.".".$src;
//make preg pattern from wildcard pattern
$prpat = GlobToPCRE(FixGlob($pat));
//make list from preg name pattern
$sourcelist = ListPages("/$prpat[0]/");
$newrows = array();
//process each source page in turn
foreach($sourcelist as $source) {
if ($source==$pagename) return '';
$page = RetrieveAuthPage($source, 'read', true);
$text = $page['text'];
$textrows = explode("\n",$text);
foreach ($textrows as $row) {
if (preg_match("/$expr/", $row)) {
$newrows[] = $row;
}
}
}
return implode("\n", $newrows);
}
The preg_match pattern in
if (preg_match("/$expr/", $row)) {
$newrows[] = $row;
}
is still not working quite well.
any suggestions for improvement will be much appreciated.
~Hans
More information about the pmwiki-users
mailing list