From 192b8e2568f499aa2ead98a24d8dd5541b1f315a Mon Sep 17 00:00:00 2001 From: Tristan Darricau Date: Sat, 2 Aug 2014 19:09:42 +0200 Subject: [ticket/11649] Expose Twig through the container PHPBB3-11649 --- phpBB/phpbb/template/twig/environment.php | 30 +++++++++++++++++++++++- phpBB/phpbb/template/twig/twig.php | 39 ++++++++----------------------- 2 files changed, 39 insertions(+), 30 deletions(-) (limited to 'phpBB/phpbb/template/twig') diff --git a/phpBB/phpbb/template/twig/environment.php b/phpBB/phpbb/template/twig/environment.php index 476ffd935e..df586af9e5 100644 --- a/phpBB/phpbb/template/twig/environment.php +++ b/phpBB/phpbb/template/twig/environment.php @@ -13,6 +13,9 @@ namespace phpbb\template\twig; +use Twig_Lexer; +use Twig_LexerInterface; + class environment extends \Twig_Environment { /** @var \phpbb\config\config */ @@ -21,6 +24,9 @@ class environment extends \Twig_Environment /** @var \phpbb\path_helper */ protected $phpbb_path_helper; + /** @var \Symfony\Component\DependencyInjection\ContainerInterface */ + protected $container; + /** @var \phpbb\extension\manager */ protected $extension_manager; @@ -38,23 +44,45 @@ class environment extends \Twig_Environment * * @param \phpbb\config\config $phpbb_config The phpBB configuration * @param \phpbb\path_helper $path_helper phpBB path helper + * @param \Symfony\Component\DependencyInjection\ContainerInterface $container * @param \phpbb\extension\manager $extension_manager phpBB extension manager * @param \Twig_LoaderInterface $loader Twig loader interface * @param array $options Array of options to pass to Twig */ - public function __construct($phpbb_config, \phpbb\path_helper $path_helper, \phpbb\extension\manager $extension_manager = null, \Twig_LoaderInterface $loader = null, $options = array()) + public function __construct($phpbb_config, \phpbb\path_helper $path_helper, \Symfony\Component\DependencyInjection\ContainerInterface $container, $cache_path, \phpbb\extension\manager $extension_manager = null, \Twig_LoaderInterface $loader = null, $options = array()) { $this->phpbb_config = $phpbb_config; $this->phpbb_path_helper = $path_helper; $this->extension_manager = $extension_manager; + $this->container = $container; $this->phpbb_root_path = $this->phpbb_path_helper->get_phpbb_root_path(); $this->web_root_path = $this->phpbb_path_helper->get_web_root_path(); + $options = array_merge(array( + 'cache' => (defined('IN_INSTALL')) ? false : $cache_path, + 'debug' => defined('DEBUG'), + 'auto_reload' => (bool) $this->phpbb_config['load_tplcompile'], + 'autoescape' => false, + ), $options); + return parent::__construct($loader, $options); } + /** + * {@inheritdoc} + */ + public function getLexer() + { + if (null === $this->lexer) { + $this->lexer = $this->container->get('template.twig.lexer'); + } + + return $this->lexer; + } + + /** * Get the list of enabled phpBB extensions * diff --git a/phpBB/phpbb/template/twig/twig.php b/phpBB/phpbb/template/twig/twig.php index 5e2057f818..dd6117819a 100644 --- a/phpBB/phpbb/template/twig/twig.php +++ b/phpBB/phpbb/template/twig/twig.php @@ -78,9 +78,12 @@ class twig extends \phpbb\template\base * @param \phpbb\config\config $config * @param \phpbb\user $user * @param \phpbb\template\context $context template context + * @param \phpbb\template\twig\environment $twig_environment + * @param string $cache_path + * @param array|\ArrayAccess $extensions * @param \phpbb\extension\manager $extension_manager extension manager, if null then template events will not be invoked */ - public function __construct(\phpbb\path_helper $path_helper, $config, $user, \phpbb\template\context $context, \phpbb\extension\manager $extension_manager = null) + public function __construct(\phpbb\path_helper $path_helper, $config, $user, \phpbb\template\context $context, \phpbb\template\twig\environment $twig_environment, $cache_path, $extensions = array(), \phpbb\extension\manager $extension_manager = null) { $this->path_helper = $path_helper; $this->phpbb_root_path = $path_helper->get_phpbb_root_path(); @@ -89,35 +92,13 @@ class twig extends \phpbb\template\base $this->user = $user; $this->context = $context; $this->extension_manager = $extension_manager; + $this->cachepath = $cache_path; + $this->twig = $twig_environment; - $this->cachepath = $this->phpbb_root_path . 'cache/twig/'; - - // Initiate the loader, __main__ namespace paths will be setup later in set_style_names() - $loader = new \phpbb\template\twig\loader(''); - - $this->twig = new \phpbb\template\twig\environment( - $this->config, - $this->path_helper, - $this->extension_manager, - $loader, - array( - 'cache' => (defined('IN_INSTALL')) ? false : $this->cachepath, - 'debug' => defined('DEBUG'), - 'auto_reload' => (bool) $this->config['load_tplcompile'], - 'autoescape' => false, - ) - ); - - $this->twig->addExtension( - new \phpbb\template\twig\extension( - $this->context, - $this->user - ) - ); - - $lexer = new \phpbb\template\twig\lexer($this->twig); - - $this->twig->setLexer($lexer); + foreach ($extensions as $extension) + { + $this->twig->addExtension($extension); + } // Add admin namespace if ($this->path_helper->get_adm_relative_path() !== null && is_dir($this->phpbb_root_path . $this->path_helper->get_adm_relative_path() . 'style/')) -- cgit v1.2.1 From 827510a4185ae8ef6fbf0d0f2fbeb92bf63ccace Mon Sep 17 00:00:00 2001 From: Tristan Darricau Date: Sat, 9 Aug 2014 16:14:58 +0200 Subject: [ticket/11649] Fix coding style PHPBB3-11649 --- phpBB/phpbb/template/twig/environment.php | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) (limited to 'phpBB/phpbb/template/twig') diff --git a/phpBB/phpbb/template/twig/environment.php b/phpBB/phpbb/template/twig/environment.php index df586af9e5..f6d9b73178 100644 --- a/phpBB/phpbb/template/twig/environment.php +++ b/phpBB/phpbb/template/twig/environment.php @@ -44,7 +44,8 @@ class environment extends \Twig_Environment * * @param \phpbb\config\config $phpbb_config The phpBB configuration * @param \phpbb\path_helper $path_helper phpBB path helper - * @param \Symfony\Component\DependencyInjection\ContainerInterface $container + * @param \Symfony\Component\DependencyInjection\ContainerInterface $container The dependency injection container + * @param string $cache_path The path to the cache directory * @param \phpbb\extension\manager $extension_manager phpBB extension manager * @param \Twig_LoaderInterface $loader Twig loader interface * @param array $options Array of options to pass to Twig @@ -61,11 +62,11 @@ class environment extends \Twig_Environment $this->web_root_path = $this->phpbb_path_helper->get_web_root_path(); $options = array_merge(array( - 'cache' => (defined('IN_INSTALL')) ? false : $cache_path, - 'debug' => defined('DEBUG'), - 'auto_reload' => (bool) $this->phpbb_config['load_tplcompile'], - 'autoescape' => false, - ), $options); + 'cache' => (defined('IN_INSTALL')) ? false : $cache_path, + 'debug' => defined('DEBUG'), + 'auto_reload' => (bool) $this->phpbb_config['load_tplcompile'], + 'autoescape' => false, + ), $options); return parent::__construct($loader, $options); } @@ -75,7 +76,8 @@ class environment extends \Twig_Environment */ public function getLexer() { - if (null === $this->lexer) { + if (null === $this->lexer) + { $this->lexer = $this->container->get('template.twig.lexer'); } -- cgit v1.2.1 From e7e6d45789d4084b98a9c6227a42976e4a1d8f7f Mon Sep 17 00:00:00 2001 From: Tristan Darricau Date: Sun, 10 Aug 2014 02:26:16 +0200 Subject: [ticket/12957] Update the constructions of the template engine PHPBB3-12957 --- phpBB/phpbb/template/twig/environment.php | 1 + phpBB/phpbb/template/twig/lexer.php | 5 +++++ 2 files changed, 6 insertions(+) (limited to 'phpBB/phpbb/template/twig') diff --git a/phpBB/phpbb/template/twig/environment.php b/phpBB/phpbb/template/twig/environment.php index f6d9b73178..b3f57b016f 100644 --- a/phpBB/phpbb/template/twig/environment.php +++ b/phpBB/phpbb/template/twig/environment.php @@ -79,6 +79,7 @@ class environment extends \Twig_Environment if (null === $this->lexer) { $this->lexer = $this->container->get('template.twig.lexer'); + $this->lexer->set_environment($this); } return $this->lexer; diff --git a/phpBB/phpbb/template/twig/lexer.php b/phpBB/phpbb/template/twig/lexer.php index c5dc7273ba..a7848738bb 100644 --- a/phpBB/phpbb/template/twig/lexer.php +++ b/phpBB/phpbb/template/twig/lexer.php @@ -15,6 +15,11 @@ namespace phpbb\template\twig; class lexer extends \Twig_Lexer { + public function set_environment(\Twig_Environment $env) + { + $this->env = $env; + } + public function tokenize($code, $filename = null) { // Our phpBB tags -- cgit v1.2.1 From 143c1ba8d10bc27500812acd433ffca56110f02c Mon Sep 17 00:00:00 2001 From: Tristan Darricau Date: Sun, 10 Aug 2014 04:01:47 +0200 Subject: [ticket/12957] Removed unused use PHPBB3-12957 --- phpBB/phpbb/template/twig/environment.php | 3 --- 1 file changed, 3 deletions(-) (limited to 'phpBB/phpbb/template/twig') diff --git a/phpBB/phpbb/template/twig/environment.php b/phpBB/phpbb/template/twig/environment.php index b3f57b016f..0ba7a265e4 100644 --- a/phpBB/phpbb/template/twig/environment.php +++ b/phpBB/phpbb/template/twig/environment.php @@ -13,9 +13,6 @@ namespace phpbb\template\twig; -use Twig_Lexer; -use Twig_LexerInterface; - class environment extends \Twig_Environment { /** @var \phpbb\config\config */ -- cgit v1.2.1 From a62adfc1157d6b071f013f9a5f34ccc86ea39220 Mon Sep 17 00:00:00 2001 From: Matt Friedman Date: Thu, 29 Jan 2015 01:41:28 -0800 Subject: [ticket/10388] Use TWIG escape JS filter instead of addslashes PHPBB3-10388 --- phpBB/phpbb/template/twig/extension.php | 4 ++-- phpBB/phpbb/template/twig/lexer.php | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-) (limited to 'phpBB/phpbb/template/twig') diff --git a/phpBB/phpbb/template/twig/extension.php b/phpBB/phpbb/template/twig/extension.php index 3a983491b9..2eb5370b59 100644 --- a/phpBB/phpbb/template/twig/extension.php +++ b/phpBB/phpbb/template/twig/extension.php @@ -71,7 +71,7 @@ class extension extends \Twig_Extension { return array( new \Twig_SimpleFilter('subset', array($this, 'loop_subset'), array('needs_environment' => true)), - new \Twig_SimpleFilter('addslashes', 'addslashes'), + new \Twig_SimpleFilter('addslashes', 'addslashes'), // Deprecate addslashes in phpBB 3.1.4 ); } @@ -177,7 +177,7 @@ class extension extends \Twig_Extension return $context_vars['L_' . $key]; } - // LA_ is transformed into lang(\'$1\')|addslashes, so we should not + // LA_ is transformed into lang(\'$1\')|escape('js'), so we should not // need to check for it return call_user_func_array(array($this->user, 'lang'), $args); diff --git a/phpBB/phpbb/template/twig/lexer.php b/phpBB/phpbb/template/twig/lexer.php index a7848738bb..f1542109a4 100644 --- a/phpBB/phpbb/template/twig/lexer.php +++ b/phpBB/phpbb/template/twig/lexer.php @@ -117,9 +117,9 @@ class lexer extends \Twig_Lexer // Appends any filters after lang() $code = preg_replace('#{L_([a-zA-Z0-9_\.]+)(\|[^}]+?)?}#', '{{ lang(\'$1\')$2 }}', $code); - // Replace all of our escaped language variables, {LA_VARNAME}, with Twig style, {{ lang('NAME')|addslashes }} - // Appends any filters after lang(), but before addslashes - $code = preg_replace('#{LA_([a-zA-Z0-9_\.]+)(\|[^}]+?)?}#', '{{ lang(\'$1\')$2|addslashes }}', $code); + // Replace all of our escaped language variables, {LA_VARNAME}, with Twig style, {{ lang('NAME')|escape('js') }} + // Appends any filters after lang(), but before escape('js') + $code = preg_replace('#{LA_([a-zA-Z0-9_\.]+)(\|[^}]+?)?}#', '{{ lang(\'$1\')$2|escape(\'js\') }}', $code); // Replace all of our variables, {VARNAME}, with Twig style, {{ VARNAME }} // Appends any filters -- cgit v1.2.1 From 5b7d1f1b437a166b893413e1196a2a3da3b334fb Mon Sep 17 00:00:00 2001 From: Matt Friedman Date: Thu, 29 Jan 2015 01:44:45 -0800 Subject: [ticket/10388] Update deprecation date for addslashes PHPBB3-10388 --- phpBB/phpbb/template/twig/extension.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'phpBB/phpbb/template/twig') diff --git a/phpBB/phpbb/template/twig/extension.php b/phpBB/phpbb/template/twig/extension.php index 2eb5370b59..c8c8be5142 100644 --- a/phpBB/phpbb/template/twig/extension.php +++ b/phpBB/phpbb/template/twig/extension.php @@ -71,7 +71,7 @@ class extension extends \Twig_Extension { return array( new \Twig_SimpleFilter('subset', array($this, 'loop_subset'), array('needs_environment' => true)), - new \Twig_SimpleFilter('addslashes', 'addslashes'), // Deprecate addslashes in phpBB 3.1.4 + new \Twig_SimpleFilter('addslashes', 'addslashes'), // Deprecated 3.2.0 ); } -- cgit v1.2.1 From 9f4c2effe9a9b8a497a3f00dc8a6d71e745c7ea9 Mon Sep 17 00:00:00 2001 From: Matt Friedman Date: Sat, 31 Jan 2015 01:11:28 -0800 Subject: [ticket/10388] Update deprecation comment PHPBB3-10388 --- phpBB/phpbb/template/twig/extension.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'phpBB/phpbb/template/twig') diff --git a/phpBB/phpbb/template/twig/extension.php b/phpBB/phpbb/template/twig/extension.php index c8c8be5142..14d1258c09 100644 --- a/phpBB/phpbb/template/twig/extension.php +++ b/phpBB/phpbb/template/twig/extension.php @@ -71,7 +71,8 @@ class extension extends \Twig_Extension { return array( new \Twig_SimpleFilter('subset', array($this, 'loop_subset'), array('needs_environment' => true)), - new \Twig_SimpleFilter('addslashes', 'addslashes'), // Deprecated 3.2.0 + // @deprecated 3.2.0 Uses twig's JS escape method instead of addslashes + new \Twig_SimpleFilter('addslashes', 'addslashes'), ); } -- cgit v1.2.1 From cf39cfc5939f9407082f8f5c1f876ea0ee607a45 Mon Sep 17 00:00:00 2001 From: Tristan Darricau Date: Tue, 7 Oct 2014 20:51:08 +0200 Subject: [ticket/13132] Twig: Add loops content to the root context PHPBB3-13132 --- phpBB/phpbb/template/twig/twig.php | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'phpBB/phpbb/template/twig') diff --git a/phpBB/phpbb/template/twig/twig.php b/phpBB/phpbb/template/twig/twig.php index 605d37e954..0e4c619029 100644 --- a/phpBB/phpbb/template/twig/twig.php +++ b/phpBB/phpbb/template/twig/twig.php @@ -352,6 +352,12 @@ class twig extends \phpbb\template\base // cleanup unset($vars['loops']['.']); + // Inject in the main context the value added by assign_block_vars() to be able to use directly the Twig loops. + foreach ($vars['loops'] as $key => &$value) + { + $vars[$key] = $value; + } + return $vars; } -- cgit v1.2.1 From 4bdef6fd21a5dcab455b0cd1ee2652de606929c3 Mon Sep 17 00:00:00 2001 From: MateBartus Date: Thu, 12 Mar 2015 00:25:00 +0100 Subject: [ticket/13697] Moving filesystem related functions to filesystem service * Moving filesystem service to \phpbb\filesystem namespace * Wraping Symfony's Filesystem component * Moving filesystem related functions from includes/functions.php into \phpbb\filesystem\filesystem Functions moved (and deprecated): - phpbb_chmod - phpbb_is_writable - phpbb_is_absolute - phpbb_own_realpath - phpbb_realpath * Adding interface for filesystem service PHPBB3-13697 --- phpBB/phpbb/template/twig/loader.php | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) (limited to 'phpBB/phpbb/template/twig') diff --git a/phpBB/phpbb/template/twig/loader.php b/phpBB/phpbb/template/twig/loader.php index 2f8ffaa776..df8183c019 100644 --- a/phpBB/phpbb/template/twig/loader.php +++ b/phpBB/phpbb/template/twig/loader.php @@ -20,6 +20,24 @@ class loader extends \Twig_Loader_Filesystem { protected $safe_directories = array(); + /** + * @var \phpbb\filesystem\filesystem_interface + */ + protected $filesystem; + + /** + * Constructor + * + * @param \phpbb\filesystem\filesystem_interface $filesystem + * @param string|array $paths + */ + public function __construct(\phpbb\filesystem\filesystem_interface $filesystem, $paths = array()) + { + $this->filesystem = $filesystem; + + parent::__construct($paths); + } + /** * Set safe directories * @@ -49,7 +67,7 @@ class loader extends \Twig_Loader_Filesystem */ public function addSafeDirectory($directory) { - $directory = phpbb_realpath($directory); + $directory = $this->filesystem->realpath($directory); if ($directory !== false) { @@ -118,7 +136,7 @@ class loader extends \Twig_Loader_Filesystem // can now check if we're within a "safe" directory // Find the real path of the directory the file is in - $directory = phpbb_realpath(dirname($file)); + $directory = $this->filesystem->realpath(dirname($file)); if ($directory === false) { -- cgit v1.2.1 From 9a99c9e4b10eba614517e335527c332761b473a4 Mon Sep 17 00:00:00 2001 From: MateBartus Date: Wed, 29 Apr 2015 01:00:13 +0200 Subject: [ticket/13762] Replace user service with lang in twig extension PHPBB3-13762 --- phpBB/phpbb/template/twig/extension.php | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'phpBB/phpbb/template/twig') diff --git a/phpBB/phpbb/template/twig/extension.php b/phpBB/phpbb/template/twig/extension.php index 14d1258c09..92f87a0331 100644 --- a/phpBB/phpbb/template/twig/extension.php +++ b/phpBB/phpbb/template/twig/extension.php @@ -18,20 +18,20 @@ class extension extends \Twig_Extension /** @var \phpbb\template\context */ protected $context; - /** @var \phpbb\user */ - protected $user; + /** @var \phpbb\language\language */ + protected $language; /** * Constructor * * @param \phpbb\template\context $context - * @param \phpbb\user $user + * @param \phpbb\language\language $language * @return \phpbb\template\twig\extension */ - public function __construct(\phpbb\template\context $context, $user) + public function __construct(\phpbb\template\context $context, $language) { $this->context = $context; - $this->user = $user; + $this->language = $language; } /** @@ -181,6 +181,6 @@ class extension extends \Twig_Extension // LA_ is transformed into lang(\'$1\')|escape('js'), so we should not // need to check for it - return call_user_func_array(array($this->user, 'lang'), $args); + return call_user_func_array(array($this->language, 'lang'), $args); } } -- cgit v1.2.1 From f821130c3a4a22efd491aaad962cc84a82dde56a Mon Sep 17 00:00:00 2001 From: Tristan Darricau Date: Tue, 25 Nov 2014 17:04:15 +0100 Subject: [ticket/12632] Add twig.debug and twig.auto_reload in config.yml PHPBB3-13206 PHPBB3-12632 --- phpBB/phpbb/template/twig/environment.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'phpBB/phpbb/template/twig') diff --git a/phpBB/phpbb/template/twig/environment.php b/phpBB/phpbb/template/twig/environment.php index 0ba7a265e4..fcd0566b6e 100644 --- a/phpBB/phpbb/template/twig/environment.php +++ b/phpBB/phpbb/template/twig/environment.php @@ -60,7 +60,7 @@ class environment extends \Twig_Environment $options = array_merge(array( 'cache' => (defined('IN_INSTALL')) ? false : $cache_path, - 'debug' => defined('DEBUG'), + 'debug' => false, 'auto_reload' => (bool) $this->phpbb_config['load_tplcompile'], 'autoescape' => false, ), $options); -- cgit v1.2.1 From 51376a43919cba7a5037edb7cc31f18b5950437b Mon Sep 17 00:00:00 2001 From: Nicofuma Date: Mon, 4 May 2015 23:50:16 +0200 Subject: [ticket/13638] Inject $filesystem in \phpbb\template\asset PHPBB3-13638 --- phpBB/phpbb/template/twig/environment.php | 25 ++++++++++++++++++++----- phpBB/phpbb/template/twig/node/includeasset.php | 2 +- 2 files changed, 21 insertions(+), 6 deletions(-) (limited to 'phpBB/phpbb/template/twig') diff --git a/phpBB/phpbb/template/twig/environment.php b/phpBB/phpbb/template/twig/environment.php index 0ba7a265e4..e7b8aeab89 100644 --- a/phpBB/phpbb/template/twig/environment.php +++ b/phpBB/phpbb/template/twig/environment.php @@ -18,6 +18,9 @@ class environment extends \Twig_Environment /** @var \phpbb\config\config */ protected $phpbb_config; + /** @var \phpbb\filesystem\filesystem */ + protected $filesystem; + /** @var \phpbb\path_helper */ protected $phpbb_path_helper; @@ -40,6 +43,7 @@ class environment extends \Twig_Environment * Constructor * * @param \phpbb\config\config $phpbb_config The phpBB configuration + * @param \phpbb\filesystem\filesystem $filesystem * @param \phpbb\path_helper $path_helper phpBB path helper * @param \Symfony\Component\DependencyInjection\ContainerInterface $container The dependency injection container * @param string $cache_path The path to the cache directory @@ -47,10 +51,11 @@ class environment extends \Twig_Environment * @param \Twig_LoaderInterface $loader Twig loader interface * @param array $options Array of options to pass to Twig */ - public function __construct($phpbb_config, \phpbb\path_helper $path_helper, \Symfony\Component\DependencyInjection\ContainerInterface $container, $cache_path, \phpbb\extension\manager $extension_manager = null, \Twig_LoaderInterface $loader = null, $options = array()) + public function __construct(\phpbb\config\config $phpbb_config, \phpbb\filesystem\filesystem $filesystem, \phpbb\path_helper $path_helper, \Symfony\Component\DependencyInjection\ContainerInterface $container, $cache_path, \phpbb\extension\manager $extension_manager = null, \Twig_LoaderInterface $loader = null, $options = array()) { $this->phpbb_config = $phpbb_config; + $this->filesystem = $filesystem; $this->phpbb_path_helper = $path_helper; $this->extension_manager = $extension_manager; $this->container = $container; @@ -106,15 +111,25 @@ class environment extends \Twig_Environment } /** - * Get the phpBB root path - * - * @return string - */ + * Get the phpBB root path + * + * @return string + */ public function get_phpbb_root_path() { return $this->phpbb_root_path; } + /** + * Get the filesystem object + * + * @return \phpbb\filesystem\filesystem + */ + public function get_filesystem() + { + return $this->filesystem; + } + /** * Get the web root path * diff --git a/phpBB/phpbb/template/twig/node/includeasset.php b/phpBB/phpbb/template/twig/node/includeasset.php index 15195a226b..324823b8d7 100644 --- a/phpBB/phpbb/template/twig/node/includeasset.php +++ b/phpBB/phpbb/template/twig/node/includeasset.php @@ -39,7 +39,7 @@ abstract class includeasset extends \Twig_Node ->write("\$asset_file = ") ->subcompile($this->getNode('expr')) ->raw(";\n") - ->write("\$asset = new \phpbb\\template\\asset(\$asset_file, \$this->getEnvironment()->get_path_helper());\n") + ->write("\$asset = new \phpbb\\template\\asset(\$asset_file, \$this->getEnvironment()->get_path_helper(), \$this->getEnvironment()->get_filesystem());\n") ->write("if (substr(\$asset_file, 0, 2) !== './' && \$asset->is_relative()) {\n") ->indent() ->write("\$asset_path = \$asset->get_path();") -- cgit v1.2.1 From 7b301e22f32e9209bb4e3ea17a5637a84a4ef908 Mon Sep 17 00:00:00 2001 From: MateBartus Date: Fri, 1 May 2015 19:04:21 +0200 Subject: [ticket/13804] Make template's user dependency optional PHPBB3-13804 --- phpBB/phpbb/template/twig/twig.php | 24 +++++++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) (limited to 'phpBB/phpbb/template/twig') diff --git a/phpBB/phpbb/template/twig/twig.php b/phpBB/phpbb/template/twig/twig.php index 0e4c619029..ab349cc740 100644 --- a/phpBB/phpbb/template/twig/twig.php +++ b/phpBB/phpbb/template/twig/twig.php @@ -13,6 +13,8 @@ namespace phpbb\template\twig; +use phpbb\template\exception\user_object_not_available; + /** * Twig Template class. */ @@ -76,14 +78,14 @@ class twig extends \phpbb\template\base * * @param \phpbb\path_helper $path_helper * @param \phpbb\config\config $config - * @param \phpbb\user $user * @param \phpbb\template\context $context template context * @param \phpbb\template\twig\environment $twig_environment * @param string $cache_path + * @param \phpbb\user|null $user * @param array|\ArrayAccess $extensions * @param \phpbb\extension\manager $extension_manager extension manager, if null then template events will not be invoked */ - public function __construct(\phpbb\path_helper $path_helper, $config, $user, \phpbb\template\context $context, \phpbb\template\twig\environment $twig_environment, $cache_path, $extensions = array(), \phpbb\extension\manager $extension_manager = null) + public function __construct(\phpbb\path_helper $path_helper, $config, \phpbb\template\context $context, \phpbb\template\twig\environment $twig_environment, $cache_path, \phpbb\user $user = null, $extensions = array(), \phpbb\extension\manager $extension_manager = null) { $this->path_helper = $path_helper; $this->phpbb_root_path = $path_helper->get_phpbb_root_path(); @@ -126,9 +128,16 @@ class twig extends \phpbb\template\base * Get the style tree of the style preferred by the current user * * @return array Style tree, most specific first + * + * @throws \phpbb\template\exception\user_object_not_available When user service was not set */ public function get_user_style() { + if ($this->user === null) + { + throw new user_object_not_available(); + } + $style_list = array( $this->user->style['style_path'], ); @@ -344,11 +353,20 @@ class twig extends \phpbb\template\base $context_vars['.'][0], // To get normal vars array( 'definition' => new \phpbb\template\twig\definition(), - 'user' => $this->user, 'loops' => $context_vars, // To get loops ) ); + if ($this->user instanceof \phpbb\user) + { + $vars = array_merge( + $vars, + array( + 'user' => $this->user, + ) + ); + } + // cleanup unset($vars['loops']['.']); -- cgit v1.2.1 From 281f2ef2dacc7d635646edb3897fba8ff6f66d25 Mon Sep 17 00:00:00 2001 From: MateBartus Date: Mon, 11 May 2015 16:59:26 +0200 Subject: [ticket/13804] Remove unnecessary array_merge PHPBB3-13804 --- phpBB/phpbb/template/twig/twig.php | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) (limited to 'phpBB/phpbb/template/twig') diff --git a/phpBB/phpbb/template/twig/twig.php b/phpBB/phpbb/template/twig/twig.php index ab349cc740..6b3cf32bc8 100644 --- a/phpBB/phpbb/template/twig/twig.php +++ b/phpBB/phpbb/template/twig/twig.php @@ -359,12 +359,7 @@ class twig extends \phpbb\template\base if ($this->user instanceof \phpbb\user) { - $vars = array_merge( - $vars, - array( - 'user' => $this->user, - ) - ); + $vars['user'] = $this->user; } // cleanup -- cgit v1.2.1 From 8e5e954438b232f4ce7aec6a5db3d52b974c07a8 Mon Sep 17 00:00:00 2001 From: Nicofuma Date: Sun, 22 Feb 2015 23:36:27 +0100 Subject: [ticket/13645] Move the feeds to controllers PHPBB3-13645 --- phpBB/phpbb/template/twig/extension/routing.php | 43 +++++++++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 phpBB/phpbb/template/twig/extension/routing.php (limited to 'phpBB/phpbb/template/twig') diff --git a/phpBB/phpbb/template/twig/extension/routing.php b/phpBB/phpbb/template/twig/extension/routing.php new file mode 100644 index 0000000000..829ce738eb --- /dev/null +++ b/phpBB/phpbb/template/twig/extension/routing.php @@ -0,0 +1,43 @@ + +* @license GNU General Public License, version 2 (GPL-2.0) +* +* For full copyright and license information, please see +* the docs/CREDITS.txt file. +* +*/ + +namespace phpbb\template\twig\extension; + +use Symfony\Bridge\Twig\Extension\RoutingExtension; +use Symfony\Component\Routing\Generator\UrlGeneratorInterface; + +class routing extends RoutingExtension +{ + /** @var \phpbb\controller\helper */ + protected $helper; + + /** + * Constructor + * + * @param \phpbb\routing\helper $helper + */ + public function __construct(\phpbb\routing\helper $helper) + { + $this->helper = $helper; + } + + public function getPath($name, $parameters = array(), $relative = false) + { + return $this->helper->route($name, $parameters, true, false, $relative ? UrlGeneratorInterface::RELATIVE_PATH : UrlGeneratorInterface::ABSOLUTE_PATH); + } + + public function getUrl($name, $parameters = array(), $schemeRelative = false) + { + return $this->helper->route($name, $parameters, true, false, $schemeRelative ? UrlGeneratorInterface::NETWORK_PATH : UrlGeneratorInterface::ABSOLUTE_URL); + } +} -- cgit v1.2.1 From 4c004748453babcb8f0a277227c366a71c8c1bc6 Mon Sep 17 00:00:00 2001 From: Tristan Darricau Date: Fri, 18 Sep 2015 21:23:34 +0200 Subject: [ticket/12633] Doesn't use DEBUG to debug templates events Check the templates events on runtime only when Twig debug is on PHPBB3-12633 --- phpBB/phpbb/template/twig/node/event.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'phpBB/phpbb/template/twig') diff --git a/phpBB/phpbb/template/twig/node/event.php b/phpBB/phpbb/template/twig/node/event.php index b765bde98d..11fdb75247 100644 --- a/phpBB/phpbb/template/twig/node/event.php +++ b/phpBB/phpbb/template/twig/node/event.php @@ -46,7 +46,7 @@ class event extends \Twig_Node { $ext_namespace = str_replace('/', '_', $ext_namespace); - if (defined('DEBUG')) + if ($this->environment->isDebug()) { // If debug mode is enabled, lets check for new/removed EVENT // templates on page load rather than at compile. This is @@ -58,7 +58,7 @@ class event extends \Twig_Node ; } - if (defined('DEBUG') || $this->environment->getLoader()->exists('@' . $ext_namespace . '/' . $location . '.html')) + if ($this->environment->isDebug() || $this->environment->getLoader()->exists('@' . $ext_namespace . '/' . $location . '.html')) { $compiler ->write("\$previous_look_up_order = \$this->env->getNamespaceLookUpOrder();\n") @@ -70,7 +70,7 @@ class event extends \Twig_Node ; } - if (defined('DEBUG')) + if ($this->environment->isDebug()) { $compiler ->outdent() -- cgit v1.2.1 From 73e6e5b77faadbb7676961bf38122d669de111db Mon Sep 17 00:00:00 2001 From: Marc Alexander Date: Thu, 3 Dec 2015 17:50:29 +0100 Subject: [ticket/13454] Remove unused variables This is the first part of the changes. More to come. PHPBB3-13454 --- phpBB/phpbb/template/twig/node/includejs.php | 2 -- 1 file changed, 2 deletions(-) (limited to 'phpBB/phpbb/template/twig') diff --git a/phpBB/phpbb/template/twig/node/includejs.php b/phpBB/phpbb/template/twig/node/includejs.php index 0f67f9ff60..e77f2afeed 100644 --- a/phpBB/phpbb/template/twig/node/includejs.php +++ b/phpBB/phpbb/template/twig/node/includejs.php @@ -28,8 +28,6 @@ class includejs extends \phpbb\template\twig\node\includeasset */ protected function append_asset(\Twig_Compiler $compiler) { - $config = $this->environment->get_phpbb_config(); - $compiler ->raw("\n") - ; + return 'script'; } } -- cgit v1.2.1 From e91b1fa464c01d2ebf9fc9c732e8d2810223bc00 Mon Sep 17 00:00:00 2001 From: Tristan Darricau Date: Mon, 25 Jan 2016 00:31:13 +0100 Subject: =?UTF-8?q?[ticket/13717]=C2=A0Fix=20tests?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit PHPBB3-13717 --- phpBB/phpbb/template/twig/environment.php | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) (limited to 'phpBB/phpbb/template/twig') diff --git a/phpBB/phpbb/template/twig/environment.php b/phpBB/phpbb/template/twig/environment.php index 709505a75f..5660ddc3a4 100644 --- a/phpBB/phpbb/template/twig/environment.php +++ b/phpBB/phpbb/template/twig/environment.php @@ -205,8 +205,23 @@ class environment extends \Twig_Environment */ public function display($name, array $context = []) { + $level = ob_get_level(); ob_start(); - parent::display($name, $context); + + try + { + parent::display($name, $context); + } + catch (\Exception $e) + { + while (ob_get_level() > $level) + { + ob_end_clean(); + } + + throw $e; + } + $output = ob_get_clean(); echo $this->inject_assets($output); -- cgit v1.2.1 From 94f87d931854bf25fb051a27be9a1883510389c4 Mon Sep 17 00:00:00 2001 From: Marc Alexander Date: Tue, 2 Feb 2016 17:06:12 +0100 Subject: [ticket/14446] Add predefined placeholder variables to twig definition PHPBB3-14446 --- phpBB/phpbb/template/twig/definition.php | 5 ++++- phpBB/phpbb/template/twig/node/includeasset.php | 2 -- 2 files changed, 4 insertions(+), 3 deletions(-) (limited to 'phpBB/phpbb/template/twig') diff --git a/phpBB/phpbb/template/twig/definition.php b/phpBB/phpbb/template/twig/definition.php index cb3c953692..205f0e68ee 100644 --- a/phpBB/phpbb/template/twig/definition.php +++ b/phpBB/phpbb/template/twig/definition.php @@ -19,7 +19,10 @@ namespace phpbb\template\twig; class definition { /** @var array **/ - protected $definitions = array(); + protected $definitions = array( + 'SCRIPTS' => '__SCRIPTS_PLACEHOLDER__', + 'STYLESHEETS' => '__STYLESHEETS_PLACEHOLDER__' + ); /** * Get a DEFINE'd variable diff --git a/phpBB/phpbb/template/twig/node/includeasset.php b/phpBB/phpbb/template/twig/node/includeasset.php index 3d3c6e4df8..6d50eafc9d 100644 --- a/phpBB/phpbb/template/twig/node/includeasset.php +++ b/phpBB/phpbb/template/twig/node/includeasset.php @@ -53,8 +53,6 @@ abstract class includeasset extends \Twig_Node ->write("\$asset->add_assets_version('{$config['assets_version']}');\n") ->outdent() ->write("}\n") - ->write("\$context['definition']->set('STYLESHEETS', '__STYLESHEETS_PLACEHOLDER__');\n") - ->write("\$context['definition']->set('SCRIPTS', '__SCRIPTS_PLACEHOLDER__');\n") ->write("\$this->getEnvironment()->get_assets_bag()->add_{$this->get_setters_name()}(\$asset);") ; } -- cgit v1.2.1 From d34ffda9c1a8ac4354e6fd6cb05124de66d87f71 Mon Sep 17 00:00:00 2001 From: Tristan Darricau Date: Fri, 5 Feb 2016 20:30:02 +0100 Subject: [ticket/14457] Uses a random placeholder to inject css and js PHPBB3-14457 --- phpBB/phpbb/template/twig/definition.php | 5 +--- phpBB/phpbb/template/twig/environment.php | 38 +++++++++++++------------------ 2 files changed, 17 insertions(+), 26 deletions(-) (limited to 'phpBB/phpbb/template/twig') diff --git a/phpBB/phpbb/template/twig/definition.php b/phpBB/phpbb/template/twig/definition.php index 205f0e68ee..cb3c953692 100644 --- a/phpBB/phpbb/template/twig/definition.php +++ b/phpBB/phpbb/template/twig/definition.php @@ -19,10 +19,7 @@ namespace phpbb\template\twig; class definition { /** @var array **/ - protected $definitions = array( - 'SCRIPTS' => '__SCRIPTS_PLACEHOLDER__', - 'STYLESHEETS' => '__STYLESHEETS_PLACEHOLDER__' - ); + protected $definitions = array(); /** * Get a DEFINE'd variable diff --git a/phpBB/phpbb/template/twig/environment.php b/phpBB/phpbb/template/twig/environment.php index 5660ddc3a4..8b35497122 100644 --- a/phpBB/phpbb/template/twig/environment.php +++ b/phpBB/phpbb/template/twig/environment.php @@ -195,9 +195,7 @@ class environment extends \Twig_Environment */ public function render($name, array $context = []) { - $output = parent::render($name, $context); - - return $this->inject_assets($output); + return $this->display_with_assets($name, $context); } /** @@ -205,26 +203,22 @@ class environment extends \Twig_Environment */ public function display($name, array $context = []) { - $level = ob_get_level(); - ob_start(); + echo $this->display_with_assets($name, $context); + } - try - { - parent::display($name, $context); - } - catch (\Exception $e) - { - while (ob_get_level() > $level) - { - ob_end_clean(); - } + /** + * {@inheritdoc} + */ + private function display_with_assets($name, array $context = []) + { + $placeholder_salt = unique_id(); - throw $e; - } + $context['definition']->set('SCRIPTS', '__SCRIPTS_'.$placeholder_salt.'__'); + $context['definition']->set('STYLESHEETS', '__STYLESHEETS_'.$placeholder_salt.'__'); - $output = ob_get_clean(); + $output = parent::render($name, $context); - echo $this->inject_assets($output); + return $this->inject_assets($output, $placeholder_salt); } /** @@ -234,10 +228,10 @@ class environment extends \Twig_Environment * * @return string */ - private function inject_assets($output) + private function inject_assets($output, $placeholder_salt) { - $output = str_replace('__STYLESHEETS_PLACEHOLDER__', $this->assets_bag->get_stylesheets_content(), $output); - $output = str_replace('__SCRIPTS_PLACEHOLDER__', $this->assets_bag->get_scripts_content(), $output); + $output = str_replace('__SCRIPTS_'.$placeholder_salt.'__', $this->assets_bag->get_stylesheets_content(), $output); + $output = str_replace('__STYLESHEETS_'.$placeholder_salt.'__', $this->assets_bag->get_scripts_content(), $output); return $output; } -- cgit v1.2.1 From f253a853b8381a343f98c29bb399c8128695b696 Mon Sep 17 00:00:00 2001 From: Tristan Darricau Date: Fri, 5 Feb 2016 21:21:41 +0100 Subject: [ticket/14457] Fix twig/twig::assign_display PHPBB3-14457 --- phpBB/phpbb/template/twig/twig.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'phpBB/phpbb/template/twig') diff --git a/phpBB/phpbb/template/twig/twig.php b/phpBB/phpbb/template/twig/twig.php index 6b3cf32bc8..f322778eda 100644 --- a/phpBB/phpbb/template/twig/twig.php +++ b/phpBB/phpbb/template/twig/twig.php @@ -335,7 +335,7 @@ class twig extends \phpbb\template\base return $this->twig->render($this->get_filename_from_handle($handle), $this->get_template_vars()); } - $this->assign_var($template_var, $this->twig->render($this->get_filename_from_handle($handle, $this->get_template_vars()))); + $this->assign_var($template_var, $this->twig->render($this->get_filename_from_handle($handle), $this->get_template_vars())); return $this; } -- cgit v1.2.1 From f7c5098c60688ab8553732d5129680c959355e15 Mon Sep 17 00:00:00 2001 From: Tristan Darricau Date: Sun, 7 Feb 2016 12:23:21 +0100 Subject: [ticket/14457] CS PHPBB3-14457 --- phpBB/phpbb/template/twig/environment.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'phpBB/phpbb/template/twig') diff --git a/phpBB/phpbb/template/twig/environment.php b/phpBB/phpbb/template/twig/environment.php index 8b35497122..27a475f046 100644 --- a/phpBB/phpbb/template/twig/environment.php +++ b/phpBB/phpbb/template/twig/environment.php @@ -213,8 +213,8 @@ class environment extends \Twig_Environment { $placeholder_salt = unique_id(); - $context['definition']->set('SCRIPTS', '__SCRIPTS_'.$placeholder_salt.'__'); - $context['definition']->set('STYLESHEETS', '__STYLESHEETS_'.$placeholder_salt.'__'); + $context['definition']->set('SCRIPTS', '__SCRIPTS_' . $placeholder_salt . '__'); + $context['definition']->set('STYLESHEETS', '__STYLESHEETS_' . $placeholder_salt . '__'); $output = parent::render($name, $context); @@ -230,8 +230,8 @@ class environment extends \Twig_Environment */ private function inject_assets($output, $placeholder_salt) { - $output = str_replace('__SCRIPTS_'.$placeholder_salt.'__', $this->assets_bag->get_stylesheets_content(), $output); - $output = str_replace('__STYLESHEETS_'.$placeholder_salt.'__', $this->assets_bag->get_scripts_content(), $output); + $output = str_replace('__SCRIPTS_' . $placeholder_salt . '__', $this->assets_bag->get_stylesheets_content(), $output); + $output = str_replace('__STYLESHEETS_' . $placeholder_salt . '__', $this->assets_bag->get_scripts_content(), $output); return $output; } -- cgit v1.2.1 From 99ace63e62fddc934eded20afc6a7aebbc05e13b Mon Sep 17 00:00:00 2001 From: Tristan Darricau Date: Sun, 7 Feb 2016 12:49:00 +0100 Subject: [ticket/14457] Don't set CSS to JS and JS to CSS PHPBB3-14457 --- phpBB/phpbb/template/twig/environment.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'phpBB/phpbb/template/twig') diff --git a/phpBB/phpbb/template/twig/environment.php b/phpBB/phpbb/template/twig/environment.php index 27a475f046..65f1af5d9e 100644 --- a/phpBB/phpbb/template/twig/environment.php +++ b/phpBB/phpbb/template/twig/environment.php @@ -230,8 +230,8 @@ class environment extends \Twig_Environment */ private function inject_assets($output, $placeholder_salt) { - $output = str_replace('__SCRIPTS_' . $placeholder_salt . '__', $this->assets_bag->get_stylesheets_content(), $output); - $output = str_replace('__STYLESHEETS_' . $placeholder_salt . '__', $this->assets_bag->get_scripts_content(), $output); + $output = str_replace('__STYLESHEETS_' . $placeholder_salt . '__', $this->assets_bag->get_stylesheets_content(), $output); + $output = str_replace('__SCRIPTS_' . $placeholder_salt . '__', $this->assets_bag->get_scripts_content(), $output); return $output; } -- cgit v1.2.1 From 97bbf2d2b8b5b7689432ad8a35e96c38fd869dd7 Mon Sep 17 00:00:00 2001 From: Tristan Darricau Date: Sun, 7 Feb 2016 14:35:42 +0100 Subject: [ticket/14457] Handle the case where there isn't any 'definition' bag PHPBB3-14457 --- phpBB/phpbb/template/twig/environment.php | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) (limited to 'phpBB/phpbb/template/twig') diff --git a/phpBB/phpbb/template/twig/environment.php b/phpBB/phpbb/template/twig/environment.php index 65f1af5d9e..56c85c8d71 100644 --- a/phpBB/phpbb/template/twig/environment.php +++ b/phpBB/phpbb/template/twig/environment.php @@ -213,8 +213,11 @@ class environment extends \Twig_Environment { $placeholder_salt = unique_id(); - $context['definition']->set('SCRIPTS', '__SCRIPTS_' . $placeholder_salt . '__'); - $context['definition']->set('STYLESHEETS', '__STYLESHEETS_' . $placeholder_salt . '__'); + if (array_key_exists('definition', $context)) + { + $context['definition']->set('SCRIPTS', '__SCRIPTS_' . $placeholder_salt . '__'); + $context['definition']->set('STYLESHEETS', '__STYLESHEETS_' . $placeholder_salt . '__'); + } $output = parent::render($name, $context); -- cgit v1.2.1 From 5cdbef860de6eccbf1ad62390668acc7fbccb46a Mon Sep 17 00:00:00 2001 From: Tristan Darricau Date: Wed, 23 Mar 2016 11:26:30 +0100 Subject: [ticket/13616] Uses symfony/proxy-manager-bridge to lazy load twig lexer PHPBB3-13616 --- phpBB/phpbb/template/twig/environment.php | 21 ++------------------- 1 file changed, 2 insertions(+), 19 deletions(-) (limited to 'phpBB/phpbb/template/twig') diff --git a/phpBB/phpbb/template/twig/environment.php b/phpBB/phpbb/template/twig/environment.php index 56c85c8d71..179412a2e3 100644 --- a/phpBB/phpbb/template/twig/environment.php +++ b/phpBB/phpbb/template/twig/environment.php @@ -50,20 +50,18 @@ class environment extends \Twig_Environment * @param \phpbb\config\config $phpbb_config The phpBB configuration * @param \phpbb\filesystem\filesystem $filesystem * @param \phpbb\path_helper $path_helper phpBB path helper - * @param \Symfony\Component\DependencyInjection\ContainerInterface $container The dependency injection container * @param string $cache_path The path to the cache directory * @param \phpbb\extension\manager $extension_manager phpBB extension manager * @param \Twig_LoaderInterface $loader Twig loader interface * @param array $options Array of options to pass to Twig */ - public function __construct(\phpbb\config\config $phpbb_config, \phpbb\filesystem\filesystem $filesystem, \phpbb\path_helper $path_helper, \Symfony\Component\DependencyInjection\ContainerInterface $container, $cache_path, \phpbb\extension\manager $extension_manager = null, \Twig_LoaderInterface $loader = null, $options = array()) + public function __construct(\phpbb\config\config $phpbb_config, \phpbb\filesystem\filesystem $filesystem, \phpbb\path_helper $path_helper, $cache_path, \phpbb\extension\manager $extension_manager = null, \Twig_LoaderInterface $loader = null, $options = array()) { $this->phpbb_config = $phpbb_config; $this->filesystem = $filesystem; $this->phpbb_path_helper = $path_helper; $this->extension_manager = $extension_manager; - $this->container = $container; $this->phpbb_root_path = $this->phpbb_path_helper->get_phpbb_root_path(); $this->web_root_path = $this->phpbb_path_helper->get_web_root_path(); @@ -77,24 +75,9 @@ class environment extends \Twig_Environment 'autoescape' => false, ), $options); - return parent::__construct($loader, $options); + parent::__construct($loader, $options); } - /** - * {@inheritdoc} - */ - public function getLexer() - { - if (null === $this->lexer) - { - $this->lexer = $this->container->get('template.twig.lexer'); - $this->lexer->set_environment($this); - } - - return $this->lexer; - } - - /** * Get the list of enabled phpBB extensions * -- cgit v1.2.1 From 7a5fbd0257d7b15b8230fa6c60581cc197cb1a47 Mon Sep 17 00:00:00 2001 From: Tristan Darricau Date: Sun, 2 Oct 2016 19:24:45 +0200 Subject: [ticket/14807] Updates Twig PHPBB3-14807 --- phpBB/phpbb/template/twig/loader.php | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'phpBB/phpbb/template/twig') diff --git a/phpBB/phpbb/template/twig/loader.php b/phpBB/phpbb/template/twig/loader.php index 8b12188a77..b2261dd8cd 100644 --- a/phpBB/phpbb/template/twig/loader.php +++ b/phpBB/phpbb/template/twig/loader.php @@ -12,6 +12,7 @@ */ namespace phpbb\template\twig; +use Twig_Loader_Filesystem; /** * Twig Template loader @@ -100,6 +101,16 @@ class loader extends \Twig_Loader_Filesystem return; } + /** + * Adds a realpath call to fix a BC break in Twig 1.26 (https://github.com/twigphp/Twig/issues/2145) + * + * {@inheritdoc} + */ + public function addPath($path, $namespace = self::MAIN_NAMESPACE) + { + return parent::addPath($this->filesystem->realpath($path), $namespace); + } + /** * Find the template * -- cgit v1.2.1 From b2711371f1267a1314ccf1de976d5432c03a2357 Mon Sep 17 00:00:00 2001 From: Tristan Darricau Date: Mon, 10 Oct 2016 09:14:24 +0200 Subject: [ticket/14807] s9e/textformatter 0.8.1 PHPBB3-14807 --- phpBB/phpbb/template/twig/loader.php | 1 - 1 file changed, 1 deletion(-) (limited to 'phpBB/phpbb/template/twig') diff --git a/phpBB/phpbb/template/twig/loader.php b/phpBB/phpbb/template/twig/loader.php index b2261dd8cd..d2b42852ce 100644 --- a/phpBB/phpbb/template/twig/loader.php +++ b/phpBB/phpbb/template/twig/loader.php @@ -12,7 +12,6 @@ */ namespace phpbb\template\twig; -use Twig_Loader_Filesystem; /** * Twig Template loader -- cgit v1.2.1 From 4d07f8a13423529d4559d6579f98305ee471ee84 Mon Sep 17 00:00:00 2001 From: Marc Alexander Date: Thu, 3 Nov 2016 21:36:12 +0100 Subject: [ticket/14716] Update dependencies to latest versions This addresses some issues with symfony that resulted in issues when open_basedir restrictions were enabled, as well as issues with JPEG images in fast-image-size. The phpBB class extending the twig lexer also had to be modified to ensure compatibility after BC was broken by the PR https://github.com/twigphp/Twig/pull/2182 for twig 1.27. PHPBB3-14716 --- phpBB/phpbb/template/twig/lexer.php | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'phpBB/phpbb/template/twig') diff --git a/phpBB/phpbb/template/twig/lexer.php b/phpBB/phpbb/template/twig/lexer.php index f1542109a4..de03aec04b 100644 --- a/phpBB/phpbb/template/twig/lexer.php +++ b/phpBB/phpbb/template/twig/lexer.php @@ -22,6 +22,11 @@ class lexer extends \Twig_Lexer public function tokenize($code, $filename = null) { + if ($code instanceof \Twig_Source) + { + $filename = $code->getName(); + $code = $code->getCode(); + } // Our phpBB tags // Commented out tokens are handled separately from the main replace $phpbb_tags = array( @@ -125,7 +130,7 @@ class lexer extends \Twig_Lexer // Appends any filters $code = preg_replace('#{([a-zA-Z0-9_\.]+)(\|[^}]+?)?}#', '{{ $1$2 }}', $code); - return parent::tokenize($code, $filename); + return parent::tokenize(new \Twig_Source($code, $filename)); } /** -- cgit v1.2.1 From a96fc3d87fdb6558397debd26992877677816d34 Mon Sep 17 00:00:00 2001 From: Marc Alexander Date: Wed, 16 Nov 2016 21:39:29 +0100 Subject: [ticket/14867] Revert back to twig 1.26.* and update dependencies The revert of twig back to 1.26.* is necessary due to a breaking change in the way the Filesystem loader returns the paths to template files. PHPBB3-14867 --- phpBB/phpbb/template/twig/lexer.php | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) (limited to 'phpBB/phpbb/template/twig') diff --git a/phpBB/phpbb/template/twig/lexer.php b/phpBB/phpbb/template/twig/lexer.php index de03aec04b..f1542109a4 100644 --- a/phpBB/phpbb/template/twig/lexer.php +++ b/phpBB/phpbb/template/twig/lexer.php @@ -22,11 +22,6 @@ class lexer extends \Twig_Lexer public function tokenize($code, $filename = null) { - if ($code instanceof \Twig_Source) - { - $filename = $code->getName(); - $code = $code->getCode(); - } // Our phpBB tags // Commented out tokens are handled separately from the main replace $phpbb_tags = array( @@ -130,7 +125,7 @@ class lexer extends \Twig_Lexer // Appends any filters $code = preg_replace('#{([a-zA-Z0-9_\.]+)(\|[^}]+?)?}#', '{{ $1$2 }}', $code); - return parent::tokenize(new \Twig_Source($code, $filename)); + return parent::tokenize($code, $filename); } /** -- cgit v1.2.1 From 633bbc9c6d42785233ea10165a081c7c32795d1c Mon Sep 17 00:00:00 2001 From: rxu Date: Wed, 11 Jan 2017 22:50:50 +0700 Subject: [ticket/14990] Add core events to the Twig environment PHPBB3-14990 --- phpBB/phpbb/template/twig/environment.php | 32 ++++++++++++++++++++++++++++++- 1 file changed, 31 insertions(+), 1 deletion(-) (limited to 'phpBB/phpbb/template/twig') diff --git a/phpBB/phpbb/template/twig/environment.php b/phpBB/phpbb/template/twig/environment.php index 179412a2e3..b2b4f990dd 100644 --- a/phpBB/phpbb/template/twig/environment.php +++ b/phpBB/phpbb/template/twig/environment.php @@ -32,6 +32,11 @@ class environment extends \Twig_Environment /** @var \phpbb\extension\manager */ protected $extension_manager; + /** + * @var \phpbb\event\dispatcher_interface + */ + protected $phpbb_dispatcher; + /** @var string */ protected $phpbb_root_path; @@ -54,14 +59,16 @@ class environment extends \Twig_Environment * @param \phpbb\extension\manager $extension_manager phpBB extension manager * @param \Twig_LoaderInterface $loader Twig loader interface * @param array $options Array of options to pass to Twig + * @param \phpbb\event\dispatcher_interface $phpbb_dispatcher Event dispatcher object */ - public function __construct(\phpbb\config\config $phpbb_config, \phpbb\filesystem\filesystem $filesystem, \phpbb\path_helper $path_helper, $cache_path, \phpbb\extension\manager $extension_manager = null, \Twig_LoaderInterface $loader = null, $options = array()) + public function __construct(\phpbb\config\config $phpbb_config, \phpbb\filesystem\filesystem $filesystem, \phpbb\path_helper $path_helper, $cache_path, \phpbb\extension\manager $extension_manager = null, \Twig_LoaderInterface $loader = null, $options = array(), \phpbb\event\dispatcher_interface $phpbb_dispatcher = null) { $this->phpbb_config = $phpbb_config; $this->filesystem = $filesystem; $this->phpbb_path_helper = $path_helper; $this->extension_manager = $extension_manager; + $this->phpbb_dispatcher = $phpbb_dispatcher; $this->phpbb_root_path = $this->phpbb_path_helper->get_phpbb_root_path(); $this->web_root_path = $this->phpbb_path_helper->get_web_root_path(); @@ -202,8 +209,31 @@ class environment extends \Twig_Environment $context['definition']->set('STYLESHEETS', '__STYLESHEETS_' . $placeholder_salt . '__'); } + /** + * Allow changing the template output stream before rendering + * + * @event core.twig_environment_render_template_before + * @var array $context Array with template variables + * @var string $name The template name + * @since 3.2.1-RC1 + */ + $vars = array('context', 'name'); + extract($this->phpbb_dispatcher->trigger_event('core.twig_environment_render_template_before', compact($vars))); + $output = parent::render($name, $context); + /** + * Allow changing the template output stream after rendering + * + * @event core.twig_environment_render_template_before + * @var array $context Array with template variables + * @var string $name The template name + * @var string $output Rendered template output stream + * @since 3.2.1-RC1 + */ + $vars = array('context', 'name', 'output'); + extract($this->phpbb_dispatcher->trigger_event('core.twig_environment_render_template_after', compact($vars))); + return $this->inject_assets($output, $placeholder_salt); } -- cgit v1.2.1 From 1ea114ca20bd4613420284d7bfc4c92ab0a817b4 Mon Sep 17 00:00:00 2001 From: rxu Date: Wed, 11 Jan 2017 23:53:12 +0700 Subject: [ticket/14990] Fix event name, email parsing, installer and dispatcher calls PHPBB3-14990 --- phpBB/phpbb/template/twig/environment.php | 32 +++++++++++++++++-------------- 1 file changed, 18 insertions(+), 14 deletions(-) (limited to 'phpBB/phpbb/template/twig') diff --git a/phpBB/phpbb/template/twig/environment.php b/phpBB/phpbb/template/twig/environment.php index b2b4f990dd..d9e84b042e 100644 --- a/phpBB/phpbb/template/twig/environment.php +++ b/phpBB/phpbb/template/twig/environment.php @@ -32,9 +32,7 @@ class environment extends \Twig_Environment /** @var \phpbb\extension\manager */ protected $extension_manager; - /** - * @var \phpbb\event\dispatcher_interface - */ + /** @var \phpbb\event\dispatcher_interface */ protected $phpbb_dispatcher; /** @var string */ @@ -61,7 +59,7 @@ class environment extends \Twig_Environment * @param array $options Array of options to pass to Twig * @param \phpbb\event\dispatcher_interface $phpbb_dispatcher Event dispatcher object */ - public function __construct(\phpbb\config\config $phpbb_config, \phpbb\filesystem\filesystem $filesystem, \phpbb\path_helper $path_helper, $cache_path, \phpbb\extension\manager $extension_manager = null, \Twig_LoaderInterface $loader = null, $options = array(), \phpbb\event\dispatcher_interface $phpbb_dispatcher = null) + public function __construct(\phpbb\config\config $phpbb_config, \phpbb\filesystem\filesystem $filesystem, \phpbb\path_helper $path_helper, $cache_path, \phpbb\extension\manager $extension_manager = null, \Twig_LoaderInterface $loader = null, $options = array(), \phpbb\event\dispatcher_interface $phpbb_dispatcher = null) { $this->phpbb_config = $phpbb_config; @@ -213,26 +211,32 @@ class environment extends \Twig_Environment * Allow changing the template output stream before rendering * * @event core.twig_environment_render_template_before - * @var array $context Array with template variables - * @var string $name The template name + * @var array context Array with template variables + * @var string name The template name * @since 3.2.1-RC1 */ - $vars = array('context', 'name'); - extract($this->phpbb_dispatcher->trigger_event('core.twig_environment_render_template_before', compact($vars))); + if ($this->phpbb_dispatcher) + { + $vars = array('context', 'name'); + extract($this->phpbb_dispatcher->trigger_event('core.twig_environment_render_template_before', compact($vars))); + } $output = parent::render($name, $context); /** * Allow changing the template output stream after rendering * - * @event core.twig_environment_render_template_before - * @var array $context Array with template variables - * @var string $name The template name - * @var string $output Rendered template output stream + * @event core.twig_environment_render_template_after + * @var array context Array with template variables + * @var string name The template name + * @var string output Rendered template output stream * @since 3.2.1-RC1 */ - $vars = array('context', 'name', 'output'); - extract($this->phpbb_dispatcher->trigger_event('core.twig_environment_render_template_after', compact($vars))); + if ($this->phpbb_dispatcher) + { + $vars = array('context', 'name', 'output'); + extract($this->phpbb_dispatcher->trigger_event('core.twig_environment_render_template_after', compact($vars))); + } return $this->inject_assets($output, $placeholder_salt); } -- cgit v1.2.1 From fcc8e155ec309669bebbf6e0370cecfe64c95193 Mon Sep 17 00:00:00 2001 From: rxu Date: Sun, 16 Apr 2017 20:53:59 +0700 Subject: [ticket/14990] Move dispatcher object to the front of the options array PHPBB3-14990 --- phpBB/phpbb/template/twig/environment.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'phpBB/phpbb/template/twig') diff --git a/phpBB/phpbb/template/twig/environment.php b/phpBB/phpbb/template/twig/environment.php index d9e84b042e..ac4b16e457 100644 --- a/phpBB/phpbb/template/twig/environment.php +++ b/phpBB/phpbb/template/twig/environment.php @@ -56,10 +56,10 @@ class environment extends \Twig_Environment * @param string $cache_path The path to the cache directory * @param \phpbb\extension\manager $extension_manager phpBB extension manager * @param \Twig_LoaderInterface $loader Twig loader interface - * @param array $options Array of options to pass to Twig * @param \phpbb\event\dispatcher_interface $phpbb_dispatcher Event dispatcher object + * @param array $options Array of options to pass to Twig */ - public function __construct(\phpbb\config\config $phpbb_config, \phpbb\filesystem\filesystem $filesystem, \phpbb\path_helper $path_helper, $cache_path, \phpbb\extension\manager $extension_manager = null, \Twig_LoaderInterface $loader = null, $options = array(), \phpbb\event\dispatcher_interface $phpbb_dispatcher = null) + public function __construct(\phpbb\config\config $phpbb_config, \phpbb\filesystem\filesystem $filesystem, \phpbb\path_helper $path_helper, $cache_path, \phpbb\extension\manager $extension_manager = null, \Twig_LoaderInterface $loader = null, \phpbb\event\dispatcher_interface $phpbb_dispatcher = null, $options = array()) { $this->phpbb_config = $phpbb_config; -- cgit v1.2.1 From f8fbe3793680af1dae2db2829cfc84068831c52f Mon Sep 17 00:00:00 2001 From: rxu Date: Wed, 28 Jun 2017 00:58:03 +0700 Subject: [ticket/14972] replace all occurrences of sizeof() with the count() PHPBB3-14972 --- phpBB/phpbb/template/twig/extension.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'phpBB/phpbb/template/twig') diff --git a/phpBB/phpbb/template/twig/extension.php b/phpBB/phpbb/template/twig/extension.php index f0e716d697..1aa7717470 100644 --- a/phpBB/phpbb/template/twig/extension.php +++ b/phpBB/phpbb/template/twig/extension.php @@ -146,7 +146,7 @@ class extension extends \Twig_Extension // of items to grab (length) // Start must always be the actual starting number for this calculation (not negative) - $start = ($start < 0) ? sizeof($item) + $start : $start; + $start = ($start < 0) ? count($item) + $start : $start; $end = $end - $start; } -- cgit v1.2.1 From 52f5e54d8a2a328123485272f18917199e06ec30 Mon Sep 17 00:00:00 2001 From: Jakub Senko Date: Mon, 18 Jun 2018 11:54:47 +0200 Subject: [ticket/15666] Fix array key in twig lang() call PHPBB3-15666 --- phpBB/phpbb/template/twig/extension.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'phpBB/phpbb/template/twig') diff --git a/phpBB/phpbb/template/twig/extension.php b/phpBB/phpbb/template/twig/extension.php index 1aa7717470..f6f8e03ca2 100644 --- a/phpBB/phpbb/template/twig/extension.php +++ b/phpBB/phpbb/template/twig/extension.php @@ -172,7 +172,7 @@ class extension extends \Twig_Extension $context_vars = $this->context->get_root_ref(); - if (isset($context_vars['L_' . $key])) + if (is_string($key) && isset($context_vars['L_' . $key])) { return $context_vars['L_' . $key]; } -- cgit v1.2.1 From 5d4fccd235072b299fba0920e464a1a43fc0b91d Mon Sep 17 00:00:00 2001 From: Marc Alexander Date: Mon, 29 Oct 2018 16:07:48 +0100 Subject: [ticket/15542] Always append assets versions to assets PHPBB3-15542 --- phpBB/phpbb/template/twig/node/includeasset.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'phpBB/phpbb/template/twig') diff --git a/phpBB/phpbb/template/twig/node/includeasset.php b/phpBB/phpbb/template/twig/node/includeasset.php index 6d50eafc9d..27ac2e6aa2 100644 --- a/phpBB/phpbb/template/twig/node/includeasset.php +++ b/phpBB/phpbb/template/twig/node/includeasset.php @@ -50,9 +50,9 @@ abstract class includeasset extends \Twig_Node ->write("\$asset->set_path(\$local_file, true);\n") ->outdent() ->write("}\n") - ->write("\$asset->add_assets_version('{$config['assets_version']}');\n") ->outdent() ->write("}\n") + ->write("\$asset->add_assets_version('{$config['assets_version']}');\n") ->write("\$this->getEnvironment()->get_assets_bag()->add_{$this->get_setters_name()}(\$asset);") ; } -- cgit v1.2.1 From 11ae11a1562649b5d7870928a3281861c9ea39db Mon Sep 17 00:00:00 2001 From: Marc Alexander Date: Mon, 29 Oct 2018 22:57:53 +0100 Subject: [ticket/15542] Only add assets version for relative paths PHPBB3-15542 --- phpBB/phpbb/template/twig/node/includeasset.php | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'phpBB/phpbb/template/twig') diff --git a/phpBB/phpbb/template/twig/node/includeasset.php b/phpBB/phpbb/template/twig/node/includeasset.php index 27ac2e6aa2..12034b7820 100644 --- a/phpBB/phpbb/template/twig/node/includeasset.php +++ b/phpBB/phpbb/template/twig/node/includeasset.php @@ -52,7 +52,12 @@ abstract class includeasset extends \Twig_Node ->write("}\n") ->outdent() ->write("}\n") + ->write("\n") + ->write("if (\$asset->is_relative()) {\n") + ->indent() ->write("\$asset->add_assets_version('{$config['assets_version']}');\n") + ->outdent() + ->write("}\n") ->write("\$this->getEnvironment()->get_assets_bag()->add_{$this->get_setters_name()}(\$asset);") ; } -- cgit v1.2.1