diff options
| author | Uwe.Tews <uwe.tews@localhost> | 2009-10-31 00:44:58 +0000 |
|---|---|---|
| committer | Uwe.Tews <uwe.tews@localhost> | 2009-10-31 00:44:58 +0000 |
| commit | cf379474fdcd2e9ef1381acfc4b72451f914edd6 (patch) | |
| tree | 19747b1bfa21b9d8939a005200aec9fe63e13898 /libs/sysplugins/smarty_internal_resource_php.php | |
| parent | 6efbb3ee586c9327295d18ee790394279bb1e25c (diff) | |
| download | smarty-cf379474fdcd2e9ef1381acfc4b72451f914edd6.tar.gz smarty-cf379474fdcd2e9ef1381acfc4b72451f914edd6.tar.bz2 smarty-cf379474fdcd2e9ef1381acfc4b72451f914edd6.zip | |
- change of filenames in sysplugins folder for internal spl_autoload function
- lexer/parser changed for increased compilation speed
Diffstat (limited to 'libs/sysplugins/smarty_internal_resource_php.php')
| -rw-r--r-- | libs/sysplugins/smarty_internal_resource_php.php | 145 |
1 files changed, 145 insertions, 0 deletions
diff --git a/libs/sysplugins/smarty_internal_resource_php.php b/libs/sysplugins/smarty_internal_resource_php.php new file mode 100644 index 00000000..f3ed97db --- /dev/null +++ b/libs/sysplugins/smarty_internal_resource_php.php @@ -0,0 +1,145 @@ +<?php + +/** +* Smarty Internal Plugin Resource PHP +* +* Implements the file system as resource for PHP templates +* +* @package Smarty +* @subpackage TemplateResources +* @author Uwe Tews +*/ +/** +* Smarty Internal Plugin Resource PHP +*/ +class Smarty_Internal_Resource_PHP { + /** + * Class constructor, enable short open tags + */ + public function __construct($smarty) + { + $this->smarty = $smarty; + ini_set('short_open_tag', '1'); + } + + /** + * Return flag if template source is existing + * + * @return boolean true + */ + public function isExisting($template) + { + if ($template->getTemplateFilepath() === false) { + return false; + } else { + return true; + } + } + + /** + * Get filepath to template source + * + * @param object $_template template object + * @return string filepath to template source file + */ + public function getTemplateFilepath($_template) + { + $_filepath = $_template->buildTemplateFilepath (); + + if ($_template->security) { + $_template->smarty->security_handler->isTrustedResourceDir($_filepath); + } + + return $_filepath; + } + + /** + * Get timestamp to template source + * + * @param object $_template template object + * @return integer timestamp of template source file + */ + public function getTemplateTimestamp($_template) + { + return filemtime($_template->getTemplateFilepath()); + } + + /** + * Read template source from file + * + * @param object $_template template object + * @return string content of template source file + */ + public function getTemplateSource($_template) + { + if (file_exists($_template->getTemplateFilepath())) { + $_template->template_source = file_get_contents($_template->getTemplateFilepath()); + return true; + } else { + return false; + } + } + + /** + * Return flag that this resource not use the compiler + * + * @return boolean false + */ + public function usesCompiler() + { + // does not use compiler, template is PHP + return false; + } + + /** + * Return flag that this is not evaluated + * + * @return boolean false + */ + public function isEvaluated() + { + // does not use compiler, must be false + return false; + } + + /** + * Get filepath to compiled template + * + * @param object $_template template object + * @return boolean return false as compiled template is not stored + */ + public function getCompiledFilepath($_template) + { + // no filepath for PHP templates + return false; + } + + /** + * renders the PHP template + */ + public function renderUncompiled($_smarty_template) + { + if (!$this->smarty->allow_php_templates) { + throw new Exception("PHP templates are disabled"); + } + if ($this->getTemplateFilepath($_smarty_template) === false) { + throw new Exception("Unable to load template \"{$_smarty_template->resource_type} : {$_smarty_template->resource_name}\""); + } + // prepare variables + $_smarty_ptr = $_smarty_template; + do { + foreach ($_smarty_ptr->tpl_vars as $_smarty_var => $_smarty_var_object) { + if (isset($_smarty_var_object->value)) { + $$_smarty_var = $_smarty_var_object->value; + } + } + $_smarty_ptr = $_smarty_ptr->parent; + } while ($_smarty_ptr != null); + unset ($_smarty_var, $_smarty_var_object, $_smarty_ptr); + // include PHP template + include($this->getTemplateFilepath($_smarty_template)); + return; + } +} + +?> |
