diff --git a/README b/README index 9011ea92..ac5dc388 100644 --- a/README +++ b/README @@ -54,6 +54,7 @@ $smarty->getConfigVariable($variable) $smarty->getStreamVariable($variable) $smarty->getConfigVars($varname = null) $smarty->clearConfig($varname = null) +$smarty->getTemplateVars($varname = null, $_ptr = null, $search_parents = true) // some API calls are moved into their own objects: @@ -87,7 +88,6 @@ $smarty->unregister->variableFilter($function_name) $smarty->utility->compileAllTemplates($extention = '.tpl', $force_compile = false, $time_limit = 0, $max_errors = null) $smarty->utility->clearCompiledTemplate($resource_name = null, $compile_id = null, $exp_time = null) -$smarty->utility->getTemplateVars($varname = null, $_ptr = null, $search_parents = true) $smarty->utility->testInstall() // then all the getters/setters, available for all properties. Here are a few: diff --git a/libs/sysplugins/smarty_internal_data.php b/libs/sysplugins/smarty_internal_data.php index 2a2eff1d..63f98a1d 100644 --- a/libs/sysplugins/smarty_internal_data.php +++ b/libs/sysplugins/smarty_internal_data.php @@ -158,6 +158,45 @@ class Smarty_Internal_Data { } } + /** + * Returns a single or all template variables + * + * @param string $varname variable name or null + * @return string variable value or or array of variables + */ + function getTemplateVars($varname = null, $_ptr = null, $search_parents = true) + { + if (isset($varname)) { + $_var = $this->getVariable($varname, $_ptr, $search_parents); + if (is_object($_var)) { + return $_var->value; + } else { + return null; + } + } else { + $_result = array(); + if ($_ptr === null) { + $_ptr = $this; + } while ($_ptr !== null) { + foreach ($_ptr->tpl_vars AS $key => $var) { + $_result[$key] = $var->value; + } + // not found, try at parent + if ($search_parents) { + $_ptr = $_ptr->parent; + } else { + $_ptr = null; + } + } + if ($search_parents) { + foreach ($this->global_tpl_vars AS $key => $var) { + $_result[$key] = $var->value; + } + } + return $_result; + } + } + /** * clear the given assigned template variable. * diff --git a/libs/sysplugins/smarty_internal_utility.php b/libs/sysplugins/smarty_internal_utility.php index 30c6e55b..abf7e1b4 100644 --- a/libs/sysplugins/smarty_internal_utility.php +++ b/libs/sysplugins/smarty_internal_utility.php @@ -154,45 +154,6 @@ class Smarty_Internal_Utility { return $_count; } - /** - * Returns a single or all template variables - * - * @param string $varname variable name or null - * @return string variable value or or array of variables - */ - function getTemplateVars($varname = null, $_ptr = null, $search_parents = true) - { - if (isset($varname)) { - $_var = $this->smarty->getVariable($varname, $_ptr, $search_parents); - if (is_object($_var)) { - return $_var->value; - } else { - return null; - } - } else { - $_result = array(); - if ($_ptr === null) { - $_ptr = $this->smarty; - } while ($_ptr !== null) { - foreach ($_ptr->tpl_vars AS $key => $var) { - $_result[$key] = $var->value; - } - // not found, try at parent - if ($search_parents) { - $_ptr = $_ptr->parent; - } else { - $_ptr = null; - } - } - if ($search_parents) { - foreach ($this->smarty->global_tpl_vars AS $key => $var) { - $_result[$key] = $var->value; - } - } - return $_result; - } - } - function testInstall() { echo "
\n";