Changeset 4578 for trunk/core/httprequest.core.php
- Timestamp:
- 08/15/10 18:45:12 (22 months ago)
- File:
-
- 1 edited
-
trunk/core/httprequest.core.php (modified) (30 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/core/httprequest.core.php
r4568 r4578 24 24 * 25 25 * @license GNU/GPL v2 or (at your option) any later version, see "/doc/LICENSE". 26 *27 26 * @author Jens-André Koch <vain@clansuite.com> 28 * @copyright Jens-André Koch (2005 - onwards) 29 * 27 * @copyright Copyleft: All rights reserved. Jens-André Koch (2005 - onwards) 30 28 * @link http://www.clansuite.com 31 * @link http://gna.org/projects/clansuite 32 * 29 * 33 30 * @version SVN: $Id$ 34 31 */ … … 51 48 # Parameters 52 49 public function getParameterNames(); 53 public function issetParameter($ parametername, $parameterArrayName = 'POST', $where = false);54 public function getParameter($ parametername, $parameterArrayName = 'POST');50 public function issetParameter($name, $arrayname = 'POST', $where = false); 51 public function getParameter($name, $arrayname = 'POST'); 55 52 public static function getHeader($name); 56 public function getCookie($name); 53 54 # Direct Access to individual Parameters Arrays 55 public function getParameterFromCookie($name); 56 public function getParameterFromGet($name); 57 public function getParameterFromPost($name); 58 public function getParameterFromServer($name); 57 59 58 60 # Request Method 59 61 public static function getRequestMethod(); 60 62 public static function setRequestMethod($method); 63 public static function isAjax(); 64 public static function isPost(); 65 public static function isGet(); 66 public static function isPut(); 67 public static function isDelete(); 61 68 62 69 # $_SERVER Stuff … … 80 87 { 81 88 /** 82 * @var array Contains the cleaned $_POST Parameters 89 * @var array Contains the cleaned $_POST Parameters. 83 90 */ 84 91 private $post_parameters; 85 92 86 93 /** 87 * @var array Contains the cleaned $_GET Parameters 94 * @var array Contains the cleaned $_GET Parameters. 88 95 */ 89 96 private $get_parameters; 90 97 91 98 /** 92 * @var array Contains the cleaned $_COOKIE Parameters 99 * @var array Contains the cleaned $_COOKIE Parameters. 93 100 */ 94 101 private $cookie_parameters; … … 107 114 * @var boolean for magic_quotes_gpc 108 115 */ 109 private $magic_quotes_gpc; 116 private static $magic_quotes_gpc; 117 118 /** 119 * @var object Object with pieces of informations about the target route. 120 */ 121 private static $route; 110 122 111 123 /** … … 129 141 if ((bool) ini_get('register_globals') and mb_strtolower(ini_get('register_globals')) != 'off') 130 142 { 131 $this->cleanGlobals();143 self::cleanGlobals(); 132 144 } 133 145 … … 138 150 if ( 1 == get_magic_quotes_gpc() ) 139 151 { 140 $this->magic_quotes_gpc = true;141 $this->fix_magic_quotes();152 self::$magic_quotes_gpc = true; 153 self::fix_magic_quotes(); 142 154 ini_set('magic_quotes_gpc', 0); 143 155 } … … 146 158 * 3) Additional Security Checks 147 159 */ 148 # Block Proxies 149 Clansuite_DoorKeeper::blockProxies(); 160 # Clansuite_DoorKeeper::blockProxies(); 161 162 # block XSS 163 $_SERVER['PHP_SELF'] = htmlspecialchars($_SERVER['PHP_SELF']); 164 $_SERVER['QUERY_STRING'] = htmlspecialchars($_SERVER['QUERY_STRING']); 150 165 151 166 /** 152 * 4) Clear Array, Filter and Assign the $_REQUEST Global to it167 * 4) Init Parameter Arrays and Assign the GLOBALS 153 168 */ 154 169 … … 158 173 $this->cookie_parameters = array(); 159 174 160 # Sanitize 161 $this->sanitizeRequest(); 162 163 # Assign the GLOBALS $_REQUEST, $_GET, $_POST, $_COOKIE 175 # Assign the GLOBALS $_GET, $_POST, $_COOKIE 164 176 $this->get_parameters = $_GET; 165 177 $this->post_parameters = $_POST; … … 177 189 * @return boolean true | false 178 190 */ 179 public function isGet()180 { 181 if( $this->requestMethod == 'GET')191 public static function isGet() 192 { 193 if(self::$requestMethod == 'GET') 182 194 { 183 195 return true; … … 191 203 * @return boolean true | false 192 204 */ 193 public function isPost()194 { 195 if( $this->requestMethod == 'POST')205 public static function isPost() 206 { 207 if(self::$requestMethod == 'POST') 196 208 { 197 209 return true; … … 205 217 * @return boolean true | false 206 218 */ 207 public function isPut()208 { 209 if( $this->requestMethod == 'PUT')219 public static function isPut() 220 { 221 if(self::$requestMethod == 'PUT') 210 222 { 211 223 return true; … … 219 231 * @return boolean true | false 220 232 */ 221 public function isDelete()222 { 223 if( $this->requestMethod == 'DELETE')233 public static function isDelete() 234 { 235 if(self::$requestMethod == 'DELETE') 224 236 { 225 237 return true; … … 232 244 * Defaults to Request parameters array 233 245 * 234 * @param string $ parameterArrayName R, G, P, C (REQUEST, GET, POST, COOKIE)246 * @param string $arrayname GET, POST, COOKIE 235 247 * @return array 236 248 */ 237 public function getParameterNames($ parameterArrayName = 'REQUEST')238 { 239 $ parameterArrayName = mb_strtoupper($parameterArrayName);240 241 if(in_array($ parameterArrayName, $this->{mb_strtolower($parameterArrayName).'_arraynames'}))242 { 243 return array_keys($this->{mb_strtolower($ parameterArrayName).'_parameters'});249 public function getParameterNames($arrayname = 'GET') 250 { 251 $arrayname = mb_strtoupper($arrayname); 252 253 if(in_array($arrayname, $this->{mb_strtolower($arrayname).'_arraynames'})) 254 { 255 return array_keys($this->{mb_strtolower($arrayname).'_parameters'}); 244 256 } 245 257 else … … 252 264 * isset, checks if a certain parameter exists in the parameters array 253 265 * 254 * @param string $ parametername Name of the Parameter255 * @param string $ parameterArrayName G, P, C. Default = POST.266 * @param string $name Name of the Parameter 267 * @param string $arrayname G, P, C. Default = POST. 256 268 * @param boolean $where If set to true, method will return the name of the array the parameter was found in. 257 269 * @return mixed | boolean true|false | string arrayname 258 270 */ 259 public function issetParameter($ parametername, $parameterArrayName = 'POST', $where = false)260 { 261 $ parameterArrayName = mb_strtoupper($parameterArrayName);262 263 if(in_array($ parameterArrayName, array ('P', 'POST')) and isset($this->post_parameters[$parametername]))271 public function issetParameter($name, $arrayname = 'POST', $where = false) 272 { 273 $arrayname = mb_strtoupper($arrayname); 274 275 if(in_array($arrayname, array ('P', 'POST')) and isset($this->post_parameters[$name])) 264 276 { 265 277 if($where == false) … … 273 285 } 274 286 275 if(in_array($ parameterArrayName, array ('G', 'GET')) and isset($this->get_parameters[$parametername]))287 if(in_array($arrayname, array ('G', 'GET')) and isset($this->get_parameters[$name])) 276 288 { 277 289 if($where == false) … … 285 297 } 286 298 287 if(in_array($ parameterArrayName, array ('C', 'COOKIE')) and isset($this->cookie_parameters[$parametername]))299 if(in_array($arrayname, array ('C', 'COOKIE')) and isset($this->cookie_parameters[$name])) 288 300 { 289 301 if($where == false) … … 303 315 * get, returns a certain parameter if existing 304 316 * 305 * @param string $ parametername Name of the Parameter306 * @param string $ parameterArrayName G, P, C. Default = POST.317 * @param string $name Name of the Parameter 318 * @param string $arrayname G, P, C. Default = POST. 307 319 * @param string $default You can set a default value. It's returned if parametername was not found. 308 320 * 309 321 * @return mixed data | null 310 322 */ 311 public function getParameter($ parametername, $parameterArrayName = 'POST', $default = null)323 public function getParameter($name, $arrayname = 'POST', $default = null) 312 324 { 313 325 /** 314 * check if the parameter exists in $ parameterArrayName326 * check if the parameter exists in $arrayname 315 327 * the third property of issetParameter is set to true, so that we get the full and correct array name back 316 * even if shortcut like R, G, P or C ($parameterArrayName) was used.328 * even if shortcut like G, P or C ($arrayname) was used. 317 329 */ 318 $parameter_array = $this->issetParameter($ parametername, $parameterArrayName, true);330 $parameter_array = $this->issetParameter($name, $arrayname, true); 319 331 320 332 /** … … 324 336 { 325 337 # this returns a value from the parameterarray 326 return $this->{mb_strtolower($parameter_array).'_parameters'}[$ parametername];338 return $this->{mb_strtolower($parameter_array).'_parameters'}[$name]; 327 339 } 328 340 elseif($default !== null) … … 340 352 * set, returns a certain parameter if existing 341 353 * 342 * @param string $ parametername Name of the Parameter343 * @param string $ parameterArrayName G, P, C. Default = POST.354 * @param string $name Name of the Parameter 355 * @param string $arrayname G, P, C. Default = POST. 344 356 * @return mixed data | null 345 357 */ 346 public function setParameter($ parametername, $parameterArrayName = 'POST')347 { 348 if(true == $this->issetParameter($ parametername, $parameterArrayName))349 { 350 return $this->{mb_strtolower($ parameterArrayName).'_parameters'}[$parametername];358 public function setParameter($name, $arrayname = 'POST') 359 { 360 if(true == $this->issetParameter($name, $arrayname)) 361 { 362 return $this->{mb_strtolower($arrayname).'_parameters'}[$name]; 351 363 } 352 364 else … … 359 371 * Shortcut to get a Parameter from $_POST 360 372 * 361 * @param string $ parametername Name of the Parameter373 * @param string $name Name of the Parameter 362 374 * @return mixed data | null 363 375 */ 364 public function getParameterFromPost($ parametername)365 { 366 return $this->getParameter($ parametername, 'POST');376 public function getParameterFromPost($name) 377 { 378 return $this->getParameter($name, 'POST'); 367 379 } 368 380 … … 370 382 * Shortcut to get a Parameter from $_GET 371 383 * 372 * @param string $ parametername Name of the Parameter384 * @param string $name Name of the Parameter 373 385 * @return mixed data | null 374 386 */ 375 public function getParameterFromGet($ parametername)376 { 377 return $this->getParameter($ parametername, 'GET');387 public function getParameterFromGet($name) 388 { 389 return $this->getParameter($name, 'GET'); 378 390 } 379 391 … … 381 393 * Shortcut to get a Parameter from $_SERVER 382 394 * 383 * @param string $ parametername Name of the Parameter395 * @param string $name Name of the Parameter 384 396 * @return mixed data | null 385 397 */ 386 public function getParameterFromServer($ parametername)387 { 388 if (in_array($ parametername, array_keys($_SERVER)))389 { 390 return $_SERVER[$ parametername];398 public function getParameterFromServer($name) 399 { 400 if (in_array($name, array_keys($_SERVER))) 401 { 402 return $_SERVER[$name]; 391 403 } 392 404 else 393 405 { 394 406 return null; 407 } 408 } 409 410 /** 411 * Get previously set cookies. 412 * 413 * @param string $name Name of the Cookie 414 * @return Returns an associative array containing any previously set cookies. 415 */ 416 public function getParameterFromCookie($name) 417 { 418 if(isset($this->cookie_parameters[$name]) == true) 419 { 420 return $this->cookie_parameters($name); 395 421 } 396 422 } … … 405 431 { 406 432 $name = 'HTTP_' . mb_strtoupper(str_replace('-','_', $name)); 433 407 434 if (isset($_SERVER[$name])) 408 435 { 409 436 return $_SERVER[$name]; 410 437 } 438 411 439 return null; 412 440 } … … 417 445 * 418 446 * @todo check $_SERVER['SSL_PROTOCOL'] + $_SERVER['HTTP_X_FORWARD_PROTO']? 447 * @todo check -> or $_SERVER['SSL_PROTOCOL'] 448 * 419 449 * @return string 420 450 */ 421 451 public static function getServerProtocol() 422 452 { 423 if(self::isSecure()) # @todo check -> or $_SERVER['SSL_PROTOCOL']453 if(self::isSecure()) 424 454 { 425 455 return 'https://'; … … 646 676 } 647 677 678 /** 679 * Get Route 680 * 681 * @return TargetRoute Container 682 */ 683 public static function getRoute() 684 { 685 return self::$route; 686 } 687 688 /** 689 * Set Route 690 * 691 * @param $route The route container. 692 */ 693 public static function setRoute($route) 694 { 695 self::$route = $route; 696 } 648 697 649 698 /** … … 726 775 727 776 /** 728 * Get previously set cookies. 729 * 730 * @param string $name Name of the Cookie 731 * @return Returns an associative array containing any previously set cookies. 732 */ 733 public function getCookie($name) 734 { 735 if(isset($this->cookie_parameters[$name]) == true) 736 { 737 return $this->cookie_parameters($name); 738 } 739 } 740 741 /** 742 * Checks if a ajax-request is given, by checking 743 * X-Requested-With Header for xmlhttprequest. 777 * Checks if a ajax(xhr)-request is given, 778 * by checking X-Requested-With Header for xmlhttprequest. 744 779 * 745 780 * @return bool 746 781 */ 747 public function isXhr()782 public static function isAjax() 748 783 { 749 784 if(isset($_SERVER['X-Requested-With']) and mb_strtolower($_SERVER['X-Requested-With']) === 'xmlhttprequest') … … 759 794 return false; 760 795 } 761 }762 763 /**764 * Shorthand for isXhr()765 *766 * @return boolean767 */768 public function isAjax()769 {770 return $this->isXhr();771 796 } 772 797 … … 777 802 * This code originally from Richard Heyes and Stefan Esser 778 803 */ 779 private function cleanGlobals()804 private static function cleanGlobals() 780 805 { 781 806 # Intercept GLOBALS overwrite … … 832 857 833 858 /** 834 * Handles possible Injections and clean up of $_REQUEST835 */836 private function sanitizeRequest()837 {838 # Filter for Request-Parameter: id839 if(isset($_REQUEST['id']) and ctype_digit($_REQUEST['id']))840 {841 $this->parameters['id'] = (int) $_REQUEST['id'];842 }843 844 # Filter for Request-Parameter: items845 if(isset($_REQUEST['items']) and ctype_digit($_REQUEST['items']))846 {847 $this->parameters['items'] = (int) $_REQUEST['items'];848 }849 850 # Filter for Request-Parameter: defaultCol (Smarty Paginate Get Variable)851 if(isset($_REQUEST['defaultCol']) and ctype_digit($_REQUEST['defaultCol']))852 {853 $this->parameters['defaultCol'] = (int) $_REQUEST['defaultCol'];854 }855 856 # Filter for Request-Parameter: defaultSort (Smarty Paginate Get Variable)857 if(isset($_REQUEST['defaultSort']) and ctype_alpha($_REQUEST['defaultSort']) and (($_REQUEST['defaultSort'] == 'desc') or ($_REQUEST['defaultSort'] == 'asc')) )858 {859 $this->parameters['defaultSort'] = (int) $_REQUEST['defaultSort'];860 }861 }862 863 /**864 859 * Revert magic_quotes() if still enabled 865 860 * stripslashes + array_deep + non_recursive … … 872 867 * @return Returns the magic quotes fixed $var 873 868 */ 874 private function fix_magic_quotes($input = null)875 { 876 if( $this->magic_quotes_gpc == false)869 private static function fix_magic_quotes($input = null) 870 { 871 if(self::$magic_quotes_gpc == false) 877 872 { 878 873 return $input;
Note: See TracChangeset
for help on using the changeset viewer.
