mirror of
https://github.com/phpbb/phpbb.git
synced 2025-08-03 15:27:42 +02:00
[feature/twig] Support our old INCLUDE statements (no quotes)
Better code for handling IF .blah PHPBB3-11598
This commit is contained in:
@@ -19,24 +19,34 @@ class phpbb_template_twig_lexer extends Twig_Lexer
|
|||||||
{
|
{
|
||||||
protected function lexExpression()
|
protected function lexExpression()
|
||||||
{
|
{
|
||||||
|
parent::lexExpression();
|
||||||
|
|
||||||
|
// Last element parsed
|
||||||
|
$last_element = end($this->tokens);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Check for old fashioned INCLUDE statements without enclosed quotes
|
||||||
|
*/
|
||||||
|
if ($last_element->getValue() === 'INCLUDE')
|
||||||
|
{
|
||||||
|
if (preg_match('#^\s*([a-zA-Z0-9_]+\.[a-zA-Z0-9]+)#', substr($this->code, $this->cursor), $match))
|
||||||
|
{
|
||||||
|
$this->pushToken(Twig_Token::STRING_TYPE, stripcslashes($match[1]));
|
||||||
|
$this->moveCursor($match[0]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This is some compatibility code to continue supporting expressions such as:
|
* This is some compatibility code to continue supporting expressions such as:
|
||||||
* <!-- IF .blah -->
|
* <!-- IF .blah -->
|
||||||
*
|
|
||||||
* This does not seem very efficient, but I have not been able to find a better
|
|
||||||
* method which works properly (maybe lexData can do it better, @todo test this)
|
|
||||||
*/
|
*/
|
||||||
$last_element = end($this->tokens);
|
if ($last_element->getValue() === 'IF')
|
||||||
if ($last_element->getValue() === '.')
|
|
||||||
{
|
{
|
||||||
$last_element2 = prev($this->tokens);
|
if (preg_match('#^\s*\.([a-zA-Z0-9\.]+)#', substr($this->code, $this->cursor), $match))
|
||||||
|
|
||||||
if ($last_element2->getValue() === 'IF')
|
|
||||||
{
|
{
|
||||||
array_pop($this->tokens);
|
$this->pushToken(Twig_Token::STRING_TYPE, stripcslashes($match[1]));
|
||||||
|
$this->moveCursor($match[0]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
parent::lexExpression();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user