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 * 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 // Initialize the request elements
46 function initRequest () {
47 $GLOBALS['raw_request']['get'] = $_GET;
48 $GLOBALS['raw_request']['post'] = $_POST;
51 // Wrapper for elements in $_GET
52 function getRequestParameter ($element) {
53 // By default no element is there
56 // Is the element cached or there?
57 if (isset($GLOBALS['cache_request']['request_get'][$element])) {
59 $value = $GLOBALS['cache_request']['request_get'][$element];
60 } elseif (isGetRequestParameterSet($element)) {
61 // Then get it directly
62 $value = SQL_ESCAPE($GLOBALS['raw_request']['get'][$element]);
65 $GLOBALS['cache_request']['request_get'][$element] = $value;
72 // Checks if an element in $_GET exists
73 function isGetRequestParameterSet ($element, $subElement = '') {
74 if (empty($subElement)) {
75 return ((isset($GLOBALS['raw_request']['get'][$element])) && (!empty($GLOBALS['raw_request']['get'][$element])));
77 return ((isset($GLOBALS['raw_request']['get'][$element][$subElement])) && (!empty($GLOBALS['raw_request']['get'][$element][$subElement])));
81 // Removes an element from $_GET
82 function unsetGetRequestParameter ($element) {
83 unset($GLOBALS['raw_request']['get'][$element]);
86 // Getter for whole $_GET array
87 function getRequestArray () {
88 return $GLOBALS['raw_request']['get'];
91 // Counts entries in $_GET or returns false if not an array
92 function countRequestGet () {
93 // By default this is not an array
97 $GET = getRequestArray();
100 if (is_array($GET)) {
102 $count = count($GET);
108 // Setter for element in $_GET
109 function setGetRequestParameter ($element, $value) {
111 $element = SQL_ESCAPE($element);
112 $value = SQL_ESCAPE($value);
115 $GLOBALS['raw_request']['get'][$element] = $value;
118 $GLOBALS['cache_request']['request_get'][$element] = $value;
121 // Wrapper for elements in $_POST
122 function postRequestParameter ($element, $subElement=null) {
123 // By default no element is there
126 // Is the element in cache?
127 if (isset($GLOBALS['cache_request']['request_post'][$element][$subElement])) {
129 $value = $GLOBALS['cache_request']['request_post'][$element][$subElement];
130 } elseif (isPostRequestParameterSet($element)) {
132 $value = $GLOBALS['raw_request']['post'][$element];
134 // Is $subElement set?
135 if ((!is_null($subElement)) && (isPostRequestParameterSet($element, $subElement))) {
137 $value = SQL_ESCAPE($value[$subElement]);
138 } elseif (!is_array($value)) {
140 $value = SQL_ESCAPE($value);
144 $GLOBALS['cache_request']['request_post'][$element][$subElement] = $value;
151 // Checks if an element in $_POST exists
152 function isPostRequestParameterSet ($element, $subElement=null) {
153 if (is_null($subElement)) {
154 return ((isset($GLOBALS['raw_request']['post'][$element])) && (isset($GLOBALS['raw_request']['post'][$element])));
156 return ((isset($GLOBALS['raw_request']['post'][$element][$subElement])) && (isset($GLOBALS['raw_request']['post'][$element][$subElement])));
160 // Removes an element from $_POST
161 function unsetPostRequestParameter ($element) {
162 unset($GLOBALS['raw_request']['post'][$element]);
165 // Getter for whole $_POST array
166 function postRequestArray () {
167 return $GLOBALS['raw_request']['post'];
170 // Setter for whole $_POST array
171 function setPostRequestArray ($postData) {
172 $GLOBALS['raw_request']['post'] = $postData;
175 // Counts entries in $_POST or returns false if not an array
176 function countRequestPost () {
177 // By default this is not an array
181 $postData = postRequestArray();
184 if (is_array($postData)) {
186 $count = count($postData);
192 // Setter for element in $_POST
193 function setPostRequestParameter ($element, $value) {
194 // Is $element or $value an array?
195 if (is_array($element)) {
197 $eval = "\$GLOBALS['raw_request']['post']['";
200 $eval .= implode("']['", $element);
202 // Finish eval() command
203 $eval .= sprintf("'] = \"%s\";", SQL_ESCAPE($value));
207 } elseif (is_array($value)) {
209 $element = SQL_ESCAPE($element);
211 // Value is an array so set it directly
212 $GLOBALS['raw_request']['post'][$element] = $value;
215 $element = SQL_ESCAPE($element);
216 $value = SQL_ESCAPE($value);
219 $GLOBALS['raw_request']['post'][$element] = $value;
223 $GLOBALS['cache_request']['request_post'][$element][null] = $value;
226 // Checks wether a form was sent. If so, the $_POST['ok'] element must be set
227 function isFormSent ($requestParameter = 'ok') {
229 return isPostRequestParameterSet($requestParameter);
232 // Checks if 'content_type' is set
233 function isContentTypeSet () {
234 return isset($GLOBALS['content_type']);
237 // Setter for content type
238 function setContentType ($contentType) {
239 $GLOBALS['content_type'] = (string) $contentType;
242 // Getter for content type
243 function getContentType () {
244 return $GLOBALS['content_type'];
247 // Getter for request URI
248 function getRequestUri () {
249 return $_SERVER['REQUEST_URI'];