aboutsummaryrefslogtreecommitdiffstats
path: root/include/smarty/libs/sysplugins/smarty_internal_method_gettemplatevars.php
diff options
context:
space:
mode:
authorplegall <plg@piwigo.org>2016-02-01 10:20:57 +0100
committerplegall <plg@piwigo.org>2016-02-01 10:20:57 +0100
commitda8d2b2af0e38715a929b3d4b900ee793cdfb3e8 (patch)
tree386658eb909674adbb0c2afbe756bdbf9a895d37 /include/smarty/libs/sysplugins/smarty_internal_method_gettemplatevars.php
parent70726892e031553563899783d9caab4d2c2e5b65 (diff)
parent2fcf276811723d300b4d4c08675994339a6688fa (diff)
Merge branch 'master' into translation
Diffstat (limited to 'include/smarty/libs/sysplugins/smarty_internal_method_gettemplatevars.php')
-rw-r--r--include/smarty/libs/sysplugins/smarty_internal_method_gettemplatevars.php114
1 files changed, 114 insertions, 0 deletions
diff --git a/include/smarty/libs/sysplugins/smarty_internal_method_gettemplatevars.php b/include/smarty/libs/sysplugins/smarty_internal_method_gettemplatevars.php
new file mode 100644
index 000000000..235bece46
--- /dev/null
+++ b/include/smarty/libs/sysplugins/smarty_internal_method_gettemplatevars.php
@@ -0,0 +1,114 @@
+<?php
+
+/**
+ * Smarty Method GetTemplateVars
+ *
+ * Smarty::getTemplateVars() method
+ *
+ * @package Smarty
+ * @subpackage PluginsInternal
+ * @author Uwe Tews
+ */
+class Smarty_Internal_Method_GetTemplateVars
+{
+ /**
+ * Valid for all objects
+ *
+ * @var int
+ */
+ public $objMap = 7;
+
+ /**
+ * Returns a single or all template variables
+ *
+ * @api Smarty::getTemplateVars()
+ * @link http://www.smarty.net/docs/en/api.get.template.vars.tpl
+ *
+ * @param \Smarty_Internal_Data|\Smarty_Internal_Template|\Smarty $data
+ * @param string $varName variable name or null
+ * @param \Smarty_Internal_Data|\Smarty_Internal_Template|\Smarty $_ptr optional pointer to data object
+ * @param bool $searchParents include parent templates?
+ *
+ * @return mixed variable value or or array of variables
+ */
+ public function getTemplateVars(Smarty_Internal_Data $data, $varName = null, Smarty_Internal_Data $_ptr = null, $searchParents = true)
+ {
+ if (isset($varName)) {
+ $_var = $this->_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