1 : <?php
2 : /**
3 : * Smarty Resource Plugin
4 : *
5 : * @package Smarty
6 : * @subpackage TemplateResources
7 : * @author Rodney Rehm
8 : */
9 :
10 : /**
11 : * Smarty Resource Plugin
12 : *
13 : * Base implementation for resource plugins
14 : *
15 : * @package Smarty
16 : * @subpackage TemplateResources
17 : */
18 : abstract class Smarty_Resource {
19 : /**
20 : * cache for Smarty_Template_Source instances
21 : * @var array
22 : */
23 : public static $sources = array();
24 : /**
25 : * cache for Smarty_Template_Compiled instances
26 : * @var array
27 : */
28 : public static $compileds = array();
29 : /**
30 : * cache for Smarty_Resource instances
31 : * @var array
32 : */
33 : public static $resources = array();
34 : /**
35 : * resource types provided by the core
36 : * @var array
37 : */
38 : protected static $sysplugins = array(
39 : 'file' => true,
40 : 'string' => true,
41 : 'extends' => true,
42 : 'stream' => true,
43 : 'eval' => true,
44 : 'php' => true
45 : );
46 :
47 : /**
48 : * Name of the Class to compile this resource's contents with
49 : * @var string
50 : */
51 : public $compiler_class = 'Smarty_Internal_SmartyTemplateCompiler';
52 :
53 : /**
54 : * Name of the Class to tokenize this resource's contents with
55 : * @var string
56 : */
57 : public $template_lexer_class = 'Smarty_Internal_Templatelexer';
58 :
59 : /**
60 : * Name of the Class to parse this resource's contents with
61 : * @var string
62 : */
63 : public $template_parser_class = 'Smarty_Internal_Templateparser';
64 :
65 : /**
66 : * Load template's source into current template object
67 : *
68 : * {@internal The loaded source is assigned to $_template->source->content directly.}}
69 : *
70 : * @param Smarty_Template_Source $source source object
71 : * @return string template source
72 : * @throws SmartyException if source cannot be loaded
73 : */
74 : public abstract function getContent(Smarty_Template_Source $source);
75 :
76 : /**
77 : * populate Source Object with meta data from Resource
78 : *
79 : * @param Smarty_Template_Source $source source object
80 : * @param Smarty_Internal_Template $_template template object
81 : */
82 : public abstract function populate(Smarty_Template_Source $source, Smarty_Internal_Template $_template=null);
83 :
84 : /**
85 : * populate Source Object with timestamp and exists from Resource
86 : *
87 : * @param Smarty_Template_Source $source source object
88 : */
89 : public function populateTimestamp(Smarty_Template_Source $source)
90 : {
91 : // intentionally left blank
92 0 : }
93 :
94 :
95 : /**
96 : * modify resource_name according to resource handlers specifications
97 : *
98 : * @param Smarty $smarty Smarty instance
99 : * @param string $resource_name resource_name to make unique
100 : * @return string unique resource name
101 : */
102 : protected function buildUniqueResourceName(Smarty $smarty, $resource_name)
103 : {
104 0 : return get_class($this) . '#' . $smarty->joined_template_dir . '#' . $resource_name;
105 : }
106 :
107 : /**
108 : * populate Compiled Object with compiled filepath
109 : *
110 : * @param Smarty_Template_Compiled $compiled compiled object
111 : * @param Smarty_Internal_Template $_template template object
112 : */
113 : public function populateCompiledFilepath(Smarty_Template_Compiled $compiled, Smarty_Internal_Template $_template)
114 : {
115 0 : $_compile_id = isset($_template->compile_id) ? preg_replace('![^\w\|]+!', '_', $_template->compile_id) : null;
116 0 : $_filepath = $compiled->source->uid;
117 : // if use_sub_dirs, break file into directories
118 0 : if ($_template->smarty->use_sub_dirs) {
119 0 : $_filepath = substr($_filepath, 0, 2) . DS
120 0 : . substr($_filepath, 2, 2) . DS
121 0 : . substr($_filepath, 4, 2) . DS
122 0 : . $_filepath;
123 0 : }
124 0 : $_compile_dir_sep = $_template->smarty->use_sub_dirs ? DS : '^';
125 0 : if (isset($_compile_id)) {
126 0 : $_filepath = $_compile_id . $_compile_dir_sep . $_filepath;
127 0 : }
128 : // caching token
129 0 : if ($_template->caching) {
130 0 : $_cache = '.cache';
131 0 : } else {
132 0 : $_cache = '';
133 : }
134 0 : $_compile_dir = $_template->smarty->getCompileDir();
135 : // set basename if not specified
136 0 : $_basename = $this->getBasename($compiled->source);
137 0 : if ($_basename === null) {
138 0 : $_basename = basename( preg_replace('![^\w\/]+!', '_', $compiled->source->name) );
139 0 : }
140 : // separate (optional) basename by dot
141 0 : if ($_basename) {
142 0 : $_basename = '.' . $_basename;
143 0 : }
144 :
145 0 : $compiled->filepath = $_compile_dir . $_filepath . '.' . $compiled->source->type . $_basename . $_cache . '.php';
146 0 : }
147 :
148 : /**
149 : * build template filepath by traversing the template_dir array
150 : *
151 : * @param Smarty_Template_Source $source source object
152 : * @param Smarty_Internal_Template $_template template object
153 : * @return string fully qualified filepath
154 : * @throws SmartyException if default template handler is registered but not callable
155 : */
156 : protected function buildFilepath(Smarty_Template_Source $source, Smarty_Internal_Template $_template=null)
157 : {
158 0 : $file = $source->name;
159 0 : if ($source instanceof Smarty_Config_Source) {
160 0 : $_directories = $source->smarty->getConfigDir();
161 0 : $_default_handler = $source->smarty->default_config_handler_func;
162 0 : } else {
163 0 : $_directories = $source->smarty->getTemplateDir();
164 0 : $_default_handler = $source->smarty->default_template_handler_func;
165 : }
166 :
167 : // go relative to a given template?
168 0 : $_file_is_dotted = $file[0] == '.' && ($file[1] == '.' || $file[1] == '/' || $file[1] == "\\");
169 0 : if ($_template && $_template->parent instanceof Smarty_Internal_Template && $_file_is_dotted) {
170 0 : if ($_template->parent->source->type != 'file' && $_template->parent->source->type != 'extends' && !$_template->parent->allow_relative_path) {
171 0 : throw new SmartyException("Template '{$file}' cannot be relative to template of resource type '{$_template->parent->source->type}'");
172 : }
173 0 : $file = dirname($_template->parent->source->filepath) . DS . $file;
174 0 : $_file_exact_match = true;
175 0 : if (!preg_match('/^([\/\\\\]|[a-zA-Z]:[\/\\\\])/', $file)) {
176 : // the path gained from the parent template is relative to the current working directory
177 : // as expansions (like include_path) have already been done
178 0 : $file = getcwd() . DS . $file;
179 0 : }
180 0 : }
181 :
182 : // resolve relative path
183 0 : if (!preg_match('/^([\/\\\\]|[a-zA-Z]:[\/\\\\])/', $file)) {
184 0 : $_was_relative_prefix = $file[0] == '.' ? substr($file, 0, strpos($file, '|')) : null;
185 0 : $_path = DS . trim($file, '/\\');
186 0 : $_was_relative = true;
187 0 : } else {
188 0 : $_path = $file;
189 : }
190 : // don't we all just love windows?
191 0 : $_path = str_replace('\\', '/', $_path);
192 : // resolve simples
193 0 : $_path = preg_replace('#(/\./(\./)*)|/{2,}#', '/', $_path);
194 : // resolve parents
195 0 : while (true) {
196 0 : $_parent = strpos($_path, '/../');
197 0 : if ($_parent === false) {
198 0 : break;
199 0 : } else if ($_parent === 0) {
200 0 : $_path = substr($_path, 3);
201 0 : break;
202 : }
203 0 : $_pos = strrpos($_path, '/', $_parent - strlen($_path) - 1);
204 0 : if ($_pos === false) {
205 : // don't we all just love windows?
206 0 : $_pos = $_parent;
207 0 : }
208 0 : $_path = substr_replace($_path, '', $_pos, $_parent + 3 - $_pos);
209 0 : }
210 0 : if (DS != '/') {
211 : // don't we all just love windows?
212 0 : $_path = str_replace('/', '\\', $_path);
213 0 : }
214 : // revert to relative
215 0 : if (isset($_was_relative)) {
216 0 : if (isset($_was_relative_prefix)){
217 0 : $_path = $_was_relative_prefix . $_path;
218 0 : } else {
219 0 : $_path = substr($_path, 1);
220 : }
221 0 : }
222 :
223 : // this is only required for directories
224 0 : $file = rtrim($_path, '/\\');
225 :
226 : // files relative to a template only get one shot
227 0 : if (isset($_file_exact_match)) {
228 0 : return $this->fileExists($source, $file) ? $file : false;
229 : }
230 :
231 : // template_dir index?
232 0 : if (preg_match('#^\[(?P<key>[^\]]+)\](?P<file>.+)$#', $file, $match)) {
233 0 : $_directory = null;
234 : // try string indexes
235 0 : if (isset($_directories[$match['key']])) {
236 0 : $_directory = $_directories[$match['key']];
237 0 : } else if (is_numeric($match['key'])) {
238 : // try numeric index
239 0 : $match['key'] = (int) $match['key'];
240 0 : if (isset($_directories[$match['key']])) {
241 0 : $_directory = $_directories[$match['key']];
242 0 : } else {
243 : // try at location index
244 0 : $keys = array_keys($_directories);
245 0 : $_directory = $_directories[$keys[$match['key']]];
246 : }
247 0 : }
248 :
249 0 : if ($_directory) {
250 0 : $_file = substr($file, strpos($file, ']') + 1);
251 0 : $_filepath = $_directory . $_file;
252 0 : if ($this->fileExists($source, $_filepath)) {
253 0 : return $_filepath;
254 : }
255 0 : }
256 0 : }
257 :
258 : // relative file name?
259 0 : if (!preg_match('/^([\/\\\\]|[a-zA-Z]:[\/\\\\])/', $file)) {
260 0 : foreach ($_directories as $_directory) {
261 0 : $_filepath = $_directory . $file;
262 0 : if ($this->fileExists($source, $_filepath)) {
263 0 : return $_filepath;
264 : }
265 0 : if ($source->smarty->use_include_path && !preg_match('/^([\/\\\\]|[a-zA-Z]:[\/\\\\])/', $_directory)) {
266 : // try PHP include_path
267 0 : if (($_filepath = Smarty_Internal_Get_Include_Path::getIncludePath($_filepath)) !== false) {
268 0 : return $_filepath;
269 : }
270 0 : }
271 0 : }
272 0 : }
273 :
274 : // try absolute filepath
275 0 : if ($this->fileExists($source, $file)) {
276 0 : return $file;
277 : }
278 :
279 : // no tpl file found
280 0 : if ($_default_handler) {
281 0 : if (!is_callable($_default_handler)) {
282 0 : if ($source instanceof Smarty_Config_Source) {
283 0 : throw new SmartyException("Default config handler not callable");
284 : } else {
285 0 : throw new SmartyException("Default template handler not callable");
286 : }
287 : }
288 0 : $_return = call_user_func_array($_default_handler,
289 0 : array($source->type, $source->name, &$_content, &$_timestamp, $source->smarty));
290 0 : if (is_string($_return)) {
291 0 : $source->timestamp = @filemtime($_return);
292 0 : $source->exists = !!$source->timestamp;
293 0 : return $_return;
294 0 : } elseif ($_return === true) {
295 0 : $source->content = $_content;
296 0 : $source->timestamp = $_timestamp;
297 0 : $source->exists = true;
298 0 : return $_filepath;
299 : }
300 0 : }
301 :
302 : // give up
303 0 : return false;
304 : }
305 :
306 : /**
307 : * test is file exists and save timestamp
308 : *
309 : * @param Smarty_Template_Source $source source object
310 : * @param string $file file name
311 : * @return bool true if file exists
312 : */
313 : protected function fileExists(Smarty_Template_Source $source, $file)
314 : {
315 0 : $source->timestamp = @filemtime($file);
316 0 : return $source->exists = !!$source->timestamp;
317 :
318 : }
319 :
320 : /**
321 : * Determine basename for compiled filename
322 : *
323 : * @param Smarty_Template_Source $source source object
324 : * @return string resource's basename
325 : */
326 : protected function getBasename(Smarty_Template_Source $source)
327 : {
328 0 : return null;
329 : }
330 :
331 : /**
332 : * Load Resource Handler
333 : *
334 : * @param Smarty $smarty smarty object
335 : * @param string $type name of the resource
336 : * @return Smarty_Resource Resource Handler
337 : */
338 : public static function load(Smarty $smarty, $type)
339 : {
340 : // try smarty's cache
341 0 : if (isset($smarty->_resource_handlers[$type])) {
342 0 : return $smarty->_resource_handlers[$type];
343 : }
344 :
345 : // try registered resource
346 0 : if (isset($smarty->registered_resources[$type])) {
347 0 : if ($smarty->registered_resources[$type] instanceof Smarty_Resource) {
348 0 : $smarty->_resource_handlers[$type] = $smarty->registered_resources[$type];
349 : // note registered to smarty is not kept unique!
350 0 : return $smarty->_resource_handlers[$type];
351 : }
352 0 : if (!isset(self::$resources['registered'])) {
353 0 : self::$resources['registered'] = new Smarty_Internal_Resource_Registered();
354 0 : $smarty->_resource_handlers[$type] = self::$resources['registered'];
355 0 : }
356 0 : return $smarty->_resource_handlers[$type];
357 : }
358 :
359 : // try sysplugins dir
360 0 : if (isset(self::$sysplugins[$type])) {
361 0 : if (!isset(self::$resources[$type])) {
362 0 : $_resource_class = 'Smarty_Internal_Resource_' . ucfirst($type);
363 0 : self::$resources[$type] = new $_resource_class();
364 0 : }
365 0 : return $smarty->_resource_handlers[$type] = self::$resources[$type];
366 : }
367 :
368 : // try plugins dir
369 0 : $_resource_class = 'Smarty_Resource_' . ucfirst($type);
370 0 : if ($smarty->loadPlugin($_resource_class)) {
371 0 : if (isset(self::$resources[$type])) {
372 0 : return $smarty->_resource_handlers[$type] = self::$resources[$type];
373 : }
374 :
375 0 : if (class_exists($_resource_class, false)) {
376 0 : self::$resources[$type] = new $_resource_class();
377 0 : return $smarty->_resource_handlers[$type] = self::$resources[$type];
378 : } else {
379 0 : $smarty->registerResource($type, array(
380 0 : "smarty_resource_{$type}_source",
381 0 : "smarty_resource_{$type}_timestamp",
382 0 : "smarty_resource_{$type}_secure",
383 0 : "smarty_resource_{$type}_trusted"
384 0 : ));
385 :
386 : // give it another try, now that the resource is registered properly
387 0 : return self::load($smarty, $type);
388 : }
389 : }
390 :
391 : // try streams
392 0 : $_known_stream = stream_get_wrappers();
393 0 : if (in_array($type, $_known_stream)) {
394 : // is known stream
395 0 : if (is_object($smarty->security_policy)) {
396 0 : $smarty->security_policy->isTrustedStream($type);
397 0 : }
398 0 : if (!isset(self::$resources['stream'])) {
399 0 : self::$resources['stream'] = new Smarty_Internal_Resource_Stream();
400 0 : }
401 0 : return $smarty->_resource_handlers[$type] = self::$resources['stream'];
402 : }
403 :
404 : // TODO: try default_(template|config)_handler
405 :
406 : // give up
407 0 : throw new SmartyException("Unkown resource type '{$type}'");
408 : }
409 :
410 : /**
411 : * extract resource_type and resource_name from template_resource and config_resource
412 : *
413 : * @note "C:/foo.tpl" was forced to file resource up till Smarty 3.1.3 (including).
414 : * @param string $resource_name template_resource or config_resource to parse
415 : * @param string $default_resource the default resource_type defined in $smarty
416 : * @param string &$name the parsed resource name
417 : * @param string &$type the parsed resource type
418 : * @return void
419 : */
420 : protected static function parseResourceName($resource_name, $default_resource, &$name, &$type)
421 : {
422 0 : $parts = explode(':', $resource_name, 2);
423 0 : if (!isset($parts[1]) || !isset($parts[0][1])) {
424 : // no resource given, use default
425 : // or single character before the colon is not a resource type, but part of the filepath
426 0 : $type = $default_resource;
427 0 : $name = $resource_name;
428 0 : } else {
429 0 : $type = $parts[0];
430 0 : $name = $parts[1];
431 : }
432 0 : }
433 :
434 :
435 : /**
436 : * modify resource_name according to resource handlers specifications
437 : *
438 : * @param Smarty $smarty Smarty instance
439 : * @param string $resource_name resource_name to make unique
440 : * @return string unique resource name
441 : */
442 :
443 : /**
444 : * modify template_resource according to resource handlers specifications
445 : *
446 : * @param string $smarty Smarty instance
447 : * @param string $template_resource template_resource to extracate resource handler and name of
448 : * @return string unique resource name
449 : */
450 : public static function getUniqueTemplateName($smarty, $template_resource)
451 : {
452 0 : self::parseResourceName($template_resource, $smarty->default_resource_type, $name, $type);
453 : // TODO: optimize for Smarty's internal resource types
454 0 : $resource = Smarty_Resource::load($smarty, $type);
455 0 : return $resource->buildUniqueResourceName($smarty, $name);
456 : }
457 :
458 : /**
459 : * initialize Source Object for given resource
460 : *
461 : * Either [$_template] or [$smarty, $template_resource] must be specified
462 : *
463 : * @param Smarty_Internal_Template $_template template object
464 : * @param Smarty $smarty smarty object
465 : * @param string $template_resource resource identifier
466 : * @return Smarty_Template_Source Source Object
467 : */
468 : public static function source(Smarty_Internal_Template $_template=null, Smarty $smarty=null, $template_resource=null)
469 : {
470 0 : if ($_template) {
471 0 : $smarty = $_template->smarty;
472 0 : $template_resource = $_template->template_resource;
473 0 : }
474 :
475 : // parse resource_name, load resource handler, identify unique resource name
476 0 : self::parseResourceName($template_resource, $smarty->default_resource_type, $name, $type);
477 0 : $resource = Smarty_Resource::load($smarty, $type);
478 0 : $unique_resource_name = $resource->buildUniqueResourceName($smarty, $name);
479 :
480 : // check runtime cache
481 0 : $_cache_key = 'template|' . $unique_resource_name;
482 0 : if (isset(self::$sources[$_cache_key])) {
483 0 : return self::$sources[$_cache_key];
484 : }
485 :
486 : // create source
487 0 : $source = new Smarty_Template_Source($resource, $smarty, $template_resource, $type, $name, $unique_resource_name);
488 0 : $resource->populate($source, $_template);
489 :
490 : // runtime cache
491 0 : self::$sources[$_cache_key] = $source;
492 0 : return $source;
493 : }
494 :
495 : /**
496 : * initialize Config Source Object for given resource
497 : *
498 : * @param Smarty_Internal_Config $_config config object
499 : * @return Smarty_Config_Source Source Object
500 : */
501 : public static function config(Smarty_Internal_Config $_config)
502 : {
503 0 : static $_incompatible_resources = array('eval' => true, 'string' => true, 'extends' => true, 'php' => true);
504 0 : $config_resource = $_config->config_resource;
505 0 : $smarty = $_config->smarty;
506 :
507 : // parse resource_name
508 0 : self::parseResourceName($config_resource, $smarty->default_config_type, $name, $type);
509 :
510 : // make sure configs are not loaded via anything smarty can't handle
511 0 : if (isset($_incompatible_resources[$type])) {
512 0 : throw new SmartyException ("Unable to use resource '{$type}' for config");
513 : }
514 :
515 : // load resource handler, identify unique resource name
516 0 : $resource = Smarty_Resource::load($smarty, $type);
517 0 : $unique_resource_name = $resource->buildUniqueResourceName($smarty, $name);
518 :
519 : // check runtime cache
520 0 : $_cache_key = 'config|' . $unique_resource_name;
521 0 : if (isset(self::$sources[$_cache_key])) {
522 0 : return self::$sources[$_cache_key];
523 : }
524 :
525 : // create source
526 0 : $source = new Smarty_Config_Source($resource, $smarty, $config_resource, $type, $name, $unique_resource_name);
527 0 : $resource->populate($source, null);
528 :
529 : // runtime cache
530 0 : self::$sources[$_cache_key] = $source;
531 0 : return $source;
532 : }
533 :
534 : }
535 :
536 : /**
537 : * Smarty Resource Data Object
538 : *
539 : * Meta Data Container for Template Files
540 : *
541 : * @package Smarty
542 : * @subpackage TemplateResources
543 : * @author Rodney Rehm
544 : *
545 : * @property integer $timestamp Source Timestamp
546 : * @property boolean $exists Source Existance
547 : * @property boolean $template Extended Template reference
548 : * @property string $content Source Content
549 : */
550 : class Smarty_Template_Source {
551 :
552 : /**
553 : * Name of the Class to compile this resource's contents with
554 : * @var string
555 : */
556 : public $compiler_class = null;
557 :
558 : /**
559 : * Name of the Class to tokenize this resource's contents with
560 : * @var string
561 : */
562 : public $template_lexer_class = null;
563 :
564 : /**
565 : * Name of the Class to parse this resource's contents with
566 : * @var string
567 : */
568 : public $template_parser_class = null;
569 :
570 : /**
571 : * Unique Template ID
572 : * @var string
573 : */
574 : public $uid = null;
575 :
576 : /**
577 : * Template Resource (Smarty_Internal_Template::$template_resource)
578 : * @var string
579 : */
580 : public $resource = null;
581 :
582 : /**
583 : * Resource Type
584 : * @var string
585 : */
586 : public $type = null;
587 :
588 : /**
589 : * Resource Name
590 : * @var string
591 : */
592 : public $name = null;
593 :
594 : /**
595 : * Unique Resource Name
596 : * @var string
597 : */
598 : public $unique_resource = null;
599 :
600 : /**
601 : * Source Filepath
602 : * @var string
603 : */
604 : public $filepath = null;
605 :
606 : /**
607 : * Source is bypassing compiler
608 : * @var boolean
609 : */
610 : public $uncompiled = null;
611 :
612 : /**
613 : * Source must be recompiled on every occasion
614 : * @var boolean
615 : */
616 : public $recompiled = null;
617 :
618 : /**
619 : * The Components an extended template is made of
620 : * @var array
621 : */
622 : public $components = null;
623 :
624 : /**
625 : * Resource Handler
626 : * @var Smarty_Resource
627 : */
628 : public $handler = null;
629 :
630 : /**
631 : * Smarty instance
632 : * @var Smarty
633 : */
634 : public $smarty = null;
635 :
636 : /**
637 : * create Source Object container
638 : *
639 : * @param Smarty_Resource $handler Resource Handler this source object communicates with
640 : * @param Smarty $smarty Smarty instance this source object belongs to
641 : * @param string $resource full template_resource
642 : * @param string $type type of resource
643 : * @param string $name resource name
644 : * @param string $unique_resource unqiue resource name
645 : */
646 : public function __construct(Smarty_Resource $handler, Smarty $smarty, $resource, $type, $name, $unique_resource)
647 : {
648 0 : $this->handler = $handler; // Note: prone to circular references
649 :
650 0 : $this->compiler_class = $handler->compiler_class;
651 0 : $this->template_lexer_class = $handler->template_lexer_class;
652 0 : $this->template_parser_class = $handler->template_parser_class;
653 0 : $this->uncompiled = $this->handler instanceof Smarty_Resource_Uncompiled;
654 0 : $this->recompiled = $this->handler instanceof Smarty_Resource_Recompiled;
655 :
656 0 : $this->smarty = $smarty;
657 0 : $this->resource = $resource;
658 0 : $this->type = $type;
659 0 : $this->name = $name;
660 0 : $this->unique_resource = $unique_resource;
661 0 : }
662 :
663 : /**
664 : * get a Compiled Object of this source
665 : *
666 : * @param Smarty_Internal_Template $_template template objet
667 : * @return Smarty_Template_Compiled compiled object
668 : */
669 : public function getCompiled(Smarty_Internal_Template $_template)
670 : {
671 : // check runtime cache
672 0 : $_cache_key = $this->unique_resource . '#' . $_template->compile_id;
673 0 : if (isset(Smarty_Resource::$compileds[$_cache_key])) {
674 0 : return Smarty_Resource::$compileds[$_cache_key];
675 : }
676 :
677 0 : $compiled = new Smarty_Template_Compiled($this);
678 0 : $this->handler->populateCompiledFilepath($compiled, $_template);
679 0 : $compiled->timestamp = @filemtime($compiled->filepath);
680 0 : $compiled->exists = !!$compiled->timestamp;
681 :
682 : // runtime cache
683 0 : Smarty_Resource::$compileds[$_cache_key] = $compiled;
684 :
685 0 : return $compiled;
686 : }
687 :
688 : /**
689 : * render the uncompiled source
690 : *
691 : * @param Smarty_Internal_Template $_template template object
692 : */
693 : public function renderUncompiled(Smarty_Internal_Template $_template)
694 : {
695 0 : return $this->handler->renderUncompiled($this, $_template);
696 : }
697 :
698 : /**
699 : * <<magic>> Generic Setter.
700 : *
701 : * @param string $property_name valid: timestamp, exists, content, template
702 : * @param mixed $value new value (is not checked)
703 : * @throws SmartyException if $property_name is not valid
704 : */
705 : public function __set($property_name, $value)
706 : {
707 : switch ($property_name) {
708 : // regular attributes
709 0 : case 'timestamp':
710 0 : case 'exists':
711 0 : case 'content':
712 : // required for extends: only
713 0 : case 'template':
714 0 : $this->$property_name = $value;
715 0 : break;
716 :
717 0 : default:
718 0 : throw new SmartyException("invalid source property '$property_name'.");
719 0 : }
720 0 : }
721 :
722 : /**
723 : * <<magic>> Generic getter.
724 : *
725 : * @param string $property_name valid: timestamp, exists, content
726 : * @return mixed
727 : * @throws SmartyException if $property_name is not valid
728 : */
729 : public function __get($property_name)
730 : {
731 : switch ($property_name) {
732 0 : case 'timestamp':
733 0 : case 'exists':
734 0 : $this->handler->populateTimestamp($this);
735 0 : return $this->$property_name;
736 :
737 0 : case 'content':
738 0 : return $this->content = $this->handler->getContent($this);
739 :
740 0 : default:
741 0 : throw new SmartyException("source property '$property_name' does not exist.");
742 0 : }
743 : }
744 :
745 : }
746 :
747 : /**
748 : * Smarty Resource Data Object
749 : *
750 : * Meta Data Container for Template Files
751 : *
752 : * @package Smarty
753 : * @subpackage TemplateResources
754 : * @author Rodney Rehm
755 : *
756 : * @property string $content compiled content
757 : */
758 : class Smarty_Template_Compiled {
759 :
760 : /**
761 : * Compiled Filepath
762 : * @var string
763 : */
764 : public $filepath = null;
765 :
766 : /**
767 : * Compiled Timestamp
768 : * @var integer
769 : */
770 : public $timestamp = null;
771 :
772 : /**
773 : * Compiled Existance
774 : * @var boolean
775 : */
776 : public $exists = false;
777 :
778 : /**
779 : * Compiled Content Loaded
780 : * @var boolean
781 : */
782 : public $loaded = false;
783 :
784 : /**
785 : * Template was compiled
786 : * @var boolean
787 : */
788 : public $isCompiled = false;
789 :
790 : /**
791 : * Source Object
792 : * @var Smarty_Template_Source
793 : */
794 : public $source = null;
795 :
796 : /**
797 : * Metadata properties
798 : *
799 : * populated by Smarty_Internal_Template::decodeProperties()
800 : * @var array
801 : */
802 : public $_properties = null;
803 :
804 : /**
805 : * create Compiled Object container
806 : *
807 : * @param Smarty_Template_Source $source source object this compiled object belongs to
808 : */
809 : public function __construct(Smarty_Template_Source $source)
810 : {
811 0 : $this->source = $source;
812 0 : }
813 :
814 : }
815 :
|