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 ($data['matches'][4][$data['key']] > 0) {
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 . ' . "';
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 // Read configuration
155 $configValue = getConfig($data['matches'][4][$data['key']]);
157 // Default replacer is the config value itself
158 $replacer = $configValue;
160 // Is there a call-back function provided?
161 if (!empty($data['callback'])) {
162 // Construct a new expression
163 $replacer = '{%pipe,' . $data['callback'] . ',' . $configValue . '%}';
166 // Replace the config entry
167 $code = replaceExpressionCode($data, $replacer);
169 // Return replaced code
173 // Expression call-back function for piping data through functions
174 function doExpressionPipe ($data) {
175 // We need callback and extra_func: callback is really the call-back function, extra_func is our value
176 $replacer = $data['extra_func'];
178 // Do we have a call-back? Should always be there!
179 if (!empty($data['callback'])) {
180 // Parse it through this function
181 $replacer = '{DQUOTE} . ' . $data['callback'] . "('" . $replacer . "') . {DQUOTE}";
184 // Replace the config entry
185 $code = replaceExpressionCode($data, $replacer);
187 // Return replaced code
191 // Expression call-back function for calling filters
192 function doExpressionFilter ($data) {
193 // Construct replacement
194 $replacer = "{DQUOTE} . runFilterChain('" . $data['matches'][4][$data['key']] . "') . {DQUOTE}";
196 // Run the filter and insert result
197 $code = replaceExpressionCode($data, $replacer);
199 // Return replaced code
203 // Expression call-back function for validator links
204 function doExpressionValidatorLinks ($data) {
205 // Default is nothing
208 // Get the code from data array for replacement/pipe-through
209 $code = $data['code'];
211 // Should we generally include validator links?
212 if ((isExtensionInstalled('validator')) && (getConfig('enable_validator') == 'Y') && (!in_array(getModule(), array('admin', 'login')))) {
213 // Load the validator template
214 $replacer = escapeQuotes(loadTemplate('validator_links', true));
218 $code = replaceExpressionCode($data, $replacer);
220 // Return the (maybe) replaced code
224 // Expression call-back for dynamic messages
225 function doExpressionMessage ($data) {
226 // Message string replacement depends on if message is masked
227 if (isMessageMasked($data['callback'])) {
228 // Message should be masked
229 $replacer = "{DQUOTE} . getMaskedMessage('" . $data['callback'] . "', '" . $data['extra_func'] . "') . {DQUOTE}";
232 $replacer = "{DQUOTE} . getMessage('" . $data['callback'] . "') . {DQUOTE}";
236 $code = replaceExpressionCode($data, $replacer);
238 // Return the (maybe) replaced code