Location: PHPKode > projects > FarODP > farodp/includes/common/WebRequest.php
<?php

class WebRequest {
	var $MAX_INT_VALUE = 0xffffffff;
	var $safeVal = array();

	function WebRequest() {
		if (get_magic_quotes_gpc()) {
		    $_POST = $this->stripslashes_deep($_POST);
		    $_GET = $this->stripslashes_deep($_GET);
			$_COOKIE = $this->stripslashes_deep($_COOKIE);
		}

	    foreach ($_GET as $k=>$v) {
	        $this->safeVal[$k] = $v;
	    }

	    foreach ($_POST as $k=>$v) {
	        if ($v != '')
	        	$this->safeVal[$k] = $v;
	    }
	}

	function getRequest() {
	    return $this->safeVal;
	}

	function stripslashes_deep($value) {
		$value = is_array($value) ? array_map(array(&$this, 'stripslashes_deep'), $value) : stripslashes($value);
		return $value;
	}

	function getVal($name, $default = '') {
	    if (isset($this->safeVal[$name]) && is_string($this->safeVal[$name]))
	    	return $this->safeVal[$name];
		else
		    return $this->safeVal[$name] = $default;
	}

	function issetVal($name) {
	    return (isset($_POST[$name]));
	}

	function getInt($name, $default = '') {
		$val = $this->getVal($name, $default);
		if ($val > $this->MAX_INT_VALUE) {
		    return $default;
		}
	    if (ctype_digit($val)) {
	        return (int) $val;
	    }
	    return $default;
	}

	function getPageNum($name, $default = '') {
		$integer = $this->getInt($name, $default);
		if ($integer === 0 ) {
		    return $default;
		}

		return $integer - 1;
	}

	function getBool($name, $default = '') {
		return $this->getVal($name, $default) ? true : false;
	}

	function getCat($name, $default = array()) {
		global $action;
	
	    $cat = $this->getVal($name, $default);
	    
	    if (strpos($cat, '//') !== false) // URL not canonical
	    {
	        $action->setAction('URLNotCanonical');
	    }
	    
		return urlCat($cat);
	}

	function getOptions($arr, $default = '') {
	    foreach ($arr as $v) {
	        if ($this->getBool($v)) {
	            return $v;
	        }
	    }
	    return $default;
	}

	function getTitle($name, $default = '', $limit = 500) {
	    return (string) str_replace('_', ' ', substr($this->getVal($name, $default), 0, $limit));
	}

	function getString($name, $default = '', $limit = 500) {
	    return (string) substr($this->getVal($name, $default), 0, $limit);
	}

	function escapeString($str) {
	    return str_replace(' ', '_', $str);
	}

	function hasGet() {
		if (!empty($_GET)) {
		    return true;
		}
		return false;
	}

	function hasPost() {
		if (!empty($_POST)) {
		    return true;
		}
		return false;
	}
}

?>
Return current item: FarODP