Initial repo created
[timetracker.git] / WEB-INF / lib / smarty / sysplugins / smarty_internal_resource_php.php
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 /**
14  * Smarty Internal Plugin Resource PHP
15  */
16 class Smarty_Internal_Resource_PHP {
17     /**
18      * Class constructor, enable short open tags
19      */
20     public function __construct($smarty)
21     {
22         $this->smarty = $smarty;
23         ini_set('short_open_tag', '1');
24     } 
25     // properties
26     public $usesCompiler = false;
27     public $isEvaluated = false;
28
29     /**
30      * Return flag if template source is existing
31      * 
32      * @return boolean true
33      */
34     public function isExisting($template)
35     {
36         if ($template->getTemplateFilepath() === false) {
37             return false;
38         } else {
39             return true;
40         } 
41     } 
42
43     /**
44      * Get filepath to template source
45      * 
46      * @param object $_template template object
47      * @return string filepath to template source file
48      */
49     public function getTemplateFilepath($_template)
50     {
51         $_filepath = $_template->buildTemplateFilepath ();
52
53         if (is_object($_template->smarty->security_policy)) {
54             $_template->smarty->security_policy->isTrustedResourceDir($_filepath);
55         } 
56         $_template->templateUid = sha1($_filepath);
57         return $_filepath;
58     } 
59
60     /**
61      * Get timestamp to template source
62      * 
63      * @param object $_template template object
64      * @return integer timestamp of template source file
65      */
66     public function getTemplateTimestamp($_template)
67     {
68         return filemtime($_template->getTemplateFilepath());
69     } 
70
71     /**
72      * Read template source from file
73      * 
74      * @param object $_template template object
75      * @return string content of template source file
76      */
77     public function getTemplateSource($_template)
78     {
79         if (file_exists($_tfp = $_template->getTemplateFilepath())) {
80             $_template->template_source = file_get_contents($_tfp);
81             return true;
82         } else {
83             return false;
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 SmartyException("PHP templates are disabled");
106         } 
107         if ($this->getTemplateFilepath($_smarty_template) === false) {
108             throw new SmartyException("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 ?>