diff --git a/libs/sysplugins/smarty_internal_extension_defaulttemplatehandler.php b/libs/sysplugins/smarty_internal_extension_defaulttemplatehandler.php new file mode 100644 index 00000000..e67d9a81 --- /dev/null +++ b/libs/sysplugins/smarty_internal_extension_defaulttemplatehandler.php @@ -0,0 +1,83 @@ +isConfig) { + $default_handler = $_template->smarty->default_config_handler_func; + } else { + $default_handler = $_template->smarty->default_template_handler_func; + } + $_content = $_timestamp = null; + $_return = call_user_func_array($default_handler, + array($source->type, $source->name, &$_content, &$_timestamp, $source->smarty)); + if (is_string($_return)) { + $source->timestamp = @filemtime($_return); + $source->exists = !!$source->timestamp; + $source->filepath = $_return; + } elseif ($_return === true) { + $source->content = $_content; + $source->timestamp = $_timestamp; + $source->exists = true; + $source->recompiled = true; + $source->filepath = false; + } + } + + /** + * register template default handler + * + * @param Smarty|Smarty_Internal_Template $obj + * @param mixed $callback + * + * @throws SmartyException + */ + static function registerDefaultTemplateHandler($obj, $callback) + { + if (is_callable($callback)) { + $obj->smarty->default_template_handler_func = $callback; + } else { + throw new SmartyException("Default template handler not callable"); + } + } + + /** + * register config default handler + * + * @param Smarty|Smarty_Internal_Template $obj + * @param mixed $callback + * + * @throws SmartyException + */ + static function registerDefaultConfigHandler($obj, $callback) + { + if (is_callable($callback)) { + $obj->smarty->default_config_handler_func = $callback; + } else { + throw new SmartyException("Default config handler not callable"); + } + } +} \ No newline at end of file diff --git a/libs/sysplugins/smarty_internal_templatebase.php b/libs/sysplugins/smarty_internal_templatebase.php index 92a3c880..5a9cf01b 100644 --- a/libs/sysplugins/smarty_internal_templatebase.php +++ b/libs/sysplugins/smarty_internal_templatebase.php @@ -342,12 +342,7 @@ abstract class Smarty_Internal_TemplateBase extends Smarty_Internal_Data */ public function registerDefaultTemplateHandler($callback) { - if (is_callable($callback)) { - $this->smarty->default_template_handler_func = $callback; - } else { - throw new SmartyException("Default template handler '$callback' not callable"); - } - + Smarty_Internal_Extension_DefaultTemplateHandler::registerDefaultTemplateHandler($this, $callback); return $this; } @@ -361,12 +356,7 @@ abstract class Smarty_Internal_TemplateBase extends Smarty_Internal_Data */ public function registerDefaultConfigHandler($callback) { - if (is_callable($callback)) { - $this->smarty->default_config_handler_func = $callback; - } else { - throw new SmartyException("Default config handler '$callback' not callable"); - } - + Smarty_Internal_Extension_DefaultTemplateHandler::registerDefaultConfigHandler($this, $callback); return $this; }