diff --git a/admin/index.php b/admin/index.php index 375f08b..cd37725 100644 --- a/admin/index.php +++ b/admin/index.php @@ -17,6 +17,9 @@ $stories = Stories::getAll(); Administration + + + diff --git a/admin/login.php b/admin/login.php index f6c237b..8f761ed 100644 --- a/admin/login.php +++ b/admin/login.php @@ -22,6 +22,9 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') { Connexion - Administration + + + diff --git a/admin/options.php b/admin/options.php index eef396b..4c9a679 100644 --- a/admin/options.php +++ b/admin/options.php @@ -50,6 +50,9 @@ $config = Config::load(); Options du site - Administration + + + diff --git a/admin/profile.php b/admin/profile.php index 7ecd876..74fdd13 100644 --- a/admin/profile.php +++ b/admin/profile.php @@ -79,6 +79,9 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') { Modifier le profil - Administration + + + diff --git a/admin/story-edit.php b/admin/story-edit.php index 6ea130f..960707c 100644 --- a/admin/story-edit.php +++ b/admin/story-edit.php @@ -62,6 +62,9 @@ function generateSlug($title) { <?= $story ? 'Modifier' : 'Nouveau' ?> roman - Administration + + + diff --git a/includes/site-upload.php b/includes/site-upload.php index ea0624f..835bc77 100644 --- a/includes/site-upload.php +++ b/includes/site-upload.php @@ -15,31 +15,31 @@ class SiteUploadHandler { throw new Exception($this->getUploadErrorMessage($file['error'])); } - // Vérifier le type MIME $finfo = new finfo(FILEINFO_MIME_TYPE); $mimeType = $finfo->file($file['tmp_name']); if (!in_array($mimeType, $this->allowedTypes)) { throw new Exception('Type de fichier non autorisé. Types acceptés : JPG, PNG, GIF, SVG'); } - // Vérifier la taille if ($file['size'] > $this->maxFileSize) { throw new Exception('Fichier trop volumineux. Taille maximum : 2MB'); } - // Générer le nom de fichier $extension = $this->getExtensionFromMimeType($mimeType); $filename = 'logo.' . $extension; $targetPath = $this->uploadDir . $filename; - // Supprimer l'ancien logo s'il existe $this->removeOldLogo(); - // Déplacer le fichier if (!move_uploaded_file($file['tmp_name'], $targetPath)) { throw new Exception('Erreur lors du déplacement du fichier uploadé'); } + // Créer le favicon si ce n'est pas un SVG + if ($mimeType !== 'image/svg+xml') { + $this->createFavicon($targetPath, $mimeType); + } + return 'assets/images/site/' . $filename; } catch (Exception $e) { @@ -59,6 +59,63 @@ class SiteUploadHandler { foreach (glob($this->uploadDir . 'logo.*') as $file) { unlink($file); } + $faviconPath = $this->uploadDir . 'favicon.png'; + if (file_exists($faviconPath)) { + unlink($faviconPath); + } + } + + private function createFavicon($sourcePath, $mimeType) { + try { + $source = $this->createImageFromFile($sourcePath, $mimeType); + if (!$source) { + throw new Exception('Impossible de créer l\'image source pour le favicon'); + } + + $favicon = imagecreatetruecolor(32, 32); + if (!$favicon) { + imagedestroy($source); + throw new Exception('Impossible de créer l\'image de destination pour le favicon'); + } + + imagealphablending($favicon, false); + imagesavealpha($favicon, true); + + if (!imagecopyresampled( + $favicon, $source, + 0, 0, 0, 0, + 32, 32, + imagesx($source), imagesy($source) + )) { + imagedestroy($source); + imagedestroy($favicon); + throw new Exception('Erreur lors du redimensionnement du favicon'); + } + + $faviconPath = $this->uploadDir . 'favicon.png'; + if (!imagepng($favicon, $faviconPath, 9)) { + throw new Exception('Impossible de sauvegarder le favicon'); + } + + imagedestroy($source); + imagedestroy($favicon); + + } catch (Exception $e) { + error_log('Erreur lors de la création du favicon : ' . $e->getMessage()); + } + } + + private function createImageFromFile($file, $mimeType) { + switch ($mimeType) { + case 'image/jpeg': + return imagecreatefromjpeg($file); + case 'image/png': + return imagecreatefrompng($file); + case 'image/gif': + return imagecreatefromgif($file); + default: + throw new Exception('Type d\'image non supporté pour le favicon'); + } } private function getExtensionFromMimeType($mimeType) { diff --git a/index.php b/index.php index bea6db3..73f35c4 100644 --- a/index.php +++ b/index.php @@ -11,6 +11,9 @@ $stories = Stories::getAll(); <?= htmlspecialchars($config['site']['name']) ?> + + +