X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=inc%2Frequest-functions.php;h=a3ff1de26a65fb576a319bacad583deedebbcabe;hb=4939d0ea8f0846283675f45c1d47f15b587789aa;hp=0066994f26757168c63a4fbe8aef21bde6e2f150;hpb=d8148e3f1f3a6762b2e786dbe99ada269dcf2ea0;p=mailer.git diff --git a/inc/request-functions.php b/inc/request-functions.php index 0066994f26..a3ff1de26a 100644 --- a/inc/request-functions.php +++ b/inc/request-functions.php @@ -10,9 +10,14 @@ * -------------------------------------------------------------------- * * Kurzbeschreibung : Spezialle Funktionen fuer die Anfragebehandlung * * -------------------------------------------------------------------- * - * * + * $Revision:: $ * + * $Date:: $ * + * $Tag:: 0.2.1-FINAL $ * + * $Author:: $ * + * Needs to be in all Files and every File needs "svn propset * + * svn:keywords Date Revision" (autoprobset!) at least!!!!!! * * -------------------------------------------------------------------- * - * Copyright (c) 2003 - 2008 by Roland Haeder * + * Copyright (c) 2003 - 2009 by Roland Haeder * * For more information visit: http://www.mxchange.org * * * * This program is free software; you can redistribute it and/or modify * @@ -33,19 +38,30 @@ // 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'] = $_GET; + $GLOBALS['raw_request']['post'] = $_POST; +} + // Wrapper for elements in $_GET -function REQUEST_GET ($element) { +function getRequestElement ($element) { // By default no element is there $value = null; - // Is the element there? - if (REQUEST_ISSET_GET($element)) { - // Then use it - $value = $_GET[$element]; + // Is the element cached or there? + if (isset($GLOBALS['cache_request']['request_get'][$element])) { + // Then use the cache + $value = $GLOBALS['cache_request']['request_get'][$element]; + } elseif (isGetRequestElementSet($element)) { + // Then get it directly + $value = SQL_ESCAPE($GLOBALS['raw_request']['get'][$element]); + + // Store it in cache + $GLOBALS['cache_request']['request_get'][$element] = $value; } // END - if // Return value @@ -53,27 +69,31 @@ function REQUEST_GET ($element) { } // Checks if an element in $_GET exists -function REQUEST_ISSET_GET ($element) { - return (isset($_GET['element'])); +function isGetRequestElementSet ($element, $subElement = '') { + if (empty($subElement)) { + return ((isset($GLOBALS['raw_request']['get'][$element])) && (!empty($GLOBALS['raw_request']['get'][$element]))); + } else { + return ((isset($GLOBALS['raw_request']['get'][$element][$subElement])) && (!empty($GLOBALS['raw_request']['get'][$element][$subElement]))); + } } // Removes an element from $_GET -function REQUEST_UNSET_GET ($element) { - unset($_GET[$element]); +function unsetGetRequestElement ($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; // Get the array - $GET = REQUEST_GET_ARRAY(); + $GET = getRequestArray(); // Is it an array? if (is_array($GET)) { @@ -84,15 +104,43 @@ function REQUEST_GET_COUNT () { // Return value } +// Setter for element in $_GET +function setRequestGetElement ($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']['request_get'][$element] = $value; +} + // Wrapper for elements in $_POST -function REQUEST_POST ($element) { +function postRequestElement ($element, $subElement=null) { // By default no element is there $value = null; - // Is the element there? - if (REQUEST_ISSET_POST($element)) { + // Is the element in cache? + if (isset($GLOBALS['cache_request']['request_post'][$element][$subElement])) { + // Then use it + $value = $GLOBALS['cache_request']['request_post'][$element][$subElement]; + } elseif (isPostRequestElementSet($element)) { // Then use it - $value = $_POST[$element]; + $value = $GLOBALS['raw_request']['post'][$element]; + + // Is $subElement set? + if ((!is_null($subElement)) && (isPostRequestElementSet($element, $subElement))) { + // Then use this + $value = SQL_ESCAPE($value[$subElement]); + } elseif (!is_array($value)) { + // Escape it here + $value = SQL_ESCAPE($value); + } + + // Set it in cache + $GLOBALS['cache_request']['request_post'][$element][$subElement] = $value; } // END - if // Return value @@ -100,42 +148,100 @@ function REQUEST_POST ($element) { } // Checks if an element in $_POST exists -function REQUEST_ISSET_POST ($element) { - return (isset($_POST['element'])); +function isPostRequestElementSet ($element, $subElement=null) { + if (is_null($subElement)) { + return ((isset($GLOBALS['raw_request']['post'][$element])) && (isset($GLOBALS['raw_request']['post'][$element]))); + } else { + return ((isset($GLOBALS['raw_request']['post'][$element][$subElement])) && (isset($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]); } // 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; // 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 } +// Setter for element in $_POST +function setRequestPostElement ($element, $value) { + // Is $element or $value an array? + if (is_array($element)) { + // Set array + $eval = "\$GLOBALS['raw_request']['post']['"; + + // Add all entries + $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 + $GLOBALS['raw_request']['post'][$element] = $value; + } else { + // Escape both + $element = SQL_ESCAPE($element); + $value = SQL_ESCAPE($value); + + // Set regular entry + $GLOBALS['raw_request']['post'][$element] = $value; + } + + // Update cache + $GLOBALS['cache_request']['request_post'][$element][null] = $value; +} + // Checks wether a form was sent. If so, the $_POST['ok'] element must be set -function IS_FORM_SENT () { +function isFormSent () { // Simply wrap it! - return REQUEST_ISSET_POST('ok'); + return isPostRequestElementSet('ok'); +} + +// Setter for content type +function setContentType ($contentType) { + $GLOBALS['content_type'] = (string) $contentType; +} + +// Getter for content type +function getContentType () { + return $GLOBALS['content_type']; +} + +// Getter for request URI +function getRequestUri () { + return $_SERVER['REQUEST_URI']; } -// +// [EOF] ?>