mirror of
https://github.com/smarty-php/smarty.git
synced 2025-08-04 10:24:26 +02:00
commit cache handler functionality
This commit is contained in:
@@ -78,7 +78,7 @@ class Config_File extends PEAR {
|
||||
{
|
||||
$this->PEAR();
|
||||
|
||||
if (substr(PHP_OS, 1, 3) == "WIN")
|
||||
if (substr(PHP_OS, 1, 3) == "WIN" || substr(PHP_OS, 1, 4) == "OS/2")
|
||||
$this->_separator = "\\";
|
||||
else
|
||||
$this->_separator = "/";
|
||||
|
7
NEWS
7
NEWS
@@ -2,6 +2,13 @@
|
||||
blocks. (Andrei, Alexander Belonosov)
|
||||
- added 'field_array' attribute to html_select_time function. (Andrei,
|
||||
Michael Caplan)
|
||||
- added {section} "max" attribute to docs (Monte)
|
||||
- fixed notice message in Smarty_Compiler.class.php (Monte)
|
||||
- fixed bug with clear_cache introduced in 1.4.6, third parameter should be
|
||||
null (Monte)
|
||||
- updated Config_File.class.php for "\" support in OS/2 (Monte, Francesco
|
||||
Ciprianii)
|
||||
- removed secure_ext setting (not used) (Monte)
|
||||
- made cache reading process more efficient. (Monte)
|
||||
- fixed bug, is_cached() now supports new 1.4.6 caching behavior. (Monte)
|
||||
- update FAQ with mailing list Reply-To header FAQ. (Monte)
|
||||
|
113
Smarty.class.php
113
Smarty.class.php
@@ -101,8 +101,10 @@ class Smarty
|
||||
// this will tell Smarty not to look for
|
||||
// insert tags and speed up cached page
|
||||
// fetches.
|
||||
var $cache_handler_func = ''; // function used for cached content. this is
|
||||
// an alternative to using the file based $cache_dir.
|
||||
|
||||
var $tpl_file_ext = '.tpl'; // template file extention
|
||||
var $tpl_file_ext = '.tpl'; // template file extention (deprecated)
|
||||
|
||||
var $php_handling = SMARTY_PHP_PASSTHRU;
|
||||
// how smarty handles php tags in the templates
|
||||
@@ -116,7 +118,6 @@ class Smarty
|
||||
|
||||
var $security = false; // enable template security (default false)
|
||||
var $secure_dir = array('./templates'); // array of directories considered secure
|
||||
var $secure_ext = array('.tpl'); // array of file extentions considered secure
|
||||
var $security_settings = array(
|
||||
'PHP_HANDLING' => false,
|
||||
'IF_FUNCS' => array('array', 'list',
|
||||
@@ -413,10 +414,14 @@ class Smarty
|
||||
Function: clear_cache()
|
||||
Purpose: clear cached content for the given template and cache id
|
||||
\*======================================================================*/
|
||||
function clear_cache($tpl_file = null, $cache_id = null, $compile_id)
|
||||
function clear_cache($tpl_file = null, $cache_id = null, $compile_id = null)
|
||||
{
|
||||
if(!empty($this->cache_handler_func) {
|
||||
return $$this->cache_handler_func('clear', $tpl_file, $cache_id, $compile_id);
|
||||
} else {
|
||||
return $this->_rm_auto($this->cache_dir, $tpl_file, $compile_id . $cache_id);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/*======================================================================*\
|
||||
@@ -425,8 +430,12 @@ class Smarty
|
||||
\*======================================================================*/
|
||||
function clear_all_cache()
|
||||
{
|
||||
if(!empty($this->cache_handler_func) {
|
||||
return $$this->cache_handler_func('clear');
|
||||
} else {
|
||||
return $this->_rm_auto($this->cache_dir);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/*======================================================================*\
|
||||
@@ -438,20 +447,7 @@ class Smarty
|
||||
if (!$this->caching)
|
||||
return false;
|
||||
|
||||
$cache_file = $this->_get_auto_filename($this->cache_dir, $tpl_file, $compile_id . $cache_id);
|
||||
|
||||
if (file_exists($cache_file) &&
|
||||
($this->cache_lifetime == 0 ||
|
||||
(time() - filemtime($cache_file) <= $this->cache_lifetime))) {
|
||||
if($this->compile_check) {
|
||||
return $this->_read_cache_file($cache_file,$results);
|
||||
} else {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
else
|
||||
return false;
|
||||
|
||||
return $this->_read_cache_file($tpl_file,$cache_id,$compile_id,$results);
|
||||
}
|
||||
|
||||
|
||||
@@ -524,13 +520,7 @@ class Smarty
|
||||
|
||||
$this->_cache_info[] = array('template', $tpl_file);
|
||||
|
||||
$cache_file = $this->_get_auto_filename($this->cache_dir, $tpl_file, $compile_id . $cache_id);
|
||||
|
||||
if (file_exists($cache_file) &&
|
||||
($this->cache_lifetime == 0 ||
|
||||
(time() - filemtime($cache_file) <= $this->cache_lifetime))) {
|
||||
|
||||
if($this->_read_cache_file($cache_file,$results)) {
|
||||
if($this->_read_cache_file($tpl_file,$cache_id,$compile_id,$results)) {
|
||||
if ($this->insert_tag_check) {
|
||||
$results = $this->_process_cached_inserts($results);
|
||||
}
|
||||
@@ -549,7 +539,6 @@ class Smarty
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$this->_assign_smarty_interface();
|
||||
|
||||
@@ -607,7 +596,7 @@ class Smarty
|
||||
}
|
||||
|
||||
if ($this->caching) {
|
||||
$this->_write_cache_file($cache_file, $results);
|
||||
$this->_write_cache_file($tpl_file,$cache_id,$compile_id,$results);
|
||||
$results = $this->_process_cached_inserts($results);
|
||||
}
|
||||
|
||||
@@ -869,7 +858,6 @@ function _generate_debug_output() {
|
||||
$smarty_compiler->compiler_funcs = $this->compiler_funcs;
|
||||
$smarty_compiler->security = $this->security;
|
||||
$smarty_compiler->secure_dir = $this->secure_dir;
|
||||
$smarty_compiler->secure_ext = $this->secure_ext;
|
||||
$smarty_compiler->security_settings = $this->security_settings;
|
||||
|
||||
if ($smarty_compiler->_compile_file($tpl_file, $template_source, $template_compiled))
|
||||
@@ -1233,62 +1221,91 @@ function _run_insert_handler($args)
|
||||
/*======================================================================*\
|
||||
Function: _write_cache_file
|
||||
Purpose: Prepend the cache information to the cache file
|
||||
and write it to disk
|
||||
and write it
|
||||
\*======================================================================*/
|
||||
function _write_cache_file($cache_file,$results)
|
||||
function _write_cache_file($tpl_file, $cache_id, $compile_id, $results)
|
||||
{
|
||||
// put the templates involved with this cache in the first line
|
||||
$cache_info = 'SMARTY_CACHE_INFO_HEADER'.serialize($this->_cache_info)."\n";
|
||||
$this->_write_file($cache_file, $cache_info.$results, true);
|
||||
// put timestamp in cache header
|
||||
$this->_cache_info['timestamp'] = time();
|
||||
|
||||
// prepend the cache header info into cache file
|
||||
$results = 'SMARTY_CACHE_INFO_HEADER'.serialize($this->_cache_info)."\n".$results;
|
||||
|
||||
if(!empty($this->cache_handler_func)) {
|
||||
// use cache_write_handler function
|
||||
return $$this->cache_handler_func('write', $tpl_file, $cache_id, $compile_id, $results, $this);
|
||||
} else {
|
||||
// use local cache file
|
||||
$cache_file = $this->_get_auto_filename($this->cache_dir, $tpl_file, $compile_id . $cache_id);
|
||||
$this->_write_file($cache_file, $results, true);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
/*======================================================================*\
|
||||
Function: _read_cache_file
|
||||
Purpose: See if any of the templates for this cache file
|
||||
have changed or not since the cache was created.
|
||||
Remove the cache info from the cache results.
|
||||
Purpose: read a cache file, determine if it needs to be
|
||||
regenerated or not
|
||||
\*======================================================================*/
|
||||
function _read_cache_file($cache_file,&$results)
|
||||
function _read_cache_file($tpl_file, $cache_id, $compile_id, &$results)
|
||||
{
|
||||
if( !($cache_header = $this->_read_file($cache_file,1,1) )) {
|
||||
if ($this->force_compile || $this->cache_lifetime == 0) {
|
||||
// force compile enabled or cache lifetime is zero, always regenerate
|
||||
return false;
|
||||
}
|
||||
|
||||
if(!empty($this->cache_handler_func)) {
|
||||
|
||||
// use cache_read_handler function
|
||||
return($$this->cache_handler_func('read',$tpl_file, $cache_id, $compile_id, $results, $this));
|
||||
|
||||
} else {
|
||||
// use local file cache
|
||||
|
||||
$cache_file = $this->_get_auto_filename($this->cache_dir, $tpl_file, $compile_id . $cache_id);
|
||||
return ($results = $this->_read_file($cache_file));
|
||||
|
||||
}
|
||||
|
||||
$cache_split = explode("\n",$results,2);
|
||||
$cache_header = $cache_split[0];
|
||||
|
||||
if (substr($cache_header, 0, 24) == 'SMARTY_CACHE_INFO_HEADER') {
|
||||
|
||||
$cache_info = unserialize(substr($cache_header, 24));
|
||||
$cache_timestamp = $cache_info['timestamp'];
|
||||
|
||||
if (time() - $cache_timestamp > $this->cache_lifetime) {
|
||||
// cache expired, regenerate
|
||||
return false;
|
||||
}
|
||||
|
||||
if ($this->compile_check) {
|
||||
$cache_filemtime = filemtime($cache_file);
|
||||
|
||||
foreach ($cache_info as $curr_cache_info) {
|
||||
switch ($curr_cache_info[0]) {
|
||||
case 'template':
|
||||
$this->_fetch_template_info($curr_cache_info[1], $template_source, $template_timestamp, false);
|
||||
if($cache_filemtime < $template_timestamp) {
|
||||
if($cache_timestamp < $template_timestamp) {
|
||||
// template file has changed, regenerate cache
|
||||
return false;
|
||||
}
|
||||
break;
|
||||
|
||||
case 'config':
|
||||
if ($cache_filemtime < filemtime($this->config_dir.'/'.$curr_cache_info[1])) {
|
||||
if ($cache_timestamp < filemtime($this->config_dir.'/'.$curr_cache_info[1])) {
|
||||
// config file file has changed, regenerate cache
|
||||
return false;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
$results = $this->_read_file($cache_file,2);
|
||||
} else {
|
||||
// no cache info header, pre Smarty 1.4.6 format
|
||||
$results = $this->_read_file($cache_file);
|
||||
}
|
||||
|
||||
$results = $cache_split[1];
|
||||
return true;
|
||||
} else {
|
||||
// no cache info header, pre Smarty 1.4.6 format. regenerate
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
@@ -374,7 +374,7 @@ class Smarty_Compiler extends Smarty {
|
||||
$attrs['section'] = 'null';
|
||||
}
|
||||
|
||||
@$scope = $this->_dequote($attrs['scope']);
|
||||
$scope = @$this->_dequote($attrs['scope']);
|
||||
if (!empty($scope)) {
|
||||
if ($scope != 'local' &&
|
||||
$scope != 'parent' &&
|
||||
|
98
docs.sgml
98
docs.sgml
@@ -40,9 +40,9 @@
|
||||
between programming/HTML a couple of times. Thus, it's important to
|
||||
have good template support because programmers don't want anything to
|
||||
do with HTML and don't want HTML designers mucking around with PHP
|
||||
code. Designers need support for config files, dynamic blocks and other
|
||||
stuff, but they don't want to have to deal with intricacies of the PHP
|
||||
programming language.
|
||||
code. Designers need support for config files, dynamic blocks and
|
||||
other interface issues, but they don't want to have to deal with
|
||||
intricacies of the PHP programming language.
|
||||
</para>
|
||||
<para>
|
||||
Looking at many templating solutions available for PHP today, most of
|
||||
@@ -89,10 +89,12 @@
|
||||
<title>What is Smarty?</title>
|
||||
<para>
|
||||
Smarty is a template engine for PHP. One of the unique aspects about
|
||||
Smarty that sets it apart from other templating solutions is that it
|
||||
compiles the templates into native PHP scripts upon the first
|
||||
invocation. After that, it merely executes the compiled PHP scripts.
|
||||
Therefore, there is no costly template file parsing for each request.
|
||||
Smarty is that it compiles the template files into native PHP scripts
|
||||
upon the first invocation. After that, it just executes the compiled
|
||||
PHP scripts. Therefore, there is no costly template file parsing for
|
||||
each request, and each template can take full advantage of PHP compiler
|
||||
cache solutions such as Zend Cache (http://www.zend.com) or APC
|
||||
(http://apc.communityconnect.com).
|
||||
</para>
|
||||
<para>
|
||||
Some of Smarty's features:
|
||||
@@ -108,9 +110,9 @@
|
||||
functions</link> and custom <link linkend="variable.modifiers">variable
|
||||
modifiers</link>, so the template language is extremely extensible.</para></listitem>
|
||||
<listitem><para>Configurable template delimiter tag syntax, so you can use
|
||||
{}, {{}}, <!--{}-->, or whatever you like.</para></listitem>
|
||||
{}, {{}}, <!--{}-->, etc.</para></listitem>
|
||||
<listitem><para>The if/elseif/else/endif constructs are passed to the
|
||||
PHP parser, so the if expression syntax can be as simple or as complex
|
||||
PHP parser, so the {if ...} expression syntax can be as simple or as complex
|
||||
as you like.</para></listitem>
|
||||
<listitem><para>Unlimited nesting of sections, ifs, etc. allowed.</para></listitem>
|
||||
<listitem><para>It is possible to embed PHP code right in your template files,
|
||||
@@ -118,6 +120,7 @@
|
||||
since the engine is so customizable.</para></listitem>
|
||||
<listitem><para>Built-in caching support (new in 1.3.0)</para></listitem>
|
||||
<listitem><para>Arbitrary template sources (new in 1.4.0)</para></listitem>
|
||||
<listitem><para>Custom cache handling functions (new in 1.4.7)</para></listitem>
|
||||
</itemizedlist>
|
||||
</sect1>
|
||||
<sect1>
|
||||
@@ -148,12 +151,13 @@
|
||||
<para>
|
||||
TECHNICAL NOTE: Any time you change a template, change values in
|
||||
config files or change the content that gets displayed in a
|
||||
template, you must turn on compile_check (new behavior in 1.4.6),
|
||||
clear the caches that are affected, or wait for the cache to expire
|
||||
to see the results of the changes. You can either do this manually
|
||||
by deleting files from the cache directory, or programatically with
|
||||
<link linkend="api.clear.cache">clear_cache</link> or <link
|
||||
linkend="api.clear.all.cache">clear_all_cache</link>.
|
||||
template, you can turn on compile_check to regenerate the caches
|
||||
that are affected, or wait for the cache to expire to see the
|
||||
results of the changes. You clear caches manually by deleting files
|
||||
from the cache directory, programatically with <link
|
||||
linkend="api.clear.cache">clear_cache</link> or <link
|
||||
linkend="api.clear.all.cache">clear_all_cache</link>, or turn on
|
||||
$compile_check (or $force_compile).
|
||||
</para>
|
||||
<para>
|
||||
TECHNICAL NOTE: As of Smarty 1.4.6, if you have caching enabled AND
|
||||
@@ -163,7 +167,8 @@
|
||||
since it has to check the templates and config files for
|
||||
modification times. Therefore if you are not actively changing
|
||||
templates or config files, it is advisable to leave compile_check
|
||||
off.
|
||||
off. As of Smarty 1.4.7, enabling $force_compile will cause cache
|
||||
files to always be regenerated.
|
||||
</para>
|
||||
</sect2>
|
||||
</sect1>
|
||||
@@ -180,13 +185,13 @@
|
||||
<sect1>
|
||||
<title>Installing Smarty</title>
|
||||
<para>
|
||||
Installing Smarty is fairly straightforward, there is just one thing
|
||||
you must be aware of. Smarty creates PHP scripts from the templates.
|
||||
This usually means allowing user "nobody" (or whomever the web server
|
||||
runs as) to have permission to write the files. Each installation of a
|
||||
Installing Smarty is fairly straightforward, there are a few things to
|
||||
be aware of. Smarty creates PHP scripts from the templates. This
|
||||
usually means allowing user "nobody" (or whomever the web server runs
|
||||
as) to have permission to write the files. Each installation of a
|
||||
Smarty application minimally needs a templates directory and a compiled
|
||||
templates directory. If you use configuration files you will also need
|
||||
a directory for those. By default these are named "templates", and
|
||||
a directory for those. By default these are named "templates",
|
||||
"templates_c" and "configs" respectively. If you plan on using caching,
|
||||
you will need to create a "cache" directory, also with permission to
|
||||
write files.
|
||||
@@ -220,6 +225,11 @@
|
||||
directory yourself before hand, and change the file ownership
|
||||
accordingly. See below.
|
||||
</para>
|
||||
<para>
|
||||
TECHNICAL NOTE: If you don't want to use include_path to find the
|
||||
Smarty files, you can set the SMARTY_DIR constant to the full path to
|
||||
your Smarty library files. Be sure the path ends with a slash!
|
||||
</para>
|
||||
<example>
|
||||
<title>Example of installing Smarty</title>
|
||||
<programlisting>
|
||||
@@ -392,7 +402,9 @@ require_once(SMARTY_DIR."Smarty.class.php");
|
||||
$compile_check to "false" to improve performance! Note that if
|
||||
you change this to "false" and a template file is changed, you
|
||||
will *not* see the change since the template will not get
|
||||
recompiled. See <link
|
||||
recompiled. If caching is enabled and compile_check is enabled,
|
||||
then the cache files will get regenerated if an involved
|
||||
template file was updated. See <link
|
||||
linkend="setting.force.compile">$force_compile</link> or <link
|
||||
linkend="api.clear.compiled.tpl">clear_compiled_tpl</link>.
|
||||
</para>
|
||||
@@ -403,7 +415,8 @@ require_once(SMARTY_DIR."Smarty.class.php");
|
||||
This forces Smarty to (re)compile templates on every
|
||||
invocation. This setting overrides $compile_check. By default
|
||||
this is disabled. This is handy for development and debugging.
|
||||
It should never be used in a production environment.
|
||||
It should never be used in a production environment. If caching
|
||||
is enabled, the cache file(s) will be regenerated every time.
|
||||
</para>
|
||||
</sect2>
|
||||
<sect2 id="setting.caching">
|
||||
@@ -411,11 +424,18 @@ require_once(SMARTY_DIR."Smarty.class.php");
|
||||
<para>
|
||||
This tells Smarty whether or not to cache the output of the
|
||||
templates. By default this is set to false. If your templates
|
||||
generate the same content over and over, it is advisable to
|
||||
turn on caching. This will result significant performance
|
||||
gains. You can also have multiple caches for the same template.
|
||||
See <link linkend="api.is.cached">is_cached</link> for details.
|
||||
This was added to Smarty 1.3.0.
|
||||
generate redundant redundant content over and over again and
|
||||
again repeatedly, it is advisable to turn on caching. This will
|
||||
result in significant performance gains. You can also have
|
||||
multiple caches for the same template. See <link
|
||||
linkend="api.is.cached">is_cached</link> for details. This was
|
||||
added to Smarty 1.3.0.
|
||||
</para>
|
||||
<para>
|
||||
If $compile_check is enabled, the cached content will be
|
||||
regenerated if any of the involved templates are changed. (new
|
||||
to 1.4.6). If $force_compile is enabled, the cached content
|
||||
will always be regenerated (new to 1.4.7).
|
||||
</para>
|
||||
</sect2>
|
||||
<sect2 id="setting.cache.dir">
|
||||
@@ -425,6 +445,8 @@ require_once(SMARTY_DIR."Smarty.class.php");
|
||||
stored. By default this is "./cache", meaning that it will
|
||||
look for the cache directory in the same directory as the
|
||||
executing php script. This was added to Smarty version 1.3.0.
|
||||
You can also use your own custom cache handler function to
|
||||
control cache files, which will ignore this setting.
|
||||
</para>
|
||||
<para>
|
||||
TECHNICAL NOTE: This setting must be either a relative or
|
||||
@@ -455,6 +477,14 @@ require_once(SMARTY_DIR."Smarty.class.php");
|
||||
search, speeding up cached page fetches.
|
||||
</para>
|
||||
</sect2>
|
||||
<sect2 id="setting.cache.handler.func">
|
||||
<title>$cache_handler_func</title>
|
||||
<para>
|
||||
You can supply a custom function to handle cache files instead
|
||||
of using the built-in method using the $cache_dir. See the
|
||||
custom cache handler function section for details.
|
||||
</para>
|
||||
</sect2>
|
||||
<sect2 id="setting.tpl.file.ext">
|
||||
<title>$tpl_file_ext</title>
|
||||
<para>
|
||||
@@ -472,7 +502,7 @@ require_once(SMARTY_DIR."Smarty.class.php");
|
||||
<para>
|
||||
Whether or not to allow PHP code in the templates. If set to
|
||||
false, PHP code is escaped and not interpreted. Embedding PHP
|
||||
code into templates is highly discouraged. Use <link
|
||||
code into templates is not recommended. Use <link
|
||||
linkend="custom.functions">custom functions</link> or <link
|
||||
linkend="variable.modifiers">modifiers</link> instead. Default
|
||||
is "false".
|
||||
@@ -1508,7 +1538,7 @@ function add_header_comment($tpl_source) {
|
||||
}
|
||||
|
||||
// register the postfilter
|
||||
$smarty->register_postfilter("add_header_comments");
|
||||
$smarty->register_postfilter("add_header_comment");
|
||||
$smarty->display("index.tpl");
|
||||
|
||||
{* from within Smarty template *}
|
||||
@@ -2441,6 +2471,14 @@ OUTPUT:
|
||||
0,2,4, etc. If step is negative, it will step through
|
||||
the array backwards. (Added to Smarty 1.4.4.)</entry>
|
||||
</row>
|
||||
<row>
|
||||
<entry>max</entry>
|
||||
<entry>integer</entry>
|
||||
<entry>No</entry>
|
||||
<entry><emphasis>1</emphasis></entry>
|
||||
<entry>Sets the maximum number of times the section
|
||||
will loop. (Added to Smarty 1.4.4.)</entry>
|
||||
</row>
|
||||
<row>
|
||||
<entry>show</entry>
|
||||
<entry>boolean</entry>
|
||||
|
@@ -78,7 +78,7 @@ class Config_File extends PEAR {
|
||||
{
|
||||
$this->PEAR();
|
||||
|
||||
if (substr(PHP_OS, 1, 3) == "WIN")
|
||||
if (substr(PHP_OS, 1, 3) == "WIN" || substr(PHP_OS, 1, 4) == "OS/2")
|
||||
$this->_separator = "\\";
|
||||
else
|
||||
$this->_separator = "/";
|
||||
|
@@ -101,8 +101,10 @@ class Smarty
|
||||
// this will tell Smarty not to look for
|
||||
// insert tags and speed up cached page
|
||||
// fetches.
|
||||
var $cache_handler_func = ''; // function used for cached content. this is
|
||||
// an alternative to using the file based $cache_dir.
|
||||
|
||||
var $tpl_file_ext = '.tpl'; // template file extention
|
||||
var $tpl_file_ext = '.tpl'; // template file extention (deprecated)
|
||||
|
||||
var $php_handling = SMARTY_PHP_PASSTHRU;
|
||||
// how smarty handles php tags in the templates
|
||||
@@ -116,7 +118,6 @@ class Smarty
|
||||
|
||||
var $security = false; // enable template security (default false)
|
||||
var $secure_dir = array('./templates'); // array of directories considered secure
|
||||
var $secure_ext = array('.tpl'); // array of file extentions considered secure
|
||||
var $security_settings = array(
|
||||
'PHP_HANDLING' => false,
|
||||
'IF_FUNCS' => array('array', 'list',
|
||||
@@ -413,10 +414,14 @@ class Smarty
|
||||
Function: clear_cache()
|
||||
Purpose: clear cached content for the given template and cache id
|
||||
\*======================================================================*/
|
||||
function clear_cache($tpl_file = null, $cache_id = null, $compile_id)
|
||||
function clear_cache($tpl_file = null, $cache_id = null, $compile_id = null)
|
||||
{
|
||||
if(!empty($this->cache_handler_func) {
|
||||
return $$this->cache_handler_func('clear', $tpl_file, $cache_id, $compile_id);
|
||||
} else {
|
||||
return $this->_rm_auto($this->cache_dir, $tpl_file, $compile_id . $cache_id);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/*======================================================================*\
|
||||
@@ -425,8 +430,12 @@ class Smarty
|
||||
\*======================================================================*/
|
||||
function clear_all_cache()
|
||||
{
|
||||
if(!empty($this->cache_handler_func) {
|
||||
return $$this->cache_handler_func('clear');
|
||||
} else {
|
||||
return $this->_rm_auto($this->cache_dir);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/*======================================================================*\
|
||||
@@ -438,20 +447,7 @@ class Smarty
|
||||
if (!$this->caching)
|
||||
return false;
|
||||
|
||||
$cache_file = $this->_get_auto_filename($this->cache_dir, $tpl_file, $compile_id . $cache_id);
|
||||
|
||||
if (file_exists($cache_file) &&
|
||||
($this->cache_lifetime == 0 ||
|
||||
(time() - filemtime($cache_file) <= $this->cache_lifetime))) {
|
||||
if($this->compile_check) {
|
||||
return $this->_read_cache_file($cache_file,$results);
|
||||
} else {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
else
|
||||
return false;
|
||||
|
||||
return $this->_read_cache_file($tpl_file,$cache_id,$compile_id,$results);
|
||||
}
|
||||
|
||||
|
||||
@@ -524,13 +520,7 @@ class Smarty
|
||||
|
||||
$this->_cache_info[] = array('template', $tpl_file);
|
||||
|
||||
$cache_file = $this->_get_auto_filename($this->cache_dir, $tpl_file, $compile_id . $cache_id);
|
||||
|
||||
if (file_exists($cache_file) &&
|
||||
($this->cache_lifetime == 0 ||
|
||||
(time() - filemtime($cache_file) <= $this->cache_lifetime))) {
|
||||
|
||||
if($this->_read_cache_file($cache_file,$results)) {
|
||||
if($this->_read_cache_file($tpl_file,$cache_id,$compile_id,$results)) {
|
||||
if ($this->insert_tag_check) {
|
||||
$results = $this->_process_cached_inserts($results);
|
||||
}
|
||||
@@ -549,7 +539,6 @@ class Smarty
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$this->_assign_smarty_interface();
|
||||
|
||||
@@ -607,7 +596,7 @@ class Smarty
|
||||
}
|
||||
|
||||
if ($this->caching) {
|
||||
$this->_write_cache_file($cache_file, $results);
|
||||
$this->_write_cache_file($tpl_file,$cache_id,$compile_id,$results);
|
||||
$results = $this->_process_cached_inserts($results);
|
||||
}
|
||||
|
||||
@@ -869,7 +858,6 @@ function _generate_debug_output() {
|
||||
$smarty_compiler->compiler_funcs = $this->compiler_funcs;
|
||||
$smarty_compiler->security = $this->security;
|
||||
$smarty_compiler->secure_dir = $this->secure_dir;
|
||||
$smarty_compiler->secure_ext = $this->secure_ext;
|
||||
$smarty_compiler->security_settings = $this->security_settings;
|
||||
|
||||
if ($smarty_compiler->_compile_file($tpl_file, $template_source, $template_compiled))
|
||||
@@ -1233,62 +1221,91 @@ function _run_insert_handler($args)
|
||||
/*======================================================================*\
|
||||
Function: _write_cache_file
|
||||
Purpose: Prepend the cache information to the cache file
|
||||
and write it to disk
|
||||
and write it
|
||||
\*======================================================================*/
|
||||
function _write_cache_file($cache_file,$results)
|
||||
function _write_cache_file($tpl_file, $cache_id, $compile_id, $results)
|
||||
{
|
||||
// put the templates involved with this cache in the first line
|
||||
$cache_info = 'SMARTY_CACHE_INFO_HEADER'.serialize($this->_cache_info)."\n";
|
||||
$this->_write_file($cache_file, $cache_info.$results, true);
|
||||
// put timestamp in cache header
|
||||
$this->_cache_info['timestamp'] = time();
|
||||
|
||||
// prepend the cache header info into cache file
|
||||
$results = 'SMARTY_CACHE_INFO_HEADER'.serialize($this->_cache_info)."\n".$results;
|
||||
|
||||
if(!empty($this->cache_handler_func)) {
|
||||
// use cache_write_handler function
|
||||
return $$this->cache_handler_func('write', $tpl_file, $cache_id, $compile_id, $results, $this);
|
||||
} else {
|
||||
// use local cache file
|
||||
$cache_file = $this->_get_auto_filename($this->cache_dir, $tpl_file, $compile_id . $cache_id);
|
||||
$this->_write_file($cache_file, $results, true);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
/*======================================================================*\
|
||||
Function: _read_cache_file
|
||||
Purpose: See if any of the templates for this cache file
|
||||
have changed or not since the cache was created.
|
||||
Remove the cache info from the cache results.
|
||||
Purpose: read a cache file, determine if it needs to be
|
||||
regenerated or not
|
||||
\*======================================================================*/
|
||||
function _read_cache_file($cache_file,&$results)
|
||||
function _read_cache_file($tpl_file, $cache_id, $compile_id, &$results)
|
||||
{
|
||||
if( !($cache_header = $this->_read_file($cache_file,1,1) )) {
|
||||
if ($this->force_compile || $this->cache_lifetime == 0) {
|
||||
// force compile enabled or cache lifetime is zero, always regenerate
|
||||
return false;
|
||||
}
|
||||
|
||||
if(!empty($this->cache_handler_func)) {
|
||||
|
||||
// use cache_read_handler function
|
||||
return($$this->cache_handler_func('read',$tpl_file, $cache_id, $compile_id, $results, $this));
|
||||
|
||||
} else {
|
||||
// use local file cache
|
||||
|
||||
$cache_file = $this->_get_auto_filename($this->cache_dir, $tpl_file, $compile_id . $cache_id);
|
||||
return ($results = $this->_read_file($cache_file));
|
||||
|
||||
}
|
||||
|
||||
$cache_split = explode("\n",$results,2);
|
||||
$cache_header = $cache_split[0];
|
||||
|
||||
if (substr($cache_header, 0, 24) == 'SMARTY_CACHE_INFO_HEADER') {
|
||||
|
||||
$cache_info = unserialize(substr($cache_header, 24));
|
||||
$cache_timestamp = $cache_info['timestamp'];
|
||||
|
||||
if (time() - $cache_timestamp > $this->cache_lifetime) {
|
||||
// cache expired, regenerate
|
||||
return false;
|
||||
}
|
||||
|
||||
if ($this->compile_check) {
|
||||
$cache_filemtime = filemtime($cache_file);
|
||||
|
||||
foreach ($cache_info as $curr_cache_info) {
|
||||
switch ($curr_cache_info[0]) {
|
||||
case 'template':
|
||||
$this->_fetch_template_info($curr_cache_info[1], $template_source, $template_timestamp, false);
|
||||
if($cache_filemtime < $template_timestamp) {
|
||||
if($cache_timestamp < $template_timestamp) {
|
||||
// template file has changed, regenerate cache
|
||||
return false;
|
||||
}
|
||||
break;
|
||||
|
||||
case 'config':
|
||||
if ($cache_filemtime < filemtime($this->config_dir.'/'.$curr_cache_info[1])) {
|
||||
if ($cache_timestamp < filemtime($this->config_dir.'/'.$curr_cache_info[1])) {
|
||||
// config file file has changed, regenerate cache
|
||||
return false;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
$results = $this->_read_file($cache_file,2);
|
||||
} else {
|
||||
// no cache info header, pre Smarty 1.4.6 format
|
||||
$results = $this->_read_file($cache_file);
|
||||
}
|
||||
|
||||
$results = $cache_split[1];
|
||||
return true;
|
||||
} else {
|
||||
// no cache info header, pre Smarty 1.4.6 format. regenerate
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
@@ -374,7 +374,7 @@ class Smarty_Compiler extends Smarty {
|
||||
$attrs['section'] = 'null';
|
||||
}
|
||||
|
||||
@$scope = $this->_dequote($attrs['scope']);
|
||||
$scope = @$this->_dequote($attrs['scope']);
|
||||
if (!empty($scope)) {
|
||||
if ($scope != 'local' &&
|
||||
$scope != 'parent' &&
|
||||
|
Reference in New Issue
Block a user