aboutsummaryrefslogtreecommitdiffstats
path: root/library/Smarty/libs/sysplugins/smarty_template_compiled.php
diff options
context:
space:
mode:
authorMario Vavti <mario@mariovavti.com>2015-12-06 21:09:58 +0100
committerMario Vavti <mario@mariovavti.com>2015-12-06 21:09:58 +0100
commit26c465ad0c1d5b6801507ed190430f44ac92c672 (patch)
tree9e80c34da1235e6dd55942c23bf9511fac31344d /library/Smarty/libs/sysplugins/smarty_template_compiled.php
parentf2d70831838b0738e6895296f3e8ce02f86fec2f (diff)
downloadvolse-hubzilla-26c465ad0c1d5b6801507ed190430f44ac92c672.tar.gz
volse-hubzilla-26c465ad0c1d5b6801507ed190430f44ac92c672.tar.bz2
volse-hubzilla-26c465ad0c1d5b6801507ed190430f44ac92c672.zip
update smarty to 3.1.28-dev which fixes a bug where changes in a template are only visible on the second pageload which is annoying for developing
Diffstat (limited to 'library/Smarty/libs/sysplugins/smarty_template_compiled.php')
-rw-r--r--library/Smarty/libs/sysplugins/smarty_template_compiled.php163
1 files changed, 86 insertions, 77 deletions
diff --git a/library/Smarty/libs/sysplugins/smarty_template_compiled.php b/library/Smarty/libs/sysplugins/smarty_template_compiled.php
index 3ff8fa897..e7710f85e 100644
--- a/library/Smarty/libs/sysplugins/smarty_template_compiled.php
+++ b/library/Smarty/libs/sysplugins/smarty_template_compiled.php
@@ -9,48 +9,15 @@
* @author Rodney Rehm
* @property string $content compiled content
*/
-class Smarty_Template_Compiled
+class Smarty_Template_Compiled extends Smarty_Template_Resource_Base
{
- /**
- * Compiled Filepath
- *
- * @var string
- */
- public $filepath = null;
-
- /**
- * Compiled Timestamp
- *
- * @var integer
- */
- public $timestamp = null;
-
- /**
- * Compiled Existence
- *
- * @var boolean
- */
- public $exists = false;
/**
- * Compiled Content Loaded
- *
- * @var boolean
- */
- public $processed = false;
- /**
- * Code of recompiled template resource
+ * nocache hash
*
* @var string|null
*/
- public $code = null;
-
- /**
- * create Compiled Object container
- */
- public function __construct()
- {
- }
+ public $nocache_hash = null;
/**
* get a Compiled Object of this source
@@ -61,11 +28,10 @@ class Smarty_Template_Compiled
*/
static function load($_template)
{
- if (!isset($_template->source)) {
- $_template->loadSource();
- }
// check runtime cache
- if (!$_template->source->recompiled && $_template->smarty->resource_caching) {
+ 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#';
@@ -76,13 +42,15 @@ class Smarty_Template_Compiled
}
}
$compiled = new Smarty_Template_Compiled();
- if (method_exists($_template->source->handler, 'populateCompiledFilepath')) {
+ if ($_template->source->handler->hasCompiledHandler) {
$_template->source->handler->populateCompiledFilepath($compiled, $_template);
} else {
$compiled->populateCompiledFilepath($_template);
}
// runtime cache
- if (!$_template->source->recompiled && $_template->smarty->resource_caching) {
+ if (!$_template->source->handler->recompiled &&
+ ($_template->smarty->resource_cache_mode & Smarty::RESOURCE_CACHE_ON)
+ ) {
$_template->source->compileds[$_cache_key] = $compiled;
}
return $compiled;
@@ -95,20 +63,20 @@ class Smarty_Template_Compiled
**/
public function populateCompiledFilepath(Smarty_Internal_Template $_template)
{
- $_compile_id = isset($_template->compile_id) ? preg_replace('![^\w\|]+!', '_', $_template->compile_id) : null;
+ $_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);
+ $_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);
+ $_flag =
+ '_' . ((int) $_template->smarty->merge_compiled_includes + (int) $_template->smarty->escape_html * 2);
}
$_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;
+ $_filepath = substr($_filepath, 0, 2) . DS . substr($_filepath, 2, 2) . DS . substr($_filepath, 4, 2) . DS .
+ $_filepath;
}
$_compile_dir_sep = $_template->smarty->use_sub_dirs ? DS : '^';
if (isset($_compile_id)) {
@@ -124,7 +92,7 @@ class Smarty_Template_Compiled
// set basename if not specified
$_basename = $_template->source->handler->getBasename($_template->source);
if ($_basename === null) {
- $_basename = basename(preg_replace('![^\w\/]+!', '_', $_template->source->name));
+ $_basename = basename(preg_replace('![^\w]+!', '_', $_template->source->name));
}
// separate (optional) basename by dot
if ($_basename) {
@@ -132,9 +100,9 @@ class Smarty_Template_Compiled
}
$this->filepath = $_compile_dir . $_filepath . '.' . $_template->source->type . $_basename . $_cache . '.php';
- $this->timestamp = $this->exists = is_file($this->filepath);
- if ($this->exists) {
- $this->timestamp = @filemtime($this->filepath);
+ $this->exists = is_file($this->filepath);
+ if (!$this->exists) {
+ $this->timestamp = false;
}
}
@@ -148,15 +116,18 @@ class Smarty_Template_Compiled
public function process(Smarty_Internal_Template $_template)
{
$_smarty_tpl = $_template;
- if ($_template->source->recompiled || !$_template->compiled->exists || $_template->smarty->force_compile) {
+ 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->recompiled) {
+ if ($_template->source->handler->recompiled) {
$level = ob_get_level();
ob_start();
try {
- eval("?>" . $this->code);
+ eval("?>" . $this->content);
}
catch (Exception $e) {
while (ob_get_level() > $level) {
@@ -165,26 +136,47 @@ class Smarty_Template_Compiled
throw $e;
}
ob_get_clean();
- $this->code = null;
+ $this->content = null;
} else {
- include($_template->compiled->filepath);
+ $this->loadCompiledTemplate($_template);
}
$_template->smarty->compile_check = $compileCheck;
} else {
- include($_template->compiled->filepath);
+ $_template->mustCompile = true;
+ @include($_template->compiled->filepath);
if ($_template->mustCompile) {
$this->compileTemplateSource($_template);
$compileCheck = $_template->smarty->compile_check;
$_template->smarty->compile_check = false;
- include($_template->compiled->filepath);
+ $this->loadCompiledTemplate($_template);
$_template->smarty->compile_check = $compileCheck;
}
}
- $this->unifunc = $_template->properties['unifunc'];
+ $_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
+ */
+ private function loadCompiledTemplate(Smarty_Internal_Template $_template)
+ {
+ if (function_exists('opcache_invalidate')) {
+ opcache_invalidate($_template->compiled->filepath);
+ }
+ $_smarty_tpl = $_template;
+ if (defined('HHVM_VERSION')) {
+ $_template->smarty->ext->_hhvm->includeHhvm($_template, $_template->compiled->filepath);
+ } else {
+ include($_template->compiled->filepath);
+ }
+ }
+
+ /**
* render compiled template code
*
* @param Smarty_Internal_Template $_template
@@ -194,12 +186,26 @@ class Smarty_Template_Compiled
*/
public function render(Smarty_Internal_Template $_template)
{
-
+ if ($_template->smarty->debugging) {
+ $_template->smarty->_debug->start_render($_template);
+ }
if (!$this->processed) {
$this->process($_template);
}
- $_template->properties['unifunc'] = $this->unifunc;
- return $_template->getRenderedTemplateCode();
+ if (isset($_template->cached)) {
+ $_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 (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->smarty->debugging) {
+ $_template->smarty->_debug->end_render($_template);
+ }
}
/**
@@ -212,22 +218,26 @@ class Smarty_Template_Compiled
*/
public function compileTemplateSource(Smarty_Internal_Template $_template)
{
- if (!$_template->source->recompiled) {
- $_template->properties['file_dependency'] = array();
- }
+ $_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->recompiled) {
- if ($saved_timestamp = $_template->compiled->timestamp) {
+ if (!$_template->source->handler->recompiled) {
+ if ($saved_timestamp = $_template->compiled->getTimeStamp()) {
touch($_template->compiled->filepath);
}
}
// call compiler
try {
+ $_template->loadCompiler();
$code = $_template->compiler->compileTemplate($_template);
}
catch (Exception $e) {
// restore old timestamp in case of error
- if (!$_template->source->recompiled && $saved_timestamp) {
+ if (!$_template->source->handler->recompiled && $saved_timestamp) {
touch($_template->compiled->filepath, $saved_timestamp);
}
throw $e;
@@ -253,18 +263,17 @@ class Smarty_Template_Compiled
*/
public function write(Smarty_Internal_Template $_template, $code)
{
- if (!$_template->source->recompiled) {
- $obj = new Smarty_Internal_Write_File();
- if ($obj->writeFile($this->filepath, $code, $_template->smarty) === true) {
+ if (!$_template->source->handler->recompiled) {
+ if ($_template->smarty->ext->_writeFile->writeFile($this->filepath, $code, $_template->smarty) === true) {
$this->timestamp = $this->exists = is_file($this->filepath);
if ($this->exists) {
- $this->timestamp = @filemtime($this->filepath);
+ $this->timestamp = filemtime($this->filepath);
return true;
}
}
return false;
} else {
- $this->code = $code;
+ $this->content = $code;
}
$this->timestamp = time();
$this->exists = true;
@@ -280,7 +289,7 @@ class Smarty_Template_Compiled
*/
public function read(Smarty_Internal_Template $_template)
{
- if (!$_template->source->recompiled) {
+ if (!$_template->source->handler->recompiled) {
return file_get_contents($this->filepath);
}
return isset($this->content) ? $this->content : false;