aboutsummaryrefslogtreecommitdiffstats
path: root/phpBB/phpbb/template/context.php
diff options
context:
space:
mode:
authorjaviexin <javiexin@gmail.com>2017-02-05 21:47:31 +0100
committerjaviexin <javiexin@gmail.com>2017-02-05 21:47:31 +0100
commitf23d9bf2e0886498a3d9d5bb0a800d663b795e61 (patch)
treea3042937f9f2cbaced596f61d4c8fca496dbf83c /phpBB/phpbb/template/context.php
parent3322117c3863c443ca1b79d25541bde4c662c0ed (diff)
downloadforums-f23d9bf2e0886498a3d9d5bb0a800d663b795e61.tar
forums-f23d9bf2e0886498a3d9d5bb0a800d663b795e61.tar.gz
forums-f23d9bf2e0886498a3d9d5bb0a800d663b795e61.tar.bz2
forums-f23d9bf2e0886498a3d9d5bb0a800d663b795e61.tar.xz
forums-f23d9bf2e0886498a3d9d5bb0a800d663b795e61.zip
[ticket/15068] Add template vars retrieval from the template object
PHPBB3-15068
Diffstat (limited to 'phpBB/phpbb/template/context.php')
-rw-r--r--phpBB/phpbb/template/context.php57
1 files changed, 57 insertions, 0 deletions
diff --git a/phpBB/phpbb/template/context.php b/phpBB/phpbb/template/context.php
index 4ee48205c8..0e5f3287aa 100644
--- a/phpBB/phpbb/template/context.php
+++ b/phpBB/phpbb/template/context.php
@@ -87,6 +87,17 @@ class context
}
/**
+ * Retreive a single scalar value from a single key.
+ *
+ * @param string $varname Variable name
+ * @return mixed Variable value, or null if not set
+ */
+ public function retrieve_var($varname)
+ {
+ return isset($this->rootref[$varname]) ? $this->rootref[$varname] : null;
+ }
+
+ /**
* Returns a reference to template data array.
*
* This function is public so that template renderer may invoke it.
@@ -264,6 +275,52 @@ class context
}
/**
+ * Retrieve key variable pairs from the specified block
+ *
+ * @param string $blockname Name of block to retrieve $vararray from
+ * @param array $vararray An array of variable names
+ * @return array of hashes with variable name as key and retrieved value or null as value
+ */
+ public function retrieve_block_vars($blockname, array $vararray)
+ {
+ // For nested block, $blockcount > 0, for top-level block, $blockcount == 0
+ $blocks = explode('.', $blockname);
+ $blockcount = sizeof($blocks) - 1;
+
+ $block = $this->tpldata;
+ for ($i = 0; $i <= $blockcount; $i++)
+ {
+ if (($pos = strpos($blocks[$i], '[')) !== false)
+ {
+ $name = substr($blocks[$i], 0, $pos);
+
+ if (strpos($blocks[$i], '[]') === $pos)
+ {
+ $index = sizeof($block[$name]) - 1;
+ }
+ else
+ {
+ $index = min((int) substr($blocks[$i], $pos + 1, -1), sizeof($block[$name]) - 1);
+ }
+ }
+ else
+ {
+ $name = $blocks[$i];
+ $index = sizeof($block[$name]) - 1;
+ }
+ $block = $block[$name];
+ $block = $block[$index];
+ }
+
+ $result = array();
+ foreach ($vararray as $varname)
+ {
+ $result[$varname] = isset($block[$varname]) ? $block[$varname] : null;
+ }
+ return $result;
+ }
+
+ /**
* Change already assigned key variable pair (one-dimensional - single loop entry)
*
* An example of how to use this function: