mirror of
https://github.com/phpbb/phpbb.git
synced 2025-06-28 14:18:52 +00:00
[feature/twig] Fixing IF .blah correctly
PHPBB3-11598
This commit is contained in:
parent
6f9acb0117
commit
612dbad63f
2 changed files with 28 additions and 8 deletions
|
@ -38,20 +38,35 @@ class phpbb_template_twig_lexer extends Twig_Lexer
|
||||||
'ENDPHP',
|
'ENDPHP',
|
||||||
'EVENT',
|
'EVENT',
|
||||||
);
|
);
|
||||||
|
|
||||||
// Replace <!-- INCLUDE blah.html --> with {% include 'blah.html' %}
|
// Replace <!-- INCLUDE blah.html --> with {% include 'blah.html' %}
|
||||||
$code = preg_replace('#<!-- INCLUDE(PHP|JS)? (.*?) -->#', "{% INCLUDE$1 '$2' %}", $code);
|
$code = preg_replace('#<!-- INCLUDE(PHP|JS)? (.*?) -->#', "{% INCLUDE$1 '$2' %}", $code);
|
||||||
|
|
||||||
|
// This strips the $ inside of a tag directly after the token, which was used in <!-- DEFINE $NAME
|
||||||
|
$code = preg_replace('#<!-- DEFINE \$(.*)-->#', '<!-- DEFINE $1-->', $code);
|
||||||
|
|
||||||
|
// This strips the . inside of a tag directly before a variable name, which was used in <!-- IF .blah
|
||||||
|
$code = preg_replace_callback('#<!-- IF((.*)[\s][\$|\.]([^\s]+)(.*))-->#', array($this, 'tag_if_cleanup'), $code);
|
||||||
|
|
||||||
// Replace all of our starting tokens, <!-- TOKEN --> with Twig style, {% TOKEN %}
|
// Replace all of our starting tokens, <!-- TOKEN --> with Twig style, {% TOKEN %}
|
||||||
// This also strips the $ inside of a tag directly after the token, which was used in <!-- DEFINE $NAME
|
|
||||||
// This also strips the . inside of a tag directly after the token, which was used in <!-- IF .blah
|
|
||||||
// This also strips outer parenthesis, <!-- IF (blah) --> becomes <!-- IF blah -->
|
// This also strips outer parenthesis, <!-- IF (blah) --> becomes <!-- IF blah -->
|
||||||
$code = preg_replace('#<!-- (' . implode('|', $valid_starting_tokens) . ') (not )?(\$|\.)?(?:(.*?) ?)?-->#', '{% $1 $2$4 %}', $code);
|
$code = preg_replace('#<!-- (' . implode('|', $valid_starting_tokens) . ')(?: (.*?) ?)?-->#', '{% $1 $2 %}', $code);
|
||||||
|
|
||||||
// Replace all of our variables, {VARNAME} or {$VARNAME}, with Twig style, {{ VARNAME }}
|
// Replace all of our variables, {VARNAME} or {$VARNAME}, with Twig style, {{ VARNAME }}
|
||||||
$code = preg_replace('#{\$?([a-zA-Z0-9_\.]+)}#', '{{ $1 }}', $code);
|
$code = preg_replace('#{\$?([a-zA-Z0-9_\.]+)}#', '{{ $1 }}', $code);
|
||||||
//echo $code;
|
|
||||||
//exit;
|
|
||||||
return parent::tokenize($code, $filename);
|
return parent::tokenize($code, $filename);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* preg_replace_callback to clean up IF statements
|
||||||
|
*
|
||||||
|
* This strips the . inside of a tag directly before a variable name, which was used in <!-- IF .blah
|
||||||
|
*
|
||||||
|
* @param mixed $matches
|
||||||
|
*/
|
||||||
|
protected function tag_if_cleanup($matches)
|
||||||
|
{
|
||||||
|
return '<!-- IF ' . preg_replace('#\s\.([a-zA-Z_0-9]+)#', ' $1', $matches[1]) . ' -->';
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -347,6 +347,11 @@ class phpbb_template_twig implements phpbb_template
|
||||||
return $this->context->alter_block_array($blockname, $vararray, $key, $mode);
|
return $this->context->alter_block_array($blockname, $vararray, $key, $mode);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get template vars in a format Twig will use (from the context)
|
||||||
|
*
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
protected function get_template_vars()
|
protected function get_template_vars()
|
||||||
{
|
{
|
||||||
$vars = array();
|
$vars = array();
|
||||||
|
@ -354,7 +359,7 @@ class phpbb_template_twig implements phpbb_template
|
||||||
// Work-around for now
|
// Work-around for now
|
||||||
foreach ($this->user->lang as $key => $value)
|
foreach ($this->user->lang as $key => $value)
|
||||||
{
|
{
|
||||||
if (is_array($value))
|
if (!is_string($value))
|
||||||
{
|
{
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue