233 lines
10 KiB
PHP
233 lines
10 KiB
PHP
<?php
|
|
require_once '../includes/config.php';
|
|
require_once '../includes/auth.php';
|
|
require_once '../includes/site-upload.php';
|
|
|
|
// Vérification de l'authentification
|
|
if (!Auth::check()) {
|
|
header('Location: login.php');
|
|
exit;
|
|
}
|
|
|
|
$success = '';
|
|
$error = '';
|
|
|
|
// Traitement du formulaire
|
|
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
|
try {
|
|
$config = Config::load();
|
|
|
|
// Mise à jour des valeurs textuelles du site
|
|
$config['site']['name'] = trim($_POST['site_name'] ?? '');
|
|
$config['site']['description'] = trim($_POST['site_description'] ?? '');
|
|
|
|
// Mise à jour des valeurs de la page À propos
|
|
$config['about']['title'] = trim($_POST['about_title'] ?? 'À propos');
|
|
$config['about']['content'] = $_POST['about_content'] ?? '';
|
|
|
|
// Traitement des liens personnalisés
|
|
$config['about']['links'] = [];
|
|
if (!empty($_POST['links'])) {
|
|
foreach ($_POST['links'] as $link) {
|
|
if (!empty($link['title']) && !empty($link['url'])) {
|
|
$config['about']['links'][] = [
|
|
'title' => trim($link['title']),
|
|
'url' => trim($link['url']),
|
|
'target' => isset($link['target']) ? '_blank' : ''
|
|
];
|
|
}
|
|
}
|
|
}
|
|
|
|
// Validation
|
|
if (empty($config['site']['name'])) {
|
|
throw new Exception('Le nom du site est requis');
|
|
}
|
|
|
|
// Gestion de l'upload du logo
|
|
if (isset($_FILES['site_logo']) && $_FILES['site_logo']['error'] !== UPLOAD_ERR_NO_FILE) {
|
|
$uploadHandler = new SiteUploadHandler();
|
|
$config['site']['logo'] = $uploadHandler->handleLogoUpload($_FILES['site_logo']);
|
|
}
|
|
|
|
// Gestion de l'upload du background de la page À propos
|
|
if (isset($_FILES['about_background']) && $_FILES['about_background']['error'] !== UPLOAD_ERR_NO_FILE) {
|
|
$uploadHandler = new SiteUploadHandler();
|
|
$config['about']['background'] = $uploadHandler->handleBackgroundUpload($_FILES['about_background']);
|
|
}
|
|
|
|
// Sauvegarde
|
|
Config::save($config);
|
|
$success = 'Configuration mise à jour avec succès';
|
|
|
|
} catch (Exception $e) {
|
|
$error = $e->getMessage();
|
|
}
|
|
}
|
|
|
|
// Chargement de la configuration actuelle
|
|
$config = Config::load();
|
|
?>
|
|
<!DOCTYPE html>
|
|
<html lang="fr">
|
|
<head>
|
|
<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">
|
|
<link href="https://cdn.quilljs.com/1.3.6/quill.snow.css" rel="stylesheet">
|
|
</head>
|
|
<body>
|
|
<nav class="admin-nav">
|
|
<div class="nav-brand">
|
|
<?php if (!empty($config['site']['logo'])): ?>
|
|
<img src="<?= htmlspecialchars('../' . $config['site']['logo']) ?>"
|
|
alt="<?= htmlspecialchars($config['site']['name']) ?>">
|
|
<?php endif; ?>
|
|
<span>Administration</span>
|
|
</div>
|
|
<div class="nav-menu">
|
|
<a href="index.php" class="button">Retour</a>
|
|
</div>
|
|
</nav>
|
|
|
|
<main class="admin-main">
|
|
<h1>Options du site</h1>
|
|
|
|
<?php if ($success): ?>
|
|
<div class="success-message"><?= htmlspecialchars($success) ?></div>
|
|
<?php endif; ?>
|
|
|
|
<?php if ($error): ?>
|
|
<div class="error-message"><?= htmlspecialchars($error) ?></div>
|
|
<?php endif; ?>
|
|
|
|
<div class="options-container">
|
|
<section class="options-section">
|
|
<h2>Options générales</h2>
|
|
<form method="POST" class="options-form" enctype="multipart/form-data">
|
|
<!-- Options du site -->
|
|
<div class="form-group">
|
|
<label for="site_name">Nom du site</label>
|
|
<input type="text"
|
|
id="site_name"
|
|
name="site_name"
|
|
value="<?= htmlspecialchars($config['site']['name']) ?>"
|
|
required>
|
|
</div>
|
|
|
|
<div class="form-group">
|
|
<label for="site_description">Description du site</label>
|
|
<textarea id="site_description"
|
|
name="site_description"
|
|
rows="4"><?= htmlspecialchars($config['site']['description']) ?></textarea>
|
|
</div>
|
|
|
|
<div class="form-group">
|
|
<label for="site_logo">Logo du site</label>
|
|
<?php if (!empty($config['site']['logo'])): ?>
|
|
<div class="current-logo">
|
|
<img src="<?= htmlspecialchars('../' . $config['site']['logo']) ?>"
|
|
alt="Logo actuel">
|
|
</div>
|
|
<?php endif; ?>
|
|
<input type="file"
|
|
id="site_logo"
|
|
name="site_logo"
|
|
accept="image/jpeg,image/png,image/gif,image/svg+xml">
|
|
<small>Formats acceptés : JPG, PNG, GIF, SVG. Taille maximum : 2MB</small>
|
|
</div>
|
|
|
|
<!-- Section À Propos -->
|
|
<h2>Page "À propos"</h2>
|
|
|
|
<div class="form-group">
|
|
<label for="about_title">Titre de la page</label>
|
|
<input type="text"
|
|
id="about_title"
|
|
name="about_title"
|
|
value="<?= htmlspecialchars($config['about']['title'] ?? 'À propos') ?>">
|
|
</div>
|
|
|
|
<div class="form-group">
|
|
<label for="about_background">Image de fond</label>
|
|
<?php if (!empty($config['about']['background'])): ?>
|
|
<div class="current-background">
|
|
<img src="<?= htmlspecialchars('../' . $config['about']['background']) ?>"
|
|
alt="Image de fond actuelle">
|
|
</div>
|
|
<?php endif; ?>
|
|
<input type="file"
|
|
id="about_background"
|
|
name="about_background"
|
|
accept="image/*">
|
|
<small>Format recommandé : 1920x250px, JPG/PNG</small>
|
|
</div>
|
|
|
|
<div class="form-group">
|
|
<label for="about_content">Contenu de la page</label>
|
|
<input type="hidden" id="about_content" name="about_content">
|
|
<div id="aboutEditor" data-initial-content="<?= htmlspecialchars($config['about']['content'] ?? '') ?>"></div>
|
|
</div>
|
|
|
|
<!-- Section Liens personnalisés -->
|
|
<h2>Liens personnalisés</h2>
|
|
<div id="customLinks" class="custom-links">
|
|
<?php
|
|
if (!empty($config['about']['links'])) {
|
|
foreach ($config['about']['links'] as $index => $link) {
|
|
?>
|
|
<div class="link-item">
|
|
<div class="form-group">
|
|
<label>Titre du lien</label>
|
|
<input type="text"
|
|
name="links[<?= $index ?>][title]"
|
|
value="<?= htmlspecialchars($link['title']) ?>"
|
|
required>
|
|
</div>
|
|
<div class="form-group">
|
|
<label>URL</label>
|
|
<input type="text"
|
|
name="links[<?= $index ?>][url]"
|
|
value="<?= htmlspecialchars($link['url']) ?>"
|
|
required>
|
|
</div>
|
|
<div class="form-group">
|
|
<label>
|
|
<input type="checkbox"
|
|
name="links[<?= $index ?>][target]"
|
|
value="_blank"
|
|
<?= (!empty($link['target']) && $link['target'] === '_blank') ? 'checked' : '' ?>>
|
|
Ouvrir dans un nouvel onglet
|
|
</label>
|
|
</div>
|
|
<button type="button" class="button delete-story">Supprimer ce lien</button>
|
|
</div>
|
|
<?php
|
|
}
|
|
}
|
|
?>
|
|
</div>
|
|
<button type="button" id="addLink" class="button">Ajouter un lien</button>
|
|
<br />
|
|
<button type="submit" class="button submit-button">Enregistrer les modifications</button>
|
|
<!-- Section Nettoyage des médias -->
|
|
<h2>Maintenance</h2>
|
|
<div class="maintenance-actions">
|
|
<button type="button" id="cleanMedia" class="button">Nettoyer les médias inutilisés</button>
|
|
<small>Supprime les images qui ne sont plus utilisées dans les romans et chapitres.</small>
|
|
</div>
|
|
</form>
|
|
</section>
|
|
</div>
|
|
</main>
|
|
|
|
<script src="https://cdn.quilljs.com/1.3.6/quill.min.js"></script>
|
|
<script src="../assets/js/options.js"></script>
|
|
<link rel="stylesheet" href="../assets/css/dialog.css">
|
|
<script src="../assets/js/dialog.js"></script>
|
|
</body>
|
|
</html>
|