libs/sysplugins/smarty_template_compiled.php Quellcode

smarty_template_compiled.php
gehe zur Dokumentation dieser Datei
1 <?php
2 
13 {
19  public $filepath = null;
20 
26  public $timestamp = null;
27 
33  public $exists = false;
34 
40  public $processed = false;
46  public $code = null;
47 
51  public function __construct()
52  {
53  }
54 
62  static function load($_template)
63  {
64  if (!isset($_template->source)) {
65  $_template->loadSource();
66  }
67  // check runtime cache
68  if (!$_template->source->recompiled && $_template->smarty->resource_caching) {
69  $_cache_key = $_template->source->unique_resource . '#';
70  if ($_template->caching) {
71  $_cache_key .= 'caching#';
72  }
73  $_cache_key .= $_template->compile_id;
74  if (isset($_template->source->compileds[$_cache_key])) {
75  return $_template->source->compileds[$_cache_key];
76  }
77  }
78  $compiled = new Smarty_Template_Compiled();
79  if (method_exists($_template->source->handler, 'populateCompiledFilepath')) {
80  $_template->source->handler->populateCompiledFilepath($compiled, $_template);
81  } else {
82  $compiled->populateCompiledFilepath($_template);
83  }
84  // runtime cache
85  if (!$_template->source->recompiled && $_template->smarty->resource_caching) {
86  $_template->source->compileds[$_cache_key] = $compiled;
87  }
88  return $compiled;
89  }
90 
97  {
98  $_compile_id = isset($_template->compile_id) ? preg_replace('![^\w\|]+!', '_', $_template->compile_id) : null;
99  if ($_template->source->isConfig) {
100  $_flag = '_' . ((int) $_template->smarty->config_read_hidden + (int) $_template->smarty->config_booleanize * 2
101  + (int) $_template->smarty->config_overwrite * 4);
102  } else {
103  $_flag = '_' . ((int) $_template->smarty->merge_compiled_includes + (int) $_template->smarty->escape_html * 2);
104  }
105  $_filepath = $_template->source->uid . $_flag;
106  // if use_sub_dirs, break file into directories
107  if ($_template->smarty->use_sub_dirs) {
108  $_filepath = substr($_filepath, 0, 2) . DS
109  . substr($_filepath, 2, 2) . DS
110  . substr($_filepath, 4, 2) . DS
111  . $_filepath;
112  }
113  $_compile_dir_sep = $_template->smarty->use_sub_dirs ? DS : '^';
114  if (isset($_compile_id)) {
115  $_filepath = $_compile_id . $_compile_dir_sep . $_filepath;
116  }
117  // caching token
118  if ($_template->caching) {
119  $_cache = '.cache';
120  } else {
121  $_cache = '';
122  }
123  $_compile_dir = $_template->smarty->getCompileDir();
124  // set basename if not specified
125  $_basename = $_template->source->handler->getBasename($_template->source);
126  if ($_basename === null) {
127  $_basename = basename(preg_replace('![^\w\/]+!', '_', $_template->source->name));
128  }
129  // separate (optional) basename by dot
130  if ($_basename) {
131  $_basename = '.' . $_basename;
132  }
133 
134  $this->filepath = $_compile_dir . $_filepath . '.' . $_template->source->type . $_basename . $_cache . '.php';
135  $this->timestamp = $this->exists = is_file($this->filepath);
136  if ($this->exists) {
137  $this->timestamp = @filemtime($this->filepath);
138  }
139  }
140 
148  public function process(Smarty_Internal_Template $_template)
149  {
150  $_smarty_tpl = $_template;
151  if ($_template->source->recompiled || !$_template->compiled->exists || $_template->smarty->force_compile) {
152  $this->compileTemplateSource($_template);
153  $compileCheck = $_template->smarty->compile_check;
154  $_template->smarty->compile_check = false;
155  if ($_template->source->recompiled) {
156  $level = ob_get_level();
157  ob_start();
158  try {
159  eval("?>" . $this->code);
160  }
161  catch (Exception $e) {
162  while (ob_get_level() > $level) {
163  ob_end_clean();
164  }
165  throw $e;
166  }
167  ob_get_clean();
168  $this->code = null;
169  } else {
170  include($_template->compiled->filepath);
171  }
172  $_template->smarty->compile_check = $compileCheck;
173  } else {
174  include($_template->compiled->filepath);
175  if ($_template->mustCompile) {
176  $this->compileTemplateSource($_template);
177  $compileCheck = $_template->smarty->compile_check;
178  $_template->smarty->compile_check = false;
179  include($_template->compiled->filepath);
180  $_template->smarty->compile_check = $compileCheck;
181  }
182  }
183  $this->unifunc = $_template->properties['unifunc'];
184  $this->processed = true;
185  }
186 
195  public function render(Smarty_Internal_Template $_template)
196  {
197 
198  if (!$this->processed) {
199  $this->process($_template);
200  }
201  $_template->properties['unifunc'] = $this->unifunc;
202  return $_template->getRenderedTemplateCode();
203  }
204 
214  {
215  if (!$_template->source->recompiled) {
216  $_template->properties['file_dependency'] = array();
217  }
218  // compile locking
219  if (!$_template->source->recompiled) {
220  if ($saved_timestamp = $_template->compiled->timestamp) {
221  touch($_template->compiled->filepath);
222  }
223  }
224  // call compiler
225  try {
226  $code = $_template->compiler->compileTemplate($_template);
227  }
228  catch (Exception $e) {
229  // restore old timestamp in case of error
230  if (!$_template->source->recompiled && $saved_timestamp) {
231  touch($_template->compiled->filepath, $saved_timestamp);
232  }
233  throw $e;
234  }
235  // compiling succeeded
236  if ($_template->compiler->write_compiled_code) {
237  // write compiled template
238  $this->write($_template, $code);
239  $code = '';
240  }
241  // release compiler object to free memory
242  unset($_template->compiler);
243  return $code;
244  }
245 
254  public function write(Smarty_Internal_Template $_template, $code)
255  {
256  if (!$_template->source->recompiled) {
257  $obj = new Smarty_Internal_Write_File();
258  if ($obj->writeFile($this->filepath, $code, $_template->smarty) === true) {
259  $this->timestamp = $this->exists = is_file($this->filepath);
260  if ($this->exists) {
261  $this->timestamp = @filemtime($this->filepath);
262  return true;
263  }
264  }
265  return false;
266  } else {
267  $this->code = $code;
268  }
269  $this->timestamp = time();
270  $this->exists = true;
271  return true;
272  }
273 
281  public function read(Smarty_Internal_Template $_template)
282  {
283  if (!$_template->source->recompiled) {
284  return file_get_contents($this->filepath);
285  }
286  return isset($this->content) ? $this->content : false;
287  }
288 }




Korrekturen, Hinweise und Ergänzungen

Bitte scheuen Sie sich nicht und melden Sie, was auf dieser Seite sachlich falsch oder irreführend ist, was ergänzt werden sollte, was fehlt usw. Dazu bitte oben aus dem Menü Seite den Eintrag Support Forum wählen. Es ist eine kostenlose Anmeldung erforderlich, um Anmerkungen zu posten. Unpassende Postings, Spam usw. werden kommentarlos entfernt.