mirror of
https://github.com/Combodo/iTop.git
synced 2026-04-24 11:08:45 +02:00
N°7315 - Migrate usages of WebPage::add_linked_script() to absolute URIs to ensure they are correctly loaded no matter the endpoint location
This commit is contained in:
@@ -26,8 +26,8 @@ class ErrorPage extends NiceWebPage
|
||||
{
|
||||
$oKpi = new ExecutionKPI();
|
||||
parent::__construct($sTitle);
|
||||
$this->add_linked_script("../js/jquery.blockUI.js");
|
||||
$this->add_linked_script("../setup/setup.js");
|
||||
$this->add_linked_script(utils::GetAbsoluteUrlAppRoot() . "js/jquery.blockUI.js");
|
||||
$this->add_linked_script(utils::GetAbsoluteUrlAppRoot() . "setup/setup.js");
|
||||
$this->add_linked_stylesheet(utils::GetAbsoluteUrlAppRoot().'css/font-awesome/css/all.min.css');
|
||||
$this->add_linked_stylesheet(utils::GetAbsoluteUrlAppRoot().'css/font-combodo/font-combodo.css');
|
||||
$this->add_saas("css/setup.scss");
|
||||
|
||||
@@ -735,15 +735,28 @@ class WebPage implements Page
|
||||
* Add a script (as an include, i.e. link) to the header of the page.<br>
|
||||
* Handles duplicates : calling twice with the same script will add the script only once
|
||||
*
|
||||
* @uses WebPage::$a_linked_scripts
|
||||
* @param string $s_linked_script
|
||||
* @param string $sLinkedScriptAbsUrl
|
||||
*
|
||||
* @return void
|
||||
* @uses WebPage::$a_linked_scripts
|
||||
* @since 3.2.0 N°6935 $sLinkedScriptAbsUrl MUST be an absolute URL
|
||||
*/
|
||||
public function add_linked_script($s_linked_script)
|
||||
public function add_linked_script($sLinkedScriptAbsUrl)
|
||||
{
|
||||
if (!empty(trim($s_linked_script))) {
|
||||
$this->a_linked_scripts[$s_linked_script] = $s_linked_script;
|
||||
// Ensure there is actually an URI
|
||||
if (utils::IsNullOrEmptyString(trim($sLinkedScriptAbsUrl))) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Check if URI is absolute ("://" do allow any protocol), otherwise warn that it's a deprecated behavior
|
||||
if (false === stripos($sLinkedScriptAbsUrl, "://")) {
|
||||
IssueLog::Warning("Linked script added to page with a non absolute URL, which may lead to it not being loaded and causing javascript errors.", null, [
|
||||
"linked_script_url" => $sLinkedScriptAbsUrl,
|
||||
"request_uri" => $_SERVER['REQUEST_URI'],
|
||||
]);
|
||||
}
|
||||
|
||||
$this->a_linked_scripts[$sLinkedScriptAbsUrl] = $sLinkedScriptAbsUrl;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -771,7 +771,7 @@ JS;
|
||||
protected function AddRequiredForModificationJsFilesToPage(iTopWebPage &$oPage): void
|
||||
{
|
||||
foreach (static::EnumRequiredForModificationJsFilesRelPaths() as $sJsFileRelPath) {
|
||||
$oPage->add_linked_script("../$sJsFileRelPath");
|
||||
$oPage->add_linked_script(utils::GetAbsoluteUrlAppRoot() . "$sJsFileRelPath");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user