mirror of
https://github.com/phpbb/phpbb.git
synced 2025-06-12 01:11:15 +02:00
[ticket/14457] Uses a random placeholder to inject css and js
PHPBB3-14457
This commit is contained in:
@ -19,10 +19,7 @@ namespace phpbb\template\twig;
|
|||||||
class definition
|
class definition
|
||||||
{
|
{
|
||||||
/** @var array **/
|
/** @var array **/
|
||||||
protected $definitions = array(
|
protected $definitions = array();
|
||||||
'SCRIPTS' => '__SCRIPTS_PLACEHOLDER__',
|
|
||||||
'STYLESHEETS' => '__STYLESHEETS_PLACEHOLDER__'
|
|
||||||
);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get a DEFINE'd variable
|
* Get a DEFINE'd variable
|
||||||
|
@ -195,9 +195,7 @@ class environment extends \Twig_Environment
|
|||||||
*/
|
*/
|
||||||
public function render($name, array $context = [])
|
public function render($name, array $context = [])
|
||||||
{
|
{
|
||||||
$output = parent::render($name, $context);
|
return $this->display_with_assets($name, $context);
|
||||||
|
|
||||||
return $this->inject_assets($output);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -205,26 +203,22 @@ class environment extends \Twig_Environment
|
|||||||
*/
|
*/
|
||||||
public function display($name, array $context = [])
|
public function display($name, array $context = [])
|
||||||
{
|
{
|
||||||
$level = ob_get_level();
|
echo $this->display_with_assets($name, $context);
|
||||||
ob_start();
|
}
|
||||||
|
|
||||||
try
|
/**
|
||||||
{
|
* {@inheritdoc}
|
||||||
parent::display($name, $context);
|
*/
|
||||||
}
|
private function display_with_assets($name, array $context = [])
|
||||||
catch (\Exception $e)
|
{
|
||||||
{
|
$placeholder_salt = unique_id();
|
||||||
while (ob_get_level() > $level)
|
|
||||||
{
|
|
||||||
ob_end_clean();
|
|
||||||
}
|
|
||||||
|
|
||||||
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
|
* @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_salt.'__', $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_scripts_content(), $output);
|
||||||
|
|
||||||
return $output;
|
return $output;
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user