mirror of
https://github.com/Piwigo/Piwigo.git
synced 2026-08-07 01:03:31 +02:00
Update Smarty to 3.1.3
This commit is contained in:
@@ -28,31 +28,12 @@ class Smarty_Template_Compiled extends Smarty_Template_Resource_Base
|
||||
*/
|
||||
static function load($_template)
|
||||
{
|
||||
// check runtime cache
|
||||
if (!$_template->source->handler->recompiled &&
|
||||
($_template->smarty->resource_cache_mode & Smarty::RESOURCE_CACHE_ON)
|
||||
) {
|
||||
$_cache_key = $_template->source->unique_resource . '#';
|
||||
if ($_template->caching) {
|
||||
$_cache_key .= 'caching#';
|
||||
}
|
||||
$_cache_key .= $_template->compile_id;
|
||||
if (isset($_template->source->compileds[$_cache_key])) {
|
||||
return $_template->source->compileds[$_cache_key];
|
||||
}
|
||||
}
|
||||
$compiled = new Smarty_Template_Compiled();
|
||||
if ($_template->source->handler->hasCompiledHandler) {
|
||||
$_template->source->handler->populateCompiledFilepath($compiled, $_template);
|
||||
} else {
|
||||
$compiled->populateCompiledFilepath($_template);
|
||||
}
|
||||
// runtime cache
|
||||
if (!$_template->source->handler->recompiled &&
|
||||
($_template->smarty->resource_cache_mode & Smarty::RESOURCE_CACHE_ON)
|
||||
) {
|
||||
$_template->source->compileds[$_cache_key] = $compiled;
|
||||
}
|
||||
return $compiled;
|
||||
}
|
||||
|
||||
@@ -63,116 +44,97 @@ class Smarty_Template_Compiled extends Smarty_Template_Resource_Base
|
||||
**/
|
||||
public function populateCompiledFilepath(Smarty_Internal_Template $_template)
|
||||
{
|
||||
$_compile_id = isset($_template->compile_id) ? preg_replace('![^\w]+!', '_', $_template->compile_id) : null;
|
||||
if ($_template->source->isConfig) {
|
||||
$_flag = '_' .
|
||||
((int) $_template->smarty->config_read_hidden + (int) $_template->smarty->config_booleanize * 2 +
|
||||
(int) $_template->smarty->config_overwrite * 4);
|
||||
} else {
|
||||
$_flag =
|
||||
'_' . ((int) $_template->smarty->merge_compiled_includes + (int) $_template->smarty->escape_html * 2);
|
||||
$source = &$_template->source;
|
||||
$smarty = &$_template->smarty;
|
||||
$this->filepath = $smarty->getCompileDir();
|
||||
if (isset($_template->compile_id)) {
|
||||
$this->filepath .= preg_replace('![^\w]+!', '_', $_template->compile_id) .
|
||||
($smarty->use_sub_dirs ? $smarty->ds : '^');
|
||||
}
|
||||
$_filepath = $_template->source->uid . $_flag;
|
||||
// if use_sub_dirs, break file into directories
|
||||
if ($_template->smarty->use_sub_dirs) {
|
||||
$_filepath = substr($_filepath, 0, 2) . DS . substr($_filepath, 2, 2) . DS . substr($_filepath, 4, 2) . DS .
|
||||
$_filepath;
|
||||
if ($smarty->use_sub_dirs) {
|
||||
$this->filepath .= $source->uid[ 0 ] . $source->uid[ 1 ] . $smarty->ds . $source->uid[ 2 ] .
|
||||
$source->uid[ 3 ] . $smarty->ds . $source->uid[ 4 ] . $source->uid[ 5 ] . $smarty->ds;
|
||||
}
|
||||
$_compile_dir_sep = $_template->smarty->use_sub_dirs ? DS : '^';
|
||||
if (isset($_compile_id)) {
|
||||
$_filepath = $_compile_id . $_compile_dir_sep . $_filepath;
|
||||
}
|
||||
// caching token
|
||||
if ($_template->caching) {
|
||||
$_cache = '.cache';
|
||||
$this->filepath .= $source->uid . '_';
|
||||
if ($source->isConfig) {
|
||||
$this->filepath .= (int) $smarty->config_read_hidden + (int) $smarty->config_booleanize * 2 +
|
||||
(int) $smarty->config_overwrite * 4;
|
||||
} else {
|
||||
$_cache = '';
|
||||
$this->filepath .= (int) $smarty->merge_compiled_includes + (int) $smarty->escape_html * 2 +
|
||||
(($smarty->merge_compiled_includes && $source->type === 'extends') ?
|
||||
(int) $smarty->extends_recursion * 4 : 0);
|
||||
}
|
||||
$_compile_dir = $_template->smarty->getCompileDir();
|
||||
// set basename if not specified
|
||||
$_basename = $_template->source->handler->getBasename($_template->source);
|
||||
if ($_basename === null) {
|
||||
$_basename = basename(preg_replace('![^\w]+!', '_', $_template->source->name));
|
||||
$this->filepath .= '.' . $source->type;
|
||||
$basename = $source->handler->getBasename($source);
|
||||
if (!empty($basename)) {
|
||||
$this->filepath .= '.' . $basename;
|
||||
}
|
||||
// separate (optional) basename by dot
|
||||
if ($_basename) {
|
||||
$_basename = '.' . $_basename;
|
||||
if ($_template->caching) {
|
||||
$this->filepath .= '.cache';
|
||||
}
|
||||
|
||||
$this->filepath = $_compile_dir . $_filepath . '.' . $_template->source->type . $_basename . $_cache . '.php';
|
||||
$this->exists = is_file($this->filepath);
|
||||
if (!$this->exists) {
|
||||
$this->timestamp = false;
|
||||
$this->filepath .= '.php';
|
||||
$this->timestamp = $this->exists = is_file($this->filepath);
|
||||
if ($this->exists) {
|
||||
$this->timestamp = filemtime($this->filepath);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* load compiled template or compile from source
|
||||
*
|
||||
* @param Smarty_Internal_Template $_template
|
||||
* @param Smarty_Internal_Template $_smarty_tpl do not change variable name, is used by compiled template
|
||||
*
|
||||
* @throws Exception
|
||||
*/
|
||||
public function process(Smarty_Internal_Template $_template)
|
||||
public function process(Smarty_Internal_Template $_smarty_tpl)
|
||||
{
|
||||
$_smarty_tpl = $_template;
|
||||
if ($_template->source->handler->recompiled || !$_template->compiled->exists ||
|
||||
$_template->smarty->force_compile || ($_template->smarty->compile_check &&
|
||||
$_template->source->getTimeStamp() > $_template->compiled->getTimeStamp())
|
||||
) {
|
||||
$this->compileTemplateSource($_template);
|
||||
$compileCheck = $_template->smarty->compile_check;
|
||||
$_template->smarty->compile_check = false;
|
||||
if ($_template->source->handler->recompiled) {
|
||||
$level = ob_get_level();
|
||||
ob_start();
|
||||
try {
|
||||
eval("?>" . $this->content);
|
||||
}
|
||||
catch (Exception $e) {
|
||||
while (ob_get_level() > $level) {
|
||||
ob_end_clean();
|
||||
}
|
||||
throw $e;
|
||||
}
|
||||
ob_get_clean();
|
||||
$this->content = null;
|
||||
$source = &$_smarty_tpl->source;
|
||||
$smarty = &$_smarty_tpl->smarty;
|
||||
if ($source->handler->recompiled) {
|
||||
$source->handler->process($_smarty_tpl);
|
||||
} elseif (!$source->handler->uncompiled) {
|
||||
if (!$this->exists || $smarty->force_compile ||
|
||||
($smarty->compile_check && $source->getTimeStamp() > $this->getTimeStamp())
|
||||
) {
|
||||
$this->compileTemplateSource($_smarty_tpl);
|
||||
$compileCheck = $smarty->compile_check;
|
||||
$smarty->compile_check = false;
|
||||
$this->loadCompiledTemplate($_smarty_tpl);
|
||||
$smarty->compile_check = $compileCheck;
|
||||
} else {
|
||||
$this->loadCompiledTemplate($_template);
|
||||
}
|
||||
$_template->smarty->compile_check = $compileCheck;
|
||||
} else {
|
||||
$_template->mustCompile = true;
|
||||
@include($_template->compiled->filepath);
|
||||
if ($_template->mustCompile) {
|
||||
$this->compileTemplateSource($_template);
|
||||
$compileCheck = $_template->smarty->compile_check;
|
||||
$_template->smarty->compile_check = false;
|
||||
$this->loadCompiledTemplate($_template);
|
||||
$_template->smarty->compile_check = $compileCheck;
|
||||
$_smarty_tpl->mustCompile = true;
|
||||
@include($this->filepath);
|
||||
if ($_smarty_tpl->mustCompile) {
|
||||
$this->compileTemplateSource($_smarty_tpl);
|
||||
$compileCheck = $smarty->compile_check;
|
||||
$smarty->compile_check = false;
|
||||
$this->loadCompiledTemplate($_smarty_tpl);
|
||||
$smarty->compile_check = $compileCheck;
|
||||
}
|
||||
}
|
||||
$_smarty_tpl->_subTemplateRegister();
|
||||
$this->processed = true;
|
||||
}
|
||||
$_template->smarty->ext->_subTemplate->registerSubTemplates($_template);
|
||||
|
||||
$this->processed = true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Load fresh compiled template by including the PHP file
|
||||
* HHVM requires a work around because of a PHP incompatibility
|
||||
*
|
||||
* @param \Smarty_Internal_Template $_template
|
||||
* @param \Smarty_Internal_Template $_smarty_tpl do not change variable name, is used by compiled template
|
||||
*/
|
||||
private function loadCompiledTemplate(Smarty_Internal_Template $_template)
|
||||
private function loadCompiledTemplate(Smarty_Internal_Template $_smarty_tpl)
|
||||
{
|
||||
if (function_exists('opcache_invalidate')) {
|
||||
opcache_invalidate($_template->compiled->filepath);
|
||||
if (function_exists('opcache_invalidate') && strlen(ini_get("opcache.restrict_api")) < 1) {
|
||||
opcache_invalidate($this->filepath, true);
|
||||
} elseif (function_exists('apc_compile_file')) {
|
||||
apc_compile_file($this->filepath);
|
||||
}
|
||||
$_smarty_tpl = $_template;
|
||||
if (defined('HHVM_VERSION')) {
|
||||
$_template->smarty->ext->_hhvm->includeHhvm($_template, $_template->compiled->filepath);
|
||||
eval("?>" . file_get_contents($this->filepath));
|
||||
} else {
|
||||
include($_template->compiled->filepath);
|
||||
include($this->filepath);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -186,7 +148,15 @@ class Smarty_Template_Compiled extends Smarty_Template_Resource_Base
|
||||
*/
|
||||
public function render(Smarty_Internal_Template $_template)
|
||||
{
|
||||
// checks if template exists
|
||||
if (!$_template->source->exists) {
|
||||
$type = $_template->source->isConfig ? 'config' : 'template';
|
||||
throw new SmartyException("Unable to load {$type} '{$_template->source->type}:{$_template->source->name}'");
|
||||
}
|
||||
if ($_template->smarty->debugging) {
|
||||
if (!isset($_template->smarty->_debug)) {
|
||||
$_template->smarty->_debug = new Smarty_Internal_Debug();
|
||||
}
|
||||
$_template->smarty->_debug->start_render($_template);
|
||||
}
|
||||
if (!$this->processed) {
|
||||
@@ -196,12 +166,13 @@ class Smarty_Template_Compiled extends Smarty_Template_Resource_Base
|
||||
$_template->cached->file_dependency =
|
||||
array_merge($_template->cached->file_dependency, $this->file_dependency);
|
||||
}
|
||||
$this->getRenderedTemplateCode($_template);
|
||||
if ($_template->caching && $this->has_nocache_code) {
|
||||
$_template->cached->hashes[$this->nocache_hash] = true;
|
||||
if ($_template->source->handler->uncompiled) {
|
||||
$_template->source->handler->renderUncompiled($_template->source, $_template);
|
||||
} else {
|
||||
$this->getRenderedTemplateCode($_template);
|
||||
}
|
||||
if (isset($_template->parent) && $_template->parent->_objType == 2 && !empty($_template->tpl_function)) {
|
||||
$_template->parent->tpl_function = array_merge($_template->parent->tpl_function, $_template->tpl_function);
|
||||
if ($_template->caching && $this->has_nocache_code) {
|
||||
$_template->cached->hashes[ $this->nocache_hash ] = true;
|
||||
}
|
||||
if ($_template->smarty->debugging) {
|
||||
$_template->smarty->_debug->end_render($_template);
|
||||
@@ -213,44 +184,35 @@ class Smarty_Template_Compiled extends Smarty_Template_Resource_Base
|
||||
*
|
||||
* @param Smarty_Internal_Template $_template
|
||||
*
|
||||
* @return string
|
||||
* @throws Exception
|
||||
*/
|
||||
public function compileTemplateSource(Smarty_Internal_Template $_template)
|
||||
{
|
||||
$_template->source->compileds = array();
|
||||
$this->file_dependency = array();
|
||||
$this->tpl_function = array();
|
||||
$this->includes = array();
|
||||
$this->nocache_hash = null;
|
||||
$this->unifunc = null;
|
||||
// compile locking
|
||||
if (!$_template->source->handler->recompiled) {
|
||||
if ($saved_timestamp = $_template->compiled->getTimeStamp()) {
|
||||
touch($_template->compiled->filepath);
|
||||
}
|
||||
$saved_timestamp = $_template->source->handler->recompiled ? false : $this->getTimeStamp();
|
||||
if ($saved_timestamp) {
|
||||
touch($this->filepath);
|
||||
}
|
||||
// call compiler
|
||||
// compile locking
|
||||
try {
|
||||
// call compiler
|
||||
$_template->loadCompiler();
|
||||
$code = $_template->compiler->compileTemplate($_template);
|
||||
$this->write($_template, $_template->compiler->compileTemplate($_template));
|
||||
}
|
||||
catch (Exception $e) {
|
||||
// restore old timestamp in case of error
|
||||
if (!$_template->source->handler->recompiled && $saved_timestamp) {
|
||||
touch($_template->compiled->filepath, $saved_timestamp);
|
||||
if ($saved_timestamp) {
|
||||
touch($this->filepath, $saved_timestamp);
|
||||
}
|
||||
unset($_template->compiler);
|
||||
throw $e;
|
||||
}
|
||||
// compiling succeeded
|
||||
if ($_template->compiler->write_compiled_code) {
|
||||
// write compiled template
|
||||
$this->write($_template, $code);
|
||||
$code = '';
|
||||
}
|
||||
// release compiler object to free memory
|
||||
unset($_template->compiler);
|
||||
return $code;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -272,11 +234,7 @@ class Smarty_Template_Compiled extends Smarty_Template_Resource_Base
|
||||
}
|
||||
}
|
||||
return false;
|
||||
} else {
|
||||
$this->content = $code;
|
||||
}
|
||||
$this->timestamp = time();
|
||||
$this->exists = true;
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user