Содержимое файла | Последнее изменение | Открыть журнал | RSS
Редакция | Автор | № строки | Строка |
---|---|---|---|
304 | alex-w | 1 | <?php |
2 | |||
3 | /** |
||
4 | * Smarty Internal Plugin Resource File |
||
5 | * |
||
6 | * Implements the file system as resource for Smarty templates |
||
7 | * |
||
8 | * @package Smarty |
||
9 | * @subpackage TemplateResources |
||
10 | * @author Uwe Tews |
||
11 | */ |
||
12 | /** |
||
13 | * Smarty Internal Plugin Resource File |
||
14 | */ |
||
15 | class Smarty_Internal_Resource_File { |
||
16 | public function __construct($smarty) |
||
17 | { |
||
18 | $this->smarty = $smarty; |
||
19 | } |
||
20 | // classes used for compiling Smarty templates from file resource |
||
21 | public $compiler_class = 'Smarty_Internal_SmartyTemplateCompiler'; |
||
22 | public $template_lexer_class = 'Smarty_Internal_Templatelexer'; |
||
23 | public $template_parser_class = 'Smarty_Internal_Templateparser'; |
||
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 ($_filepath !== false) { |
||
50 | if ($_template->security) { |
||
51 | $_template->smarty->security_handler->isTrustedResourceDir($_filepath); |
||
52 | } |
||
53 | } |
||
54 | return $_filepath; |
||
55 | } |
||
56 | |||
57 | /** |
||
58 | * Get timestamp to template source |
||
59 | * |
||
60 | * @param object $_template template object |
||
61 | * @return integer timestamp of template source file |
||
62 | */ |
||
63 | public function getTemplateTimestamp($_template) |
||
64 | { |
||
65 | return filemtime($_template->getTemplateFilepath()); |
||
66 | } |
||
67 | |||
68 | /** |
||
69 | * Read template source from file |
||
70 | * |
||
71 | * @param object $_template template object |
||
72 | * @return string content of template source file |
||
73 | */ |
||
74 | public function getTemplateSource($_template) |
||
75 | { |
||
76 | // read template file |
||
77 | if (file_exists($_template->getTemplateFilepath())) { |
||
78 | $_template->template_source = file_get_contents($_template->getTemplateFilepath()); |
||
79 | return true; |
||
80 | } else { |
||
81 | return false; |
||
82 | } |
||
83 | } |
||
84 | |||
85 | /** |
||
86 | * Return flag that this resource uses the compiler |
||
87 | * |
||
88 | * @return boolean true |
||
89 | */ |
||
90 | public function usesCompiler() |
||
91 | { |
||
92 | // template has tags, uses compiler |
||
93 | return true; |
||
94 | } |
||
95 | |||
96 | /** |
||
97 | * Return flag that this is not evaluated |
||
98 | * |
||
99 | * @return boolean false |
||
100 | */ |
||
101 | public function isEvaluated() |
||
102 | { |
||
103 | // save the compiled file to disk, do not evaluate |
||
104 | return false; |
||
105 | } |
||
106 | /** |
||
107 | * Get filepath to compiled template |
||
108 | * |
||
109 | * @param object $_template template object |
||
110 | * @return string return path to compiled template |
||
111 | */ |
||
112 | public function getCompiledFilepath($_template) |
||
113 | { |
||
114 | // $_filepath = md5($_template->resource_name); |
||
115 | $_filepath = (string)abs(crc32($_template->resource_name)); |
||
116 | // if use_sub_dirs, break file into directories |
||
117 | if ($_template->smarty->use_sub_dirs) { |
||
118 | $_filepath = substr($_filepath, 0, 3) . DS |
||
119 | . substr($_filepath, 0, 2) . DS |
||
120 | . substr($_filepath, 0, 1) . DS |
||
121 | . $_filepath; |
||
122 | } |
||
123 | $_compile_dir_sep = $_template->smarty->use_sub_dirs ? DS : '^'; |
||
124 | if (isset($_template->compile_id)) { |
||
125 | $_filepath = $_template->compile_id . $_compile_dir_sep . $_filepath; |
||
126 | } |
||
127 | if ($_template->caching) { |
||
128 | $_cache = '.cache'; |
||
129 | } else { |
||
130 | $_cache = ''; |
||
131 | } |
||
132 | $_compile_dir = $_template->smarty->compile_dir; |
||
133 | if (strpos('/\\', substr($_compile_dir, -1)) === false) { |
||
134 | $_compile_dir .= DS; |
||
135 | } |
||
136 | return $_compile_dir . $_filepath . '.' . $_template->resource_type . '.' . basename($_template->resource_name). $_cache . $_template->smarty->php_ext; |
||
137 | } |
||
138 | } |
||
139 | |||
140 | ?> |