2 /************************************************************************
3 * Mailer v0.2.1-FINAL Start: 02/28/2009 *
4 * =================== Last change: 02/28/2009 *
6 * -------------------------------------------------------------------- *
7 * File : request-functions.php *
8 * -------------------------------------------------------------------- *
9 * Short description : Special functions for request handling *
10 * -------------------------------------------------------------------- *
11 * Kurzbeschreibung : Spezialle Funktionen fuer die Anfragebehandlung *
12 * -------------------------------------------------------------------- *
15 * $Tag:: 0.2.1-FINAL $ *
17 * -------------------------------------------------------------------- *
18 * Copyright (c) 2003 - 2009 by Roland Haeder *
19 * Copyright (c) 2009, 2010 by Mailer Developer Team *
20 * For more information visit: http://www.mxchange.org *
22 * This program is free software; you can redistribute it and/or modify *
23 * it under the terms of the GNU General Public License as published by *
24 * the Free Software Foundation; either version 2 of the License, or *
25 * (at your option) any later version. *
27 * This program is distributed in the hope that it will be useful, *
28 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
29 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
30 * GNU General Public License for more details. *
32 * You should have received a copy of the GNU General Public License *
33 * along with this program; if not, write to the Free Software *
34 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, *
36 ************************************************************************/
38 // Some security stuff...
39 if (!defined('__SECURITY')) {
43 // Initialize the request elements
44 function initRequest () {
45 $GLOBALS['raw_request']['get'] = $_GET;
46 $GLOBALS['raw_request']['post'] = $_POST;
49 // Wrapper for elements in $_GET
50 function getRequestParameter ($element) {
51 // By default no element is there
54 // Is the element cached or there?
55 if (isset($GLOBALS['cache_request']['request_get'][$element])) {
57 $value = $GLOBALS['cache_request']['request_get'][$element];
58 } elseif (isGetRequestParameterSet($element)) {
59 // Then get it directly
60 $value = SQL_ESCAPE($GLOBALS['raw_request']['get'][$element]);
63 $GLOBALS['cache_request']['request_get'][$element] = $value;
70 // Checks if an element in $_GET exists
71 function isGetRequestParameterSet ($element, $subElement = '') {
72 if (empty($subElement)) {
73 return ((isset($GLOBALS['raw_request']['get'][$element])) && (!empty($GLOBALS['raw_request']['get'][$element])));
75 return ((isset($GLOBALS['raw_request']['get'][$element][$subElement])) && (!empty($GLOBALS['raw_request']['get'][$element][$subElement])));
79 // Removes an element from $_GET
80 function unsetGetRequestParameter ($element) {
81 unset($GLOBALS['raw_request']['get'][$element]);
84 // Getter for whole $_GET array
85 function getRequestArray () {
86 return $GLOBALS['raw_request']['get'];
89 // Counts entries in $_GET or returns false if not an array
90 function countRequestGet () {
91 // By default this is not an array
95 $GET = getRequestArray();
100 $count = count($GET);
106 // Setter for element in $_GET
107 function setGetRequestParameter ($element, $value) {
109 $element = SQL_ESCAPE($element);
110 $value = SQL_ESCAPE($value);
113 $GLOBALS['raw_request']['get'][$element] = $value;
116 $GLOBALS['cache_request']['request_get'][$element] = $value;
119 // Wrapper for elements in $_POST
120 function postRequestParameter ($element, $subElement=null) {
121 // By default no element is there
124 // Is the element in cache?
125 if (isset($GLOBALS['cache_request']['request_post'][$element][$subElement])) {
127 $value = $GLOBALS['cache_request']['request_post'][$element][$subElement];
128 } elseif (isPostRequestParameterSet($element)) {
130 $value = $GLOBALS['raw_request']['post'][$element];
132 // Is $subElement set?
133 if ((!is_null($subElement)) && (isPostRequestParameterSet($element, $subElement))) {
135 $value = SQL_ESCAPE($value[$subElement]);
136 } elseif (!is_array($value)) {
138 $value = SQL_ESCAPE($value);
142 $GLOBALS['cache_request']['request_post'][$element][$subElement] = $value;
149 // Checks if an element in $_POST exists
150 function isPostRequestParameterSet ($element, $subElement=null) {
151 if (is_null($subElement)) {
152 return ((isset($GLOBALS['raw_request']['post'][$element])) && (isset($GLOBALS['raw_request']['post'][$element])));
154 return ((isset($GLOBALS['raw_request']['post'][$element][$subElement])) && (isset($GLOBALS['raw_request']['post'][$element][$subElement])));
158 // Removes an element from $_POST
159 function unsetPostRequestParameter ($element) {
160 unset($GLOBALS['raw_request']['post'][$element]);
163 // Getter for whole $_POST array
164 function postRequestArray () {
165 return $GLOBALS['raw_request']['post'];
168 // Setter for whole $_POST array
169 function setPostRequestArray ($postData) {
170 $GLOBALS['raw_request']['post'] = $postData;
173 // Counts entries in $_POST or returns false if not an array
174 function countRequestPost () {
175 // By default this is not an array
179 $postData = postRequestArray();
182 if (is_array($postData)) {
184 $count = count($postData);
190 // Setter for element in $_POST
191 function setPostRequestParameter ($element, $value) {
192 // Is $element or $value an array?
193 if (is_array($element)) {
195 $eval = "\$GLOBALS['raw_request']['post']['";
198 $eval .= implode("']['", $element);
200 // Finish eval() command
201 $eval .= sprintf("'] = \"%s\";", SQL_ESCAPE($value));
205 } elseif (is_array($value)) {
207 $element = SQL_ESCAPE($element);
209 // Value is an array so set it directly
210 $GLOBALS['raw_request']['post'][$element] = $value;
213 $element = SQL_ESCAPE($element);
214 $value = SQL_ESCAPE($value);
217 $GLOBALS['raw_request']['post'][$element] = $value;
221 $GLOBALS['cache_request']['request_post'][$element][null] = $value;
224 // Checks wether a form was sent. If so, the $_POST['ok'] element must be set
225 function isFormSent ($requestParameter = 'ok') {
227 return isPostRequestParameterSet($requestParameter);
230 // Checks if 'content_type' is set
231 function isContentTypeSet () {
232 return isset($GLOBALS['content_type']);
235 // Setter for content type
236 function setContentType ($contentType) {
237 $GLOBALS['content_type'] = (string) $contentType;
240 // Getter for content type
241 function getContentType () {
242 return $GLOBALS['content_type'];
245 // Getter for request URI
246 function getRequestUri () {
247 return $_SERVER['REQUEST_URI'];