From c656bd60ef99218a710882b6f640fea099e9c6e2 Mon Sep 17 00:00:00 2001 From: javiexin Date: Fri, 30 Dec 2016 18:03:09 +0100 Subject: [PATCH] [ticket/14944] Add possibility to search for template loop indexes by key Adds a new function to the template interface, and implements it in the context class. The function returns the ordinal index for a specified key, with the same structure that the key for alter_block_array. Reuses same code. Remove unneeded references, do nothing for int keys. PHPBB3-14944 --- phpBB/phpbb/template/context.php | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/phpBB/phpbb/template/context.php b/phpBB/phpbb/template/context.php index e390c5a677..1617ca3d19 100644 --- a/phpBB/phpbb/template/context.php +++ b/phpBB/phpbb/template/context.php @@ -284,7 +284,7 @@ class context $blocks = explode('.', $blockname); $blockcount = sizeof($blocks) - 1; - $block = &$this->tpldata; + $block = $this->tpldata; for ($i = 0; $i < $blockcount; $i++) { if (($pos = strpos($blocks[$i], '[')) !== false) @@ -305,11 +305,11 @@ class context $name = $blocks[$i]; $index = sizeof($block[$name]) - 1; } - $block = &$block[$name]; - $block = &$block[$index]; + $block = $block[$name]; + $block = $block[$index]; } - $block = &$block[$blocks[$i]]; // Traverse the last block + $block = $block[$blocks[$i]]; // Traverse the last block // Change key to zero (change first position) if false and to last position if true if ($key === false || $key === true) @@ -331,7 +331,7 @@ class context } } - return false; + return is_int($key) ? $key : false; } /**