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 * For more information visit: http://www.mxchange.org *
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. *
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. *
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, *
37 ************************************************************************/
39 // Some security stuff...
40 if (!defined('__SECURITY')) {
44 // Initialize the request elements
45 function initRequest () {
46 $GLOBALS['raw_request']['get'] = $_GET;
47 $GLOBALS['raw_request']['post'] = $_POST;
50 // Wrapper for elements in $_GET
51 function getRequestParameter ($element) {
52 // By default no element is there
55 // Is the element cached or there?
56 if (isset($GLOBALS['cache_request']['request_get'][$element])) {
58 $value = $GLOBALS['cache_request']['request_get'][$element];
59 } elseif (isGetRequestParameterSet($element)) {
60 // Then get it directly
61 $value = SQL_ESCAPE($GLOBALS['raw_request']['get'][$element]);
64 $GLOBALS['cache_request']['request_get'][$element] = $value;
71 // Checks if an element in $_GET exists
72 function isGetRequestParameterSet ($element, $subElement = '') {
73 if (empty($subElement)) {
74 return ((isset($GLOBALS['raw_request']['get'][$element])) && (!empty($GLOBALS['raw_request']['get'][$element])));
76 return ((isset($GLOBALS['raw_request']['get'][$element][$subElement])) && (!empty($GLOBALS['raw_request']['get'][$element][$subElement])));
80 // Removes an element from $_GET
81 function unsetGetRequestParameter ($element) {
82 unset($GLOBALS['raw_request']['get'][$element]);
85 // Getter for whole $_GET array
86 function getRequestArray () {
87 return $GLOBALS['raw_request']['get'];
90 // Counts entries in $_GET or returns false if not an array
91 function countRequestGet () {
92 // By default this is not an array
96 $GET = getRequestArray();
101 $count = count($GET);
107 // Setter for element in $_GET
108 function setGetRequestParameter ($element, $value) {
110 $element = SQL_ESCAPE($element);
111 $value = SQL_ESCAPE($value);
114 $GLOBALS['raw_request']['get'][$element] = $value;
117 $GLOBALS['cache_request']['request_get'][$element] = $value;
120 // Wrapper for elements in $_POST
121 function postRequestParameter ($element, $subElement=null) {
122 // By default no element is there
125 // Is the element in cache?
126 if (isset($GLOBALS['cache_request']['request_post'][$element][$subElement])) {
128 $value = $GLOBALS['cache_request']['request_post'][$element][$subElement];
129 } elseif (isPostRequestParameterSet($element)) {
131 $value = $GLOBALS['raw_request']['post'][$element];
133 // Is $subElement set?
134 if ((!is_null($subElement)) && (isPostRequestParameterSet($element, $subElement))) {
136 $value = SQL_ESCAPE($value[$subElement]);
137 } elseif (!is_array($value)) {
139 $value = SQL_ESCAPE($value);
143 $GLOBALS['cache_request']['request_post'][$element][$subElement] = $value;
150 // Checks if an element in $_POST exists
151 function isPostRequestParameterSet ($element, $subElement=null) {
152 if (is_null($subElement)) {
153 return ((isset($GLOBALS['raw_request']['post'][$element])) && (isset($GLOBALS['raw_request']['post'][$element])));
155 return ((isset($GLOBALS['raw_request']['post'][$element][$subElement])) && (isset($GLOBALS['raw_request']['post'][$element][$subElement])));
159 // Removes an element from $_POST
160 function unsetPostRequestParameter ($element) {
161 unset($GLOBALS['raw_request']['post'][$element]);
164 // Getter for whole $_POST array
165 function postRequestArray () {
166 return $GLOBALS['raw_request']['post'];
169 // Setter for whole $_POST array
170 function setPostRequestArray ($postData) {
171 $GLOBALS['raw_request']['post'] = $postData;
174 // Counts entries in $_POST or returns false if not an array
175 function countRequestPost () {
176 // By default this is not an array
180 $postData = postRequestArray();
183 if (is_array($postData)) {
185 $count = count($postData);
191 // Setter for element in $_POST
192 function setPostRequestParameter ($element, $value) {
193 // Is $element or $value an array?
194 if (is_array($element)) {
196 $eval = "\$GLOBALS['raw_request']['post']['";
199 $eval .= implode("']['", $element);
201 // Finish eval() command
202 $eval .= sprintf("'] = \"%s\";", SQL_ESCAPE($value));
206 } elseif (is_array($value)) {
208 $element = SQL_ESCAPE($element);
210 // Value is an array so set it directly
211 $GLOBALS['raw_request']['post'][$element] = $value;
214 $element = SQL_ESCAPE($element);
215 $value = SQL_ESCAPE($value);
218 $GLOBALS['raw_request']['post'][$element] = $value;
222 $GLOBALS['cache_request']['request_post'][$element][null] = $value;
225 // Checks wether a form was sent. If so, the $_POST['ok'] element must be set
226 function isFormSent () {
228 return isPostRequestParameterSet('ok');
231 // Setter for content type
232 function setContentType ($contentType) {
233 $GLOBALS['content_type'] = (string) $contentType;
236 // Getter for content type
237 function getContentType () {
238 return $GLOBALS['content_type'];
241 // Getter for request URI
242 function getRequestUri () {
243 return $_SERVER['REQUEST_URI'];