Find this useful? Enter your email to receive occasional updates for securing PHP code.
Signing you up...
Thank you for signing up!
PHP Decode
<?php namespace Swoole; /** * * * @package SwooleSystem * @author Tianfeng.Han * @..
Decoded Output download
<?php
namespace Swoole;
/**
*
*
* @package SwooleSystem
* @author Tianfeng.Han
* @subpackage MVC
*/
class View extends \ArrayObject
{
protected $_var = array();
protected $trace = array();
protected $swoole;
public $template_dir = '';
public $if_pagecache = false;
public $cache_life = 3600;
public $show_runtime = false;
function __construct($swoole)
{
$this->swoole = $swoole;
$this->template_dir = \Swoole::$app_path . '/views/';
}
/**
* +----------------------------------------------------------
*
* +----------------------------------------------------------
* @access public
* +----------------------------------------------------------
* @param mixed $name
* @param mixed $value
+----------------------------------------------------------
*/
public function assign($name, $value = '')
{
if (is_array($name))
{
$this->_var = array_merge($this->_var, $name);
}
elseif (is_object($name))
{
foreach ($name as $key => $val)
{
$this->_var[$key] = $val;
}
}
else
{
$this->_var[$name] = $value;
}
}
/**
* +----------------------------------------------------------
* Trace
* +----------------------------------------------------------
* @access public
* +----------------------------------------------------------
* @param mixed $name
* @param mixed $value
+----------------------------------------------------------
*/
public function trace($title, $value = '')
{
if (is_array($title))
{
$this->trace = array_merge($this->trace, $title);
}
else
{
$this->trace[$title] = $value;
}
}
/**
* +----------------------------------------------------------
*
* +----------------------------------------------------------
* @access public
* +----------------------------------------------------------
* @param string $name
+----------------------------------------------------------
* @return mixed
+----------------------------------------------------------
*/
public function get($name)
{
if (isset($this->_var[$name]))
{
return $this->_var[$name];
}
else
{
return false;
}
}
/**
* +----------------------------------------------------------
*
* +----------------------------------------------------------
* @access public
* +----------------------------------------------------------
* @param string $templateFile
* @param string $charset
* @param string $contentType
* +----------------------------------------------------------
* @return mixed
+----------------------------------------------------------
*/
public function display($templateFile = '', $charset = '', $contentType = 'text/html')
{
$this->fetch($templateFile, $charset, $contentType, true);
}
/**
* +----------------------------------------------------------
*
* +----------------------------------------------------------
* @access public
* +----------------------------------------------------------
* @param string $charset
* @param string $contentType
* @param string $display
* +----------------------------------------------------------
* @return mixed
+----------------------------------------------------------
*/
public function layout($content, $charset = '', $contentType = 'text/html')
{
//
$find = preg_match_all('/<!-- layout::(.+?)::(.+?) -->/is', $content, $matches);
if ($find)
{
for ($i = 0; $i < $find; $i++)
{
//
if (0 === strpos($matches[1][$i], '$'))
{
//
$matches[1][$i] = $this->get(substr($matches[1][$i], 1));
}
if (0 != $matches[2][$i])
{
//
//
$guid = md5($matches[1][$i]);
$cache = S($guid);
if ($cache)
{
$layoutContent = $cache;
}
else
{
$layoutContent = $this->fetch($matches[1][$i], $charset, $contentType);
S($guid, $layoutContent, $matches[2][$i]);
}
}
else
{
$layoutContent = $this->fetch($matches[1][$i], $charset, $contentType);
}
$content = str_replace($matches[0][$i], $layoutContent, $content);
}
}
return $content;
}
/**
* +----------------------------------------------------------
*
* +----------------------------------------------------------
* @access public
* +----------------------------------------------------------
* @param string $templateFile
* @param string $charset
* @param string $contentType
* @param string $display
* +----------------------------------------------------------
* @return mixed
+----------------------------------------------------------
*/
public function fetch($templateFile = '', $charset = '', $contentType = 'text/html', $display = false)
{
$GLOBALS['_viewStartTime'] = microtime(true);
if (null === $templateFile)
{
// null
return;
}
if (empty($charset))
{
$charset = 'utf-8';
}
//
header("Content-Type:" . $contentType . "; charset=" . $charset);
header("Cache-control: private"); //
//
ob_start();
ob_implicit_flush(0);
$this->render($templateFile);
//
$content = ob_get_clean();
//
$content = $this->layout($content, $charset, $contentType);
//
return $this->output($content, $display);
}
private function render($templateFile)
{
extract($this->_var);
$templateFile = $this->parseTemplateFile($templateFile);
require($templateFile);
}
/**
* +----------------------------------------------------------
*
* +----------------------------------------------------------
* @access public
* +----------------------------------------------------------
* @htmlfile
* @param string $templateFile
*
* @param string $charset
* @param string $contentType
* +----------------------------------------------------------
* @return string
+----------------------------------------------------------
*/
public function buildHtml($htmlfile = '', $templateFile = '', $charset = '', $contentType = 'text/html')
{
$content = $this->fetch($templateFile, $charset, $contentType);
if (empty($htmlfile))
{
$htmlfile = HTML_PATH . rtrim($_SERVER['PATH_INFO'], '/') . C('HTML_FILE_SUFFIX');
}
if (!is_dir(dirname($htmlfile)))
{
//
mk_dir(dirname($htmlfile));
}
if (false === file_put_contents($htmlfile, $content))
{
throw_exception(L('_CACHE_WRITE_ERROR_'));
}
return $content;//readfile($htmlfile);
}
/**
* +----------------------------------------------------------
*
* +----------------------------------------------------------
* @access protected
* +----------------------------------------------------------
* @param string $content
* @param boolean $display
* +----------------------------------------------------------
* @return mixed
+----------------------------------------------------------
*/
protected function output($content, $display)
{
if ($this->if_pagecache)
{
$pagecache = new Swoole_pageCache($this->cache_life);
if ($pagecache->isCached())
{
$pagecache->load();
}
else
{
$pagecache->create($content);
}
}
if ($display)
{
$showTime = $this->showTime();
echo $content;
if ($this->show_runtime)
{
$this->showTrace();
}
return null;
}
else
{
return $content;
}
}
private function parseTemplateFile($templateFile)
{
if ('' == $templateFile)
{
$templateFile = $this->swoole->env['mvc']['controller'] . '_' . $this->swoole->env['mvc']['view'] . '.html';
}
$templateFile = $this->template_dir . $templateFile;
if (!file_exists($templateFile))
{
Error::info('View Error!', 'Template file not exists! <b>' . $templateFile . '</b>');
}
return $templateFile;
}
/**
* +----------------------------------------------------------
*
* +----------------------------------------------------------
* @access protected
* +----------------------------------------------------------
* @return string
+----------------------------------------------------------
*/
protected function showTime()
{
//
$startTime = $this->swoole->env['runtime']['start'];
$endTime = microtime(true);
$total_run_time = number_format(($endTime - $startTime), 4);
$showTime = ': ' . $total_run_time . 's ';
$startMem = array_sum(explode(' ', $this->swoole->env['runtime']['mem']));
$endMem = array_sum(explode(' ', memory_get_usage()));
$showTime .= ' | :' . number_format(($endMem - $startMem) / 1024) . ' kb';
return $showTime;
}
/**
* +----------------------------------------------------------
* Trace
* +----------------------------------------------------------
* @access protected
* +----------------------------------------------------------
* @param string $showTime
* +----------------------------------------------------------
*/
public function showTrace($detail = false)
{
// Trace Trace
// return array(''=>$_SERVER['PHP_SELF'],''=>$_SERVER['SERVER_PROTOCOL'],...);
$_trace = array();
//
$this->trace('', $_SERVER['REQUEST_URI']);
$this->trace('', $_SERVER['REQUEST_METHOD']);
$this->trace('', $_SERVER['SERVER_PROTOCOL']);
$this->trace('', date('Y-m-d H:i:s', $_SERVER['REQUEST_TIME']));
$this->trace('', $_SERVER['HTTP_USER_AGENT']);
if (isset($_SESSION))
{
$this->trace('ID', session_id());
}
$this->trace('', $this->swoole->db->read_times . '');
$this->trace('', $this->swoole->db->write_times . '');
$included_files = get_included_files();
$this->trace('', count($included_files));
$this->trace('PHP', $this->showTime());
$_trace = array_merge($_trace, $this->trace);
// Trace
echo <<<HTML
<div id="think_page_trace" style="background:white;margin:6px;font-size:14px;border:1px dashed silver;padding:8px">
<fieldset id="querybox" style="margin:5px;">
<legend style="color:gray;font-weight:bold">Trace</legend>
<div style="overflow:auto;height:300px;text-align:left;">
HTML;
foreach ($_trace as $key => $info)
{
echo $key . ' : ' . $info . '<br/>';
}
if ($detail)
{
//
echo '<br/>';
foreach ($included_files as $file)
{
echo 'require ' . $file . '<br/>';
}
}
echo "</div></fieldset> </div>";
}
}
?>
Did this file decode correctly?
Original Code
<?php
namespace Swoole;
/**
*
*
* @package SwooleSystem
* @author Tianfeng.Han
* @subpackage MVC
*/
class View extends \ArrayObject
{
protected $_var = array();
protected $trace = array();
protected $swoole;
public $template_dir = '';
public $if_pagecache = false;
public $cache_life = 3600;
public $show_runtime = false;
function __construct($swoole)
{
$this->swoole = $swoole;
$this->template_dir = \Swoole::$app_path . '/views/';
}
/**
* +----------------------------------------------------------
*
* +----------------------------------------------------------
* @access public
* +----------------------------------------------------------
* @param mixed $name
* @param mixed $value
+----------------------------------------------------------
*/
public function assign($name, $value = '')
{
if (is_array($name))
{
$this->_var = array_merge($this->_var, $name);
}
elseif (is_object($name))
{
foreach ($name as $key => $val)
{
$this->_var[$key] = $val;
}
}
else
{
$this->_var[$name] = $value;
}
}
/**
* +----------------------------------------------------------
* Trace
* +----------------------------------------------------------
* @access public
* +----------------------------------------------------------
* @param mixed $name
* @param mixed $value
+----------------------------------------------------------
*/
public function trace($title, $value = '')
{
if (is_array($title))
{
$this->trace = array_merge($this->trace, $title);
}
else
{
$this->trace[$title] = $value;
}
}
/**
* +----------------------------------------------------------
*
* +----------------------------------------------------------
* @access public
* +----------------------------------------------------------
* @param string $name
+----------------------------------------------------------
* @return mixed
+----------------------------------------------------------
*/
public function get($name)
{
if (isset($this->_var[$name]))
{
return $this->_var[$name];
}
else
{
return false;
}
}
/**
* +----------------------------------------------------------
*
* +----------------------------------------------------------
* @access public
* +----------------------------------------------------------
* @param string $templateFile
* @param string $charset
* @param string $contentType
* +----------------------------------------------------------
* @return mixed
+----------------------------------------------------------
*/
public function display($templateFile = '', $charset = '', $contentType = 'text/html')
{
$this->fetch($templateFile, $charset, $contentType, true);
}
/**
* +----------------------------------------------------------
*
* +----------------------------------------------------------
* @access public
* +----------------------------------------------------------
* @param string $charset
* @param string $contentType
* @param string $display
* +----------------------------------------------------------
* @return mixed
+----------------------------------------------------------
*/
public function layout($content, $charset = '', $contentType = 'text/html')
{
//
$find = preg_match_all('/<!-- layout::(.+?)::(.+?) -->/is', $content, $matches);
if ($find)
{
for ($i = 0; $i < $find; $i++)
{
//
if (0 === strpos($matches[1][$i], '$'))
{
//
$matches[1][$i] = $this->get(substr($matches[1][$i], 1));
}
if (0 != $matches[2][$i])
{
//
//
$guid = md5($matches[1][$i]);
$cache = S($guid);
if ($cache)
{
$layoutContent = $cache;
}
else
{
$layoutContent = $this->fetch($matches[1][$i], $charset, $contentType);
S($guid, $layoutContent, $matches[2][$i]);
}
}
else
{
$layoutContent = $this->fetch($matches[1][$i], $charset, $contentType);
}
$content = str_replace($matches[0][$i], $layoutContent, $content);
}
}
return $content;
}
/**
* +----------------------------------------------------------
*
* +----------------------------------------------------------
* @access public
* +----------------------------------------------------------
* @param string $templateFile
* @param string $charset
* @param string $contentType
* @param string $display
* +----------------------------------------------------------
* @return mixed
+----------------------------------------------------------
*/
public function fetch($templateFile = '', $charset = '', $contentType = 'text/html', $display = false)
{
$GLOBALS['_viewStartTime'] = microtime(true);
if (null === $templateFile)
{
// null
return;
}
if (empty($charset))
{
$charset = 'utf-8';
}
//
header("Content-Type:" . $contentType . "; charset=" . $charset);
header("Cache-control: private"); //
//
ob_start();
ob_implicit_flush(0);
$this->render($templateFile);
//
$content = ob_get_clean();
//
$content = $this->layout($content, $charset, $contentType);
//
return $this->output($content, $display);
}
private function render($templateFile)
{
extract($this->_var);
$templateFile = $this->parseTemplateFile($templateFile);
require($templateFile);
}
/**
* +----------------------------------------------------------
*
* +----------------------------------------------------------
* @access public
* +----------------------------------------------------------
* @htmlfile
* @param string $templateFile
*
* @param string $charset
* @param string $contentType
* +----------------------------------------------------------
* @return string
+----------------------------------------------------------
*/
public function buildHtml($htmlfile = '', $templateFile = '', $charset = '', $contentType = 'text/html')
{
$content = $this->fetch($templateFile, $charset, $contentType);
if (empty($htmlfile))
{
$htmlfile = HTML_PATH . rtrim($_SERVER['PATH_INFO'], '/') . C('HTML_FILE_SUFFIX');
}
if (!is_dir(dirname($htmlfile)))
{
//
mk_dir(dirname($htmlfile));
}
if (false === file_put_contents($htmlfile, $content))
{
throw_exception(L('_CACHE_WRITE_ERROR_'));
}
return $content;//readfile($htmlfile);
}
/**
* +----------------------------------------------------------
*
* +----------------------------------------------------------
* @access protected
* +----------------------------------------------------------
* @param string $content
* @param boolean $display
* +----------------------------------------------------------
* @return mixed
+----------------------------------------------------------
*/
protected function output($content, $display)
{
if ($this->if_pagecache)
{
$pagecache = new Swoole_pageCache($this->cache_life);
if ($pagecache->isCached())
{
$pagecache->load();
}
else
{
$pagecache->create($content);
}
}
if ($display)
{
$showTime = $this->showTime();
echo $content;
if ($this->show_runtime)
{
$this->showTrace();
}
return null;
}
else
{
return $content;
}
}
private function parseTemplateFile($templateFile)
{
if ('' == $templateFile)
{
$templateFile = $this->swoole->env['mvc']['controller'] . '_' . $this->swoole->env['mvc']['view'] . '.html';
}
$templateFile = $this->template_dir . $templateFile;
if (!file_exists($templateFile))
{
Error::info('View Error!', 'Template file not exists! <b>' . $templateFile . '</b>');
}
return $templateFile;
}
/**
* +----------------------------------------------------------
*
* +----------------------------------------------------------
* @access protected
* +----------------------------------------------------------
* @return string
+----------------------------------------------------------
*/
protected function showTime()
{
//
$startTime = $this->swoole->env['runtime']['start'];
$endTime = microtime(true);
$total_run_time = number_format(($endTime - $startTime), 4);
$showTime = ': ' . $total_run_time . 's ';
$startMem = array_sum(explode(' ', $this->swoole->env['runtime']['mem']));
$endMem = array_sum(explode(' ', memory_get_usage()));
$showTime .= ' | :' . number_format(($endMem - $startMem) / 1024) . ' kb';
return $showTime;
}
/**
* +----------------------------------------------------------
* Trace
* +----------------------------------------------------------
* @access protected
* +----------------------------------------------------------
* @param string $showTime
* +----------------------------------------------------------
*/
public function showTrace($detail = false)
{
// Trace Trace
// return array(''=>$_SERVER['PHP_SELF'],''=>$_SERVER['SERVER_PROTOCOL'],...);
$_trace = array();
//
$this->trace('', $_SERVER['REQUEST_URI']);
$this->trace('', $_SERVER['REQUEST_METHOD']);
$this->trace('', $_SERVER['SERVER_PROTOCOL']);
$this->trace('', date('Y-m-d H:i:s', $_SERVER['REQUEST_TIME']));
$this->trace('', $_SERVER['HTTP_USER_AGENT']);
if (isset($_SESSION))
{
$this->trace('ID', session_id());
}
$this->trace('', $this->swoole->db->read_times . '');
$this->trace('', $this->swoole->db->write_times . '');
$included_files = get_included_files();
$this->trace('', count($included_files));
$this->trace('PHP', $this->showTime());
$_trace = array_merge($_trace, $this->trace);
// Trace
echo <<<HTML
<div id="think_page_trace" style="background:white;margin:6px;font-size:14px;border:1px dashed silver;padding:8px">
<fieldset id="querybox" style="margin:5px;">
<legend style="color:gray;font-weight:bold">Trace</legend>
<div style="overflow:auto;height:300px;text-align:left;">
HTML;
foreach ($_trace as $key => $info)
{
echo $key . ' : ' . $info . '<br/>';
}
if ($detail)
{
//
echo '<br/>';
foreach ($included_files as $file)
{
echo 'require ' . $file . '<br/>';
}
}
echo "</div></fieldset> </div>";
}
}
Function Calls
None |
Stats
MD5 | 507c58017b58db911bf37c4af882c828 |
Eval Count | 0 |
Decode Time | 139 ms |