diff options
author | Nathan Guse <nathaniel.guse@gmail.com> | 2013-05-20 10:47:45 -0500 |
---|---|---|
committer | Nathan Guse <nathaniel.guse@gmail.com> | 2013-05-20 10:47:45 -0500 |
commit | 9fab868f0f0a420b4eb7efb42e9c4cf27e66e9b3 (patch) | |
tree | 58ab21bfd02d64fdbec8876e52aae350f56509da | |
parent | 71c1973db9cc13d24fff17393b3f7bf9fd24b736 (diff) | |
parent | 8567aaed324eb87856ee6274f8330c52beecd0a3 (diff) | |
download | forums-9fab868f0f0a420b4eb7efb42e9c4cf27e66e9b3.tar forums-9fab868f0f0a420b4eb7efb42e9c4cf27e66e9b3.tar.gz forums-9fab868f0f0a420b4eb7efb42e9c4cf27e66e9b3.tar.bz2 forums-9fab868f0f0a420b4eb7efb42e9c4cf27e66e9b3.tar.xz forums-9fab868f0f0a420b4eb7efb42e9c4cf27e66e9b3.zip |
Merge remote-tracking branch 'remotes/cyberalien/ticket/11482' into develop
# By Vjacheslav Trushkin
# Via Vjacheslav Trushkin
* remotes/cyberalien/ticket/11482:
[ticket/11482] Use double quotes for code
[ticket/11482] Unit tests for advanced DEFINE
[ticket/11482] Implementation of advanced DEFINE tag
-rw-r--r-- | phpBB/includes/template/filter.php | 28 | ||||
-rw-r--r-- | tests/template/template_test.php | 14 | ||||
-rw-r--r-- | tests/template/templates/define.html | 2 | ||||
-rw-r--r-- | tests/template/templates/define_advanced.html | 12 | ||||
-rw-r--r-- | tests/template/templates/define_include2.html | 11 | ||||
-rw-r--r-- | tests/template/templates/define_unclosed.html | 2 |
6 files changed, 67 insertions, 2 deletions
diff --git a/phpBB/includes/template/filter.php b/phpBB/includes/template/filter.php index c2c100e93e..ea7990da53 100644 --- a/phpBB/includes/template/filter.php +++ b/phpBB/includes/template/filter.php @@ -335,6 +335,10 @@ class phpbb_template_filter extends php_user_filter return '<?php ' . $this->compile_tag_define($matches[2], false) . ' ?>'; break; + case 'ENDDEFINE': + return '<?php ' . $this->compile_tag_enddefine() . ' ?>'; + break; + case 'INCLUDE': return '<?php ' . $this->compile_tag_include($matches[2]) . ' ?>'; break; @@ -839,6 +843,16 @@ class phpbb_template_filter extends php_user_filter $match = array(); preg_match('#^((?:' . self::REGEX_NS . '\.)+)?\$(?=[A-Z])([A-Z0-9_\-]*)(?: = (.*?))?$#', $tag_args, $match); + if (!empty($match[2]) && !isset($match[3]) && $op) + { + // DEFINE tag with ENDDEFINE + $array = "\$_tpldata['DEFINE']['.vars']"; + $code = 'ob_start(); '; + $code .= "if (!isset($array)) { $array = array(); } "; + $code .= "{$array}[] = '{$match[2]}'"; + return $code; + } + if (empty($match[2]) || (!isset($match[3]) && $op)) { return ''; @@ -866,6 +880,20 @@ class phpbb_template_filter extends php_user_filter } /** + * Compile ENDDEFINE tag + * + * @return string compiled template code + */ + private function compile_tag_enddefine() + { + $array = "\$_tpldata['DEFINE']['.vars']"; + $code = "if (!isset($array) || !sizeof($array)) { trigger_error('ENDDEFINE tag without DEFINE in ' . basename(__FILE__), E_USER_ERROR); }"; + $code .= "\$define_var = array_pop($array); "; + $code .= "\$_tpldata['DEFINE']['.'][\$define_var] = ob_get_clean();"; + return $code; + } + + /** * Compile INCLUDE tag * * @param string $tag_args Expression given with INCLUDE in source template diff --git a/tests/template/template_test.php b/tests/template/template_test.php index 56cc7a9de5..a3c0b69123 100644 --- a/tests/template/template_test.php +++ b/tests/template/template_test.php @@ -133,6 +133,20 @@ class phpbb_template_template_test extends phpbb_template_template_test_case "xyz\nabc\nabc\nbar\nbar\nabc", ), array( + 'define_advanced.html', + array(), + array('loop' => array(array(), array(), array(), array(), array(), array(), array()), 'test' => array(array()), 'test.deep' => array(array()), 'test.deep.defines' => array(array())), + array(), + "abc\nzxc\ncde\nbcd", + ), + array( + 'define_unclosed.html', + array(), + array(), + array(), + "test", + ), + array( 'expressions.html', array(), array(), diff --git a/tests/template/templates/define.html b/tests/template/templates/define.html index 4459fffbe0..4e6d0ee793 100644 --- a/tests/template/templates/define.html +++ b/tests/template/templates/define.html @@ -7,5 +7,3 @@ {$VALUE} <!-- UNDEFINE $VALUE --> {$VALUE} -<!-- DEFINE $VALUE --> - diff --git a/tests/template/templates/define_advanced.html b/tests/template/templates/define_advanced.html new file mode 100644 index 0000000000..83467a5b4b --- /dev/null +++ b/tests/template/templates/define_advanced.html @@ -0,0 +1,12 @@ +<!-- DEFINE $VALUE --> +abc +<!-- ENDDEFINE --> +{$VALUE} +<!-- DEFINE $VALUE1 --> +bcd +<!-- ENDDEFINE --> +<!-- DEFINE $VALUE2 --> +cde +<!-- ENDDEFINE --> +<!-- INCLUDE define_include2.html --> +{$INCLUDED_VALUE3} diff --git a/tests/template/templates/define_include2.html b/tests/template/templates/define_include2.html new file mode 100644 index 0000000000..874f3e1852 --- /dev/null +++ b/tests/template/templates/define_include2.html @@ -0,0 +1,11 @@ +<!-- DEFINE $INCLUDED_VALUE1 --> +zxc +<!-- ENDDEFINE --> +<!-- DEFINE $INCLUDED_VALUE2 --> +qwe +<!-- ENDDEFINE --> +{$INCLUDED_VALUE1} +<!-- DEFINE $INCLUDED_VALUE3 --> +{$VALUE2} +{$VALUE1} +<!-- ENDDEFINE --> diff --git a/tests/template/templates/define_unclosed.html b/tests/template/templates/define_unclosed.html new file mode 100644 index 0000000000..1c975eab2b --- /dev/null +++ b/tests/template/templates/define_unclosed.html @@ -0,0 +1,2 @@ +<!-- DEFINE $VALUE --> +test |