PEEL Shopping
Open source ecommerce : PEEL Shopping
smarty_internal_cacheresource_file.php
Go to the documentation of this file.
1 <?php
20 
28  public function populate(Smarty_Template_Cached $cached, Smarty_Internal_Template $_template)
29  {
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;
34  // if use_sub_dirs, break file into directories
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
39  . $_filepath;
40  }
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;
44  } else {
45  $_cache_id = '';
46  }
47  if (isset($_compile_id)) {
48  $_compile_id = $_compile_id . $_compile_dir_sep;
49  } else {
50  $_compile_id = '';
51  }
52  $_cache_dir = $_template->smarty->getCacheDir();
53  if ($_template->smarty->cache_locking) {
54  // create locking file name
55  // relative file name?
56  if (!preg_match('/^([\/\\\\]|[a-zA-Z]:[\/\\\\])/', $_cache_dir)) {
57  $_lock_dir = rtrim(getcwd(), '/\\') . DS . $_cache_dir;
58  } else {
59  $_lock_dir = $_cache_dir;
60  }
61  $cached->lock_id = $_lock_dir.sha1($_cache_id.$_compile_id.$_template->source->uid).'.lock';
62  }
63  $cached->filepath = $_cache_dir . $_cache_id . $_compile_id . $_filepath . '.' . basename($_source_file_path) . '.php';
64  $cached->timestamp = @filemtime($cached->filepath);
65  $cached->exists = !!$cached->timestamp;
66  }
67 
74  public function populateTimestamp(Smarty_Template_Cached $cached)
75  {
76  $cached->timestamp = @filemtime($cached->filepath);
77  $cached->exists = !!$cached->timestamp;
78  }
79 
87  public function process(Smarty_Internal_Template $_template, Smarty_Template_Cached $cached=null)
88  {
89  $_smarty_tpl = $_template;
90  return @include $_template->cached->filepath;
91  }
92 
100  public function writeCachedContent(Smarty_Internal_Template $_template, $content)
101  {
102  if (Smarty_Internal_Write_File::writeFile($_template->cached->filepath, $content, $_template->smarty) === true) {
103  $_template->cached->timestamp = @filemtime($_template->cached->filepath);
104  $_template->cached->exists = !!$_template->cached->timestamp;
105  if ($_template->cached->exists) {
106  return true;
107  }
108  }
109  return false;
110  }
111 
119  public function clearAll(Smarty $smarty, $exp_time = null)
120  {
121  return $this->clear($smarty, null, null, null, $exp_time);
122  }
123 
134  public function clear(Smarty $smarty, $resource_name, $cache_id, $compile_id, $exp_time)
135  {
136  $_cache_id = isset($cache_id) ? preg_replace('![^\w\|]+!', '_', $cache_id) : null;
137  $_compile_id = isset($compile_id) ? preg_replace('![^\w\|]+!', '_', $compile_id) : null;
138  $_dir_sep = $smarty->use_sub_dirs ? '/' : '^';
139  $_compile_id_offset = $smarty->use_sub_dirs ? 3 : 0;
140  $_dir = $smarty->getCacheDir();
141  $_dir_length = strlen($_dir);
142  if (isset($_cache_id)) {
143  $_cache_id_parts = explode('|', $_cache_id);
144  $_cache_id_parts_count = count($_cache_id_parts);
145  if ($smarty->use_sub_dirs) {
146  foreach ($_cache_id_parts as $id_part) {
147  $_dir .= $id_part . DS;
148  }
149  }
150  }
151  if (isset($resource_name)) {
152  $_save_stat = $smarty->caching;
153  $smarty->caching = true;
154  $tpl = new $smarty->template_class($resource_name, $smarty);
155  $smarty->caching = $_save_stat;
156 
157  // remove from template cache
158  $tpl->source; // have the template registered before unset()
159  if ($smarty->allow_ambiguous_resources) {
160  $_templateId = $tpl->source->unique_resource . $tpl->cache_id . $tpl->compile_id;
161  } else {
162  $_templateId = $smarty->joined_template_dir . '#' . $resource_name . $tpl->cache_id . $tpl->compile_id;
163  }
164  if (isset($_templateId[150])) {
165  $_templateId = sha1($_templateId);
166  }
167  unset($smarty->template_objects[$_templateId]);
168 
169  if ($tpl->source->exists) {
170  $_resourcename_parts = basename(str_replace('^', '/', $tpl->cached->filepath));
171  } else {
172  return 0;
173  }
174  }
175  $_count = 0;
176  $_time = time();
177  if (file_exists($_dir)) {
178  $_cacheDirs = new RecursiveDirectoryIterator($_dir);
179  $_cache = new RecursiveIteratorIterator($_cacheDirs, RecursiveIteratorIterator::CHILD_FIRST);
180  foreach ($_cache as $_file) {
181  if (substr(basename($_file->getPathname()),0,1) == '.' || strpos($_file, '.svn') !== false) continue;
182  // directory ?
183  if ($_file->isDir()) {
184  if (!$_cache->isDot()) {
185  // delete folder if empty
186  @rmdir($_file->getPathname());
187  }
188  } else {
189  $_parts = explode($_dir_sep, str_replace('\\', '/', substr((string)$_file, $_dir_length)));
190  $_parts_count = count($_parts);
191  // check name
192  if (isset($resource_name)) {
193  if ($_parts[$_parts_count-1] != $_resourcename_parts) {
194  continue;
195  }
196  }
197  // check compile id
198  if (isset($_compile_id) && (!isset($_parts[$_parts_count-2 - $_compile_id_offset]) || $_parts[$_parts_count-2 - $_compile_id_offset] != $_compile_id)) {
199  continue;
200  }
201  // check cache id
202  if (isset($_cache_id)) {
203  // count of cache id parts
204  $_parts_count = (isset($_compile_id)) ? $_parts_count - 2 - $_compile_id_offset : $_parts_count - 1 - $_compile_id_offset;
205  if ($_parts_count < $_cache_id_parts_count) {
206  continue;
207  }
208  for ($i = 0; $i < $_cache_id_parts_count; $i++) {
209  if ($_parts[$i] != $_cache_id_parts[$i]) continue 2;
210  }
211  }
212  // expired ?
213  if (isset($exp_time)) {
214  if ($exp_time < 0) {
215  preg_match('#\'cache_lifetime\' =>\s*(\d*)#', file_get_contents($_file), $match);
216  if ($_time < (@filemtime($_file) + $match[1])) {
217  continue;
218  }
219  } else {
220  if ($_time - @filemtime($_file) < $exp_time) {
221  continue;
222  }
223  }
224  }
225  $_count += @unlink((string) $_file) ? 1 : 0;
226  }
227  }
228  }
229  return $_count;
230  }
231 
239  public function hasLock(Smarty $smarty, Smarty_Template_Cached $cached)
240  {
241  if (version_compare(PHP_VERSION, '5.3.0', '>=')) {
242  clearstatcache(true, $cached->lock_id);
243  } else {
244  clearstatcache();
245  }
246  $t = @filemtime($cached->lock_id);
247  return $t && (time() - $t < $smarty->locking_timeout);
248  }
249 
256  public function acquireLock(Smarty $smarty, Smarty_Template_Cached $cached)
257  {
258  $cached->is_locked = true;
259  touch($cached->lock_id);
260  }
261 
268  public function releaseLock(Smarty $smarty, Smarty_Template_Cached $cached)
269  {
270  $cached->is_locked = false;
271  @unlink($cached->lock_id);
272  }
273  }
274 
275 ?>
releaseLock(Smarty $smarty, Smarty_Template_Cached $cached)
Unlock cache for this template.
hasLock(Smarty $smarty, Smarty_Template_Cached $cached)
Check is cache is locked for this template.
if(!empty($_GET['id'])) if(isset($_POST['form_name'], $_POST['form_subject'], $_POST['form_text'], $_POST['form_lang'])&&empty($_GET['id'])) if(empty($_GET['id'])) $tpl
Smarty plugin to format text blocks.
populate(Smarty_Template_Cached $cached, Smarty_Internal_Template $_template)
populate Cached Object with meta data from Resource
acquireLock(Smarty $smarty, Smarty_Template_Cached $cached)
Lock cache for this template.
clearAll(Smarty $smarty, $exp_time=null)
Empty cache.
writeCachedContent(Smarty_Internal_Template $_template, $content)
Write the rendered template output to cache.
clear(Smarty $smarty, $resource_name, $cache_id, $compile_id, $exp_time)
Empty cache for a specific template.
populateTimestamp(Smarty_Template_Cached $cached)
populate Cached Object with timestamp and exists from Resource
process(Smarty_Internal_Template $_template, Smarty_Template_Cached $cached=null)
Read the cached template and process its header.
$match
Definition: search.php:86
getCacheDir()
Get cache directory.
static writeFile($_filepath, $_contents, Smarty $smarty)
Writes file in a safe way to disk.

This documentation for Open ecommerce PEEL Shopping and PEEL.fr has been generated by Doxygen on Thu Oct 15 2015 14:41:16 - Peel ecommerce is a product of Agence web Advisto SAS. All rights reserved.