| 
									
										
										
										
											2009-09-30 22:16:14 +00:00
										 |  |  | <?php | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /** | 
					
						
							| 
									
										
										
										
											2010-08-17 15:39:51 +00:00
										 |  |  |  * Smarty Internal Plugin Resource PHP | 
					
						
							|  |  |  |  * Implements the file system as resource for PHP templates | 
					
						
							| 
									
										
										
										
											2011-09-24 18:20:13 +00:00
										 |  |  |  * | 
					
						
							| 
									
										
										
										
											2014-06-06 02:40:04 +00:00
										 |  |  |  * @package    Smarty | 
					
						
							| 
									
										
										
										
											2010-08-17 15:39:51 +00:00
										 |  |  |  * @subpackage TemplateResources | 
					
						
							| 
									
										
										
										
											2014-06-06 02:40:04 +00:00
										 |  |  |  * @author     Uwe Tews | 
					
						
							|  |  |  |  * @author     Rodney Rehm | 
					
						
							| 
									
										
										
										
											2010-08-17 15:39:51 +00:00
										 |  |  |  */ | 
					
						
							| 
									
										
										
										
											2013-07-14 22:15:45 +00:00
										 |  |  | class Smarty_Internal_Resource_PHP extends Smarty_Resource_Uncompiled | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2009-09-30 22:16:14 +00:00
										 |  |  |     /** | 
					
						
							| 
									
										
										
										
											2011-09-16 14:19:56 +00:00
										 |  |  |      * container for short_open_tag directive's value before executing PHP templates | 
					
						
							| 
									
										
										
										
											2014-06-06 02:40:04 +00:00
										 |  |  |      * | 
					
						
							| 
									
										
										
										
											2011-09-16 14:19:56 +00:00
										 |  |  |      * @var string | 
					
						
							| 
									
										
										
										
											2010-08-17 15:39:51 +00:00
										 |  |  |      */ | 
					
						
							| 
									
										
										
										
											2011-09-16 14:19:56 +00:00
										 |  |  |     protected $short_open_tag; | 
					
						
							| 
									
										
										
										
											2011-09-24 18:20:13 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-10-05 18:55:22 +00:00
										 |  |  |     /** | 
					
						
							| 
									
										
										
										
											2011-09-16 14:19:56 +00:00
										 |  |  |      * Create a new PHP Resource | 
					
						
							| 
									
										
										
										
											2014-06-06 02:40:04 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-08-17 15:39:51 +00:00
										 |  |  |      */ | 
					
						
							| 
									
										
										
										
											2011-09-16 14:19:56 +00:00
										 |  |  |     public function __construct() | 
					
						
							| 
									
										
										
										
											2009-10-05 18:55:22 +00:00
										 |  |  |     { | 
					
						
							| 
									
										
										
										
											2014-06-06 02:40:04 +00:00
										 |  |  |         $this->short_open_tag = ini_get('short_open_tag'); | 
					
						
							| 
									
										
										
										
											2011-09-24 18:20:13 +00:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-09-30 22:16:14 +00:00
										 |  |  |     /** | 
					
						
							| 
									
										
										
										
											2011-09-16 14:19:56 +00:00
										 |  |  |      * populate Source Object with meta data from Resource | 
					
						
							|  |  |  |      * | 
					
						
							| 
									
										
										
										
											2013-07-14 22:15:45 +00:00
										 |  |  |      * @param  Smarty_Template_Source   $source    source object | 
					
						
							|  |  |  |      * @param  Smarty_Internal_Template $_template template object | 
					
						
							| 
									
										
										
										
											2014-06-06 02:40:04 +00:00
										 |  |  |      * | 
					
						
							| 
									
										
										
										
											2011-09-16 14:19:56 +00:00
										 |  |  |      * @return void | 
					
						
							| 
									
										
										
										
											2010-08-17 15:39:51 +00:00
										 |  |  |      */ | 
					
						
							| 
									
										
										
										
											2014-06-06 02:40:04 +00:00
										 |  |  |     public function populate(Smarty_Template_Source $source, Smarty_Internal_Template $_template = null) | 
					
						
							| 
									
										
										
										
											2009-09-30 22:16:14 +00:00
										 |  |  |     { | 
					
						
							| 
									
										
										
										
											2011-09-16 14:19:56 +00:00
										 |  |  |         $source->filepath = $this->buildFilepath($source, $_template); | 
					
						
							| 
									
										
										
										
											2009-09-30 22:16:14 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-09-16 14:19:56 +00:00
										 |  |  |         if ($source->filepath !== false) { | 
					
						
							|  |  |  |             if (is_object($source->smarty->security_policy)) { | 
					
						
							|  |  |  |                 $source->smarty->security_policy->isTrustedResourceDir($source->filepath); | 
					
						
							|  |  |  |             } | 
					
						
							| 
									
										
										
										
											2011-09-24 18:20:13 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-09-16 14:19:56 +00:00
										 |  |  |             $source->uid = sha1($source->filepath); | 
					
						
							|  |  |  |             if ($source->smarty->compile_check) { | 
					
						
							|  |  |  |                 $source->timestamp = @filemtime($source->filepath); | 
					
						
							|  |  |  |                 $source->exists = !!$source->timestamp; | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2011-09-24 18:20:13 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-09-30 22:16:14 +00:00
										 |  |  |     /** | 
					
						
							| 
									
										
										
										
											2011-09-16 14:19:56 +00:00
										 |  |  |      * populate Source Object with timestamp and exists from Resource | 
					
						
							|  |  |  |      * | 
					
						
							| 
									
										
										
										
											2013-07-14 22:15:45 +00:00
										 |  |  |      * @param  Smarty_Template_Source $source source object | 
					
						
							| 
									
										
										
										
											2014-06-06 02:40:04 +00:00
										 |  |  |      * | 
					
						
							| 
									
										
										
										
											2011-09-16 14:19:56 +00:00
										 |  |  |      * @return void | 
					
						
							| 
									
										
										
										
											2010-08-17 15:39:51 +00:00
										 |  |  |      */ | 
					
						
							| 
									
										
										
										
											2011-09-16 14:19:56 +00:00
										 |  |  |     public function populateTimestamp(Smarty_Template_Source $source) | 
					
						
							| 
									
										
										
										
											2009-09-30 22:16:14 +00:00
										 |  |  |     { | 
					
						
							| 
									
										
										
										
											2011-09-16 14:19:56 +00:00
										 |  |  |         $source->timestamp = @filemtime($source->filepath); | 
					
						
							|  |  |  |         $source->exists = !!$source->timestamp; | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2009-09-30 22:16:14 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |     /** | 
					
						
							| 
									
										
										
										
											2011-09-16 14:19:56 +00:00
										 |  |  |      * Load template's source from file into current template object | 
					
						
							| 
									
										
										
										
											2011-09-24 18:20:13 +00:00
										 |  |  |      * | 
					
						
							| 
									
										
										
										
											2013-07-14 22:15:45 +00:00
										 |  |  |      * @param  Smarty_Template_Source $source source object | 
					
						
							| 
									
										
										
										
											2014-06-06 02:40:04 +00:00
										 |  |  |      * | 
					
						
							| 
									
										
										
										
											2013-07-14 22:15:45 +00:00
										 |  |  |      * @return string                 template source | 
					
						
							|  |  |  |      * @throws SmartyException        if source cannot be loaded | 
					
						
							| 
									
										
										
										
											2010-08-17 15:39:51 +00:00
										 |  |  |      */ | 
					
						
							| 
									
										
										
										
											2011-09-16 14:19:56 +00:00
										 |  |  |     public function getContent(Smarty_Template_Source $source) | 
					
						
							| 
									
										
										
										
											2009-09-30 22:16:14 +00:00
										 |  |  |     { | 
					
						
							| 
									
										
										
										
											2011-09-16 14:19:56 +00:00
										 |  |  |         if ($source->timestamp) { | 
					
						
							|  |  |  |             return ''; | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |         throw new SmartyException("Unable to read template {$source->type} '{$source->name}'"); | 
					
						
							| 
									
										
										
										
											2011-09-24 18:20:13 +00:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2009-09-30 22:16:14 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |     /** | 
					
						
							| 
									
										
										
										
											2011-09-16 14:19:56 +00:00
										 |  |  |      * Render and output the template (without using the compiler) | 
					
						
							|  |  |  |      * | 
					
						
							| 
									
										
										
										
											2013-07-14 22:15:45 +00:00
										 |  |  |      * @param  Smarty_Template_Source   $source    source object | 
					
						
							|  |  |  |      * @param  Smarty_Internal_Template $_template template object | 
					
						
							| 
									
										
										
										
											2014-06-06 02:40:04 +00:00
										 |  |  |      * | 
					
						
							| 
									
										
										
										
											2011-09-16 14:19:56 +00:00
										 |  |  |      * @return void | 
					
						
							| 
									
										
										
										
											2013-07-14 22:15:45 +00:00
										 |  |  |      * @throws SmartyException          if template cannot be loaded or allow_php_templates is disabled | 
					
						
							| 
									
										
										
										
											2010-08-17 15:39:51 +00:00
										 |  |  |      */ | 
					
						
							| 
									
										
										
										
											2011-09-16 14:19:56 +00:00
										 |  |  |     public function renderUncompiled(Smarty_Template_Source $source, Smarty_Internal_Template $_template) | 
					
						
							| 
									
										
										
										
											2009-09-30 22:16:14 +00:00
										 |  |  |     { | 
					
						
							| 
									
										
										
										
											2011-09-16 14:19:56 +00:00
										 |  |  |         if (!$source->smarty->allow_php_templates) { | 
					
						
							| 
									
										
										
										
											2010-08-13 10:39:51 +00:00
										 |  |  |             throw new SmartyException("PHP templates are disabled"); | 
					
						
							| 
									
										
										
										
											2011-09-24 18:20:13 +00:00
										 |  |  |         } | 
					
						
							| 
									
										
										
										
											2011-09-16 14:19:56 +00:00
										 |  |  |         if (!$source->exists) { | 
					
						
							| 
									
										
										
										
											2011-09-24 18:20:13 +00:00
										 |  |  |             if ($_template->parent instanceof Smarty_Internal_Template) { | 
					
						
							|  |  |  |                 $parent_resource = " in '{$_template->parent->template_resource}'"; | 
					
						
							|  |  |  |             } else { | 
					
						
							|  |  |  |                 $parent_resource = ''; | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |             throw new SmartyException("Unable to load template {$source->type} '{$source->name}'{$parent_resource}"); | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-09-30 22:16:14 +00:00
										 |  |  |         // prepare variables
 | 
					
						
							| 
									
										
										
										
											2011-09-16 14:19:56 +00:00
										 |  |  |         extract($_template->getTemplateVars()); | 
					
						
							| 
									
										
										
										
											2011-09-24 18:20:13 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-09-16 14:19:56 +00:00
										 |  |  |         // include PHP template with short open tags enabled
 | 
					
						
							| 
									
										
										
										
											2014-06-06 02:40:04 +00:00
										 |  |  |         ini_set('short_open_tag', '1'); | 
					
						
							|  |  |  |         /** @var Smarty_Internal_Template $_smarty_template | 
					
						
							|  |  |  |          * used in included file | 
					
						
							|  |  |  |          */ | 
					
						
							|  |  |  |         $_smarty_template = $_template; | 
					
						
							| 
									
										
										
										
											2011-09-16 14:19:56 +00:00
										 |  |  |         include($source->filepath); | 
					
						
							| 
									
										
										
										
											2014-06-06 02:40:04 +00:00
										 |  |  |         ini_set('short_open_tag', $this->short_open_tag); | 
					
						
							| 
									
										
										
										
											2011-09-24 18:20:13 +00:00
										 |  |  |     } | 
					
						
							|  |  |  | } |