function CondExpr($pagename, $condname, $condparm) { global $CondExprOps; SDV($CondExprOps, 'and|x?or|&&|\\|\\||[!()]'); if ($condname == '(' || $condname == '[') $condparm = preg_replace('/[\\]\\)]\\s*$/', '', $condparm); $condparm = str_replace('&&', '&&', $condparm); $terms = preg_split("/(?<!\\S)($CondExprOps)(?!\\S)/i", $condparm, -1, PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_NO_EMPTY); foreach($terms as $i => $t) { $t = trim($t); if (preg_match("/^($CondExprOps)$/i", $t)) continue; if ($t) $terms[$i] = CondText($pagename, "if $t", 'TRUE') ? '1' : '0'; } return @eval('return(' . implode(' ', $terms) . ');'); }
function PmFormTemplateRequires($pagename, &$text, $args = NULL) { if (!$args) { $args = array(); } $errors = array(); if (!PmFormTemplateDirective($text, "requires?", $match)) { return; } foreach ($match as $m) { $text = str_replace($m[0], '', $text); if ($args) { $m[2] = FmtTemplateVars($m[2], $args); } $opt = ParseArgs($m[2]); $opt[''] = (array) $opt['']; $name = isset($opt['name']) ? $opt['name'] : array_shift($opt['']); $match = '?*'; if (isset($opt['match'])) { $match = $opt['match']; } else { if ($opt['']) { $match = array_shift($opt['']); } } list($inclp, $exclp) = GlobToPCRE($match); foreach (preg_split('/[\\s,]+/', $name, -1, PREG_SPLIT_NO_EMPTY) as $n) { $n = preg_replace('/^\\$:/', 'ptv_', $n); if ($match == '' && $args[$n] != '' || $inclp && !preg_match("/{$inclp}/is", $args[$n]) || $exclp && preg_match("/{$exclp}/is", $args[$n])) { $errors[] = isset($opt['errmsg']) ? $opt['errmsg'] : "\$[Invalid parameter] {$n}"; } } if (@$opt['if'] && !CondText($pagename, 'if ' . $opt['if'], 'hello')) { $errors[] = isset($opt['errmsg']) ? $opt['errmsg'] : "\$[Required condition failed]"; } } return $errors; }