issue 2119. supporting php 5.4. object, page and security classes.

git-svn-id: http://xe-core.googlecode.com/svn/branches/maserati@12693 201d5d3c-b55e-5fd7-737f-ddc643e51545
This commit is contained in:
flyskyko 2013-02-05 02:33:02 +00:00
parent 9b5bee6544
commit 915cdb3824
5 changed files with 409 additions and 333 deletions

View file

@ -1,4 +1,5 @@
<?php
/**
* - Security class
* - This class helps to solve security problems.
@ -8,18 +9,19 @@
*/
class Security
{
/**
* Action target variable. If this value is null, the method will use Context variables
* @var mixed
*/
var $_targetVar = null;
var $_targetVar = NULL;
/**
* @constructor
* @param mixed $var Target context
* @return void
*/
function Security($var = null)
function Security($var = NULL)
{
$this->_targetVar = $var;
}
@ -31,22 +33,28 @@ class Security
* separate the owner(object or array) and the item(property or element) using a dot(.)
* @return mixed
*/
function encodeHTML(/*, $varName1, $varName2, ... */)
function encodeHTML(/* , $varName1, $varName2, ... */)
{
$varNames = func_get_args();
if(count($varNames) < 0) return false;
if(count($varNames) < 0)
{
return FALSE;
}
$use_context = is_null($this->_targetVar);
if(!$use_context)
{
if(!count($varNames) || (!is_object($this->_targetVar) && !is_array($this->_targetVar)) ) return $this->_encodeHTML($this->_targetVar);
if(!count($varNames) || (!is_object($this->_targetVar) && !is_array($this->_targetVar)))
{
return $this->_encodeHTML($this->_targetVar);
}
$is_object = is_object($this->_targetVar);
}
foreach($varNames as $varName)
{
$varName = explode('.', $varName);
$varName = explode('.', $varName);
$varName0 = array_shift($varName);
if($use_context)
{
@ -62,7 +70,10 @@ class Security
}
$var = $this->_encodeHTML($var, $varName);
if($var === false) continue;
if($var === FALSE)
{
continue;
}
if($use_context)
{
@ -70,8 +81,14 @@ class Security
}
elseif($varName0)
{
if($is_object) $this->_targetVar->{$varName0} = $var;
else $this->_targetVar[$varName0] = $var;
if($is_object)
{
$this->_targetVar->{$varName0} = $var;
}
else
{
$this->_targetVar[$varName0] = $var;
}
}
else
{
@ -79,7 +96,10 @@ class Security
}
}
if (!$use_context) return $this->_targetVar;
if(!$use_context)
{
return $this->_targetVar;
}
}
/**
@ -88,47 +108,71 @@ class Security
* @param array $name
* @return mixed
*/
function _encodeHTML($var, $name=array())
function _encodeHTML($var, $name = array())
{
if(is_string($var))
{
if (!preg_match('/^\$user_lang->/', $var)) $var = htmlspecialchars($var);
if(!preg_match('/^\$user_lang->/', $var))
{
$var = htmlspecialchars($var);
}
return $var;
}
if(!count($name) || (!is_array($var) && !is_object($var)) ) return false;
if(!count($name) || (!is_array($var) && !is_object($var)))
{
return false;
}
$is_object = is_object($var);
$name0 = array_shift($name);
$name0 = array_shift($name);
if(strlen($name0))
{
$target = $is_object ? $var->{$name0} : $var[$name0];
$target = $this->_encodeHTML($target, $name);
if($target === false) return $var;
if($target === false)
{
return $var;
}
if($is_object) $var->{$name0} = $target;
else $var[$name0] = $target;
if($is_object)
{
$var->{$name0} = $target;
}
else
{
$var[$name0] = $target;
}
return $var;
}
foreach($var as $key=>$target)
foreach($var as $key => $target)
{
$cloned_name = array_slice($name, 0);
$target = $this->_encodeHTML($target, $name);
$name = $cloned_name;
$name = $cloned_name;
if($target === false) continue;
if($target === false)
{
continue;
}
if($is_object) $var->{$key} = $target;
else $var[$key] = $target;
if($is_object)
{
$var->{$key} = $target;
}
else
{
$var[$key] = $target;
}
}
return $var;
}
}
}
/* End of file : Security.class.php */
/* Location: ./classes/security/Security.class.php */