mirror of
https://github.com/smarty-php/smarty.git
synced 2025-08-04 18:34:27 +02:00
- remove unneeded code and properties, minor fixes
This commit is contained in:
@@ -4,6 +4,7 @@
|
||||
- bugfix {$smarty.block.parent} did always reference the root parent block https://github.com/smarty-php/smarty/issues/68
|
||||
- move subtemplate code into runtime extension and optimize for size and speed
|
||||
- move template function code into runtime extension
|
||||
- remove unneeded code and properties, minor fixes
|
||||
|
||||
23.08.2015
|
||||
- introduce Smarty::$resource_cache_mode and cache template object of {include} inside loop
|
||||
|
@@ -42,9 +42,6 @@ class Smarty_Internal_Extension_CodeFrame
|
||||
}
|
||||
$output = "<?php\n";
|
||||
$output .= "/*%%SmartyHeaderCode:{$_template->compiled->nocache_hash}%%*/\n";
|
||||
if ($_template->smarty->direct_access_security) {
|
||||
$output .= "if(!defined('SMARTY_DIR')) exit('no direct access allowed');\n";
|
||||
}
|
||||
$output .= "\$_valid = \$_smarty_tpl->decodeProperties(" . var_export($properties, true) . ',' .
|
||||
($cache ? 'true' : 'false') . ");\n";
|
||||
$output .= "/*/%%SmartyHeaderCode%%*/\n";
|
||||
@@ -97,6 +94,7 @@ class Smarty_Internal_Extension_CodeFrame
|
||||
{
|
||||
$output = "<?php\n";
|
||||
$output .= "/*%%SmartyHeaderCode:{$_template->compiled->nocache_hash}%%*/\n";
|
||||
$output .= "/* {$_template->source->type}:{$_template->source->name} */\n";
|
||||
$output .= "if (\$_valid && !is_callable('{$_template->compiled->unifunc}')) {\n";
|
||||
$output .= "function {$_template->compiled->unifunc} (\$_smarty_tpl) {\n";
|
||||
$output .= "?>\n" . $content;
|
||||
@@ -116,8 +114,8 @@ class Smarty_Internal_Extension_CodeFrame
|
||||
*/
|
||||
public static function appendCode($left, $right)
|
||||
{
|
||||
if (preg_match('/\s*\?>$/', $left) && preg_match('/^<\?php\s+/', $right)) {
|
||||
$left = preg_replace('/\s*\?>$/', "\n", $left);
|
||||
if (preg_match('/\s*\?>[\n]?$/', $left) && preg_match('/^<\?php\s+/', $right)) {
|
||||
$left = preg_replace('/\s*\?>[\n]?$/', "\n", $left);
|
||||
$left .= preg_replace('/^<\?php\s+/', '', $right);
|
||||
} else {
|
||||
$left .= $right;
|
||||
|
@@ -115,7 +115,7 @@ class Smarty_Internal_Resource_File extends Smarty_Resource
|
||||
$source->filepath = $this->buildFilepath($source, $_template);
|
||||
|
||||
if ($source->filepath !== false) {
|
||||
if (is_object($source->smarty->security_policy)) {
|
||||
if (isset($source->smarty->security_policy) && is_object($source->smarty->security_policy)) {
|
||||
$source->smarty->security_policy->isTrustedResourceDir($source->filepath, $source->isConfig);
|
||||
}
|
||||
$source->exists = true;
|
||||
|
@@ -56,13 +56,6 @@ class Smarty_Internal_Template extends Smarty_Internal_TemplateBase
|
||||
*/
|
||||
public $mustCompile = null;
|
||||
|
||||
/**
|
||||
* blocks for template inheritance
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public $block_data = array();
|
||||
|
||||
/**
|
||||
* Template Id
|
||||
*
|
||||
@@ -289,56 +282,6 @@ class Smarty_Internal_Template extends Smarty_Internal_TemplateBase
|
||||
$this->smarty->_getTemplateId($this->template_resource, $this->cache_id, $this->compile_id);
|
||||
}
|
||||
|
||||
/**
|
||||
* Cache resources for current template
|
||||
*
|
||||
* @param bool $cache_tpl_obj force caching
|
||||
*/
|
||||
public function cacheTpl($cache_tpl_obj)
|
||||
{
|
||||
if (!$this->source->handler->recompiled &&
|
||||
(isset($this->smarty->_cache['template_objects'][$this->parent->templateId]) ||
|
||||
($cache_tpl_obj && $this->smarty->resource_cache_mode & Smarty::RESOURCE_CACHE_AUTOMATIC) ||
|
||||
$this->smarty->resource_cache_mode & Smarty::RESOURCE_CACHE_ON)
|
||||
) {
|
||||
$this->smarty->_cache['template_objects'][$this->templateId] = $this;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Call template function
|
||||
*
|
||||
* @param string $name template function name
|
||||
* @param object|\Smarty_Internal_Template $_smarty_tpl template object
|
||||
* @param array $params parameter array
|
||||
* @param bool $nocache true if called nocache
|
||||
*
|
||||
* @throws \SmartyException
|
||||
*/
|
||||
public function callTemplateFunction($name, Smarty_Internal_Template $_smarty_tpl, $params, $nocache)
|
||||
{
|
||||
if (isset($_smarty_tpl->tpl_function[$name])) {
|
||||
if (!$_smarty_tpl->caching || ($_smarty_tpl->caching && $nocache)) {
|
||||
$function = $_smarty_tpl->tpl_function[$name]['call_name'];
|
||||
} else {
|
||||
if (isset($_smarty_tpl->tpl_function[$name]['call_name_caching'])) {
|
||||
$function = $_smarty_tpl->tpl_function[$name]['call_name_caching'];
|
||||
} else {
|
||||
$function = $_smarty_tpl->tpl_function[$name]['call_name'];
|
||||
}
|
||||
}
|
||||
if (function_exists($function)) {
|
||||
$function ($_smarty_tpl, $params);
|
||||
return;
|
||||
}
|
||||
// try to load template function dynamically
|
||||
if (Smarty_Internal_Function_Call_Handler::call($name, $_smarty_tpl, $function)) {
|
||||
$function ($_smarty_tpl, $params);
|
||||
return;
|
||||
}
|
||||
}
|
||||
throw new SmartyException("Unable to find template function '{$name}'");
|
||||
}
|
||||
/**
|
||||
* This function is executed automatically when a compiled or cached template file is included
|
||||
* - Decode saved properties from compiled template and cache files
|
||||
@@ -360,7 +303,7 @@ class Smarty_Internal_Template extends Smarty_Internal_TemplateBase
|
||||
) {
|
||||
// check file dependencies at compiled code
|
||||
foreach ($properties['file_dependency'] as $_file_to_check) {
|
||||
if ($_file_to_check[2] == 'file' || $_file_to_check[2] == 'php') {
|
||||
if ($_file_to_check[2] == 'file' || $_file_to_check[2] == 'extends' || $_file_to_check[2] == 'php') {
|
||||
if ($this->source->filepath == $_file_to_check[0]) {
|
||||
// do not recheck current template
|
||||
continue;
|
||||
@@ -433,55 +376,6 @@ class Smarty_Internal_Template extends Smarty_Internal_TemplateBase
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Template code runtime function to get pointer to template variable array of requested scope
|
||||
*
|
||||
* @param int $scope requested variable scope
|
||||
*
|
||||
* @return array array of template variables
|
||||
*/
|
||||
public function &getScope($scope)
|
||||
{
|
||||
if ($scope == Smarty::SCOPE_PARENT && !empty($this->parent)) {
|
||||
return $this->parent->tpl_vars;
|
||||
} elseif ($scope == Smarty::SCOPE_ROOT && !empty($this->parent)) {
|
||||
$ptr = $this->parent;
|
||||
while (!empty($ptr->parent)) {
|
||||
$ptr = $ptr->parent;
|
||||
}
|
||||
|
||||
return $ptr->tpl_vars;
|
||||
} elseif ($scope == Smarty::SCOPE_GLOBAL) {
|
||||
return Smarty::$global_tpl_vars;
|
||||
}
|
||||
$null = null;
|
||||
|
||||
return $null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get parent or root of template parent chain
|
||||
*
|
||||
* @param int $scope parent or root scope
|
||||
*
|
||||
* @return mixed object
|
||||
*/
|
||||
public function getScopePointer($scope)
|
||||
{
|
||||
if ($scope == Smarty::SCOPE_PARENT && !empty($this->parent)) {
|
||||
return $this->parent;
|
||||
} elseif ($scope == Smarty::SCOPE_ROOT && !empty($this->parent)) {
|
||||
$ptr = $this->parent;
|
||||
while (!empty($ptr->parent)) {
|
||||
$ptr = $ptr->parent;
|
||||
}
|
||||
|
||||
return $ptr;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* [util function] counts an array, arrayAccess/traversable or PDOStatement object
|
||||
*
|
||||
|
Reference in New Issue
Block a user