mirror of
https://github.com/smarty-php/smarty.git
synced 2025-08-04 10:24:26 +02:00
add support for is-modified-since headers, adjust a doc example
This commit is contained in:
@@ -97,6 +97,7 @@ class Smarty
|
|||||||
var $cache_handler_func = null; // function used for cached content. this is
|
var $cache_handler_func = null; // function used for cached content. this is
|
||||||
// an alternative to using the built-in file
|
// an alternative to using the built-in file
|
||||||
// based caching.
|
// based caching.
|
||||||
|
var $check_if_modified = true; // respect If-Modified-Since headers on cached content
|
||||||
|
|
||||||
|
|
||||||
var $default_template_handler_func = ''; // function to handle missing templates
|
var $default_template_handler_func = ''; // function to handle missing templates
|
||||||
@@ -546,15 +547,26 @@ class Smarty
|
|||||||
$_smarty_results = $this->_process_cached_inserts($_smarty_results);
|
$_smarty_results = $this->_process_cached_inserts($_smarty_results);
|
||||||
}
|
}
|
||||||
if ($_smarty_display) {
|
if ($_smarty_display) {
|
||||||
echo $_smarty_results;
|
|
||||||
if ($this->debugging)
|
if ($this->debugging)
|
||||||
{
|
{
|
||||||
// capture time for debugging info
|
// capture time for debugging info
|
||||||
$this->_smarty_debug_info[$included_tpls_idx]['exec_time'] = $this->_get_microtime() - $debug_start_time;
|
$this->_smarty_debug_info[$included_tpls_idx]['exec_time'] = $this->_get_microtime() - $debug_start_time;
|
||||||
|
|
||||||
echo $this->_generate_debug_output();
|
$_smarty_results .= $this->_generate_debug_output();
|
||||||
}
|
}
|
||||||
return;
|
if( $this->check_if_modified ) {
|
||||||
|
global $HTTP_IF_MODIFIED_SINCE;
|
||||||
|
$last_modified_date = substr($HTTP_IF_MODIFIED_SINCE,0,strpos($HTTP_IF_MODIFIED_SINCE,'GMT')+3);
|
||||||
|
$gmt_mtime = gmdate('D, d M Y H:i:s', $this->_cache_info['timestamp']).' GMT';
|
||||||
|
if( !$this->_cache_info['insert_tags']
|
||||||
|
&& $gmt_mtime == $last_modified_date ) {
|
||||||
|
header("HTTP/1.1 304 Not Modified");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
header("Content-Length: ".strlen($_smarty_results));
|
||||||
|
header("Last-Modified: ".$gmt_mtime);
|
||||||
|
echo $_smarty_results;
|
||||||
|
return true;
|
||||||
} else {
|
} else {
|
||||||
return $_smarty_results;
|
return $_smarty_results;
|
||||||
}
|
}
|
||||||
|
15
docs.sgml
15
docs.sgml
@@ -1473,13 +1473,18 @@ function get_db_template ($tpl_name, &$tpl_source, &$tpl_timestamp,
|
|||||||
$get_source=true, &$smarty_obj) {
|
$get_source=true, &$smarty_obj) {
|
||||||
|
|
||||||
if($get_source) {
|
if($get_source) {
|
||||||
// do database calls (or whatever) here to fetch your template, populating
|
// do database call here to fetch your template, populating
|
||||||
// $tpl_source and $tpl_timestamp.
|
// $tpl_source and $tpl_timestamp.
|
||||||
$tpl_source = "This is a simulation of a template fetched from a db.";
|
$sql = new SQL;
|
||||||
$tpl_timestamp = mktime();
|
$sql->query("select tpl_source, tpl_timestamp from my_table
|
||||||
|
where tpl_name='$tpl_name'");
|
||||||
|
extract($sql->record);
|
||||||
} else {
|
} else {
|
||||||
// just populate $tpl_timestamp.
|
// do database call here to populate $tpl_timestamp.
|
||||||
$tpl_timestamp = mktime();
|
$sql = new SQL;
|
||||||
|
$sql->query("select tpl_timestamp from my_table
|
||||||
|
where tpl_name='$tpl_name'");
|
||||||
|
extract($sql->record);
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
@@ -97,6 +97,7 @@ class Smarty
|
|||||||
var $cache_handler_func = null; // function used for cached content. this is
|
var $cache_handler_func = null; // function used for cached content. this is
|
||||||
// an alternative to using the built-in file
|
// an alternative to using the built-in file
|
||||||
// based caching.
|
// based caching.
|
||||||
|
var $check_if_modified = true; // respect If-Modified-Since headers on cached content
|
||||||
|
|
||||||
|
|
||||||
var $default_template_handler_func = ''; // function to handle missing templates
|
var $default_template_handler_func = ''; // function to handle missing templates
|
||||||
@@ -546,15 +547,26 @@ class Smarty
|
|||||||
$_smarty_results = $this->_process_cached_inserts($_smarty_results);
|
$_smarty_results = $this->_process_cached_inserts($_smarty_results);
|
||||||
}
|
}
|
||||||
if ($_smarty_display) {
|
if ($_smarty_display) {
|
||||||
echo $_smarty_results;
|
|
||||||
if ($this->debugging)
|
if ($this->debugging)
|
||||||
{
|
{
|
||||||
// capture time for debugging info
|
// capture time for debugging info
|
||||||
$this->_smarty_debug_info[$included_tpls_idx]['exec_time'] = $this->_get_microtime() - $debug_start_time;
|
$this->_smarty_debug_info[$included_tpls_idx]['exec_time'] = $this->_get_microtime() - $debug_start_time;
|
||||||
|
|
||||||
echo $this->_generate_debug_output();
|
$_smarty_results .= $this->_generate_debug_output();
|
||||||
}
|
}
|
||||||
return;
|
if( $this->check_if_modified ) {
|
||||||
|
global $HTTP_IF_MODIFIED_SINCE;
|
||||||
|
$last_modified_date = substr($HTTP_IF_MODIFIED_SINCE,0,strpos($HTTP_IF_MODIFIED_SINCE,'GMT')+3);
|
||||||
|
$gmt_mtime = gmdate('D, d M Y H:i:s', $this->_cache_info['timestamp']).' GMT';
|
||||||
|
if( !$this->_cache_info['insert_tags']
|
||||||
|
&& $gmt_mtime == $last_modified_date ) {
|
||||||
|
header("HTTP/1.1 304 Not Modified");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
header("Content-Length: ".strlen($_smarty_results));
|
||||||
|
header("Last-Modified: ".$gmt_mtime);
|
||||||
|
echo $_smarty_results;
|
||||||
|
return true;
|
||||||
} else {
|
} else {
|
||||||
return $_smarty_results;
|
return $_smarty_results;
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user