From d0df6cb89dc1f9ed304a24a3c1adbc7e94a15913 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=A9my=20Dufraisse?= Date: Tue, 6 Dec 2022 13:08:17 +0100 Subject: [PATCH] fix(trouble): when dispaying images --- includes/YesWiki.php | 2 +- includes/services/TemplateEngine.php | 7 ++---- tools/attach/libs/attach.lib.php | 20 ++++++++++++++++- tools/bazar/fields/FileField.php | 4 ++-- tools/templates/actions/FaviconAction.php | 27 ++++++++++++++--------- tools/templates/actions/section.php | 2 +- 6 files changed, 42 insertions(+), 20 deletions(-) diff --git a/includes/YesWiki.php b/includes/YesWiki.php index 105ab9ad1..20c29d287 100755 --- a/includes/YesWiki.php +++ b/includes/YesWiki.php @@ -407,7 +407,7 @@ public function getLocalPath($folder = '') $dataPath = $this->getDataPath(); if (in_array($folder, $dataFolders) && !empty($dataPath)) { // we add an imaginary folder in order to retrieve yeswiki assets from yeswiki's source folder. web servers need to be configured to redirect yeswiki-assets to the main yeswiki folder - $folder = "$dataPath/$folder" ; + $folder = empty($folder) ? $dataPath : "$dataPath/$folder" ; } return $folder; } diff --git a/includes/services/TemplateEngine.php b/includes/services/TemplateEngine.php index 283ae72dc..19659fb5a 100644 --- a/includes/services/TemplateEngine.php +++ b/includes/services/TemplateEngine.php @@ -172,7 +172,6 @@ public function __construct( if (!class_exists('attach')) { include('tools/attach/libs/attach.lib.php'); } - $basePath = $this->wiki->getBaseUrl().'/'; $attach = new attach($this->wiki); $image_dest = $attach->getResizedFilename($options['fileName'], $options['width'], $options['height'], $options['mode']); $safeRefresh = !$this->wiki->services->get(SecurityController::class)->isWikiHibernated() @@ -183,12 +182,10 @@ public function __construct( $result = $attach->redimensionner_image($options['fileName'], $image_dest, $options['width'], $options['height'], $options['mode']); if ($result != $image_dest) { // do nothing : error - return $basePath.$options['fileName']; + return $attach->getFileUrl($options['fileName']); } - return $basePath.$image_dest; - } else { - return $basePath.$image_dest; } + return $attach->getFileUrl($image_dest); }); $this->addTwigHelper('hasAcl', function ($acl, $tag = "", $adminCheck = true) { return $this->wiki->services->get(AclService::class)->check($acl, null, $adminCheck, $tag); diff --git a/tools/attach/libs/attach.lib.php b/tools/attach/libs/attach.lib.php index 6a47ee385..4319f8972 100644 --- a/tools/attach/libs/attach.lib.php +++ b/tools/attach/libs/attach.lib.php @@ -239,6 +239,24 @@ public function GetFullFilename($newName = false) } return $full_file_name; } + + public function getFileUrl(string $fullFileName): string + { + $uploadPath = $this->GetUploadPath(); + $cachePath = $this->GetCachePath(); + if (substr($fullFileName, 0, strlen($uploadPath)) == $uploadPath) { + return $this->wiki->getBaseUrl().'/'. + $this->attachConfig['upload_path']. + substr($fullFileName, strlen($uploadPath)); + } elseif (substr($fullFileName, 0, strlen($cachePath)) == $cachePath) { + return $this->wiki->getBaseUrl().'/'. + $this->attachConfig['cache_path']. + substr($fullFileName, strlen($cachePath)); + } else { + return $this->wiki->getBaseUrl().'/'.$fullFileName; + } + } + /** * Test si le fichier est une image */ @@ -517,7 +535,7 @@ public function showAsImage($fullFilename) $link = ''; } else { if (empty($this->nofullimagelink) or !$this->nofullimagelink) { - $link = ''; + $link = ''; } } $caption = ''; diff --git a/tools/bazar/fields/FileField.php b/tools/bazar/fields/FileField.php index a4a3714c6..3f9c68494 100644 --- a/tools/bazar/fields/FileField.php +++ b/tools/bazar/fields/FileField.php @@ -57,7 +57,7 @@ protected function renderInput($entry) : [ 'value' => $value, 'shortFileName' => $this->getShortFileName($value), - 'fileUrl' => $this->getBasePath(). $value, + 'fileUrl' => $this->getAttach()->getFileUrl($value), 'deleteUrl' => empty($entry) ? '' : $this->getWiki()->href('edit', $entry['id_fiche'], ['delete_file' => $value], false), 'isAllowedToDeleteFile' => empty($entry) ? false : $this->isAllowedToDeleteFile($entry, $value) ] @@ -110,7 +110,7 @@ protected function renderStatic($entry) return $this->render('@bazar/fields/file.twig', [ 'value' => $value, 'fileUrl' => ($shortFileName == $value) - ? $this->getWiki()->getBaseUrl().'/'.$basePath . $value + ? $this->getAttah()->getFileUrl($value) : $this->getWiki()->Href('download', $entry['id_fiche']."_".$this->getPropertyName(), ['file'=>$value], false), 'shortFileName' => $shortFileName, ]); diff --git a/tools/templates/actions/FaviconAction.php b/tools/templates/actions/FaviconAction.php index b6ed49d34..2b4fb27cf 100644 --- a/tools/templates/actions/FaviconAction.php +++ b/tools/templates/actions/FaviconAction.php @@ -7,23 +7,30 @@ class FaviconAction extends YesWikiAction public function run() { $favicon = $this->wiki->getConfigValue('favicon'); - + // backward compatibility, favicon used to be in the theme folder if (!$favicon) { - $favicon = "themes/{$this->wiki->getConfigValue('favorite_theme')}/images/favicon.png"; - if (file_exists("custom/$favicon")) $favicon = "custom/$favicon"; // handles custom theme - $favicon = $this->wiki->getBaseUrl(true).'/'.$favicon; + $favicon = "themes/{$this->wiki->getConfigValue('favorite_theme')}/images/favicon.png"; + if (file_exists("{$this->wiki->getLocalPath('custom')}/$favicon")) { + // handles local custom theme + $favicon = $this->wiki->getBaseUrl(false)."/custom/$favicon"; + } else { + if (file_exists("custom/$favicon")) { + $favicon = "custom/$favicon"; + } // handles custom theme + $favicon = $this->wiki->getBaseUrl(true).'/'.$favicon; + } } $isEmoji = strpos($favicon, '.') === false; - if ($isEmoji) - return << - HTML; - else - return << HTML; - + } } } diff --git a/tools/templates/actions/section.php b/tools/templates/actions/section.php index 1cba6f61b..50fafc671 100644 --- a/tools/templates/actions/section.php +++ b/tools/templates/actions/section.php @@ -136,7 +136,7 @@ .(!empty($bgcolor) ? 'background-color:' . $bgcolor .'; ' : '') .(!empty($height) ? 'height:' . $height . 'px; ' : '') .(!empty($pattern) ? $pattern : '') - .(isset($fullFilename) ? 'background-image:url(' . $fullFilename . ');' : '').'"' + .(isset($fullFilename) ? 'background-image:url(' . $att->getFileUrl($fullFilename) . ');' : '').'"' ; if (is_array($data)) { foreach ($data as $key => $value) {