Хранилища Subversion ant

Редакция

Содержимое файла | Последнее изменение | Открыть журнал | RSS

Редакция Автор № строки Строка
304 alex-w 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
*/
15
class 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
 
25
    /**
26
    * Return flag if template source is existing
27
    *
28
    * @return boolean true
29
    */
30
    public function isExisting($template)
31
    {
32
        if ($template->getTemplateFilepath() === false) {
33
            return false;
34
        } else {
35
            return true;
36
        }
37
    }
38
 
39
    /**
40
    * Get filepath to template source
41
    *
42
    * @param object $_template template object
43
    * @return string filepath to template source file
44
    */
45
    public function getTemplateFilepath($_template)
46
    {
47
        $_filepath = $_template->buildTemplateFilepath ();
48
 
49
        if ($_template->security) {
50
            $_template->smarty->security_handler->isTrustedResourceDir($_filepath);
51
        }
52
 
53
        return $_filepath;
54
    }
55
 
56
    /**
57
    * Get timestamp to template source
58
    *
59
    * @param object $_template template object
60
    * @return integer timestamp of template source file
61
    */
62
    public function getTemplateTimestamp($_template)
63
    {
64
        return filemtime($_template->getTemplateFilepath());
65
    }
66
 
67
    /**
68
    * Read template source from file
69
    *
70
    * @param object $_template template object
71
    * @return string content of template source file
72
    */
73
    public function getTemplateSource($_template)
74
    {
75
        if (file_exists($_template->getTemplateFilepath())) {
76
            $_template->template_source = file_get_contents($_template->getTemplateFilepath());
77
            return true;
78
        } else {
79
            return false;
80
        }
81
    }
82
 
83
    /**
84
    * Return flag that this resource not use the compiler
85
    *
86
    * @return boolean false
87
    */
88
    public function usesCompiler()
89
    {
90
        // does not use compiler, template is PHP
91
        return false;
92
    }
93
 
94
    /**
95
    * Return flag that this is not evaluated
96
    *
97
    * @return boolean false
98
    */
99
    public function isEvaluated()
100
    {
101
        // does not use compiler, must be false
102
        return false;
103
    }
104
 
105
    /**
106
    * Get filepath to compiled template
107
    *
108
    * @param object $_template template object
109
    * @return boolean return false as compiled template is not stored
110
    */
111
    public function getCompiledFilepath($_template)
112
    {
113
        // no filepath for PHP templates
114
        return false;
115
    }
116
 
117
    /**
118
    * renders the PHP template
119
    */
120
    public function renderUncompiled($_smarty_template)
121
    {
122
        if (!$this->smarty->allow_php_templates) {
123
            throw new Exception("PHP templates are disabled");
124
        }
125
        if ($this->getTemplateFilepath($_smarty_template) === false) {
126
            throw new Exception("Unable to load template \"{$_smarty_template->resource_type} : {$_smarty_template->resource_name}\"");
127
        }
128
        // prepare variables
129
        $_smarty_ptr = $_smarty_template;
130
        do {
131
            foreach ($_smarty_ptr->tpl_vars as $_smarty_var => $_smarty_var_object) {
132
                if (isset($_smarty_var_object->value)) {
133
                    $$_smarty_var = $_smarty_var_object->value;
134
                }
135
            }
136
            $_smarty_ptr = $_smarty_ptr->parent;
137
        } while ($_smarty_ptr != null);
138
        unset ($_smarty_var, $_smarty_var_object, $_smarty_ptr);
139
        // include PHP template
140
        include($this->getTemplateFilepath($_smarty_template));
141
        return;
142
    }
143
}
144
 
145
?>