{$var}', '/\\{(\\(\\w+\\b.*?\\))\\}/e', "MarkupExpression(\$pagename, PSS('$1'))"); SDVA($MarkupExpr, array( 'substr' => 'call_user_func_array("substr", $args)', 'strlen' => 'strlen($args[0])', 'ftime' => 'ME_ftime(@$args[0], @$args[1], $argp)', 'rand' => '($args) ? rand($args[0], $args[1]) : rand()', 'ucfirst' => 'ucfirst($args[0])', 'ucwords' => 'ucwords($args[0])', 'tolower' => 'strtolower($args[0])', 'toupper' => 'strtoupper($args[0])', 'asspaced' => '$GLOBALS["AsSpacedFunction"]($args[0])', 'pagename' => 'MakePageName($pagename, preg_replace($rpat, $rrep, $params))', )); function MarkupExpression($pagename, $expr) { global $KeepToken, $KPV, $MarkupExpr; $rpat = "/$KeepToken(\\d+P)$KeepToken/e"; $rrep = '$KPV[\'$1\']'; $expr = preg_replace('/([\'"])(.*?)\\1/e', "Keep(PSS('$2'),'P')", $expr); $expr = preg_replace('/\\(\\W/e', "Keep(PSS('$2'),'P')", $expr); while (preg_match('/\\((\\w+)(\\s[^()]*)?\\)/', $expr, $match)) { list($repl, $func, $params) = $match; $code = @$MarkupExpr[$func]; ## if not a valid function, save this string as-is and exit if (!$code) break; ## if the code uses '$params', we just evaluate directly if (strpos($code, '$params') !== false) { $out = eval("return ({$code});"); if ($expr == $repl) { $expr = $out; break; } $expr = str_replace($repl, $out, $expr); continue; } ## otherwise, we parse arguments into $args before evaluating $argp = ParseArgs($params); $x = $argp['#']; $args = array(); while ($x) { list($k, $v) = array_splice($x, 0, 2); if ($k == '' || $k == '+' || $k == '-') $args[] = $k.preg_replace($rpat, $rrep, $v); } ## fix any quoted arguments foreach ($argp as $k => $v) if (!is_array($v)) $argp[$k] = preg_replace($rpat, $rrep, $v); $out = eval("return ({$code});"); if ($expr == $repl) { $expr = $out; break; } $expr = str_replace($repl, Keep($out, 'P'), $expr); } return preg_replace($rpat, $rrep, $expr); } ## ME_ftime handles {(ftime ...)} expressions. ## function ME_ftime($arg0 = '', $arg1 = '', $argp = NULL) { global $TimeFmt, $Now, $FTimeFmt; if (@$argp['fmt']) $fmt = $argp['fmt']; else if (strpos($arg0, '%') !== false) { $fmt = $arg0; $arg0 = $arg1; } else if (strpos($arg1, '%') !== false) $fmt = $arg1; ## determine the timestamp if (isset($argp['when'])) list($time, $x) = DRange($argp['when']); else if ($arg0 > '') list($time, $x) = DRange($arg0); else $time = $Now; if (@$fmt == '') { SDV($FTimeFmt, $TimeFmt); $fmt = $FTimeFmt; } ## make sure we have %F available for ISO dates $fmt = str_replace(array('%F', '%s'), array('%Y-%m-%d', $time), $fmt); return strftime($fmt, $time); }