123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225 |
- <?php
-
-
-
- class Smarty_Internal_CacheResource_File extends Smarty_CacheResource
- {
-
-
- public function populate(Smarty_Template_Cached $cached, Smarty_Internal_Template $_template)
- {
- $_source_file_path = str_replace(':', '.', $_template->source->filepath);
- $_cache_id = isset($_template->cache_id) ? preg_replace('![^\w\|]+!', '_', $_template->cache_id) : null;
- $_compile_id = isset($_template->compile_id) ? preg_replace('![^\w]+!', '_', $_template->compile_id) : null;
- $_filepath = $_template->source->uid;
-
- if ($_template->smarty->use_sub_dirs) {
- $_filepath = substr($_filepath, 0, 2) . DS . substr($_filepath, 2, 2) . DS . substr($_filepath, 4, 2) . DS .
- $_filepath;
- }
- $_compile_dir_sep = $_template->smarty->use_sub_dirs ? DS : '^';
- if (isset($_cache_id)) {
- $_cache_id = str_replace('|', $_compile_dir_sep, $_cache_id) . $_compile_dir_sep;
- } else {
- $_cache_id = '';
- }
- if (isset($_compile_id)) {
- $_compile_id = $_compile_id . $_compile_dir_sep;
- } else {
- $_compile_id = '';
- }
- $_cache_dir = $_template->smarty->getCacheDir();
- if ($_template->smarty->cache_locking) {
-
-
- if (!preg_match('/^([\/\\\\]|[a-zA-Z]:[\/\\\\])/', $_cache_dir)) {
- $_lock_dir = rtrim(getcwd(), '/\\') . DS . $_cache_dir;
- } else {
- $_lock_dir = $_cache_dir;
- }
- $cached->lock_id = $_lock_dir . sha1($_cache_id . $_compile_id . $_template->source->uid) . '.lock';
- }
- $cached->filepath = $_cache_dir . $_cache_id . $_compile_id . $_filepath . '.' . basename($_source_file_path) .
- '.php';
- $cached->timestamp = $cached->exists = is_file($cached->filepath);
- if ($cached->exists) {
- $cached->timestamp = filemtime($cached->filepath);
- }
- }
-
-
-
- public function populateTimestamp(Smarty_Template_Cached $cached)
- {
- $cached->timestamp = $cached->exists = is_file($cached->filepath);
- if ($cached->exists) {
- $cached->timestamp = filemtime($cached->filepath);
- }
- }
-
-
-
- public function process(Smarty_Internal_Template $_template, Smarty_Template_Cached $cached = null, $update = false)
- {
-
-
- $_smarty_tpl = $_template;
- $_template->cached->valid = false;
- if ($update && defined('HHVM_VERSION')) {
- return $_template->smarty->ext->_hhvm->includeHhvm($_template, $_template->cached->filepath);
- } else {
- return @include $_template->cached->filepath;
- }
- }
-
-
-
- public function writeCachedContent(Smarty_Internal_Template $_template, $content)
- {
- if ($_template->smarty->ext->_writeFile->writeFile($_template->cached->filepath, $content, $_template->smarty) === true) {
- if (function_exists('opcache_invalidate')) {
- opcache_invalidate($_template->cached->filepath);
- }
- $cached = $_template->cached;
- $cached->timestamp = $cached->exists = is_file($cached->filepath);
- if ($cached->exists) {
- $cached->timestamp = filemtime($cached->filepath);
- return true;
- }
- }
- return false;
- }
-
-
-
- public function readCachedContent(Smarty_Internal_Template $_template)
- {
- if (is_file($_template->cached->filepath)) {
- return file_get_contents($_template->cached->filepath);
- }
- return false;
- }
-
-
-
- public function clearAll(Smarty $smarty, $exp_time = null)
- {
- return Smarty_Internal_Extension_Clear::clear($smarty, null, null, null, $exp_time);
- }
-
-
-
- public function clear(Smarty $smarty, $resource_name, $cache_id, $compile_id, $exp_time)
- {
- return Smarty_Internal_Extension_Clear::clear($smarty, $resource_name, $cache_id, $compile_id, $exp_time);
- }
-
-
-
- public function hasLock(Smarty $smarty, Smarty_Template_Cached $cached)
- {
- if (version_compare(PHP_VERSION, '5.3.0', '>=')) {
- clearstatcache(true, $cached->lock_id);
- } else {
- clearstatcache();
- }
- if (is_file($cached->lock_id)) {
- $t = @filemtime($cached->lock_id);
- return $t && (time() - $t < $smarty->locking_timeout);
- } else {
- return false;
- }
- }
-
-
-
- public function acquireLock(Smarty $smarty, Smarty_Template_Cached $cached)
- {
- $cached->is_locked = true;
- touch($cached->lock_id);
- }
-
-
-
- public function releaseLock(Smarty $smarty, Smarty_Template_Cached $cached)
- {
- $cached->is_locked = false;
- @unlink($cached->lock_id);
- }
- }
|