summaryrefslogtreecommitdiff
path: root/lib/smarty3/sysplugins/smarty_internal_runtime_updatecache.php
diff options
context:
space:
mode:
Diffstat (limited to 'lib/smarty3/sysplugins/smarty_internal_runtime_updatecache.php')
-rw-r--r--lib/smarty3/sysplugins/smarty_internal_runtime_updatecache.php152
1 files changed, 85 insertions, 67 deletions
diff --git a/lib/smarty3/sysplugins/smarty_internal_runtime_updatecache.php b/lib/smarty3/sysplugins/smarty_internal_runtime_updatecache.php
index 77d790e..c1abbb3 100644
--- a/lib/smarty3/sysplugins/smarty_internal_runtime_updatecache.php
+++ b/lib/smarty3/sysplugins/smarty_internal_runtime_updatecache.php
@@ -6,7 +6,6 @@
* @package Smarty
* @subpackage PluginsInternal
* @author Uwe Tews
- *
**/
class Smarty_Internal_Runtime_UpdateCache
{
@@ -15,63 +14,13 @@ class Smarty_Internal_Runtime_UpdateCache
*
* @param \Smarty_Template_Cached $cached
* @param Smarty_Internal_Template $_template
- * @param string $content
+ * @param string $content
*/
public function cacheModifiedCheck(Smarty_Template_Cached $cached, Smarty_Internal_Template $_template, $content)
{
}
/**
- * Sanitize content and write it to cache resource
- *
- * @param \Smarty_Template_Cached $cached
- * @param Smarty_Internal_Template $_template
- * @param bool $no_output_filter
- *
- * @throws \SmartyException
- */
- public function removeNoCacheHash(Smarty_Template_Cached $cached, Smarty_Internal_Template $_template,
- $no_output_filter)
- {
- $content = ob_get_clean();
- unset($cached->hashes[ $_template->compiled->nocache_hash ]);
- if (!empty($cached->hashes)) {
- $hash_array = array();
- foreach ($cached->hashes as $hash => $foo) {
- $hash_array[] = "/{$hash}/";
- }
- $content = preg_replace($hash_array, $_template->compiled->nocache_hash, $content);
- }
- $_template->cached->has_nocache_code = false;
- // get text between non-cached items
- $cache_split =
- preg_split("!/\*%%SmartyNocache:{$_template->compiled->nocache_hash}%%\*\/(.+?)/\*/%%SmartyNocache:{$_template->compiled->nocache_hash}%%\*/!s",
- $content);
- // get non-cached items
- preg_match_all("!/\*%%SmartyNocache:{$_template->compiled->nocache_hash}%%\*\/(.+?)/\*/%%SmartyNocache:{$_template->compiled->nocache_hash}%%\*/!s",
- $content, $cache_parts);
- $content = '';
- // loop over items, stitch back together
- foreach ($cache_split as $curr_idx => $curr_split) {
- // escape PHP tags in template content
- $content .= preg_replace('/(<%|%>|<\?php|<\?|\?>|<script\s+language\s*=\s*[\"\']?\s*php\s*[\"\']?\s*>)/',
- "<?php echo '\$1'; ?>\n", $curr_split);
- if (isset($cache_parts[ 0 ][ $curr_idx ])) {
- $_template->cached->has_nocache_code = true;
- $content .= $cache_parts[ 1 ][ $curr_idx ];
- }
- }
- if (!$no_output_filter && !$_template->cached->has_nocache_code &&
- (isset($_template->smarty->autoload_filters[ 'output' ]) ||
- isset($_template->smarty->registered_filters[ 'output' ]))
- ) {
- $content = $_template->smarty->ext->_filterHandler->runFilter('output', $content, $_template);
- }
- // write cache file content
- $this->writeCachedContent($cached, $_template, $content);
- }
-
- /**
* Cache was invalid , so render from compiled and write to cache
*
* @param \Smarty_Template_Cached $cached
@@ -91,15 +40,15 @@ class Smarty_Internal_Runtime_UpdateCache
$_template->smarty->_debug->start_cache($_template);
}
$this->removeNoCacheHash($cached, $_template, $no_output_filter);
- $compile_check = $_template->smarty->compile_check;
- $_template->smarty->compile_check = false;
- if (isset($_template->parent) && $_template->parent->_objType == 2) {
+ $compile_check = (int)$_template->compile_check;
+ $_template->compile_check = Smarty::COMPILECHECK_OFF;
+ if ($_template->_isSubTpl()) {
$_template->compiled->unifunc = $_template->parent->compiled->unifunc;
}
if (!$_template->cached->processed) {
$_template->cached->process($_template, true);
}
- $_template->smarty->compile_check = $compile_check;
+ $_template->compile_check = $compile_check;
$cached->getRenderedTemplateCode($_template);
if ($_template->smarty->debugging) {
$_template->smarty->_debug->end_cache($_template);
@@ -107,38 +56,110 @@ class Smarty_Internal_Runtime_UpdateCache
}
/**
- * Writes the content to cache resource
+ * Sanitize content and write it to cache resource
*
* @param \Smarty_Template_Cached $cached
* @param Smarty_Internal_Template $_template
+ * @param bool $no_output_filter
+ *
+ * @throws \SmartyException
+ */
+ public function removeNoCacheHash(
+ Smarty_Template_Cached $cached,
+ Smarty_Internal_Template $_template,
+ $no_output_filter
+ ) {
+ $php_pattern = '/(<%|%>|<\?php|<\?|\?>|<script\s+language\s*=\s*[\"\']?\s*php\s*[\"\']?\s*>)/';
+ $content = ob_get_clean();
+ $hash_array = $cached->hashes;
+ $hash_array[ $_template->compiled->nocache_hash ] = true;
+ $hash_array = array_keys($hash_array);
+ $nocache_hash = '(' . implode('|', $hash_array) . ')';
+ $_template->cached->has_nocache_code = false;
+ // get text between non-cached items
+ $cache_split =
+ preg_split(
+ "!/\*%%SmartyNocache:{$nocache_hash}%%\*\/(.+?)/\*/%%SmartyNocache:{$nocache_hash}%%\*/!s",
+ $content
+ );
+ // get non-cached items
+ preg_match_all(
+ "!/\*%%SmartyNocache:{$nocache_hash}%%\*\/(.+?)/\*/%%SmartyNocache:{$nocache_hash}%%\*/!s",
+ $content,
+ $cache_parts
+ );
+ $content = '';
+ // loop over items, stitch back together
+ foreach ($cache_split as $curr_idx => $curr_split) {
+ if (preg_match($php_pattern, $curr_split)) {
+ // escape PHP tags in template content
+ $php_split = preg_split(
+ $php_pattern,
+ $curr_split
+ );
+ preg_match_all(
+ $php_pattern,
+ $curr_split,
+ $php_parts
+ );
+ foreach ($php_split as $idx_php => $curr_php) {
+ $content .= $curr_php;
+ if (isset($php_parts[ 0 ][ $idx_php ])) {
+ $content .= "<?php echo '{$php_parts[ 1 ][ $idx_php ]}'; ?>\n";
+ }
+ }
+ } else {
+ $content .= $curr_split;
+ }
+ if (isset($cache_parts[ 0 ][ $curr_idx ])) {
+ $_template->cached->has_nocache_code = true;
+ $content .= $cache_parts[ 2 ][ $curr_idx ];
+ }
+ }
+ if (!$no_output_filter && !$_template->cached->has_nocache_code
+ && (isset($_template->smarty->autoload_filters[ 'output' ])
+ || isset($_template->smarty->registered_filters[ 'output' ]))
+ ) {
+ $content = $_template->smarty->ext->_filterHandler->runFilter('output', $content, $_template);
+ }
+ // write cache file content
+ $this->writeCachedContent($_template, $content);
+ }
+
+ /**
+ * Writes the content to cache resource
+ *
+ * @param Smarty_Internal_Template $_template
* @param string $content
*
* @return bool
*/
- public function writeCachedContent(Smarty_Template_Cached $cached, Smarty_Internal_Template $_template, $content)
+ public function writeCachedContent(Smarty_Internal_Template $_template, $content)
{
- if ($_template->source->handler->recompiled || !($_template->caching == Smarty::CACHING_LIFETIME_CURRENT ||
- $_template->caching == Smarty::CACHING_LIFETIME_SAVED)
+ if ($_template->source->handler->recompiled || !$_template->caching
) {
// don't write cache file
return false;
}
+ if (!isset($_template->cached)) {
+ $_template->loadCached();
+ }
$content = $_template->smarty->ext->_codeFrame->create($_template, $content, '', true);
- return $this->write($cached, $_template, $content);
+ return $this->write($_template, $content);
}
/**
* Write this cache object to handler
*
- * @param \Smarty_Template_Cached $cached
* @param Smarty_Internal_Template $_template template object
* @param string $content content to cache
*
* @return bool success
*/
- public function write(Smarty_Template_Cached $cached, Smarty_Internal_Template $_template, $content)
+ public function write(Smarty_Internal_Template $_template, $content)
{
if (!$_template->source->handler->recompiled) {
+ $cached = $_template->cached;
if ($cached->handler->writeCachedContent($_template, $content)) {
$cached->content = null;
$cached->timestamp = time();
@@ -149,7 +170,6 @@ class Smarty_Internal_Runtime_UpdateCache
if ($_template->smarty->cache_locking) {
$cached->handler->releaseLock($_template->smarty, $cached);
}
-
return true;
}
$cached->content = null;
@@ -158,8 +178,6 @@ class Smarty_Internal_Runtime_UpdateCache
$cached->valid = false;
$cached->processed = false;
}
-
return false;
}
-
-} \ No newline at end of file
+}