30 $_source_file_path = str_replace(
':',
'.', $_template->source->filepath);
31 $_cache_id = isset($_template->cache_id) ? preg_replace(
'![^\w\|]+!',
'_', $_template->cache_id) : null;
32 $_compile_id = isset($_template->compile_id) ? preg_replace(
'![^\w\|]+!',
'_', $_template->compile_id) : null;
33 $_filepath = $_template->source->uid;
35 if ($_template->smarty->use_sub_dirs) {
36 $_filepath = substr($_filepath, 0, 2) . DS
37 . substr($_filepath, 2, 2) . DS
38 . substr($_filepath, 4, 2) . DS
41 $_compile_dir_sep = $_template->smarty->use_sub_dirs ? DS :
'^';
42 if (isset($_cache_id)) {
43 $_cache_id = str_replace(
'|', $_compile_dir_sep, $_cache_id) . $_compile_dir_sep;
47 if (isset($_compile_id)) {
48 $_compile_id = $_compile_id . $_compile_dir_sep;
52 $_cache_dir = $_template->smarty->getCacheDir();
53 if ($_template->smarty->cache_locking) {
56 if (!preg_match(
'/^([\/\\\\]|[a-zA-Z]:[\/\\\\])/', $_cache_dir)) {
57 $_lock_dir = rtrim(getcwd(),
'/\\') . DS . $_cache_dir;
59 $_lock_dir = $_cache_dir;
61 $cached->lock_id = $_lock_dir . sha1($_cache_id . $_compile_id . $_template->source->uid) .
'.lock';
63 $cached->filepath = $_cache_dir . $_cache_id . $_compile_id . $_filepath .
'.' . basename($_source_file_path) .
'.php';
64 $cached->timestamp = $cached->exists = is_file($cached->filepath);
65 if ($cached->exists) {
66 $cached->timestamp = filemtime($cached->filepath);
79 $cached->timestamp = $cached->exists = is_file($cached->filepath);
80 if ($cached->exists) {
81 $cached->timestamp = filemtime($cached->filepath);
98 $_smarty_tpl = $_template;
100 return @include $_template->cached->filepath;
114 if ($obj->writeFile($_template->cached->filepath, $content, $_template->smarty) ===
true) {
115 $cached = $_template->cached;
116 $cached->timestamp = $cached->exists = is_file($cached->filepath);
117 if ($cached->exists) {
118 $cached->timestamp = filemtime($cached->filepath);
134 if (is_file($_template->cached->filepath)) {
135 return file_get_contents($_template->cached->filepath);
150 return $this->
clear($smarty, null, null, null, $exp_time);
164 public function clear(
Smarty $smarty, $resource_name, $cache_id, $compile_id, $exp_time)
166 $_cache_id = isset($cache_id) ? preg_replace(
'![^\w\|]+!',
'_', $cache_id) : null;
167 $_compile_id = isset($compile_id) ? preg_replace(
'![^\w\|]+!',
'_', $compile_id) : null;
168 $_dir_sep = $smarty->use_sub_dirs ?
'/' :
'^';
169 $_compile_id_offset = $smarty->use_sub_dirs ? 3 : 0;
174 $_dir_length = strlen($_dir);
175 if (isset($_cache_id)) {
176 $_cache_id_parts = explode(
'|', $_cache_id);
177 $_cache_id_parts_count = count($_cache_id_parts);
178 if ($smarty->use_sub_dirs) {
179 foreach ($_cache_id_parts as $id_part) {
180 $_dir .= $id_part . DS;
184 if (isset($resource_name)) {
185 $_save_stat = $smarty->caching;
186 $smarty->caching =
true;
187 $tpl =
new $smarty->template_class($resource_name, $smarty);
188 $smarty->caching = $_save_stat;
192 if ($smarty->allow_ambiguous_resources) {
193 $_templateId = $tpl->source->unique_resource . $tpl->cache_id . $tpl->compile_id;
195 $_templateId = $smarty->joined_template_dir .
'#' . $resource_name . $tpl->cache_id . $tpl->compile_id;
197 if (isset($_templateId[150])) {
198 $_templateId = sha1($_templateId);
200 unset($smarty->template_objects[$_templateId]);
202 if ($tpl->source->exists) {
203 $_resourcename_parts = basename(str_replace(
'^',
'/', $tpl->cached->filepath));
210 if (file_exists($_dir)) {
211 $_cacheDirs =
new RecursiveDirectoryIterator($_dir);
212 $_cache =
new RecursiveIteratorIterator($_cacheDirs, RecursiveIteratorIterator::CHILD_FIRST);
213 foreach ($_cache as $_file) {
214 if (substr(basename($_file->getPathname()), 0, 1) ==
'.' || strpos($_file,
'.svn') !==
false) {
218 if ($_file->isDir()) {
219 if (!$_cache->isDot()) {
221 @rmdir($_file->getPathname());
224 $_parts = explode($_dir_sep, str_replace(
'\\',
'/', substr((
string) $_file, $_dir_length)));
225 $_parts_count = count($_parts);
227 if (isset($resource_name)) {
228 if ($_parts[$_parts_count - 1] != $_resourcename_parts) {
233 if (isset($_compile_id) && (!isset($_parts[$_parts_count - 2 - $_compile_id_offset]) || $_parts[$_parts_count - 2 - $_compile_id_offset] != $_compile_id)) {
237 if (isset($_cache_id)) {
239 $_parts_count = (isset($_compile_id)) ? $_parts_count - 2 - $_compile_id_offset : $_parts_count - 1 - $_compile_id_offset;
240 if ($_parts_count < $_cache_id_parts_count) {
243 for ($i = 0; $i < $_cache_id_parts_count; $i ++) {
244 if ($_parts[$i] != $_cache_id_parts[$i]) {
250 if (isset($exp_time)) {
252 preg_match(
'#\'cache_lifetime\' =>\s*(\d*)#', file_get_contents($_file), $match);
253 if ($_time < (@filemtime($_file) + $match[1])) {
257 if ($_time - @filemtime($_file) < $exp_time) {
262 $_count += @unlink((
string) $_file) ? 1 : 0;
280 if (version_compare(PHP_VERSION,
'5.3.0',
'>=')) {
281 clearstatcache(
true, $cached->lock_id);
285 if (is_file($cached->lock_id)) {
286 $t = @filemtime($cached->lock_id);
287 return $t && (time() - $t < $smarty->locking_timeout);
303 $cached->is_locked =
true;
304 touch($cached->lock_id);
317 $cached->is_locked =
false;
318 @unlink($cached->lock_id);