| 1: | <?php
|
| 2: | |
| 3: | |
| 4: | |
| 5: | |
| 6: | |
| 7: |
|
| 8: |
|
| 9: | |
| 10: | |
| 11: | |
| 12: | |
| 13: | |
| 14: | |
| 15: | |
| 16: |
|
| 17: | class Smarty_Template_Cached extends Smarty_Template_Resource_Base
|
| 18: | {
|
| 19: | |
| 20: | |
| 21: | |
| 22: | |
| 23: |
|
| 24: | public $valid = null;
|
| 25: |
|
| 26: | |
| 27: | |
| 28: | |
| 29: | |
| 30: |
|
| 31: | public $handler = null;
|
| 32: |
|
| 33: | |
| 34: | |
| 35: | |
| 36: | |
| 37: |
|
| 38: | public $cache_id = null;
|
| 39: |
|
| 40: | |
| 41: | |
| 42: | |
| 43: | |
| 44: |
|
| 45: | public $cache_lifetime = 0;
|
| 46: |
|
| 47: | |
| 48: | |
| 49: | |
| 50: | |
| 51: |
|
| 52: | public $lock_id = null;
|
| 53: |
|
| 54: | |
| 55: | |
| 56: | |
| 57: | |
| 58: |
|
| 59: | public $is_locked = false;
|
| 60: |
|
| 61: | |
| 62: | |
| 63: | |
| 64: | |
| 65: |
|
| 66: | public $source = null;
|
| 67: |
|
| 68: | |
| 69: | |
| 70: | |
| 71: | |
| 72: |
|
| 73: | public $hashes = array();
|
| 74: |
|
| 75: | |
| 76: | |
| 77: | |
| 78: | |
| 79: |
|
| 80: | public $isCache = true;
|
| 81: |
|
| 82: | |
| 83: | |
| 84: | |
| 85: | |
| 86: | |
| 87: | |
| 88: |
|
| 89: | public function __construct(Smarty_Internal_Template $_template)
|
| 90: | {
|
| 91: | $this->compile_id = $_template->compile_id;
|
| 92: | $this->cache_id = $_template->cache_id;
|
| 93: | $this->source = $_template->source;
|
| 94: | if (!class_exists('Smarty_CacheResource', false)) {
|
| 95: | include SMARTY_SYSPLUGINS_DIR . 'smarty_cacheresource.php';
|
| 96: | }
|
| 97: | $this->handler = Smarty_CacheResource::load($_template->smarty);
|
| 98: | }
|
| 99: |
|
| 100: | |
| 101: | |
| 102: | |
| 103: | |
| 104: |
|
| 105: | public static function load(Smarty_Internal_Template $_template)
|
| 106: | {
|
| 107: | $_template->cached = new Smarty_Template_Cached($_template);
|
| 108: | $_template->cached->handler->populate($_template->cached, $_template);
|
| 109: |
|
| 110: | if (!$_template->caching || $_template->source->handler->recompiled
|
| 111: | ) {
|
| 112: | $_template->cached->valid = false;
|
| 113: | }
|
| 114: | return $_template->cached;
|
| 115: | }
|
| 116: |
|
| 117: | |
| 118: | |
| 119: | |
| 120: | |
| 121: | |
| 122: | |
| 123: | |
| 124: |
|
| 125: | public function render(Smarty_Internal_Template $_template, $no_output_filter = true)
|
| 126: | {
|
| 127: | if ($this->isCached($_template)) {
|
| 128: | if ($_template->smarty->debugging) {
|
| 129: | if (!isset($_template->smarty->_debug)) {
|
| 130: | $_template->smarty->_debug = new Smarty_Internal_Debug();
|
| 131: | }
|
| 132: | $_template->smarty->_debug->start_cache($_template);
|
| 133: | }
|
| 134: | if (!$this->processed) {
|
| 135: | $this->process($_template);
|
| 136: | }
|
| 137: | $this->getRenderedTemplateCode($_template);
|
| 138: | if ($_template->smarty->debugging) {
|
| 139: | $_template->smarty->_debug->end_cache($_template);
|
| 140: | }
|
| 141: | return;
|
| 142: | } else {
|
| 143: | $_template->smarty->ext->_updateCache->updateCache($this, $_template, $no_output_filter);
|
| 144: | }
|
| 145: | }
|
| 146: |
|
| 147: | |
| 148: | |
| 149: | |
| 150: | |
| 151: | |
| 152: | |
| 153: |
|
| 154: | public function isCached(Smarty_Internal_Template $_template)
|
| 155: | {
|
| 156: | if ($this->valid !== null) {
|
| 157: | return $this->valid;
|
| 158: | }
|
| 159: | while (true) {
|
| 160: | while (true) {
|
| 161: | if ($this->exists === false || $_template->smarty->force_compile || $_template->smarty->force_cache) {
|
| 162: | $this->valid = false;
|
| 163: | } else {
|
| 164: | $this->valid = true;
|
| 165: | }
|
| 166: | if ($this->valid && $_template->caching === Smarty::CACHING_LIFETIME_CURRENT
|
| 167: | && $_template->cache_lifetime >= 0 && time() > ($this->timestamp + $_template->cache_lifetime)
|
| 168: | ) {
|
| 169: |
|
| 170: | $this->valid = false;
|
| 171: | }
|
| 172: | if ($this->valid && $_template->compile_check === Smarty::COMPILECHECK_ON
|
| 173: | && $_template->source->getTimeStamp() > $this->timestamp
|
| 174: | ) {
|
| 175: | $this->valid = false;
|
| 176: | }
|
| 177: | if ($this->valid || !$_template->smarty->cache_locking) {
|
| 178: | break;
|
| 179: | }
|
| 180: | if (!$this->handler->locked($_template->smarty, $this)) {
|
| 181: | $this->handler->acquireLock($_template->smarty, $this);
|
| 182: | break 2;
|
| 183: | }
|
| 184: | $this->handler->populate($this, $_template);
|
| 185: | }
|
| 186: | if ($this->valid) {
|
| 187: | if (!$_template->smarty->cache_locking || $this->handler->locked($_template->smarty, $this) === null) {
|
| 188: |
|
| 189: | if ($_template->smarty->debugging) {
|
| 190: | $_template->smarty->_debug->start_cache($_template);
|
| 191: | }
|
| 192: | if ($this->handler->process($_template, $this) === false) {
|
| 193: | $this->valid = false;
|
| 194: | } else {
|
| 195: | $this->processed = true;
|
| 196: | }
|
| 197: | if ($_template->smarty->debugging) {
|
| 198: | $_template->smarty->_debug->end_cache($_template);
|
| 199: | }
|
| 200: | } else {
|
| 201: | $this->is_locked = true;
|
| 202: | continue;
|
| 203: | }
|
| 204: | } else {
|
| 205: | return $this->valid;
|
| 206: | }
|
| 207: | if ($this->valid && $_template->caching === Smarty::CACHING_LIFETIME_SAVED
|
| 208: | && $_template->cached->cache_lifetime >= 0
|
| 209: | && (time() > ($_template->cached->timestamp + $_template->cached->cache_lifetime))
|
| 210: | ) {
|
| 211: | $this->valid = false;
|
| 212: | }
|
| 213: | if ($_template->smarty->cache_locking) {
|
| 214: | if (!$this->valid) {
|
| 215: | $this->handler->acquireLock($_template->smarty, $this);
|
| 216: | } elseif ($this->is_locked) {
|
| 217: | $this->handler->releaseLock($_template->smarty, $this);
|
| 218: | }
|
| 219: | }
|
| 220: | return $this->valid;
|
| 221: | }
|
| 222: | return $this->valid;
|
| 223: | }
|
| 224: |
|
| 225: | |
| 226: | |
| 227: | |
| 228: | |
| 229: | |
| 230: |
|
| 231: | public function process(Smarty_Internal_Template $_template, $update = false)
|
| 232: | {
|
| 233: | if ($this->handler->process($_template, $this, $update) === false) {
|
| 234: | $this->valid = false;
|
| 235: | }
|
| 236: | if ($this->valid) {
|
| 237: | $this->processed = true;
|
| 238: | } else {
|
| 239: | $this->processed = false;
|
| 240: | }
|
| 241: | }
|
| 242: |
|
| 243: | |
| 244: | |
| 245: | |
| 246: | |
| 247: | |
| 248: | |
| 249: |
|
| 250: | public function read(Smarty_Internal_Template $_template)
|
| 251: | {
|
| 252: | if (!$_template->source->handler->recompiled) {
|
| 253: | return $this->handler->readCachedContent($_template);
|
| 254: | }
|
| 255: | return false;
|
| 256: | }
|
| 257: | }
|
| 258: | |