From 16d8b0bf78334194dd507d196a040b5a5c740850 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rub=C3=A9n=20Calvo?= Date: Fri, 8 Sep 2017 11:33:52 +0200 Subject: [ticket/15330] Twig function to know if a language string is defined PHPBB3-15330 --- phpBB/phpbb/template/twig/extension.php | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) (limited to 'phpBB/phpbb/template/twig/extension.php') diff --git a/phpBB/phpbb/template/twig/extension.php b/phpBB/phpbb/template/twig/extension.php index f6f8e03ca2..3c2c8418e6 100644 --- a/phpBB/phpbb/template/twig/extension.php +++ b/phpBB/phpbb/template/twig/extension.php @@ -85,6 +85,7 @@ class extension extends \Twig_Extension { return array( new \Twig_SimpleFunction('lang', array($this, 'lang')), + new \Twig_SimpleFunction('lang_defined', array($this, 'lang_defined')), ); } @@ -136,7 +137,7 @@ class extension extends \Twig_Extension * * @return mixed The sliced variable */ - 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) @@ -165,7 +166,7 @@ class extension extends \Twig_Extension * * @return string */ - function lang() + public function lang() { $args = func_get_args(); $key = $args[0]; @@ -182,4 +183,14 @@ class extension extends \Twig_Extension return call_user_func_array(array($this->language, 'lang'), $args); } + + /** + * Check if a language variable exist + * + * @return bool + */ + public function lang_defined($key) + { + return call_user_func_array([$this->language, 'is_set'], [$key]); + } } -- cgit v1.2.1 From 1b9507d93d479609017b604447aba954a292f526 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rub=C3=A9n=20Calvo?= Date: Fri, 8 Sep 2017 14:39:04 +0200 Subject: [ticket/15330] Fix typo PHPBB3-15330 --- phpBB/phpbb/template/twig/extension.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'phpBB/phpbb/template/twig/extension.php') diff --git a/phpBB/phpbb/template/twig/extension.php b/phpBB/phpbb/template/twig/extension.php index 3c2c8418e6..b40048ef11 100644 --- a/phpBB/phpbb/template/twig/extension.php +++ b/phpBB/phpbb/template/twig/extension.php @@ -185,7 +185,7 @@ class extension extends \Twig_Extension } /** - * Check if a language variable exist + * Check if a language variable exists * * @return bool */ -- cgit v1.2.1 From 40e61e4d1ec3da2ea48efda401b0044f2aff6071 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois-Xavier=20de=20Guillebon?= Date: Tue, 16 Jan 2018 12:46:48 +0100 Subject: [ticket/15508] Remove call to getEnvironment() from parser PHPBB3-15508 --- phpBB/phpbb/template/twig/extension.php | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) (limited to 'phpBB/phpbb/template/twig/extension.php') diff --git a/phpBB/phpbb/template/twig/extension.php b/phpBB/phpbb/template/twig/extension.php index b40048ef11..c5b3db1aaf 100644 --- a/phpBB/phpbb/template/twig/extension.php +++ b/phpBB/phpbb/template/twig/extension.php @@ -18,6 +18,9 @@ class extension extends \Twig_Extension /** @var \phpbb\template\context */ protected $context; + /** @var \phpbb\template\twig\environment */ + protected $environment; + /** @var \phpbb\language\language */ protected $language; @@ -25,12 +28,14 @@ class extension extends \Twig_Extension * Constructor * * @param \phpbb\template\context $context + * @param \phpbb\template\twig\environment $environment * @param \phpbb\language\language $language * @return \phpbb\template\twig\extension */ - public function __construct(\phpbb\template\context $context, $language) + public function __construct(\phpbb\template\context $context, \phpbb\template\twig\environment $environment, $language) { $this->context = $context; + $this->environment = $environment; $this->language = $language; } @@ -56,9 +61,9 @@ class extension extends \Twig_Extension new \phpbb\template\twig\tokenparser\includeparser, new \phpbb\template\twig\tokenparser\includejs, new \phpbb\template\twig\tokenparser\includecss, - new \phpbb\template\twig\tokenparser\event, - new \phpbb\template\twig\tokenparser\includephp, - new \phpbb\template\twig\tokenparser\php, + new \phpbb\template\twig\tokenparser\event($this->environment), + new \phpbb\template\twig\tokenparser\includephp($this->environment), + new \phpbb\template\twig\tokenparser\php($this->environment), ); } -- cgit v1.2.1 From 7989f3f71fd665aa743d947c7487d41c6f0a33d4 Mon Sep 17 00:00:00 2001 From: mrgoldy Date: Sun, 9 Dec 2018 23:52:50 +0100 Subject: [ticket/15905] Try with existing phpbb extension PHPBB3-15905 --- phpBB/phpbb/template/twig/extension.php | 48 +++++++++++++++++++++++++++++++-- 1 file changed, 46 insertions(+), 2 deletions(-) (limited to 'phpBB/phpbb/template/twig/extension.php') diff --git a/phpBB/phpbb/template/twig/extension.php b/phpBB/phpbb/template/twig/extension.php index c5b3db1aaf..5bb0c67291 100644 --- a/phpBB/phpbb/template/twig/extension.php +++ b/phpBB/phpbb/template/twig/extension.php @@ -15,6 +15,9 @@ namespace phpbb\template\twig; class extension extends \Twig_Extension { + /** @var \phpbb\auth\auth */ + protected $auth; + /** @var \phpbb\template\context */ protected $context; @@ -27,13 +30,14 @@ class extension extends \Twig_Extension /** * Constructor * + * @param \phpbb\auth\auth $auth * @param \phpbb\template\context $context * @param \phpbb\template\twig\environment $environment * @param \phpbb\language\language $language - * @return \phpbb\template\twig\extension */ - public function __construct(\phpbb\template\context $context, \phpbb\template\twig\environment $environment, $language) + public function __construct(\phpbb\auth\auth $auth, \phpbb\template\context $context, \phpbb\template\twig\environment $environment, $language) { + $this->auth = $auth; $this->context = $context; $this->environment = $environment; $this->language = $language; @@ -91,6 +95,8 @@ class extension extends \Twig_Extension return array( new \Twig_SimpleFunction('lang', array($this, 'lang')), new \Twig_SimpleFunction('lang_defined', array($this, 'lang_defined')), + new \Twig_SimpleFunction('auth', array($this, 'get_auth')), + new \Twig_SimpleFunction('auth_global', array($this, 'get_auth_global')), ); } @@ -198,4 +204,42 @@ class extension extends \Twig_Extension { return call_user_func_array([$this->language, 'is_set'], [$key]); } + + /** + * Look up permission option(s). + * + * How to use in a template: + * - {{ auth(options, forum_id) }} + * + * The options are required, either as a single string 'a_' or as a twig array ['a_', 'm_']. + * The forum identifier is optional. + * + * @return bool + */ + public function get_auth() + { + $args = func_get_args(); + + $options = $args[0]; + $forum_id = isset($args[1]) ? (int) $args[1] : 0; + + return is_array($options) ? $this->auth->acl_gets($options, $forum_id) : $this->auth->acl_get($options, $forum_id); + } + + /** + * Look up permission option(s) for any forum + * + * How to use in a template: + * - {{ auth_global(options) }} + * + * The options are required, either as a single string 'a_' or as a twig array ['a_', 'm_']. + * + * @return bool + */ + public function get_auth_global() + { + $args = func_get_args(); + + return $this->auth->acl_getf_global($args); + } } -- cgit v1.2.1 From eee00652e7b608967a2ec5ee8fd165c2760be145 Mon Sep 17 00:00:00 2001 From: mrgoldy Date: Sun, 9 Dec 2018 23:58:34 +0100 Subject: [ticket/15905] Resolve conflicts PHPBB3-15905 --- phpBB/phpbb/template/twig/extension.php | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) (limited to 'phpBB/phpbb/template/twig/extension.php') diff --git a/phpBB/phpbb/template/twig/extension.php b/phpBB/phpbb/template/twig/extension.php index 5bb0c67291..384bac773a 100644 --- a/phpBB/phpbb/template/twig/extension.php +++ b/phpBB/phpbb/template/twig/extension.php @@ -95,6 +95,7 @@ class extension extends \Twig_Extension 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_SimpleFunction('auth', array($this, 'get_auth')), new \Twig_SimpleFunction('auth_global', array($this, 'get_auth_global')), ); @@ -196,10 +197,10 @@ class extension extends \Twig_Extension } /** - * Check if a language variable exists - * - * @return bool - */ + * Check if a language variable exists + * + * @return bool + */ public function lang_defined($key) { return call_user_func_array([$this->language, 'is_set'], [$key]); -- cgit v1.2.1 From 133dfd0a84ce258fadab5f48de45684869b14800 Mon Sep 17 00:00:00 2001 From: mrgoldy Date: Mon, 10 Dec 2018 00:10:27 +0100 Subject: [ticket/15905] Try it without auth PHPBB3-15905 --- phpBB/phpbb/template/twig/extension.php | 59 +-------------------------------- 1 file changed, 1 insertion(+), 58 deletions(-) (limited to 'phpBB/phpbb/template/twig/extension.php') diff --git a/phpBB/phpbb/template/twig/extension.php b/phpBB/phpbb/template/twig/extension.php index 384bac773a..027abc44ec 100644 --- a/phpBB/phpbb/template/twig/extension.php +++ b/phpBB/phpbb/template/twig/extension.php @@ -15,9 +15,6 @@ namespace phpbb\template\twig; class extension extends \Twig_Extension { - /** @var \phpbb\auth\auth */ - protected $auth; - /** @var \phpbb\template\context */ protected $context; @@ -30,14 +27,12 @@ class extension extends \Twig_Extension /** * Constructor * - * @param \phpbb\auth\auth $auth * @param \phpbb\template\context $context * @param \phpbb\template\twig\environment $environment * @param \phpbb\language\language $language */ - public function __construct(\phpbb\auth\auth $auth, \phpbb\template\context $context, \phpbb\template\twig\environment $environment, $language) + public function __construct(\phpbb\template\context $context, \phpbb\template\twig\environment $environment, $language) { - $this->auth = $auth; $this->context = $context; $this->environment = $environment; $this->language = $language; @@ -94,10 +89,6 @@ class extension extends \Twig_Extension { 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_SimpleFunction('auth', array($this, 'get_auth')), - new \Twig_SimpleFunction('auth_global', array($this, 'get_auth_global')), ); } @@ -195,52 +186,4 @@ class extension extends \Twig_Extension return call_user_func_array(array($this->language, 'lang'), $args); } - - /** - * Check if a language variable exists - * - * @return bool - */ - public function lang_defined($key) - { - return call_user_func_array([$this->language, 'is_set'], [$key]); - } - - /** - * Look up permission option(s). - * - * How to use in a template: - * - {{ auth(options, forum_id) }} - * - * The options are required, either as a single string 'a_' or as a twig array ['a_', 'm_']. - * The forum identifier is optional. - * - * @return bool - */ - public function get_auth() - { - $args = func_get_args(); - - $options = $args[0]; - $forum_id = isset($args[1]) ? (int) $args[1] : 0; - - return is_array($options) ? $this->auth->acl_gets($options, $forum_id) : $this->auth->acl_get($options, $forum_id); - } - - /** - * Look up permission option(s) for any forum - * - * How to use in a template: - * - {{ auth_global(options) }} - * - * The options are required, either as a single string 'a_' or as a twig array ['a_', 'm_']. - * - * @return bool - */ - public function get_auth_global() - { - $args = func_get_args(); - - return $this->auth->acl_getf_global($args); - } } -- cgit v1.2.1 From f21003f977e7f9c2b414885ad5e05333dbdcd0ac Mon Sep 17 00:00:00 2001 From: mrgoldy Date: Mon, 10 Dec 2018 00:19:50 +0100 Subject: [ticket/15905] Re-add add_class and lang_defined PHPBB3-15905 --- phpBB/phpbb/template/twig/extension.php | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'phpBB/phpbb/template/twig/extension.php') diff --git a/phpBB/phpbb/template/twig/extension.php b/phpBB/phpbb/template/twig/extension.php index 027abc44ec..1131a7f3aa 100644 --- a/phpBB/phpbb/template/twig/extension.php +++ b/phpBB/phpbb/template/twig/extension.php @@ -89,6 +89,8 @@ class extension extends \Twig_Extension { 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'), ); } @@ -186,4 +188,14 @@ class extension extends \Twig_Extension return call_user_func_array(array($this->language, 'lang'), $args); } + + /** + * Check if a language variable exists + * + * @return bool + */ + public function lang_defined($key) + { + return call_user_func_array([$this->language, 'is_set'], [$key]); + } } -- cgit v1.2.1