define missing properties

This commit is contained in:
uwetews
2015-08-15 18:25:06 +02:00
parent af6f77a9e6
commit 9ad5e1eb1e
3 changed files with 53 additions and 43 deletions

View File

@@ -16,13 +16,6 @@
*/ */
class Smarty_Template_Cached extends Smarty_Template_Resource_Base class Smarty_Template_Cached extends Smarty_Template_Resource_Base
{ {
/**
* Source Content
*
* @var string
*/
public $content = null;
/** /**
* Cache Is Valid * Cache Is Valid
* *
@@ -44,6 +37,13 @@ class Smarty_Template_Cached extends Smarty_Template_Resource_Base
*/ */
public $cache_id = null; public $cache_id = null;
/**
* saved cache lifetime in seconds
*
* @var integer
*/
public $cache_lifetime = 0;
/** /**
* Id for cache locking * Id for cache locking
* *
@@ -65,7 +65,6 @@ class Smarty_Template_Cached extends Smarty_Template_Resource_Base
*/ */
public $source = null; public $source = null;
/** /**
* create Cached Object container * create Cached Object container
* *
@@ -92,7 +91,9 @@ class Smarty_Template_Cached extends Smarty_Template_Resource_Base
$_template->cached = $cached = new Smarty_Template_Cached($_template); $_template->cached = $cached = new Smarty_Template_Cached($_template);
$cached->handler->populate($cached, $_template); $cached->handler->populate($cached, $_template);
// caching enabled ? // caching enabled ?
if (!($_template->caching == Smarty::CACHING_LIFETIME_CURRENT || $_template->caching == Smarty::CACHING_LIFETIME_SAVED) || $_template->source->recompiled) { if (!($_template->caching == Smarty::CACHING_LIFETIME_CURRENT ||
$_template->caching == Smarty::CACHING_LIFETIME_SAVED) || $_template->source->recompiled
) {
$cached->valid = false; $cached->valid = false;
} }
return $cached; return $cached;
@@ -117,11 +118,15 @@ class Smarty_Template_Cached extends Smarty_Template_Resource_Base
} else { } else {
$this->valid = true; $this->valid = true;
} }
if ($this->valid && $_template->caching == Smarty::CACHING_LIFETIME_CURRENT && $_template->cache_lifetime >= 0 && time() > ($this->timestamp + $_template->cache_lifetime)) { if ($this->valid && $_template->caching == Smarty::CACHING_LIFETIME_CURRENT &&
$_template->cache_lifetime >= 0 && time() > ($this->timestamp + $_template->cache_lifetime)
) {
// lifetime expired // lifetime expired
$this->valid = false; $this->valid = false;
} }
if ($this->valid && $_template->smarty->compile_check == 1 && $_template->source->getTimeStamp() > $this->timestamp) { if ($this->valid && $_template->smarty->compile_check == 1 &&
$_template->source->getTimeStamp() > $this->timestamp
) {
$this->valid = false; $this->valid = false;
} }
if ($this->valid || !$_template->smarty->cache_locking) { if ($this->valid || !$_template->smarty->cache_locking) {
@@ -154,7 +159,10 @@ class Smarty_Template_Cached extends Smarty_Template_Resource_Base
} else { } else {
return $this->valid; return $this->valid;
} }
if ($this->valid && $_template->caching === Smarty::CACHING_LIFETIME_SAVED && $_template->cached->cache_lifetime >= 0 && (time() > ($_template->cached->timestamp + $_template->cached->cache_lifetime))) { if ($this->valid && $_template->caching === Smarty::CACHING_LIFETIME_SAVED &&
$_template->cached->cache_lifetime >= 0 &&
(time() > ($_template->cached->timestamp + $_template->cached->cache_lifetime))
) {
$this->valid = false; $this->valid = false;
} }
if ($_template->smarty->cache_locking) { if ($_template->smarty->cache_locking) {
@@ -215,10 +223,11 @@ class Smarty_Template_Cached extends Smarty_Template_Resource_Base
{ {
if (!$_template->source->recompiled) { if (!$_template->source->recompiled) {
if ($this->handler->writeCachedContent($_template, $content)) { if ($this->handler->writeCachedContent($_template, $content)) {
$this->buffer = null; $this->content = null;
$this->timestamp = time(); $this->timestamp = time();
$this->exists = true; $this->exists = true;
$this->valid = true; $this->valid = true;
$this->cache_lifetime = $_template->cache_lifetime;
$this->processed = false; $this->processed = false;
if ($_template->smarty->cache_locking) { if ($_template->smarty->cache_locking) {
$this->handler->releaseLock($_template->smarty, $this); $this->handler->releaseLock($_template->smarty, $this);
@@ -226,7 +235,7 @@ class Smarty_Template_Cached extends Smarty_Template_Resource_Base
return true; return true;
} }
$this->buffer = null; $this->content = null;
$this->timestamp = false; $this->timestamp = false;
$this->exists = false; $this->exists = false;
$this->valid = false; $this->valid = false;
@@ -277,7 +286,10 @@ class Smarty_Template_Cached extends Smarty_Template_Resource_Base
$output .= $cache_parts[1][$curr_idx]; $output .= $cache_parts[1][$curr_idx];
} }
} }
if (!$no_output_filter && !$_template->compiled->has_nocache_code && (isset($_template->smarty->autoload_filters['output']) || isset($_template->smarty->registered_filters['output']))) { if (!$no_output_filter && !$_template->compiled->has_nocache_code &&
(isset($_template->smarty->autoload_filters['output']) ||
isset($_template->smarty->registered_filters['output']))
) {
$output = Smarty_Internal_Filter_Handler::runFilter('output', $output, $_template); $output = Smarty_Internal_Filter_Handler::runFilter('output', $output, $_template);
} }
// write cache file content // write cache file content
@@ -294,7 +306,9 @@ class Smarty_Template_Cached extends Smarty_Template_Resource_Base
*/ */
public function writeCachedContent(Smarty_Internal_Template $_template, $content) public function writeCachedContent(Smarty_Internal_Template $_template, $content)
{ {
if ($_template->source->recompiled || !($_template->caching == Smarty::CACHING_LIFETIME_CURRENT || $_template->caching == Smarty::CACHING_LIFETIME_SAVED)) { if ($_template->source->recompiled || !($_template->caching == Smarty::CACHING_LIFETIME_CURRENT ||
$_template->caching == Smarty::CACHING_LIFETIME_SAVED)
) {
// don't write cache file // don't write cache file
return false; return false;
} }
@@ -324,7 +338,8 @@ class Smarty_Template_Cached extends Smarty_Template_Resource_Base
public function cacheModifiedCheck(Smarty_Internal_Template $_template, $content) public function cacheModifiedCheck(Smarty_Internal_Template $_template, $content)
{ {
$_isCached = $_template->isCached() && !$_template->compiled->has_nocache_code; $_isCached = $_template->isCached() && !$_template->compiled->has_nocache_code;
$_last_modified_date = @substr($_SERVER['HTTP_IF_MODIFIED_SINCE'], 0, strpos($_SERVER['HTTP_IF_MODIFIED_SINCE'], 'GMT') + 3); $_last_modified_date = @substr($_SERVER['HTTP_IF_MODIFIED_SINCE'], 0, strpos($_SERVER['HTTP_IF_MODIFIED_SINCE'], 'GMT') +
3);
if ($_isCached && $this->timestamp <= strtotime($_last_modified_date)) { if ($_isCached && $this->timestamp <= strtotime($_last_modified_date)) {
switch (PHP_SAPI) { switch (PHP_SAPI) {
case 'cgi': // php-cgi < 5.3 case 'cgi': // php-cgi < 5.3
@@ -351,7 +366,8 @@ class Smarty_Template_Cached extends Smarty_Template_Resource_Base
if ( /* ^phpunit */ if ( /* ^phpunit */
!empty($_SERVER['SMARTY_PHPUNIT_DISABLE_HEADERS']) /* phpunit$ */ !empty($_SERVER['SMARTY_PHPUNIT_DISABLE_HEADERS']) /* phpunit$ */
) { ) {
$_SERVER['SMARTY_PHPUNIT_HEADERS'][] = 'Last-Modified: ' . gmdate('D, d M Y H:i:s', $this->timestamp) . ' GMT'; $_SERVER['SMARTY_PHPUNIT_HEADERS'][] = 'Last-Modified: ' .
gmdate('D, d M Y H:i:s', $this->timestamp) . ' GMT';
} }
break; break;
default: default:

View File

@@ -132,7 +132,7 @@ class Smarty_Template_Compiled extends Smarty_Template_Resource_Base
$level = ob_get_level(); $level = ob_get_level();
ob_start(); ob_start();
try { try {
eval("?>" . $this->buffer); eval("?>" . $this->content);
} }
catch (Exception $e) { catch (Exception $e) {
while (ob_get_level() > $level) { while (ob_get_level() > $level) {
@@ -141,7 +141,7 @@ class Smarty_Template_Compiled extends Smarty_Template_Resource_Base
throw $e; throw $e;
} }
ob_get_clean(); ob_get_clean();
$this->buffer = null; $this->content = null;
} else { } else {
$this->loadCompiledTemplate($_template); $this->loadCompiledTemplate($_template);
} }
@@ -263,7 +263,7 @@ class Smarty_Template_Compiled extends Smarty_Template_Resource_Base
} }
return false; return false;
} else { } else {
$this->buffer = $code; $this->content = $code;
} }
$this->timestamp = time(); $this->timestamp = time();
$this->exists = true; $this->exists = true;
@@ -282,19 +282,6 @@ class Smarty_Template_Compiled extends Smarty_Template_Resource_Base
if (!$_template->source->recompiled) { if (!$_template->source->recompiled) {
return file_get_contents($this->filepath); return file_get_contents($this->filepath);
} }
return isset($this->buffer) ? $this->buffer : false; return isset($this->content) ? $this->content : false;
}
/**
* Get compiled time stamp
*
* @return int
*/
public function getTimeStamp()
{
if ($this->exists && !isset($this->timestamp)) {
$this->timestamp = @filemtime($this->filepath);
}
return $this->timestamp;
} }
} }

View File

@@ -67,11 +67,11 @@ abstract class Smarty_Template_Resource_Base
public $file_dependency = array(); public $file_dependency = array();
/** /**
* Code of recompiled template resource * Content buffer
* *
* @var string|null * @var string
*/ */
public $buffer = null; public $content = null;
/** /**
* required plugins * required plugins
@@ -80,6 +80,13 @@ abstract class Smarty_Template_Resource_Base
*/ */
public $required_plugins = array(); public $required_plugins = array();
/**
* Known template functions
*
* @var array
*/
public $tpl_function = array();
/** /**
* Process resource * Process resource
* *
@@ -125,7 +132,7 @@ abstract class Smarty_Template_Resource_Base
} }
return false; return false;
} else { } else {
$this->buffer = $code; $this->content = $code;
} }
$this->timestamp = time(); $this->timestamp = time();
$this->exists = true; $this->exists = true;