diff options
| author | Chris Smith <toonarmy@phpbb.com> | 2008-11-25 00:31:32 +0000 |
|---|---|---|
| committer | Chris Smith <toonarmy@phpbb.com> | 2008-11-25 00:31:32 +0000 |
| commit | c95f0c793543e4af68df133a09d0db5af3b4a822 (patch) | |
| tree | 083ba1a68a3ea44b83617262be62c6add84c25f1 /phpBB/includes | |
| parent | 332521a3696df8e1504933bee5658d005549f3b4 (diff) | |
| download | forums-c95f0c793543e4af68df133a09d0db5af3b4a822.tar forums-c95f0c793543e4af68df133a09d0db5af3b4a822.tar.gz forums-c95f0c793543e4af68df133a09d0db5af3b4a822.tar.bz2 forums-c95f0c793543e4af68df133a09d0db5af3b4a822.tar.xz forums-c95f0c793543e4af68df133a09d0db5af3b4a822.zip | |
- Add template variable S_BLOCK_NAME
- Modify template::alter_block_array() so it supports modification of nested blocks
- Add (incomplete) tests for template::alter_block_array()
git-svn-id: file:///svn/phpbb/trunk@9116 89ea8834-ac86-4346-8a33-228a782c2dd0
Diffstat (limited to 'phpBB/includes')
| -rw-r--r-- | phpBB/includes/functions_template.php | 15 | ||||
| -rw-r--r-- | phpBB/includes/template.php | 52 |
2 files changed, 57 insertions, 10 deletions
diff --git a/phpBB/includes/functions_template.php b/phpBB/includes/functions_template.php index c8c79ab5e4..71de53b4c4 100644 --- a/phpBB/includes/functions_template.php +++ b/phpBB/includes/functions_template.php @@ -458,6 +458,10 @@ class template_filter extends php_user_filter $token = "(\$_${namespace}_i == \$_${namespace}_count - 1)"; break; + case 'S_BLOCK_NAME': + $token = "'$namespace'"; + break; + default: $token = $this->generate_block_data_ref(substr($varrefs[1], 0, -1), true, $varrefs[2]) . '[\'' . $varrefs[3] . '\']'; break; @@ -637,6 +641,8 @@ class template_filter extends php_user_filter // Strip the trailing period. $namespace = substr($namespace, 0, -1); + $expr = true; + // S_ROW_COUNT is deceptive, it returns the current row number now the number of rows // hence S_ROW_COUNT is deprecated in favour of S_ROW_NUM switch ($varname) @@ -658,6 +664,10 @@ class template_filter extends php_user_filter $varref = "(\$_${namespace}_i == \$_${namespace}_count - 1)"; break; + case 'S_BLOCK_NAME': + $varref = "'$namespace'"; + break; + default: // Get a reference to the data block for this namespace. $varref = $this->generate_block_data_ref($namespace, true, $defop); @@ -665,9 +675,12 @@ class template_filter extends php_user_filter // Append the variable reference. $varref .= "['$varname']"; + + $expr = false; break; } - $varref = ($echo) ? "<?php echo $varref; ?>" : ((isset($varref)) ? $varref : ''); + // @todo Test the !$expr more + $varref = ($echo) ? "<?php echo $varref; ?>" : (($expr || isset($varref)) ? $varref : ''); return $varref; } diff --git a/phpBB/includes/template.php b/phpBB/includes/template.php index 953cc984c0..a49fd75eb3 100644 --- a/phpBB/includes/template.php +++ b/phpBB/includes/template.php @@ -386,14 +386,47 @@ class template { if (strpos($blockname, '.') !== false) { - // Nested blocks are not supported - return false; + // Nested block. + $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]; + } + + $block = &$block[$blocks[$i]]; // Traverse the last block + } + else + { + // Top-level block. + $block = &$this->_tpldata[$blockname]; } // 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($this->_tpldata[$blockname]); + $key = ($key === false) ? 0 : sizeof($block); } // Get correct position if array given @@ -403,7 +436,7 @@ class template list($search_key, $search_value) = @each($key); $key = NULL; - foreach ($this->_tpldata[$blockname] as $i => $val_ary) + foreach ($block as $i => $val_ary) { if ($val_ary[$search_key] === $search_value) { @@ -423,13 +456,13 @@ class template if ($mode == 'insert') { // Re-position template blocks - for ($i = sizeof($this->_tpldata[$blockname]); $i > $key; $i--) + for ($i = sizeof($block); $i > $key; $i--) { - $this->_tpldata[$blockname][$i] = $this->_tpldata[$blockname][$i-1]; + $block[$i] = $block[$i-1]; } // Insert vararray at given position - $this->_tpldata[$blockname][$key] = $vararray; + $block[$key] = $vararray; return true; } @@ -437,12 +470,13 @@ class template // Which block to change? if ($mode == 'change') { - if ($key == sizeof($this->_tpldata[$blockname])) + if ($key == sizeof($block)) { $key--; } - $this->_tpldata[$blockname][$key] = array_merge($this->_tpldata[$blockname][$key], $vararray); + $block[$key] = array_merge($block[$key], $vararray); + return true; } |
