X-Git-Url: https://git.mxchange.org/?p=mailer.git;a=blobdiff_plain;f=inc%2Frequest-functions.php;h=e3296109b45ebdc0bf09d700e9f7ccf9bc434968;hp=ed1a0a78c2b7fcba37bd783f132553eea29d2d00;hb=5b2fa7f464317185154a3550edb5786d52b2cbf9;hpb=263a089d8a499e0e26d0af9e7aa7639f88b8ca60 diff --git a/inc/request-functions.php b/inc/request-functions.php index ed1a0a78c2..e3296109b4 100644 --- a/inc/request-functions.php +++ b/inc/request-functions.php @@ -14,11 +14,10 @@ * $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 - 2009 by Roland Haeder * - * For more information visit: http://www.mxchange.org * + * 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 * @@ -43,25 +42,25 @@ if (!defined('__SECURITY')) { // Initialize the request elements function initRequest () { - $GLOBALS['raw_request']['get'] = $_GET; - $GLOBALS['raw_request']['post'] = $_POST; + $GLOBALS['raw_request']['get'] = (array) $_GET; + $GLOBALS['raw_request']['post'] = (array) $_POST; } // Wrapper for elements in $_GET function getRequestElement ($element) { // By default no element is there - $value = null; + $value = NULL; // Is the element cached or there? - if (isset($GLOBALS['cache_request']['request_get'][$element])) { + if (isset($GLOBALS['cache_request']['get'][$element])) { // Then use the cache - $value = $GLOBALS['cache_request']['request_get'][$element]; + $value = $GLOBALS['cache_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; + $GLOBALS['cache_request']['get'][$element] = $value; } // END - if // Return value @@ -71,14 +70,15 @@ function getRequestElement ($element) { // Checks if an element in $_GET exists function isGetRequestElementSet ($element, $subElement = '') { if (empty($subElement)) { - return ((isset($GLOBALS['raw_request']['get'][$element])) && (!empty($GLOBALS['raw_request']['get'][$element]))); + return ((isset($GLOBALS['raw_request']['get'][$element])) && ('' . ($GLOBALS['raw_request']['get'][$element] . '') != '')); } else { - return ((isset($GLOBALS['raw_request']['get'][$element][$subElement])) && (!empty($GLOBALS['raw_request']['get'][$element][$subElement]))); + return ((isset($GLOBALS['raw_request']['get'][$element][$subElement])) && ('' . ($GLOBALS['raw_request']['get'][$element][$subElement] . '') != '')); } } // Removes an element from $_GET function unsetGetRequestElement ($element) { + unset($GLOBALS['cache_request']['get'][$element]); unset($GLOBALS['raw_request']['get'][$element]); } @@ -90,7 +90,7 @@ function getRequestArray () { // Counts entries in $_GET or returns false if not an array function countRequestGet () { // By default this is not an array - $count = false; + $count = FALSE; // Get the array $GET = getRequestArray(); @@ -105,7 +105,7 @@ function countRequestGet () { } // Setter for element in $_GET -function setRequestGetElement ($element, $value) { +function setGetRequestElement ($element, $value) { // Escape both $element = SQL_ESCAPE($element); $value = SQL_ESCAPE($value); @@ -114,18 +114,20 @@ function setRequestGetElement ($element, $value) { $GLOBALS['raw_request']['get'][$element] = $value; // Update cache - $GLOBALS['cache_request']['request_get'][$element] = $value; + $GLOBALS['cache_request']['get'][$element] = $value; } // Wrapper for elements in $_POST -function postRequestElement ($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 in cache? - if (isset($GLOBALS['cache_request']['request_post'][$element][$subElement])) { + if (isset($GLOBALS['cache_request']['post'][$element][$subElement])) { // Then use it - $value = $GLOBALS['cache_request']['request_post'][$element][$subElement]; + $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 = $GLOBALS['raw_request']['post'][$element]; @@ -134,31 +136,47 @@ function postRequestElement ($element, $subElement=null) { if ((!is_null($subElement)) && (isPostRequestElementSet($element, $subElement))) { // Then use this $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 - $GLOBALS['cache_request']['request_post'][$element][$subElement] = $value; + //* 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 isPostRequestElementSet ($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($GLOBALS['raw_request']['post'][$element])) && (isset($GLOBALS['raw_request']['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($GLOBALS['raw_request']['post'][$element][$subElement])) && (isset($GLOBALS['raw_request']['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 unsetPostRequestElement ($element) { unset($GLOBALS['raw_request']['post'][$element]); + unset($GLOBALS['cache_request']['post'][$element]); } // Getter for whole $_POST array @@ -174,7 +192,7 @@ function setPostRequestArray ($postData) { // Counts entries in $_POST or returns false if not an array function countRequestPost () { // By default this is not an array - $count = false; + $count = FALSE; // Get the array $postData = postRequestArray(); @@ -186,10 +204,11 @@ function countRequestPost () { } // END - if // Return value + return $count; } // Setter for element in $_POST -function setRequestPostElement ($element, $value) { +function setPostRequestElement ($element, $value) { // Is $element or $value an array? if (is_array($element)) { // Set array @@ -210,38 +229,59 @@ function setRequestPostElement ($element, $value) { // Value is an array so set it directly $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 $GLOBALS['raw_request']['post'][$element] = $value; } // Update cache - $GLOBALS['cache_request']['request_post'][$element][null] = $value; + $GLOBALS['cache_request']['post'][$element][NULL] = $value; } -// Checks wether a form was sent. If so, the $_POST['ok'] element must be set -function isFormSent () { +// Checks whether a form was sent. If so, the $_POST['ok'] element must be set +function isFormSent ($requestParameter = 'ok') { // Simply wrap it! - 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']; + 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] ?>