]> git.mxchange.org Git - friendica.git/blob - vendor/smarty/smarty/libs/sysplugins/smarty_internal_method_gettemplatevars.php
Add Smarty to Composer
[friendica.git] / vendor / smarty / smarty / libs / sysplugins / smarty_internal_method_gettemplatevars.php
1 <?php
2
3 /**
4  * Smarty Method GetTemplateVars
5  *
6  * Smarty::getTemplateVars() method
7  *
8  * @package    Smarty
9  * @subpackage PluginsInternal
10  * @author     Uwe Tews
11  */
12 class Smarty_Internal_Method_GetTemplateVars
13 {
14     /**
15      * Valid for all objects
16      *
17      * @var int
18      */
19     public $objMap = 7;
20
21     /**
22      * Returns a single or all template variables
23      *
24      * @api  Smarty::getTemplateVars()
25      * @link http://www.smarty.net/docs/en/api.get.template.vars.tpl
26      *
27      * @param \Smarty_Internal_Data|\Smarty_Internal_Template|\Smarty $data
28      * @param  string                                                 $varName       variable name or null
29      * @param \Smarty_Internal_Data|\Smarty_Internal_Template|\Smarty $_ptr          optional pointer to data object
30      * @param  bool                                                   $searchParents include parent templates?
31      *
32      * @return mixed variable value or or array of variables
33      */
34     public function getTemplateVars(Smarty_Internal_Data $data, $varName = null, Smarty_Internal_Data $_ptr = null,
35                                     $searchParents = true)
36     {
37         if (isset($varName)) {
38             $_var = $this->_getVariable($data, $varName, $_ptr, $searchParents, false);
39             if (is_object($_var)) {
40                 return $_var->value;
41             } else {
42                 return null;
43             }
44         } else {
45             $_result = array();
46             if ($_ptr === null) {
47                 $_ptr = $data;
48             }
49             while ($_ptr !== null) {
50                 foreach ($_ptr->tpl_vars AS $key => $var) {
51                     if (!array_key_exists($key, $_result)) {
52                         $_result[ $key ] = $var->value;
53                     }
54                 }
55                 // not found, try at parent
56                 if ($searchParents) {
57                     $_ptr = $_ptr->parent;
58                 } else {
59                     $_ptr = null;
60                 }
61             }
62             if ($searchParents && isset(Smarty::$global_tpl_vars)) {
63                 foreach (Smarty::$global_tpl_vars AS $key => $var) {
64                     if (!array_key_exists($key, $_result)) {
65                         $_result[ $key ] = $var->value;
66                     }
67                 }
68             }
69             return $_result;
70         }
71     }
72
73     /**
74      * gets the object of a Smarty variable
75      *
76      * @param \Smarty_Internal_Data|\Smarty_Internal_Template|\Smarty $data
77      * @param string                                                  $varName       the name of the Smarty variable
78      * @param \Smarty_Internal_Data|\Smarty_Internal_Template|\Smarty $_ptr          optional pointer to data object
79      * @param bool                                                    $searchParents search also in parent data
80      * @param bool                                                    $errorEnable
81      *
82      * @return \Smarty_Variable
83      */
84     public function _getVariable(Smarty_Internal_Data $data, $varName, Smarty_Internal_Data $_ptr = null,
85                                  $searchParents = true, $errorEnable = true)
86     {
87         if ($_ptr === null) {
88             $_ptr = $data;
89         }
90         while ($_ptr !== null) {
91             if (isset($_ptr->tpl_vars[ $varName ])) {
92                 // found it, return it
93                 return $_ptr->tpl_vars[ $varName ];
94             }
95             // not found, try at parent
96             if ($searchParents) {
97                 $_ptr = $_ptr->parent;
98             } else {
99                 $_ptr = null;
100             }
101         }
102         if (isset(Smarty::$global_tpl_vars[ $varName ])) {
103             // found it, return it
104             return Smarty::$global_tpl_vars[ $varName ];
105         }
106         /* @var \Smarty $smarty */
107         $smarty = isset($data->smarty) ? $data->smarty : $data;
108         if ($smarty->error_unassigned && $errorEnable) {
109             // force a notice
110             $x = $$varName;
111         }
112
113         return new Smarty_Undefined_Variable;
114     }
115
116 }