| 
									
										
										
										
											2014-10-18 00:18:11 +02:00
										 |  |  | <?php | 
					
						
							|  |  |  | /** | 
					
						
							|  |  |  |  * Smarty Internal Plugin Smarty Template  Base | 
					
						
							|  |  |  |  * This file contains the basic shared methods for template handling | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * @package    Smarty | 
					
						
							|  |  |  |  * @subpackage Template | 
					
						
							|  |  |  |  * @author     Uwe Tews | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /** | 
					
						
							|  |  |  |  * Class with shared template methods | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * @package    Smarty | 
					
						
							|  |  |  |  * @subpackage Template | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | abstract class Smarty_Internal_TemplateBase extends Smarty_Internal_Data | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2014-12-31 15:44:08 +01:00
										 |  |  |     /** | 
					
						
							|  |  |  |      * Set this if you want different sets of cache files for the same | 
					
						
							|  |  |  |      * templates. | 
					
						
							|  |  |  |      * | 
					
						
							|  |  |  |      * @var string | 
					
						
							|  |  |  |      */ | 
					
						
							|  |  |  |     public $cache_id = null; | 
					
						
							|  |  |  |     /** | 
					
						
							|  |  |  |      * Set this if you want different sets of compiled files for the same | 
					
						
							|  |  |  |      * templates. | 
					
						
							|  |  |  |      * | 
					
						
							|  |  |  |      * @var string | 
					
						
							|  |  |  |      */ | 
					
						
							|  |  |  |     public $compile_id = null; | 
					
						
							|  |  |  |     /** | 
					
						
							|  |  |  |      * caching enabled | 
					
						
							|  |  |  |      * | 
					
						
							|  |  |  |      * @var boolean | 
					
						
							|  |  |  |      */ | 
					
						
							|  |  |  |     public $caching = false; | 
					
						
							|  |  |  |     /** | 
					
						
							|  |  |  |      * cache lifetime in seconds | 
					
						
							|  |  |  |      * | 
					
						
							|  |  |  |      * @var integer | 
					
						
							|  |  |  |      */ | 
					
						
							|  |  |  |     public $cache_lifetime = 3600; | 
					
						
							| 
									
										
										
										
											2015-01-01 22:27:45 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-10-18 00:18:11 +02:00
										 |  |  |     /** | 
					
						
							|  |  |  |      * test if cache is valid | 
					
						
							|  |  |  |      * | 
					
						
							|  |  |  |      * @param  string|object $template   the resource handle of the template file or template object | 
					
						
							|  |  |  |      * @param  mixed         $cache_id   cache id to be used with this template | 
					
						
							|  |  |  |      * @param  mixed         $compile_id compile id to be used with this template | 
					
						
							|  |  |  |      * @param  object        $parent     next higher level of Smarty variables | 
					
						
							|  |  |  |      * | 
					
						
							|  |  |  |      * @return boolean       cache status | 
					
						
							|  |  |  |      */ | 
					
						
							|  |  |  |     public function isCached($template = null, $cache_id = null, $compile_id = null, $parent = null) | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         if ($template === null && $this instanceof $this->template_class) { | 
					
						
							| 
									
										
										
										
											2015-05-06 23:10:39 +02:00
										 |  |  |             $template = $this; | 
					
						
							|  |  |  |         } else { | 
					
						
							|  |  |  |             if (!($template instanceof $this->template_class)) { | 
					
						
							|  |  |  |                 if ($parent === null) { | 
					
						
							|  |  |  |                     $parent = $this; | 
					
						
							|  |  |  |                 } | 
					
						
							|  |  |  |                 $smarty = isset($this->smarty) ? $this->smarty : $this; | 
					
						
							|  |  |  |                 $template = $smarty->createTemplate($template, $cache_id, $compile_id, $parent, false); | 
					
						
							| 
									
										
										
										
											2014-10-18 00:18:11 +02:00
										 |  |  |             } | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |         // return cache status of template
 | 
					
						
							| 
									
										
										
										
											2015-05-07 22:57:59 +02:00
										 |  |  |         if (!isset($template->cached)) { | 
					
						
							|  |  |  |             $template->loadCached(); | 
					
						
							|  |  |  |         } | 
					
						
							| 
									
										
										
										
											2015-05-06 23:10:39 +02:00
										 |  |  |         return $template->cached->isCached($template); | 
					
						
							| 
									
										
										
										
											2014-10-18 00:18:11 +02:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     /** | 
					
						
							|  |  |  |      * creates a data object | 
					
						
							|  |  |  |      * | 
					
						
							|  |  |  |      * @param object $parent next higher level of Smarty variables | 
					
						
							| 
									
										
										
										
											2014-11-08 21:06:53 +01:00
										 |  |  |      * @param string $name   optional data block name | 
					
						
							| 
									
										
										
										
											2014-10-18 00:18:11 +02:00
										 |  |  |      * | 
					
						
							|  |  |  |      * @returns Smarty_Data data object | 
					
						
							|  |  |  |      */ | 
					
						
							| 
									
										
										
										
											2014-11-03 22:27:32 +01:00
										 |  |  |     public function createData($parent = null, $name = null) | 
					
						
							| 
									
										
										
										
											2014-10-18 00:18:11 +02:00
										 |  |  |     { | 
					
						
							| 
									
										
										
										
											2014-11-03 22:27:32 +01:00
										 |  |  |         $dataObj = new Smarty_Data($parent, $this, $name); | 
					
						
							|  |  |  |         if ($this->debugging) { | 
					
						
							|  |  |  |             Smarty_Internal_Debug::register_data($dataObj); | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |         return $dataObj; | 
					
						
							| 
									
										
										
										
											2014-10-18 00:18:11 +02:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-01-01 22:27:45 +01:00
										 |  |  |     /** | 
					
						
							|  |  |  |      * Get unique template id | 
					
						
							|  |  |  |      * | 
					
						
							|  |  |  |      * @param string     $template_name | 
					
						
							|  |  |  |      * @param null|mixed $cache_id | 
					
						
							|  |  |  |      * @param null|mixed $compile_id | 
					
						
							|  |  |  |      * | 
					
						
							|  |  |  |      * @return string | 
					
						
							|  |  |  |      */ | 
					
						
							|  |  |  |     public function getTemplateId($template_name, $cache_id = null, $compile_id = null) | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         $cache_id = isset($cache_id) ? $cache_id : $this->cache_id; | 
					
						
							|  |  |  |         $compile_id = isset($compile_id) ? $compile_id : $this->compile_id; | 
					
						
							| 
									
										
										
										
											2015-02-15 01:45:37 +01:00
										 |  |  |         $smarty = isset($this->smarty) ? $this->smarty : $this; | 
					
						
							|  |  |  |         if ($smarty->allow_ambiguous_resources) { | 
					
						
							| 
									
										
										
										
											2015-01-01 22:27:45 +01:00
										 |  |  |             $_templateId = Smarty_Resource::getUniqueTemplateName($this, $template_name) . "#{$cache_id}#{$compile_id}"; | 
					
						
							|  |  |  |         } else { | 
					
						
							| 
									
										
										
										
											2015-02-15 01:45:37 +01:00
										 |  |  |             $_templateId = $smarty->joined_template_dir . "#{$template_name}#{$cache_id}#{$compile_id}"; | 
					
						
							| 
									
										
										
										
											2015-01-01 22:27:45 +01:00
										 |  |  |         } | 
					
						
							|  |  |  |         if (isset($_templateId[150])) { | 
					
						
							|  |  |  |             $_templateId = sha1($_templateId); | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |         return $_templateId; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-10-18 00:18:11 +02:00
										 |  |  |     /** | 
					
						
							|  |  |  |      * Registers plugin to be used in templates | 
					
						
							|  |  |  |      * | 
					
						
							|  |  |  |      * @param  string   $type       plugin type | 
					
						
							|  |  |  |      * @param  string   $tag        name of template tag | 
					
						
							|  |  |  |      * @param  callback $callback   PHP callback to register | 
					
						
							|  |  |  |      * @param  boolean  $cacheable  if true (default) this fuction is cachable | 
					
						
							|  |  |  |      * @param  array    $cache_attr caching attributes if any | 
					
						
							|  |  |  |      * | 
					
						
							| 
									
										
										
										
											2015-05-06 23:10:39 +02:00
										 |  |  |      * @return Smarty_Internal_Templatebase current Smarty_Internal_Templatebase (or Smarty or | 
					
						
							|  |  |  |      *                                      Smarty_Internal_Template) instance for chaining | 
					
						
							| 
									
										
										
										
											2014-10-18 00:18:11 +02:00
										 |  |  |      * @throws SmartyException              when the plugin tag is invalid | 
					
						
							|  |  |  |      */ | 
					
						
							|  |  |  |     public function registerPlugin($type, $tag, $callback, $cacheable = true, $cache_attr = null) | 
					
						
							|  |  |  |     { | 
					
						
							| 
									
										
										
										
											2015-02-15 01:45:37 +01:00
										 |  |  |         $smarty = isset($this->smarty) ? $this->smarty : $this; | 
					
						
							|  |  |  |         if (isset($smarty->registered_plugins[$type][$tag])) { | 
					
						
							| 
									
										
										
										
											2014-10-18 00:18:11 +02:00
										 |  |  |             throw new SmartyException("Plugin tag \"{$tag}\" already registered"); | 
					
						
							|  |  |  |         } elseif (!is_callable($callback)) { | 
					
						
							|  |  |  |             throw new SmartyException("Plugin \"{$tag}\" not callable"); | 
					
						
							|  |  |  |         } else { | 
					
						
							| 
									
										
										
										
											2015-02-15 01:45:37 +01:00
										 |  |  |             $smarty->registered_plugins[$type][$tag] = array($callback, (bool) $cacheable, (array) $cache_attr); | 
					
						
							| 
									
										
										
										
											2014-10-18 00:18:11 +02:00
										 |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         return $this; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     /** | 
					
						
							|  |  |  |      * Unregister Plugin | 
					
						
							|  |  |  |      * | 
					
						
							|  |  |  |      * @param  string $type of plugin | 
					
						
							|  |  |  |      * @param  string $tag  name of plugin | 
					
						
							|  |  |  |      * | 
					
						
							| 
									
										
										
										
											2015-05-06 23:10:39 +02:00
										 |  |  |      * @return Smarty_Internal_Templatebase current Smarty_Internal_Templatebase (or Smarty or | 
					
						
							|  |  |  |      *                                      Smarty_Internal_Template) instance for chaining | 
					
						
							| 
									
										
										
										
											2014-10-18 00:18:11 +02:00
										 |  |  |      */ | 
					
						
							|  |  |  |     public function unregisterPlugin($type, $tag) | 
					
						
							|  |  |  |     { | 
					
						
							| 
									
										
										
										
											2015-02-15 01:45:37 +01:00
										 |  |  |         $smarty = isset($this->smarty) ? $this->smarty : $this; | 
					
						
							|  |  |  |         if (isset($smarty->registered_plugins[$type][$tag])) { | 
					
						
							|  |  |  |             unset($smarty->registered_plugins[$type][$tag]); | 
					
						
							| 
									
										
										
										
											2014-10-18 00:18:11 +02:00
										 |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         return $this; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     /** | 
					
						
							|  |  |  |      * Registers a resource to fetch a template | 
					
						
							|  |  |  |      * | 
					
						
							|  |  |  |      * @param  string                $type     name of resource type | 
					
						
							| 
									
										
										
										
											2015-05-06 23:10:39 +02:00
										 |  |  |      * @param  Smarty_Resource|array $callback or instance of Smarty_Resource, or array of callbacks to handle resource | 
					
						
							|  |  |  |      *                                         (deprecated) | 
					
						
							| 
									
										
										
										
											2014-10-18 00:18:11 +02:00
										 |  |  |      * | 
					
						
							| 
									
										
										
										
											2015-05-06 23:10:39 +02:00
										 |  |  |      * @return Smarty_Internal_Templatebase current Smarty_Internal_Templatebase (or Smarty or | 
					
						
							|  |  |  |      *                                      Smarty_Internal_Template) instance for chaining | 
					
						
							| 
									
										
										
										
											2014-10-18 00:18:11 +02:00
										 |  |  |      */ | 
					
						
							|  |  |  |     public function registerResource($type, $callback) | 
					
						
							|  |  |  |     { | 
					
						
							| 
									
										
										
										
											2015-02-15 01:45:37 +01:00
										 |  |  |         $smarty = isset($this->smarty) ? $this->smarty : $this; | 
					
						
							|  |  |  |         $smarty->registered_resources[$type] = $callback instanceof Smarty_Resource ? $callback : array($callback, false); | 
					
						
							| 
									
										
										
										
											2014-10-18 00:18:11 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |         return $this; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     /** | 
					
						
							|  |  |  |      * Unregisters a resource | 
					
						
							|  |  |  |      * | 
					
						
							|  |  |  |      * @param  string $type name of resource type | 
					
						
							|  |  |  |      * | 
					
						
							| 
									
										
										
										
											2015-05-06 23:10:39 +02:00
										 |  |  |      * @return Smarty_Internal_Templatebase current Smarty_Internal_Templatebase (or Smarty or | 
					
						
							|  |  |  |      *                                      Smarty_Internal_Template) instance for chaining | 
					
						
							| 
									
										
										
										
											2014-10-18 00:18:11 +02:00
										 |  |  |      */ | 
					
						
							|  |  |  |     public function unregisterResource($type) | 
					
						
							|  |  |  |     { | 
					
						
							| 
									
										
										
										
											2015-02-15 01:45:37 +01:00
										 |  |  |         $smarty = isset($this->smarty) ? $this->smarty : $this; | 
					
						
							|  |  |  |         if (isset($smarty->registered_resources[$type])) { | 
					
						
							|  |  |  |             unset($smarty->registered_resources[$type]); | 
					
						
							| 
									
										
										
										
											2014-10-18 00:18:11 +02:00
										 |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         return $this; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     /** | 
					
						
							|  |  |  |      * Registers a cache resource to cache a template's output | 
					
						
							|  |  |  |      * | 
					
						
							|  |  |  |      * @param  string               $type     name of cache resource type | 
					
						
							|  |  |  |      * @param  Smarty_CacheResource $callback instance of Smarty_CacheResource to handle output caching | 
					
						
							|  |  |  |      * | 
					
						
							| 
									
										
										
										
											2015-05-06 23:10:39 +02:00
										 |  |  |      * @return Smarty_Internal_Templatebase current Smarty_Internal_Templatebase (or Smarty or | 
					
						
							|  |  |  |      *                                      Smarty_Internal_Template) instance for chaining | 
					
						
							| 
									
										
										
										
											2014-10-18 00:18:11 +02:00
										 |  |  |      */ | 
					
						
							|  |  |  |     public function registerCacheResource($type, Smarty_CacheResource $callback) | 
					
						
							|  |  |  |     { | 
					
						
							| 
									
										
										
										
											2015-02-15 01:45:37 +01:00
										 |  |  |         $smarty = isset($this->smarty) ? $this->smarty : $this; | 
					
						
							|  |  |  |         $smarty->registered_cache_resources[$type] = $callback; | 
					
						
							| 
									
										
										
										
											2014-10-18 00:18:11 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |         return $this; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     /** | 
					
						
							|  |  |  |      * Unregisters a cache resource | 
					
						
							|  |  |  |      * | 
					
						
							|  |  |  |      * @param  string $type name of cache resource type | 
					
						
							|  |  |  |      * | 
					
						
							| 
									
										
										
										
											2015-05-06 23:10:39 +02:00
										 |  |  |      * @return Smarty_Internal_Templatebase current Smarty_Internal_Templatebase (or Smarty or | 
					
						
							|  |  |  |      *                                      Smarty_Internal_Template) instance for chaining | 
					
						
							| 
									
										
										
										
											2014-10-18 00:18:11 +02:00
										 |  |  |      */ | 
					
						
							|  |  |  |     public function unregisterCacheResource($type) | 
					
						
							|  |  |  |     { | 
					
						
							| 
									
										
										
										
											2015-02-15 01:45:37 +01:00
										 |  |  |         $smarty = isset($this->smarty) ? $this->smarty : $this; | 
					
						
							|  |  |  |         if (isset($smarty->registered_cache_resources[$type])) { | 
					
						
							|  |  |  |             unset($smarty->registered_cache_resources[$type]); | 
					
						
							| 
									
										
										
										
											2014-10-18 00:18:11 +02:00
										 |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         return $this; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     /** | 
					
						
							|  |  |  |      * Registers object to be used in templates | 
					
						
							|  |  |  |      * | 
					
						
							|  |  |  |      * @param          $object_name | 
					
						
							|  |  |  |      * @param  object  $object_impl   the referenced PHP object to register | 
					
						
							|  |  |  |      * @param  array   $allowed       list of allowed methods (empty = all) | 
					
						
							|  |  |  |      * @param  boolean $smarty_args   smarty argument format, else traditional | 
					
						
							|  |  |  |      * @param  array   $block_methods list of block-methods | 
					
						
							|  |  |  |      * | 
					
						
							|  |  |  |      * @throws SmartyException | 
					
						
							| 
									
										
										
										
											2015-05-06 23:10:39 +02:00
										 |  |  |      * @return Smarty_Internal_Templatebase current Smarty_Internal_Templatebase (or Smarty or | 
					
						
							|  |  |  |      *                                      Smarty_Internal_Template) instance for chaining | 
					
						
							| 
									
										
										
										
											2014-10-18 00:18:11 +02:00
										 |  |  |      */ | 
					
						
							|  |  |  |     public function registerObject($object_name, $object_impl, $allowed = array(), $smarty_args = true, $block_methods = array()) | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         // test if allowed methods callable
 | 
					
						
							|  |  |  |         if (!empty($allowed)) { | 
					
						
							|  |  |  |             foreach ((array) $allowed as $method) { | 
					
						
							|  |  |  |                 if (!is_callable(array($object_impl, $method)) && !property_exists($object_impl, $method)) { | 
					
						
							|  |  |  |                     throw new SmartyException("Undefined method or property '$method' in registered object"); | 
					
						
							|  |  |  |                 } | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |         // test if block methods callable
 | 
					
						
							|  |  |  |         if (!empty($block_methods)) { | 
					
						
							|  |  |  |             foreach ((array) $block_methods as $method) { | 
					
						
							|  |  |  |                 if (!is_callable(array($object_impl, $method))) { | 
					
						
							|  |  |  |                     throw new SmartyException("Undefined method '$method' in registered object"); | 
					
						
							|  |  |  |                 } | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |         // register the object
 | 
					
						
							| 
									
										
										
										
											2015-02-15 01:45:37 +01:00
										 |  |  |         $smarty = isset($this->smarty) ? $this->smarty : $this; | 
					
						
							|  |  |  |         $smarty->registered_objects[$object_name] = | 
					
						
							| 
									
										
										
										
											2014-10-18 00:18:11 +02:00
										 |  |  |             array($object_impl, (array) $allowed, (boolean) $smarty_args, (array) $block_methods); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         return $this; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     /** | 
					
						
							|  |  |  |      * return a reference to a registered object | 
					
						
							|  |  |  |      * | 
					
						
							|  |  |  |      * @param  string $name object name | 
					
						
							|  |  |  |      * | 
					
						
							|  |  |  |      * @return object | 
					
						
							|  |  |  |      * @throws SmartyException if no such object is found | 
					
						
							|  |  |  |      */ | 
					
						
							|  |  |  |     public function getRegisteredObject($name) | 
					
						
							|  |  |  |     { | 
					
						
							| 
									
										
										
										
											2015-02-15 01:45:37 +01:00
										 |  |  |         $smarty = isset($this->smarty) ? $this->smarty : $this; | 
					
						
							|  |  |  |         if (!isset($smarty->registered_objects[$name])) { | 
					
						
							| 
									
										
										
										
											2014-10-18 00:18:11 +02:00
										 |  |  |             throw new SmartyException("'$name' is not a registered object"); | 
					
						
							|  |  |  |         } | 
					
						
							| 
									
										
										
										
											2015-02-15 01:45:37 +01:00
										 |  |  |         if (!is_object($smarty->registered_objects[$name][0])) { | 
					
						
							| 
									
										
										
										
											2014-10-18 00:18:11 +02:00
										 |  |  |             throw new SmartyException("registered '$name' is not an object"); | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-02-15 01:45:37 +01:00
										 |  |  |         return $smarty->registered_objects[$name][0]; | 
					
						
							| 
									
										
										
										
											2014-10-18 00:18:11 +02:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     /** | 
					
						
							|  |  |  |      * unregister an object | 
					
						
							|  |  |  |      * | 
					
						
							|  |  |  |      * @param  string $name object name | 
					
						
							|  |  |  |      * | 
					
						
							| 
									
										
										
										
											2015-05-06 23:10:39 +02:00
										 |  |  |      * @return Smarty_Internal_Templatebase current Smarty_Internal_Templatebase (or Smarty or | 
					
						
							|  |  |  |      *                                      Smarty_Internal_Template) instance for chaining | 
					
						
							| 
									
										
										
										
											2014-10-18 00:18:11 +02:00
										 |  |  |      */ | 
					
						
							|  |  |  |     public function unregisterObject($name) | 
					
						
							|  |  |  |     { | 
					
						
							| 
									
										
										
										
											2015-02-15 01:45:37 +01:00
										 |  |  |         $smarty = isset($this->smarty) ? $this->smarty : $this; | 
					
						
							|  |  |  |         if (isset($smarty->registered_objects[$name])) { | 
					
						
							|  |  |  |             unset($smarty->registered_objects[$name]); | 
					
						
							| 
									
										
										
										
											2014-10-18 00:18:11 +02:00
										 |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         return $this; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     /** | 
					
						
							|  |  |  |      * Registers static classes to be used in templates | 
					
						
							|  |  |  |      * | 
					
						
							|  |  |  |      * @param         $class_name | 
					
						
							|  |  |  |      * @param  string $class_impl the referenced PHP class to register | 
					
						
							|  |  |  |      * | 
					
						
							|  |  |  |      * @throws SmartyException | 
					
						
							| 
									
										
										
										
											2015-05-06 23:10:39 +02:00
										 |  |  |      * @return Smarty_Internal_Templatebase current Smarty_Internal_Templatebase (or Smarty or | 
					
						
							|  |  |  |      *                                      Smarty_Internal_Template) instance for chaining | 
					
						
							| 
									
										
										
										
											2014-10-18 00:18:11 +02:00
										 |  |  |      */ | 
					
						
							|  |  |  |     public function registerClass($class_name, $class_impl) | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         // test if exists
 | 
					
						
							|  |  |  |         if (!class_exists($class_impl)) { | 
					
						
							|  |  |  |             throw new SmartyException("Undefined class '$class_impl' in register template class"); | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |         // register the class
 | 
					
						
							| 
									
										
										
										
											2015-02-15 01:45:37 +01:00
										 |  |  |         $smarty = isset($this->smarty) ? $this->smarty : $this; | 
					
						
							|  |  |  |         $smarty->registered_classes[$class_name] = $class_impl; | 
					
						
							| 
									
										
										
										
											2014-10-18 00:18:11 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |         return $this; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     /** | 
					
						
							|  |  |  |      * Registers a default plugin handler | 
					
						
							|  |  |  |      * | 
					
						
							|  |  |  |      * @param  callable $callback class/method name | 
					
						
							|  |  |  |      * | 
					
						
							| 
									
										
										
										
											2015-05-06 23:10:39 +02:00
										 |  |  |      * @return Smarty_Internal_Templatebase current Smarty_Internal_Templatebase (or Smarty or | 
					
						
							|  |  |  |      *                                      Smarty_Internal_Template) instance for chaining | 
					
						
							| 
									
										
										
										
											2014-10-18 00:18:11 +02:00
										 |  |  |      * @throws SmartyException              if $callback is not callable | 
					
						
							|  |  |  |      */ | 
					
						
							|  |  |  |     public function registerDefaultPluginHandler($callback) | 
					
						
							|  |  |  |     { | 
					
						
							| 
									
										
										
										
											2015-02-15 01:45:37 +01:00
										 |  |  |         $smarty = isset($this->smarty) ? $this->smarty : $this; | 
					
						
							| 
									
										
										
										
											2014-10-18 00:18:11 +02:00
										 |  |  |         if (is_callable($callback)) { | 
					
						
							| 
									
										
										
										
											2015-02-15 01:45:37 +01:00
										 |  |  |             $smarty->default_plugin_handler_func = $callback; | 
					
						
							| 
									
										
										
										
											2014-10-18 00:18:11 +02:00
										 |  |  |         } else { | 
					
						
							|  |  |  |             throw new SmartyException("Default plugin handler '$callback' not callable"); | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         return $this; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     /** | 
					
						
							|  |  |  |      * Registers a default template handler | 
					
						
							|  |  |  |      * | 
					
						
							|  |  |  |      * @param  callable $callback class/method name | 
					
						
							|  |  |  |      * | 
					
						
							| 
									
										
										
										
											2015-05-06 23:10:39 +02:00
										 |  |  |      * @return Smarty_Internal_Templatebase current Smarty_Internal_Templatebase (or Smarty or | 
					
						
							|  |  |  |      *                                      Smarty_Internal_Template) instance for chaining | 
					
						
							| 
									
										
										
										
											2014-10-18 00:18:11 +02:00
										 |  |  |      * @throws SmartyException              if $callback is not callable | 
					
						
							|  |  |  |      */ | 
					
						
							|  |  |  |     public function registerDefaultTemplateHandler($callback) | 
					
						
							|  |  |  |     { | 
					
						
							| 
									
										
										
										
											2015-01-02 10:48:07 +01:00
										 |  |  |         Smarty_Internal_Extension_DefaultTemplateHandler::registerDefaultTemplateHandler($this, $callback); | 
					
						
							| 
									
										
										
										
											2014-10-18 00:18:11 +02:00
										 |  |  |         return $this; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     /** | 
					
						
							|  |  |  |      * Registers a default template handler | 
					
						
							|  |  |  |      * | 
					
						
							|  |  |  |      * @param  callable $callback class/method name | 
					
						
							|  |  |  |      * | 
					
						
							| 
									
										
										
										
											2015-05-06 23:10:39 +02:00
										 |  |  |      * @return Smarty_Internal_Templatebase current Smarty_Internal_Templatebase (or Smarty or | 
					
						
							|  |  |  |      *                                      Smarty_Internal_Template) instance for chaining | 
					
						
							| 
									
										
										
										
											2014-10-18 00:18:11 +02:00
										 |  |  |      * @throws SmartyException              if $callback is not callable | 
					
						
							|  |  |  |      */ | 
					
						
							|  |  |  |     public function registerDefaultConfigHandler($callback) | 
					
						
							|  |  |  |     { | 
					
						
							| 
									
										
										
										
											2015-01-02 10:48:07 +01:00
										 |  |  |         Smarty_Internal_Extension_DefaultTemplateHandler::registerDefaultConfigHandler($this, $callback); | 
					
						
							| 
									
										
										
										
											2014-10-18 00:18:11 +02:00
										 |  |  |         return $this; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     /** | 
					
						
							|  |  |  |      * Registers a filter function
 | 
					
						
							|  |  |  |      * | 
					
						
							|  |  |  |      * @param  string   $type filter type | 
					
						
							|  |  |  |      * @param  callback $callback | 
					
						
							|  |  |  |      * | 
					
						
							| 
									
										
										
										
											2015-05-06 23:10:39 +02:00
										 |  |  |      * @return Smarty_Internal_Templatebase current Smarty_Internal_Templatebase (or Smarty or | 
					
						
							|  |  |  |      *                                      Smarty_Internal_Template) instance for chaining | 
					
						
							| 
									
										
										
										
											2014-10-18 00:18:11 +02:00
										 |  |  |      */ | 
					
						
							|  |  |  |     public function registerFilter($type, $callback) | 
					
						
							|  |  |  |     { | 
					
						
							| 
									
										
										
										
											2015-02-15 01:45:37 +01:00
										 |  |  |         $smarty = isset($this->smarty) ? $this->smarty : $this; | 
					
						
							|  |  |  |         $smarty->registered_filters[$type][$this->_get_filter_name($callback)] = $callback; | 
					
						
							| 
									
										
										
										
											2014-10-18 00:18:11 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |         return $this; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     /** | 
					
						
							|  |  |  |      * Unregisters a filter function
 | 
					
						
							|  |  |  |      * | 
					
						
							|  |  |  |      * @param  string   $type filter type | 
					
						
							|  |  |  |      * @param  callback $callback | 
					
						
							|  |  |  |      * | 
					
						
							| 
									
										
										
										
											2015-05-06 23:10:39 +02:00
										 |  |  |      * @return Smarty_Internal_Templatebase current Smarty_Internal_Templatebase (or Smarty or | 
					
						
							|  |  |  |      *                                      Smarty_Internal_Template) instance for chaining | 
					
						
							| 
									
										
										
										
											2014-10-18 00:18:11 +02:00
										 |  |  |      */ | 
					
						
							|  |  |  |     public function unregisterFilter($type, $callback) | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         $name = $this->_get_filter_name($callback); | 
					
						
							| 
									
										
										
										
											2015-02-15 01:45:37 +01:00
										 |  |  |         $smarty = isset($this->smarty) ? $this->smarty : $this; | 
					
						
							|  |  |  |         if (isset($smarty->registered_filters[$type][$name])) { | 
					
						
							|  |  |  |             unset($smarty->registered_filters[$type][$name]); | 
					
						
							| 
									
										
										
										
											2014-10-18 00:18:11 +02:00
										 |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         return $this; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     /** | 
					
						
							|  |  |  |      * Return internal filter name | 
					
						
							|  |  |  |      * | 
					
						
							|  |  |  |      * @param  callback $function_name | 
					
						
							|  |  |  |      * | 
					
						
							|  |  |  |      * @return string   internal filter name | 
					
						
							|  |  |  |      */ | 
					
						
							|  |  |  |     public function _get_filter_name($function_name) | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         if (is_array($function_name)) { | 
					
						
							|  |  |  |             $_class_name = (is_object($function_name[0]) ? | 
					
						
							|  |  |  |                 get_class($function_name[0]) : $function_name[0]); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |             return $_class_name . '_' . $function_name[1]; | 
					
						
							|  |  |  |         } else { | 
					
						
							|  |  |  |             return $function_name; | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     /** | 
					
						
							|  |  |  |      * load a filter of specified type and name | 
					
						
							|  |  |  |      * | 
					
						
							|  |  |  |      * @param  string $type filter type | 
					
						
							|  |  |  |      * @param  string $name filter name | 
					
						
							|  |  |  |      * | 
					
						
							|  |  |  |      * @throws SmartyException if filter could not be loaded | 
					
						
							|  |  |  |      */ | 
					
						
							|  |  |  |     public function loadFilter($type, $name) | 
					
						
							|  |  |  |     { | 
					
						
							| 
									
										
										
										
											2015-02-15 01:45:37 +01:00
										 |  |  |         $smarty = isset($this->smarty) ? $this->smarty : $this; | 
					
						
							| 
									
										
										
										
											2014-10-18 00:18:11 +02:00
										 |  |  |         $_plugin = "smarty_{$type}filter_{$name}"; | 
					
						
							|  |  |  |         $_filter_name = $_plugin; | 
					
						
							| 
									
										
										
										
											2015-02-15 01:45:37 +01:00
										 |  |  |         if ($smarty->loadPlugin($_plugin)) { | 
					
						
							| 
									
										
										
										
											2014-10-18 00:18:11 +02:00
										 |  |  |             if (class_exists($_plugin, false)) { | 
					
						
							|  |  |  |                 $_plugin = array($_plugin, 'execute'); | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |             if (is_callable($_plugin)) { | 
					
						
							| 
									
										
										
										
											2015-02-15 01:45:37 +01:00
										 |  |  |                 $smarty->registered_filters[$type][$_filter_name] = $_plugin; | 
					
						
							| 
									
										
										
										
											2014-10-18 00:18:11 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |                 return true; | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |         throw new SmartyException("{$type}filter \"{$name}\" not callable"); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     /** | 
					
						
							|  |  |  |      * unload a filter of specified type and name | 
					
						
							|  |  |  |      * | 
					
						
							|  |  |  |      * @param  string $type filter type | 
					
						
							|  |  |  |      * @param  string $name filter name | 
					
						
							|  |  |  |      * | 
					
						
							| 
									
										
										
										
											2015-05-06 23:10:39 +02:00
										 |  |  |      * @return Smarty_Internal_Templatebase current Smarty_Internal_Templatebase (or Smarty or | 
					
						
							|  |  |  |      *                                      Smarty_Internal_Template) instance for chaining | 
					
						
							| 
									
										
										
										
											2014-10-18 00:18:11 +02:00
										 |  |  |      */ | 
					
						
							|  |  |  |     public function unloadFilter($type, $name) | 
					
						
							|  |  |  |     { | 
					
						
							| 
									
										
										
										
											2015-02-15 01:45:37 +01:00
										 |  |  |         $smarty = isset($this->smarty) ? $this->smarty : $this; | 
					
						
							| 
									
										
										
										
											2014-10-18 00:18:11 +02:00
										 |  |  |         $_filter_name = "smarty_{$type}filter_{$name}"; | 
					
						
							| 
									
										
										
										
											2015-02-15 01:45:37 +01:00
										 |  |  |         if (isset($smarty->registered_filters[$type][$_filter_name])) { | 
					
						
							|  |  |  |             unset ($smarty->registered_filters[$type][$_filter_name]); | 
					
						
							| 
									
										
										
										
											2014-10-18 00:18:11 +02:00
										 |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         return $this; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     /** | 
					
						
							|  |  |  |      * preg_replace callback to convert camelcase getter/setter to underscore property names | 
					
						
							|  |  |  |      * | 
					
						
							|  |  |  |      * @param  string $match match string | 
					
						
							|  |  |  |      * | 
					
						
							|  |  |  |      * @return string replacemant | 
					
						
							|  |  |  |      */ | 
					
						
							|  |  |  |     private function replaceCamelcase($match) | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         return "_" . strtolower($match[1]); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     /** | 
					
						
							|  |  |  |      * Handle unknown class methods | 
					
						
							|  |  |  |      * | 
					
						
							|  |  |  |      * @param string $name unknown method-name | 
					
						
							|  |  |  |      * @param array  $args argument array | 
					
						
							|  |  |  |      * | 
					
						
							|  |  |  |      * @throws SmartyException | 
					
						
							|  |  |  |      */ | 
					
						
							|  |  |  |     public function __call($name, $args) | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         static $_prefixes = array('set' => true, 'get' => true); | 
					
						
							|  |  |  |         static $_resolved_property_name = array(); | 
					
						
							|  |  |  |         static $_resolved_property_source = array(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         // see if this is a set/get for a property
 | 
					
						
							|  |  |  |         $first3 = strtolower(substr($name, 0, 3)); | 
					
						
							|  |  |  |         if (isset($_prefixes[$first3]) && isset($name[3]) && $name[3] !== '_') { | 
					
						
							|  |  |  |             if (isset($_resolved_property_name[$name])) { | 
					
						
							|  |  |  |                 $property_name = $_resolved_property_name[$name]; | 
					
						
							|  |  |  |             } else { | 
					
						
							|  |  |  |                 // try to keep case correct for future PHP 6.0 case-sensitive class methods
 | 
					
						
							|  |  |  |                 // lcfirst() not available < PHP 5.3.0, so improvise
 | 
					
						
							|  |  |  |                 $property_name = strtolower(substr($name, 3, 1)) . substr($name, 4); | 
					
						
							|  |  |  |                 // convert camel case to underscored name
 | 
					
						
							|  |  |  |                 $property_name = preg_replace_callback('/([A-Z])/', array($this, 'replaceCamelcase'), $property_name); | 
					
						
							|  |  |  |                 $_resolved_property_name[$name] = $property_name; | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |             if (isset($_resolved_property_source[$property_name])) { | 
					
						
							| 
									
										
										
										
											2015-02-15 01:45:37 +01:00
										 |  |  |                 $status = $_resolved_property_source[$property_name]; | 
					
						
							| 
									
										
										
										
											2014-10-18 00:18:11 +02:00
										 |  |  |             } else { | 
					
						
							| 
									
										
										
										
											2015-02-15 01:45:37 +01:00
										 |  |  |                 $status = null; | 
					
						
							| 
									
										
										
										
											2014-10-18 00:18:11 +02:00
										 |  |  |                 if (property_exists($this, $property_name)) { | 
					
						
							| 
									
										
										
										
											2015-02-15 01:45:37 +01:00
										 |  |  |                     $status = true; | 
					
						
							| 
									
										
										
										
											2014-10-18 00:18:11 +02:00
										 |  |  |                 } elseif (property_exists($this->smarty, $property_name)) { | 
					
						
							| 
									
										
										
										
											2015-02-15 01:45:37 +01:00
										 |  |  |                     $status = false; | 
					
						
							| 
									
										
										
										
											2014-10-18 00:18:11 +02:00
										 |  |  |                 } | 
					
						
							| 
									
										
										
										
											2015-02-15 01:45:37 +01:00
										 |  |  |                 $_resolved_property_source[$property_name] = $status; | 
					
						
							| 
									
										
										
										
											2014-10-18 00:18:11 +02:00
										 |  |  |             } | 
					
						
							| 
									
										
										
										
											2015-02-15 01:45:37 +01:00
										 |  |  |             $smarty = null; | 
					
						
							|  |  |  |             if ($status === true) { | 
					
						
							|  |  |  |                 $smarty = $this; | 
					
						
							|  |  |  |             } elseif ($status === false) { | 
					
						
							|  |  |  |                 $smarty = $this->smarty; | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |             if ($smarty) { | 
					
						
							| 
									
										
										
										
											2014-10-18 00:18:11 +02:00
										 |  |  |                 if ($first3 == 'get') { | 
					
						
							| 
									
										
										
										
											2015-02-15 01:45:37 +01:00
										 |  |  |                     return $smarty->$property_name; | 
					
						
							| 
									
										
										
										
											2014-10-18 00:18:11 +02:00
										 |  |  |                 } else { | 
					
						
							| 
									
										
										
										
											2015-02-15 01:45:37 +01:00
										 |  |  |                     return $smarty->$property_name = $args[0]; | 
					
						
							| 
									
										
										
										
											2014-10-18 00:18:11 +02:00
										 |  |  |                 } | 
					
						
							| 
									
										
										
										
											2014-11-01 22:42:34 +01:00
										 |  |  |             } | 
					
						
							| 
									
										
										
										
											2015-02-15 01:45:37 +01:00
										 |  |  |             throw new SmartyException("property '$property_name' does not exist."); | 
					
						
							| 
									
										
										
										
											2014-10-18 00:18:11 +02:00
										 |  |  |         } | 
					
						
							|  |  |  |         throw new SmartyException("Call of unknown method '$name'."); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2015-02-15 01:45:37 +01:00
										 |  |  | 
 |