<?php
/************************************************************************
- * MXChange v0.2.1 Start: 02/28/2009 *
- * =============== Last change: 02/28/2009 *
+ * Mailer v0.2.1-FINAL Start: 02/28/2009 *
+ * =================== Last change: 02/28/2009 *
* *
* -------------------------------------------------------------------- *
* File : request-functions.php *
* -------------------------------------------------------------------- *
* Kurzbeschreibung : Spezialle Funktionen fuer die Anfragebehandlung *
* -------------------------------------------------------------------- *
- * $Revision:: 856 $ *
- * $Date:: 2009-03-06 20:24:32 +0100 (Fr, 06. Mär 2009) $ *
+ * $Revision:: $ *
+ * $Date:: $ *
* $Tag:: 0.2.1-FINAL $ *
- * $Author:: stelzi $ *
- * Needs to be in all Files and every File needs "svn propset *
- * svn:keywords Date Revision" (autoprobset!) at least!!!!!! *
+ * $Author:: $ *
* -------------------------------------------------------------------- *
- * Copyright (c) 2003 - 2008 by Roland Haeder *
- * For more information visit: http://www.mxchange.org *
+ * Copyright (c) 2003 - 2009 by Roland Haeder *
+ * Copyright (c) 2009 - 2012 by Mailer Developer Team *
+ * For more information visit: http://mxchange.org *
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
// Some security stuff...
if (!defined('__SECURITY')) {
- $INC = substr(dirname(__FILE__), 0, strpos(dirname(__FILE__), "/inc") + 4) . "/security.php";
- require($INC);
+ die();
} // END - if
+// Initialize the request elements
+function initRequest () {
+ $GLOBALS['raw_request']['get'] = (array) $_GET;
+ $GLOBALS['raw_request']['post'] = (array) $_POST;
+}
+
// Wrapper for elements in $_GET
-function REQUEST_GET ($element) {
+function getRequestElement ($element) {
// By default no element is there
- $value = null;
+ $value = NULL;
// Is the element cached or there?
- if (isset($GLOBALS['cache_array']['request_get'][$element])) {
+ if (isset($GLOBALS['cache_request']['get'][$element])) {
// Then use the cache
- $value = $GLOBALS['cache_array']['request_get'][$element];
- } elseif (REQUEST_ISSET_GET($element)) {
+ $value = $GLOBALS['cache_request']['get'][$element];
+ } elseif (isGetRequestElementSet($element)) {
// Then get it directly
- $value = SQL_ESCAPE($_GET[$element]);
+ $value = SQL_ESCAPE($GLOBALS['raw_request']['get'][$element]);
// Store it in cache
- $GLOBALS['cache_array']['request_get'][$element] = $value;
+ $GLOBALS['cache_request']['get'][$element] = $value;
} // END - if
// Return value
}
// Checks if an element in $_GET exists
-function REQUEST_ISSET_GET ($element, $subElement="") {
+function isGetRequestElementSet ($element, $subElement = '') {
if (empty($subElement)) {
- return (isset($_GET[$element]));
+ return ((isset($GLOBALS['raw_request']['get'][$element])) && ('' . ($GLOBALS['raw_request']['get'][$element] . '') != ''));
} else {
- return (isset($_GET[$element][$subElement]));
+ return ((isset($GLOBALS['raw_request']['get'][$element][$subElement])) && ('' . ($GLOBALS['raw_request']['get'][$element][$subElement] . '') != ''));
}
}
// Removes an element from $_GET
-function REQUEST_UNSET_GET ($element) {
- unset($_GET[$element]);
+function unsetGetRequestElement ($element) {
+ unset($GLOBALS['cache_request']['get'][$element]);
+ unset($GLOBALS['raw_request']['get'][$element]);
}
// Getter for whole $_GET array
-function REQUEST_GET_ARRAY () {
- return $_GET;
+function getRequestArray () {
+ return $GLOBALS['raw_request']['get'];
}
// Counts entries in $_GET or returns false if not an array
-function REQUEST_GET_COUNT () {
+function countRequestGet () {
// By default this is not an array
- $count = false;
+ $count = FALSE;
// Get the array
- $GET = REQUEST_GET_ARRAY();
+ $GET = getRequestArray();
// Is it an array?
if (is_array($GET)) {
}
// Setter for element in $_GET
-function REQUEST_SET_GET ($element, $value) {
- $_GET[SQL_ESCAPE($element)] = SQL_ESCAPE($value);
+function setGetRequestElement ($element, $value) {
+ // Escape both
+ $element = SQL_ESCAPE($element);
+ $value = SQL_ESCAPE($value);
+
+ // Set in $_GET
+ $GLOBALS['raw_request']['get'][$element] = $value;
+
+ // Update cache
+ $GLOBALS['cache_request']['get'][$element] = $value;
}
// Wrapper for elements in $_POST
-function REQUEST_POST ($element, $subElement=null) {
+function postRequestElement ($element, $subElement = NULL) {
+ //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'element[' . gettype($element) . ']=' . $element . ',subElement[' . gettype($subElement) . ']=' . $subElement . ' - ENTERED!');
// By default no element is there
- $value = null;
+ $value = NULL;
- // Is the element there?
- if (REQUEST_ISSET_POST($element)) {
+ // Is the element in cache?
+ if (isset($GLOBALS['cache_request']['post'][$element][$subElement])) {
+ // Then use it
+ $value = $GLOBALS['cache_request']['post'][$element][$subElement];
+ //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'element[' . gettype($element) . ']=' . $element . ',subElement[' . gettype($subElement) . ']=' . $subElement . ',value[' . gettype($value) . ']=' . $value . ' - CACHE!');
+ } elseif (isPostRequestElementSet($element)) {
// Then use it
- $value = $_POST[$element];
+ $value = $GLOBALS['raw_request']['post'][$element];
// Is $subElement set?
- if ((!is_null($subElement)) && (REQUEST_ISSET_POST($element, $subElement))) {
+ if ((!is_null($subElement)) && (isPostRequestElementSet($element, $subElement))) {
// Then use this
- $value = $value[$subElement];
- } // END - if
+ $value = SQL_ESCAPE($value[$subElement]);
+ //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'element=' . $element . ',subElement=' . $subElement . ' - SUB!');
+ } elseif (!is_array($value)) {
+ // Escape it here
+ $value = SQL_ESCAPE($value);
+ //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'element=' . $element . ' - REGULAR!');
+ }
+
+ // Set it in cache
+ //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'element=' . $element . ',subElement=' . $subElement . ',value=' . $value.' - ADDED!');
+ $GLOBALS['cache_request']['post'][$element][$subElement] = $value;
} // END - if
// Return value
+ //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'element[' . gettype($element) . ']=' . $element . ',subElement[' . gettype($subElement) . ']=' . $subElement . ',value[' . gettype($value) . ']=' . $value . ' - EXIT!');
return $value;
}
// Checks if an element in $_POST exists
-function REQUEST_ISSET_POST ($element, $subElement=null) {
+function isPostRequestElementSet ($element, $subElement = NULL) {
+ /*
+ * Always check that $element is a string and that $subElement is NULL or
+ * a string as numerical indexes are not wanted in POST data (in this
+ * project).
+ */
+ //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'element[]=' . gettype($element) . ',subElement[]=' . gettype($subElement));
+ assert(is_string($element) && ((is_null($subElement)) || (is_string($subElement)) || (is_int($subElement)) || (is_double($subElement))));
+
+ // Is a sub element set?
if (is_null($subElement)) {
- return (isset($_POST[$element]));
+ // No, then only check $element
+ return ((isset($GLOBALS['raw_request']['post'][$element])) && ((is_array($GLOBALS['raw_request']['post'][$element])) || (('' . $GLOBALS['raw_request']['post'][$element] . '') != '')));
} else {
- return (isset($_POST[$element][$subElement]));
+ // Yes, then check both together
+ return ((isset($GLOBALS['raw_request']['post'][$element][$subElement])) && (('' . $GLOBALS['raw_request']['post'][$element][$subElement] . '') != ''));
}
}
// Removes an element from $_POST
-function REQUEST_UNSET_POST ($element) {
- unset($_POST[$element]);
+function unsetPostRequestElement ($element) {
+ unset($GLOBALS['raw_request']['post'][$element]);
+ unset($GLOBALS['cache_request']['post'][$element]);
}
// Getter for whole $_POST array
-function REQUEST_POST_ARRAY () {
- return $_POST;
+function postRequestArray () {
+ return $GLOBALS['raw_request']['post'];
+}
+
+// Setter for whole $_POST array
+function setPostRequestArray ($postData) {
+ $GLOBALS['raw_request']['post'] = $postData;
}
// Counts entries in $_POST or returns false if not an array
-function REQUEST_POST_COUNT () {
+function countRequestPost () {
// By default this is not an array
- $count = false;
+ $count = FALSE;
// Get the array
- $POST = REQUEST_POST_ARRAY();
+ $postData = postRequestArray();
// Is it an array?
- if (is_array($POST)) {
+ if (is_array($postData)) {
// Then count it
- $count = count($POST);
+ $count = count($postData);
} // END - if
// Return value
+ return $count;
}
// Setter for element in $_POST
-function REQUEST_SET_POST ($element, $value) {
+function setPostRequestElement ($element, $value) {
+ // Is $element or $value an array?
if (is_array($element)) {
// Set array
- $eval = "\$_POST['";
+ $eval = "\$GLOBALS['raw_request']['post']['";
// Add all entries
- $eval .= implode("', '", $element);
+ $eval .= implode("']['", $element);
// Finish eval() command
$eval .= sprintf("'] = \"%s\";", SQL_ESCAPE($value));
// And run it
eval($eval);
} elseif (is_array($value)) {
+ // Escape element
+ $element = SQL_ESCAPE($element);
+
// Value is an array so set it directly
- $_POST[SQL_ESCAPE($element)] = $value;
+ $GLOBALS['raw_request']['post'][$element] = $value;
} else {
+ // Debug message
+ //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'element=' . $element . ',value=' . $value . ' - BEFORE!');
+
+ // Escape both
+ $element = SQL_ESCAPE($element);
+ $value = SQL_ESCAPE($value);
+
+ // Debug message
+ //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'element=' . $element . ',value=' . $value . ' - AFTER!');
+
// Set regular entry
- $_POST[SQL_ESCAPE($element)] = SQL_ESCAPE($value);
+ $GLOBALS['raw_request']['post'][$element] = $value;
}
+
+ // Update cache
+ $GLOBALS['cache_request']['post'][$element][NULL] = $value;
}
-// Checks wether a form was sent. If so, the $_POST['ok'] element must be set
-function IS_FORM_SENT () {
+// Checks whether a form was sent. If so, the $_POST['ok'] element must be set
+function isFormSent ($requestParameter = 'ok') {
// Simply wrap it!
- return REQUEST_ISSET_POST('ok');
+ return isPostRequestElementSet($requestParameter);
+}
+
+// Getter for request URI
+function getRequestUri () {
+ // Is it not set?
+ if (!isset($_SERVER['REQUEST_URI'])) {
+ // Return empty string
+ return '';
+ } // END - if
+
+ // Return it
+ return $_SERVER['REQUEST_URI'];
+}
+
+// Add all GET parameters to a string (without leading sign)
+function addAllGetRequestParameters () {
+ // Init variable
+ $return = '';
+
+ // Now add all parameters
+ foreach (getRequestArray() as $key => $value) {
+ // Add it secured
+ $return .= SQL_ESCAPE($key) . '=' . SQL_ESCAPE($value) . '&';
+ } // END - foreach
+
+ // Remove trailing &
+ $return = substr($return, 0, -5);
+
+ // Return it
+ return $return;
}
-//
+// [EOF]
?>