Another fix in week view for negative hours.
[timetracker.git] / WEB-INF / lib / smarty / sysplugins / smarty_internal_resource_extends.php
1 <?php
2
3 /**
4  * Smarty Internal Plugin Resource Extends
5  * 
6  * Implements the file system as resource for Smarty which does extend a chain of template files templates
7  * 
8  * @package Smarty
9  * @subpackage TemplateResources
10  * @author Uwe Tews 
11  */
12
13 /**
14  * Smarty Internal Plugin Resource Extends
15  */
16 class Smarty_Internal_Resource_Extends {
17     public function __construct($smarty)
18     {
19         $this->smarty = $smarty;
20         $this->_rdl = preg_quote($smarty->right_delimiter);
21         $this->_ldl = preg_quote($smarty->left_delimiter);
22     } 
23     // classes used for compiling Smarty templates from file resource
24     public $compiler_class = 'Smarty_Internal_SmartyTemplateCompiler';
25     public $template_lexer_class = 'Smarty_Internal_Templatelexer';
26     public $template_parser_class = 'Smarty_Internal_Templateparser'; 
27     // properties
28     public $usesCompiler = true;
29     public $isEvaluated = false;
30     public $allFilepaths = array();
31
32     /**
33      * Return flag if template source is existing
34      * 
35      * @param object $_template template object
36      * @return boolean result
37      */
38     public function isExisting($_template)
39     {
40           $_template->getTemplateFilepath();
41           foreach ($this->allFilepaths as $_filepath) {
42                 if ($_filepath === false) {
43             return false;
44           }
45         }
46         return true;
47     } 
48     /**
49      * Get filepath to template source
50      * 
51      * @param object $_template template object
52      * @return string filepath to template source file
53      */
54     public function getTemplateFilepath($_template)
55     {
56         $sha1String = '';
57         $_files = explode('|', $_template->resource_name);
58         foreach ($_files as $_file) {
59             $_filepath = $_template->buildTemplateFilepath ($_file);
60             if ($_filepath !== false) {
61                 if (is_object($_template->smarty->security_policy)) {
62                         $_template->smarty->security_policy->isTrustedResourceDir($_filepath);
63                 } 
64             } 
65             $sha1String .= $_filepath;
66             $this->allFilepaths[$_file] = $_filepath;
67         } 
68         $_template->templateUid = sha1($sha1String);
69         return $_filepath;
70     } 
71
72     /**
73      * Get timestamp to template source
74      * 
75      * @param object $_template template object
76      * @return integer timestamp of template source file
77      */
78     public function getTemplateTimestamp($_template)
79     {
80         return filemtime($_template->getTemplateFilepath());
81     } 
82
83     /**
84      * Read template source from file
85      * 
86      * @param object $_template template object
87      * @return string content of template source file
88      */
89     public function getTemplateSource($_template)
90     {
91         $this->template = $_template;
92         $_files = array_reverse($this->allFilepaths);
93                 $_first = reset($_files);
94                 $_last = end($_files);
95         foreach ($_files as $_file => $_filepath) {
96                         if ($_filepath === false) {
97                         throw new SmartyException("Unable to load template 'file : {$_file}'");
98                         }
99             // read template file
100             if ($_filepath != $_first) {
101                 $_template->properties['file_dependency'][sha1($_filepath)] = array($_filepath, filemtime($_filepath),'file');
102             } 
103             $_template->template_filepath = $_filepath;
104             $_content = file_get_contents($_filepath);
105             if ($_filepath != $_last) {
106                 if (preg_match_all("!({$this->_ldl}block\s(.+?){$this->_rdl})!", $_content, $_open) !=
107                         preg_match_all("!({$this->_ldl}/block{$this->_rdl})!", $_content, $_close)) {
108                     $this->smarty->triggerError("unmatched {block} {/block} pairs in file '$_filepath'");
109                 } 
110                 preg_match_all("!{$this->_ldl}block\s(.+?){$this->_rdl}|{$this->_ldl}/block{$this->_rdl}!", $_content, $_result, PREG_OFFSET_CAPTURE);
111                 $_result_count = count($_result[0]);
112                 $_start = 0;
113                 while ($_start < $_result_count) {
114                     $_end = 0;
115                     $_level = 1;
116                     while ($_level != 0) {
117                         $_end++;
118                         if (!strpos($_result[0][$_start + $_end][0], '/')) {
119                             $_level++;
120                         } else {
121                             $_level--;
122                         } 
123                     } 
124                     $_block_content = str_replace($this->smarty->left_delimiter . '$smarty.block.parent' . $this->smarty->right_delimiter, '%%%%SMARTY_PARENT%%%%',
125                         substr($_content, $_result[0][$_start][1] + strlen($_result[0][$_start][0]), $_result[0][$_start + $_end][1] - $_result[0][$_start][1] - + strlen($_result[0][$_start][0])));
126                     Smarty_Internal_Compile_Block::saveBlockData($_block_content, $_result[0][$_start][0], $_template, $_filepath);
127                     $_start = $_start + $_end + 1;
128                 } 
129             } else {
130                 $_template->template_source = $_content;
131                 return true;
132             } 
133         } 
134     }
135     
136
137     /**
138      * Get filepath to compiled template
139      * 
140      * @param object $_template template object
141      * @return string return path to compiled template
142      */
143     public function getCompiledFilepath($_template)
144     {
145         $_compile_id = isset($_template->compile_id) ? preg_replace('![^\w\|]+!', '_', $_template->compile_id) : null;
146         $_files = explode('|', $_template->resource_name); 
147         // calculate Uid if not already done
148         if ($_template->templateUid == '') {
149             $_template->getTemplateFilepath();
150         } 
151         $_filepath = $_template->templateUid; 
152         // if use_sub_dirs, break file into directories
153         if ($_template->smarty->use_sub_dirs) {
154             $_filepath = substr($_filepath, 0, 2) . DS
155              . substr($_filepath, 2, 2) . DS
156              . substr($_filepath, 4, 2) . DS
157              . $_filepath;
158         } 
159         $_compile_dir_sep = $_template->smarty->use_sub_dirs ? DS : '^';
160         if (isset($_compile_id)) {
161             $_filepath = $_compile_id . $_compile_dir_sep . $_filepath;
162         } 
163         if ($_template->caching) {
164             $_cache = '.cache';
165         } else {
166             $_cache = '';
167         } 
168         $_compile_dir = $_template->smarty->compile_dir;
169         if (substr($_compile_dir, -1) != DS) {
170             $_compile_dir .= DS;
171         } 
172         return $_compile_dir . $_filepath . '.' . $_template->resource_type . '.' . basename($_files[count($_files)-1]) . $_cache . '.php';
173     } 
174
175
176 ?>