]> git.mxchange.org Git - mailer.git/commitdiff
Expression call-back functions are now externalized in own PHP script, redirect had...
authorRoland Häder <roland@mxchange.org>
Fri, 4 Dec 2009 01:09:18 +0000 (01:09 +0000)
committerRoland Häder <roland@mxchange.org>
Fri, 4 Dec 2009 01:09:18 +0000 (01:09 +0000)
.gitattributes
DOCS/TODOs.txt
inc/expression-functions.php [new file with mode: 0644]
inc/filters.php
inc/functions.php
inc/mysql-connect.php

index f3c1ca3a6b286d1c896a51aac7aa3b49940da87e..ac51f2424bf0bdfe4fd546851889b11cf2698857 100644 (file)
@@ -113,6 +113,7 @@ inc/debug/client/.htaccess -text
 inc/debug/relay/.htaccess -text
 inc/debug/request_ -text
 inc/debug/server/.htaccess -text
+inc/expression-functions.php -text
 inc/extensions-functions.php -text
 inc/extensions/.htaccess -text
 inc/extensions/ext- -text
index 103df2caf8d6b59dc7b29559a2c996c6114d9ea6..f07be0ad56e44dd3bd34b537999f54b3c2cc4d85 100644 (file)
@@ -32,8 +32,6 @@
 ./inc/extensions/ext-yoomedia.php:55:// @TODO Only deprecated when 'network' is ready! setExtensionDeprecated('Y');
 ./inc/extensions-functions.php:379:// @TODO Change from ext_id to ext_name (not just even the variable! ;-) )
 ./inc/extensions-functions.php:492:            // @TODO Extension is loaded, what next?
-./inc/filters.php:472:                 // @TODO This whole switch-block is very static
-./inc/filters.php:543:                         case 'config': // @TODO FILTER_COMPILE_CONFIG does not handle call-back functions so we handle it here again
 ./inc/functions.php:1010:// @TODO $simple is deprecated
 ./inc/functions.php:1045:      // @TODO Do only use $content and deprecate $GLOBALS and $DATA in templates
 ./inc/functions.php:2521:// @TODO Please describe this function
diff --git a/inc/expression-functions.php b/inc/expression-functions.php
new file mode 100644 (file)
index 0000000..485e619
--- /dev/null
@@ -0,0 +1,165 @@
+<?php
+/************************************************************************
+ * Mailer v0.2.1-FINAL                                Start: 04/12/2009 *
+ * ===================                          Last change: 04/12/2009 *
+ *                                                                      *
+ * -------------------------------------------------------------------- *
+ * File              : expression-functions.php                         *
+ * -------------------------------------------------------------------- *
+ * Short description : Expression callback functions                    *
+ * -------------------------------------------------------------------- *
+ * Kurzbeschreibung  : Expression-Callback-Funktionen                   *
+ * -------------------------------------------------------------------- *
+ * $Revision::                                                        $ *
+ * $Date::                                                            $ *
+ * $Tag:: 0.2.1-FINAL                                                 $ *
+ * $Author::                                                          $ *
+ * Needs to be in all Files and every File needs "svn propset           *
+ * svn:keywords Date Revision" (autoprobset!) at least!!!!!!            *
+ * -------------------------------------------------------------------- *
+ * Copyright (c) 2003 - 2009 by Roland Haeder                           *
+ * For more information visit: http://www.mxchange.org                  *
+ *                                                                      *
+ * This program is free software; you can redistribute it and/or modify *
+ * it under the terms of the GNU General Public License as published by *
+ * the Free Software Foundation; either version 2 of the License, or    *
+ * (at your option) any later version.                                  *
+ *                                                                      *
+ * This program is distributed in the hope that it will be useful,      *
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of       *
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the        *
+ * GNU General Public License for more details.                         *
+ *                                                                      *
+ * You should have received a copy of the GNU General Public License    *
+ * along with this program; if not, write to the Free Software          *
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,               *
+ * MA  02110-1301  USA                                                  *
+ ************************************************************************/
+
+// Some security stuff...
+if (!defined('__SECURITY')) {
+       die();
+} // END - if
+
+// Expression call-back function for getCode() calls
+function doExpressionCode ($data) {
+       // Replace the code
+       $code = str_replace($data['matches'][0][$data['key']], "\" . getCode('" . $data['matches'][4][$data['key']] . "') . \"", $data['code']);
+
+       // Return replaced code
+       return $code;
+}
+
+// Expression call-back function for URLs
+function doExpressionUrl ($data) {
+       // Do we have JS-mode?
+       if ($data['callback'] == 'js') $data['mode'] = 1;
+
+       // Handle an URL here
+       $replacer = "\" . encodeUrl(\"" . $data['matches'][4][$data['key']] . "\", " . $data['mode'] . ") . \"";
+
+       // Replace it
+       $code = str_replace($data['matches'][0][$data['key']], $replacer, $data['code']);
+
+       // Return replaced code
+       return $code;
+}
+
+// Expression call-back function for reading data from $_SERVER
+function doExpressionServer ($data) {
+       // This will make 'foo_bar' to detectFooBar()
+       $functionName = "'detect' . implode('', array_map('ucfirst', explode('_', '" . $data['callback'] . "')))";
+
+       // Replace it
+       $code = str_replace($data['matches'][0][$data['key']], "\" . call_user_func(" . $functionName . ") . \"", $data['code']);
+
+       // Return replaced code
+       return $code;
+}
+
+// Expression call-back function for fetching user data
+function doExpressionUser ($data) {
+       // Use current userid by default
+       $functionName = 'getMemberId()';
+
+       // User-related data, so is there a userid?
+       if (!empty($data['matches'][4][$data['key']])) {
+               // Do we have a userid or $userid?
+               if ($data['matches'][4][$data['key']] == '$userid') {
+                       // Use dynamic call
+                       $functionName = "getFetchedUserData('userid', \$userid, '" . $data['callback'] . "')";
+               } elseif ($data['matches'][4][$data['key']] > 0) {
+                       // User data found
+                       $functionName = "getFetchedUserData('userid', " . $data['matches'][4][$data['key']] . ", " . $data['callback'] . "')";
+               }
+       } elseif ((!empty($data['callback'])) && (isUserDataValid())) {
+               // "Call-back" alias column for current logged in user's data
+               $functionName = "getUserData('" . $data['callback'] . "')";
+       }
+
+       // Do we have another function to run (e.g. translations)
+       if (!empty($extraFunction)) {
+               // Surround the original function call with it
+               $functionName = $extraFunction . '(' . $functionName . ')';
+       } // END - if
+
+       // Now replace the code
+       $code = str_replace($data['matches'][0][$data['key']], "\" . " . $functionName . " . \"", $data['code']);
+
+       // Return replaced code
+       return $code;
+}
+
+// Expression call-back function for getting extension data
+function doExpressionExt ($data) {
+       // Not installed is default
+       $replacer = 'false';
+
+       // Is the extension installed?
+       if (isExtensionInstalled($data['matches'][4][$data['key']])) {
+               // Construct call-back function name
+               $functionName = 'getExtension' . ucfirst(strtolower($data['callback']));
+
+               // Construct call of the function
+               $replacer = "\" . call_user_func_array('" . $functionName . "', array('" . $data['matches'][4][$data['key']] . "', true)) . \"";
+       } // END - if
+
+       // Replace it and insert parameter for GET request
+       $code = str_replace($data['matches'][0][$data['key']], sprintf("&amp;ext=%s&amp;ver=%s&amp;rev=\" . getConfig('CURR_SVN_REVISION') . \"", $data['matches'][4][$data['key']], $replacer), $data['code']);
+
+       // Return replaced code
+       return $code;
+}
+
+// Expression call-back function for getting configuration data
+function doExpressionConfig ($data) {
+       // Read configuration
+       $configValue = getConfig($data['matches'][4][$data['key']]);
+
+       // Do we have a call-back?
+       if (!empty($data['callback'])) {
+               // Parse it through this function
+               $configValue = call_user_func_array($data['callback'], array($configValue));
+       } // END - if
+
+       // Replace the config entry
+       $code = str_replace($data['matches'][0][$data['key']], $configValue, $data['code']);
+
+       // Return replaced code
+       return $code;
+}
+
+// Expression call-back function for calling filters
+function doExpressionFilter ($data) {
+       // Construct replacement
+       $replacer = "\" . runFilterChain('" . $data['matches'][4][$data['key']] . "') . \"";
+
+       // Run the filter and insert result
+       $code = str_replace($data['matches'][0][$data['key']], $replacer, $data['code']);
+
+       // Return replaced code
+       return $code;
+}
+
+// [EOF]
+?>
index 35ff120eb7067af5178da838051dafbb9822e897..fd55e5785abbc2c10312add003fcb4cde87837d5 100644 (file)
@@ -445,7 +445,7 @@ function FILTER_COMPILE_CONFIG ($code, $compiled = false) {
 
 // Filter for compiling expression code
 function FILTER_COMPILE_EXPRESSION_CODE ($code) {
-       // Compile {%cmd=some_value%} to get expression code snippets
+       // Compile {%cmd,callback,extraFunction=some_value%} to get expression code snippets
        // See switch() command below for supported commands
        preg_match_all('/\{%(([a-zA-Z0-9-_,]+)(=([^\}]+)){0,1})*%\}/', $code, $matches);
        //* DEBUG: */ print('<pre>'.print_r($matches, true).'</pre>');
@@ -465,108 +465,29 @@ function FILTER_COMPILE_EXPRESSION_CODE ($code) {
                        // Extract command and call-back
                        $cmdArray = explode(',', $cmd);
                        $cmd = $cmdArray[0];
-                       if (isset($cmdArray[1])) $callback = $cmdArray[1];
+                       if (isset($cmdArray[1])) $callback      = $cmdArray[1];
                        if (isset($cmdArray[2])) $extraFunction = $cmdArray[2];
 
-                       // Is the extension installed or code provided?
-                       // @TODO This whole switch-block is very static
-                       switch ($cmd) {
-                               case 'code': // Code asked for
-                                       $code = str_replace($matches[0][$key], "\" . getCode('" . $matches[4][$key] . "') . \"", $code);
-                                       break;
-
-                               case '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);
-                                       break;
-
-                               case 'server':
-                                       // This will make 'foo_bar' to detectFooBar()
-                                       $functionName = "'detect' . implode('', array_map('ucfirst', explode('_', '" . $callback . "')))";
-
-                                       // Replace it
-                                       $code = str_replace($matches[0][$key], "\" . call_user_func(" . $functionName . ") . \"", $code);
-                                       break;
-
-                               case 'user':
-                                       // 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, '" . $callback . "')";
-                                               } elseif ($matches[4][$key] > 0) {
-                                                       // User data found
-                                                       $functionName = "getFetchedUserData('userid', " . $matches[4][$key] . ", " . $callback . "')";
-                                               } // END - if
-                                       } elseif ((!empty($callback)) && (isUserDataValid())) {
-                                               // "Call-back" alias column for current logged in user's data
-                                               $functionName = "getUserData('" . $callback . "')";
-                                       }
-
-                                       // Do we have another function to run (e.g. translations)
-                                       if (!empty($extraFunction)) {
-                                               // Surround the original function call with it
-                                               $functionName = $extraFunction . '(' . $functionName . ')';
-                                       } // END - if
-
-                                       // Now replace the code
-                                       $code = str_replace($matches[0][$key], "\" . " . $functionName . " . \"", $code);
-                                       break;
-
-                               case 'ext':
-                                       // Not installed is default
-                                       $replacer = 'false';
-
-                                       // Is the extension installed?
-                                       if (isExtensionInstalled($matches[4][$key])) {
-                                               // Construct call-back function name
-                                               $functionName = 'getExtension' . ucfirst(strtolower($callback));
-
-                                               // Construct call of the function
-                                               $replacer = "\" . call_user_func_array('" . $functionName . "', array('" . $matches[4][$key] . "', true)) . \"";
-                                       } // END - if
-
-                                       // Replace it and insert parameter for GET request
-                                       $code = str_replace($matches[0][$key], sprintf("&amp;ext=%s&amp;ver=%s&amp;rev=\" . getConfig('CURR_SVN_REVISION') . \"", $matches[4][$key], $replacer), $code);
-                                       break;
-
-                               case 'config': // @TODO FILTER_COMPILE_CONFIG does not handle call-back functions so we handle it here again
-                                       // Read configuration
-                                       $configValue = getConfig($matches[4][$key]);
-
-                                       // Do we have a call-back?
-                                       if (!empty($callback)) {
-                                               // Parse it through this function
-                                               $configValue = call_user_func_array($callback, array($configValue));
-                                       } // END - if
-
-                                       // Replace the config entry
-                                       $code = str_replace($matches[0][$key], $configValue, $code);
-                                       break;
-
-                               case 'filter':
-                                       // Construct replacement
-                                       $replacer = "\" . runFilterChain('" . $matches[4][$key] . "') . \"";
-
-                                       // Run the filter and insert result
-                                       $code = str_replace($matches[0][$key], $replacer, $code);
-                                       break;
-
-                               default:
-                                       // Unsupported command detected
-                                       debug_report_bug('Command=' . $cmd . ', callback=' . $callback . ', extra=' . $extraFunction . ' is unsupported.');
-                                       break;
-                       } // END - switch
+                       // 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
+                               );
+
+                               // Call it
+                               $code = call_user_func($commandFunction, $data);
+                       } else {
+                               // Unsupported command detected
+                               debug_report_bug('Command=' . $cmd . ', callback=' . $callback . ', extra=' . $extraFunction . ' is unsupported.');
+                       }
                } // END - foreach
        } // END - if
 
index 515455d3dad516ed923bc2ccbe50499e55d62297..3b95accab04348cf298294fe1291cbf7f18d402b 100644 (file)
@@ -936,7 +936,7 @@ function redirectToUrl ($URL) {
        } // END - if
 
        // Three different ways to debug...
-       /* DEBUG: */ debug_report_bug(sprintf("%s[%s:] URL=%s", __FUNCTION__, __LINE__, $URL));
+       //* DEBUG: */ debug_report_bug(sprintf("%s[%s:] URL=%s", __FUNCTION__, __LINE__, $URL));
        //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'URL=' . $URL);
        //* DEBUG: */ die($URL);
 
index 92d7936266ab7473ef9ce32ce255d1bb8bfbfd71..0dd8936b1e9bd8815c401b7d267fa7d9fd435c8b 100644 (file)
@@ -42,7 +42,7 @@ if (!defined('__SECURITY')) {
 } // END - if
 
 // Load more function libraries or includes
-foreach (array('functions', 'request-functions', 'session-functions', 'code-functions', 'language-functions', 'sql-functions', 'filter-functions', 'filters', 'mysql-manager', 'extensions-functions', 'handler') as $lib) {
+foreach (array('functions', 'request-functions', 'session-functions', 'code-functions', 'language-functions', 'sql-functions', 'expression-functions', 'filter-functions', 'filters', 'mysql-manager', 'extensions-functions', 'handler') as $lib) {
        // Load special functions
        loadIncludeOnce('inc/' . $lib . '.php');
 } // END - foreach