From 7085a0c2f7104a56a7e946c43ba0b5736be5f4e7 Mon Sep 17 00:00:00 2001 From: emkael Date: Tue, 27 Dec 2016 14:47:01 +0100 Subject: * smarty bundled --- .../smarty_internal_method_gettemplatevars.php | 116 +++++++++++++++++++++ 1 file changed, 116 insertions(+) create mode 100644 lib/smarty3/sysplugins/smarty_internal_method_gettemplatevars.php (limited to 'lib/smarty3/sysplugins/smarty_internal_method_gettemplatevars.php') diff --git a/lib/smarty3/sysplugins/smarty_internal_method_gettemplatevars.php b/lib/smarty3/sysplugins/smarty_internal_method_gettemplatevars.php new file mode 100644 index 0000000..1759646 --- /dev/null +++ b/lib/smarty3/sysplugins/smarty_internal_method_gettemplatevars.php @@ -0,0 +1,116 @@ +_getVariable($data, $varName, $_ptr, $searchParents, false); + if (is_object($_var)) { + return $_var->value; + } else { + return null; + } + } else { + $_result = array(); + if ($_ptr === null) { + $_ptr = $data; + } + while ($_ptr !== null) { + foreach ($_ptr->tpl_vars AS $key => $var) { + if (!array_key_exists($key, $_result)) { + $_result[ $key ] = $var->value; + } + } + // not found, try at parent + if ($searchParents) { + $_ptr = $_ptr->parent; + } else { + $_ptr = null; + } + } + if ($searchParents && isset(Smarty::$global_tpl_vars)) { + foreach (Smarty::$global_tpl_vars AS $key => $var) { + if (!array_key_exists($key, $_result)) { + $_result[ $key ] = $var->value; + } + } + } + return $_result; + } + } + + /** + * gets the object of a Smarty variable + * + * @param \Smarty_Internal_Data|\Smarty_Internal_Template|\Smarty $data + * @param string $varName the name of the Smarty variable + * @param \Smarty_Internal_Data|\Smarty_Internal_Template|\Smarty $_ptr optional pointer to data object + * @param bool $searchParents search also in parent data + * @param bool $errorEnable + * + * @return \Smarty_Variable + */ + public function _getVariable(Smarty_Internal_Data $data, $varName, Smarty_Internal_Data $_ptr = null, + $searchParents = true, $errorEnable = true) + { + if ($_ptr === null) { + $_ptr = $data; + } + while ($_ptr !== null) { + if (isset($_ptr->tpl_vars[ $varName ])) { + // found it, return it + return $_ptr->tpl_vars[ $varName ]; + } + // not found, try at parent + if ($searchParents) { + $_ptr = $_ptr->parent; + } else { + $_ptr = null; + } + } + if (isset(Smarty::$global_tpl_vars[ $varName ])) { + // found it, return it + return Smarty::$global_tpl_vars[ $varName ]; + } + /* @var \Smarty $smarty */ + $smarty = isset($data->smarty) ? $data->smarty : $data; + if ($smarty->error_unassigned && $errorEnable) { + // force a notice + $x = $$varName; + } + + return new Smarty_Undefined_Variable; + } + +} \ No newline at end of file -- cgit v1.2.3