2 /************************************************************************
3 * Mailer v0.2.1-FINAL Start: 04/12/2009 *
4 * =================== Last change: 04/12/2009 *
6 * -------------------------------------------------------------------- *
7 * File : expression-functions.php *
8 * -------------------------------------------------------------------- *
9 * Short description : Expression callback functions *
10 * -------------------------------------------------------------------- *
11 * Kurzbeschreibung : Expression-Callback-Funktionen *
12 * -------------------------------------------------------------------- *
15 * $Tag:: 0.2.1-FINAL $ *
17 * Needs to be in all Files and every File needs "svn propset *
18 * svn:keywords Date Revision" (autoprobset!) at least!!!!!! *
19 * -------------------------------------------------------------------- *
20 * Copyright (c) 2003 - 2009 by Roland Haeder *
21 * For more information visit: http://www.mxchange.org *
23 * This program is free software; you can redistribute it and/or modify *
24 * it under the terms of the GNU General Public License as published by *
25 * the Free Software Foundation; either version 2 of the License, or *
26 * (at your option) any later version. *
28 * This program is distributed in the hope that it will be useful, *
29 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
30 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
31 * GNU General Public License for more details. *
33 * You should have received a copy of the GNU General Public License *
34 * along with this program; if not, write to the Free Software *
35 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, *
37 ************************************************************************/
39 // Some security stuff...
40 if (!defined('__SECURITY')) {
44 // Expression call-back function for getCode() calls
45 function doExpressionCode ($data) {
47 $code = str_replace($data['matches'][0][$data['key']], "\" . getCode('" . $data['matches'][4][$data['key']] . "') . \"", $data['code']);
49 // Return replaced code
53 // Expression call-back function for URLs
54 function doExpressionUrl ($data) {
55 // Do we have JS-mode?
56 if ($data['callback'] == 'js') $data['mode'] = 1;
59 $replacer = "\" . encodeUrl(\"" . $data['matches'][4][$data['key']] . "\", " . $data['mode'] . ") . \"";
62 $code = str_replace($data['matches'][0][$data['key']], $replacer, $data['code']);
64 // Return replaced code
68 // Expression call-back function for reading data from $_SERVER
69 function doExpressionServer ($data) {
70 // This will make 'foo_bar' to detectFooBar()
71 $functionName = "'detect' . implode('', array_map('ucfirst', explode('_', '" . $data['callback'] . "')))";
74 $code = str_replace($data['matches'][0][$data['key']], "\" . call_user_func(" . $functionName . ") . \"", $data['code']);
76 // Return replaced code
80 // Expression call-back function for fetching user data
81 function doExpressionUser ($data) {
82 // Use current userid by default
83 $functionName = 'getMemberId()';
85 // User-related data, so is there a userid?
86 if (!empty($data['matches'][4][$data['key']])) {
87 // Do we have a userid or $userid?
88 if ($data['matches'][4][$data['key']] == '$userid') {
90 $functionName = "getFetchedUserData('userid', \$userid, '" . $data['callback'] . "')";
91 } elseif ($data['matches'][4][$data['key']] > 0) {
93 $functionName = "getFetchedUserData('userid', " . $data['matches'][4][$data['key']] . ", " . $data['callback'] . "')";
95 } elseif ((!empty($data['callback'])) && (isUserDataValid())) {
96 // "Call-back" alias column for current logged in user's data
97 $functionName = "getUserData('" . $data['callback'] . "')";
100 // Do we have another function to run (e.g. translations)
101 if (!empty($data['extra_func'])) {
102 // Surround the original function call with it
103 $functionName = $data['extra_func'] . '(' . $functionName . ')';
106 // Now replace the code
107 $code = str_replace($data['matches'][0][$data['key']], "\" . " . $functionName . " . \"", $data['code']);
109 // Return replaced code
113 // Expression call-back function for getting extension data
114 function doExpressionExt ($data) {
115 // Not installed is default
118 // Is the extension installed?
119 if (isExtensionInstalled($data['matches'][4][$data['key']])) {
120 // Construct call-back function name
121 $functionName = 'getExtension' . ucfirst(strtolower($data['callback']));
123 // Construct call of the function
124 $replacer = "\" . call_user_func_array('" . $functionName . "', array('" . $data['matches'][4][$data['key']] . "', true)) . \"";
127 // Replace it and insert parameter for GET request
128 $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']);
130 // Return replaced code
134 // Expression call-back function for getting configuration data
135 // @TODO FILTER_COMPILE_CONFIG does not handle call-back functions so we handle it here again
136 function doExpressionConfig ($data) {
137 // Read configuration
138 $configValue = getConfig($data['matches'][4][$data['key']]);
140 // Do we have a call-back?
141 if (!empty($data['callback'])) {
142 // Parse it through this function
143 $configValue = call_user_func_array($data['callback'], array($configValue));
146 // Replace the config entry
147 $code = str_replace($data['matches'][0][$data['key']], $configValue, $data['code']);
149 // Return replaced code
153 // Expression call-back function for calling filters
154 function doExpressionFilter ($data) {
155 // Construct replacement
156 $replacer = "\" . runFilterChain('" . $data['matches'][4][$data['key']] . "') . \"";
158 // Run the filter and insert result
159 $code = str_replace($data['matches'][0][$data['key']], $replacer, $data['code']);
161 // Return replaced code