+<?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("&ext=%s&ver=%s&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]
+?>