]> git.mxchange.org Git - mailer.git/blobdiff - inc/filters.php
Rewrite of all mail templates with user data to new 'tag-like' functionality
[mailer.git] / inc / filters.php
index 89af47dbfd6a1edc52f03a0a3af8c7c047ee8f83..1b20ecccf7d5079f4bea58e06526df752d1e083b 100644 (file)
@@ -448,7 +448,7 @@ function FILTER_COMPILE_EXTENSION ($code) {
        // 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
@@ -465,20 +465,55 @@ function FILTER_COMPILE_EXTENSION ($code) {
                        // @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];
@@ -487,14 +522,14 @@ function FILTER_COMPILE_EXTENSION ($code) {
                                $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("&amp;ext=%s&amp;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("&amp;%s=%s&amp;rev=\" . getConfig('CURR_SVN_REVISION') . \"", $cmd, $replacer), $code);
                } // END - foreach
        } // END - if