correction du traitement des urls des images dans les différents contenus

This commit is contained in:
Esenjin 2025-02-17 21:18:17 +01:00
parent 31d611267a
commit dd154c632d
8 changed files with 30 additions and 9 deletions

View File

@ -39,7 +39,7 @@ $siteStats = $stats->getStats();
<!-- Contenu principal -->
<div class="about-content">
<div class="about-description">
<?= $about['content'] // Le contenu est déjà en HTML ?>
<?= $about['content'] = Config::fixImagePaths($about['content']); ?>
</div>
<aside class="sidebar">

View File

@ -82,7 +82,7 @@ class AboutImageUploadHandler {
// Retourner le chemin relatif pour l'éditeur
return [
'success' => true,
'url' => '../assets/images/about/' . $filename,
'url' => 'assets/images/about/' . $filename,
'width' => $needsResize ? $newWidth : $width,
'height' => $needsResize ? $newHeight : $height
];

View File

@ -81,9 +81,12 @@ class ImageUploadHandler {
}
// Retourner le chemin relatif pour l'éditeur
$relativePath = $this->getRelativePath($targetPath);
$adminPreviewPath = '../' . $relativePath;
return [
'success' => true,
'url' => $this->getRelativePath($targetPath),
'url' => $adminPreviewPath,
'storage_url' => $relativePath,
'width' => $needsResize ? $newWidth : $width,
'height' => $needsResize ? $newHeight : $height
];
@ -149,9 +152,7 @@ class ImageUploadHandler {
}
private function getRelativePath($absolutePath) {
$relativePath = str_replace(__DIR__ . '/../../', '', $absolutePath);
// Ajout de '../' car on est dans admin/api/
return '../' . str_replace('\\', '/', $relativePath); // Pour la compatibilité Windows
return str_replace(__DIR__ . '/../../', '', $absolutePath);
}
private function getUploadErrorMessage($error) {

View File

@ -537,6 +537,15 @@ body {
padding: var(--spacing-lg);
border-radius: var(--radius-md);
border: 1px solid var(--border-color);
overflow: hidden;
}
.about-description img {
max-width: 100%;
height: auto;
display: block;
margin: var(--spacing-md) 0;
border-radius: var(--radius-sm);
}
/* Sidebar */

View File

@ -1,6 +1,7 @@
document.addEventListener('DOMContentLoaded', function() {
const urlParams = new URLSearchParams(window.location.search);
const storyId = document.querySelector('input[name="id"]')?.value || urlParams.get('id');
let currentChapterId = null;
const storyId = document.querySelector('input[name="id"]')?.value;
// Fonction de notification
function showNotification(message, type = 'success') {
@ -96,6 +97,12 @@ document.addEventListener('DOMContentLoaded', function() {
if (result.success) {
const range = quill.getSelection(true);
quill.insertEmbed(range.index, 'image', result.url);
const insertOp = quill.getContents().ops.find(op =>
op.insert && op.insert.image === result.url
);
if (insertOp) {
insertOp.insert.image = result.storage_url;
}
quill.setSelection(range.index + 1);
} else {
showNotification(result.error || 'Erreur lors de l\'upload', 'error');

View File

@ -68,7 +68,7 @@ $config = Config::load();
<!-- Contenu principal -->
<div class="novel-content">
<div class="novel-description chapter-content">
<?= $currentChapter['content'] ?>
<?= $currentChapter['content'] = Config::fixImagePaths($currentChapter['content']); ?>
<!-- Navigation entre chapitres -->
<div class="chapter-navigation">

View File

@ -31,6 +31,10 @@ class Config {
return $config[$key] ?? $default;
}
public static function fixImagePaths($content) {
return preg_replace('/(src|url)=(["\'])\.\.\//i', '$1=$2', $content);
}
public static function save($newConfig) {
$configFile = __DIR__ . '/../config.json';

View File

@ -46,7 +46,7 @@ $config = Config::load();
<!-- Contenu principal -->
<div class="novel-content">
<div class="novel-description">
<?= $story['description'] ?>
<?= $story['description'] = Config::fixImagePaths($story['description']); ?>
</div>
<aside class="chapters-menu">