From 49d54c0c3199fb8e380ce68f8fb08a308ddf56a7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jes=C3=BAs=20Eduardo?= Date: Mon, 25 Dec 2017 16:58:41 -0500 Subject: =?UTF-8?q?migraci=C3=B3n=20mayor=20a=20smarty=20PHP?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...ernal_method_registerdefaulttemplatehandler.php | 82 ++++++++++++++++++++++ 1 file changed, 82 insertions(+) create mode 100644 smarty/sysplugins/smarty_internal_method_registerdefaulttemplatehandler.php (limited to 'smarty/sysplugins/smarty_internal_method_registerdefaulttemplatehandler.php') diff --git a/smarty/sysplugins/smarty_internal_method_registerdefaulttemplatehandler.php b/smarty/sysplugins/smarty_internal_method_registerdefaulttemplatehandler.php new file mode 100644 index 0000000..73e8f62 --- /dev/null +++ b/smarty/sysplugins/smarty_internal_method_registerdefaulttemplatehandler.php @@ -0,0 +1,82 @@ +smarty) ? $obj->smarty : $obj; + if (is_callable($callback)) { + $smarty->default_template_handler_func = $callback; + } else { + throw new SmartyException("Default template handler not callable"); + } + return $obj; + } + + /** + * get default content from template or config resource handler + * + * @param Smarty_Template_Source $source + * + * @throws \SmartyException + */ + public static function _getDefaultTemplate(Smarty_Template_Source $source) + { + if ($source->isConfig) { + $default_handler = $source->smarty->default_config_handler_func; + } else { + $default_handler = $source->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->exists = is_file($_return); + if ($source->exists) { + $source->timestamp = filemtime($_return); + } else { + throw new SmartyException("Default handler: Unable to load " . + ($source->isConfig ? 'config' : 'template') . + " default file '{$_return}' for '{$source->type}:{$source->name}'"); + } + $source->name = $source->filepath = $_return; + $source->uid = sha1($source->filepath); + } elseif ($_return === true) { + $source->content = $_content; + $source->exists = true; + $source->uid = $source->name = sha1($_content); + $source->handler = Smarty_Resource::load($source->smarty, 'eval'); + } else { + $source->exists = false; + throw new SmartyException('Default handler: No ' . ($source->isConfig ? 'config' : 'template') . + " default content for '{$source->type}:{$source->name}'"); + } + } +} \ No newline at end of file -- cgit v1.2.3