TODO updated, my website is now approved
[mailer.git] / inc / expression-functions.php
1 <?php
2 /************************************************************************
3  * Mailer v0.2.1-FINAL                                Start: 04/12/2009 *
4  * ===================                          Last change: 04/12/2009 *
5  *                                                                      *
6  * -------------------------------------------------------------------- *
7  * File              : expression-functions.php                         *
8  * -------------------------------------------------------------------- *
9  * Short description : Expression callback functions                    *
10  * -------------------------------------------------------------------- *
11  * Kurzbeschreibung  : Expression-Callback-Funktionen                   *
12  * -------------------------------------------------------------------- *
13  * $Revision::                                                        $ *
14  * $Date::                                                            $ *
15  * $Tag:: 0.2.1-FINAL                                                 $ *
16  * $Author::                                                          $ *
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                  *
22  *                                                                      *
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.                                  *
27  *                                                                      *
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.                         *
32  *                                                                      *
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,               *
36  * MA  02110-1301  USA                                                  *
37  ************************************************************************/
38
39 // Some security stuff...
40 if (!defined('__SECURITY')) {
41         die();
42 } // END - if
43
44 // Expression call-back function for getCode() calls
45 function doExpressionCode ($data) {
46         // Replace the code
47         $code = str_replace($data['matches'][0][$data['key']], "\" . getCode('" . $data['matches'][4][$data['key']] . "') . \"", $data['code']);
48
49         // Return replaced code
50         return $code;
51 }
52
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;
57
58         // Handle an URL here
59         $replacer = "\" . encodeUrl(\"" . $data['matches'][4][$data['key']] . "\", " . $data['mode'] . ") . \"";
60
61         // Replace it
62         $code = str_replace($data['matches'][0][$data['key']], $replacer, $data['code']);
63
64         // Return replaced code
65         return $code;
66 }
67
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'] . "')))";
72
73         // Replace it
74         $code = str_replace($data['matches'][0][$data['key']], "\" . call_user_func(" . $functionName . ") . \"", $data['code']);
75
76         // Return replaced code
77         return $code;
78 }
79
80 // Expression call-back function for fetching user data
81 function doExpressionUser ($data) {
82         // Use current userid by default
83         $functionName = 'getMemberId()';
84
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') {
89                         // Use dynamic call
90                         $functionName = "getFetchedUserData('userid', \$userid, '" . $data['callback'] . "')";
91                 } elseif ($data['matches'][4][$data['key']] > 0) {
92                         // User data found
93                         $functionName = "getFetchedUserData('userid', " . $data['matches'][4][$data['key']] . ", " . $data['callback'] . "')";
94                 }
95         } elseif ((!empty($data['callback'])) && (isUserDataValid())) {
96                 // "Call-back" alias column for current logged in user's data
97                 $functionName = "getUserData('" . $data['callback'] . "')";
98         }
99
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 . ')';
104         } // END - if
105
106         // Now replace the code
107         $code = str_replace($data['matches'][0][$data['key']], "\" . " . $functionName . " . \"", $data['code']);
108
109         // Return replaced code
110         return $code;
111 }
112
113 // Expression call-back function for getting extension data
114 function doExpressionExt ($data) {
115         // Not installed is default
116         $replacer = 'false';
117
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']));
122
123                 // Construct call of the function
124                 $replacer = "\" . call_user_func_array('" . $functionName . "', array('" . $data['matches'][4][$data['key']] . "', true)) . \"";
125         } // END - if
126
127         // Replace it and insert parameter for GET request
128         $code = str_replace($data['matches'][0][$data['key']], sprintf("&amp;ext=%s&amp;ver=%s&amp;rev=\" . getConfig('CURR_SVN_REVISION') . \"", $data['matches'][4][$data['key']], $replacer), $data['code']);
129
130         // Return replaced code
131         return $code;
132 }
133
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']]);
139
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));
144         } // END - if
145
146         // Replace the config entry
147         $code = str_replace($data['matches'][0][$data['key']], $configValue, $data['code']);
148
149         // Return replaced code
150         return $code;
151 }
152
153 // Expression call-back function for calling filters
154 function doExpressionFilter ($data) {
155         // Construct replacement
156         $replacer = "\" . runFilterChain('" . $data['matches'][4][$data['key']] . "') . \"";
157
158         // Run the filter and insert result
159         $code = str_replace($data['matches'][0][$data['key']], $replacer, $data['code']);
160
161         // Return replaced code
162         return $code;
163 }
164
165 // [EOF]
166 ?>