Initial repo created
[timetracker.git] / WEB-INF / lib / smarty / sysplugins / smarty_internal_resource_string.php
1 <?php
2
3 /**
4  * Smarty Internal Plugin Resource String
5  * 
6  * Implements the strings as resource for Smarty template
7  * 
8  * @package Smarty
9  * @subpackage TemplateResources
10  * @author Uwe Tews 
11  */
12  
13 /**
14  * Smarty Internal Plugin Resource String
15  */
16 class Smarty_Internal_Resource_String {
17     public function __construct($smarty)
18     {
19         $this->smarty = $smarty;
20     } 
21     // classes used for compiling Smarty templates from file resource
22     public $compiler_class = 'Smarty_Internal_SmartyTemplateCompiler';
23     public $template_lexer_class = 'Smarty_Internal_Templatelexer';
24     public $template_parser_class = 'Smarty_Internal_Templateparser';
25     // properties
26     public $usesCompiler = true;
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         return true;
37     } 
38
39     /**
40      * Get filepath to template source
41      * 
42      * @param object $_template template object
43      * @return string return 'string' as template source is not a file
44      */
45     public function getTemplateFilepath($_template)
46     { 
47         $_template->templateUid = sha1($_template->resource_name);
48         // no filepath for strings
49         // return "string" for compiler error messages
50         return 'string:';
51     } 
52
53     /**
54      * Get timestamp to template source
55      * 
56      * @param object $_template template object
57      * @return boolean false as string resources have no timestamp
58      */
59     public function getTemplateTimestamp($_template)
60     { 
61         if ($this->isEvaluated) {
62                 //must always be compiled and have no timestamp
63                 return false;
64         } else {
65                 return 0;
66         }
67     } 
68
69     /**
70      * Get timestamp of template source by type and name
71      * 
72      * @param object $_template template object
73      * @return int  timestamp (always 0)
74      */
75     public function getTemplateTimestampTypeName($_resource_type, $_resource_name)
76     { 
77         // return timestamp 0
78         return 0;
79     } 
80
81
82     /**
83      * Retuen template source from resource name
84      * 
85      * @param object $_template template object
86      * @return string content of template source
87      */
88     public function getTemplateSource($_template)
89     { 
90         // return template string
91         $_template->template_source = $_template->resource_name;
92         return true;
93     } 
94
95     /**
96      * Get filepath to compiled template
97      * 
98      * @param object $_template template object
99      * @return boolean return false as compiled template is not stored
100      */
101     public function getCompiledFilepath($_template)
102     {
103         $_compile_id = isset($_template->compile_id) ? preg_replace('![^\w\|]+!', '_', $_template->compile_id) : null;
104         // calculate Uid if not already done
105         if ($_template->templateUid == '') {
106             $_template->getTemplateFilepath();
107         } 
108         $_filepath = $_template->templateUid; 
109         // if use_sub_dirs, break file into directories
110         if ($_template->smarty->use_sub_dirs) {
111             $_filepath = substr($_filepath, 0, 2) . DS
112              . substr($_filepath, 2, 2) . DS
113              . substr($_filepath, 4, 2) . DS
114              . $_filepath;
115         } 
116         $_compile_dir_sep = $_template->smarty->use_sub_dirs ? DS : '^';
117         if (isset($_compile_id)) {
118             $_filepath = $_compile_id . $_compile_dir_sep . $_filepath;
119         } 
120         if ($_template->caching) {
121             $_cache = '.cache';
122         } else {
123             $_cache = '';
124         } 
125         $_compile_dir = $_template->smarty->compile_dir;
126         if (strpos('/\\', substr($_compile_dir, -1)) === false) {
127             $_compile_dir .= DS;
128         } 
129         return $_compile_dir . $_filepath . '.' . $_template->resource_type . $_cache . '.php';
130     } 
131
132
133 ?>