| 
									
										
										
										
											2009-03-22 16:09:05 +00:00
										 |  |  | <?php | 
					
						
							|  |  |  | /** | 
					
						
							| 
									
										
										
										
											2010-08-17 15:39:51 +00:00
										 |  |  |  * Smarty Internal Plugin Resource File | 
					
						
							| 
									
										
										
										
											2011-09-16 14:19:56 +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
										 |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-09-16 14:19:56 +00:00
										 |  |  | /** | 
					
						
							| 
									
										
										
										
											2010-08-17 15:39:51 +00:00
										 |  |  |  * Smarty Internal Plugin Resource File | 
					
						
							| 
									
										
										
										
											2011-09-16 14:19:56 +00:00
										 |  |  |  * Implements the file system as resource for Smarty templates | 
					
						
							|  |  |  |  * | 
					
						
							| 
									
										
										
										
											2014-06-06 02:40:04 +00:00
										 |  |  |  * @package    Smarty | 
					
						
							| 
									
										
										
										
											2011-09-16 14:19:56 +00:00
										 |  |  |  * @subpackage TemplateResources | 
					
						
							| 
									
										
										
										
											2010-08-17 15:39:51 +00:00
										 |  |  |  */ | 
					
						
							| 
									
										
										
										
											2013-07-14 22:15:45 +00:00
										 |  |  | class Smarty_Internal_Resource_File extends Smarty_Resource | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2015-01-01 23:34:29 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |     /** | 
					
						
							|  |  |  |      * build template filepath by traversing the template_dir array | 
					
						
							|  |  |  |      * | 
					
						
							|  |  |  |      * @param Smarty_Template_Source    $source    source object | 
					
						
							|  |  |  |      * @param  Smarty_Internal_Template $_template template object | 
					
						
							|  |  |  |      * | 
					
						
							|  |  |  |      * @return string fully qualified filepath | 
					
						
							|  |  |  |      * @throws SmartyException | 
					
						
							|  |  |  |      */ | 
					
						
							|  |  |  |     protected function buildFilepath(Smarty_Template_Source $source, Smarty_Internal_Template $_template = null) | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         $file = str_replace(array('\\', '/./'), '/', $source->name); | 
					
						
							|  |  |  |         if ($source->isConfig) { | 
					
						
							|  |  |  |             $_directories = $source->smarty->getConfigDir(); | 
					
						
							|  |  |  |         } else { | 
					
						
							|  |  |  |             $_directories = $source->smarty->getTemplateDir(); | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |         preg_match('#^((?P<absolute>[\/]|[a-zA-Z]:[\/])|(\[(?P<index>[^\]]+)\])|((?P<rel1>\.[\/])?(?P<rel2>(\.\.[\/])*))|(?P<skip>[\/]))?(?P<file>.+)$#', $file, $fileMatch); | 
					
						
							| 
									
										
										
										
											2015-01-03 21:27:33 +01:00
										 |  |  |         // save basename
 | 
					
						
							| 
									
										
										
										
											2015-01-04 05:51:03 +01:00
										 |  |  |         if (!empty($fileMatch['absolute'])) { | 
					
						
							|  |  |  |             return is_file($file) ? $file : false; | 
					
						
							|  |  |  |         } | 
					
						
							| 
									
										
										
										
											2015-01-01 23:34:29 +01:00
										 |  |  |         // go relative to a given template?
 | 
					
						
							|  |  |  |         if ($_template && $_template->parent instanceof Smarty_Internal_Template && (!empty($fileMatch['rel1']) || !empty($fileMatch['rel2']))) { | 
					
						
							|  |  |  |             if ($_template->parent->source->type != 'file' && $_template->parent->source->type != 'extends' && !$_template->parent->allow_relative_path) { | 
					
						
							|  |  |  |                 throw new SmartyException("Template '{$file}' cannot be relative to template of resource type '{$_template->parent->source->type}'"); | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |             $path = dirname($_template->parent->source->filepath); | 
					
						
							|  |  |  |             if (!preg_match('/^([\/\\\\]|[a-zA-Z]:[\/\\\\])/', $path)) { | 
					
						
							|  |  |  |                 // the path gained from the parent template is relative to the current working directory
 | 
					
						
							|  |  |  |                 // as expansions (like include_path) have already been done
 | 
					
						
							| 
									
										
										
										
											2015-01-02 06:26:04 +01:00
										 |  |  |                 $path = str_replace('\\', '/', getcwd()) . '/' . $path; | 
					
						
							| 
									
										
										
										
											2015-01-01 23:34:29 +01:00
										 |  |  |             } | 
					
						
							|  |  |  |             // normalize path
 | 
					
						
							|  |  |  |             $path = str_replace(array('\\', './'), array('/', ''), $path); | 
					
						
							|  |  |  |             // simple relative
 | 
					
						
							|  |  |  |             if (!empty($fileMatch['rel1'])) { | 
					
						
							|  |  |  |                 $file = $path . '/' . $fileMatch['file']; | 
					
						
							|  |  |  |             } else { | 
					
						
							|  |  |  |                 for ($i = 1; $i <= substr_count($fileMatch['rel2'], '../'); $i ++) { | 
					
						
							|  |  |  |                     $path = substr($path, 0, strrpos($path, '/')); | 
					
						
							|  |  |  |                 } | 
					
						
							|  |  |  |                 $file = $path . '/' . $fileMatch['file']; | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |             // files relative to a template only get one shot
 | 
					
						
							| 
									
										
										
										
											2015-01-03 21:27:33 +01:00
										 |  |  |             return is_file($file) ? $file : false; | 
					
						
							| 
									
										
										
										
											2015-01-01 23:34:29 +01:00
										 |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         $_filepath = null; | 
					
						
							|  |  |  |         // template_dir index?
 | 
					
						
							|  |  |  |         if (!empty($fileMatch['index'])) { | 
					
						
							|  |  |  |             $index = $fileMatch['index']; | 
					
						
							|  |  |  |             $_directory = null; | 
					
						
							|  |  |  |             // try string indexes
 | 
					
						
							|  |  |  |             if (isset($_directories[$index])) { | 
					
						
							|  |  |  |                 $_directory = $_directories[$index]; | 
					
						
							|  |  |  |             } elseif (is_numeric($index)) { | 
					
						
							|  |  |  |                 // try numeric index
 | 
					
						
							|  |  |  |                 $index = (int) $index; | 
					
						
							|  |  |  |                 if (isset($_directories[$index])) { | 
					
						
							|  |  |  |                     $_directory = $_directories[$index]; | 
					
						
							|  |  |  |                 } else { | 
					
						
							|  |  |  |                     // try at location index
 | 
					
						
							|  |  |  |                     $keys = array_keys($_directories); | 
					
						
							|  |  |  |                     $_directory = $_directories[$keys[$index]]; | 
					
						
							|  |  |  |                 } | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |             if ($_directory) { | 
					
						
							|  |  |  |                 $_filepath = $_directory . $fileMatch['file']; | 
					
						
							| 
									
										
										
										
											2015-01-03 21:27:33 +01:00
										 |  |  |                 if (is_file($_filepath)) { | 
					
						
							| 
									
										
										
										
											2015-01-01 23:34:29 +01:00
										 |  |  |                     return $_filepath; | 
					
						
							|  |  |  |                 } | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         // relative file name?
 | 
					
						
							| 
									
										
										
										
											2015-01-04 05:51:03 +01:00
										 |  |  |         foreach ($_directories as $_directory) { | 
					
						
							|  |  |  |             if (empty($fileMatch['rel2'])) { | 
					
						
							|  |  |  |                 $_filepath = $_directory . $fileMatch['file']; | 
					
						
							|  |  |  |             } else { | 
					
						
							|  |  |  |                 if (false === strpos($_directory, '..')) { | 
					
						
							|  |  |  |                     for ($i = 1; $i <= substr_count($fileMatch['rel2'], '../') + 1; $i ++) { | 
					
						
							|  |  |  |                         $_directory = substr($_directory, 0, strrpos($_directory, '/')); | 
					
						
							| 
									
										
										
										
											2015-01-03 21:27:33 +01:00
										 |  |  |                     } | 
					
						
							| 
									
										
										
										
											2015-01-04 05:51:03 +01:00
										 |  |  |                     $_filepath = $_directory . '/' . $fileMatch['file']; | 
					
						
							|  |  |  |                 } else { | 
					
						
							|  |  |  |                     $_filepath = $_directory . $file; | 
					
						
							| 
									
										
										
										
											2015-01-01 23:34:29 +01:00
										 |  |  |                 } | 
					
						
							| 
									
										
										
										
											2015-01-04 05:51:03 +01:00
										 |  |  |             } | 
					
						
							|  |  |  |             if (is_file($_filepath)) { | 
					
						
							|  |  |  |                 return $_filepath; | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |             if ($source->smarty->use_include_path && !preg_match('/^([\/\\\\]|[a-zA-Z]:[\/\\\\])/', $_directory)) { | 
					
						
							|  |  |  |                 // try PHP include_path
 | 
					
						
							|  |  |  |                 if (function_exists('stream_resolve_include_path')) { | 
					
						
							|  |  |  |                     $_filepath = stream_resolve_include_path($_filepath); | 
					
						
							|  |  |  |                 } else { | 
					
						
							|  |  |  |                     $_filepath = Smarty_Internal_Get_Include_Path::getIncludePath($_filepath); | 
					
						
							| 
									
										
										
										
											2015-01-01 23:34:29 +01:00
										 |  |  |                 } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-01-04 05:51:03 +01:00
										 |  |  |                 if ($_filepath !== false) { | 
					
						
							|  |  |  |                     if (is_file($_filepath)) { | 
					
						
							|  |  |  |                         return $_filepath; | 
					
						
							| 
									
										
										
										
											2015-01-01 23:34:29 +01:00
										 |  |  |                     } | 
					
						
							|  |  |  |                 } | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |         // Could be relative to cwd
 | 
					
						
							| 
									
										
										
										
											2015-01-02 06:26:04 +01:00
										 |  |  |         $path = str_replace('\\', '/', getcwd()); | 
					
						
							|  |  |  |         if (empty($fileMatch['rel2'])) { | 
					
						
							|  |  |  |             $file = $path . '/' . $fileMatch['file']; | 
					
						
							| 
									
										
										
										
											2015-01-01 23:34:29 +01:00
										 |  |  |         } else { | 
					
						
							|  |  |  |             for ($i = 1; $i <= substr_count($fileMatch['rel2'], '../'); $i ++) { | 
					
						
							|  |  |  |                 $path = substr($path, 0, strrpos($path, '/')); | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |             $file = $path . '/' . $fileMatch['file']; | 
					
						
							|  |  |  |         } | 
					
						
							| 
									
										
										
										
											2015-01-03 21:27:33 +01:00
										 |  |  |         return is_file($file) ? $file : false; | 
					
						
							| 
									
										
										
										
											2015-01-01 23:34:29 +01:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     /** | 
					
						
							|  |  |  |      * test is file exists and save timestamp | 
					
						
							|  |  |  |      * | 
					
						
							|  |  |  |      * @param  Smarty_Template_Source $source source object | 
					
						
							|  |  |  |      * @param  string                 $file   file name | 
					
						
							|  |  |  |      * | 
					
						
							|  |  |  |      * @return bool                   true if file exists | 
					
						
							|  |  |  |      */ | 
					
						
							|  |  |  |     protected function fileExists(Smarty_Template_Source $source, $file) | 
					
						
							|  |  |  |     { | 
					
						
							| 
									
										
										
										
											2015-01-03 21:27:33 +01:00
										 |  |  |         $source->timestamp = is_file($file) ? @filemtime($file) : false; | 
					
						
							|  |  |  |         return $source->exists = !!$source->timestamp; | 
					
						
							| 
									
										
										
										
											2015-01-01 23:34:29 +01:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-09-30 18:28:50 +00:00
										 |  |  |     /** | 
					
						
							| 
									
										
										
										
											2011-09-16 14:19:56 +00:00
										 |  |  |      * populate Source Object with meta data from Resource | 
					
						
							|  |  |  |      * | 
					
						
							| 
									
										
										
										
											2015-01-04 05:51:03 +01:00
										 |  |  |      * @param Smarty_Template_Source   $source    source object | 
					
						
							| 
									
										
										
										
											2011-09-16 14:19:56 +00:00
										 |  |  |      * @param Smarty_Internal_Template $_template template object | 
					
						
							| 
									
										
										
										
											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 18:28:50 +00:00
										 |  |  |     { | 
					
						
							| 
									
										
										
										
											2011-09-16 14:19:56 +00:00
										 |  |  |         $source->filepath = $this->buildFilepath($source, $_template); | 
					
						
							| 
									
										
										
										
											2009-09-30 18:28:50 +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); | 
					
						
							|  |  |  |             } | 
					
						
							| 
									
										
										
										
											2009-03-22 16:09:05 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-01-01 23:34:29 +01:00
										 |  |  |             $source->uid = sha1(getcwd() . $source->filepath); | 
					
						
							| 
									
										
										
										
											2011-09-16 14:19:56 +00:00
										 |  |  |             if ($source->smarty->compile_check && !isset($source->timestamp)) { | 
					
						
							| 
									
										
										
										
											2015-05-05 00:41:30 +02:00
										 |  |  |                 $source->timestamp = $source->exists = is_file($source->filepath); | 
					
						
							|  |  |  |                 if ($source->exists) { | 
					
						
							|  |  |  |                     $source->timestamp = @filemtime($source->filepath); | 
					
						
							|  |  |  |                 } | 
					
						
							| 
									
										
										
										
											2011-09-16 14:19:56 +00:00
										 |  |  |             } | 
					
						
							| 
									
										
										
										
											2015-01-03 21:27:33 +01:00
										 |  |  |         } else { | 
					
						
							|  |  |  |             $source->timestamp = false; | 
					
						
							|  |  |  |             $source->exists = false; | 
					
						
							| 
									
										
										
										
											2011-09-16 14:19:56 +00:00
										 |  |  |         } | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2009-03-22 16:09:05 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |     /** | 
					
						
							| 
									
										
										
										
											2011-09-16 14:19:56 +00:00
										 |  |  |      * populate Source Object with timestamp and exists from Resource | 
					
						
							|  |  |  |      * | 
					
						
							|  |  |  |      * @param Smarty_Template_Source $source source object | 
					
						
							| 
									
										
										
										
											2010-08-17 15:39:51 +00:00
										 |  |  |      */ | 
					
						
							| 
									
										
										
										
											2011-09-16 14:19:56 +00:00
										 |  |  |     public function populateTimestamp(Smarty_Template_Source $source) | 
					
						
							| 
									
										
										
										
											2009-03-22 16:09:05 +00:00
										 |  |  |     { | 
					
						
							| 
									
										
										
										
											2015-05-05 00:41:30 +02:00
										 |  |  |         $source->timestamp = $source->exists = is_file($source->filepath); | 
					
						
							|  |  |  |         if ($source->exists) { | 
					
						
							|  |  |  |             $source->timestamp = @filemtime($source->filepath); | 
					
						
							|  |  |  |         } | 
					
						
							| 
									
										
										
										
											2011-09-16 14:19:56 +00:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2009-03-22 16:09:05 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |     /** | 
					
						
							| 
									
										
										
										
											2011-09-16 14:19:56 +00:00
										 |  |  |      * Load template's source from file into current template object | 
					
						
							|  |  |  |      * | 
					
						
							| 
									
										
										
										
											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) | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         if ($source->timestamp) { | 
					
						
							|  |  |  |             return file_get_contents($source->filepath); | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |         if ($source instanceof Smarty_Config_Source) { | 
					
						
							|  |  |  |             throw new SmartyException("Unable to read config {$source->type} '{$source->name}'"); | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |         throw new SmartyException("Unable to read template {$source->type} '{$source->name}'"); | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2009-03-22 16:09:05 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |     /** | 
					
						
							| 
									
										
										
										
											2011-09-16 14:19:56 +00:00
										 |  |  |      * Determine basename for compiled filename | 
					
						
							|  |  |  |      * | 
					
						
							| 
									
										
										
										
											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                 resource's basename | 
					
						
							| 
									
										
										
										
											2010-08-17 15:39:51 +00:00
										 |  |  |      */ | 
					
						
							| 
									
										
										
										
											2011-09-16 14:19:56 +00:00
										 |  |  |     public function getBasename(Smarty_Template_Source $source) | 
					
						
							| 
									
										
										
										
											2010-01-05 21:10:25 +00:00
										 |  |  |     { | 
					
						
							| 
									
										
										
										
											2015-01-04 05:51:03 +01:00
										 |  |  |         return basename($source->filepath); | 
					
						
							| 
									
										
										
										
											2011-09-16 14:19:56 +00:00
										 |  |  |     } | 
					
						
							|  |  |  | } |