correction du traitement des urls des images dans les différents contenus
This commit is contained in:
parent
31d611267a
commit
dd154c632d
@ -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">
|
||||
|
@ -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
|
||||
];
|
||||
|
@ -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) {
|
||||
|
@ -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 */
|
||||
|
@ -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');
|
||||
|
@ -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">
|
||||
|
@ -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';
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user