| 
									
										
										
										
											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) | 
					
						
							|  |  |  |     { | 
					
						
							| 
									
										
										
										
											2015-06-14 03:30:31 +02:00
										 |  |  |         $file = $source->name; | 
					
						
							| 
									
										
										
										
											2015-06-28 12:54:47 +02:00
										 |  |  |         // absolute file ?
 | 
					
						
							| 
									
										
										
										
											2016-02-09 01:27:15 +01:00
										 |  |  |         if ($file[ 0 ] == '/' || $file[ 1 ] == ':') { | 
					
						
							| 
									
										
										
										
											2015-07-07 17:56:50 +02:00
										 |  |  |             $file = $source->smarty->_realpath($file, true); | 
					
						
							| 
									
										
										
										
											2015-01-04 05:51:03 +01:00
										 |  |  |             return is_file($file) ? $file : false; | 
					
						
							|  |  |  |         } | 
					
						
							| 
									
										
										
										
											2015-01-01 23:34:29 +01:00
										 |  |  |         // go relative to a given template?
 | 
					
						
							| 
									
										
										
										
											2016-09-11 04:35:52 +02:00
										 |  |  |         if ($file[ 0 ] == '.' && $_template && $_template->_isSubTpl() && | 
					
						
							| 
									
										
										
										
											2015-07-07 17:56:50 +02:00
										 |  |  |             preg_match('#^[.]{1,2}[\\\/]#', $file) | 
					
						
							|  |  |  |         ) { | 
					
						
							|  |  |  |             if ($_template->parent->source->type != 'file' && $_template->parent->source->type != 'extends' && | 
					
						
							| 
									
										
										
										
											2016-02-09 01:27:15 +01:00
										 |  |  |                 !isset($_template->parent->_cache[ 'allow_relative_path' ]) | 
					
						
							| 
									
										
										
										
											2015-07-07 17:56:50 +02:00
										 |  |  |             ) { | 
					
						
							| 
									
										
										
										
											2015-01-01 23:34:29 +01:00
										 |  |  |                 throw new SmartyException("Template '{$file}' cannot be relative to template of resource type '{$_template->parent->source->type}'"); | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |             // normalize path
 | 
					
						
							| 
									
										
										
										
											2016-08-23 08:03:39 +02:00
										 |  |  |             $path = $source->smarty->_realpath(dirname($_template->parent->source->filepath) . $source->smarty->ds . $file); | 
					
						
							| 
									
										
										
										
											2015-01-01 23:34:29 +01:00
										 |  |  |             // files relative to a template only get one shot
 | 
					
						
							| 
									
										
										
										
											2015-06-14 03:30:31 +02:00
										 |  |  |             return is_file($path) ? $path : false; | 
					
						
							| 
									
										
										
										
											2015-01-01 23:34:29 +01:00
										 |  |  |         } | 
					
						
							| 
									
										
										
										
											2016-08-23 08:03:39 +02:00
										 |  |  |         // normalize $source->smarty->ds
 | 
					
						
							|  |  |  |         if (strpos($file, $source->smarty->ds == '/' ? '\\' : '/') !== false) { | 
					
						
							|  |  |  |             $file = str_replace($source->smarty->ds == '/' ? '\\' : '/', $source->smarty->ds, $file); | 
					
						
							| 
									
										
										
										
											2015-10-18 04:40:45 +02:00
										 |  |  |         } | 
					
						
							| 
									
										
										
										
											2015-01-01 23:34:29 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-06-29 02:41:42 +02:00
										 |  |  |         $_directories = $source->smarty->getTemplateDir(null, $source->isConfig); | 
					
						
							| 
									
										
										
										
											2015-01-01 23:34:29 +01:00
										 |  |  |         // template_dir index?
 | 
					
						
							| 
									
										
										
										
											2016-02-09 01:27:15 +01:00
										 |  |  |         if ($file[ 0 ] == '[' && preg_match('#^\[([^\]]+)\](.+)$#', $file, $fileMatch)) { | 
					
						
							|  |  |  |             $file = $fileMatch[ 2 ]; | 
					
						
							|  |  |  |             $_indices = explode(',', $fileMatch[ 1 ]); | 
					
						
							| 
									
										
										
										
											2015-07-07 18:18:19 +02:00
										 |  |  |             $_index_dirs = array(); | 
					
						
							|  |  |  |             foreach ($_indices as $index) { | 
					
						
							|  |  |  |                 $index = trim($index); | 
					
						
							|  |  |  |                 // try string indexes
 | 
					
						
							| 
									
										
										
										
											2016-02-09 01:27:15 +01:00
										 |  |  |                 if (isset($_directories[ $index ])) { | 
					
						
							|  |  |  |                     $_index_dirs[] = $_directories[ $index ]; | 
					
						
							| 
									
										
										
										
											2015-07-07 18:18:19 +02:00
										 |  |  |                 } elseif (is_numeric($index)) { | 
					
						
							|  |  |  |                     // try numeric index
 | 
					
						
							|  |  |  |                     $index = (int) $index; | 
					
						
							| 
									
										
										
										
											2016-02-09 01:27:15 +01:00
										 |  |  |                     if (isset($_directories[ $index ])) { | 
					
						
							|  |  |  |                         $_index_dirs[] = $_directories[ $index ]; | 
					
						
							| 
									
										
										
										
											2015-07-07 18:18:19 +02:00
										 |  |  |                     } else { | 
					
						
							|  |  |  |                         // try at location index
 | 
					
						
							|  |  |  |                         $keys = array_keys($_directories); | 
					
						
							| 
									
										
										
										
											2016-02-09 01:27:15 +01:00
										 |  |  |                         if (isset($_directories[ $keys[ $index ] ])) { | 
					
						
							|  |  |  |                             $_index_dirs[] = $_directories[ $keys[ $index ] ]; | 
					
						
							| 
									
										
										
										
											2015-07-07 18:18:19 +02:00
										 |  |  |                         } | 
					
						
							|  |  |  |                     } | 
					
						
							| 
									
										
										
										
											2015-01-01 23:34:29 +01:00
										 |  |  |                 } | 
					
						
							|  |  |  |             } | 
					
						
							| 
									
										
										
										
											2015-07-07 18:18:19 +02:00
										 |  |  |             if (empty($_index_dirs)) { | 
					
						
							| 
									
										
										
										
											2015-06-14 03:30:31 +02:00
										 |  |  |                 // index not found
 | 
					
						
							|  |  |  |                 return false; | 
					
						
							| 
									
										
										
										
											2015-07-07 18:18:19 +02:00
										 |  |  |             } else { | 
					
						
							|  |  |  |                 $_directories = $_index_dirs; | 
					
						
							| 
									
										
										
										
											2015-01-01 23:34:29 +01:00
										 |  |  |             } | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         // relative file name?
 | 
					
						
							| 
									
										
										
										
											2015-01-04 05:51:03 +01:00
										 |  |  |         foreach ($_directories as $_directory) { | 
					
						
							| 
									
										
										
										
											2015-06-29 02:41:42 +02:00
										 |  |  |             $path = $_directory . $file; | 
					
						
							| 
									
										
										
										
											2015-06-14 03:30:31 +02:00
										 |  |  |             if (is_file($path)) { | 
					
						
							| 
									
										
										
										
											2016-08-23 08:03:39 +02:00
										 |  |  |                 return (strpos($path, '.' . $source->smarty->ds) !== false) ? $source->smarty->_realpath($path) : $path; | 
					
						
							| 
									
										
										
										
											2015-01-01 23:34:29 +01:00
										 |  |  |             } | 
					
						
							|  |  |  |         } | 
					
						
							| 
									
										
										
										
											2015-07-07 18:18:19 +02:00
										 |  |  |         if (!isset($_index_dirs)) { | 
					
						
							|  |  |  |             // Could be relative to cwd
 | 
					
						
							|  |  |  |             $path = $source->smarty->_realpath($file, true); | 
					
						
							|  |  |  |             if (is_file($path)) { | 
					
						
							|  |  |  |                 return $path; | 
					
						
							|  |  |  |             } | 
					
						
							| 
									
										
										
										
											2015-06-29 02:41:42 +02:00
										 |  |  |         } | 
					
						
							|  |  |  |         // Use include path ?
 | 
					
						
							|  |  |  |         if ($source->smarty->use_include_path) { | 
					
						
							| 
									
										
										
										
											2015-10-24 05:02:24 +02:00
										 |  |  |             return $source->smarty->ext->_getIncludePath->getIncludePath($_directories, $file, $source->smarty); | 
					
						
							| 
									
										
										
										
											2015-06-29 02:41:42 +02:00
										 |  |  |         } | 
					
						
							|  |  |  |         return false; | 
					
						
							| 
									
										
										
										
											2015-06-14 03:30:31 +02:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-08-23 01:50:05 +02: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) { | 
					
						
							| 
									
										
										
										
											2015-09-01 02:52:09 +02:00
										 |  |  |             if (isset($source->smarty->security_policy) && is_object($source->smarty->security_policy)) { | 
					
						
							| 
									
										
										
										
											2015-06-28 02:37:41 +02:00
										 |  |  |                 $source->smarty->security_policy->isTrustedResourceDir($source->filepath, $source->isConfig); | 
					
						
							| 
									
										
										
										
											2011-09-16 14:19:56 +00:00
										 |  |  |             } | 
					
						
							| 
									
										
										
										
											2015-06-14 03:30:31 +02:00
										 |  |  |             $source->exists = true; | 
					
						
							| 
									
										
										
										
											2016-02-09 01:27:15 +01:00
										 |  |  |             $source->uid = sha1($source->filepath . ($source->isConfig ? $source->smarty->_joined_config_dir : | 
					
						
							|  |  |  |                                     $source->smarty->_joined_template_dir)); | 
					
						
							| 
									
										
										
										
											2016-05-15 11:13:31 +02:00
										 |  |  |             $source->timestamp = filemtime($source->filepath); | 
					
						
							| 
									
										
										
										
											2015-01-03 21:27:33 +01:00
										 |  |  |         } else { | 
					
						
							| 
									
										
										
										
											2016-05-15 11:13:31 +02:00
										 |  |  |             $source->timestamp = $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-07-01 03:27:06 +02:00
										 |  |  |         if (!$source->exists) { | 
					
						
							|  |  |  |             $source->timestamp = $source->exists = is_file($source->filepath); | 
					
						
							|  |  |  |         } | 
					
						
							| 
									
										
										
										
											2015-05-05 00:41:30 +02:00
										 |  |  |         if ($source->exists) { | 
					
						
							| 
									
										
										
										
											2015-07-01 03:27:06 +02:00
										 |  |  |             $source->timestamp = filemtime($source->filepath); | 
					
						
							| 
									
										
										
										
											2015-05-05 00:41:30 +02:00
										 |  |  |         } | 
					
						
							| 
									
										
										
										
											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) | 
					
						
							|  |  |  |     { | 
					
						
							| 
									
										
										
										
											2015-07-06 03:25:03 +02:00
										 |  |  |         if ($source->exists) { | 
					
						
							| 
									
										
										
										
											2011-09-16 14:19:56 +00:00
										 |  |  |             return file_get_contents($source->filepath); | 
					
						
							|  |  |  |         } | 
					
						
							| 
									
										
										
										
											2015-07-12 02:26:42 +02:00
										 |  |  |         throw new SmartyException('Unable to read ' . ($source->isConfig ? 'config' : 'template') . | 
					
						
							|  |  |  |                                   " {$source->type} '{$source->name}'"); | 
					
						
							| 
									
										
										
										
											2011-09-16 14:19:56 +00:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											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
										 |  |  |     } | 
					
						
							|  |  |  | } |