1 | <?php |
---|
2 | /** |
---|
3 | * Smarty Internal Plugin Resource Eval |
---|
4 | * |
---|
5 | * @package Smarty |
---|
6 | * @subpackage TemplateResources |
---|
7 | * @author Uwe Tews |
---|
8 | * @author Rodney Rehm |
---|
9 | */ |
---|
10 | |
---|
11 | /** |
---|
12 | * Smarty Internal Plugin Resource Eval |
---|
13 | * |
---|
14 | * Implements the strings as resource for Smarty template |
---|
15 | * |
---|
16 | * {@internal unlike string-resources the compiled state of eval-resources is NOT saved for subsequent access}} |
---|
17 | * |
---|
18 | * @package Smarty |
---|
19 | * @subpackage TemplateResources |
---|
20 | */ |
---|
21 | class Smarty_Internal_Resource_Eval extends Smarty_Resource_Recompiled { |
---|
22 | |
---|
23 | /** |
---|
24 | * populate Source Object with meta data from Resource |
---|
25 | * |
---|
26 | * @param Smarty_Template_Source $source source object |
---|
27 | * @param Smarty_Internal_Template $_template template object |
---|
28 | * @return void |
---|
29 | */ |
---|
30 | public function populate(Smarty_Template_Source $source, Smarty_Internal_Template $_template=null) |
---|
31 | { |
---|
32 | $source->uid = $source->filepath = sha1($source->name); |
---|
33 | $source->timestamp = false; |
---|
34 | $source->exists = true; |
---|
35 | } |
---|
36 | |
---|
37 | /** |
---|
38 | * Load template's source from $resource_name into current template object |
---|
39 | * |
---|
40 | * @uses decode() to decode base64 and urlencoded template_resources |
---|
41 | * @param Smarty_Template_Source $source source object |
---|
42 | * @return string template source |
---|
43 | */ |
---|
44 | public function getContent(Smarty_Template_Source $source) |
---|
45 | { |
---|
46 | return $this->decode($source->name); |
---|
47 | } |
---|
48 | |
---|
49 | /** |
---|
50 | * decode base64 and urlencode |
---|
51 | * |
---|
52 | * @param string $string template_resource to decode |
---|
53 | * @return string decoded template_resource |
---|
54 | */ |
---|
55 | protected function decode($string) |
---|
56 | { |
---|
57 | // decode if specified |
---|
58 | if (($pos = strpos($string, ':')) !== false) { |
---|
59 | if (!strncmp($string, 'base64', 6)) { |
---|
60 | return base64_decode(substr($string, 7)); |
---|
61 | } elseif (!strncmp($string, 'urlencode', 9)) { |
---|
62 | return urldecode(substr($string, 10)); |
---|
63 | } |
---|
64 | } |
---|
65 | |
---|
66 | return $string; |
---|
67 | } |
---|
68 | |
---|
69 | /** |
---|
70 | * modify resource_name according to resource handlers specifications |
---|
71 | * |
---|
72 | * @param Smarty $smarty Smarty instance |
---|
73 | * @param string $resource_name resource_name to make unique |
---|
74 | * @return string unique resource name |
---|
75 | */ |
---|
76 | protected function buildUniqueResourceName(Smarty $smarty, $resource_name) |
---|
77 | { |
---|
78 | return get_class($this) . '#' .$this->decode($resource_name); |
---|
79 | } |
---|
80 | |
---|
81 | /** |
---|
82 | * Determine basename for compiled filename |
---|
83 | * |
---|
84 | * @param Smarty_Template_Source $source source object |
---|
85 | * @return string resource's basename |
---|
86 | */ |
---|
87 | protected function getBasename(Smarty_Template_Source $source) |
---|
88 | { |
---|
89 | return ''; |
---|
90 | } |
---|
91 | |
---|
92 | } |
---|
93 | |
---|
94 | ?> |
---|