Skip to content

Commit

Permalink
fix(trouble): when dispaying images
Browse files Browse the repository at this point in the history
  • Loading branch information
J9rem committed Sep 15, 2023
1 parent b419f42 commit d0df6cb
Show file tree
Hide file tree
Showing 6 changed files with 42 additions and 20 deletions.
2 changes: 1 addition & 1 deletion includes/YesWiki.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
7 changes: 2 additions & 5 deletions includes/services/TemplateEngine.php
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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);
Expand Down
20 changes: 19 additions & 1 deletion tools/attach/libs/attach.lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand Down Expand Up @@ -517,7 +535,7 @@ public function showAsImage($fullFilename)
$link = '<a href="'.$this->wiki->generateLink($this->link).'"'.$classDataForLinks.'>';
} else {
if (empty($this->nofullimagelink) or !$this->nofullimagelink) {
$link = '<a href="' . $this->GetScriptPath() . $fullFilename . '"'.$classDataForLinks.'>';
$link = '<a href="' . $this->getFileUrl($fullFilename) . '"'.$classDataForLinks.'>';
}
}
$caption = '';
Expand Down
4 changes: 2 additions & 2 deletions tools/bazar/fields/FileField.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)
]
Expand Down Expand Up @@ -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,
]);
Expand Down
27 changes: 17 additions & 10 deletions tools/templates/actions/FaviconAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
if ($isEmoji) {
return <<<HTML
<link rel="icon" href="data:image/svg+xml,<svg xmlns=%22http://www.w3.org/2000/svg%22 viewBox=%220 0 100 100%22><text y=%22.9em%22 font-size=%2290%22>$favicon</text></svg>">
HTML;
else
return <<<HTML
HTML;
} else {
return <<<HTML
<link rel="icon" type="image/png" href="$favicon" />
HTML;
}
}
}
2 changes: 1 addition & 1 deletion tools/templates/actions/section.php
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit d0df6cb

Please sign in to comment.