From 6b0b0f2a9fdd2e2169534756e9ceb4421125c7ea Mon Sep 17 00:00:00 2001 From: Nathaniel Guse Date: Sun, 14 Jul 2013 12:10:49 -0500 Subject: [ticket/11701] Loop variables are not passed correctly to events PHPBB3-11701 --- phpBB/phpbb/template/twig/lexer.php | 10 +++++----- phpBB/phpbb/template/twig/twig.php | 4 ++-- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/phpBB/phpbb/template/twig/lexer.php b/phpBB/phpbb/template/twig/lexer.php index 4f88147542..606ca347ae 100644 --- a/phpBB/phpbb/template/twig/lexer.php +++ b/phpBB/phpbb/template/twig/lexer.php @@ -191,20 +191,20 @@ class phpbb_template_twig_lexer extends Twig_Lexer // Recursive...fix any child nodes $body = $parent_class->fix_begin_tokens($body, $parent_nodes); - // Rename loopname vars (to prevent collisions, loop children are named (loop name)_loop_element) - $body = str_replace($name . '.', $name . '_loop_element.', $body); + // Rename loopname vars + $body = str_replace($name . '.', $name . '.', $body); // Need the parent variable name array_pop($parent_nodes); - $parent = (!empty($parent_nodes)) ? end($parent_nodes) . '_loop_element.' : ''; + $parent = (!empty($parent_nodes)) ? end($parent_nodes) . '.' : ''; if ($subset !== '') { $subset = '|subset(' . $subset . ')'; } - // Turn into a Twig for loop, using (loop name)_loop_element for each child - return "{% for {$name}_loop_element in {$parent}{$name}{$subset} %}{$body}{% endfor %}"; + // Turn into a Twig for loop + return "{% for {$name} in loops.{$parent}{$name}{$subset} %}{$body}{% endfor %}"; }; // Replace correctly, only needs to be done once diff --git a/phpBB/phpbb/template/twig/twig.php b/phpBB/phpbb/template/twig/twig.php index 92a37d1634..6cff1bb8e4 100644 --- a/phpBB/phpbb/template/twig/twig.php +++ b/phpBB/phpbb/template/twig/twig.php @@ -429,15 +429,15 @@ class phpbb_template_twig implements phpbb_template $vars = array_merge( $context_vars['.'][0], // To get normal vars - $context_vars, // To get loops array( 'definition' => new phpbb_template_twig_definition(), 'user' => $this->user, + 'loops' => $context_vars, // To get loops ) ); // cleanup - unset($vars['.']); + unset($vars['loops']['.']); return $vars; } -- cgit v1.2.1 From 0d31420ae099b9284c6240bfbda0f03f1be155c1 Mon Sep 17 00:00:00 2001 From: Nathaniel Guse Date: Sun, 14 Jul 2013 12:18:44 -0500 Subject: [ticket/11701] Remove useless str_replace PHPBB3-11701 --- phpBB/phpbb/template/twig/lexer.php | 3 --- 1 file changed, 3 deletions(-) diff --git a/phpBB/phpbb/template/twig/lexer.php b/phpBB/phpbb/template/twig/lexer.php index 606ca347ae..3c072adff9 100644 --- a/phpBB/phpbb/template/twig/lexer.php +++ b/phpBB/phpbb/template/twig/lexer.php @@ -191,9 +191,6 @@ class phpbb_template_twig_lexer extends Twig_Lexer // Recursive...fix any child nodes $body = $parent_class->fix_begin_tokens($body, $parent_nodes); - // Rename loopname vars - $body = str_replace($name . '.', $name . '.', $body); - // Need the parent variable name array_pop($parent_nodes); $parent = (!empty($parent_nodes)) ? end($parent_nodes) . '.' : ''; -- cgit v1.2.1 From c0b9db1c626c88780b2ee5f5a237561a125c54aa Mon Sep 17 00:00:00 2001 From: Nathaniel Guse Date: Sun, 14 Jul 2013 14:10:11 -0500 Subject: [ticket/11701] Fix loops var check PHPBB3-11701 --- phpBB/phpbb/template/twig/lexer.php | 8 ++++-- tests/template/template_test.php | 32 +++++++++++------------ tests/template/templates/include_loop.html | 8 +++--- tests/template/templates/include_loop_define.html | 6 ++--- tests/template/templates/loop.html | 14 +++++----- tests/template/templates/loop_advanced.html | 20 +++++++------- tests/template/templates/loop_size.html | 10 +++---- tests/template/templates/loop_vars.html | 18 ++++++------- 8 files changed, 60 insertions(+), 56 deletions(-) diff --git a/phpBB/phpbb/template/twig/lexer.php b/phpBB/phpbb/template/twig/lexer.php index 3c072adff9..4f127bd7e6 100644 --- a/phpBB/phpbb/template/twig/lexer.php +++ b/phpBB/phpbb/template/twig/lexer.php @@ -200,8 +200,9 @@ class phpbb_template_twig_lexer extends Twig_Lexer $subset = '|subset(' . $subset . ')'; } + $parent = ($parent) ?: 'loops.'; // Turn into a Twig for loop - return "{% for {$name} in loops.{$parent}{$name}{$subset} %}{$body}{% endfor %}"; + return "{% for {$name} in {$parent}{$name}{$subset} %}{$body}{% endfor %}"; }; // Replace correctly, only needs to be done once @@ -224,7 +225,10 @@ class phpbb_template_twig_lexer extends Twig_Lexer // Replace $TEST with definition.TEST $inner = preg_replace('#\s\$([a-zA-Z_0-9]+)#', ' definition.$1', $inner); - // Replace .test with test|length + // Replace .foo with loops.foo|length + $inner = preg_replace('#\s\.([a-zA-Z_0-9]+)#', ' loops.$1|length', $inner); + + // Replace .foo.bar with foo.bar|length $inner = preg_replace('#\s\.([a-zA-Z_0-9\.]+)#', ' $1|length', $inner); return ""; diff --git a/tests/template/template_test.php b/tests/template/template_test.php index dd9ba21c26..0a6b680100 100644 --- a/tests/template/template_test.php +++ b/tests/template/template_test.php @@ -93,49 +93,49 @@ class phpbb_template_template_test extends phpbb_template_template_test_case array( 'loop.html', array(), - array('loop' => array(array())), + array('test_loop' => array(array())), array(), "loop\nloop", ), array( 'loop.html', array(), - array('loop' => array(array(), array()), 'loop.block' => array(array())), + array('test_loop' => array(array(), array()), 'test_loop.block' => array(array())), array(), "loop\nloop\nloop\nloop", ), array( 'loop.html', array(), - array('loop' => array(array(), array()), 'loop.block' => array(array()), 'block' => array(array(), array())), + array('test_loop' => array(array(), array()), 'test_loop.block' => array(array()), 'block' => array(array(), array())), array(), "loop\nloop\nloop\nloop\nloop#0-block#0\nloop#0-block#1\nloop#1-block#0\nloop#1-block#1", ), array( 'loop_vars.html', array(), - array('loop' => array(array('VARIABLE' => 'x'))), + array('test_loop' => array(array('VARIABLE' => 'x'))), array(), "first\n0 - a\nx - b\nset\nlast", ), array( 'loop_vars.html', array(), - array('loop' => array(array('VARIABLE' => 'x'), array('VARIABLE' => 'y'))), + array('test_loop' => array(array('VARIABLE' => 'x'), array('VARIABLE' => 'y'))), array(), "first\n0 - a\nx - b\nset\n1 - a\ny - b\nset\nlast", ), array( 'loop_vars.html', array(), - array('loop' => array(array('VARIABLE' => 'x'), array('VARIABLE' => 'y')), 'loop.inner' => array(array(), array())), + array('test_loop' => array(array('VARIABLE' => 'x'), array('VARIABLE' => 'y')), 'test_loop.inner' => array(array(), array())), array(), "first\n0 - a\nx - b\nset\n1 - a\ny - b\nset\nlast\n0 - c\n1 - c\nlast inner", ), array( 'loop_advanced.html', array(), - array('loop' => array(array(), array(), array(), array(), array(), array(), array())), + array('test_loop' => array(array(), array(), array(), array(), array(), array(), array())), array(), "101234561\nx\n101234561\nx\n101234561\nx\n1234561\nx\n1\nx\n101\nx\n234\nx\n10\nx\n561\nx\n561", ), @@ -149,14 +149,14 @@ class phpbb_template_template_test extends phpbb_template_template_test_case array( 'define.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('test_loop' => array(array(), array(), array(), array(), array(), array(), array()), 'test' => array(array()), 'test.deep' => array(array()), 'test.deep.defines' => array(array())), array(), "xyz\nabc\n\$VALUE == 'abc'abc\nbar\nbar\nabc\ntest!@#$%^&*()_-=+{}[]:;\",<.>/?", ), 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('test_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", ), @@ -200,7 +200,7 @@ class phpbb_template_template_test extends phpbb_template_template_test_case array( 'include_loop.html', array(), - array('loop' => array(array('NESTED_FILE' => 'include_loop1.html')), 'loop.inner' => array(array('NESTED_FILE' => 'include_loop1.html'), array('NESTED_FILE' => 'include_loop2.html'), array('NESTED_FILE' => 'include_loop3.html'))), + array('test_loop' => array(array('NESTED_FILE' => 'include_loop1.html')), 'test_loop.inner' => array(array('NESTED_FILE' => 'include_loop1.html'), array('NESTED_FILE' => 'include_loop2.html'), array('NESTED_FILE' => 'include_loop3.html'))), array(), "1\n_1\n_02\n_3", ), @@ -221,8 +221,8 @@ class phpbb_template_template_test extends phpbb_template_template_test_case array( 'loop_vars.html', array(), - array('loop' => array(array('VARIABLE' => 'x'), array('VARIABLE' => 'y')), 'loop.inner' => array(array(), array())), - array('loop'), + array('test_loop' => array(array('VARIABLE' => 'x'), array('VARIABLE' => 'y')), 'test_loop.inner' => array(array(), array())), + array('test_loop'), '', ), array( @@ -235,7 +235,7 @@ class phpbb_template_template_test extends phpbb_template_template_test_case array( 'include_loop_define.html', array('VARIABLE' => 'value'), - array('loop' => array(array('NESTED_FILE' => 'variable.html'))), + array('test_loop' => array(array('NESTED_FILE' => 'variable.html'))), array(), 'value', ), @@ -243,8 +243,8 @@ class phpbb_template_template_test extends phpbb_template_template_test_case array( 'loop_vars.html', array(), - array('loop' => array(array('VARIABLE' => 'x'), array('VARIABLE' => 'y')), 'loop.inner' => array(array(), array())), - array('loop.inner'), + array('test_loop' => array(array('VARIABLE' => 'x'), array('VARIABLE' => 'y')), 'test_loop.inner' => array(array(), array())), + array('test_loop.inner'), "first\n0\n0\n2\nx\nset\n1\n1\n2\ny\nset\nlast", ),*/ array( @@ -295,7 +295,7 @@ class phpbb_template_template_test extends phpbb_template_template_test_case array( 'loop_size.html', array(), - array('loop' => array(array()), 'empty_loop' => array()), + array('test_loop' => array(array()), 'empty_loop' => array()), array(), "nonexistent = 0\n! nonexistent\n\nempty = 0\n! empty\nloop\n\nin loop", ), diff --git a/tests/template/templates/include_loop.html b/tests/template/templates/include_loop.html index d5c3d9bc82..5cad34b363 100644 --- a/tests/template/templates/include_loop.html +++ b/tests/template/templates/include_loop.html @@ -1,4 +1,4 @@ - - -_ - + + +_ + diff --git a/tests/template/templates/include_loop_define.html b/tests/template/templates/include_loop_define.html index f539b21396..4bab09422e 100644 --- a/tests/template/templates/include_loop_define.html +++ b/tests/template/templates/include_loop_define.html @@ -1,4 +1,4 @@ - - + + - + diff --git a/tests/template/templates/loop.html b/tests/template/templates/loop.html index de1a10004d..f541e934df 100644 --- a/tests/template/templates/loop.html +++ b/tests/template/templates/loop.html @@ -1,21 +1,21 @@ - + loop noloop - + - + loop noloop - + loop - + -loop#{loop.S_ROW_COUNT}-block#{block.S_ROW_COUNT} +loop#{test_loop.S_ROW_COUNT}-block#{block.S_ROW_COUNT} - + diff --git a/tests/template/templates/loop_advanced.html b/tests/template/templates/loop_advanced.html index c75fe55f03..1f56686eaa 100644 --- a/tests/template/templates/loop_advanced.html +++ b/tests/template/templates/loop_advanced.html @@ -1,19 +1,19 @@ -{loop.S_FIRST_ROW}{loop.S_ROW_COUNT}{loop.S_LAST_ROW} +{test_loop.S_FIRST_ROW}{test_loop.S_ROW_COUNT}{test_loop.S_LAST_ROW} x -{loop.S_FIRST_ROW}{loop.S_ROW_COUNT}{loop.S_LAST_ROW} +{test_loop.S_FIRST_ROW}{test_loop.S_ROW_COUNT}{test_loop.S_LAST_ROW} x -{loop.S_FIRST_ROW}{loop.S_ROW_COUNT}{loop.S_LAST_ROW} +{test_loop.S_FIRST_ROW}{test_loop.S_ROW_COUNT}{test_loop.S_LAST_ROW} x -{loop.S_FIRST_ROW}{loop.S_ROW_COUNT}{loop.S_LAST_ROW} +{test_loop.S_FIRST_ROW}{test_loop.S_ROW_COUNT}{test_loop.S_LAST_ROW} x -{loop.S_FIRST_ROW}{loop.S_ROW_COUNT}{loop.S_LAST_ROW} +{test_loop.S_FIRST_ROW}{test_loop.S_ROW_COUNT}{test_loop.S_LAST_ROW} x -{loop.S_FIRST_ROW}{loop.S_ROW_COUNT}{loop.S_LAST_ROW} +{test_loop.S_FIRST_ROW}{test_loop.S_ROW_COUNT}{test_loop.S_LAST_ROW} x -{loop.S_FIRST_ROW}{loop.S_ROW_COUNT}{loop.S_LAST_ROW} +{test_loop.S_FIRST_ROW}{test_loop.S_ROW_COUNT}{test_loop.S_LAST_ROW} x -{loop.S_FIRST_ROW}{loop.S_ROW_COUNT}{loop.S_LAST_ROW} +{test_loop.S_FIRST_ROW}{test_loop.S_ROW_COUNT}{test_loop.S_LAST_ROW} x -{loop.S_FIRST_ROW}{loop.S_ROW_COUNT}{loop.S_LAST_ROW} +{test_loop.S_FIRST_ROW}{test_loop.S_ROW_COUNT}{test_loop.S_LAST_ROW} x -{loop.S_FIRST_ROW}{loop.S_ROW_COUNT}{loop.S_LAST_ROW} +{test_loop.S_FIRST_ROW}{test_loop.S_ROW_COUNT}{test_loop.S_LAST_ROW} diff --git a/tests/template/templates/loop_size.html b/tests/template/templates/loop_size.html index 8f581cef10..2b1fcd2dd4 100644 --- a/tests/template/templates/loop_size.html +++ b/tests/template/templates/loop_size.html @@ -22,18 +22,18 @@ ! empty - + loop - + loop = 0 - + ! loop - + in loop - + diff --git a/tests/template/templates/loop_vars.html b/tests/template/templates/loop_vars.html index 7d86d4b7b6..70a3eb2cec 100644 --- a/tests/template/templates/loop_vars.html +++ b/tests/template/templates/loop_vars.html @@ -1,13 +1,13 @@ - -first -{loop.S_ROW_NUM} - a -{loop.VARIABLE} - b -set - + +first +{test_loop.S_ROW_NUM} - a +{test_loop.VARIABLE} - b +set + last -{inner.S_ROW_NUM} - c -last inner +{test_loop.inner.S_ROW_NUM} - c +last inner - + -- cgit v1.2.1 From 2d764ef7d54104be2925aa015193da20c4383c5d Mon Sep 17 00:00:00 2001 From: Nathaniel Guse Date: Fri, 19 Jul 2013 11:31:52 -0500 Subject: [ticket/11701] Fix regex for appending |length PHPBB3-11701 --- phpBB/phpbb/template/twig/lexer.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/phpBB/phpbb/template/twig/lexer.php b/phpBB/phpbb/template/twig/lexer.php index 4f127bd7e6..95b3043403 100644 --- a/phpBB/phpbb/template/twig/lexer.php +++ b/phpBB/phpbb/template/twig/lexer.php @@ -226,10 +226,10 @@ class phpbb_template_twig_lexer extends Twig_Lexer $inner = preg_replace('#\s\$([a-zA-Z_0-9]+)#', ' definition.$1', $inner); // Replace .foo with loops.foo|length - $inner = preg_replace('#\s\.([a-zA-Z_0-9]+)#', ' loops.$1|length', $inner); + $inner = preg_replace('#\s\.([a-zA-Z_0-9]+) #', ' loops.$1|length ', $inner); // Replace .foo.bar with foo.bar|length - $inner = preg_replace('#\s\.([a-zA-Z_0-9\.]+)#', ' $1|length', $inner); + $inner = preg_replace('#\s\.([a-zA-Z_0-9\.]+) #', ' $1|length ', $inner); return ""; }; -- cgit v1.2.1 From ea250a5ef5dd3e790b22336e5a9e74c77da35569 Mon Sep 17 00:00:00 2001 From: Nathaniel Guse Date: Fri, 19 Jul 2013 12:43:24 -0500 Subject: [ticket/11701] Refix regex for appending |length PHPBB3-11701 --- phpBB/phpbb/template/twig/lexer.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/phpBB/phpbb/template/twig/lexer.php b/phpBB/phpbb/template/twig/lexer.php index 95b3043403..3534311b7a 100644 --- a/phpBB/phpbb/template/twig/lexer.php +++ b/phpBB/phpbb/template/twig/lexer.php @@ -226,10 +226,10 @@ class phpbb_template_twig_lexer extends Twig_Lexer $inner = preg_replace('#\s\$([a-zA-Z_0-9]+)#', ' definition.$1', $inner); // Replace .foo with loops.foo|length - $inner = preg_replace('#\s\.([a-zA-Z_0-9]+) #', ' loops.$1|length ', $inner); + $inner = preg_replace('#\s\.([a-zA-Z_0-9]+)([^a-zA-Z_0-9\.])#', ' loops.$1|length$2', $inner); // Replace .foo.bar with foo.bar|length - $inner = preg_replace('#\s\.([a-zA-Z_0-9\.]+) #', ' $1|length ', $inner); + $inner = preg_replace('#\s\.([a-zA-Z_0-9\.]+)([^a-zA-Z_0-9\.])#', ' $1|length$2', $inner); return ""; }; -- cgit v1.2.1 From 30bfd7fb61bbe1d7ca50290730d8c4b6094c41a4 Mon Sep 17 00:00:00 2001 From: Nathaniel Guse Date: Fri, 19 Jul 2013 13:25:53 -0500 Subject: [ticket/11701] Test events in loops PHPBB3-11701 --- .../ext/trivial/styles/all/template/test_event_loop.html | 1 + .../ext_trivial/styles/silver/template/event_loop.html | 3 +++ tests/template/template_events_test.php | 10 ++++++++++ 3 files changed, 14 insertions(+) create mode 100644 tests/template/datasets/ext_trivial/ext/trivial/styles/all/template/test_event_loop.html create mode 100644 tests/template/datasets/ext_trivial/styles/silver/template/event_loop.html diff --git a/tests/template/datasets/ext_trivial/ext/trivial/styles/all/template/test_event_loop.html b/tests/template/datasets/ext_trivial/ext/trivial/styles/all/template/test_event_loop.html new file mode 100644 index 0000000000..149398d6bd --- /dev/null +++ b/tests/template/datasets/ext_trivial/ext/trivial/styles/all/template/test_event_loop.html @@ -0,0 +1 @@ +{event_loop.S_ROW_COUNT}| \ No newline at end of file diff --git a/tests/template/datasets/ext_trivial/styles/silver/template/event_loop.html b/tests/template/datasets/ext_trivial/styles/silver/template/event_loop.html new file mode 100644 index 0000000000..c70d8f86d7 --- /dev/null +++ b/tests/template/datasets/ext_trivial/styles/silver/template/event_loop.html @@ -0,0 +1,3 @@ + +event_loop + diff --git a/tests/template/template_events_test.php b/tests/template/template_events_test.php index f7bcd2dcc6..d3b65e763a 100644 --- a/tests/template/template_events_test.php +++ b/tests/template/template_events_test.php @@ -80,6 +80,16 @@ Zeta test event in all', array(), 'two in silver in omega', ), + array( + 'EVENT in loop', + 'ext_trivial', + array('silver'), + 'event_loop.html', + array(), + array('event_loop' => array(array(), array(), array())), + array(), + 'event_loop0|event_loop1|event_loop2', + ), ); } -- cgit v1.2.1 From 0f83d7fd6cf6819c0fe2f4bfa9f65873f7124b72 Mon Sep 17 00:00:00 2001 From: Nathaniel Guse Date: Fri, 19 Jul 2013 13:36:28 -0500 Subject: [ticket/11701] New line at EOF PHPBB3-11701 --- .../ext_trivial/ext/trivial/styles/all/template/test_event_loop.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/template/datasets/ext_trivial/ext/trivial/styles/all/template/test_event_loop.html b/tests/template/datasets/ext_trivial/ext/trivial/styles/all/template/test_event_loop.html index 149398d6bd..235e129f85 100644 --- a/tests/template/datasets/ext_trivial/ext/trivial/styles/all/template/test_event_loop.html +++ b/tests/template/datasets/ext_trivial/ext/trivial/styles/all/template/test_event_loop.html @@ -1 +1 @@ -{event_loop.S_ROW_COUNT}| \ No newline at end of file +{event_loop.S_ROW_COUNT}| -- cgit v1.2.1