diff options
author | javiexin <javiexin@gmail.com> | 2017-01-08 00:00:47 +0100 |
---|---|---|
committer | javiexin <javiexin@gmail.com> | 2017-01-08 00:00:47 +0100 |
commit | 20c03cccdde2302412d1e14adda370e7eb57b8e8 (patch) | |
tree | 079407dfc7be03fe22b30c8d3f3da358e14125f3 /phpBB/phpbb | |
parent | c656bd60ef99218a710882b6f640fea099e9c6e2 (diff) | |
download | forums-20c03cccdde2302412d1e14adda370e7eb57b8e8.tar forums-20c03cccdde2302412d1e14adda370e7eb57b8e8.tar.gz forums-20c03cccdde2302412d1e14adda370e7eb57b8e8.tar.bz2 forums-20c03cccdde2302412d1e14adda370e7eb57b8e8.tar.xz forums-20c03cccdde2302412d1e14adda370e7eb57b8e8.zip |
[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.
Check out of bounds or wrong blockname errors. Added tests.
PHPBB3-14944
Diffstat (limited to 'phpBB/phpbb')
-rw-r--r-- | phpBB/phpbb/template/context.php | 16 |
1 files changed, 14 insertions, 2 deletions
diff --git a/phpBB/phpbb/template/context.php b/phpBB/phpbb/template/context.php index 1617ca3d19..8bfbd73f1a 100644 --- a/phpBB/phpbb/template/context.php +++ b/phpBB/phpbb/template/context.php @@ -305,16 +305,28 @@ class context $name = $blocks[$i]; $index = sizeof($block[$name]) - 1; } + if (!isset($block[$name])) + { + return false; + } $block = $block[$name]; + if (!isset($block[$index])) + { + return false; + } $block = $block[$index]; } + if (!isset($block[$blocks[$i]])) + { + return false; + } $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) { - return ($key === false) ? 0 : sizeof($block); + return ($key === false) ? 0 : sizeof($block) - 1; } // Get correct position if array given @@ -331,7 +343,7 @@ class context } } - return is_int($key) ? $key : false; + return (is_int($key) && ((0 <= $key) && ($key < sizeof($block)))) ? $key : false; } /** |