| 
									
										
										
										
											2011-09-16 14:19:56 +00:00
										 |  |  | <?php | 
					
						
							|  |  |  | /** | 
					
						
							|  |  |  |  * Smarty Resource Plugin | 
					
						
							|  |  |  |  * | 
					
						
							| 
									
										
										
										
											2014-06-06 02:40:04 +00:00
										 |  |  |  * @package    Smarty | 
					
						
							| 
									
										
										
										
											2011-09-16 14:19:56 +00:00
										 |  |  |  * @subpackage TemplateResources | 
					
						
							| 
									
										
										
										
											2014-06-06 02:40:04 +00:00
										 |  |  |  * @author     Rodney Rehm | 
					
						
							| 
									
										
										
										
											2011-09-16 14:19:56 +00:00
										 |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /** | 
					
						
							|  |  |  |  * Smarty Resource Plugin | 
					
						
							|  |  |  |  * Wrapper Implementation for custom resource plugins | 
					
						
							|  |  |  |  * | 
					
						
							| 
									
										
										
										
											2014-06-06 02:40:04 +00:00
										 |  |  |  * @package    Smarty | 
					
						
							| 
									
										
										
										
											2011-09-16 14:19:56 +00:00
										 |  |  |  * @subpackage TemplateResources | 
					
						
							|  |  |  |  */ | 
					
						
							| 
									
										
										
										
											2013-07-14 22:15:45 +00:00
										 |  |  | abstract class Smarty_Resource_Custom extends Smarty_Resource | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2011-09-16 14:19:56 +00:00
										 |  |  |     /** | 
					
						
							|  |  |  |      * fetch template and its modification time from data source | 
					
						
							|  |  |  |      * | 
					
						
							|  |  |  |      * @param string  $name    template name | 
					
						
							|  |  |  |      * @param string  &$source template source | 
					
						
							|  |  |  |      * @param integer &$mtime  template modification timestamp (epoch) | 
					
						
							|  |  |  |      */ | 
					
						
							| 
									
										
										
										
											2013-07-14 22:15:45 +00:00
										 |  |  |     abstract protected function fetch($name, &$source, &$mtime); | 
					
						
							| 
									
										
										
										
											2011-09-16 14:19:56 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |     /** | 
					
						
							|  |  |  |      * Fetch template's modification timestamp from data source | 
					
						
							|  |  |  |      * {@internal implementing this method is optional. | 
					
						
							|  |  |  |      *  Only implement it if modification times can be accessed faster than loading the complete template source.}} | 
					
						
							|  |  |  |      * | 
					
						
							| 
									
										
										
										
											2014-06-06 02:40:04 +00:00
										 |  |  |      * @param  string $name template name | 
					
						
							|  |  |  |      * | 
					
						
							| 
									
										
										
										
											2011-09-16 14:19:56 +00:00
										 |  |  |      * @return integer|boolean timestamp (epoch) the template was modified, or false if not found | 
					
						
							|  |  |  |      */ | 
					
						
							|  |  |  |     protected function fetchTimestamp($name) | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         return null; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     /** | 
					
						
							|  |  |  |      * populate Source Object with meta data from Resource | 
					
						
							|  |  |  |      * | 
					
						
							|  |  |  |      * @param Smarty_Template_Source   $source    source object | 
					
						
							|  |  |  |      * @param Smarty_Internal_Template $_template template object | 
					
						
							|  |  |  |      */ | 
					
						
							| 
									
										
										
										
											2014-06-06 02:40:04 +00:00
										 |  |  |     public function populate(Smarty_Template_Source $source, Smarty_Internal_Template $_template = null) | 
					
						
							| 
									
										
										
										
											2011-09-16 14:19:56 +00:00
										 |  |  |     { | 
					
						
							| 
									
										
										
										
											2014-03-26 20:33:03 +00:00
										 |  |  |         $source->filepath = $source->type . ':' . $source->name; | 
					
						
							| 
									
										
										
										
											2011-09-16 14:19:56 +00:00
										 |  |  |         $source->uid = sha1($source->type . ':' . $source->name); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         $mtime = $this->fetchTimestamp($source->name); | 
					
						
							|  |  |  |         if ($mtime !== null) { | 
					
						
							|  |  |  |             $source->timestamp = $mtime; | 
					
						
							|  |  |  |         } else { | 
					
						
							|  |  |  |             $this->fetch($source->name, $content, $timestamp); | 
					
						
							|  |  |  |             $source->timestamp = isset($timestamp) ? $timestamp : false; | 
					
						
							| 
									
										
										
										
											2014-06-06 02:40:04 +00:00
										 |  |  |             if (isset($content)) { | 
					
						
							| 
									
										
										
										
											2011-09-16 14:19:56 +00:00
										 |  |  |                 $source->content = $content; | 
					
						
							| 
									
										
										
										
											2014-06-06 02:40:04 +00:00
										 |  |  |             } | 
					
						
							| 
									
										
										
										
											2011-09-16 14:19:56 +00:00
										 |  |  |         } | 
					
						
							|  |  |  |         $source->exists = !!$source->timestamp; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     /** | 
					
						
							|  |  |  |      * Load template's source 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 | 
					
						
							| 
									
										
										
										
											2011-09-16 14:19:56 +00:00
										 |  |  |      */ | 
					
						
							|  |  |  |     public function getContent(Smarty_Template_Source $source) | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         $this->fetch($source->name, $content, $timestamp); | 
					
						
							|  |  |  |         if (isset($content)) { | 
					
						
							|  |  |  |             return $content; | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         throw new SmartyException("Unable to read template {$source->type} '{$source->name}'"); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     /** | 
					
						
							|  |  |  |      * 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 | 
					
						
							| 
									
										
										
										
											2011-09-16 14:19:56 +00:00
										 |  |  |      */ | 
					
						
							| 
									
										
										
										
											2015-01-01 23:34:29 +01:00
										 |  |  |     public function getBasename(Smarty_Template_Source $source) | 
					
						
							| 
									
										
										
										
											2011-09-16 14:19:56 +00:00
										 |  |  |     { | 
					
						
							|  |  |  |         return basename($source->name); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | } |