diff options
Diffstat (limited to 'phpBB/phpbb/template/context.php')
-rw-r--r-- | phpBB/phpbb/template/context.php | 79 |
1 files changed, 33 insertions, 46 deletions
diff --git a/phpBB/phpbb/template/context.php b/phpBB/phpbb/template/context.php index c1e971c148..de583d3224 100644 --- a/phpBB/phpbb/template/context.php +++ b/phpBB/phpbb/template/context.php @@ -142,7 +142,7 @@ class context */ protected function set_num_rows(&$loop_data) { - $s_num_rows = sizeof($loop_data); + $s_num_rows = count($loop_data); foreach ($loop_data as &$mod_block) { foreach ($mod_block as $sub_block_name => &$sub_block) @@ -265,7 +265,7 @@ 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++) @@ -276,17 +276,17 @@ class context if (strpos($blocks[$i], '[]') === $pos) { - $index = sizeof($block[$name]) - 1; + $index = count($block[$name]) - 1; } else { - $index = min((int) substr($blocks[$i], $pos + 1, -1), sizeof($block[$name]) - 1); + $index = min((int) substr($blocks[$i], $pos + 1, -1), count($block[$name]) - 1); } } else { $name = $blocks[$i]; - $index = sizeof($block[$name]) - 1; + $index = count($block[$name]) - 1; } $block = $block[$name]; $block = $block[$index]; @@ -335,39 +335,26 @@ 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); + $pos = strpos($blocks[$i], '['); + $name = ($pos !== false) ? substr($blocks[$i], 0, $pos) : $blocks[$i]; - 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; - } if (!isset($block[$name])) { return false; } - $block = $block[$name]; - if (!isset($block[$index])) + + $index = (!$pos || strpos($blocks[$i], '[]') === $pos) ? (count($block[$name]) - 1) : (min((int) substr($blocks[$i], $pos + 1, -1), count($block[$name]) - 1)); + + if (!isset($block[$name][$index])) { return false; } - $block = $block[$index]; + $block = $block[$name][$index]; } if (!isset($block[$blocks[$i]])) @@ -377,9 +364,9 @@ class context $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) + if (is_bool($key)) { - return ($key === false) ? 0 : sizeof($block) - 1; + return (!$key) ? 0 : count($block) - 1; } // Get correct position if array given @@ -396,7 +383,7 @@ class context } } - return (is_int($key) && ((0 <= $key) && ($key < sizeof($block)))) ? $key : false; + return (is_int($key) && ((0 <= $key) && ($key < count($block)))) ? $key : false; } /** @@ -433,7 +420,7 @@ 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++) @@ -444,17 +431,17 @@ class context if (strpos($blocks[$i], '[]') === $pos) { - $index = sizeof($block[$name]) - 1; + $index = count($block[$name]) - 1; } else { - $index = min((int) substr($blocks[$i], $pos + 1, -1), sizeof($block[$name]) - 1); + $index = min((int) substr($blocks[$i], $pos + 1, -1), count($block[$name]) - 1); } } else { $name = $blocks[$i]; - $index = sizeof($block[$name]) - 1; + $index = count($block[$name]) - 1; } $block = &$block[$name]; $block = &$block[$index]; @@ -476,7 +463,7 @@ class context // Change key to zero (change first position) if false and to last position if true if ($key === false || $key === true) { - $key = ($key === false) ? 0 : sizeof($block); + $key = ($key === false) ? 0 : count($block); } // Get correct position if array given @@ -506,9 +493,9 @@ class context if ($mode == 'insert') { // Make sure we are not exceeding the last iteration - if ($key >= sizeof($block)) + if ($key >= count($block)) { - $key = sizeof($block); + $key = count($block); unset($block[($key - 1)]['S_LAST_ROW']); $vararray['S_LAST_ROW'] = true; } @@ -523,7 +510,7 @@ class context $vararray['S_BLOCK_NAME'] = $name; // Re-position template blocks - for ($i = sizeof($block); $i > $key; $i--) + for ($i = count($block); $i > $key; $i--) { $block[$i] = $block[$i-1]; @@ -541,12 +528,12 @@ class context if ($mode == 'change') { // If key is out of bounds, do not change anything - if ($key > sizeof($block) || $key < 0) + if ($key > count($block) || $key < 0) { return false; } - if ($key == sizeof($block)) + if ($key == count($block)) { $key--; } @@ -560,26 +547,26 @@ class context if ($mode == 'delete') { // If we are exceeding last iteration, do not delete anything - if ($key > sizeof($block) || $key < 0) + if ($key > count($block) || $key < 0) { return false; } // If we are positioned at the end, we remove the last element - if ($key == sizeof($block)) + if ($key == count($block)) { $key--; } // We are deleting the last element in the block, so remove the block - if (sizeof($block) === 1) + if (count($block) === 1) { $block = null; // unset($block); does not work on references return true; } // Re-position template blocks - for ($i = $key; $i < sizeof($block)-1; $i++) + for ($i = $key; $i < count($block)-1; $i++) { $block[$i] = $block[$i+1]; $block[$i]['S_ROW_COUNT'] = $block[$i]['S_ROW_NUM'] = $i; @@ -590,7 +577,7 @@ class context // Set first and last elements again, in case they were removed $block[0]['S_FIRST_ROW'] = true; - $block[sizeof($block)-1]['S_LAST_ROW'] = true; + $block[count($block)-1]['S_LAST_ROW'] = true; return true; } @@ -611,13 +598,13 @@ class context { // Nested block. $blocks = explode('.', $blockname); - $blockcount = sizeof($blocks) - 1; + $blockcount = count($blocks) - 1; $str = &$this->tpldata; for ($i = 0; $i < $blockcount; $i++) { $str = &$str[$blocks[$i]]; - $str = &$str[sizeof($str) - 1]; + $str = &$str[count($str) - 1]; } unset($str[$blocks[$blockcount]]); |