// Compile {%cmd=some_value%} to get extension data
// Support cmd is:
// - version -> getExtensionVersion() call
- preg_match_all('/\{%(([a-zA-Z0-9-_,]+)=([^\}]+))%\}/', $code, $matches);
+ preg_match_all('/\{%(([a-zA-Z0-9-_,]+)(=([^\}]+)){0,1})*%\}/', $code, $matches);
//* DEBUG: */ print('<pre>'.print_r($matches, true).'</pre>');
// Default is from OUTPUT_HTML
// @TODO This whole if-block is very static
if ($cmd == 'code') {
// Code asked for
- $replacer = "\" . getCode('" . $matches[3][$key] . "') . \"";
+ $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[3][$key] . "\", " . $outputMode . ") . \"";
+ $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];
- // And continue with next entry
- continue;
- } elseif (substr($cmd, 0 , 3) == 'ext') {
+ // 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];
$functionName = 'getExtension' . ucfirst(strtolower($extCmd));
// Construct call of the function
- $replacer = "\" . call_user_func_array('" . $functionName . "', array('" . $matches[3][$key] . "', true)) . \"";
+ $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);
} else {
// Unknown command detected
debug_report_bug('Unknown command ' . $cmd . ' detected.');
}
-
- // Replace it and insert parameter for GET request
- $code = str_replace($matches[0][$key], sprintf("&%s=%s&rev=\" . getConfig('CURR_SVN_REVISION') . \"", $cmd, $replacer), $code);
} // END - foreach
} // END - if