diff options
author | Tristan Darricau <tristan.darricau@sensiolabs.com> | 2016-02-05 20:30:02 +0100 |
---|---|---|
committer | Tristan Darricau <tristan.darricau@sensiolabs.com> | 2016-02-18 17:30:31 +0100 |
commit | d34ffda9c1a8ac4354e6fd6cb05124de66d87f71 (patch) | |
tree | fa66fe7797654b9b7393e75c2177f43e2d849316 /phpBB | |
parent | d0ce6a18df2172a6e9baf1f1c2802efb30b25323 (diff) | |
download | forums-d34ffda9c1a8ac4354e6fd6cb05124de66d87f71.tar forums-d34ffda9c1a8ac4354e6fd6cb05124de66d87f71.tar.gz forums-d34ffda9c1a8ac4354e6fd6cb05124de66d87f71.tar.bz2 forums-d34ffda9c1a8ac4354e6fd6cb05124de66d87f71.tar.xz forums-d34ffda9c1a8ac4354e6fd6cb05124de66d87f71.zip |
[ticket/14457] Uses a random placeholder to inject css and js
PHPBB3-14457
Diffstat (limited to 'phpBB')
-rw-r--r-- | phpBB/phpbb/template/twig/definition.php | 5 | ||||
-rw-r--r-- | phpBB/phpbb/template/twig/environment.php | 38 |
2 files changed, 17 insertions, 26 deletions
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; } |