-
- // Is the extension installed or code provided?
- // @TODO This whole if-block is very static
- if ($cmd == 'code') {
- // Code asked for
- $replacer = "\" . getCode('" . $matches[3][$key] . "') . \"";
- } elseif (substr($cmd, 0, 3) == 'url') {
- // Do we have JS-mode?
- if (substr($cmd, -2, 2) == 'js') $outputMode = 1;
-
- // Handle an URL here
- $replacer = "\" . encodeUrl(\"" . $matches[3][$key] . "\", " . $outputMode . ") . \"";
-
- // Replace it
- $code = str_replace($matches[0][$key], $replacer, $code);
-
- // And continue with next entry
- continue;
+ $callback = '';
+ $extraFunction = '';
+
+ // Extract command and call-back
+ $cmdArray = explode(',', $cmd);
+ $cmd = $cmdArray[0];
+ if (isset($cmdArray[1])) $callback = $cmdArray[1];
+ if (isset($cmdArray[2])) $extraFunction = $cmdArray[2];
+
+ // Construct call-back function name for the command
+ $commandFunction = 'doExpression' . ucfirst(strtolower($cmd));
+
+ // Is this function there?
+ if (function_exists($commandFunction)) {
+ // Prepare $matches, $key, $outputMode, etc.
+ $data = array(
+ 'matches' => $matches,
+ 'key' => $key,
+ 'mode' => $outputMode,
+ 'code' => $code,
+ 'callback' => $callback,
+ 'extra_func' => $extraFunction
+ );
+
+ // Call it
+ $code = call_user_func($commandFunction, $data);