1: | <?php
|
2: |
|
3: | |
4: | |
5: | |
6: | |
7: | |
8: | |
9: | |
10: | |
11: |
|
12: | class Smarty_Internal_Method_GetTemplateVars
|
13: | {
|
14: | |
15: | |
16: | |
17: | |
18: |
|
19: | public $objMap = 7;
|
20: |
|
21: | |
22: | |
23: | |
24: | |
25: | |
26: | |
27: | |
28: | |
29: | |
30: | |
31: | |
32: | |
33: |
|
34: | public function getTemplateVars(
|
35: | Smarty_Internal_Data $data,
|
36: | $varName = null,
|
37: | Smarty_Internal_Data $_ptr = null,
|
38: | $searchParents = true
|
39: | ) {
|
40: | if (isset($varName)) {
|
41: | $_var = $this->_getVariable($data, $varName, $_ptr, $searchParents, false);
|
42: | if (is_object($_var)) {
|
43: | return $_var->value;
|
44: | } else {
|
45: | return null;
|
46: | }
|
47: | } else {
|
48: | $_result = array();
|
49: | if ($_ptr === null) {
|
50: | $_ptr = $data;
|
51: | }
|
52: | while ($_ptr !== null) {
|
53: | foreach ($_ptr->tpl_vars as $key => $var) {
|
54: | if (!array_key_exists($key, $_result)) {
|
55: | $_result[ $key ] = $var->value;
|
56: | }
|
57: | }
|
58: |
|
59: | if ($searchParents && isset($_ptr->parent)) {
|
60: | $_ptr = $_ptr->parent;
|
61: | } else {
|
62: | $_ptr = null;
|
63: | }
|
64: | }
|
65: | if ($searchParents && isset(Smarty::$global_tpl_vars)) {
|
66: | foreach (Smarty::$global_tpl_vars as $key => $var) {
|
67: | if (!array_key_exists($key, $_result)) {
|
68: | $_result[ $key ] = $var->value;
|
69: | }
|
70: | }
|
71: | }
|
72: | return $_result;
|
73: | }
|
74: | }
|
75: |
|
76: | |
77: | |
78: | |
79: | |
80: | |
81: | |
82: | |
83: | |
84: | |
85: | |
86: |
|
87: | public function _getVariable(
|
88: | Smarty_Internal_Data $data,
|
89: | $varName,
|
90: | Smarty_Internal_Data $_ptr = null,
|
91: | $searchParents = true,
|
92: | $errorEnable = true
|
93: | ) {
|
94: | if ($_ptr === null) {
|
95: | $_ptr = $data;
|
96: | }
|
97: | while ($_ptr !== null) {
|
98: | if (isset($_ptr->tpl_vars[ $varName ])) {
|
99: |
|
100: | return $_ptr->tpl_vars[ $varName ];
|
101: | }
|
102: |
|
103: | if ($searchParents && isset($_ptr->parent)) {
|
104: | $_ptr = $_ptr->parent;
|
105: | } else {
|
106: | $_ptr = null;
|
107: | }
|
108: | }
|
109: | if (isset(Smarty::$global_tpl_vars[ $varName ])) {
|
110: |
|
111: | return Smarty::$global_tpl_vars[ $varName ];
|
112: | }
|
113: | if ($errorEnable && $data->_getSmartyObj()->error_unassigned) {
|
114: |
|
115: | $x = $$varName;
|
116: | }
|
117: | return new Smarty_Undefined_Variable;
|
118: | }
|
119: | }
|
120: | |