Хранилища Subversion ant

Редакция

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

Редакция Автор № строки Строка
304 alex-w 1
<?php
2
 
3
/**
4
* Smarty Internal Plugin Template
5
*
6
* This files contains the Smarty template engine
7
*
8
* @package Smarty
9
* @subpackage Templates
10
* @author Uwe Tews
11
*/
12
 
13
/**
14
* Main class with template data structures and methods
15
*/
16
class Smarty_Internal_Template extends Smarty_Internal_TemplateBase {
17
    // object cache
18
    public $compiler_object = null;
19
    public $cacher_object = null;
20
    // Smarty parameter
21
    public $cache_id = null;
22
    public $compile_id = null;
23
    public $caching = null;
24
    public $cache_lifetime = null;
25
    public $cacher_class = null;
26
    public $caching_type = null;
27
    public $force_compile = null;
28
    // Template resource
29
    public $template_resource = null;
30
    public $resource_type = null;
31
    public $resource_name = null;
32
    private $usesCompiler = null;
33
    private $isEvaluated = null;
34
    private $isExisting = null;
35
    // Template source
36
    public $template_filepath = null;
37
    public $template_source = null;
38
    private $template_timestamp = null;
39
    // Compiled template
40
    private $compiled_filepath = null;
41
    public $compiled_template = null;
42
    private $compiled_timestamp = null;
43
    public $compile_time = 0;
44
    public $mustCompile = null;
45
    public $suppressHeader = false;
46
    public $extract_code = false;
47
    public $extracted_compiled_code = '';
48
    // Rendered content
49
    public $rendered_content = null;
50
    // Cache file
51
    private $cached_filepath = null;
52
    private $cached_timestamp = null;
53
    private $isCached = null;
54
    public $cache_time = 0;
55
    // template variables
56
    public $tpl_vars = array();
57
    public $parent = null;
58
    public $config_vars = array();
59
    // storage for plugin
60
    public $plugin_data = array();
61
    // special properties
62
    public $properties = array();
63
    // storage for block data
64
    public $block_data = array();
65
 
66
    public $render_time = 0;
67
 
68
    /**
69
    * Create template data object
70
    *
71
    * Some of the global Smarty settings copied to template scope
72
    * It load the required template resources and cacher plugins
73
    *
74
    * @param string $template_resource template resource string
75
    * @param object $_parent back pointer to parent object with variables or null
76
    * @param mixed $_cache_id cache id or null
77
    * @param mixed $_compile_id compile id or null
78
    */
79
    public function __construct($template_resource, $smarty, $_parent = null, $_cache_id = null, $_compile_id = null)
80
    {
81
        $this->smarty = $smarty;
82
        // Smarty parameter
83
        $this->cache_id = $_cache_id === null ? $this->smarty->cache_id : $_cache_id;
84
        $this->compile_id = $_compile_id === null ? $this->smarty->compile_id : $_compile_id;
85
        $this->force_compile = $this->smarty->force_compile;
86
        $this->caching = $this->smarty->caching;
87
        $this->cache_lifetime = $this->smarty->cache_lifetime;
88
        $this->force_cache = $this->smarty->force_cache;
89
        $this->cacher_class = $this->smarty->cacher_class;
90
        $this->caching_type = $this->smarty->default_caching_type;
91
        $this->security = $this->smarty->security;
92
        $this->cache_resource_class = 'Smarty_Internal_CacheResource_' . ucfirst($this->caching_type);
93
        $this->parent = $_parent;
94
        $this->properties['file_dependency'] = array();
95
        // dummy local smarty variable
96
        $this->tpl_vars['smarty'] = new Smarty_Variable;
97
        // Template resource
98
        $this->template_resource = $template_resource;
99
        // parse resource name
100
        if (!$this->parseResourceName ($template_resource, $this->resource_type, $this->resource_name, $dummy)) {
101
            throw new Exception ("Unable to parse resource name \"{$template_resource}\"");
102
        }
103
        // load cache resource
104
        if (!$this->isEvaluated() && $this->caching && !isset($this->smarty->cache_resource_objects[$this->caching_type])) {
105
            $this->smarty->loadPlugin($this->cache_resource_class);
106
            $this->smarty->cache_resource_objects[$this->caching_type] = new $this->cache_resource_class($this->smarty);
107
        }
108
    }
109
 
110
    /**
111
    * Returns the template filepath
112
    *
113
    * The template filepath is determined by the actual resource handler
114
    *
115
    * @return string the template filepath
116
    */
117
    public function getTemplateFilepath ()
118
    {
119
        return $this->template_filepath === null ?
120
        $this->template_filepath = $this->smarty->resource_objects[$this->resource_type]->getTemplateFilepath($this) :
121
        $this->template_filepath;
122
    }
123
 
124
    /**
125
    * Returns the timpestamp of the template source
126
    *
127
    * The template timestamp is determined by the actual resource handler
128
    *
129
    * @return integer the template timestamp
130
    */
131
    public function getTemplateTimestamp ()
132
    {
133
        return $this->template_timestamp === null ?
134
        $this->template_timestamp = $this->smarty->resource_objects[$this->resource_type]->getTemplateTimestamp($this) :
135
        $this->template_timestamp;
136
    }
137
 
138
    /**
139
    * Returns the template source code
140
    *
141
    * The template source is being read by the actual resource handler
142
    *
143
    * @return string the template source
144
    */
145
    public function getTemplateSource ()
146
    {
147
        if ($this->template_source === null) {
148
            if (!$this->smarty->resource_objects[$this->resource_type]->getTemplateSource($this)) {
149
                throw new Exception("Unable to read template '{$this->resource_name}'");
150
            }
151
        }
152
        return $this->template_source;
153
    }
154
 
155
    /**
156
    * Returns if the  template is existing
157
    *
158
    * The status is determined by the actual resource handler
159
    *
160
    * @return boolean true if the template exists
161
    */
162
    public function isExisting ($error= false)
163
    {
164
        if ($this->isExisting === null) {
165
        $this->isExisting = $this->smarty->resource_objects[$this->resource_type]->isExisting($this);
166
        }
167
        if (!$this->isExisting && $error) {
168
            throw new Exception("Unable to load template \"{$this->resource_type} : {$this->resource_name}\"");
169
        }
170
        return $this->isExisting;
171
    }
172
    /**
173
    * Returns if the template resource uses the Smarty compiler
174
    *
175
    * The status is determined by the actual resource handler
176
    *
177
    * @return boolean true if the template will use the compiler
178
    */
179
    public function usesCompiler ()
180
    {
181
        return $this->usesCompiler === null ?
182
        $this->usesCompiler = $this->smarty->resource_objects[$this->resource_type]->usesCompiler() :
183
        $this->usesCompiler;
184
    }
185
 
186
    /**
187
    * Returns if the compiled template is stored or just evaluated in memory
188
    *
189
    * The status is determined by the actual resource handler
190
    *
191
    * @return boolean true if the compiled template has to be evaluated
192
    */
193
    public function isEvaluated ()
194
    {
195
        return $this->isEvaluated === null ?
196
        $this->isEvaluated = $this->smarty->resource_objects[$this->resource_type]->isEvaluated() :
197
        $this->isEvaluated;
198
    }
199
 
200
    /**
201
    * Returns if the current template must be compiled by the Smarty compiler
202
    *
203
    * It does compare the timestamps of template source and the compiled templates and checks the force compile configuration
204
    *
205
    * @return boolean true if the template must be compiled
206
    */
207
    public function mustCompile ()
208
    {
209
        $this->isExisting(true);
210
 
211
        if ($this->mustCompile === null) {
212
            $this->mustCompile = ($this->usesCompiler() && ($this->force_compile || $this->isEvaluated() || ($this->smarty->compile_check && $this->getCompiledTimestamp () !== $this->getTemplateTimestamp ())));
213
        }
214
        return $this->mustCompile;
215
    }
216
 
217
    /**
218
    * Returns the compiled template filepath
219
    *
220
    * @return string the template filepath
221
    */
222
    public function getCompiledFilepath ()
223
    {
224
        return $this->compiled_filepath === null ?
225
        ($this->compiled_filepath = !$this->isEvaluated() ? $this->smarty->resource_objects[$this->resource_type]->getCompiledFilepath($this) : false) :
226
        $this->compiled_filepath;
227
    }
228
 
229
    /**
230
    * Returns the timpestamp of the compiled template
231
    *
232
    * @return integer the template timestamp
233
    */
234
    public function getCompiledTimestamp ()
235
    {
236
        return $this->compiled_timestamp === null ?
237
        ($this->compiled_timestamp = (!$this->isEvaluated() && file_exists($this->getCompiledFilepath())) ? filemtime($this->getCompiledFilepath()) : false) :
238
        $this->compiled_timestamp;
239
    }
240
 
241
    /**
242
    * Returns the compiled template
243
    *
244
    * It checks if the template must be compiled or just read from the template resource
245
    *
246
    * @return string the compiled template
247
    */
248
    public function getCompiledTemplate ()
249
    {
250
        if ($this->compiled_template === null) {
251
            // see if template needs compiling.
252
            if ($this->mustCompile()) {
253
                $this->compileTemplateSource();
254
            } else {
255
                if ($this->compiled_template === null) {
256
                    $this->compiled_template = !$this->isEvaluated() && $this->usesCompiler() ? file_get_contents($this->getCompiledFilepath()) : false;
257
                }
258
            }
259
        }
260
        return $this->compiled_template;
261
    }
262
 
263
    /**
264
    * Compiles the template
265
    *
266
    * If the template is not evaluated the compiled template is saved on disk
267
    */
268
    public function compileTemplateSource ()
269
    {
270
        $_start_time = $this->_get_time();
271
        if (!$this->isEvaluated) {
272
            $this->properties['file_dependency']['F' . abs(crc32($this->getTemplateFilepath()))] = array($this->getTemplateFilepath(), $this->getTemplateTimestamp());
273
        }
274
        // compile template
275
        if (!is_object($this->compiler_object)) {
276
            // load compiler
277
            require_once(SMARTY_SYSPLUGINS_DIR . 'internal.compilebase.php');
278
            require_once(SMARTY_SYSPLUGINS_DIR . 'internal.templatecompilerbase.php');
279
            // $this->smarty->loadPlugin('Smarty_Internal_CompileBase');
280
            // $this->smarty->loadPlugin('Smarty_Internal_TemplateCompilerBase');
281
            $this->smarty->loadPlugin($this->smarty->resource_objects[$this->resource_type]->compiler_class);
282
            $this->compiler_object = new $this->smarty->resource_objects[$this->resource_type]->compiler_class($this->smarty->resource_objects[$this->resource_type]->template_lexer_class, $this->smarty->resource_objects[$this->resource_type]->template_parser_class, $this->smarty);
283
            // load cacher
284
            if ($this->caching) {
285
                $this->smarty->loadPlugin($this->cacher_class);
286
                $this->cacher_object = new $this->cacher_class($this->smarty);
287
            }
288
        }
289
        if (!is_object($this->smarty->write_file_object)) {
290
            require_once(SMARTY_SYSPLUGINS_DIR . 'internal.write_file.php');
291
            // $this->smarty->loadPlugin("Smarty_Internal_Write_File");
292
            $this->smarty->write_file_object = new Smarty_Internal_Write_File;
293
        }
294
        // call compiler
295
        if ($this->compiler_object->compileTemplate($this)) {
296
            // compiling succeded
297
            if (!$this->isEvaluated()) {
298
                // write compiled template
299
                $this->smarty->write_file_object->writeFile($this->getCompiledFilepath(), $this->compiled_template);
300
                // make template and compiled file timestamp match
301
                touch($this->getCompiledFilepath(), $this->getTemplateTimestamp());
302
            }
303
        } else {
304
            // error compiling template
305
            throw new Exception("Error compiling template {$this->getTemplateFilepath ()}");
306
            return false;
307
        }
308
        $this->compile_time += $this->_get_time() - $_start_time;
309
    }
310
 
311
    /**
312
    * Returns the filepath of the cached template output
313
    *
314
    * The filepath is determined by the actual resource handler of the cacher
315
    *
316
    * @return string the cache filepath
317
    */
318
    public function getCachedFilepath ()
319
    {
320
        return $this->cached_filepath === null ?
321
        $this->cached_filepath = ($this->isEvaluated() || !$this->caching) ? false : $this->smarty->cache_resource_objects[$this->caching_type]->getCachedFilepath($this) :
322
        $this->cached_filepath;
323
    }
324
 
325
    /**
326
    * Returns the timpestamp of the cached template output
327
    *
328
    * The timestamp is determined by the actual resource handler of the cacher
329
    *
330
    * @return integer the template timestamp
331
    */
332
    public function getCachedTimestamp ()
333
    {
334
        return $this->cached_timestamp === null ?
335
        $this->cached_timestamp = ($this->isEvaluated() || !$this->caching) ? false : $this->smarty->cache_resource_objects[$this->caching_type]->getCachedTimestamp($this) :
336
        $this->cached_timestamp;
337
    }
338
 
339
    /**
340
    * Returns the cached template output
341
    *
342
    * @return string |booelan the template content or false if the file does not exist
343
    */
344
    public function getCachedContent ()
345
    {
346
        return $this->rendered_content === null ?
347
        $this->rendered_content = ($this->isEvaluated() || !$this->caching) ? false : $this->smarty->cache_resource_objects[$this->caching_type]->getCachedContents($this) :
348
        $this->rendered_content;
349
    }
350
 
351
    /**
352
    * Writes the cached template output
353
    */
354
    public function writeCachedContent ()
355
    {
356
        // build file dependency string
357
        $this->properties['cache_lifetime'] = $this->cache_lifetime;
358
        return ($this->isEvaluated() || !$this->caching) ? false : $this->smarty->cache_resource_objects[$this->caching_type]->writeCachedContent($this, $this->createPropertyHeader() . $this->rendered_content);
359
    }
360
 
361
    /**
362
    * Checks of a valid version redered HTML output is in the cache
363
    *
364
    * If the cache is valid the contents is stored in the template object
365
    *
366
    * @return boolean true if cache is valid
367
    */
368
    public function isCached ()
369
    {
370
        if ($this->isCached === null) {
371
            $this->isCached = false;
372
            if ($this->caching && !$this->isEvaluated() && !$this->force_compile && !$this->force_cache) {
373
                if ($this->getCachedTimestamp() === false) {
374
                    return $this->isCached;
375
                }
376
                if (($this->caching == SMARTY_CACHING_LIVETIME_SAVED || ($this->caching == SMARTY_CACHING_LIFETIME_CURRENT && (time() <= ($this->getCachedTimestamp() + $this->cache_lifetime) || $this->cache_lifetime < 0)))) {
377
                    $_start_time = $this->_get_time();
378
                    $this->rendered_content = $this->smarty->cache_resource_objects[$this->caching_type]->getCachedContents($this);
379
                    $this->cache_time += $this->_get_time() - $_start_time;
380
                    if ($this->caching == SMARTY_CACHING_LIVETIME_SAVED && (time() > ($this->getCachedTimestamp() + $this->properties['cache_lifetime']) || $this->properties['cache_lifetime'] < 0)) {
381
                        $this->rendered_content = null;
382
                        return $this->isCached;
383
                    }
384
                    if (!empty($this->properties['file_dependency']) && $this->smarty->compile_check) {
385
                        foreach ($this->properties['file_dependency'] as $_file_to_check) {
386
                            If (is_file($_file_to_check[0])) {
387
                                $mtime = filemtime($_file_to_check[0]);
388
                            } else {
389
                                $this->parseResourceName($_file_to_check[0], $resource_type, $resource_name, $resource_handler);
390
                                $mtime = $resource_handler->getTemplateTimestampTypeName($resource_type, $resource_name);
391
                            }
392
                            // If ($mtime > $this->getCachedTimestamp()) {
393
                            If ($mtime > $_file_to_check[1]) {
394
                                $this->rendered_content = null;
395
                                $this->properties['file_dependency'] = array();
396
                                return $this->isCached;
397
                            }
398
                        }
399
                    }
400
                    $this->isCached = true;
401
                }
402
            }
403
        }
404
        return $this->isCached;
405
    }
406
 
407
    /**
408
    * Render the output using the compiled template or the PHP template source
409
    *
410
    * The rendering process is accomplished by just including the PHP files.
411
    * The only exceptions are evaluated templates (string template). Their code has
412
    * to be evaluated
413
    */
414
    public function renderTemplate ()
415
    {
416
        if ($this->usesCompiler()) {
417
            if ($this->mustCompile()) {
418
                $this->compileTemplateSource();
419
            }
420
            $_smarty_tpl = $this;
421
            $_start_time = $this->_get_time();
422
            ob_start();
423
            if ($this->isEvaluated()) {
424
                eval("?>" . $this->compiled_template);
425
            } else {
426
                include($this->getCompiledFilepath ());
427
                // check file dependencies at compiled code
428
                if ($this->smarty->compile_check) {
429
                    if (!empty($this->properties['file_dependency'])) {
430
                        $this->mustCompile = false;
431
                        foreach ($this->properties['file_dependency'] as $_file_to_check) {
432
                            If (is_file($_file_to_check[0])) {
433
                                $mtime = filemtime($_file_to_check[0]);
434
                            } else {
435
                                $this->parseResourceName($_file_to_check[0], $resource_type, $resource_name, $resource_handler);
436
                                $mtime = $resource_handler->getTemplateTimestampTypeName($resource_type, $resource_name);
437
                            }
438
                            If ($mtime != $_file_to_check[1]) {
439
                                $this->properties['file_dependency'] = array();
440
                                $this->mustCompile = true;
441
                            }
442
                        }
443
                        if ($this->mustCompile) {
444
                            // recompile and render again
445
                            ob_get_clean();
446
                            $this->compileTemplateSource();
447
                            ob_start();
448
                            include($this->getCompiledFilepath ());
449
                        }
450
                    }
451
                }
452
            }
453
        } else {
454
            if (is_callable(array($this->smarty->resource_objects[$this->resource_type], 'renderUncompiled'))) {
455
                $_start_time = $this->_get_time();
456
                ob_start();
457
                $this->smarty->resource_objects[$this->resource_type]->renderUncompiled($this);
458
            } else {
459
                throw new Exception("Resource '$this->resource_type' must have 'renderUncompiled' methode");
460
            }
461
        }
462
        $this->rendered_content = ob_get_clean();
463
        $this->render_time += $this->_get_time() - $_start_time;
464
        if (!$this->isEvaluated) {
465
            $this->properties['file_dependency']['F' . abs(crc32($this->getTemplateFilepath()))] = array($this->getTemplateFilepath(), $this->getTemplateTimestamp());
466
        }
467
        if ($this->parent instanceof Smarty_Template or $this->parent instanceof Smarty_Internal_Template) {
468
            // var_dump('merge ', $this->parent->getTemplateFilepath(), $this->parent->properties['file_dependency'], $this->getTemplateFilepath(), $this->properties['file_dependency']);
469
            $this->parent->properties['file_dependency'] = array_merge($this->parent->properties['file_dependency'], $this->properties['file_dependency']);
470
        }
471
        // write to cache when nessecary
472
        if (!$this->isEvaluated() && $this->caching) {
473
            // write rendered template
474
            $this->writeCachedContent($this);
475
            // cache file may contain nocache code. read it back for processing
476
            $this->rendered_content = $this->smarty->cache_resource_objects[$this->caching_type]->getCachedContents($this);
477
        }
478
    }
479
 
480
    /**
481
    * Returns the rendered HTML output
482
    *
483
    * If the cache is valid the cached content is used, otherwise
484
    * the output is rendered from the compiled template or PHP template source
485
    *
486
    * @return string rendered HTML output
487
    */
488
    public function getRenderedTemplate ()
489
    {
490
        // disable caching for evaluated code
491
        if ($this->isEvaluated()) {
492
            $this->caching = false;
493
        }
494
        // checks if template exists
495
        $this->isExisting(true);
496
        // read from cache or render
497
        if ($this->rendered_content === null && !$this->isCached()) {
498
            // render template (not loaded and not in cache)
499
            $this->renderTemplate();
500
        }
501
        $this->updateParentVariables();
502
        return (isset($this->smarty->autoload_filters['output']) || isset($this->smarty->registered_filters['output']))?
503
        $this->smarty->filter_handler->execute('output', $this->rendered_content) : $this->rendered_content;
504
    }
505
 
506
    /**
507
    * parse a template resource in its name and type
508
    *
509
    * @param string $template_resource template resource specification
510
    */
511
    public function parseResourceName($template_resource, &$resource_type, &$resource_name, &$resource_handler)
512
    {
513
        if (empty($template_resource))
514
            return false;
515
        if (strpos($template_resource, ':') === false) {
516
            // no resource given, use default
517
            $resource_type = $this->smarty->default_resource_type;
518
            $resource_name = $template_resource;
519
        } else {
520
            // get type and name from path
521
            list($resource_type, $resource_name) = explode(':', $template_resource, 2);
522
            if (strlen($resource_type) == 1) {
523
                // 1 char is not resource type, but part of filepath
524
                $resource_type = 'file';
525
                $resource_name = $template_resource;
526
            } else {
527
                $resource_type = strtolower($resource_type);
528
            }
529
        }
530
        // load resource handler if required
531
        if (!isset($this->smarty->resource_objects[$resource_type])) {
532
            // try registered resource
533
            if (isset($this->smarty->_plugins['resource'][$resource_type])) {
534
                require_once(SMARTY_SYSPLUGINS_DIR . 'internal.resource_registered.php');
535
                // $this->smarty->loadPlugin('Smarty_Internal_Resource_Registered');
536
                $resource_handler = $this->smarty->resource_objects[$resource_type] = new Smarty_Internal_Resource_Registered($this->smarty);
537
            } else {
538
                // try sysplugins dir
539
                $_resource_class = "Smarty_Internal_Resource_{$resource_type}";
540
                if ($this->smarty->loadPlugin($_resource_class)) {
541
                    $resource_handler = $this->smarty->resource_objects[$resource_type] = new $_resource_class($this->smarty);
542
                } else {
543
                    // try plugins dir
544
                    $_resource_class = "Smarty_Resource_{$resource_type}";
545
                    if ($this->smarty->loadPlugin($_resource_class)) {
546
                        $resource_handler = $this->smarty->resource_objects[$resource_type] = new $_resource_class($this->smarty);
547
                    } else {
548
                        // try streams
549
                        $_known_stream = stream_get_wrappers();
550
                        if (in_array($resource_type, $_known_stream)) {
551
                            // is known stream
552
                            if ($this->smarty->security) {
553
                                $this->smarty->security_handler->isTrustedStream($resource_type);
554
                            }
555
                            require_once(SMARTY_SYSPLUGINS_DIR . 'internal.resource_stream.php');
556
                            // $this->smarty->loadPlugin('Smarty_Internal_Resource_Stream');
557
                            $resource_handler = $this->smarty->resource_objects[$resource_type] = new Smarty_Internal_Resource_Stream($this->smarty);
558
//                            $resource_name = str_replace(':', '://', $template_resource);
559
                        } else {
560
                            throw new Exception('Unkown resource type \'' . $resource_type . '\'');
561
                        }
562
                    }
563
                }
564
            }
565
        } else {
566
            $resource_handler = $this->smarty->resource_objects[$resource_type];
567
        }
568
        // cache template object under a unique ID
569
        // do not cache string resources
570
        if ($resource_type != 'string') {
571
           $this->smarty->template_objects[$this->buildTemplateId ($this->template_resource, $this->cache_id, $this->compile_id)] = $this;
572
        }
573
        return true;
574
    }
575
 
576
    /**
577
    * get system filepath to template
578
    */
579
    public function buildTemplateFilepath ($file = null)
580
    {
581
        if ($file == null) {
582
            $file = $this->resource_name;
583
        }
584
        foreach((array)$this->smarty->template_dir as $_template_dir) {
585
            if (strpos('/\\', substr($_template_dir, -1)) === false) {
586
                $_template_dir .= DS;
587
            }
588
 
589
            $_filepath = $_template_dir . $file;
590
            if (file_exists($_filepath))
591
                return $_filepath;
592
        }
593
        if (file_exists($file)) return $file;
594
        // no tpl file found
595
        if (!empty($this->smarty->default_template_handler_func)) {
596
            if (!is_callable($this->smarty->default_template_handler_func)) {
597
                throw new Exception("Default template handler not callable");
598
            } else {
599
                $_return = call_user_func_array($this->smarty->default_template_handler_func,
600
                    array($this->resource_type, $this->resource_name, &$this->template_source, &$this->template_timestamp, &$this));
601
                if ($_return == true) {
602
                    return $_filepath;
603
                }
604
            }
605
        }
606
        // throw new Exception("Unable to load template \"{$file}\"");
607
        return false;
608
    }
609
 
610
    /**
611
    * Decode saved properties from compiled template and cache files
612
    */
613
    public function decodeProperties ($properties)
614
    {
615
        $prop = unserialize($properties);
616
        if (isset($prop['cache_lifetime'])) {
617
            $this->properties['cache_lifetime'] = $prop['cache_lifetime'];
618
        }
619
        if (isset($prop['file_dependency'])) {
620
            $this->properties['file_dependency'] = array_merge($this->properties['file_dependency'], $prop['file_dependency']);
621
            // $this->properties['file_dependency'] = array_unique($this->properties['file_dependency']);
622
        }
623
        if (!empty($prop['function'])) {
624
            foreach ($prop['function'] as $_name => $_data) {
625
                $this->smarty->template_functions[$_name]['compiled'] = str_replace('_%n', "\n", $_data['compiled']);
626
                $this->smarty->template_functions[$_name]['parameter'] = $_data['parameter'];
627
            }
628
        }
629
    }
630
 
631
    /**
632
    * Update Smarty variables in parent variable object
633
    */
634
    public function updateParentVariables ($scope = SMARTY_LOCAL_SCOPE)
635
    {
636
        foreach ($this->tpl_vars as $_key => $_variable) {
637
            // copy global vars back to parent
638
            if (isset($this->parent) && ($scope == SMARTY_PARENT_SCOPE || $this->tpl_vars[$_key]->scope == SMARTY_PARENT_SCOPE)) {
639
                if (isset($this->parent->tpl_vars[$_key])) {
640
                    // variable is already defined in parent, copy value
641
                    $this->parent->tpl_vars[$_key]->value = $this->tpl_vars[$_key]->value;
642
                } else {
643
                    // create variable in parent
644
                    $this->parent->tpl_vars[$_key] = clone $_variable;
645
                    $this->parent->tpl_vars[$_key]->scope = SMARTY_LOCAL_SCOPE;
646
                }
647
            }
648
            if ($scope == SMARTY_ROOT_SCOPE || $this->tpl_vars[$_key]->scope == SMARTY_ROOT_SCOPE) {
649
                $_ptr = $this;
650
                // find  root
651
                while ($_ptr->parent != null) {
652
                    $_ptr = $_ptr->parent;
653
                }
654
                if (isset($_ptr->tpl_vars[$_key])) {
655
                    // variable is already defined in root, copy value
656
                    $_ptr->tpl_vars[$_key]->value = $this->tpl_vars[$_key]->value;
657
                } else {
658
                    // create variable in root
659
                    $_ptr->tpl_vars[$_key] = clone $_variable;
660
                    $_ptr->tpl_vars[$_key]->scope = SMARTY_LOCAL_SCOPE;
661
                }
662
            }
663
            if ($scope == SMARTY_GLOBAL_SCOPE || $this->tpl_vars[$_key]->scope == SMARTY_GLOBAL_SCOPE) {
664
                if (isset($this->smarty->global_tpl_vars[$_key])) {
665
                    // variable is already defined in root, copy value
666
                    $this->smarty->global_tpl_vars[$_key]->value = $this->tpl_vars[$_key]->value;
667
                } else {
668
                    // create variable in root
669
                    $this->smarty->global_tpl_vars[$_key] = clone $_variable;
670
                }
671
                $this->smarty->global_tpl_vars[$_key]->scope = SMARTY_LOCAL_SCOPE;
672
            }
673
        }
674
    }
675
 
676
    /**
677
    * Create property header
678
    */
679
    public function createPropertyHeader ()
680
    {
681
        $directory_security = $this->smarty->direct_access_security ? "<?php if(!defined('SMARTY_DIR')) exit('no direct access allowed'); ?>\n" : '';
682
        $properties_string = "<?php \$_smarty_tpl->decodeProperties('" . str_replace("'", '"', (serialize($this->properties))) . "'); ?>\n";
683
        return $directory_security . $properties_string;
684
    }
685
 
686
    /**
687
    * wrapper for display
688
    */
689
    public function display ()
690
    {
691
        return $this->smarty->display($this);
692
    }
693
 
694
    /**
695
    * wrapper for fetch
696
    */
697
    public function fetch ()
698
    {
699
        return $this->smarty->fetch($this);
700
    }
701
    /**
702
    * wrapper for is_cached
703
    */
704
    public function is_cached ()
705
    {
706
        return $this->iscached();
707
    }
708
}
709
 
710
/**
711
* wrapper for template class
712
*/
713
class Smarty_Template extends Smarty_Internal_Template {
714
}
715
 
716
?>