1
0
mirror of https://github.com/phpbb/phpbb.git synced 2025-07-31 22:10:45 +02:00

Merge remote-tracking branch 'EXreaction/ticket/11701' into develop

* EXreaction/ticket/11701:
  [ticket/11701] New line at EOF
  [ticket/11701] Test events in loops
  [ticket/11701] Refix regex for appending |length
  [ticket/11701] Fix regex for appending |length
  [ticket/11701] Fix loops var check
  [ticket/11701] Remove useless str_replace
  [ticket/11701] Loop variables are not passed correctly to events
This commit is contained in:
Joas Schilling
2013-08-09 17:25:00 +02:00
12 changed files with 79 additions and 64 deletions

View File

@@ -191,20 +191,18 @@ 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);
// 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 %}";
$parent = ($parent) ?: 'loops.';
// Turn into a Twig for loop
return "{% for {$name} in {$parent}{$name}{$subset} %}{$body}{% endfor %}";
};
// Replace <!-- BEGINELSE --> correctly, only needs to be done once
@@ -227,8 +225,11 @@ 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
$inner = preg_replace('#\s\.([a-zA-Z_0-9\.]+)#', ' $1|length', $inner);
// Replace .foo with loops.foo|length
$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\.]+)([^a-zA-Z_0-9\.])#', ' $1|length$2', $inner);
return "<!-- {$matches[1]}IF{$inner}-->";
};

View File

@@ -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;
}