aboutsummaryrefslogtreecommitdiffstats
path: root/phpBB/phpbb/template/twig/environment.php
diff options
context:
space:
mode:
authorMarc Alexander <admin@m-a-styles.de>2016-02-18 21:52:48 +0100
committerMarc Alexander <admin@m-a-styles.de>2016-02-18 21:52:48 +0100
commitf6fd819764016afe39dcc3c486b0fe73c9478ad5 (patch)
tree43828d9b0761cf8144c59f032891249c7b79ac68 /phpBB/phpbb/template/twig/environment.php
parent028191e7c2360b3bf0d3ed4b70cbf70364e3b230 (diff)
parent58359b158716d6dc752c6a50b05b8dea7d5dfff4 (diff)
downloadforums-f6fd819764016afe39dcc3c486b0fe73c9478ad5.tar
forums-f6fd819764016afe39dcc3c486b0fe73c9478ad5.tar.gz
forums-f6fd819764016afe39dcc3c486b0fe73c9478ad5.tar.bz2
forums-f6fd819764016afe39dcc3c486b0fe73c9478ad5.tar.xz
forums-f6fd819764016afe39dcc3c486b0fe73c9478ad5.zip
Merge pull request #4165 from Nicofuma/ticket/14457
[ticket/14457] Uses a random placeholder to inject css and js
Diffstat (limited to 'phpBB/phpbb/template/twig/environment.php')
-rw-r--r--phpBB/phpbb/template/twig/environment.php39
1 files changed, 18 insertions, 21 deletions
diff --git a/phpBB/phpbb/template/twig/environment.php b/phpBB/phpbb/template/twig/environment.php
index 5660ddc3a4..56c85c8d71 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,25 @@ 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;
+ if (array_key_exists('definition', $context))
+ {
+ $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 +231,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('__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;
}