phpBB

Code Changes

File: phpbb/template/twig/extension.php

  Unmodified   Added   Modified   Removed
Line 13Line 13

namespace phpbb\template\twig;



namespace phpbb\template\twig;


class extension extends \Twig_Extension



use Twig\Error\RuntimeError;

class extension extends \Twig\Extension\AbstractExtension

{
/** @var \phpbb\template\context */
protected $context;

{
/** @var \phpbb\template\context */
protected $context;

Line 51Line 53
	/**
* Returns the token parser instance to add to the existing list.
*

	/**
* Returns the token parser instance to add to the existing list.
*

	* @return array An array of Twig_TokenParser instances

	* @return array An array of \Twig\TokenParser\AbstractTokenParser instances

	*/
public function getTokenParsers()
{

	*/
public function getTokenParsers()
{

Line 74Line 76
	public function getFilters()
{
return array(

	public function getFilters()
{
return array(

			new \Twig_SimpleFilter('subset', array($this, 'loop_subset'), array('needs_environment' => true)),

			new \Twig\TwigFilter('subset', array($this, 'loop_subset'), array('needs_environment' => true)),

			// @deprecated 3.2.0 Uses twig's JS escape method instead of addslashes

			// @deprecated 3.2.0 Uses twig's JS escape method instead of addslashes

			new \Twig_SimpleFilter('addslashes', 'addslashes'),



			new \Twig\TwigFilter('addslashes', 'addslashes'),
new \Twig\TwigFilter('int', 'intval'),
new \Twig\TwigFilter('float', 'floatval'),

		);
}


		);
}


Line 88Line 92
	public function getFunctions()
{
return array(

	public function getFunctions()
{
return array(

			new \Twig_SimpleFunction('lang', array($this, 'lang')),
new \Twig_SimpleFunction('lang_defined', array($this, 'lang_defined')),
new \Twig_SimpleFunction('get_class', 'get_class'),


			new \Twig\TwigFunction('lang', array($this, 'lang')),
new \Twig\TwigFunction('lang_defined', array($this, 'lang_defined')),
new \Twig\TwigFunction('lang_js', [$this, 'lang_js']),
new \Twig\TwigFunction('get_class', 'get_class'),

		);
}


		);
}


Line 103Line 108
	{
return array(
array(

	{
return array(
array(

				'!' => array('precedence' => 50, 'class' => 'Twig_Node_Expression_Unary_Not'),

				'!' => array('precedence' => 50, 'class' => '\Twig\Node\Expression\Unary\NotUnary'),

			),
array(
// precedence settings are copied from similar operators in Twig core extension

			),
array(
// precedence settings are copied from similar operators in Twig core extension

				'||' => array('precedence' => 10, 'class' => 'Twig_Node_Expression_Binary_Or', 'associativity' => \Twig_ExpressionParser::OPERATOR_LEFT),
'&&' => array('precedence' => 15, 'class' => 'Twig_Node_Expression_Binary_And', 'associativity' => \Twig_ExpressionParser::OPERATOR_LEFT),

				'||' => array('precedence' => 10, 'class' => '\Twig\Node\Expression\Binary\OrBinary', 'associativity' => \Twig\ExpressionParser::OPERATOR_LEFT),
'&&' => array('precedence' => 15, 'class' => '\Twig\Node\Expression\Binary\AndBinary', 'associativity' => \Twig\ExpressionParser::OPERATOR_LEFT),





				'eq' => array('precedence' => 20, 'class' => 'Twig_Node_Expression_Binary_Equal', 'associativity' => \Twig_ExpressionParser::OPERATOR_LEFT),

				'eq' => array('precedence' => 20, 'class' => '\Twig\Node\Expression\Binary\EqualBinary', 'associativity' => \Twig\ExpressionParser::OPERATOR_LEFT),





				'ne' => array('precedence' => 20, 'class' => 'Twig_Node_Expression_Binary_NotEqual', 'associativity' => \Twig_ExpressionParser::OPERATOR_LEFT),
'neq' => array('precedence' => 20, 'class' => 'Twig_Node_Expression_Binary_NotEqual', 'associativity' => \Twig_ExpressionParser::OPERATOR_LEFT),
'<>' => array('precedence' => 20, 'class' => 'Twig_Node_Expression_Binary_NotEqual', 'associativity' => \Twig_ExpressionParser::OPERATOR_LEFT),

				'ne' => array('precedence' => 20, 'class' => '\Twig\Node\Expression\Binary\NotEqualBinary', 'associativity' => \Twig\ExpressionParser::OPERATOR_LEFT),
'neq' => array('precedence' => 20, 'class' => '\Twig\Node\Expression\Binary\NotEqualBinary', 'associativity' => \Twig\ExpressionParser::OPERATOR_LEFT),
'<>' => array('precedence' => 20, 'class' => '\Twig\Node\Expression\Binary\NotEqualBinary', 'associativity' => \Twig\ExpressionParser::OPERATOR_LEFT),





				'===' => array('precedence' => 20, 'class' => '\phpbb\template\twig\node\expression\binary\equalequal', 'associativity' => \Twig_ExpressionParser::OPERATOR_LEFT),
'!==' => array('precedence' => 20, 'class' => '\phpbb\template\twig\node\expression\binary\notequalequal', 'associativity' => \Twig_ExpressionParser::OPERATOR_LEFT),

				'===' => array('precedence' => 20, 'class' => '\phpbb\template\twig\node\expression\binary\equalequal', 'associativity' => \Twig\ExpressionParser::OPERATOR_LEFT),
'!==' => array('precedence' => 20, 'class' => '\phpbb\template\twig\node\expression\binary\notequalequal', 'associativity' => \Twig\ExpressionParser::OPERATOR_LEFT),





				'gt' => array('precedence' => 20, 'class' => 'Twig_Node_Expression_Binary_Greater', 'associativity' => \Twig_ExpressionParser::OPERATOR_LEFT),
'gte' => array('precedence' => 20, 'class' => 'Twig_Node_Expression_Binary_GreaterEqual', 'associativity' => \Twig_ExpressionParser::OPERATOR_LEFT),
'ge' => array('precedence' => 20, 'class' => 'Twig_Node_Expression_Binary_GreaterEqual', 'associativity' => \Twig_ExpressionParser::OPERATOR_LEFT),
'lt' => array('precedence' => 20, 'class' => 'Twig_Node_Expression_Binary_Less', 'associativity' => \Twig_ExpressionParser::OPERATOR_LEFT),
'lte' => array('precedence' => 20, 'class' => 'Twig_Node_Expression_Binary_LessEqual', 'associativity' => \Twig_ExpressionParser::OPERATOR_LEFT),
'le' => array('precedence' => 20, 'class' => 'Twig_Node_Expression_Binary_LessEqual', 'associativity' => \Twig_ExpressionParser::OPERATOR_LEFT),

				'gt' => array('precedence' => 20, 'class' => '\Twig\Node\Expression\Binary\GreaterBinary', 'associativity' => \Twig\ExpressionParser::OPERATOR_LEFT),
'gte' => array('precedence' => 20, 'class' => '\Twig\Node\Expression\Binary\GreaterEqualBinary', 'associativity' => \Twig\ExpressionParser::OPERATOR_LEFT),
'ge' => array('precedence' => 20, 'class' => '\Twig\Node\Expression\Binary\GreaterEqualBinary', 'associativity' => \Twig\ExpressionParser::OPERATOR_LEFT),
'lt' => array('precedence' => 20, 'class' => '\Twig\Node\Expression\Binary\LessBinary', 'associativity' => \Twig\ExpressionParser::OPERATOR_LEFT),
'lte' => array('precedence' => 20, 'class' => '\Twig\Node\Expression\Binary\LessEqualBinary', 'associativity' => \Twig\ExpressionParser::OPERATOR_LEFT),
'le' => array('precedence' => 20, 'class' => '\Twig\Node\Expression\Binary\LessEqualBinary', 'associativity' => \Twig\ExpressionParser::OPERATOR_LEFT),





				'mod' => array('precedence' => 60, 'class' => 'Twig_Node_Expression_Binary_Mod', 'associativity' => \Twig_ExpressionParser::OPERATOR_LEFT),

				'mod' => array('precedence' => 60, 'class' => '\Twig\Node\Expression\Binary\ModBinary', 'associativity' => \Twig\ExpressionParser::OPERATOR_LEFT),

			),
);
}

			),
);
}

Line 134Line 139
	/**
* Grabs a subset of a loop
*

	/**
* Grabs a subset of a loop
*

	* @param \Twig_Environment $env          A Twig_Environment instance

	* @param \Twig\Environment $env          A Twig\Environment instance

	* @param mixed            $item         A variable
* @param integer $start Start of the subset
* @param integer $end End of the subset

	* @param mixed            $item         A variable
* @param integer $start Start of the subset
* @param integer $end End of the subset

	* @param Boolean          $preserveKeys Whether to preserve key or not (when the input is an array)

	* @param boolean          $preserveKeys Whether to preserve key or not (when the input is an array)

	*
* @return mixed The sliced variable
*/

	*
* @return mixed The sliced variable
*/

	public function loop_subset(\Twig_Environment $env, $item, $start, $end = null, $preserveKeys = false)

	public function loop_subset(\Twig\Environment $env, $item, $start, $end = null, $preserveKeys = false)

	{
// We do almost the same thing as Twig's slice (array_slice), except when $end is positive
if ($end >= 1)

	{
// We do almost the same thing as Twig's slice (array_slice), except when $end is positive
if ($end >= 1)

Line 197Line 202
	public function lang_defined($key)
{
return call_user_func_array([$this->language, 'is_set'], [$key]);

	public function lang_defined($key)
{
return call_user_func_array([$this->language, 'is_set'], [$key]);

 
	}

/**
* Get output for language variable in JS code
*
* @throws RuntimeError When data passed to twig_escape_filter is not a UTF8 string
*/
public function lang_js(): string
{
$args = func_get_args();

return twig_escape_filter($this->environment, call_user_func_array([$this, 'lang'], $args), 'js');

	}
}


	}
}