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 // Expression call-back function for getCode() calls
46 function doExpressionCode ($data) {
48 $code = str_replace($data['matches'][0][$data['key']], "\" . getCode('" . $data['matches'][4][$data['key']] . "') . \"", $data['code']);
50 // Return replaced code
54 // Expression call-back function for URLs
55 function doExpressionUrl ($data) {
56 // Do we have JS-mode?
57 if ($data['callback'] == 'js') $data['mode'] = 1;
60 $replacer = "\" . encodeUrl(\"" . $data['matches'][4][$data['key']] . "\", " . $data['mode'] . ") . \"";
63 $code = str_replace($data['matches'][0][$data['key']], $replacer, $data['code']);
65 // Return replaced code
69 // Expression call-back function for reading data from $_SERVER
70 function doExpressionServer ($data) {
71 // This will make 'foo_bar' to detectFooBar()
72 $functionName = "'detect' . implode('', array_map('ucfirst', explode('_', '" . $data['callback'] . "')))";
75 $code = str_replace($data['matches'][0][$data['key']], "\" . call_user_func(" . $functionName . ") . \"", $data['code']);
77 // Return replaced code
81 // Expression call-back function for fetching user data
82 function doExpressionUser ($data) {
83 // Use current userid by default
84 $functionName = 'getMemberId()';
86 // User-related data, so is there a userid?
87 if (!empty($data['matches'][4][$data['key']])) {
88 // Do we have a userid or $userid?
89 if ($data['matches'][4][$data['key']] == '$userid') {
91 $functionName = "getFetchedUserData('userid', \$userid, '" . $data['callback'] . "')";
92 } elseif ($data['matches'][4][$data['key']] > 0) {
94 $functionName = "getFetchedUserData('userid', " . $data['matches'][4][$data['key']] . ", " . $data['callback'] . "')";
96 } elseif ((!empty($data['callback'])) && (isUserDataValid())) {
97 // "Call-back" alias column for current logged in user's data
98 $functionName = "getUserData('" . $data['callback'] . "')";
101 // Do we have another function to run (e.g. translations)
102 if (!empty($data['extra_func'])) {
103 // Surround the original function call with it
104 $functionName = $data['extra_func'] . '(' . $functionName . ')';
107 // Now replace the code
108 $code = str_replace($data['matches'][0][$data['key']], "\" . " . $functionName . " . \"", $data['code']);
110 // Return replaced code
114 // Expression call-back function for getting extension data
115 function doExpressionExt ($data) {
116 // Not installed is default
119 // Is the extension installed?
120 if (isExtensionInstalled($data['matches'][4][$data['key']])) {
121 // Construct call-back function name
122 $functionName = 'getExtension' . ucfirst(strtolower($data['callback']));
124 // Construct call of the function
125 $replacer = "\" . call_user_func_array('" . $functionName . "', array('" . $data['matches'][4][$data['key']] . "', true)) . \"";
128 // Replace it and insert parameter for GET request
129 $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']);
131 // Return replaced code
135 // Expression call-back function for getting configuration data
136 // @TODO FILTER_COMPILE_CONFIG does not handle call-back functions so we handle it here again
137 function doExpressionConfig ($data) {
138 // Read configuration
139 $configValue = getConfig($data['matches'][4][$data['key']]);
141 // Do we have a call-back?
142 if (!empty($data['callback'])) {
143 // Parse it through this function
144 $configValue = call_user_func_array($data['callback'], array($configValue));
147 // Replace the config entry
148 $code = str_replace($data['matches'][0][$data['key']], $configValue, $data['code']);
150 // Return replaced code
154 // Expression call-back function for calling filters
155 function doExpressionFilter ($data) {
156 // Construct replacement
157 $replacer = "\" . runFilterChain('" . $data['matches'][4][$data['key']] . "') . \"";
159 // Run the filter and insert result
160 $code = str_replace($data['matches'][0][$data['key']], $replacer, $data['code']);
162 // Return replaced code
166 // Expression call-back function for validator links
167 function doExpressionValidatorLinks ($data) {
168 // Default is nothing
171 // Get the code from data array for replacement/pipe-through
172 $code = $data['code'];
174 // Should we generally include validator links?
175 if ((isExtensionInstalled('validator')) && (getConfig('enable_validator') == 'Y') && (!in_array(getModule(), array('admin', 'login')))) {
176 // Load the validator template
177 $replacer = escapeQuotes(loadTemplate('validator_links', true));
181 $code = str_replace($data['matches'][0][$data['key']], $replacer, $code);
183 // Return the (maybe) replaced code