mirror of
https://github.com/smarty-php/smarty.git
synced 2025-08-07 11:54:26 +02:00
- internal changes to improve performance
- fix registering of filters for classes
This commit is contained in:
@@ -1,3 +1,7 @@
|
||||
10/03/2009
|
||||
- internal changes to improve performance
|
||||
- fix registering of filters for classes
|
||||
|
||||
10/01/2009
|
||||
- removed default timezone setting
|
||||
- reactivated PHP resource for simple PHP templates. Must set allow_php_templates = true to enable
|
||||
|
@@ -178,6 +178,8 @@ class Smarty extends Smarty_Internal_TemplateBase {
|
||||
public $template_objects = null;
|
||||
// check If-Modified-Since headers
|
||||
public $cache_modified_check = false;
|
||||
// cached objects
|
||||
public $resource_objects = array();
|
||||
// registered plugins
|
||||
public $registered_plugins = array();
|
||||
// plugin search order
|
||||
|
@@ -25,7 +25,8 @@ class Smarty_Internal_Resource_Extend {
|
||||
/**
|
||||
* Return flag if template source is existing
|
||||
*
|
||||
* @return boolean true
|
||||
* @param object $template template object
|
||||
* @return boolean result
|
||||
*/
|
||||
public function isExisting($template)
|
||||
{
|
||||
@@ -38,16 +39,16 @@ class Smarty_Internal_Resource_Extend {
|
||||
/**
|
||||
* Get filepath to template source
|
||||
*
|
||||
* @param object $_template template object
|
||||
* @param object $template template object
|
||||
* @return string filepath to template source file
|
||||
*/
|
||||
public function getTemplateFilepath($_template)
|
||||
public function getTemplateFilepath($template)
|
||||
{
|
||||
$_files = explode('|', $_template->resource_name);
|
||||
$_filepath = $_template->buildTemplateFilepath ($_files[count($_files)-1]);
|
||||
$_files = explode('|', $template->resource_name);
|
||||
$_filepath = $template->buildTemplateFilepath ($_files[count($_files)-1]);
|
||||
if ($_filepath !== false) {
|
||||
if ($_template->security) {
|
||||
$_template->smarty->security_handler->isTrustedResourceDir($_filepath);
|
||||
if ($template->security) {
|
||||
$template->smarty->security_handler->isTrustedResourceDir($_filepath);
|
||||
}
|
||||
}
|
||||
return $_filepath;
|
||||
@@ -56,48 +57,48 @@ class Smarty_Internal_Resource_Extend {
|
||||
/**
|
||||
* Get timestamp to template source
|
||||
*
|
||||
* @param object $_template template object
|
||||
* @param object $template template object
|
||||
* @return integer timestamp of template source file
|
||||
*/
|
||||
public function getTemplateTimestamp($_template)
|
||||
public function getTemplateTimestamp($template)
|
||||
{
|
||||
return filemtime($_template->getTemplateFilepath());
|
||||
return filemtime($template->getTemplateFilepath());
|
||||
}
|
||||
|
||||
/**
|
||||
* Read template source from file
|
||||
*
|
||||
* @param object $_template template object
|
||||
* @param object $template template object
|
||||
* @return string content of template source file
|
||||
*/
|
||||
public function getTemplateSource($_template)
|
||||
public function getTemplateSource($template)
|
||||
{
|
||||
$this->template = $_template;
|
||||
$_files = explode('|', $_template->resource_name);
|
||||
$this->template = $template;
|
||||
$_files = explode('|', $template->resource_name);
|
||||
$_files = array_reverse($_files);
|
||||
foreach ($_files as $_file) {
|
||||
$_filepath = $_template->buildTemplateFilepath ($_file);
|
||||
$_filepath = $template->buildTemplateFilepath ($_file);
|
||||
// read template file
|
||||
if ($_filepath === false) {
|
||||
throw new Exception("Unable to load template \"file : {$_file}\"");
|
||||
}
|
||||
if ($_file != $_files[0]) {
|
||||
$_template->properties['file_dependency']['F' . abs(crc32($_filepath))] = array($_filepath, filemtime($_filepath));
|
||||
$template->properties['file_dependency']['F' . abs(crc32($_filepath))] = array($_filepath, filemtime($_filepath));
|
||||
}
|
||||
$_content = file_get_contents($_filepath);
|
||||
if ($_file != $_files[count($_files)-1]) {
|
||||
if (preg_match_all('/(' . $this->smarty->left_delimiter . 'block(.+?)' . $this->smarty->right_delimiter . ')/', $_content, $s, PREG_OFFSET_CAPTURE) !=
|
||||
preg_match_all('/(' . $this->smarty->left_delimiter . '\/block(.*?)' . $this->smarty->right_delimiter . ')/', $_content, $c, PREG_OFFSET_CAPTURE)) {
|
||||
if (preg_match_all('/(' . $this->smarty->left_delimiter . 'block(.+?)' . $this->smarty->right_delimiter . ')/', $_content, $_open, PREG_OFFSET_CAPTURE) !=
|
||||
preg_match_all('/(' . $this->smarty->left_delimiter . '\/block(.*?)' . $this->smarty->right_delimiter . ')/', $_content, $_close, PREG_OFFSET_CAPTURE)) {
|
||||
$this->smarty->trigger_error(" unmatched {block} {/block} pairs");
|
||||
}
|
||||
$block_count = count($s[0]);
|
||||
for ($i = 0; $i < $block_count; $i++) {
|
||||
$block_content = str_replace($this->smarty->left_delimiter . '$smarty.parent' . $this->smarty->right_delimiter, '%%%%SMARTY_PARENT%%%%',
|
||||
substr($_content, $s[0][$i][1] + strlen($s[0][$i][0]), $c[0][$i][1] - $s[0][$i][1] - strlen($s[0][$i][0])));
|
||||
$this->saveBlockData($block_content, $s[0][$i][0]);
|
||||
$_block_count = count($_open[0]);
|
||||
for ($_i = 0; $_i < $_block_count; $_i++) {
|
||||
$_block_content = str_replace($this->smarty->left_delimiter . '$smarty.parent' . $this->smarty->right_delimiter, '%%%%SMARTY_PARENT%%%%',
|
||||
substr($_content, $_open[0][$_i][1] + strlen($_open[0][$_i][0]), $_close[0][$_i][1] - $_open[0][$_i][1] - strlen($_open[0][$_i][0])));
|
||||
$this->saveBlockData($_block_content, $_open[0][$_i][0]);
|
||||
}
|
||||
} else {
|
||||
$_template->template_source = $_content;
|
||||
$template->template_source = $_content;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -161,34 +162,34 @@ class Smarty_Internal_Resource_Extend {
|
||||
/**
|
||||
* Get filepath to compiled template
|
||||
*
|
||||
* @param object $_template template object
|
||||
* @param object $template template object
|
||||
* @return string return path to compiled template
|
||||
*/
|
||||
public function getCompiledFilepath($_template)
|
||||
public function getCompiledFilepath($template)
|
||||
{
|
||||
$_files = explode('|', $_template->resource_name);
|
||||
$_filepath = (string)abs(crc32($_template->resource_name));
|
||||
$_files = explode('|', $template->resource_name);
|
||||
$_filepath = (string)abs(crc32($template->resource_name));
|
||||
// if use_sub_dirs, break file into directories
|
||||
if ($_template->smarty->use_sub_dirs) {
|
||||
if ($template->smarty->use_sub_dirs) {
|
||||
$_filepath = substr($_filepath, 0, 3) . DS
|
||||
. substr($_filepath, 0, 2) . DS
|
||||
. substr($_filepath, 0, 1) . DS
|
||||
. $_filepath;
|
||||
}
|
||||
$_compile_dir_sep = $_template->smarty->use_sub_dirs ? DS : '^';
|
||||
if (isset($_template->compile_id)) {
|
||||
$_filepath = $_template->compile_id . $_compile_dir_sep . $_filepath;
|
||||
$_compile_dir_sep = $template->smarty->use_sub_dirs ? DS : '^';
|
||||
if (isset($template->compile_id)) {
|
||||
$_filepath = $template->compile_id . $_compile_dir_sep . $_filepath;
|
||||
}
|
||||
if ($_template->caching) {
|
||||
if ($template->caching) {
|
||||
$_cache = '.cache';
|
||||
} else {
|
||||
$_cache = '';
|
||||
}
|
||||
$_compile_dir = $_template->smarty->compile_dir;
|
||||
$_compile_dir = $template->smarty->compile_dir;
|
||||
if (substr($_compile_dir, -1) != DS) {
|
||||
$_compile_dir .= DS;
|
||||
}
|
||||
return $_compile_dir . $_filepath . '.' . basename($_files[count($_files)-1]) . $_cache . $_template->smarty->php_ext;
|
||||
return $_compile_dir . $_filepath . '.' . basename($_files[count($_files)-1]) . $_cache . $template->smarty->php_ext;
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -133,7 +133,7 @@ class Smarty_Internal_Resource_File {
|
||||
if (strpos('/\\', substr($_compile_dir, -1)) === false) {
|
||||
$_compile_dir .= DS;
|
||||
}
|
||||
return $_compile_dir . $_filepath . '.' . basename($_template->resource_name) . $_cache . $_template->smarty->php_ext;
|
||||
return $_compile_dir . $_filepath . '.' . $_template->resource_type . '.' . basename($_template->resource_name). $_cache . $_template->smarty->php_ext;
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -124,7 +124,7 @@ class Smarty_Internal_Resource_Registered {
|
||||
public function getCompiledFilepath($_template)
|
||||
{
|
||||
// $_filepath = md5($_template->resource_name);
|
||||
$_filepath = (string)abs(crc32($_template->resource_name));
|
||||
$_filepath = (string)abs(crc32($_template->template_resource));
|
||||
// if use_sub_dirs, break file into directories
|
||||
if ($_template->smarty->use_sub_dirs) {
|
||||
$_filepath = substr($_filepath, 0, 3) . DS
|
||||
@@ -145,7 +145,7 @@ class Smarty_Internal_Resource_Registered {
|
||||
if (strpos('/\\', substr($_compile_dir, -1)) === false) {
|
||||
$_compile_dir .= DS;
|
||||
}
|
||||
return $_compile_dir . $_filepath . '.' . basename($_template->resource_name) . '.' . $_template->resource_type . $_cache . $_template->smarty->php_ext;
|
||||
return $_compile_dir . $_filepath . '.' . $_template->resource_type . '.' . basename($_template->resource_name) . $_cache . $_template->smarty->php_ext;
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -46,7 +46,7 @@ class Smarty_Internal_Resource_Stream {
|
||||
{
|
||||
// no filepath for strings
|
||||
// return resource name for compiler error messages
|
||||
return $_template->resource_name;
|
||||
return str_replace(':', '://', $_template->template_resource);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -71,7 +71,7 @@ class Smarty_Internal_Resource_Stream {
|
||||
{
|
||||
// return template string
|
||||
$_template->template_source = '';
|
||||
$fp = fopen($_template->resource_name,'r+');
|
||||
$fp = fopen(str_replace(':', '://', $_template->template_resource),'r+');
|
||||
while (!feof($fp)) {
|
||||
$_template->template_source .= fgets($fp);
|
||||
}
|
||||
|
@@ -15,7 +15,6 @@
|
||||
*/
|
||||
class Smarty_Internal_Template extends Smarty_Internal_TemplateBase {
|
||||
// object cache
|
||||
public $resource_objects = array();
|
||||
public $compiler_object = null;
|
||||
public $cacher_object = null;
|
||||
// Smarty parameter
|
||||
@@ -106,11 +105,6 @@ class Smarty_Internal_Template extends Smarty_Internal_TemplateBase {
|
||||
$this->smarty->loadPlugin($this->cache_resource_class);
|
||||
$this->smarty->cache_resource_objects[$this->caching_type] = new $this->cache_resource_class($this->smarty);
|
||||
}
|
||||
if ($this->smarty->direct_access_security) {
|
||||
$this->dir_acc_sec_string = "<?php if(!defined('SMARTY_DIR')) exit('no direct access allowed'); ?>\n";
|
||||
} else {
|
||||
$this->dir_acc_sec_string = '';
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -123,7 +117,7 @@ class Smarty_Internal_Template extends Smarty_Internal_TemplateBase {
|
||||
public function getTemplateFilepath ()
|
||||
{
|
||||
return $this->template_filepath === null ?
|
||||
$this->template_filepath = $this->resource_objects[$this->resource_type]->getTemplateFilepath($this) :
|
||||
$this->template_filepath = $this->smarty->resource_objects[$this->resource_type]->getTemplateFilepath($this) :
|
||||
$this->template_filepath;
|
||||
}
|
||||
|
||||
@@ -137,7 +131,7 @@ class Smarty_Internal_Template extends Smarty_Internal_TemplateBase {
|
||||
public function getTemplateTimestamp ()
|
||||
{
|
||||
return $this->template_timestamp === null ?
|
||||
$this->template_timestamp = $this->resource_objects[$this->resource_type]->getTemplateTimestamp($this) :
|
||||
$this->template_timestamp = $this->smarty->resource_objects[$this->resource_type]->getTemplateTimestamp($this) :
|
||||
$this->template_timestamp;
|
||||
}
|
||||
|
||||
@@ -151,7 +145,7 @@ class Smarty_Internal_Template extends Smarty_Internal_TemplateBase {
|
||||
public function getTemplateSource ()
|
||||
{
|
||||
if ($this->template_source === null) {
|
||||
if (!$this->resource_objects[$this->resource_type]->getTemplateSource($this)) {
|
||||
if (!$this->smarty->resource_objects[$this->resource_type]->getTemplateSource($this)) {
|
||||
throw new Exception("Unable to read template '{$this->resource_name}'");
|
||||
}
|
||||
}
|
||||
@@ -165,11 +159,15 @@ class Smarty_Internal_Template extends Smarty_Internal_TemplateBase {
|
||||
*
|
||||
* @return boolean true if the template exists
|
||||
*/
|
||||
public function isExisting ()
|
||||
public function isExisting ($error= false)
|
||||
{
|
||||
return $this->isExisting === null ?
|
||||
$this->isExisting = $this->resource_objects[$this->resource_type]->isExisting($this) :
|
||||
$this->isExisting;
|
||||
if ($this->isExisting === null) {
|
||||
$this->isExisting = $this->smarty->resource_objects[$this->resource_type]->isExisting($this);
|
||||
}
|
||||
if (!$this->isExisting && $error) {
|
||||
throw new Exception("Unable to load template \"{$this->resource_type} : {$this->resource_name}\"");
|
||||
}
|
||||
return $this->isExisting;
|
||||
}
|
||||
/**
|
||||
* Returns if the template resource uses the Smarty compiler
|
||||
@@ -181,7 +179,7 @@ class Smarty_Internal_Template extends Smarty_Internal_TemplateBase {
|
||||
public function usesCompiler ()
|
||||
{
|
||||
return $this->usesCompiler === null ?
|
||||
$this->usesCompiler = $this->resource_objects[$this->resource_type]->usesCompiler() :
|
||||
$this->usesCompiler = $this->smarty->resource_objects[$this->resource_type]->usesCompiler() :
|
||||
$this->usesCompiler;
|
||||
}
|
||||
|
||||
@@ -195,7 +193,7 @@ class Smarty_Internal_Template extends Smarty_Internal_TemplateBase {
|
||||
public function isEvaluated ()
|
||||
{
|
||||
return $this->isEvaluated === null ?
|
||||
$this->isEvaluated = $this->resource_objects[$this->resource_type]->isEvaluated() :
|
||||
$this->isEvaluated = $this->smarty->resource_objects[$this->resource_type]->isEvaluated() :
|
||||
$this->isEvaluated;
|
||||
}
|
||||
|
||||
@@ -208,14 +206,10 @@ class Smarty_Internal_Template extends Smarty_Internal_TemplateBase {
|
||||
*/
|
||||
public function mustCompile ()
|
||||
{
|
||||
if (!$this->isExisting()) {
|
||||
throw new Exception("Unable to load template \"{$this->resource_type} : {$this->resource_name}\"");
|
||||
}
|
||||
$this->isExisting(true);
|
||||
|
||||
if ($this->mustCompile === null) {
|
||||
$this->mustCompile = ($this->usesCompiler() && ($this->force_compile || $this->isEvaluated() || ($this->smarty->compile_check && $this->getCompiledTimestamp () !== $this->getTemplateTimestamp ())));
|
||||
if ($this->mustCompile) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return $this->mustCompile;
|
||||
}
|
||||
@@ -228,7 +222,7 @@ class Smarty_Internal_Template extends Smarty_Internal_TemplateBase {
|
||||
public function getCompiledFilepath ()
|
||||
{
|
||||
return $this->compiled_filepath === null ?
|
||||
($this->compiled_filepath = !$this->isEvaluated() ? $this->resource_objects[$this->resource_type]->getCompiledFilepath($this) : false) :
|
||||
($this->compiled_filepath = !$this->isEvaluated() ? $this->smarty->resource_objects[$this->resource_type]->getCompiledFilepath($this) : false) :
|
||||
$this->compiled_filepath;
|
||||
}
|
||||
|
||||
@@ -284,8 +278,8 @@ class Smarty_Internal_Template extends Smarty_Internal_TemplateBase {
|
||||
require_once(SMARTY_SYSPLUGINS_DIR . 'internal.templatecompilerbase.php');
|
||||
// $this->smarty->loadPlugin('Smarty_Internal_CompileBase');
|
||||
// $this->smarty->loadPlugin('Smarty_Internal_TemplateCompilerBase');
|
||||
$this->smarty->loadPlugin($this->resource_objects[$this->resource_type]->compiler_class);
|
||||
$this->compiler_object = new $this->resource_objects[$this->resource_type]->compiler_class($this->resource_objects[$this->resource_type]->template_lexer_class, $this->resource_objects[$this->resource_type]->template_parser_class, $this->smarty);
|
||||
$this->smarty->loadPlugin($this->smarty->resource_objects[$this->resource_type]->compiler_class);
|
||||
$this->compiler_object = new $this->smarty->resource_objects[$this->resource_type]->compiler_class($this->smarty->resource_objects[$this->resource_type]->template_lexer_class, $this->smarty->resource_objects[$this->resource_type]->template_parser_class, $this->smarty);
|
||||
// load cacher
|
||||
if ($this->caching) {
|
||||
$this->smarty->loadPlugin($this->cacher_class);
|
||||
@@ -301,9 +295,6 @@ class Smarty_Internal_Template extends Smarty_Internal_TemplateBase {
|
||||
if ($this->compiler_object->compileTemplate($this)) {
|
||||
// compiling succeded
|
||||
if (!$this->isEvaluated()) {
|
||||
// build template property string
|
||||
$this->properties_string = "<?php \$_smarty_tpl->decodeProperties('" . str_replace("'", '"', (serialize($this->properties))) . "'); ?>\n";
|
||||
$this->compiled_template = $this->dir_acc_sec_string . $this->properties_string . $this->compiled_template;
|
||||
// write compiled template
|
||||
$this->smarty->write_file_object->writeFile($this->getCompiledFilepath(), $this->compiled_template);
|
||||
// make template and compiled file timestamp match
|
||||
@@ -364,8 +355,7 @@ class Smarty_Internal_Template extends Smarty_Internal_TemplateBase {
|
||||
{
|
||||
// build file dependency string
|
||||
$this->properties['cache_lifetime'] = $this->cache_lifetime;
|
||||
$this->properties_string = "<?php \$_smarty_tpl->decodeProperties('" . str_replace("'", '"', (serialize($this->properties))) . "'); ?>\n";
|
||||
return ($this->isEvaluated() || !$this->caching) ? false : $this->smarty->cache_resource_objects[$this->caching_type]->writeCachedContent($this, $this->dir_acc_sec_string . $this->properties_string . $this->rendered_content);
|
||||
return ($this->isEvaluated() || !$this->caching) ? false : $this->smarty->cache_resource_objects[$this->caching_type]->writeCachedContent($this, $this->createPropertyHeader() . $this->rendered_content);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -461,10 +451,10 @@ class Smarty_Internal_Template extends Smarty_Internal_TemplateBase {
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if (is_callable(array($this->resource_objects[$this->resource_type], 'renderUncompiled'))) {
|
||||
if (is_callable(array($this->smarty->resource_objects[$this->resource_type], 'renderUncompiled'))) {
|
||||
$_start_time = $this->_get_time();
|
||||
ob_start();
|
||||
$this->resource_objects[$this->resource_type]->renderUncompiled($this);
|
||||
$this->smarty->resource_objects[$this->resource_type]->renderUncompiled($this);
|
||||
} else {
|
||||
throw new Exception("Resource '$this->resource_type' must have 'renderUncompiled' methode");
|
||||
}
|
||||
@@ -482,8 +472,8 @@ class Smarty_Internal_Template extends Smarty_Internal_TemplateBase {
|
||||
if (!$this->isEvaluated() && $this->caching) {
|
||||
// write rendered template
|
||||
$this->writeCachedContent($this);
|
||||
// cache file may contain nocache code. read it back for processing
|
||||
$this->rendered_content = $this->smarty->cache_resource_objects[$this->caching_type]->getCachedContents($this);
|
||||
// cache file may contain nocache code. read it back for processing
|
||||
$this->rendered_content = $this->smarty->cache_resource_objects[$this->caching_type]->getCachedContents($this);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -502,7 +492,7 @@ class Smarty_Internal_Template extends Smarty_Internal_TemplateBase {
|
||||
$this->caching = false;
|
||||
}
|
||||
// checks if template exists
|
||||
$this->getTemplateFilepath();
|
||||
$this->isExisting(true);
|
||||
// read from cache or render
|
||||
if ($this->rendered_content === null && !$this->isCached()) {
|
||||
// render template (not loaded and not in cache)
|
||||
@@ -518,7 +508,7 @@ class Smarty_Internal_Template extends Smarty_Internal_TemplateBase {
|
||||
*
|
||||
* @param string $template_resource template resource specification
|
||||
*/
|
||||
private function parseResourceName($template_resource, &$resource_type, &$resource_name, &$resource_handler)
|
||||
public function parseResourceName($template_resource, &$resource_type, &$resource_name, &$resource_handler)
|
||||
{
|
||||
if (empty($template_resource))
|
||||
return false;
|
||||
@@ -531,29 +521,29 @@ class Smarty_Internal_Template extends Smarty_Internal_TemplateBase {
|
||||
list($resource_type, $resource_name) = explode(':', $template_resource, 2);
|
||||
if (strlen($resource_type) == 1) {
|
||||
// 1 char is not resource type, but part of filepath
|
||||
$resource_type = $this->smarty->default_resource_type;
|
||||
$resource_type = 'file';
|
||||
$resource_name = $template_resource;
|
||||
} else {
|
||||
$resource_type = strtolower($resource_type);
|
||||
}
|
||||
}
|
||||
// load resource handler if required
|
||||
if (!isset($this->resource_objects[$resource_type])) {
|
||||
if (!isset($this->smarty->resource_objects[$resource_type])) {
|
||||
// try registered resource
|
||||
if (isset($this->smarty->_plugins['resource'][$resource_type])) {
|
||||
require_once(SMARTY_SYSPLUGINS_DIR . 'internal.resource_registered.php');
|
||||
// $this->smarty->loadPlugin('Smarty_Internal_Resource_Registered');
|
||||
$resource_handler = $this->resource_objects[$resource_type] = new Smarty_Internal_Resource_Registered($this->smarty);
|
||||
$resource_handler = $this->smarty->resource_objects[$resource_type] = new Smarty_Internal_Resource_Registered($this->smarty);
|
||||
} else {
|
||||
// try sysplugins dir
|
||||
$_resource_class = "Smarty_Internal_Resource_{$resource_type}";
|
||||
if ($this->smarty->loadPlugin($_resource_class)) {
|
||||
$resource_handler = $this->resource_objects[$resource_type] = new $_resource_class($this->smarty);
|
||||
$resource_handler = $this->smarty->resource_objects[$resource_type] = new $_resource_class($this->smarty);
|
||||
} else {
|
||||
// try plugins dir
|
||||
$_resource_class = "Smarty_Resource_{$resource_type}";
|
||||
if ($this->smarty->loadPlugin($_resource_class)) {
|
||||
$resource_handler = $this->resource_objects[$resource_type] = new $_resource_class($this->smarty);
|
||||
$resource_handler = $this->smarty->resource_objects[$resource_type] = new $_resource_class($this->smarty);
|
||||
} else {
|
||||
// try streams
|
||||
$_known_stream = stream_get_wrappers();
|
||||
@@ -564,8 +554,8 @@ class Smarty_Internal_Template extends Smarty_Internal_TemplateBase {
|
||||
}
|
||||
require_once(SMARTY_SYSPLUGINS_DIR . 'internal.resource_stream.php');
|
||||
// $this->smarty->loadPlugin('Smarty_Internal_Resource_Stream');
|
||||
$resource_handler = $this->resource_objects[$resource_type] = new Smarty_Internal_Resource_Stream($this->smarty);
|
||||
$resource_name = str_replace(':', '://', $template_resource);
|
||||
$resource_handler = $this->smarty->resource_objects[$resource_type] = new Smarty_Internal_Resource_Stream($this->smarty);
|
||||
// $resource_name = str_replace(':', '://', $template_resource);
|
||||
} else {
|
||||
throw new Exception('Unkown resource type \'' . $resource_type . '\'');
|
||||
}
|
||||
@@ -573,12 +563,12 @@ class Smarty_Internal_Template extends Smarty_Internal_TemplateBase {
|
||||
}
|
||||
}
|
||||
} else {
|
||||
$resource_handler = $this->resource_objects[$resource_type];
|
||||
$resource_handler = $this->smarty->resource_objects[$resource_type];
|
||||
}
|
||||
// cache template object under a unique ID
|
||||
// do not cache string resources
|
||||
if ($resource_type != 'string') {
|
||||
$this->smarty->template_objects[$this->buildTemplateId ($this->template_resource, $this->cache_id, $this->compile_id)] = $this;
|
||||
$this->smarty->template_objects[$this->buildTemplateId ($this->template_resource, $this->cache_id, $this->compile_id)] = $this;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
@@ -643,7 +633,7 @@ class Smarty_Internal_Template extends Smarty_Internal_TemplateBase {
|
||||
*/
|
||||
public function updateParentVariables ($scope = SMARTY_LOCAL_SCOPE)
|
||||
{
|
||||
foreach ($this->tpl_vars as $_key => $_value) {
|
||||
foreach ($this->tpl_vars as $_key => $_variable) {
|
||||
// copy global vars back to parent
|
||||
if (isset($this->parent) && ($scope == SMARTY_PARENT_SCOPE || $this->tpl_vars[$_key]->scope == SMARTY_PARENT_SCOPE)) {
|
||||
if (isset($this->parent->tpl_vars[$_key])) {
|
||||
@@ -651,7 +641,7 @@ class Smarty_Internal_Template extends Smarty_Internal_TemplateBase {
|
||||
$this->parent->tpl_vars[$_key]->value = $this->tpl_vars[$_key]->value;
|
||||
} else {
|
||||
// create variable in parent
|
||||
$this->parent->tpl_vars[$_key] = clone $_value;
|
||||
$this->parent->tpl_vars[$_key] = clone $_variable;
|
||||
$this->parent->tpl_vars[$_key]->scope = SMARTY_LOCAL_SCOPE;
|
||||
}
|
||||
}
|
||||
@@ -666,7 +656,7 @@ class Smarty_Internal_Template extends Smarty_Internal_TemplateBase {
|
||||
$_ptr->tpl_vars[$_key]->value = $this->tpl_vars[$_key]->value;
|
||||
} else {
|
||||
// create variable in root
|
||||
$_ptr->tpl_vars[$_key] = clone $_value;
|
||||
$_ptr->tpl_vars[$_key] = clone $_variable;
|
||||
$_ptr->tpl_vars[$_key]->scope = SMARTY_LOCAL_SCOPE;
|
||||
}
|
||||
}
|
||||
@@ -676,13 +666,23 @@ class Smarty_Internal_Template extends Smarty_Internal_TemplateBase {
|
||||
$this->smarty->global_tpl_vars[$_key]->value = $this->tpl_vars[$_key]->value;
|
||||
} else {
|
||||
// create variable in root
|
||||
$this->smarty->global_tpl_vars[$_key] = clone $_value;
|
||||
$this->smarty->global_tpl_vars[$_key] = clone $_variable;
|
||||
}
|
||||
$this->smarty->global_tpl_vars[$_key]->scope = SMARTY_LOCAL_SCOPE;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Create property header
|
||||
*/
|
||||
public function createPropertyHeader ()
|
||||
{
|
||||
$directory_security = $this->smarty->direct_access_security ? "<?php if(!defined('SMARTY_DIR')) exit('no direct access allowed'); ?>\n" : '';
|
||||
$properties_string = "<?php \$_smarty_tpl->decodeProperties('" . str_replace("'", '"', (serialize($this->properties))) . "'); ?>\n";
|
||||
return $directory_security . $properties_string;
|
||||
}
|
||||
|
||||
/**
|
||||
* wrapper for display
|
||||
*/
|
||||
|
@@ -51,7 +51,7 @@ class Smarty_Internal_TemplateCompilerBase {
|
||||
// template header code
|
||||
$template_header = '';
|
||||
if (!$template->suppressHeader) {
|
||||
$template_header = "<?php /* Smarty version " . Smarty::$_version . ", created on " . strftime("%Y-%m-%d %H:%M:%S") . "\n";
|
||||
$template_header .= "<?php /* Smarty version " . Smarty::$_version . ", created on " . strftime("%Y-%m-%d %H:%M:%S") . "\n";
|
||||
$template_header .= " compiled from \"" . $this->template->getTemplateFilepath() . "\" */ ?>\n";
|
||||
}
|
||||
|
||||
@@ -66,7 +66,7 @@ class Smarty_Internal_TemplateCompilerBase {
|
||||
}
|
||||
// on empty template just return header
|
||||
if ($_content == '') {
|
||||
$template->compiled_template = $template_header;
|
||||
$template->compiled_template = $template->createPropertyHeader() . $template_header;
|
||||
return true;
|
||||
}
|
||||
// init cacher plugin
|
||||
@@ -77,7 +77,7 @@ class Smarty_Internal_TemplateCompilerBase {
|
||||
|
||||
if (!$this->compile_error) {
|
||||
// close cacher and return compiled template
|
||||
$template->compiled_template = $template_header . $template->cacher_object->closeCacher($this, $_compiled_code);
|
||||
$template->compiled_template = $template->createPropertyHeader() . $template_header . $template->cacher_object->closeCacher($this, $_compiled_code);
|
||||
// run postfilter if required
|
||||
if (isset($this->smarty->autoload_filters['post']) || isset($this->smarty->registered_filters['post'])) {
|
||||
$template->compiled_template = $this->smarty->filter_handler->execute('post', $template->compiled_template);
|
||||
|
File diff suppressed because it is too large
Load Diff
31
libs/sysplugins/method._get_filter_name.php
Normal file
31
libs/sysplugins/method._get_filter_name.php
Normal file
@@ -0,0 +1,31 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Smarty method _get_filter_name
|
||||
*
|
||||
* Return internal filter name
|
||||
*
|
||||
* @package Smarty
|
||||
* @subpackage SmartyMethod
|
||||
* @author Uwe Tews
|
||||
*/
|
||||
|
||||
/**
|
||||
* Return internal filter name
|
||||
*
|
||||
* @param object $smarty
|
||||
* @param callback $function
|
||||
*/
|
||||
function _get_filter_name($smarty, $function)
|
||||
{
|
||||
if (is_array($function)) {
|
||||
$_class_name = (is_object($function[0]) ?
|
||||
get_class($function[0]) : $function[0]);
|
||||
return $_class_name . '_' . $function[1];
|
||||
}
|
||||
else {
|
||||
return $function;
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
@@ -19,8 +19,7 @@
|
||||
*/
|
||||
function register_outputfilter($smarty, $function)
|
||||
{
|
||||
$_name = (is_array($function)) ? $function[0] : $function;
|
||||
$smarty->registered_filters['output'][$_name] = $function;
|
||||
$smarty->registered_filters['output'][$smarty->_get_filter_name($function)] = $function;
|
||||
}
|
||||
|
||||
?>
|
||||
|
@@ -19,8 +19,7 @@
|
||||
*/
|
||||
function register_postfilter($smarty, $function)
|
||||
{
|
||||
$_name = (is_array($function)) ? $function[0] : $function;
|
||||
$smarty->registered_filters['post'][$_name] = $function;
|
||||
$smarty->registered_filters['post'][$smarty->_get_filter_name($function)] = $function;
|
||||
}
|
||||
|
||||
?>
|
||||
|
@@ -19,8 +19,7 @@
|
||||
*/
|
||||
function register_prefilter($smarty, $function)
|
||||
{
|
||||
$_name = (is_array($function)) ? $function[0] : $function;
|
||||
$smarty->registered_filters['pre'][$_name] = $function;
|
||||
$smarty->registered_filters['pre'][$smarty->_get_filter_name($function)] = $function;
|
||||
}
|
||||
|
||||
?>
|
||||
|
@@ -19,8 +19,7 @@
|
||||
*/
|
||||
function register_variablefilter($smarty, $function)
|
||||
{
|
||||
$_name = (is_array($function)) ? $function[0] : $function;
|
||||
$smarty->registered_filters['variable'][$_name] = $function;
|
||||
$smarty->registered_filters['variable'][$smarty->_get_filter_name($function)] = $function;
|
||||
}
|
||||
|
||||
?>
|
||||
|
@@ -22,8 +22,7 @@
|
||||
*/
|
||||
function unregister_outputfilter($smarty, $function)
|
||||
{
|
||||
$_name = (is_array($function)) ? $function[0] : $function;
|
||||
unset($smarty->registered_filters['output'][$_name]);
|
||||
unset($smarty->registered_filters['output'][$smarty->_get_filter_name($function)]);
|
||||
}
|
||||
|
||||
?>
|
||||
|
@@ -21,8 +21,7 @@
|
||||
*/
|
||||
function unregister_postfilter($smarty, $function)
|
||||
{
|
||||
$_name = (is_array($function)) ? $function[0] : $function;
|
||||
unset($smarty->registered_filters['post'][$_name]);
|
||||
unset($smarty->registered_filters['post'][$smarty->_get_filter_name($function)]);
|
||||
}
|
||||
|
||||
?>
|
||||
|
@@ -21,8 +21,7 @@
|
||||
*/
|
||||
function unregister_prefilter($smarty, $function)
|
||||
{
|
||||
$_name = (is_array($function)) ? $function[0] : $function;
|
||||
unset($smarty->registered_filters['pre'][$_name]);
|
||||
unset($smarty->registered_filters['pre'][$smarty->_get_filter_name($function)]);
|
||||
}
|
||||
|
||||
?>
|
||||
|
@@ -21,8 +21,7 @@
|
||||
*/
|
||||
function unregister_variablefilter($smarty, $function)
|
||||
{
|
||||
$_name = (is_array($function)) ? $function[0] : $function;
|
||||
unset($smarty->registered_filters['variable'][$_name]);
|
||||
unset($smarty->registered_filters['variable'][$smarty->_get_filter_name($function)]);
|
||||
}
|
||||
|
||||
?>
|
||||
|
Reference in New Issue
Block a user