From 26c465ad0c1d5b6801507ed190430f44ac92c672 Mon Sep 17 00:00:00 2001 From: Mario Vavti Date: Sun, 6 Dec 2015 21:09:58 +0100 Subject: 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 --- .../smarty_internal_cacheresource_file.php | 135 +++------------------ 1 file changed, 20 insertions(+), 115 deletions(-) (limited to 'library/Smarty/libs/sysplugins/smarty_internal_cacheresource_file.php') diff --git a/library/Smarty/libs/sysplugins/smarty_internal_cacheresource_file.php b/library/Smarty/libs/sysplugins/smarty_internal_cacheresource_file.php index de794517a..64d02dfe5 100644 --- a/library/Smarty/libs/sysplugins/smarty_internal_cacheresource_file.php +++ b/library/Smarty/libs/sysplugins/smarty_internal_cacheresource_file.php @@ -29,14 +29,12 @@ class Smarty_Internal_CacheResource_File extends Smarty_CacheResource { $_source_file_path = str_replace(':', '.', $_template->source->filepath); $_cache_id = isset($_template->cache_id) ? preg_replace('![^\w\|]+!', '_', $_template->cache_id) : null; - $_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; $_filepath = $_template->source->uid; // 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($_cache_id)) { @@ -60,7 +58,8 @@ class Smarty_Internal_CacheResource_File extends Smarty_CacheResource } $cached->lock_id = $_lock_dir . sha1($_cache_id . $_compile_id . $_template->source->uid) . '.lock'; } - $cached->filepath = $_cache_dir . $_cache_id . $_compile_id . $_filepath . '.' . basename($_source_file_path) . '.php'; + $cached->filepath = $_cache_dir . $_cache_id . $_compile_id . $_filepath . '.' . basename($_source_file_path) . + '.php'; $cached->timestamp = $cached->exists = is_file($cached->filepath); if ($cached->exists) { $cached->timestamp = filemtime($cached->filepath); @@ -87,17 +86,22 @@ class Smarty_Internal_CacheResource_File extends Smarty_CacheResource * * @param Smarty_Internal_Template $_template template object * @param Smarty_Template_Cached $cached cached object + * @param bool $update flag if called because cache update * - * @return booleantrue or false if the cached content does not exist + * @return boolean true or false if the cached content does not exist */ - public function process(Smarty_Internal_Template $_template, Smarty_Template_Cached $cached = null) + public function process(Smarty_Internal_Template $_template, Smarty_Template_Cached $cached = null, $update = false) { /** @var Smarty_Internal_Template $_smarty_tpl * used in included file */ $_smarty_tpl = $_template; - - return @include $_template->cached->filepath; + $_template->cached->valid = false; + if ($update && defined('HHVM_VERSION')) { + return $_template->smarty->ext->_hhvm->includeHhvm($_template, $_template->cached->filepath); + } else { + return @include $_template->cached->filepath; + } } /** @@ -110,8 +114,10 @@ class Smarty_Internal_CacheResource_File extends Smarty_CacheResource */ public function writeCachedContent(Smarty_Internal_Template $_template, $content) { - $obj = new Smarty_Internal_Write_File(); - if ($obj->writeFile($_template->cached->filepath, $content, $_template->smarty) === true) { + if ($_template->smarty->ext->_writeFile->writeFile($_template->cached->filepath, $content, $_template->smarty) === true) { + if (function_exists('opcache_invalidate')) { + opcache_invalidate($_template->cached->filepath); + } $cached = $_template->cached; $cached->timestamp = $cached->exists = is_file($cached->filepath); if ($cached->exists) { @@ -147,7 +153,7 @@ class Smarty_Internal_CacheResource_File extends Smarty_CacheResource */ public function clearAll(Smarty $smarty, $exp_time = null) { - return $this->clear($smarty, null, null, null, $exp_time); + return Smarty_Internal_Extension_Clear::clear($smarty, null, null, null, $exp_time); } /** @@ -163,108 +169,7 @@ class Smarty_Internal_CacheResource_File extends Smarty_CacheResource */ public function clear(Smarty $smarty, $resource_name, $cache_id, $compile_id, $exp_time) { - $_cache_id = isset($cache_id) ? preg_replace('![^\w\|]+!', '_', $cache_id) : null; - $_compile_id = isset($compile_id) ? preg_replace('![^\w\|]+!', '_', $compile_id) : null; - $_dir_sep = $smarty->use_sub_dirs ? '/' : '^'; - $_compile_id_offset = $smarty->use_sub_dirs ? 3 : 0; - $_dir = realpath($smarty->getCacheDir()) . '/'; - if ($_dir == '/') { //We should never want to delete this! - return 0; - } - $_dir_length = strlen($_dir); - if (isset($_cache_id)) { - $_cache_id_parts = explode('|', $_cache_id); - $_cache_id_parts_count = count($_cache_id_parts); - if ($smarty->use_sub_dirs) { - foreach ($_cache_id_parts as $id_part) { - $_dir .= $id_part . DS; - } - } - } - if (isset($resource_name)) { - $_save_stat = $smarty->caching; - $smarty->caching = true; - $tpl = new $smarty->template_class($resource_name, $smarty); - $smarty->caching = $_save_stat; - - // remove from template cache - $tpl->source; // have the template registered before unset() - if ($smarty->allow_ambiguous_resources) { - $_templateId = $tpl->source->unique_resource . $tpl->cache_id . $tpl->compile_id; - } else { - $_templateId = $smarty->joined_template_dir . '#' . $resource_name . $tpl->cache_id . $tpl->compile_id; - } - if (isset($_templateId[150])) { - $_templateId = sha1($_templateId); - } - unset($smarty->template_objects[$_templateId]); - - if ($tpl->source->exists) { - $_resourcename_parts = basename(str_replace('^', '/', $tpl->cached->filepath)); - } else { - return 0; - } - } - $_count = 0; - $_time = time(); - if (file_exists($_dir)) { - $_cacheDirs = new RecursiveDirectoryIterator($_dir); - $_cache = new RecursiveIteratorIterator($_cacheDirs, RecursiveIteratorIterator::CHILD_FIRST); - foreach ($_cache as $_file) { - if (substr(basename($_file->getPathname()), 0, 1) == '.' || strpos($_file, '.svn') !== false) { - continue; - } - // directory ? - if ($_file->isDir()) { - if (!$_cache->isDot()) { - // delete folder if empty - @rmdir($_file->getPathname()); - } - } else { - $_parts = explode($_dir_sep, str_replace('\\', '/', substr((string) $_file, $_dir_length))); - $_parts_count = count($_parts); - // check name - if (isset($resource_name)) { - if ($_parts[$_parts_count - 1] != $_resourcename_parts) { - continue; - } - } - // check compile id - if (isset($_compile_id) && (!isset($_parts[$_parts_count - 2 - $_compile_id_offset]) || $_parts[$_parts_count - 2 - $_compile_id_offset] != $_compile_id)) { - continue; - } - // check cache id - if (isset($_cache_id)) { - // count of cache id parts - $_parts_count = (isset($_compile_id)) ? $_parts_count - 2 - $_compile_id_offset : $_parts_count - 1 - $_compile_id_offset; - if ($_parts_count < $_cache_id_parts_count) { - continue; - } - for ($i = 0; $i < $_cache_id_parts_count; $i ++) { - if ($_parts[$i] != $_cache_id_parts[$i]) { - continue 2; - } - } - } - // expired ? - if (isset($exp_time)) { - if ($exp_time < 0) { - preg_match('#\'cache_lifetime\' =>\s*(\d*)#', file_get_contents($_file), $match); - if ($_time < (@filemtime($_file) + $match[1])) { - continue; - } - } else { - if ($_time - @filemtime($_file) < $exp_time) { - continue; - } - } - } - $_count += @unlink((string) $_file) ? 1 : 0; - } - } - } - - return $_count; + return Smarty_Internal_Extension_Clear::clear($smarty, $resource_name, $cache_id, $compile_id, $exp_time); } /** -- cgit v1.2.3