ajout d'un favicon
This commit is contained in:
parent
e13139cb13
commit
a6869a20e8
@ -17,6 +17,9 @@ $stories = Stories::getAll();
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>Administration</title>
|
||||
<?php if (file_exists(__DIR__ . '/../assets/images/site/favicon.png')): ?>
|
||||
<link rel="icon" type="image/png" href="../assets/images/site/favicon.png">
|
||||
<?php endif; ?>
|
||||
<link rel="stylesheet" href="../assets/css/main.css">
|
||||
</head>
|
||||
<body>
|
||||
|
@ -22,6 +22,9 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>Connexion - Administration</title>
|
||||
<?php if (file_exists(__DIR__ . '/../assets/images/site/favicon.png')): ?>
|
||||
<link rel="icon" type="image/png" href="../assets/images/site/favicon.png">
|
||||
<?php endif; ?>
|
||||
<link rel="stylesheet" href="../assets/css/main.css">
|
||||
</head>
|
||||
<body class="login-page">
|
||||
|
@ -50,6 +50,9 @@ $config = Config::load();
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>Options du site - Administration</title>
|
||||
<?php if (file_exists(__DIR__ . '/../assets/images/site/favicon.png')): ?>
|
||||
<link rel="icon" type="image/png" href="../assets/images/site/favicon.png">
|
||||
<?php endif; ?>
|
||||
<link rel="stylesheet" href="../assets/css/main.css">
|
||||
</head>
|
||||
<body>
|
||||
|
@ -79,6 +79,9 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>Modifier le profil - Administration</title>
|
||||
<?php if (file_exists(__DIR__ . '/../assets/images/site/favicon.png')): ?>
|
||||
<link rel="icon" type="image/png" href="../assets/images/site/favicon.png">
|
||||
<?php endif; ?>
|
||||
<link rel="stylesheet" href="../assets/css/main.css">
|
||||
</head>
|
||||
<body>
|
||||
|
@ -62,6 +62,9 @@ function generateSlug($title) {
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title><?= $story ? 'Modifier' : 'Nouveau' ?> roman - Administration</title>
|
||||
<?php if (file_exists(__DIR__ . '/../assets/images/site/favicon.png')): ?>
|
||||
<link rel="icon" type="image/png" href="../assets/images/site/favicon.png">
|
||||
<?php endif; ?>
|
||||
<link rel="stylesheet" href="../assets/css/main.css">
|
||||
<link href="https://cdn.quilljs.com/1.3.6/quill.snow.css" rel="stylesheet">
|
||||
</head>
|
||||
|
@ -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) {
|
||||
|
@ -11,6 +11,9 @@ $stories = Stories::getAll();
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title><?= htmlspecialchars($config['site']['name']) ?></title>
|
||||
<?php if (file_exists(__DIR__ . '/assets/images/site/favicon.png')): ?>
|
||||
<link rel="icon" type="image/png" href="assets/images/site/favicon.png">
|
||||
<?php endif; ?>
|
||||
<link rel="stylesheet" href="assets/css/style.css">
|
||||
</head>
|
||||
<body>
|
||||
|
Loading…
x
Reference in New Issue
Block a user