| 
									
										
										
										
											2015-01-01 23:28:09 +01:00
										 |  |  | <?php | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /** | 
					
						
							|  |  |  |  * Smarty Resource Data Object | 
					
						
							|  |  |  |  * Meta Data Container for Template Files | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * @package    Smarty | 
					
						
							|  |  |  |  * @subpackage TemplateResources | 
					
						
							|  |  |  |  * @author     Rodney Rehm | 
					
						
							|  |  |  |  * @property string $content compiled content | 
					
						
							|  |  |  |  */ | 
					
						
							| 
									
										
										
										
											2015-08-09 20:43:04 +02:00
										 |  |  | class Smarty_Template_Compiled extends Smarty_Template_Resource_Base | 
					
						
							| 
									
										
										
										
											2015-01-01 23:28:09 +01:00
										 |  |  | { | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     /** | 
					
						
							| 
									
										
										
										
											2015-08-09 20:43:04 +02:00
										 |  |  |      * nocache hash | 
					
						
							| 
									
										
										
										
											2015-01-01 23:28:09 +01:00
										 |  |  |      * | 
					
						
							|  |  |  |      * @var string|null | 
					
						
							|  |  |  |      */ | 
					
						
							| 
									
										
										
										
											2015-08-09 20:43:04 +02:00
										 |  |  |     public $nocache_hash = null; | 
					
						
							| 
									
										
										
										
											2015-08-06 00:57:36 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-01-01 23:28:09 +01:00
										 |  |  |     /** | 
					
						
							|  |  |  |      * get a Compiled Object of this source | 
					
						
							|  |  |  |      * | 
					
						
							|  |  |  |      * @param  Smarty_Internal_Template $_template template object | 
					
						
							|  |  |  |      * | 
					
						
							|  |  |  |      * @return Smarty_Template_Compiled compiled object | 
					
						
							|  |  |  |      */ | 
					
						
							|  |  |  |     static function load($_template) | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         $compiled = new Smarty_Template_Compiled(); | 
					
						
							| 
									
										
										
										
											2015-08-23 01:25:57 +02:00
										 |  |  |         if ($_template->source->handler->hasCompiledHandler) { | 
					
						
							| 
									
										
										
										
											2015-08-18 02:57:10 +02:00
										 |  |  |             $_template->source->handler->populateCompiledFilepath($compiled, $_template); | 
					
						
							| 
									
										
										
										
											2015-01-01 23:28:09 +01:00
										 |  |  |         } else { | 
					
						
							|  |  |  |             $compiled->populateCompiledFilepath($_template); | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |         return $compiled; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     /** | 
					
						
							|  |  |  |      * populate Compiled Object with compiled filepath | 
					
						
							|  |  |  |      * | 
					
						
							|  |  |  |      * @param Smarty_Internal_Template $_template template object | 
					
						
							|  |  |  |      **/ | 
					
						
							|  |  |  |     public function populateCompiledFilepath(Smarty_Internal_Template $_template) | 
					
						
							|  |  |  |     { | 
					
						
							| 
									
										
										
										
											2016-05-15 11:13:31 +02:00
										 |  |  |         $source = &$_template->source; | 
					
						
							|  |  |  |         $smarty = &$_template->smarty; | 
					
						
							|  |  |  |         $this->filepath = $smarty->getCompileDir(); | 
					
						
							|  |  |  |         if (isset($_template->compile_id)) { | 
					
						
							|  |  |  |             $this->filepath .= preg_replace('![^\w]+!', '_', $_template->compile_id) . | 
					
						
							| 
									
										
										
										
											2016-08-23 08:03:39 +02:00
										 |  |  |                                ($smarty->use_sub_dirs ? $smarty->ds : '^'); | 
					
						
							| 
									
										
										
										
											2015-01-03 07:36:07 +01:00
										 |  |  |         } | 
					
						
							| 
									
										
										
										
											2015-01-01 23:28:09 +01:00
										 |  |  |         // if use_sub_dirs, break file into directories
 | 
					
						
							| 
									
										
										
										
											2016-05-15 11:13:31 +02:00
										 |  |  |         if ($smarty->use_sub_dirs) { | 
					
						
							| 
									
										
										
										
											2016-08-23 08:03:39 +02:00
										 |  |  |             $this->filepath .= $source->uid[ 0 ] . $source->uid[ 1 ] . $smarty->ds . $source->uid[ 2 ] . $source->uid[ 3 ] . $smarty->ds . | 
					
						
							|  |  |  |                                $source->uid[ 4 ] . $source->uid[ 5 ] . $smarty->ds; | 
					
						
							| 
									
										
										
										
											2016-05-15 11:13:31 +02:00
										 |  |  |         } | 
					
						
							|  |  |  |         $this->filepath .= $source->uid . '_'; | 
					
						
							|  |  |  |         if ($source->isConfig) { | 
					
						
							|  |  |  |             $this->filepath .= (int) $smarty->config_read_hidden + (int) $smarty->config_booleanize * 2 + | 
					
						
							|  |  |  |                                (int) $smarty->config_overwrite * 4; | 
					
						
							| 
									
										
										
										
											2015-01-01 23:28:09 +01:00
										 |  |  |         } else { | 
					
						
							| 
									
										
										
										
											2016-05-15 11:13:31 +02:00
										 |  |  |             $this->filepath .= (int) $smarty->merge_compiled_includes + (int) $smarty->escape_html * 2; | 
					
						
							| 
									
										
										
										
											2015-01-01 23:28:09 +01:00
										 |  |  |         } | 
					
						
							| 
									
										
										
										
											2016-05-15 11:13:31 +02:00
										 |  |  |         $this->filepath .= '.' . $source->type; | 
					
						
							| 
									
										
										
										
											2016-05-15 11:51:46 +02:00
										 |  |  |         $basename = $source->handler->getBasename($source); | 
					
						
							|  |  |  |         if (!empty($basename)) { | 
					
						
							| 
									
										
										
										
											2016-05-15 11:13:31 +02:00
										 |  |  |             $this->filepath .= '.' . $basename; | 
					
						
							| 
									
										
										
										
											2015-01-01 23:28:09 +01:00
										 |  |  |         } | 
					
						
							| 
									
										
										
										
											2016-05-15 11:13:31 +02:00
										 |  |  |         if ($_template->caching) { | 
					
						
							|  |  |  |             $this->filepath .= '.cache'; | 
					
						
							| 
									
										
										
										
											2015-01-01 23:28:09 +01:00
										 |  |  |         } | 
					
						
							| 
									
										
										
										
											2016-05-15 11:13:31 +02:00
										 |  |  |         $this->filepath .= '.php'; | 
					
						
							|  |  |  |         $this->timestamp = $this->exists = is_file($this->filepath); | 
					
						
							|  |  |  |         if ($this->exists) { | 
					
						
							|  |  |  |             $this->timestamp = filemtime($this->filepath); | 
					
						
							| 
									
										
										
										
											2015-05-05 00:41:30 +02:00
										 |  |  |         } | 
					
						
							| 
									
										
										
										
											2015-01-01 23:28:09 +01:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     /** | 
					
						
							|  |  |  |      * load compiled template or compile from source | 
					
						
							|  |  |  |      * | 
					
						
							| 
									
										
										
										
											2016-03-11 01:07:26 +01:00
										 |  |  |      * @param Smarty_Internal_Template $_smarty_tpl do not change variable name, is used by compiled template | 
					
						
							| 
									
										
										
										
											2015-01-01 23:28:09 +01:00
										 |  |  |      * | 
					
						
							|  |  |  |      * @throws Exception | 
					
						
							|  |  |  |      */ | 
					
						
							| 
									
										
										
										
											2016-03-11 01:07:26 +01:00
										 |  |  |     public function process(Smarty_Internal_Template $_smarty_tpl) | 
					
						
							| 
									
										
										
										
											2015-01-01 23:28:09 +01:00
										 |  |  |     { | 
					
						
							| 
									
										
										
										
											2016-05-15 11:13:31 +02:00
										 |  |  |         $source = &$_smarty_tpl->source; | 
					
						
							|  |  |  |         $smarty = &$_smarty_tpl->smarty; | 
					
						
							|  |  |  |         if ($source->handler->recompiled) { | 
					
						
							|  |  |  |             $source->handler->process($_smarty_tpl); | 
					
						
							|  |  |  |         } elseif (!$source->handler->uncompiled) { | 
					
						
							|  |  |  |             if (!$this->exists || $smarty->force_compile || | 
					
						
							|  |  |  |                 ($smarty->compile_check && $source->getTimeStamp() > $this->getTimeStamp()) | 
					
						
							| 
									
										
										
										
											2016-03-10 22:22:46 +01:00
										 |  |  |             ) { | 
					
						
							| 
									
										
										
										
											2016-03-11 01:07:26 +01:00
										 |  |  |                 $this->compileTemplateSource($_smarty_tpl); | 
					
						
							| 
									
										
										
										
											2016-05-15 11:13:31 +02:00
										 |  |  |                 $compileCheck = $smarty->compile_check; | 
					
						
							|  |  |  |                 $smarty->compile_check = false; | 
					
						
							|  |  |  |                 $this->loadCompiledTemplate($_smarty_tpl); | 
					
						
							|  |  |  |                 $smarty->compile_check = $compileCheck; | 
					
						
							| 
									
										
										
										
											2016-03-10 22:22:46 +01:00
										 |  |  |             } else { | 
					
						
							| 
									
										
										
										
											2016-03-11 01:07:26 +01:00
										 |  |  |                 $_smarty_tpl->mustCompile = true; | 
					
						
							| 
									
										
										
										
											2016-03-10 22:22:46 +01:00
										 |  |  |                 @include($this->filepath); | 
					
						
							| 
									
										
										
										
											2016-03-11 01:07:26 +01:00
										 |  |  |                 if ($_smarty_tpl->mustCompile) { | 
					
						
							|  |  |  |                     $this->compileTemplateSource($_smarty_tpl); | 
					
						
							| 
									
										
										
										
											2016-05-15 11:13:31 +02:00
										 |  |  |                     $compileCheck = $smarty->compile_check; | 
					
						
							|  |  |  |                     $smarty->compile_check = false; | 
					
						
							| 
									
										
										
										
											2016-03-11 01:07:26 +01:00
										 |  |  |                     $this->loadCompiledTemplate($_smarty_tpl); | 
					
						
							| 
									
										
										
										
											2016-05-15 11:13:31 +02:00
										 |  |  |                     $smarty->compile_check = $compileCheck; | 
					
						
							| 
									
										
										
										
											2016-03-10 22:22:46 +01:00
										 |  |  |                 } | 
					
						
							| 
									
										
										
										
											2015-08-18 02:55:53 +02:00
										 |  |  |             } | 
					
						
							| 
									
										
										
										
											2016-03-11 01:07:26 +01:00
										 |  |  |             $_smarty_tpl->_subTemplateRegister(); | 
					
						
							| 
									
										
										
										
											2016-03-10 22:22:46 +01:00
										 |  |  |             $this->processed = true; | 
					
						
							| 
									
										
										
										
											2015-08-18 02:55:53 +02:00
										 |  |  |         } | 
					
						
							| 
									
										
										
										
											2015-01-01 23:28:09 +01:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-08-06 00:57:36 +02:00
										 |  |  |     /** | 
					
						
							|  |  |  |      * Load fresh compiled template by including the PHP file | 
					
						
							|  |  |  |      * HHVM requires a work around because of a PHP incompatibility | 
					
						
							|  |  |  |      * | 
					
						
							| 
									
										
										
										
											2016-05-15 11:13:31 +02:00
										 |  |  |      * @param \Smarty_Internal_Template $_smarty_tpl do not change variable name, is used by compiled template | 
					
						
							| 
									
										
										
										
											2015-08-06 00:57:36 +02:00
										 |  |  |      */ | 
					
						
							| 
									
										
										
										
											2016-03-11 01:07:26 +01:00
										 |  |  |     private function loadCompiledTemplate(Smarty_Internal_Template $_smarty_tpl) | 
					
						
							| 
									
										
										
										
											2015-08-06 00:57:36 +02:00
										 |  |  |     { | 
					
						
							| 
									
										
										
										
											2016-07-18 19:45:30 +02:00
										 |  |  |         if (function_exists('opcache_invalidate') && strlen(ini_get("opcache.restrict_api")) < 1) { | 
					
						
							| 
									
										
										
										
											2016-03-10 22:22:46 +01:00
										 |  |  |             opcache_invalidate($this->filepath, true); | 
					
						
							| 
									
										
										
										
											2015-12-25 10:29:29 +01:00
										 |  |  |         } elseif (function_exists('apc_compile_file')) { | 
					
						
							| 
									
										
										
										
											2016-03-10 22:22:46 +01:00
										 |  |  |             apc_compile_file($this->filepath); | 
					
						
							| 
									
										
										
										
											2015-08-06 00:57:36 +02:00
										 |  |  |         } | 
					
						
							| 
									
										
										
										
											2015-10-29 21:41:21 +01:00
										 |  |  |         if (defined('HHVM_VERSION')) { | 
					
						
							| 
									
										
										
										
											2016-03-10 22:22:46 +01:00
										 |  |  |             eval("?>" . file_get_contents($this->filepath)); | 
					
						
							| 
									
										
										
										
											2015-08-06 00:57:36 +02:00
										 |  |  |         } else { | 
					
						
							| 
									
										
										
										
											2016-03-10 22:22:46 +01:00
										 |  |  |             include($this->filepath); | 
					
						
							| 
									
										
										
										
											2015-08-06 00:57:36 +02:00
										 |  |  |         } | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-01-01 23:28:09 +01:00
										 |  |  |     /** | 
					
						
							|  |  |  |      * render compiled template code | 
					
						
							|  |  |  |      * | 
					
						
							|  |  |  |      * @param Smarty_Internal_Template $_template | 
					
						
							|  |  |  |      * | 
					
						
							|  |  |  |      * @return string | 
					
						
							|  |  |  |      * @throws Exception | 
					
						
							|  |  |  |      */ | 
					
						
							|  |  |  |     public function render(Smarty_Internal_Template $_template) | 
					
						
							|  |  |  |     { | 
					
						
							| 
									
										
										
										
											2016-08-05 21:29:15 +02:00
										 |  |  |         // checks if template exists
 | 
					
						
							|  |  |  |         if (!$_template->source->exists) { | 
					
						
							|  |  |  |             $type = $_template->source->isConfig ? 'config' : 'template'; | 
					
						
							|  |  |  |             throw new SmartyException("Unable to load {$type} '{$_template->source->type}:{$_template->source->name}'"); | 
					
						
							|  |  |  |         } | 
					
						
							| 
									
										
										
										
											2015-08-23 01:25:57 +02:00
										 |  |  |         if ($_template->smarty->debugging) { | 
					
						
							| 
									
										
										
										
											2016-07-13 01:07:53 +02:00
										 |  |  |             if (!isset($_template->smarty->_debug)) { | 
					
						
							|  |  |  |                 $_template->smarty->_debug = new Smarty_Internal_Debug(); | 
					
						
							|  |  |  |             } | 
					
						
							| 
									
										
										
										
											2015-08-23 01:25:57 +02:00
										 |  |  |             $_template->smarty->_debug->start_render($_template); | 
					
						
							|  |  |  |         } | 
					
						
							| 
									
										
										
										
											2015-01-01 23:28:09 +01:00
										 |  |  |         if (!$this->processed) { | 
					
						
							|  |  |  |             $this->process($_template); | 
					
						
							|  |  |  |         } | 
					
						
							| 
									
										
										
										
											2015-08-15 18:25:06 +02:00
										 |  |  |         if (isset($_template->cached)) { | 
					
						
							| 
									
										
										
										
											2015-09-01 02:27:22 +02:00
										 |  |  |             $_template->cached->file_dependency = | 
					
						
							|  |  |  |                 array_merge($_template->cached->file_dependency, $this->file_dependency); | 
					
						
							| 
									
										
										
										
											2015-08-09 20:43:04 +02:00
										 |  |  |         } | 
					
						
							| 
									
										
										
										
											2016-03-10 22:22:46 +01:00
										 |  |  |         if ($_template->source->handler->uncompiled) { | 
					
						
							|  |  |  |             $_template->source->handler->renderUncompiled($_template->source, $_template); | 
					
						
							|  |  |  |         } else { | 
					
						
							|  |  |  |             $this->getRenderedTemplateCode($_template); | 
					
						
							|  |  |  |         } | 
					
						
							| 
									
										
										
										
											2015-08-19 01:18:25 +02:00
										 |  |  |         if ($_template->caching && $this->has_nocache_code) { | 
					
						
							| 
									
										
										
										
											2016-02-09 01:27:15 +01:00
										 |  |  |             $_template->cached->hashes[ $this->nocache_hash ] = true; | 
					
						
							| 
									
										
										
										
											2015-08-19 01:18:25 +02:00
										 |  |  |         } | 
					
						
							| 
									
										
										
										
											2015-08-23 01:25:57 +02:00
										 |  |  |         if ($_template->smarty->debugging) { | 
					
						
							|  |  |  |             $_template->smarty->_debug->end_render($_template); | 
					
						
							|  |  |  |         } | 
					
						
							| 
									
										
										
										
											2015-01-01 23:28:09 +01:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     /** | 
					
						
							|  |  |  |      * compile template from source | 
					
						
							|  |  |  |      * | 
					
						
							|  |  |  |      * @param Smarty_Internal_Template $_template | 
					
						
							|  |  |  |      * | 
					
						
							|  |  |  |      * @throws Exception | 
					
						
							|  |  |  |      */ | 
					
						
							|  |  |  |     public function compileTemplateSource(Smarty_Internal_Template $_template) | 
					
						
							|  |  |  |     { | 
					
						
							| 
									
										
										
										
											2015-08-09 20:43:04 +02:00
										 |  |  |         $this->file_dependency = array(); | 
					
						
							| 
									
										
										
										
											2015-08-19 01:09:08 +02:00
										 |  |  |         $this->includes = array(); | 
					
						
							| 
									
										
										
										
											2015-08-09 20:43:04 +02:00
										 |  |  |         $this->nocache_hash = null; | 
					
						
							|  |  |  |         $this->unifunc = null; | 
					
						
							| 
									
										
										
										
											2015-01-01 23:28:09 +01:00
										 |  |  |         // compile locking
 | 
					
						
							| 
									
										
										
										
											2016-05-15 11:13:31 +02:00
										 |  |  |         if ($saved_timestamp = $this->getTimeStamp()) { | 
					
						
							|  |  |  |             touch($this->filepath); | 
					
						
							| 
									
										
										
										
											2015-01-01 23:28:09 +01:00
										 |  |  |         } | 
					
						
							|  |  |  |         // call compiler
 | 
					
						
							| 
									
										
										
										
											2016-05-15 11:13:31 +02:00
										 |  |  |         $_template->loadCompiler(); | 
					
						
							|  |  |  |         $this->write($_template, $_template->compiler->compileTemplate($_template)); | 
					
						
							| 
									
										
										
										
											2015-01-01 23:28:09 +01:00
										 |  |  |         // release compiler object to free memory
 | 
					
						
							|  |  |  |         unset($_template->compiler); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     /** | 
					
						
							|  |  |  |      * Write compiled code by handler | 
					
						
							|  |  |  |      * | 
					
						
							|  |  |  |      * @param Smarty_Internal_Template $_template template object | 
					
						
							|  |  |  |      * @param string                   $code      compiled code | 
					
						
							|  |  |  |      * | 
					
						
							|  |  |  |      * @return boolean success | 
					
						
							|  |  |  |      */ | 
					
						
							|  |  |  |     public function write(Smarty_Internal_Template $_template, $code) | 
					
						
							|  |  |  |     { | 
					
						
							| 
									
										
										
										
											2015-08-23 01:46:30 +02:00
										 |  |  |         if (!$_template->source->handler->recompiled) { | 
					
						
							| 
									
										
										
										
											2015-10-24 05:14:47 +02:00
										 |  |  |             if ($_template->smarty->ext->_writeFile->writeFile($this->filepath, $code, $_template->smarty) === true) { | 
					
						
							| 
									
										
										
										
											2015-05-05 00:41:30 +02:00
										 |  |  |                 $this->timestamp = $this->exists = is_file($this->filepath); | 
					
						
							| 
									
										
										
										
											2015-01-01 23:28:09 +01:00
										 |  |  |                 if ($this->exists) { | 
					
						
							| 
									
										
										
										
											2015-07-01 03:27:06 +02:00
										 |  |  |                     $this->timestamp = filemtime($this->filepath); | 
					
						
							| 
									
										
										
										
											2015-01-01 23:28:09 +01:00
										 |  |  |                     return true; | 
					
						
							|  |  |  |                 } | 
					
						
							| 
									
										
										
										
											2015-05-10 11:53:09 +02:00
										 |  |  |             } | 
					
						
							| 
									
										
										
										
											2015-01-01 23:28:09 +01:00
										 |  |  |             return false; | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |         return true; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     /** | 
					
						
							|  |  |  |      * Read compiled content from handler | 
					
						
							|  |  |  |      * | 
					
						
							|  |  |  |      * @param Smarty_Internal_Template $_template template object | 
					
						
							|  |  |  |      * | 
					
						
							|  |  |  |      * @return string content | 
					
						
							|  |  |  |      */ | 
					
						
							|  |  |  |     public function read(Smarty_Internal_Template $_template) | 
					
						
							|  |  |  |     { | 
					
						
							| 
									
										
										
										
											2015-08-23 01:46:30 +02:00
										 |  |  |         if (!$_template->source->handler->recompiled) { | 
					
						
							| 
									
										
										
										
											2015-01-01 23:28:09 +01:00
										 |  |  |             return file_get_contents($this->filepath); | 
					
						
							|  |  |  |         } | 
					
						
							| 
									
										
										
										
											2015-08-15 18:25:06 +02:00
										 |  |  |         return isset($this->content) ? $this->content : false; | 
					
						
							| 
									
										
										
										
											2015-07-01 03:27:06 +02:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2015-01-01 23:28:09 +01:00
										 |  |  | } |