1 <?php |
|
2 /** |
|
3 * Smarty Internal Plugin Resource Extends |
|
4 * |
|
5 * @package Smarty |
|
6 * @subpackage TemplateResources |
|
7 * @author Uwe Tews |
|
8 * @author Rodney Rehm |
|
9 */ |
|
10 |
|
11 /** |
|
12 * Smarty Internal Plugin Resource Extends |
|
13 * Implements the file system as resource for Smarty which {extend}s a chain of template files templates |
|
14 * |
|
15 * @package Smarty |
|
16 * @subpackage TemplateResources |
|
17 */ |
|
18 class Smarty_Internal_Resource_Extends extends Smarty_Resource { |
|
19 /** |
|
20 * mbstring.overload flag |
|
21 * |
|
22 * @var int |
|
23 */ |
|
24 public $mbstring_overload = 0; |
|
25 |
|
26 /** |
|
27 * populate Source Object with meta data from Resource |
|
28 * |
|
29 * @param Smarty_Template_Source $source source object |
|
30 * @param Smarty_Internal_Template $_template template object |
|
31 * |
|
32 * @throws SmartyException |
|
33 */ |
|
34 public function populate(Smarty_Template_Source $source, Smarty_Internal_Template $_template = null) { |
|
35 $uid = sha1(getcwd()); |
|
36 $sources = array(); |
|
37 $components = explode('|', $source->name); |
|
38 $exists = true; |
|
39 foreach ($components as $component) { |
|
40 $s = Smarty_Resource::source(null, $source->smarty, $component); |
|
41 if ($s->type == 'php') { |
|
42 throw new SmartyException("Resource type {$s->type} cannot be used with the extends resource type"); |
|
43 } |
|
44 $sources[$s->uid] = $s; |
|
45 $uid .= realpath($s->filepath); |
|
46 if ($_template && $_template->smarty->compile_check) { |
|
47 $exists = $exists && $s->exists; |
|
48 } |
|
49 } |
|
50 $source->components = $sources; |
|
51 $source->filepath = $s->filepath; |
|
52 $source->uid = sha1($uid); |
|
53 if ($_template && $_template->smarty->compile_check) { |
|
54 $source->timestamp = $s->timestamp; |
|
55 $source->exists = $exists; |
|
56 } |
|
57 // need the template at getContent() |
|
58 $source->template = $_template; |
|
59 } |
|
60 |
|
61 /** |
|
62 * populate Source Object with timestamp and exists from Resource |
|
63 * |
|
64 * @param Smarty_Template_Source $source source object |
|
65 */ |
|
66 public function populateTimestamp(Smarty_Template_Source $source) { |
|
67 $source->exists = true; |
|
68 foreach ($source->components as $s) { |
|
69 $source->exists = $source->exists && $s->exists; |
|
70 } |
|
71 $source->timestamp = $s->timestamp; |
|
72 } |
|
73 |
|
74 /** |
|
75 * Load template's source from files into current template object |
|
76 * |
|
77 * @param Smarty_Template_Source $source source object |
|
78 * |
|
79 * @return string template source |
|
80 * @throws SmartyException if source cannot be loaded |
|
81 */ |
|
82 public function getContent(Smarty_Template_Source $source) { |
|
83 if (!$source->exists) { |
|
84 throw new SmartyException("Unable to read template {$source->type} '{$source->name}'"); |
|
85 } |
|
86 |
|
87 $_components = array_reverse($source->components); |
|
88 |
|
89 $_content = ''; |
|
90 foreach ($_components as $_component) { |
|
91 // read content |
|
92 $_content .= $_component->content; |
|
93 } |
|
94 return $_content; |
|
95 } |
|
96 |
|
97 /** |
|
98 * Determine basename for compiled filename |
|
99 * |
|
100 * @param Smarty_Template_Source $source source object |
|
101 * |
|
102 * @return string resource's basename |
|
103 */ |
|
104 public function getBasename(Smarty_Template_Source $source) { |
|
105 return str_replace(':', '.', basename($source->filepath)); |
|
106 } |
|
107 } |
|