From b419f42f2e0c4e9d3e16ca55331391898ff2335b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=A9my=20Dufraisse?= Date: Tue, 6 Dec 2022 12:06:47 +0100 Subject: [PATCH] fix(AssetsManager): detect local assets --- includes/services/AssetsManager.php | 40 +++++++++++++++++++++-------- 1 file changed, 30 insertions(+), 10 deletions(-) diff --git a/includes/services/AssetsManager.php b/includes/services/AssetsManager.php index 7b5fcb99c..7033fbe74 100644 --- a/includes/services/AssetsManager.php +++ b/includes/services/AssetsManager.php @@ -35,13 +35,15 @@ class AssetsManager 'javascripts/vendor/vue/vue.js' => 'javascripts/vendor/vue/vue.min.js', ]; + protected $dataPath; protected $wiki; public function __construct(Wiki $wiki) { $this->wiki = $wiki; + $this->dataPath = $this->wiki->getDataPath(); } - + public function AddCSS($style) { if (!isset($GLOBALS['css'])) { @@ -72,10 +74,11 @@ public function AddCSSFile($file, $conditionstart = '', $conditionend = '', $att public function LinkCSSFile($file, $conditionstart = '', $conditionend = '', $attrs = "") { $file = $this->mapFilePath($file); - $isUrl = strpos($file, "http://") === 0 || strpos($file, "https://") === 0; - - if ($isUrl || !empty($file) && file_exists($file)) { - $href = $isUrl ? $file : "{$this->wiki->getBaseUrl(true)}/{$file}"; + $isUrl = $this->isUrl($file); + $isLocal = !$isUrl && $this->isLocalFile($file); + + if ($isUrl || $isLocal || (!empty($file) && file_exists($file))) { + $href = $isUrl ? $file : "{$this->wiki->getBaseUrl(!$isLocal)}/{$file}"; $revision = $this->wiki->GetConfigValue('yeswiki_release', null); return <<wiki->GetConfigValue('yeswiki_release', null); $initChar = (strpos($file, '?') !== false) ? '&' : '?'; $rev = ($revision) ? $initChar.'v='.$revision : ''; - + $file = $this->mapFilePath($file); + $isUrl = $this->isUrl($file); + $isLocal = !$isUrl && $this->isLocalFile($file); - if (!empty($file) && file_exists($file)) { + if (!$isUrl && ($isLocal || (!empty($file) && file_exists($file)))) { // include local files - $code = "