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 <?php
/** /**
* Every modules inherits from Object class. It includes error, message, and other variables for communicatin purpose. * Every modules inherits from Object class. It includes error, message, and other variables for communicatin purpose.
* *
@ -6,6 +7,7 @@
*/ */
class Object class Object
{ {
/** /**
* Error code. If `0`, it is not an error. * Error code. If `0`, it is not an error.
* @var int * @var int
@ -30,7 +32,6 @@ class Object
*/ */
var $httpStatusCode = NULL; var $httpStatusCode = NULL;
/** /**
* Constructor * Constructor
* *
@ -44,7 +45,6 @@ class Object
$this->setMessage($message); $this->setMessage($message);
} }
/** /**
* Setter to set error code * Setter to set error code
* *
@ -95,11 +95,12 @@ class Object
*/ */
function setMessage($message = 'success') function setMessage($message = 'success')
{ {
if(Context::getLang($message)) $message = Context::getLang($message); if(Context::getLang($message))
$message = Context::getLang($message);
$this->message = $message; $this->message = $message;
// TODO This method always returns True. We'd better remove it // TODO This method always returns True. We'd better remove it
return true; return TRUE;
} }
/** /**
@ -139,7 +140,10 @@ class Object
if(is_array($object)) if(is_array($object))
{ {
foreach($object as $key => $val) $this->variables[$key] = $val; foreach($object as $key => $val)
{
$this->variables[$key] = $val;
}
} }
} }
@ -154,7 +158,6 @@ class Object
return $this->variables[$key]; return $this->variables[$key];
} }
/** /**
* Method to retrieve an object containing a key/value paris * Method to retrieve an object containing a key/value paris
* *
@ -189,7 +192,11 @@ class Object
*/ */
function getObjectVars() function getObjectVars()
{ {
foreach($this->variables as $key => $val) $output->{$key} = $val; $output = new stdClass();
foreach($this->variables as $key => $val)
{
$output->{$key} = $val;
}
return $output; return $output;
} }
@ -201,10 +208,9 @@ class Object
function toBool() function toBool()
{ {
// TODO This method is misleading in that it returns true if error is 0, which should be true in boolean representation. // TODO This method is misleading in that it returns true if error is 0, which should be true in boolean representation.
return $this->error==0?true:false; return $this->error == 0 ? TRUE : FALSE;
} }
/** /**
* Method to return either true or false depnding on the value in a 'error' variable * Method to return either true or false depnding on the value in a 'error' variable
* *
@ -214,7 +220,7 @@ class Object
{ {
return $this->toBool(); return $this->toBool();
} }
}
}
/* End of file Object.class.php */ /* End of file Object.class.php */
/* Location: ./classes/object/Object.class.php */ /* Location: ./classes/object/Object.class.php */

View file

@ -1,4 +1,5 @@
<?php <?php
/** /**
* @class PageHandler * @class PageHandler
* @author NHN (developers@xpressengine.com) * @author NHN (developers@xpressengine.com)
@ -10,6 +11,7 @@
*/ */
class PageHandler extends Handler class PageHandler extends Handler
{ {
var $total_count = 0; ///< number of total items var $total_count = 0; ///< number of total items
var $total_page = 0; ///< number of total pages var $total_page = 0; ///< number of total pages
var $cur_page = 0; ///< current page number var $cur_page = 0; ///< current page number
@ -26,6 +28,7 @@ class PageHandler extends Handler
* @param int $page_count number of page links displayed at one time * @param int $page_count number of page links displayed at one time
* @return void * @return void
*/ */
function PageHandler($total_count, $total_page, $cur_page, $page_count = 10) function PageHandler($total_count, $total_page, $cur_page, $page_count = 10)
{ {
$this->total_count = $total_count; $this->total_count = $total_count;
@ -35,7 +38,10 @@ class PageHandler extends Handler
$this->point = 0; $this->point = 0;
$first_page = $cur_page - (int) ($page_count / 2); $first_page = $cur_page - (int) ($page_count / 2);
if($first_page<1) $first_page = 1; if($first_page < 1)
{
$first_page = 1;
}
if($total_page > $page_count && $first_page + $page_count - 1 > $total_page) if($total_page > $page_count && $first_page + $page_count - 1 > $total_page)
{ {
@ -43,12 +49,18 @@ class PageHandler extends Handler
} }
$last_page = $total_page; $last_page = $total_page;
if($last_page>$total_page) $last_page = $total_page; if($last_page > $total_page)
{
$last_page = $total_page;
}
$this->first_page = $first_page; $this->first_page = $first_page;
$this->last_page = $last_page; $this->last_page = $last_page;
if($total_page < $this->page_count) $this->page_count = $total_page; if($total_page < $this->page_count)
{
$this->page_count = $total_page;
}
} }
/** /**
@ -58,7 +70,10 @@ class PageHandler extends Handler
function getNextPage() function getNextPage()
{ {
$page = $this->first_page + $this->point++; $page = $this->first_page + $this->point++;
if($this->point > $this->page_count || $page > $this->last_page) $page = 0; if($this->point > $this->page_count || $page > $this->last_page)
{
$page = 0;
}
return $page; return $page;
} }
@ -71,6 +86,7 @@ class PageHandler extends Handler
{ {
return max(min($this->cur_page + $offset, $this->total_page), ''); return max(min($this->cur_page + $offset, $this->total_page), '');
} }
} }
/* End of file PageHandler.class.php */ /* End of file PageHandler.class.php */
/* Location: ./classes/page/PageHandler.class.php */ /* Location: ./classes/page/PageHandler.class.php */

View file

@ -1,13 +1,16 @@
<?php <?php
include _XE_PATH_ . 'classes/security/phphtmlparser/src/htmlparser.inc'; include _XE_PATH_ . 'classes/security/phphtmlparser/src/htmlparser.inc';
class EmbedFilter class EmbedFilter
{ {
/** /**
* allow script access list * allow script access list
* @var array * @var array
*/ */
var $allowscriptaccessList = array(); var $allowscriptaccessList = array();
/** /**
* allow script access key * allow script access key
* @var int * @var int
@ -369,9 +372,9 @@ class EmbedFilter
{ {
foreach($embedTagList AS $key => $embedTag) foreach($embedTagList AS $key => $embedTag)
{ {
$isWhiteDomain = true; $isWhiteDomain = TRUE;
$isWhiteMimetype = true; $isWhiteMimetype = TRUE;
$isWhiteExt = true; $isWhiteExt = TRUE;
$ext = ''; $ext = '';
$parser = new HtmlParser($embedTag); $parser = new HtmlParser($embedTag);
@ -425,7 +428,7 @@ class EmbedFilter
{ {
foreach($iframeTagList AS $key => $iframeTag) foreach($iframeTagList AS $key => $iframeTag)
{ {
$isWhiteDomain = true; $isWhiteDomain = TRUE;
$ext = ''; $ext = '';
$parser = new HtmlParser($iframeTag); $parser = new HtmlParser($iframeTag);
@ -465,8 +468,8 @@ class EmbedFilter
{ {
foreach($paramTagList AS $key => $paramTag) foreach($paramTagList AS $key => $paramTag)
{ {
$isWhiteDomain = true; $isWhiteDomain = TRUE;
$isWhiteExt = true; $isWhiteExt = TRUE;
$ext = ''; $ext = '';
$parser = new HtmlParser($paramTag); $parser = new HtmlParser($paramTag);
@ -508,11 +511,11 @@ class EmbedFilter
{ {
if(preg_match('@^' . preg_quote($value) . '@i', $urlAttribute)) if(preg_match('@^' . preg_quote($value) . '@i', $urlAttribute))
{ {
return true; return TRUE;
} }
} }
} }
return false; return FALSE;
} }
/** /**
@ -527,11 +530,11 @@ class EmbedFilter
{ {
if(preg_match('@^' . preg_quote($value) . '@i', $urlAttribute)) if(preg_match('@^' . preg_quote($value) . '@i', $urlAttribute))
{ {
return true; return TRUE;
} }
} }
} }
return false; return FALSE;
} }
/** /**
@ -542,18 +545,18 @@ class EmbedFilter
{ {
if(isset($this->mimeTypeList[$mimeType])) if(isset($this->mimeTypeList[$mimeType]))
{ {
return true; return TRUE;
} }
return false; return FALSE;
} }
function isWhiteExt($ext) function isWhiteExt($ext)
{ {
if(isset($this->extList[$ext])) if(isset($this->extList[$ext]))
{ {
return true; return TRUE;
} }
return false; return FALSE;
} }
function _checkAllowScriptAccess($m) function _checkAllowScriptAccess($m)
@ -627,7 +630,9 @@ class EmbedFilter
$embedDomainList = $domainListObj->whiteurl->embed->domain; $embedDomainList = $domainListObj->whiteurl->embed->domain;
$iframeDomainList = $domainListObj->whiteurl->iframe->domain; $iframeDomainList = $domainListObj->whiteurl->iframe->domain;
$buff = '<?php if(!defined("__ZBXE__")) exit();'; $buff = '<?php if(!defined("__XE__")) exit();';
$buff .= '$whiteUrlList = array();';
$buff .= '$whiteIframeUrlList = array();';
if(is_array($embedDomainList)) if(is_array($embedDomainList))
{ {
foreach($embedDomainList AS $key => $value) foreach($embedDomainList AS $key => $value)
@ -640,7 +645,8 @@ class EmbedFilter
$buff .= sprintf('$whiteUrlList[] = \'%s\';', $value->body); $buff .= sprintf('$whiteUrlList[] = \'%s\';', $value->body);
} }
} }
else $buff .= sprintf('$whiteUrlList[] = \'%s\';', $patternList->body); else
$buff .= sprintf('$whiteUrlList[] = \'%s\';', $patternList->body);
} }
} }
@ -656,13 +662,15 @@ class EmbedFilter
$buff .= sprintf('$whiteIframeUrlList[] = \'%s\';', $value->body); $buff .= sprintf('$whiteIframeUrlList[] = \'%s\';', $value->body);
} }
} }
else $buff .= sprintf('$whiteIframeUrlList[] = \'%s\';', $patternList->body); else
$buff .= sprintf('$whiteIframeUrlList[] = \'%s\';', $patternList->body);
} }
} }
$buff .= '?>'; $buff .= '?>';
FileHandler::writeFile($this->whiteUrlCacheFile, $buff); FileHandler::writeFile($this->whiteUrlCacheFile, $buff);
} }
} }
} }
/* End of file : EmbedFilter.class.php */ /* End of file : EmbedFilter.class.php */
/* Location: ./classes/security/EmbedFilter.class.php */ /* Location: ./classes/security/EmbedFilter.class.php */

View file

@ -1,6 +1,8 @@
<?php <?php
class Purifier class Purifier
{ {
private $_cacheDir; private $_cacheDir;
private $_htmlPurifier; private $_htmlPurifier;
private $_config; private $_config;
@ -33,13 +35,13 @@ class Purifier
$this->_config = HTMLPurifier_Config::createDefault(); $this->_config = HTMLPurifier_Config::createDefault();
$this->_config->set('HTML.TidyLevel', 'light'); $this->_config->set('HTML.TidyLevel', 'light');
$this->_config->set('HTML.SafeObject', true); $this->_config->set('HTML.SafeObject', TRUE);
$this->_config->set('HTML.SafeIframe', true); $this->_config->set('HTML.SafeIframe', TRUE);
$this->_config->set('URI.SafeIframeRegexp', $whiteDomainRegex); $this->_config->set('URI.SafeIframeRegexp', $whiteDomainRegex);
$this->_config->set('Cache.SerializerPath', $this->_cacheDir); $this->_config->set('Cache.SerializerPath', $this->_cacheDir);
$this->_config->set('Attr.AllowedClasses', $allowdClasses); $this->_config->set('Attr.AllowedClasses', $allowdClasses);
$this->_def = $this->_config->getHTMLDefinition(true); $this->_def = $this->_config->getHTMLDefinition(TRUE);
} }
private function _setDefinition(&$content) private function _setDefinition(&$content)
@ -160,7 +162,7 @@ class Purifier
$content = $this->_htmlPurifier->purify($content); $content = $this->_htmlPurifier->purify($content);
} }
}
}
/* End of file : Purifier.class.php */ /* End of file : Purifier.class.php */
/* Location: ./classes/security/Purifier.class.php */ /* Location: ./classes/security/Purifier.class.php */

View file

@ -1,4 +1,5 @@
<?php <?php
/** /**
* - Security class * - Security class
* - This class helps to solve security problems. * - This class helps to solve security problems.
@ -8,18 +9,19 @@
*/ */
class Security class Security
{ {
/** /**
* Action target variable. If this value is null, the method will use Context variables * Action target variable. If this value is null, the method will use Context variables
* @var mixed * @var mixed
*/ */
var $_targetVar = null; var $_targetVar = NULL;
/** /**
* @constructor * @constructor
* @param mixed $var Target context * @param mixed $var Target context
* @return void * @return void
*/ */
function Security($var = null) function Security($var = NULL)
{ {
$this->_targetVar = $var; $this->_targetVar = $var;
} }
@ -34,12 +36,18 @@ class Security
function encodeHTML(/* , $varName1, $varName2, ... */) function encodeHTML(/* , $varName1, $varName2, ... */)
{ {
$varNames = func_get_args(); $varNames = func_get_args();
if(count($varNames) < 0) return false; if(count($varNames) < 0)
{
return FALSE;
}
$use_context = is_null($this->_targetVar); $use_context = is_null($this->_targetVar);
if(!$use_context) 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); $is_object = is_object($this->_targetVar);
} }
@ -62,7 +70,10 @@ class Security
} }
$var = $this->_encodeHTML($var, $varName); $var = $this->_encodeHTML($var, $varName);
if($var === false) continue; if($var === FALSE)
{
continue;
}
if($use_context) if($use_context)
{ {
@ -70,8 +81,14 @@ class Security
} }
elseif($varName0) elseif($varName0)
{ {
if($is_object) $this->_targetVar->{$varName0} = $var; if($is_object)
else $this->_targetVar[$varName0] = $var; {
$this->_targetVar->{$varName0} = $var;
}
else
{
$this->_targetVar[$varName0] = $var;
}
} }
else else
{ {
@ -79,7 +96,10 @@ class Security
} }
} }
if (!$use_context) return $this->_targetVar; if(!$use_context)
{
return $this->_targetVar;
}
} }
/** /**
@ -92,11 +112,17 @@ class Security
{ {
if(is_string($var)) if(is_string($var))
{ {
if (!preg_match('/^\$user_lang->/', $var)) $var = htmlspecialchars($var); if(!preg_match('/^\$user_lang->/', $var))
{
$var = htmlspecialchars($var);
}
return $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); $is_object = is_object($var);
$name0 = array_shift($name); $name0 = array_shift($name);
@ -106,10 +132,19 @@ class Security
$target = $is_object ? $var->{$name0} : $var[$name0]; $target = $is_object ? $var->{$name0} : $var[$name0];
$target = $this->_encodeHTML($target, $name); $target = $this->_encodeHTML($target, $name);
if($target === false) return $var; if($target === false)
{
return $var;
}
if($is_object) $var->{$name0} = $target; if($is_object)
else $var[$name0] = $target; {
$var->{$name0} = $target;
}
else
{
$var[$name0] = $target;
}
return $var; return $var;
} }
@ -120,15 +155,24 @@ class Security
$target = $this->_encodeHTML($target, $name); $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; if($is_object)
else $var[$key] = $target; {
$var->{$key} = $target;
}
else
{
$var[$key] = $target;
}
} }
return $var; return $var;
} }
}
}
/* End of file : Security.class.php */ /* End of file : Security.class.php */
/* Location: ./classes/security/Security.class.php */ /* Location: ./classes/security/Security.class.php */