| 
									
										
										
										
											2015-10-25 04:53:19 +01:00
										 |  |  | <?php | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /** | 
					
						
							|  |  |  |  * Inline Runtime Methods render, setSourceByUid, setupSubTemplate | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * @package    Smarty | 
					
						
							|  |  |  |  * @subpackage PluginsInternal | 
					
						
							|  |  |  |  * @author     Uwe Tews | 
					
						
							|  |  |  |  **/ | 
					
						
							|  |  |  | class Smarty_Internal_Runtime_UpdateCache | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     /** | 
					
						
							|  |  |  |      * check client side cache | 
					
						
							|  |  |  |      * | 
					
						
							|  |  |  |      * @param \Smarty_Template_Cached  $cached | 
					
						
							|  |  |  |      * @param Smarty_Internal_Template $_template | 
					
						
							| 
									
										
										
										
											2018-06-12 09:58:15 +02:00
										 |  |  |      * @param string                   $content | 
					
						
							| 
									
										
										
										
											2015-10-25 04:53:19 +01:00
										 |  |  |      */ | 
					
						
							|  |  |  |     public function cacheModifiedCheck(Smarty_Template_Cached $cached, Smarty_Internal_Template $_template, $content) | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     /** | 
					
						
							|  |  |  |      * Cache was invalid , so render from compiled and write to cache | 
					
						
							| 
									
										
										
										
											2015-12-19 21:35:24 +01:00
										 |  |  |      * | 
					
						
							| 
									
										
										
										
											2015-10-25 04:53:19 +01:00
										 |  |  |      * @param \Smarty_Template_Cached   $cached | 
					
						
							|  |  |  |      * @param \Smarty_Internal_Template $_template | 
					
						
							| 
									
										
										
										
											2018-08-31 16:45:09 +02:00
										 |  |  |      * @param                           $no_output_filter | 
					
						
							| 
									
										
										
										
											2015-10-25 04:53:19 +01:00
										 |  |  |      * | 
					
						
							|  |  |  |      * @throws \Exception | 
					
						
							|  |  |  |      */ | 
					
						
							|  |  |  |     public function updateCache(Smarty_Template_Cached $cached, Smarty_Internal_Template $_template, $no_output_filter) | 
					
						
							|  |  |  |     { | 
					
						
							| 
									
										
										
										
											2016-03-10 22:22:46 +01:00
										 |  |  |         ob_start(); | 
					
						
							|  |  |  |         if (!isset($_template->compiled)) { | 
					
						
							|  |  |  |             $_template->loadCompiled(); | 
					
						
							| 
									
										
										
										
											2015-10-25 04:53:19 +01:00
										 |  |  |         } | 
					
						
							| 
									
										
										
										
											2016-03-10 22:22:46 +01:00
										 |  |  |         $_template->compiled->render($_template); | 
					
						
							| 
									
										
										
										
											2015-10-25 04:53:19 +01:00
										 |  |  |         if ($_template->smarty->debugging) { | 
					
						
							|  |  |  |             $_template->smarty->_debug->start_cache($_template); | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |         $this->removeNoCacheHash($cached, $_template, $no_output_filter); | 
					
						
							| 
									
										
										
										
											2017-11-06 01:02:56 +01:00
										 |  |  |         $compile_check = (int)$_template->compile_check; | 
					
						
							|  |  |  |         $_template->compile_check = Smarty::COMPILECHECK_OFF; | 
					
						
							| 
									
										
										
										
											2016-09-11 04:35:52 +02:00
										 |  |  |         if ($_template->_isSubTpl()) { | 
					
						
							| 
									
										
										
										
											2015-10-25 04:53:19 +01:00
										 |  |  |             $_template->compiled->unifunc = $_template->parent->compiled->unifunc; | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |         if (!$_template->cached->processed) { | 
					
						
							|  |  |  |             $_template->cached->process($_template, true); | 
					
						
							|  |  |  |         } | 
					
						
							| 
									
										
										
										
											2017-11-06 01:02:56 +01:00
										 |  |  |         $_template->compile_check = $compile_check; | 
					
						
							| 
									
										
										
										
											2015-10-25 04:53:19 +01:00
										 |  |  |         $cached->getRenderedTemplateCode($_template); | 
					
						
							|  |  |  |         if ($_template->smarty->debugging) { | 
					
						
							|  |  |  |             $_template->smarty->_debug->end_cache($_template); | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-03-23 19:11:12 +01:00
										 |  |  |     /** | 
					
						
							|  |  |  |      * Sanitize content and write it to cache resource | 
					
						
							|  |  |  |      * | 
					
						
							|  |  |  |      * @param \Smarty_Template_Cached  $cached | 
					
						
							|  |  |  |      * @param Smarty_Internal_Template $_template | 
					
						
							|  |  |  |      * @param bool                     $no_output_filter | 
					
						
							|  |  |  |      * | 
					
						
							|  |  |  |      * @throws \SmartyException | 
					
						
							|  |  |  |      */ | 
					
						
							| 
									
										
										
										
											2018-08-31 16:45:09 +02:00
										 |  |  |     public function removeNoCacheHash( | 
					
						
							|  |  |  |         Smarty_Template_Cached $cached, | 
					
						
							| 
									
										
										
										
											2018-06-12 09:58:15 +02:00
										 |  |  |         Smarty_Internal_Template $_template, | 
					
						
							|  |  |  |         $no_output_filter | 
					
						
							|  |  |  |     ) { | 
					
						
							| 
									
										
										
										
											2018-03-23 19:11:12 +01:00
										 |  |  |         $php_pattern = '/(<%|%>|<\?php|<\?|\?>|<script\s+language\s*=\s*[\"\']?\s*php\s*[\"\']?\s*>)/'; | 
					
						
							|  |  |  |         $content = ob_get_clean(); | 
					
						
							|  |  |  |         $hash_array = $cached->hashes; | 
					
						
							| 
									
										
										
										
											2018-08-31 16:45:09 +02:00
										 |  |  |         $hash_array[ $_template->compiled->nocache_hash ] = true; | 
					
						
							| 
									
										
										
										
											2018-03-23 19:11:12 +01:00
										 |  |  |         $hash_array = array_keys($hash_array); | 
					
						
							|  |  |  |         $nocache_hash = '(' . implode('|', $hash_array) . ')'; | 
					
						
							|  |  |  |         $_template->cached->has_nocache_code = false; | 
					
						
							|  |  |  |         // get text between non-cached items
 | 
					
						
							|  |  |  |         $cache_split = | 
					
						
							| 
									
										
										
										
											2018-06-12 09:58:15 +02:00
										 |  |  |             preg_split( | 
					
						
							|  |  |  |                 "!/\*%%SmartyNocache:{$nocache_hash}%%\*\/(.+?)/\*/%%SmartyNocache:{$nocache_hash}%%\*/!s", | 
					
						
							|  |  |  |                 $content | 
					
						
							|  |  |  |             ); | 
					
						
							| 
									
										
										
										
											2018-03-23 19:11:12 +01:00
										 |  |  |         // get non-cached items
 | 
					
						
							| 
									
										
										
										
											2018-06-12 09:58:15 +02:00
										 |  |  |         preg_match_all( | 
					
						
							|  |  |  |             "!/\*%%SmartyNocache:{$nocache_hash}%%\*\/(.+?)/\*/%%SmartyNocache:{$nocache_hash}%%\*/!s", | 
					
						
							|  |  |  |             $content, | 
					
						
							|  |  |  |             $cache_parts | 
					
						
							|  |  |  |         ); | 
					
						
							| 
									
										
										
										
											2018-03-23 19:11:12 +01:00
										 |  |  |         $content = ''; | 
					
						
							|  |  |  |         // loop over items, stitch back together
 | 
					
						
							|  |  |  |         foreach ($cache_split as $curr_idx => $curr_split) { | 
					
						
							|  |  |  |             if (preg_match($php_pattern, $curr_split)) { | 
					
						
							|  |  |  |                 // escape PHP tags in template content
 | 
					
						
							| 
									
										
										
										
											2018-06-12 09:58:15 +02:00
										 |  |  |                 $php_split = preg_split( | 
					
						
							|  |  |  |                     $php_pattern, | 
					
						
							|  |  |  |                     $curr_split | 
					
						
							|  |  |  |                 ); | 
					
						
							|  |  |  |                 preg_match_all( | 
					
						
							|  |  |  |                     $php_pattern, | 
					
						
							|  |  |  |                     $curr_split, | 
					
						
							|  |  |  |                     $php_parts | 
					
						
							|  |  |  |                 ); | 
					
						
							| 
									
										
										
										
											2018-03-23 19:11:12 +01:00
										 |  |  |                 foreach ($php_split as $idx_php => $curr_php) { | 
					
						
							|  |  |  |                     $content .= $curr_php; | 
					
						
							|  |  |  |                     if (isset($php_parts[ 0 ][ $idx_php ])) { | 
					
						
							|  |  |  |                         $content .= "<?php echo '{$php_parts[ 1 ][ $idx_php ]}'; ?>\n"; | 
					
						
							|  |  |  |                     } | 
					
						
							|  |  |  |                 } | 
					
						
							|  |  |  |             } else { | 
					
						
							|  |  |  |                 $content .= $curr_split; | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |             if (isset($cache_parts[ 0 ][ $curr_idx ])) { | 
					
						
							|  |  |  |                 $_template->cached->has_nocache_code = true; | 
					
						
							|  |  |  |                 $content .= $cache_parts[ 2 ][ $curr_idx ]; | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |         } | 
					
						
							| 
									
										
										
										
											2018-08-31 16:45:09 +02:00
										 |  |  |         if (!$no_output_filter && !$_template->cached->has_nocache_code | 
					
						
							|  |  |  |             && (isset($_template->smarty->autoload_filters[ 'output' ]) | 
					
						
							|  |  |  |                 || isset($_template->smarty->registered_filters[ 'output' ])) | 
					
						
							| 
									
										
										
										
											2018-03-23 19:11:12 +01:00
										 |  |  |         ) { | 
					
						
							|  |  |  |             $content = $_template->smarty->ext->_filterHandler->runFilter('output', $content, $_template); | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |         // write cache file content
 | 
					
						
							| 
									
										
										
										
											2018-03-28 07:15:29 +02:00
										 |  |  |         $this->writeCachedContent($_template, $content); | 
					
						
							| 
									
										
										
										
											2018-03-23 19:11:12 +01:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-10-25 04:53:19 +01:00
										 |  |  |     /** | 
					
						
							|  |  |  |      * Writes the content to cache resource | 
					
						
							|  |  |  |      * | 
					
						
							|  |  |  |      * @param Smarty_Internal_Template $_template | 
					
						
							|  |  |  |      * @param string                   $content | 
					
						
							|  |  |  |      * | 
					
						
							|  |  |  |      * @return bool | 
					
						
							|  |  |  |      */ | 
					
						
							| 
									
										
										
										
											2018-03-28 07:15:29 +02:00
										 |  |  |     public function writeCachedContent(Smarty_Internal_Template $_template, $content) | 
					
						
							| 
									
										
										
										
											2015-10-25 04:53:19 +01:00
										 |  |  |     { | 
					
						
							| 
									
										
										
										
											2017-11-06 01:02:56 +01:00
										 |  |  |         if ($_template->source->handler->recompiled || !$_template->caching | 
					
						
							| 
									
										
										
										
											2015-10-25 04:53:19 +01:00
										 |  |  |         ) { | 
					
						
							|  |  |  |             // don't write cache file
 | 
					
						
							|  |  |  |             return false; | 
					
						
							|  |  |  |         } | 
					
						
							| 
									
										
										
										
											2018-03-28 07:15:29 +02:00
										 |  |  |         if (!isset($_template->cached)) { | 
					
						
							|  |  |  |             $_template->loadCached(); | 
					
						
							|  |  |  |         } | 
					
						
							| 
									
										
										
										
											2015-10-25 04:53:19 +01:00
										 |  |  |         $content = $_template->smarty->ext->_codeFrame->create($_template, $content, '', true); | 
					
						
							| 
									
										
										
										
											2018-03-28 07:15:29 +02:00
										 |  |  |         return $this->write($_template, $content); | 
					
						
							| 
									
										
										
										
											2015-10-25 04:53:19 +01:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     /** | 
					
						
							|  |  |  |      * Write this cache object to handler | 
					
						
							|  |  |  |      * | 
					
						
							|  |  |  |      * @param Smarty_Internal_Template $_template template object | 
					
						
							|  |  |  |      * @param string                   $content   content to cache | 
					
						
							|  |  |  |      * | 
					
						
							|  |  |  |      * @return bool success | 
					
						
							|  |  |  |      */ | 
					
						
							| 
									
										
										
										
											2018-03-28 07:15:29 +02:00
										 |  |  |     public function write(Smarty_Internal_Template $_template, $content) | 
					
						
							| 
									
										
										
										
											2015-10-25 04:53:19 +01:00
										 |  |  |     { | 
					
						
							|  |  |  |         if (!$_template->source->handler->recompiled) { | 
					
						
							| 
									
										
										
										
											2018-03-28 07:15:29 +02:00
										 |  |  |             $cached = $_template->cached; | 
					
						
							| 
									
										
										
										
											2015-10-25 04:53:19 +01:00
										 |  |  |             if ($cached->handler->writeCachedContent($_template, $content)) { | 
					
						
							|  |  |  |                 $cached->content = null; | 
					
						
							|  |  |  |                 $cached->timestamp = time(); | 
					
						
							|  |  |  |                 $cached->exists = true; | 
					
						
							|  |  |  |                 $cached->valid = true; | 
					
						
							|  |  |  |                 $cached->cache_lifetime = $_template->cache_lifetime; | 
					
						
							|  |  |  |                 $cached->processed = false; | 
					
						
							|  |  |  |                 if ($_template->smarty->cache_locking) { | 
					
						
							|  |  |  |                     $cached->handler->releaseLock($_template->smarty, $cached); | 
					
						
							|  |  |  |                 } | 
					
						
							|  |  |  |                 return true; | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |             $cached->content = null; | 
					
						
							|  |  |  |             $cached->timestamp = false; | 
					
						
							|  |  |  |             $cached->exists = false; | 
					
						
							|  |  |  |             $cached->valid = false; | 
					
						
							|  |  |  |             $cached->processed = false; | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |         return false; | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2018-06-12 09:58:15 +02:00
										 |  |  | } |