diff options
author | javiexin <javiexin@gmail.com> | 2017-05-31 13:57:41 +0200 |
---|---|---|
committer | Marc Alexander <admin@m-a-styles.de> | 2017-11-01 12:29:49 +0100 |
commit | c2043e47dabc23100ecc388ae1e9d8ae20c2257e (patch) | |
tree | 71cf246315b587dfe64a15043e4a49f561d11127 /phpBB/phpbb/template/context.php | |
parent | bf882826e48d4f29ca4c48ecb7d65cbdf459d5fb (diff) | |
download | forums-c2043e47dabc23100ecc388ae1e9d8ae20c2257e.tar forums-c2043e47dabc23100ecc388ae1e9d8ae20c2257e.tar.gz forums-c2043e47dabc23100ecc388ae1e9d8ae20c2257e.tar.bz2 forums-c2043e47dabc23100ecc388ae1e9d8ae20c2257e.tar.xz forums-c2043e47dabc23100ecc388ae1e9d8ae20c2257e.zip |
[ticket/14994] Refactor template->assign_block_var
Refactor assign_block_var to use the same block selection mechanism
as is used in alter_block_array. This allows creating new blocks
at any position in the template structure, not only on the last block.
Allows selecting a block as outer[2].middle.
Added tests. Added PHP 7.2 compatibility.
PHPBB3-14994
Diffstat (limited to 'phpBB/phpbb/template/context.php')
-rw-r--r-- | phpBB/phpbb/template/context.php | 23 |
1 files changed, 4 insertions, 19 deletions
diff --git a/phpBB/phpbb/template/context.php b/phpBB/phpbb/template/context.php index 55d7b9c861..5a15e12582 100644 --- a/phpBB/phpbb/template/context.php +++ b/phpBB/phpbb/template/context.php @@ -193,30 +193,15 @@ class context // For nested block, $blockcount > 0, for top-level block, $blockcount == 0 $blocks = explode('.', $blockname); - $blockcount = sizeof($blocks) - 1; + $blockcount = count($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; - } + $pos = strpos($blocks[$i], '['); + $name = ($pos !== false) ? substr($blocks[$i], 0, $pos) : $blocks[$i]; $block = &$block[$name]; + $index = (!$pos || strpos($blocks[$i], '[]') === $pos) ? (count($block) - 1) : (min((int) substr($blocks[$i], $pos + 1, -1), count($block) - 1)); $block = &$block[$index]; } |