introduce a template function to output a inline script
This handles the output of a potentially available nonce.
This commit is contained in:
parent
e0aa67753c
commit
a77ab274d6
|
@ -150,7 +150,7 @@ class Editor extends Ui
|
|||
// start editor html output
|
||||
if ($wr) {
|
||||
// sets changed to true when previewed
|
||||
echo '<script>/*<![CDATA[*/textChanged = ' . ($mod ? 'true' : 'false') . '/*!]]>*/</script>';
|
||||
tpl_inlineScript('textChanged = ' . ($mod ? 'true' : 'false') . ';');
|
||||
}
|
||||
|
||||
// print intro locale text (edit, rditrev, or read.txt)
|
||||
|
|
|
@ -440,6 +440,30 @@ function _tpl_metaheaders_action($data)
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Output the given script as inline script tag
|
||||
*
|
||||
* This function will add the nonce attribute if a nonce is available.
|
||||
*
|
||||
* The script is NOT automatically escaped!
|
||||
*
|
||||
* @param string $script
|
||||
* @param bool $return Return or print directly?
|
||||
* @return string|void
|
||||
*/
|
||||
function tpl_inlineScript($script, $return = false)
|
||||
{
|
||||
$nonce = getenv('NONCE');
|
||||
if ($nonce) {
|
||||
$script = '<script nonce="' . $nonce . '">' . $script . '</script>';
|
||||
} else {
|
||||
$script = '<script>' . $script . '</script>';
|
||||
}
|
||||
|
||||
if ($return) return $script;
|
||||
echo $script;
|
||||
}
|
||||
|
||||
/**
|
||||
* Print a link
|
||||
*
|
||||
|
|
Loading…
Reference in New Issue