PageRenderTime 14ms CodeModel.GetById 9ms app.highlight 3ms RepoModel.GetById 0ms app.codeStats 0ms

/framework/vendor/smarty3/lib/libs/sysplugins/smarty_internal_resource_php.php

http://zoop.googlecode.com/
PHP | 127 lines | 66 code | 10 blank | 51 comment | 10 complexity | 9692e0f0a088fa3ec1e39bfc7577319c MD5 | raw file
  1<?php
  2
  3/**
  4* Smarty Internal Plugin Resource PHP
  5* 
  6* Implements the file system as resource for PHP templates
  7* 
  8* @package Smarty
  9* @subpackage TemplateResources
 10* @author Uwe Tews 
 11*/
 12/**
 13* Smarty Internal Plugin Resource PHP
 14*/
 15class Smarty_Internal_Resource_PHP {
 16    /**
 17    * Class constructor, enable short open tags
 18    */
 19    public function __construct($smarty)
 20    {
 21        $this->smarty = $smarty;
 22        ini_set('short_open_tag', '1');
 23    } 
 24    // properties
 25    public $usesCompiler = false;
 26    public $isEvaluated = false;
 27
 28    /**
 29    * Return flag if template source is existing
 30    * 
 31    * @return boolean true
 32    */
 33    public function isExisting($template)
 34    {
 35        if ($template->getTemplateFilepath() === false) {
 36            return false;
 37        } else {
 38            return true;
 39        } 
 40    } 
 41
 42    /**
 43    * Get filepath to template source
 44    * 
 45    * @param object $_template template object
 46    * @return string filepath to template source file
 47    */
 48    public function getTemplateFilepath($_template)
 49    {
 50        $_filepath = $_template->buildTemplateFilepath ();
 51
 52        if ($_template->security) {
 53            $_template->smarty->security_handler->isTrustedResourceDir($_filepath);
 54        } 
 55        $_template->templateUid = sha1($_filepath);
 56        return $_filepath;
 57    } 
 58
 59    /**
 60    * Get timestamp to template source
 61    * 
 62    * @param object $_template template object
 63    * @return integer timestamp of template source file
 64    */
 65    public function getTemplateTimestamp($_template)
 66    {
 67        return filemtime($_template->getTemplateFilepath());
 68    } 
 69
 70    /**
 71    * Read template source from file
 72    * 
 73    * @param object $_template template object
 74    * @return string content of template source file
 75    */
 76    public function getTemplateSource($_template)
 77    {
 78        if (file_exists($_template->getTemplateFilepath())) {
 79            $_template->template_source = file_get_contents($_template->getTemplateFilepath());
 80            return true;
 81        } else {
 82            return false;
 83        } 
 84    } 
 85
 86
 87    /**
 88    * Get filepath to compiled template
 89    * 
 90    * @param object $_template template object
 91    * @return boolean return false as compiled template is not stored
 92    */
 93    public function getCompiledFilepath($_template)
 94    { 
 95        // no filepath for PHP templates
 96        return false;
 97    } 
 98
 99    /**
100    * renders the PHP template
101    */
102    public function renderUncompiled($_smarty_template)
103    {
104        if (!$this->smarty->allow_php_templates) {
105            throw new Exception("PHP templates are disabled");
106        } 
107        if ($this->getTemplateFilepath($_smarty_template) === false) {
108            throw new Exception("Unable to load template \"{$_smarty_template->resource_type} : {$_smarty_template->resource_name}\"");
109        } 
110        // prepare variables
111        $_smarty_ptr = $_smarty_template;
112        do {
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;
116                } 
117            } 
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));
123        return;
124    } 
125} 
126
127?>