-
- // Is the extension installed or code provided?
- // @TODO This whole if-block is very static
- if ($cmd == 'code') {
- // Code asked for
- $code = str_replace($matches[0][$key], "\" . getCode('" . $matches[4][$key] . "') . \"", $code);
- } 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[4][$key] . "\", " . $outputMode . ") . \"";
-
- // Replace it
- $code = str_replace($matches[0][$key], $replacer, $code);
- } elseif (substr($cmd, 0, 6) == 'server') {
- // Get data from $_SERVER by their respective functions
- $serverCmd = explode(',', $cmd);
- $serverCmd = $serverCmd[1];
-
- // This will make 'foo_bar' to detectFooBar()
- $functionName = "'detect' . implode('', array_map('ucfirst', explode('_', '" . $serverCmd . "')))";
-
- // Replace it
- $code = str_replace($matches[0][$key], "\" . call_user_func(" . $functionName . ") . \"", $code);
- } elseif (substr($cmd, 0, 4) == 'user') {
- // Extract user command
- $userCmdArray = explode(',', $cmd);
- $userCmd = $userCmdArray[1];
-
- // Use current userid by default
- $functionName = 'getMemberId()';
-
- // User-related data, so is there a userid?
- if (!empty($matches[4][$key])) {
- // Do we have a userid or $userid?
- if ($matches[4][$key] == '$userid') {
- // Use dynamic call
- $functionName = "getFetchedUserData('userid', \$userid, '" . $userCmd . "')";
- } elseif ($matches[4][$key] > 0) {
- // User data found
- $functionName = "getFetchedUserData('userid', " . $matches[4][$key] . ", " . $userCmd . "')";
- } // END - if
- } // END - if
-
- // Do we have another function to run (e.g. translations)
- if (isset($userCmdArray[2])) {
- // Surround the original function call with it
- $functionName = $userCmdArray[2] . '(' . $functionName . ')';
- } // END - if
-
- // Now replace the code
- $code = str_replace($matches[0][$key], "\" . " . $functionName . " . \"", $code);
- } elseif (substr($cmd, 0, 3) == 'ext') {
- // Get the extension command
- $extCmd = explode(',', $cmd);
- $extCmd = $extCmd[1];
-
- // Construct call-back function name
- $functionName = 'getExtension' . ucfirst(strtolower($extCmd));
-
- // Construct call of the function
- $replacer = "\" . call_user_func_array('" . $functionName . "', array('" . $matches[4][$key] . "', true)) . \"";
-
- // Replace it and insert parameter for GET request
- $code = str_replace($matches[0][$key], sprintf("&ext=%s&rev=\" . getConfig('CURR_SVN_REVISION') . \"", $replacer), $code);
+ $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);