[pmwiki-users] Conditional extensions
Patrick R. Michaud
pmichaud at pobox.com
Thu Apr 21 08:23:38 CDT 2005
On Wed, Apr 20, 2005 at 10:54:22PM +0200, Dominique Faure wrote:
> Sorry to ask you to update the recipe script again, but I had time to
> seriously update it and give it an infix notation, with the resulting
> SideBar code as example:
Wow, what a clever (and impressive) implementation!
Perhaps it can be shortened a bit...?
$Conditions['expr'] = "ExprCondition(\$pagename, \$condparm)";
function ExprCondition($pagename, $condparm) {
$condparm = str_replace('&&', '&&', $condparm);
$delims = '/(\\s*(and|or|xor|&&|\\|\\||!|\\(|\\))\\s*)/i';
$terms = preg_split($delims, $condparm, -1,
PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_NO_EMPTY);
foreach($terms as $i => $t)
if(!preg_match($delims, $t))
$terms[$i] = CondText($pagename, "if $t", 'TRUE') ? '1' : '0';
return @eval('return (' . implode(' ', $terms) . ');');
}
Pm
More information about the pmwiki-users
mailing list