A lot has been rewritten, ext-teams added, ext-forced continued:
[mailer.git] / inc / request-functions.php
index b8f862fee9011d8409d4da0675298e8cd362ec87..b82c12a7ef810354de2ee467316fbd487511a8e3 100644 (file)
@@ -1,7 +1,7 @@
 <?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                            *
  * $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                           *
+ * Copyright (c) 2009 - 2011 by Mailer Developer Team                   *
  * For more information visit: http://www.mxchange.org                  *
  *                                                                      *
  * This program is free software; you can redistribute it and/or modify *
 
 // 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 getRequestParameter ($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 (isGetRequestParameterSet($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
@@ -64,31 +68,31 @@ function REQUEST_GET ($element) {
 }
 
 // Checks if an element in $_GET exists
-function REQUEST_ISSET_GET ($element, $subElement="") {
+function isGetRequestParameterSet ($element, $subElement = '') {
        if (empty($subElement)) {
-               return ((isset($_GET[$element])) && (!empty($_GET[$element])));
+               return ((isset($GLOBALS['raw_request']['get'][$element])) && ('' . ($GLOBALS['raw_request']['get'][$element] . '') != ''));
        } else {
-               return ((isset($_GET[$element][$subElement])) && (!empty($_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 unsetGetRequestParameter ($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)) {
@@ -100,25 +104,42 @@ function REQUEST_GET_COUNT () {
 }
 
 // Setter for element in $_GET
-function REQUEST_SET_GET ($element, $value) {
-       $_GET[SQL_ESCAPE($element)] = SQL_ESCAPE($value);
+function setGetRequestParameter ($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 postRequestParameter ($element, $subElement=null) {
        // 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];
+       } elseif (isPostRequestParameterSet($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)) && (isPostRequestParameterSet($element, $subElement))) {
                        // Then use this
-                       $value = $value[$subElement];
-               } // END - if
+                       $value = SQL_ESCAPE($value[$subElement]);
+               } elseif (!is_array($value)) {
+                       // Escape it here
+                       $value = SQL_ESCAPE($value);
+               }
+
+               // Set it in cache
+               $GLOBALS['cache_request']['post'][$element][$subElement] = $value;
        } // END - if
 
        // Return value
@@ -126,49 +147,55 @@ function REQUEST_POST ($element, $subElement=null) {
 }
 
 // Checks if an element in $_POST exists
-function REQUEST_ISSET_POST ($element, $subElement=null) {
+function isPostRequestParameterSet ($element, $subElement=null) {
        if (is_null($subElement)) {
-               return ((isset($_POST[$element])) && (!empty($_POST[$element])));
+               return ((isset($GLOBALS['raw_request']['post'][$element])) && (('' . $GLOBALS['raw_request']['post'][$element] . '') != ''));
        } else {
-               return ((isset($_POST[$element][$subElement])) && (!empty($_POST[$element][$subElement])));
+               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 unsetPostRequestParameter ($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 REQUEST_SET_POST ($element, $value) {
+function setPostRequestParameter ($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));
@@ -176,19 +203,49 @@ function REQUEST_SET_POST ($element, $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 {
+               // Escape both
+               $element = SQL_ESCAPE($element);
+               $value   = SQL_ESCAPE($value);
+
                // 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 () {
+function isFormSent ($requestParameter = 'ok') {
        // Simply wrap it!
-       return REQUEST_ISSET_POST('ok');
+       return isPostRequestParameterSet($requestParameter);
+}
+
+// Checks if 'content_type' is set
+function isContentTypeSet () {
+       return isset($GLOBALS['content_type']);
+}
+
+// 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]
 ?>