mirror of
https://github.com/Lastorder-DC/rhymix.git
synced 2026-05-08 11:33:55 +09:00
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:
parent
9b5bee6544
commit
915cdb3824
5 changed files with 409 additions and 333 deletions
|
|
@ -1,4 +1,5 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* Every modules inherits from Object class. It includes error, message, and other variables for communicatin purpose.
|
||||
*
|
||||
|
|
@ -6,6 +7,7 @@
|
|||
*/
|
||||
class Object
|
||||
{
|
||||
|
||||
/**
|
||||
* Error code. If `0`, it is not an error.
|
||||
* @var int
|
||||
|
|
@ -30,7 +32,6 @@ class Object
|
|||
*/
|
||||
var $httpStatusCode = NULL;
|
||||
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
|
|
@ -44,7 +45,6 @@ class Object
|
|||
$this->setMessage($message);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Setter to set error code
|
||||
*
|
||||
|
|
@ -95,11 +95,12 @@ class Object
|
|||
*/
|
||||
function setMessage($message = 'success')
|
||||
{
|
||||
if(Context::getLang($message)) $message = Context::getLang($message);
|
||||
if(Context::getLang($message))
|
||||
$message = Context::getLang($message);
|
||||
$this->message = $message;
|
||||
|
||||
// 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))
|
||||
{
|
||||
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];
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Method to retrieve an object containing a key/value paris
|
||||
*
|
||||
|
|
@ -189,7 +192,11 @@ class Object
|
|||
*/
|
||||
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;
|
||||
}
|
||||
|
||||
|
|
@ -201,10 +208,9 @@ class Object
|
|||
function toBool()
|
||||
{
|
||||
// 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
|
||||
*
|
||||
|
|
@ -214,7 +220,7 @@ class Object
|
|||
{
|
||||
return $this->toBool();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
/* End of file Object.class.php */
|
||||
/* Location: ./classes/object/Object.class.php */
|
||||
|
|
|
|||
|
|
@ -1,4 +1,5 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @class PageHandler
|
||||
* @author NHN (developers@xpressengine.com)
|
||||
|
|
@ -10,6 +11,7 @@
|
|||
*/
|
||||
class PageHandler extends Handler
|
||||
{
|
||||
|
||||
var $total_count = 0; ///< number of total items
|
||||
var $total_page = 0; ///< number of total pages
|
||||
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
|
||||
* @return void
|
||||
*/
|
||||
|
||||
function PageHandler($total_count, $total_page, $cur_page, $page_count = 10)
|
||||
{
|
||||
$this->total_count = $total_count;
|
||||
|
|
@ -35,7 +38,10 @@ class PageHandler extends Handler
|
|||
$this->point = 0;
|
||||
|
||||
$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)
|
||||
{
|
||||
|
|
@ -43,12 +49,18 @@ class PageHandler extends Handler
|
|||
}
|
||||
|
||||
$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->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()
|
||||
{
|
||||
$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;
|
||||
}
|
||||
|
||||
|
|
@ -71,6 +86,7 @@ class PageHandler extends Handler
|
|||
{
|
||||
return max(min($this->cur_page + $offset, $this->total_page), '');
|
||||
}
|
||||
|
||||
}
|
||||
/* End of file PageHandler.class.php */
|
||||
/* Location: ./classes/page/PageHandler.class.php */
|
||||
|
|
|
|||
|
|
@ -1,13 +1,16 @@
|
|||
<?php
|
||||
|
||||
include _XE_PATH_ . 'classes/security/phphtmlparser/src/htmlparser.inc';
|
||||
|
||||
class EmbedFilter
|
||||
{
|
||||
|
||||
/**
|
||||
* allow script access list
|
||||
* @var array
|
||||
*/
|
||||
var $allowscriptaccessList = array();
|
||||
|
||||
/**
|
||||
* allow script access key
|
||||
* @var int
|
||||
|
|
@ -369,9 +372,9 @@ class EmbedFilter
|
|||
{
|
||||
foreach($embedTagList AS $key => $embedTag)
|
||||
{
|
||||
$isWhiteDomain = true;
|
||||
$isWhiteMimetype = true;
|
||||
$isWhiteExt = true;
|
||||
$isWhiteDomain = TRUE;
|
||||
$isWhiteMimetype = TRUE;
|
||||
$isWhiteExt = TRUE;
|
||||
$ext = '';
|
||||
|
||||
$parser = new HtmlParser($embedTag);
|
||||
|
|
@ -425,7 +428,7 @@ class EmbedFilter
|
|||
{
|
||||
foreach($iframeTagList AS $key => $iframeTag)
|
||||
{
|
||||
$isWhiteDomain = true;
|
||||
$isWhiteDomain = TRUE;
|
||||
$ext = '';
|
||||
|
||||
$parser = new HtmlParser($iframeTag);
|
||||
|
|
@ -465,8 +468,8 @@ class EmbedFilter
|
|||
{
|
||||
foreach($paramTagList AS $key => $paramTag)
|
||||
{
|
||||
$isWhiteDomain = true;
|
||||
$isWhiteExt = true;
|
||||
$isWhiteDomain = TRUE;
|
||||
$isWhiteExt = TRUE;
|
||||
$ext = '';
|
||||
|
||||
$parser = new HtmlParser($paramTag);
|
||||
|
|
@ -508,11 +511,11 @@ class EmbedFilter
|
|||
{
|
||||
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))
|
||||
{
|
||||
return true;
|
||||
return TRUE;
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -542,18 +545,18 @@ class EmbedFilter
|
|||
{
|
||||
if(isset($this->mimeTypeList[$mimeType]))
|
||||
{
|
||||
return true;
|
||||
return TRUE;
|
||||
}
|
||||
return false;
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
function isWhiteExt($ext)
|
||||
{
|
||||
if(isset($this->extList[$ext]))
|
||||
{
|
||||
return true;
|
||||
return TRUE;
|
||||
}
|
||||
return false;
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
function _checkAllowScriptAccess($m)
|
||||
|
|
@ -627,7 +630,9 @@ class EmbedFilter
|
|||
$embedDomainList = $domainListObj->whiteurl->embed->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))
|
||||
{
|
||||
foreach($embedDomainList AS $key => $value)
|
||||
|
|
@ -640,7 +645,8 @@ class EmbedFilter
|
|||
$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);
|
||||
}
|
||||
}
|
||||
else $buff .= sprintf('$whiteIframeUrlList[] = \'%s\';', $patternList->body);
|
||||
else
|
||||
$buff .= sprintf('$whiteIframeUrlList[] = \'%s\';', $patternList->body);
|
||||
}
|
||||
}
|
||||
$buff .= '?>';
|
||||
FileHandler::writeFile($this->whiteUrlCacheFile, $buff);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
/* End of file : EmbedFilter.class.php */
|
||||
/* Location: ./classes/security/EmbedFilter.class.php */
|
||||
|
|
|
|||
|
|
@ -1,6 +1,8 @@
|
|||
<?php
|
||||
|
||||
class Purifier
|
||||
{
|
||||
|
||||
private $_cacheDir;
|
||||
private $_htmlPurifier;
|
||||
private $_config;
|
||||
|
|
@ -33,13 +35,13 @@ class Purifier
|
|||
|
||||
$this->_config = HTMLPurifier_Config::createDefault();
|
||||
$this->_config->set('HTML.TidyLevel', 'light');
|
||||
$this->_config->set('HTML.SafeObject', true);
|
||||
$this->_config->set('HTML.SafeIframe', true);
|
||||
$this->_config->set('HTML.SafeObject', TRUE);
|
||||
$this->_config->set('HTML.SafeIframe', TRUE);
|
||||
$this->_config->set('URI.SafeIframeRegexp', $whiteDomainRegex);
|
||||
$this->_config->set('Cache.SerializerPath', $this->_cacheDir);
|
||||
$this->_config->set('Attr.AllowedClasses', $allowdClasses);
|
||||
|
||||
$this->_def = $this->_config->getHTMLDefinition(true);
|
||||
$this->_def = $this->_config->getHTMLDefinition(TRUE);
|
||||
}
|
||||
|
||||
private function _setDefinition(&$content)
|
||||
|
|
@ -160,7 +162,7 @@ class Purifier
|
|||
|
||||
$content = $this->_htmlPurifier->purify($content);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
/* End of file : Purifier.class.php */
|
||||
/* Location: ./classes/security/Purifier.class.php */
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
}
|
||||
|
|
@ -34,12 +36,18 @@ class Security
|
|||
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);
|
||||
}
|
||||
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -92,11 +112,17 @@ class Security
|
|||
{
|
||||
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);
|
||||
|
|
@ -106,10 +132,19 @@ class Security
|
|||
$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;
|
||||
}
|
||||
|
|
@ -120,15 +155,24 @@ class Security
|
|||
$target = $this->_encodeHTML($target, $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 */
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue