4  * Smarty Internal Plugin Resource PHP
 
   6  * Implements the file system as resource for PHP templates
 
   9  * @subpackage TemplateResources
 
  14  * Smarty Internal Plugin Resource PHP
 
  16 class Smarty_Internal_Resource_PHP {
 
  18      * Class constructor, enable short open tags
 
  20     public function __construct($smarty)
 
  22         $this->smarty = $smarty;
 
  23         ini_set('short_open_tag', '1');
 
  26     public $usesCompiler = false;
 
  27     public $isEvaluated = false;
 
  30      * Return flag if template source is existing
 
  32      * @return boolean true
 
  34     public function isExisting($template)
 
  36         if ($template->getTemplateFilepath() === false) {
 
  44      * Get filepath to template source
 
  46      * @param object $_template template object
 
  47      * @return string filepath to template source file
 
  49     public function getTemplateFilepath($_template)
 
  51         $_filepath = $_template->buildTemplateFilepath ();
 
  53         if (is_object($_template->smarty->security_policy)) {
 
  54             $_template->smarty->security_policy->isTrustedResourceDir($_filepath);
 
  56         $_template->templateUid = sha1($_filepath);
 
  61      * Get timestamp to template source
 
  63      * @param object $_template template object
 
  64      * @return integer timestamp of template source file
 
  66     public function getTemplateTimestamp($_template)
 
  68         return filemtime($_template->getTemplateFilepath());
 
  72      * Read template source from file
 
  74      * @param object $_template template object
 
  75      * @return string content of template source file
 
  77     public function getTemplateSource($_template)
 
  79         if (file_exists($_tfp = $_template->getTemplateFilepath())) {
 
  80             $_template->template_source = file_get_contents($_tfp);
 
  88      * Get filepath to compiled template
 
  90      * @param object $_template template object
 
  91      * @return boolean return false as compiled template is not stored
 
  93     public function getCompiledFilepath($_template)
 
  95         // no filepath for PHP templates
 
 100      * renders the PHP template
 
 102     public function renderUncompiled($_smarty_template)
 
 104         if (!$this->smarty->allow_php_templates) {
 
 105             throw new SmartyException("PHP templates are disabled");
 
 107         if ($this->getTemplateFilepath($_smarty_template) === false) {
 
 108             throw new SmartyException("Unable to load template \"{$_smarty_template->resource_type} : {$_smarty_template->resource_name}\"");
 
 111         $_smarty_ptr = $_smarty_template;
 
 113             foreach ($_smarty_ptr->tpl_vars as $_smarty_var => $_smarty_var_object) {
 
 114                 if (isset($_smarty_var_object->value)) {
 
 115                     $$_smarty_var = $_smarty_var_object->value;
 
 118             $_smarty_ptr = $_smarty_ptr->parent;
 
 119         } while ($_smarty_ptr != null);
 
 120         unset ($_smarty_var, $_smarty_var_object, $_smarty_ptr); 
 
 121         // include PHP template
 
 122         include($this->getTemplateFilepath($_smarty_template));