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 * Copyright (c) 2009, 2010 by Mailer Developer Team *
22 * For more information visit: http://www.mxchange.org *
24 * This program is free software; you can redistribute it and/or modify *
25 * it under the terms of the GNU General Public License as published by *
26 * the Free Software Foundation; either version 2 of the License, or *
27 * (at your option) any later version. *
29 * This program is distributed in the hope that it will be useful, *
30 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
31 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
32 * GNU General Public License for more details. *
34 * You should have received a copy of the GNU General Public License *
35 * along with this program; if not, write to the Free Software *
36 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, *
38 ************************************************************************/
40 // Some security stuff...
41 if (!defined('__SECURITY')) {
45 // Private function to replace the code
46 function replaceExpressionCode ($data, $replacer) {
48 // @TODO is escapeQuotes() enougth for strings with single/double quotes?
49 return str_replace($data['matches'][0][$data['key']], $replacer, escapeQuotes($data['code']));
52 // Expression call-back function for getCode() calls
53 function doExpressionCode ($data) {
55 $code = str_replace($data['matches'][0][$data['key']], "{DQUOTE} . getCode('" . $data['matches'][4][$data['key']] . "') . {DQUOTE}", $data['code']);
57 // Return replaced code
61 // Expression call-back function for URLs
62 function doExpressionUrl ($data) {
63 // Do we have JS-mode?
64 if ($data['callback'] == 'js') $data['mode'] = 1;
67 $replacer = "{DQUOTE} . encodeUrl('" . $data['matches'][4][$data['key']] . "', " . $data['mode'] . ') . {DQUOTE}';
70 $code = replaceExpressionCode($data, $replacer);
72 // Return replaced code
76 // Expression call-back function for reading data from $_SERVER
77 function doExpressionServer ($data) {
78 // This will make 'foo_bar' to detectFooBar()
79 $functionName = "'detect' . implode('', array_map('ucfirst', explode('_', '" . $data['callback'] . "')))";
82 $replacer = '{DQUOTE} . call_user_func(' . $functionName . ') . {DQUOTE}';
85 $code = replaceExpressionCode($data, $replacer);
87 // Return replaced code
91 // Expression call-back function for fetching user data
92 function doExpressionUser ($data) {
93 // Use current userid by default
94 $functionName = 'getMemberId()';
96 // User-related data, so is there a userid?
97 if (!empty($data['matches'][4][$data['key']])) {
98 // Do we have a userid or $userid?
99 if ($data['matches'][4][$data['key']] == '$userid') {
101 $functionName = "getFetchedUserData('userid', \$userid, '" . $data['callback'] . "')";
102 } elseif (!empty($data['matches'][4][$data['key']])) {
104 $functionName = "getFetchedUserData('userid', " . $data['matches'][4][$data['key']] . ", '" . $data['callback'] . "')";
106 } elseif ((!empty($data['callback'])) && (isUserDataValid())) {
107 // "Call-back" alias column for current logged in user's data
108 $functionName = "getUserData('" . $data['callback'] . "')";
111 // Do we have another function to run (e.g. translations)
112 if (!empty($data['extra_func'])) {
113 // Surround the original function call with it
114 $functionName = $data['extra_func'] . '(' . $functionName . ')';
118 $replacer = '{DQUOTE} . ' . $functionName . ' . {DQUOTE}';
120 // Now replace the code
121 $code = replaceExpressionCode($data, $replacer);
123 // Return replaced code
127 // Expression call-back function for getting extension data
128 function doExpressionExt ($data) {
129 // Not installed is default
132 // Is the extension installed?
133 if (isExtensionInstalled($data['matches'][4][$data['key']])) {
134 // Construct call-back function name
135 $functionName = 'getExtension' . ucfirst(strtolower($data['callback']));
137 // Construct call of the function
138 $replacer = "{DQUOTE} . call_user_func_array('" . $functionName . "', array('" . $data['matches'][4][$data['key']] . "', true)) . {DQUOTE}";
142 $replacer = sprintf("&ext=%s&ver=%s&rev={DQUOTE} . getConfig('CURR_SVN_REVISION') . {DQUOTE}", $data['matches'][4][$data['key']], $replacer);
144 // Replace it and insert parameter for GET request
145 $code = replaceExpressionCode($data, $replacer);
147 // Return replaced code
151 // Expression call-back function for getting configuration data
152 // @TODO FILTER_COMPILE_CONFIG does not handle call-back functions so we handle it here again
153 function doExpressionConfig ($data) {
154 // Default replacer is the config value itself
155 $replacer = '{DQUOTE} . ' . $data['callback'] . '(getConfig(' . "'" . $data['matches'][4][$data['key']] . "'" . ')) . {DQUOTE}';
157 // Replace the config entry
158 $code = replaceExpressionCode($data, $replacer);
160 // Return replaced code
164 // Expression call-back function for piping data through functions
165 function doExpressionPipe ($data) {
166 // We need callback and extra_func: callback is really the call-back function, extra_func is our value
167 $replacer = $data['extra_func'];
169 // Is the extra_func empty and value set?
170 if ((empty($replacer)) && (isset($data['value']))) {
172 $replacer = $data['value'];
175 // Do we have a call-back? Should always be there!
176 if (!empty($data['callback'])) {
177 // Parse it through this function
178 $replacer = '{DQUOTE} . ' . $data['callback'] . "('" . $replacer . "') . {DQUOTE}";
181 // Replace the config entry
182 $code = replaceExpressionCode($data, $replacer);
184 // Return replaced code
188 // Expression call-back function for calling filters
189 function doExpressionFilter ($data) {
190 // Construct replacement
191 $replacer = "{DQUOTE} . runFilterChain('" . $data['matches'][4][$data['key']] . "') . {DQUOTE}";
193 // Run the filter and insert result
194 $code = replaceExpressionCode($data, $replacer);
196 // Return replaced code
200 // Expression call-back function for validator links
201 function doExpressionValidatorLinks ($data) {
202 // Default is nothing
205 // Get the code from data array for replacement/pipe-through
206 $code = $data['code'];
208 // Should we generally include validator links?
209 if ((isExtensionInstalled('validator')) && (getConfig('enable_validator') == 'Y') && (!in_array(getModule(), array('admin', 'login')))) {
210 // Load the validator template
211 $replacer = escapeQuotes(loadTemplate('validator_links', true));
215 $code = replaceExpressionCode($data, $replacer);
217 // Return the (maybe) replaced code
221 // Expression call-back for dynamic messages
222 function doExpressionMessage ($data) {
223 // Message string replacement depends on if message is masked
224 if ((isMessageMasked($data['callback'])) && ((!empty($data['extra_func'])) || ($data['extra_func'] == '0'))) {
225 // Message should be masked
226 $replacer = "{DQUOTE} . getMaskedMessage('" . $data['callback'] . "', '" . $data['extra_func'] . "') . {DQUOTE}";
229 $replacer = "{DQUOTE} . getMessage('" . $data['callback'] . "') . {DQUOTE}";
233 $code = replaceExpressionCode($data, $replacer);
235 // Return the (maybe) replaced code