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