Compare commits
72 Commits
8be56bc27f
..
dev
| Author | SHA1 | Date | |
|---|---|---|---|
| d729e943a3 | |||
| 868e68fa85 | |||
| ed3f8062da | |||
| c2035314fb | |||
| c140ba4069 | |||
| 84d4b12fb2 | |||
| c979238b0c | |||
| e03594c22e | |||
| 298f18dabe | |||
| fabe5a9f53 | |||
| 430b7ddd6f | |||
| e2d218f364 | |||
| ca6cfa4ebf | |||
| 3b22be94e8 | |||
| 5ce91da06a | |||
| 11399a54a6 | |||
| 51055b7321 | |||
| dc4701d667 | |||
| ae4ac11305 | |||
| 347e4be0b7 | |||
| c17cad9c66 | |||
| 88cc67d945 | |||
| 6092cf940d | |||
| 5b16fb465b | |||
| 996ab3e508 | |||
| 8af2c8e20b | |||
| 04a7713286 | |||
| 3ddfc1dcf3 | |||
| fa00f61ee0 | |||
| 8889110133 | |||
| 3e856dc476 | |||
| 58a110d5b9 | |||
| 5e88d44129 | |||
| a55e22f1f4 | |||
| 5cea473d17 | |||
| 1d05138329 | |||
| ee2b8a4ac7 | |||
| 556c2cfea9 | |||
| e19d20ca17 | |||
| d0b486f11c | |||
| 18b7194069 | |||
| 21f6e75878 | |||
| 2a60790006 | |||
| 3647289f86 | |||
| ea950f2c25 | |||
| af0a0bb9d5 | |||
| 797937340a | |||
| d5bba5e6e5 | |||
| 53dbce5bb0 | |||
| 4e262ddde8 | |||
| 7737edf402 | |||
| 6d159e7dda | |||
| ebf0e2df65 | |||
| 331e9c9ecd | |||
| 0280ef3ca1 | |||
| eddde2165a | |||
| 07d004b3f0 | |||
| 5cb0e854fd | |||
| 8f6c17f0f2 | |||
| 5452fb4927 | |||
| de8785d088 | |||
| 4b5943c0a4 | |||
| a552f105cd | |||
| 16afec3039 | |||
| 2d2148079d | |||
| 3965be6854 | |||
| e803d2d0a7 | |||
| 9069a64a0c | |||
| 819d6d1b8f | |||
| 16965ee8cb | |||
| 55a2120be1 | |||
| 5828aac4f5 |
@@ -6,6 +6,7 @@
|
||||
APP_URL=https://example.com
|
||||
APP_ENV=prod
|
||||
APP_DEBUG=0
|
||||
APP_TIMEZONE=Europe/Paris
|
||||
|
||||
# Authentification admin (email de l'administrateur principal)
|
||||
ADMIN_EMAIL=
|
||||
@@ -40,6 +41,25 @@ SMTP_FROM_NAME=
|
||||
CONTACT_EMAIL=
|
||||
CONTACT_FROM_EMAIL=
|
||||
|
||||
# Dépôt Folio pour le vérificateur de mises à jour (UpdateChecker)
|
||||
# URL de base du dépôt Gitea (sans slash final)
|
||||
FOLIO_REPO_URL=https://git.abonnel.fr/cedricAbonnel/folio
|
||||
# Branche suivie pour les mises à jour (défaut : main)
|
||||
# FOLIO_UPDATE_BRANCH=main
|
||||
|
||||
# Chemin absolu vers le répertoire des articles (data/)
|
||||
# Par défaut : BASE_PATH/data (dans le répertoire de l'application)
|
||||
# Recommandé en production : chemin hors du répertoire web, ex. /srv/data/folio
|
||||
DATA_PATH=/srv/data/folio
|
||||
|
||||
# Logs Apache (onglet Recherches dans /admin)
|
||||
# Nom du fichier de log d'accès du vhost dans /var/log/apache2/
|
||||
APACHE_ACCESS_LOG=lan.acegrp.varlog-access.log
|
||||
|
||||
# IA — analyse critique et réécriture d'articles dans l'éditeur
|
||||
# Provider : anthropic (API) ou claude_code (CLI local)
|
||||
# AI_PROVIDER=anthropic
|
||||
# Clé API Anthropic (obtenir sur https://console.anthropic.com/)
|
||||
ANTHROPIC_API_KEY=
|
||||
# Modèle à utiliser (défaut : claude-haiku-4-5-20251001) — ignoré si provider=claude_code
|
||||
# AI_MODEL=claude-haiku-4-5-20251001
|
||||
|
||||
@@ -11,5 +11,4 @@ Thumbs.db
|
||||
# Données des sites (articles, config, cache) — propres à chaque workspace
|
||||
data/*
|
||||
!data/.gitkeep
|
||||
!data/site/
|
||||
_cache/
|
||||
|
||||
+321
@@ -5,10 +5,331 @@ Format : [Keep a Changelog](https://keepachangelog.com/fr/1.0.0/) — versionnag
|
||||
|
||||
---
|
||||
|
||||
## [1.6.27] - 2026-05-19
|
||||
|
||||
### Ajouté
|
||||
- Admin stats : sparklines SVG 14 jours par page dans « Pages les plus visitées » — courbe + dégradé, carte pleine largeur (#101)
|
||||
|
||||
### Corrigé
|
||||
- Admin stats : IPs privées/LAN exclues de la répartition par réseau (Uptime Kuma et hairpin NAT ne polluent plus les stats) (#102)
|
||||
|
||||
---
|
||||
|
||||
## [1.6.26] - 2026-05-16
|
||||
|
||||
### Ajouté
|
||||
- Page publique `/books` — catalogue de tous les livres avec ≥ 1 article publié, cards cover/titre/description/nombre de pages (#99)
|
||||
- Accueil : section « Livres » (max 6) après les redécouvertes avec lien « Voir tous → /books » (#100)
|
||||
|
||||
---
|
||||
|
||||
## [1.6.25] - 2026-05-16
|
||||
|
||||
### Ajouté
|
||||
- Admin : onglet « IA » — statut provider/clé, sélecteur `anthropic`/`claude_code`, champ modèle, procédure d'installation CLI, sauvegarde dans `site_settings.json` (#97)
|
||||
- `AiService` : support du provider Claude Code CLI via `proc_open` + lecture provider/modèle depuis `SiteSettings` (#97)
|
||||
- Éditeur : bouton IA unique « Analyser et proposer » — un seul appel retourne l'analyse critique et la réécriture via séparateur `===CRITIQUE===/===REWRITE===` (#96)
|
||||
|
||||
### Corrigé
|
||||
- Éditeur IA : boutons placés dans `wizard/step1.php` (la vraie page d'édition) ; `ai-editor.js` adapté pour `#wz-content` et extraction du titre depuis le Markdown (#96)
|
||||
- Sécurité CSP : extraction du `<script>` inline de `comments_section.php` vers `comments.js` (#95)
|
||||
- Sécurité CSP : remplacement du `onclick` inline dans `wizard/step6.php` par `data-confirm-discard` + listener dans `admin.js` (#95)
|
||||
- Sécurité CSP : remplacement du `oninput` inline dans `post_confirm.php` par un `addEventListener` dans `post_confirm.js` (#95)
|
||||
|
||||
---
|
||||
|
||||
## [1.6.24] - 2026-05-16
|
||||
|
||||
### Ajouté
|
||||
- Éditeur : intégration IA — service `AiService`, route `ai_query`, script `ai-editor.js`, clé `ANTHROPIC_API_KEY` dans `.env` (#96)
|
||||
|
||||
---
|
||||
|
||||
## [1.6.23] - 2026-05-16
|
||||
|
||||
### Ajouté
|
||||
- Section « Historique » dans la sidebar des articles (connectés) : liste des révisions avec lien vers le diff (#82)
|
||||
|
||||
---
|
||||
|
||||
## [1.6.22] - 2026-05-16
|
||||
|
||||
### Ajouté
|
||||
- Widget de notation ★ (1-5 étoiles) sur les articles, accessible aux utilisateurs connectés ; affiche la moyenne et le nombre de votes pour tous (#13)
|
||||
- Admin `flux` : onglet listant tous les flux RSS agrégés avec action de suppression admin (#87)
|
||||
|
||||
---
|
||||
|
||||
## [1.6.21] - 2026-05-16
|
||||
|
||||
### Ajouté
|
||||
- Feed RSS : balise `<media:thumbnail>` avec l'image de couverture de l'article (namespace `media:`) (#90)
|
||||
- Admin livres : slug généré automatiquement depuis le titre à la création (#89)
|
||||
- Admin livres : champ de filtre texte en temps réel sur le sélecteur « Ajouter une page » (#89)
|
||||
|
||||
### Corrigé
|
||||
- `autoSeoDesc` : décodage des entités HTML (`&`, ` `…) + suppression du titre en tête de description (#91)
|
||||
- `post_confirm.js` : guard null sur `#confirm-slug` absent (étape 5 du wizard) — plus d'erreur JS (#91)
|
||||
|
||||
---
|
||||
|
||||
## [1.6.20] - 2026-05-16
|
||||
|
||||
### Ajouté
|
||||
- Barre de partage sur les articles publiés : mail, X, LinkedIn, Mastodon, copie de lien, Web Share API mobile (#47)
|
||||
- Déduplication des images uploadées par hardlink si même hash+taille existe déjà dans un autre article (#35)
|
||||
|
||||
---
|
||||
|
||||
## [1.6.19] - 2026-05-16
|
||||
|
||||
### Ajouté
|
||||
- `admin/articles` : clic sur la ligne entière pour cocher/décocher la case de sélection bulk (#86)
|
||||
- Cache HTTP `Last-Modified` + réponse `304 Not Modified` pour les articles publiés (#18)
|
||||
- Fingerprinting des assets CSS/JS dans `layout.php` (`?v=<hash>`) pour invalidation automatique du cache navigateur (#18)
|
||||
- Cache fichier `_cache/articles_list.json` pour `getAll()` — invalidé à chaque écriture, élimine le scan complet par requête (#16)
|
||||
- Logging des 404 dans `DATA_PATH/_logs/not_found.json` (url, referer, user-agent, date) (#52)
|
||||
|
||||
### Corrigé
|
||||
- `case 'view'` : les accès refusés (brouillon, avant-première, catégorie privée) utilisent désormais `templates/404.php` au lieu d'un `echo` nu (#52)
|
||||
|
||||
---
|
||||
|
||||
## [1.6.18] - 2026-05-16
|
||||
|
||||
### Ajouté
|
||||
- Lien magique : page de confirmation GET avant consommation POST — protège contre les scanners email (#27)
|
||||
- Lien magique : notification email à l'auteur de l'article lors de la vérification d'un commentaire (#44)
|
||||
- Lien magique : rate limit par IP (`MAGIC_MAX_PER_IP_HOUR`, défaut 10/h) en plus du rate limit par email (#23)
|
||||
- `ArticleManager::duplicate()` + route `/duplicate/{uuid}` + bouton ⧉ dans `admin/articles` (#7)
|
||||
- Cache du rendu Markdown par article (`_cache/content_rendered.json`, invalidé sur `mtime` de `index.md`) (#17)
|
||||
- Lazy loading (`loading="lazy"`) sur toutes les images du contenu Markdown (#21)
|
||||
|
||||
---
|
||||
|
||||
## [1.6.17] - 2026-05-16
|
||||
|
||||
### Ajouté
|
||||
- RSS : élément `<content:encoded>` avec HTML complet par article + namespace `content` (#42)
|
||||
- RSS : filtre `?category=nom` — flux filtré par catégorie, titre et description du channel adaptés (#43)
|
||||
- Commentaires : cookie `cmt_name` / `cmt_email` (1 an) pour pré-remplir le formulaire à la prochaine visite (#51)
|
||||
- `flux/` : bandeau d'alerte admin listant les feeds en erreur (URL, label, email) (#45)
|
||||
- `admin/emails` : bouton « Voir ↗ » ouvre le contenu HTML de l'email dans un nouvel onglet via `/admin/email-preview/{id}` (#37)
|
||||
|
||||
### Modifié
|
||||
- RSS : `<description>` utilise désormais le champ `plain` pré-calculé (fix : contenu vide depuis v1.6.14) (#42)
|
||||
|
||||
---
|
||||
|
||||
## [1.6.16] - 2026-05-16
|
||||
|
||||
### Ajouté
|
||||
- `SearchLogParser` : paramètre `$days` (7 ou 14) — cache distinct par période, filtre logFiles par date (#46)
|
||||
- `admin/searches` : boutons 7 j / 14 j pour choisir la fenêtre d'analyse (#46)
|
||||
|
||||
### Modifié
|
||||
- `SearchLogParser` : tri par visiteurs uniques (IPs distinctes) au lieu de hits bruts — colonne renommée « Visiteurs » (#41)
|
||||
- URL inconnue / article introuvable : redirection 302 vers `/search?q=…` au lieu de page 404 (#57)
|
||||
- `edit_tags` : sections « Abréviations » et « Noms composés » masquées si des valeurs connues existent pour le type (#48)
|
||||
|
||||
---
|
||||
|
||||
## [1.6.15] - 2026-05-16
|
||||
|
||||
### Ajouté
|
||||
- `admin/articles` : champ de recherche par titre (`filter_search`), cumulable avec les autres filtres (#85)
|
||||
- `admin/articles` : colonne « ★ À la une » avec toggle rapide par ligne et filtre `filter_featured` (#84)
|
||||
- `post/` : date de modification affichée sous la date de publication si l'article a été modifié après sa mise en ligne (#81)
|
||||
|
||||
### Modifié
|
||||
- `sources/` : bouton « ← Modifier » remplacé par « ← Retour à l'article » pointant vers `post/<slug>` (#83)
|
||||
|
||||
---
|
||||
|
||||
## [1.6.14] - 2026-05-15
|
||||
|
||||
### Modifié
|
||||
- Perf : `getAll()` ne charge plus le contenu Markdown — `loadArticle()` reçoit `$withContent = false` dans `loadAll()`, seul `getByUuid()` lit encore `index.md` (#24)
|
||||
- Perf : `search_index.json` enrichi du champ `featured` ; `rebuildSearchIndex()` lit `index.md` directement (indépendant du cache article)
|
||||
- Perf : excerpts dans `post_list`, `author_articles`, `author_profile` proviennent du champ `plain` pré-calculé — plus de passage par Parsedown (#24)
|
||||
|
||||
---
|
||||
|
||||
## [1.6.13] - 2026-05-15
|
||||
|
||||
### Ajouté
|
||||
- Typographie : guillemets droits convertis en guillemets courbes (`"` → `"` / `"`, `'` → `'` / `'`) dans le rendu des articles — blocs `<code>` et `<pre>` préservés (#15)
|
||||
|
||||
### Corrigé
|
||||
- Suppression du dead code : `AuthService`, `UserRepository` et `Domain\User` — incompatibles avec le système de session actuel, aucune référence active (#19)
|
||||
- Factorisation des helpers `env()` et `db()` dans `src/helpers.php`, chargé par `config/config.php` — plus de triple définition dans les pages login/OIDC (#22)
|
||||
|
||||
---
|
||||
|
||||
## [1.6.12] - 2026-05-15
|
||||
|
||||
### Ajouté
|
||||
- Wizard édition — étape SEO : sélecteur d'**image de couverture** (og:image) désormais affiché en mode édition (était limité à la création) — sélection parmi les fichiers images existants, appliquée immédiatement via `setCover()` et mémorisée dans le draft overlay
|
||||
|
||||
---
|
||||
|
||||
## [1.6.11] - 2026-05-15
|
||||
|
||||
### Corrigé
|
||||
- En mode édition, le slug de l'article n'est plus jamais modifié : suppression du `hidden[slug]` dans l'étape 6 de confirmation et du bloc qui le propagait dans le draft overlay
|
||||
|
||||
---
|
||||
|
||||
## [1.6.10] - 2026-05-15
|
||||
|
||||
### Corrigé
|
||||
- Suppression d'article échouait silencieusement quand le répertoire UUID appartenait à un autre utilisateur que `www-data` (permissions `2755` → groupe sans écriture) — `removeDir()` échouait sans erreur visible et l'article restait accessible
|
||||
- `ArticleManager::delete()` retourne maintenant `bool` : si le répertoire existe encore après tentative de suppression, les index ne sont pas reconstruits et l'utilisateur est redirigé vers l'article avec un message d'erreur
|
||||
- `removeDir()` : erreurs PHP supprimées silencieusement (`@unlink`, `@rmdir`, `@scandir`) pour éviter les warnings qui cassaient les redirects
|
||||
- `mkArticleDir()` : nouvelle méthode privée qui crée les répertoires d'articles avec `chmod 0775` explicite (contourne le umask), garantissant que `www-data` (groupe) a toujours les droits d'écriture
|
||||
|
||||
---
|
||||
|
||||
## [Unreleased]
|
||||
|
||||
---
|
||||
|
||||
## [1.6.9] - 2026-05-15
|
||||
|
||||
### Ajouté
|
||||
- `/admin/articles` : tri par **Titre** (A→Z / Z→A) et par **Date** (publication) en cliquant les en-têtes de colonne — indicateur ↑ / ↓ sur la colonne active, paramètres `sort` et `dir` préservés lors du filtrage
|
||||
|
||||
---
|
||||
|
||||
## [1.6.8] - 2026-05-15
|
||||
|
||||
### Corrigé
|
||||
- Tous les scripts inline déplacés vers des fichiers JS statiques (`density-fouc.js`, `density.js`, `trending-home.js`, `admin-stats.js`) — conformité CSP `script-src 'self'` (varlog)
|
||||
- `onclick` / `onchange` inline dans `admin.php` migrés vers `admin.js`
|
||||
- Densité M (980 px) définie comme valeur par défaut au lieu de L (pleine largeur)
|
||||
|
||||
---
|
||||
|
||||
## [1.6.7] - 2026-05-15
|
||||
|
||||
### Ajouté
|
||||
- Sélecteur de densité L / M / S sur la page liste : pleine largeur (défaut), normal (980 px), compact (660 px) — préférence persistée dans `localStorage`
|
||||
|
||||
---
|
||||
|
||||
## [1.6.6] - 2026-05-15
|
||||
|
||||
### Modifié
|
||||
- Page d'accueil "Meilleures audiences" : chargement AJAX depuis le flux RSS XML `/trending?period=1h` (DOMParser côté client, plus de rendu PHP)
|
||||
- `/admin/stats` section "Pages les plus visitées" : chargement AJAX depuis le flux RSS XML `/trending?period=14d` — plus de parsing de logs direct pour cette colonne
|
||||
- `/admin/stats` : suppression de `topGrouped` pour les pages ; seuls les livres (`/book/`) et l'ASN conservent le parsing log côté serveur
|
||||
|
||||
---
|
||||
|
||||
## [1.6.5] - 2026-05-15
|
||||
|
||||
### Modifié
|
||||
- `/tendances` et page d'accueil (rubrique "Meilleures audiences") : lecture seule du cache généré par `/trending?period=…` — plus aucun parsing de logs en dehors du flux RSS
|
||||
- Rubrique renommée "Meilleures audiences · 1 heure" (ex "Tendances · 10 derniers jours")
|
||||
|
||||
---
|
||||
|
||||
## [1.6.4] - 2026-05-15
|
||||
|
||||
### Ajouté
|
||||
- `src/TrendingParser.php` : parseur de logs Apache comptant les visiteurs uniques (IPs distinctes, HTTP 200) par article, avec support multi-préfixes et méthode `topGrouped()` (un seul parse pour pages + livres)
|
||||
- `public/trending.php` : flux RSS des 50 articles les plus consultés, paramétrable par période (`?period=10m|20m|30m|1h|8h|1d|7d|14d|30d|1y`), cache TTL adaptatif
|
||||
- `public/tendances.php` : page publique présentant les tendances par période, les flux RSS disponibles et la méthodologie
|
||||
- Route `/tendances` dans `.htaccess`
|
||||
|
||||
### Modifié
|
||||
- `/admin/stats` : utilise `TrendingParser` (visiteurs uniques) au lieu d'`AccessLogParser` (hits bruts) pour les pages et les livres ; label mis à jour
|
||||
- Page d'accueil — rubrique Tendances : source principale désormais les logs Apache sur 1 heure (cache 12 min), fallback sur le score pondéré DB si les logs ne sont pas lisibles
|
||||
|
||||
---
|
||||
|
||||
## [1.6.3] - 2026-05-15
|
||||
|
||||
### Ajouté
|
||||
- `scripts/server/folio-upgrade.sh` : script de déploiement serveur (clone fresh, permissions, composer, migrations SQL, `.sessions`, `safe.directory`) appelé par `sudo` depuis le bouton admin "Mettre à jour"
|
||||
- `UpdateChecker::getLastUpgradeLog()` : affiche le journal de la dernière mise à jour dans l'admin (`<details>`)
|
||||
|
||||
### Modifié
|
||||
- `run_engine_update` : délègue entièrement le déploiement au script `sudo /usr/local/bin/folio-upgrade.sh` — supprime le `git pull` inline qui ne fonctionnait pas avec les contraintes de permissions root
|
||||
- `run_content_migrations` ajouté aux actions `noindex`
|
||||
- Stats admin (`/admin/stats`) : cache 60 s dans `DATA_PATH/.stats_cache.json` pour le parsing des logs Apache et le lookup ASN
|
||||
|
||||
---
|
||||
|
||||
## [1.6.2] - 2026-05-15
|
||||
|
||||
### Corrigé
|
||||
- `oidc/start.php` : garde explicite après `session_start()` — erreur 500 immédiate si `session.save_path` est inaccessible, évite un flux OIDC condamné à l'échec silencieux
|
||||
- `oidc/callback.php` : même garde de session ; `error_log` en cas d'échec du contrôle de state pour faciliter le diagnostic
|
||||
- `consignes.md` : règle ajoutée — pool PHP-FPM avec `user = www-data`, pas le compte admin personnel
|
||||
|
||||
---
|
||||
|
||||
## [1.6.1] - 2026-05-15
|
||||
|
||||
### Corrigé
|
||||
- `login/index.php`, `login/magic.php`, `logout.php` : ordre de chargement corrigé (`config.php` avant `bootstrap.php`) pour que `SESSION_NAME` soit défini avant `session_start()`
|
||||
- `data/site/` retiré du suivi git du moteur (contenu site-spécifique) ; `.gitignore` mis à jour
|
||||
|
||||
---
|
||||
|
||||
## [1.6.0] - 2026-05-15
|
||||
|
||||
### Ajouté
|
||||
- Admin → Dashboard : bouton unique **Mettre à jour** (git pull + migrations SQL + migrations contenu) remplace les boutons séparés
|
||||
- Branche `dev` : branche d'intégration permanente pour le développement quotidien
|
||||
|
||||
### Corrigé
|
||||
- `run_engine_update` : vérifie que le remote git `origin` correspond à `FOLIO_REPO_URL` avant tout `git pull` (évite le pull sur le mauvais dépôt)
|
||||
|
||||
---
|
||||
|
||||
## [1.5.0] - 2026-05-15
|
||||
|
||||
### Ajouté
|
||||
- Admin → Site : configuration de l'URL du dépôt Folio et de la branche suivie pour les mises à jour, sans modifier le `.env` (`folio_repo_url`, `folio_update_branch` dans `site_settings.json`)
|
||||
- `APP_TIMEZONE` : fuseau horaire configurable via `.env` (défaut `Europe/Paris`), appliqué globalement dans `bootstrap.php`
|
||||
|
||||
### Corrigé
|
||||
- Bouton « Vérifier » masqué avec message explicatif si `FOLIO_REPO_URL` n'est pas configuré (ni dans `.env` ni dans l'admin)
|
||||
- `FOLIO_REPO_URL` et `FOLIO_UPDATE_BRANCH` documentés dans `.env.example`
|
||||
- `scripts/push.sh` : ne pousse plus directement sur `main` — pousse sur la branche courante pour forcer le passage par une PR
|
||||
|
||||
---
|
||||
|
||||
## [1.4.0] - 2026-05-15
|
||||
|
||||
### Ajouté
|
||||
- **`DATA_PATH`** : chemin des articles configurable via `.env`, indépendant du document root — permet de stocker `/data` hors de l'arborescence web (ex. `/srv/data/folio`)
|
||||
- **`DataGit`** : auto-commit git sur toutes les écritures articles et livres (création, modification, suppression, métadonnées, tags, fichiers, liens…) sauf `autosave` — no-op silencieux si `DATA_PATH` n'est pas un dépôt git
|
||||
- **Admin — Moteur Folio** : affiche la branche suivie pour les mises à jour (`FOLIO_UPDATE_BRANCH`, défaut `main`), la date du dernier contrôle, et un bouton **Vérifier** pour forcer la vérification sans attendre le TTL du cache (1 h)
|
||||
|
||||
### Modifié
|
||||
- `UpdateChecker` : branche cible configurable via `FOLIO_UPDATE_BRANCH` (plus de `main` hardcodé dans l'URL Gitea)
|
||||
|
||||
---
|
||||
|
||||
## [1.3.0] - 2026-05-15
|
||||
|
||||
### Ajouté
|
||||
- Onglet **Statistiques** dans l'admin : pages les plus visitées, livres consultés, répartition par AS (#64)
|
||||
- `AccessLogParser` : lecture des logs Apache (plain, `.gz`, `.tar.gz`), cache 10 min
|
||||
- `AsnLookup` : résolution ASN via ip-api.com (batch, cache 30 j), détection LAN automatique
|
||||
- Filtrage des AS par groupes configurables (motifs case-insensitive, formulaire admin)
|
||||
- Pattern de log configurable via l'UI (onglet Recherches) avec support glob
|
||||
|
||||
### Corrigé
|
||||
- Permissions rsync : `--chmod=Fug+rw,Fo-w` assure la lisibilité groupe sur les fichiers déployés
|
||||
- `saveSiteSettings()` et `saveSmtpSettings()` : retournent un `bool` et affichent une erreur si l'écriture échoue
|
||||
- `scripts/setup.sh` : script d'initialisation Folio (composer, répertoires, droits, migrations, groupe `adm`)
|
||||
|
||||
---
|
||||
|
||||
## [1.2.2] - 2026-05-14
|
||||
|
||||
### Corrigé
|
||||
|
||||
@@ -0,0 +1,86 @@
|
||||
# CLAUDE.md
|
||||
|
||||
## Ce qu'est ce dépôt
|
||||
|
||||
**Folio** est un moteur de blog PHP.
|
||||
Ce répertoire est la **copie locale du dépôt Git** (`https://git.abonnel.fr/cedricAbonnel/folio`), branche DEV.
|
||||
Il contient uniquement le code du moteur — pas de données, pas de credentials.
|
||||
|
||||
## Architecture
|
||||
|
||||
| Répertoire local | Site distant | Rôle |
|
||||
|-----------------|-------------|------|
|
||||
| `~/Projects/folio/` | — | Copie du dépôt Folio (branche DEV). On code ici. |
|
||||
| `~/Projects/varlog/` | varlog.a5l.fr | Workspace varlog (scripts de déploiement/sync). Sert de site de test pour le moteur. |
|
||||
| `~/Projects/varlog-data/` | varlog.a5l.fr | Articles de varlog. Sync bidirectionnelle. |
|
||||
| `~/Projects/fr.abonnel.www/` | www.abonnel.fr | Workspace abonnel.fr (scripts de déploiement/sync). |
|
||||
| `~/Projects/fr.abonnel.www-data/` | www.abonnel.fr | Articles de abonnel.fr. Sync bidirectionnelle. |
|
||||
|
||||
**abonnel.fr** utilise Folio mais se met à jour seul via son UpdateChecker interne (vérifie `version.txt` sur Gitea). Aucune action manuelle nécessaire côté serveur.
|
||||
|
||||
## Articles (`data/`)
|
||||
|
||||
Les articles ne sont pas versionnés dans ce dépôt. Ils ont leur propre dépôt git (`~/Projects/varlog-data/`, `~/Projects/fr.abonnel.www-data/`), synchronisé de façon bidirectionnelle avec le serveur distant.
|
||||
|
||||
## Modifier le moteur
|
||||
|
||||
### Branches
|
||||
|
||||
| Branche | Rôle |
|
||||
|---------|------|
|
||||
| `dev` | Branche d'intégration permanente. **Tout le développement courant se fait ici.** |
|
||||
| `main` | Branche de production. **Jamais de commit direct.** |
|
||||
| `feat/*` | Branches feature optionnelles pour du travail isolé, mergées dans `dev`. |
|
||||
|
||||
### Workflow
|
||||
|
||||
1. Toujours travailler sur `dev` (ou une branche feature mergée dans `dev`) :
|
||||
```bash
|
||||
git checkout dev
|
||||
```
|
||||
2. **Tester sur varlog.a5l.fr** à chaque itération (rsync des fichiers locaux, DB persistante) :
|
||||
```bash
|
||||
~/Projects/varlog/scripts/sync.sh
|
||||
# puis tester sur http://varlog.acegrp.lan
|
||||
```
|
||||
3. Quand `dev` est stable et prête pour la production :
|
||||
- Bumper `public/version.txt` (semver)
|
||||
- Ajouter une entrée `CHANGELOG.md` (`### Ajouté / Corrigé / Modifié`)
|
||||
- Ouvrir une **PR `dev` → `main`** sur Gitea
|
||||
4. Merger la PR → abonnel.fr se met à jour automatiquement.
|
||||
|
||||
**Règle absolue : ne jamais commiter directement sur `main`.** Le script `scripts/push.sh` bloque cette action.
|
||||
|
||||
### Pourquoi `dev` et non des branches feature à la volée
|
||||
|
||||
- La DB de varlog (test) accumule les migrations au fil du temps — changer de branche ne fait pas reculer les migrations.
|
||||
- Travailler toujours sur `dev` évite toute désynchronisation entre le code rsyncé et la DB.
|
||||
|
||||
## Données articles (`DATA_PATH`)
|
||||
|
||||
Les articles sont stockés dans un répertoire **hors du dépôt Folio**, configurable via `DATA_PATH` dans `.env` (défaut production : `/srv/data/folio`).
|
||||
|
||||
| Environnement | Dépôt local articles | Dépôt Gitea | Serveur |
|
||||
|--------------|---------------------|------------|---------|
|
||||
| varlog | `~/Projects/varlog-data/` | `cedricAbonnel/varlog` | `varlog:/srv/data/folio` |
|
||||
| abonnel.fr | `~/Projects/fr.abonnel.www-data/` | `cedricAbonnel/abonnel-www` | `abonnel-wiki:/srv/data/folio` |
|
||||
|
||||
Sync bidirectionnelle via **git** (pas rsync). Scripts dans `~/Projects/varlog/scripts/` et `~/Projects/fr.abonnel.www/scripts/` :
|
||||
- `pull-data.sh` : commit auto serveur + git pull local
|
||||
- `push-data.sh` : git commit local + git push + git pull serveur
|
||||
- `sync.sh` : moteur (rsync) + articles (git bidirectionnel)
|
||||
|
||||
## Asymétrie de déploiement moteur
|
||||
|
||||
| Site | Mécanisme | Raison |
|
||||
|------|-----------|--------|
|
||||
| varlog (test) | rsync depuis `~/Projects/folio/` | Itération rapide, pas de contrainte de stabilité |
|
||||
| abonnel.fr (prod) | `git pull origin main` sur le serveur | Contrôle via PR/merge, UpdateChecker autonome |
|
||||
|
||||
Pour initialiser git sur un serveur abonnel.fr déployé via rsync : `scripts/git-init-remote.sh`
|
||||
|
||||
## Ne pas mettre ici
|
||||
|
||||
- `.env` (credentials → dans chaque workspace site)
|
||||
- `data/` (articles → dans chaque workspace site)
|
||||
- `vendor/` (non versionné)
|
||||
@@ -0,0 +1,69 @@
|
||||
# FOLIO
|
||||
|
||||
Moteur de blog PHP — utilisé par plusieurs sites.
|
||||
|
||||
## Dépôt
|
||||
|
||||
`https://git.abonnel.fr/cedricAbonnel/folio` — branche `main`
|
||||
|
||||
## Sites utilisant Folio
|
||||
|
||||
| Site | Workspace local | Serveur |
|
||||
|---|---|---|
|
||||
| varlog.a5l.fr | `~/Projects/varlog/` | `ssh varlog` |
|
||||
| www.abonnel.fr | `~/Projects/fr.abonnel.www/` | `ssh abonnel-wiki` |
|
||||
|
||||
## Structure du moteur
|
||||
|
||||
```
|
||||
folio/
|
||||
├── src/ Classes PHP (ArticleManager, PostManager, auth…)
|
||||
├── public/ Point d'entrée web (index.php, route.php, assets/)
|
||||
├── templates/ Vues PHP (layout, header, footer, post_*)
|
||||
├── config/ Configuration (config.php)
|
||||
├── database/ Schéma SQL + migrate.php
|
||||
├── composer.json
|
||||
└── CHANGELOG.md
|
||||
```
|
||||
|
||||
## Workflow de modification du moteur
|
||||
|
||||
### 1. Développement et test sur varlog.a5l.fr
|
||||
|
||||
Modifier le code ici dans `~/Projects/folio/`, tester sur **varlog.a5l.fr** :
|
||||
|
||||
```bash
|
||||
# Déployer sur varlog pour test
|
||||
~/Projects/varlog/scripts/sync.sh
|
||||
|
||||
# Tester sur http://varlog.acegrp.lan (ou https://varlog.a5l.fr)
|
||||
```
|
||||
|
||||
### 2. Validation
|
||||
|
||||
Une fois validé sur varlog.a5l.fr :
|
||||
|
||||
```bash
|
||||
# Commiter sur le serveur varlog (git de déploiement)
|
||||
~/Projects/varlog/scripts/commit.sh "description du changement"
|
||||
```
|
||||
|
||||
### 3. Push vers le dépôt Folio
|
||||
|
||||
Pousser le code validé vers le dépôt canonique Folio :
|
||||
|
||||
```bash
|
||||
cd ~/Projects/folio
|
||||
./scripts/push.sh "description du changement"
|
||||
```
|
||||
|
||||
### 4. Déployer sur les autres sites si nécessaire
|
||||
|
||||
```bash
|
||||
~/Projects/fr.abonnel.www/scripts/sync.sh
|
||||
~/Projects/fr.abonnel.www/scripts/commit.sh "même message"
|
||||
```
|
||||
|
||||
## Credentials locaux
|
||||
|
||||
Aucun credential dans folio/ — les `.env` sont dans chaque workspace site.
|
||||
@@ -0,0 +1,166 @@
|
||||
# Folio
|
||||
|
||||
Moteur de blog PHP minimaliste — articles Markdown, authentification SSO (OIDC) ou lien magique, commentaires, recherche, flux RSS.
|
||||
|
||||
---
|
||||
|
||||
## Prérequis
|
||||
|
||||
- PHP ≥ 8.2 avec les extensions `pdo`, `pdo_pgsql`, `mbstring`, `openssl`
|
||||
- PostgreSQL ≥ 14
|
||||
- Composer
|
||||
- Apache avec `mod_rewrite` (ou Nginx — voir ci-dessous)
|
||||
|
||||
## Installation
|
||||
|
||||
### 1. Cloner et installer les dépendances
|
||||
|
||||
```bash
|
||||
git clone https://git.abonnel.fr/cedricAbonnel/folio mon-site
|
||||
cd mon-site
|
||||
composer install --no-dev
|
||||
```
|
||||
|
||||
### 2. Configurer l'environnement
|
||||
|
||||
```bash
|
||||
cp .env.example .env
|
||||
```
|
||||
|
||||
Remplir les valeurs dans `.env` :
|
||||
|
||||
| Variable | Description |
|
||||
|---|---|
|
||||
| `APP_URL` | URL publique du site (`https://example.com`) |
|
||||
| `ADMIN_EMAIL` | Email de l'administrateur principal |
|
||||
| `SESSION_NAME` | Nom du cookie de session — doit être unique par instance |
|
||||
| `DATA_PATH` | Chemin absolu vers le répertoire des articles (ex. `/srv/data/mon-site`). Par défaut : `<racine>/data` |
|
||||
| `OIDC_ISSUER` / `OIDC_CLIENT_ID` / `OIDC_CLIENT_SECRET` | SSO OpenID Connect |
|
||||
| `DB_DSN` / `DB_USER` / `DB_PASS` | Connexion PostgreSQL |
|
||||
| `SMTP_*` | Serveur email sortant (commentaires, contact, lien magique) |
|
||||
| `CONTACT_EMAIL` | Destinataire du formulaire de contact |
|
||||
|
||||
> En production, placer `DATA_PATH` **hors du document root** (ex. `/srv/data/mon-site`) pour que les articles ne soient pas accessibles directement via le serveur web.
|
||||
|
||||
### 3. Créer la base de données
|
||||
|
||||
```bash
|
||||
createdb monsite
|
||||
```
|
||||
|
||||
### 4. Initialiser le schéma et jouer les migrations
|
||||
|
||||
```bash
|
||||
php database/migrate.php
|
||||
```
|
||||
|
||||
Ce script crée toutes les tables et applique les migrations dans l'ordre. À relancer après chaque mise à jour.
|
||||
|
||||
### 5. Configurer le vhost Apache
|
||||
|
||||
```apache
|
||||
<VirtualHost *:443>
|
||||
ServerName example.com
|
||||
DocumentRoot /var/www/mon-site/public
|
||||
|
||||
<Directory /var/www/mon-site/public>
|
||||
AllowOverride All
|
||||
Require all granted
|
||||
</Directory>
|
||||
</VirtualHost>
|
||||
```
|
||||
|
||||
Le fichier `public/.htaccess` gère le routage via `mod_rewrite`. `AllowOverride All` est requis.
|
||||
|
||||
<details>
|
||||
<summary>Nginx</summary>
|
||||
|
||||
```nginx
|
||||
server {
|
||||
listen 443 ssl;
|
||||
server_name example.com;
|
||||
root /var/www/mon-site/public;
|
||||
index index.php;
|
||||
|
||||
location / {
|
||||
try_files $uri $uri/ /index.php?$query_string;
|
||||
}
|
||||
|
||||
location ~ \.php$ {
|
||||
fastcgi_pass unix:/run/php/php8.2-fpm.sock;
|
||||
fastcgi_param SCRIPT_FILENAME $realpath_root$fastcgi_script_name;
|
||||
include fastcgi_params;
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
</details>
|
||||
|
||||
### 6. Permissions fichiers
|
||||
|
||||
```bash
|
||||
# Répertoire des articles
|
||||
mkdir -p /srv/data/mon-site
|
||||
chown -R www-data:www-data /srv/data/mon-site
|
||||
|
||||
# .env lisible par www-data uniquement
|
||||
chown user:www-data .env
|
||||
chmod 640 .env
|
||||
```
|
||||
|
||||
PHP-FPM tourne en `www-data`. Le `.env` doit être lisible par `www-data` mais pas par les autres.
|
||||
|
||||
> Le script `scripts/setup.sh` automatise la vérification des prérequis, la création des répertoires et les droits.
|
||||
|
||||
### 7. Paramètres du site
|
||||
|
||||
Au premier lancement, se connecter en tant qu'admin et aller dans **Administration → Paramètres du site** pour définir le titre, le claim, la langue et la licence.
|
||||
|
||||
Ou créer directement `$DATA_PATH/site_settings.json` :
|
||||
|
||||
```json
|
||||
{
|
||||
"site_title": "Mon site",
|
||||
"site_claim": "Un blog propulsé par Folio",
|
||||
"site_lang": "fr-FR",
|
||||
"site_license_label": "CC BY 4.0",
|
||||
"site_license_url": "https://creativecommons.org/licenses/by/4.0/",
|
||||
"posts_per_page": 12
|
||||
}
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## Mise à jour
|
||||
|
||||
### Manuelle
|
||||
|
||||
```bash
|
||||
git pull
|
||||
composer install --no-dev
|
||||
php database/migrate.php
|
||||
```
|
||||
|
||||
### Via le bouton admin ("Mettre à jour")
|
||||
|
||||
L'interface d'administration propose un bouton **Mettre à jour** qui déclenche un déploiement complet via `sudo /usr/local/bin/folio-upgrade.sh`. Une configuration sudoers est requise une fois par serveur.
|
||||
|
||||
→ Voir **[docs/deployment.md](docs/deployment.md)** pour la procédure complète.
|
||||
|
||||
## Structure du projet
|
||||
|
||||
```
|
||||
├── config/ Configuration (charge .env, définit APP_URL et DATA_PATH)
|
||||
├── database/ Schéma SQL et runner de migrations
|
||||
├── docs/ Documentation technique
|
||||
├── public/ Racine web (index.php, assets, .htaccess)
|
||||
├── scripts/ Scripts utilitaires (setup.sh, migrations de contenu)
|
||||
├── src/ Code applicatif
|
||||
└── templates/ Vues PHP
|
||||
```
|
||||
|
||||
Les articles sont stockés dans `DATA_PATH` (hors dépôt git).
|
||||
|
||||
## Licence
|
||||
|
||||
[MIT](LICENSE)
|
||||
@@ -6,6 +6,16 @@ if (!defined('BASE_PATH')) {
|
||||
define('BASE_PATH', __DIR__);
|
||||
}
|
||||
|
||||
$__tz = $_ENV['APP_TIMEZONE'] ?? getenv('APP_TIMEZONE') ?: 'Europe/Paris';
|
||||
date_default_timezone_set($__tz);
|
||||
unset($__tz);
|
||||
|
||||
if (!defined('DATA_PATH')) {
|
||||
$__dataPath = $_ENV['DATA_PATH'] ?? getenv('DATA_PATH') ?: '';
|
||||
define('DATA_PATH', $__dataPath !== '' ? rtrim($__dataPath, '/') : BASE_PATH . '/data');
|
||||
unset($__dataPath);
|
||||
}
|
||||
|
||||
if (session_status() === PHP_SESSION_NONE) {
|
||||
$isHttps = !empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] !== 'off';
|
||||
$sessionName = $_ENV['SESSION_NAME'] ?? (getenv('SESSION_NAME') ?: null);
|
||||
|
||||
@@ -20,6 +20,12 @@ if (!$_ENV['APP_URL']) {
|
||||
// Normalise: toujours un trailing slash unique
|
||||
define('APP_URL', rtrim($_ENV['APP_URL'], '/') . '/');
|
||||
|
||||
if (!defined('DATA_PATH')) {
|
||||
$__dp = $_ENV['DATA_PATH'] ?? getenv('DATA_PATH') ?: '';
|
||||
define('DATA_PATH', $__dp !== '' ? rtrim($__dp, '/') : BASE_PATH . '/data');
|
||||
unset($__dp);
|
||||
}
|
||||
|
||||
// (Optionnel) Expose dans $_ENV si besoin
|
||||
$_ENV['APP_URL'] = APP_URL;
|
||||
|
||||
@@ -38,3 +44,5 @@ if (!function_exists('url')) {
|
||||
return $u;
|
||||
}
|
||||
}
|
||||
|
||||
require_once BASE_PATH . '/src/helpers.php';
|
||||
|
||||
+133
@@ -0,0 +1,133 @@
|
||||
# Consignes — Folio
|
||||
|
||||
## Architecture
|
||||
|
||||
**Folio** est un moteur de blog PHP.
|
||||
|
||||
### Dépôts et rôles
|
||||
|
||||
| Répertoire local | Rôle | Remote Gitea |
|
||||
|-----------------|------|-------------|
|
||||
| `~/Projects/folio/` | Copie du moteur Folio, branche `dev`. **Tout le développement se fait ici.** | `git.abonnel.fr/cedricAbonnel/folio` |
|
||||
| `~/Projects/varlog/` | Workspace du site varlog (scripts, config). | — |
|
||||
| `~/Projects/varlog-data/` | Articles de varlog.a5l.fr. Sync bidirectionnelle. | `cedricAbonnel/varlog` |
|
||||
| `~/Projects/fr.abonnel.www/` | Workspace du site abonnel.fr (scripts, config). | — |
|
||||
| `~/Projects/fr.abonnel.www-data/` | Articles de www.abonnel.fr. Sync bidirectionnelle. | `cedricAbonnel/abonnel-www` |
|
||||
|
||||
### Environnements
|
||||
|
||||
| Site | Rôle | Mise à jour moteur | Articles |
|
||||
|------|------|--------------------|---------|
|
||||
| varlog.a5l.fr | Test | rsync depuis `~/Projects/folio/` | `varlog-data/` ↔ `varlog:/srv/data/folio` |
|
||||
| www.abonnel.fr | Production | Auto (UpdateChecker vérifie `version.txt` sur Gitea) | `fr.abonnel.www-data/` ↔ `abonnel-wiki:/srv/data/folio` |
|
||||
|
||||
### Articles (`DATA_PATH`)
|
||||
|
||||
Les articles ne sont **jamais** dans le dépôt folio. Ils vivent dans un répertoire séparé, configurable via `DATA_PATH` dans le `.env` de chaque instance.
|
||||
|
||||
- Serveur varlog : `DATA_PATH=/srv/data/folio`
|
||||
- Serveur abonnel.fr : `DATA_PATH=/srv/data/folio`
|
||||
- En local pour tester : pointer `DATA_PATH` vers `~/Projects/varlog-data/`
|
||||
|
||||
La sync des articles se fait via git (pas rsync) avec les scripts `pull-data.sh` et `push-data.sh`.
|
||||
|
||||
---
|
||||
|
||||
## Workflow moteur
|
||||
|
||||
1. Travailler sur `dev` dans `~/Projects/folio/`
|
||||
2. Tester sur varlog.a5l.fr :
|
||||
```bash
|
||||
~/Projects/varlog/scripts/sync.sh
|
||||
# puis vérifier sur http://varlog.acegrp.lan (ou varlog.a5l.fr)
|
||||
```
|
||||
3. Quand `dev` est stable :
|
||||
- Bumper `public/version.txt` (semver)
|
||||
- Ajouter une entrée dans `CHANGELOG.md`
|
||||
- Ouvrir une **PR `dev` → `main`** sur Gitea
|
||||
4. Merger la PR → abonnel.fr se met à jour automatiquement.
|
||||
|
||||
**Règle absolue : jamais de commit direct sur `main`.**
|
||||
|
||||
---
|
||||
|
||||
## Mise à jour du moteur (varlog)
|
||||
|
||||
Le poste local n'a pas de base de données. Tout ce qui touche à la DB ou au contenu s'exécute **sur le serveur varlog** via SSH — les scripts locaux ne font qu'ouvrir une connexion SSH et lancer le PHP distant.
|
||||
|
||||
**Cycle de développement :**
|
||||
1. Modifier le code dans `~/Projects/folio/` (local)
|
||||
2. Déployer et tester :
|
||||
|
||||
```bash
|
||||
# Rsync moteur (folio → varlog) + sync articles bidirectionnel
|
||||
~/Projects/varlog/scripts/sync.sh
|
||||
# puis tester sur http://varlog.acegrp.lan
|
||||
```
|
||||
|
||||
3. Si des migrations de schéma BDD sont nécessaires :
|
||||
```bash
|
||||
~/Projects/varlog/scripts/db-migrate.sh # exécute le PHP sur varlog via SSH
|
||||
```
|
||||
|
||||
4. Si des migrations de contenu sont nécessaires :
|
||||
```bash
|
||||
~/Projects/varlog/scripts/content-migrate.sh # exécute le PHP sur varlog via SSH
|
||||
```
|
||||
|
||||
**Déploiement complet en une commande (lint + rsync + DB + contenu + commit serveur) :**
|
||||
```bash
|
||||
~/Projects/varlog/scripts/deploy.sh "message de commit"
|
||||
```
|
||||
|
||||
Chemin serveur : `varlog:/var/www/lan.acegrp.varlog/`
|
||||
|
||||
---
|
||||
|
||||
## Mise à jour manuelle du moteur (abonnel.fr)
|
||||
|
||||
À utiliser uniquement si l'UpdateChecker échoue :
|
||||
|
||||
```bash
|
||||
# Sauvegarde du .env
|
||||
cp /var/www/lan.acegrp.abonnel-www/.env /tmp/.env.bak
|
||||
|
||||
# Clone fresh (en root car /var/www appartient à root)
|
||||
sudo rm -rf /var/www/lan.acegrp.abonnel-www
|
||||
sudo git clone --depth=1 https://git.abonnel.fr/cedricAbonnel/folio.git /var/www/lan.acegrp.abonnel-www
|
||||
|
||||
# Permissions : www-data propriétaire (PHP-FPM tourne en www-data)
|
||||
sudo chown -R www-data:www-data /var/www/lan.acegrp.abonnel-www
|
||||
sudo chmod -R g+rwX,o= /var/www/lan.acegrp.abonnel-www
|
||||
|
||||
# Restauration du .env
|
||||
sudo cp /tmp/.env.bak /var/www/lan.acegrp.abonnel-www/.env
|
||||
sudo chown www-data:www-data /var/www/lan.acegrp.abonnel-www/.env
|
||||
|
||||
# Dépendances et migrations (en tant que www-data car le répertoire lui appartient)
|
||||
cd /var/www/lan.acegrp.abonnel-www
|
||||
sudo -u www-data composer install --no-dev --optimize-autoloader
|
||||
sudo -u www-data php database/migrate.php
|
||||
|
||||
# Répertoire de sessions
|
||||
sudo mkdir -p /var/www/lan.acegrp.abonnel-www/.sessions
|
||||
sudo chown www-data:www-data /var/www/lan.acegrp.abonnel-www/.sessions
|
||||
sudo chmod 700 /var/www/lan.acegrp.abonnel-www/.sessions
|
||||
|
||||
# Autoriser git à opérer sur ce dépôt (multi-utilisateurs)
|
||||
sudo git config --system --add safe.directory /var/www/lan.acegrp.abonnel-www
|
||||
```
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
---
|
||||
|
||||
## Règles à respecter
|
||||
|
||||
- Ne **jamais** écraser le `.env` serveur (ni scp, ni réécriture). Indiquer les variables à l'utilisateur pour qu'il les saisisse lui-même.
|
||||
- Ne **jamais** versionner `data/`, `.env`, ou `vendor/` dans le dépôt folio.
|
||||
- Toujours bumper la version **et** mettre à jour le changelog dans le même commit que la PR.
|
||||
- Dans les pools PHP-FPM, toujours utiliser `user = www-data` / `group = www-data`. `cedrix` est un admin ordinaire, pas un compte de service.
|
||||
- **CSP** : le header `Content-Security-Policy` est défini dans la config Apache (`varlog/server/apache/lan.acegrp.varlog.conf`), pas dans PHP. La directive `script-src 'self'` interdit les scripts inline — ne jamais écrire de `<script>` inline dans les templates ; toujours utiliser des fichiers `.js` externes dans `public/assets/js/`. Les erreurs CSP mentionnant `content.js` viennent d'extensions navigateur bloquées par le CSP (comportement normal, pas un bug Folio). Concernant les formulaires HTML : les `<form>` imbriqués sont invalides — un bouton submit dans un form imbriqué soumet le form parent. Utiliser l'attribut HTML5 `form="id-du-form"` pour associer un bouton à un form situé hors du form englobant.
|
||||
@@ -1,18 +0,0 @@
|
||||
{
|
||||
"uuid": "a3d8f2c1-7b4e-4f9a-8c3d-2e5a9b6f1d4c",
|
||||
"slug": "about",
|
||||
"title": "À propos",
|
||||
"author": "cedric@abonnel.fr",
|
||||
"published": true,
|
||||
"published_at": "2021-01-16 04:02:40",
|
||||
"created_at": "2021-01-16 04:02:40",
|
||||
"updated_at": "2026-05-13 00:00:00",
|
||||
"revisions": [],
|
||||
"cover": "",
|
||||
"files_meta": [],
|
||||
"external_links": [],
|
||||
"seo_title": "",
|
||||
"seo_description": "",
|
||||
"og_image": "",
|
||||
"category": ""
|
||||
}
|
||||
@@ -1,39 +0,0 @@
|
||||
# À propos
|
||||
|
||||
Qui se cache derrière varlog ?
|
||||
|
||||
Je m'appelle **Cédric**. Passionné d'informatique depuis longtemps, je gère un **HomeLab** à la maison — un petit laboratoire personnel où je fais tourner des serveurs, expérimente des configs réseau et casse des choses pour mieux les comprendre.
|
||||
|
||||
varlog est mon carnet de bord technique. J'y documente ce que je fais, ce que j'apprends, et parfois ce qui tourne mal — les incidents sont souvent les meilleures leçons.
|
||||
|
||||
Le blog a été lancé publiquement aux **JDLL 2025** (Journées Du Logiciel Libre), à Lyon.
|
||||
|
||||
## Ce dont je parle ici
|
||||
|
||||
### HomeLab & infrastructure
|
||||
|
||||
Proxmox, virtualisation, domotique (Zigbee, MQTT, Home Assistant), supervision avec Uptime Kuma, auto-hébergement de services (Gitea, Keycloak…), incidents réseau et leurs post-mortems.
|
||||
|
||||
### Réseaux & télécom
|
||||
|
||||
Passionné par les réseaux mobiles (3G/4G/5G/6G), la fibre optique (50G-PON), les stratégies des opérateurs et les infrastructures qui font fonctionner tout ça sans qu'on y pense.
|
||||
|
||||
### Linux & développement
|
||||
|
||||
Debian au quotidien, scripts, administration système, et un peu de PHP — dont ce blog lui-même, développé maison sous le nom de code *Folio*.
|
||||
|
||||
### Numérique & société
|
||||
|
||||
Souveraineté numérique, données personnelles, IA et plateformes qui monétisent nos contenus — des sujets qui m'intéressent autant qu'ils m'inquiètent.
|
||||
|
||||
### Le reste
|
||||
|
||||
Bricolage, travaux, anecdotes techniques, lectures, liseuses Kobo, et quelques billets qui n'entrent dans aucune case. La vie ne se range pas en catégories.
|
||||
|
||||
## Contact
|
||||
|
||||
Vous pouvez me joindre via le [formulaire de contact](/contact). Je lis tous les messages, même si je ne réponds pas toujours vite.
|
||||
|
||||
---
|
||||
|
||||
Le contenu de ce blog est publié sous licence [CC BY 4.0](https://creativecommons.org/licenses/by/4.0/) sauf mention contraire. Le moteur *Folio* est distribué sous [licence MIT](/LICENSE).
|
||||
@@ -1,18 +0,0 @@
|
||||
{
|
||||
"uuid": "b2c7e1f4-4a3d-4e8b-9f2a-1d6c8e3f5a7b",
|
||||
"slug": "legal",
|
||||
"title": "Mentions légales",
|
||||
"author": "cedric@abonnel.fr",
|
||||
"published": true,
|
||||
"published_at": "2021-01-16 04:02:40",
|
||||
"created_at": "2021-01-16 04:02:40",
|
||||
"updated_at": "2026-05-13 00:00:00",
|
||||
"revisions": [],
|
||||
"cover": "",
|
||||
"files_meta": [],
|
||||
"external_links": [],
|
||||
"seo_title": "",
|
||||
"seo_description": "",
|
||||
"og_image": "",
|
||||
"category": ""
|
||||
}
|
||||
@@ -1,43 +0,0 @@
|
||||
# Mentions légales
|
||||
|
||||
Conformément à la loi n° 2004-575 du 21 juin 2004 pour la confiance dans l'économie numérique (LCEN).
|
||||
|
||||
## Éditeur du site
|
||||
|
||||
**Responsable de publication :** Cédric Abonnel
|
||||
**Qualité :** Particulier — site personnel non commercial
|
||||
**Contact :** [formulaire de contact](/contact)
|
||||
|
||||
## Hébergement
|
||||
|
||||
**Type :** Auto-hébergement sur infrastructure personnelle (HomeLab)
|
||||
**Exploitant :** Cédric Abonnel
|
||||
**Fournisseur d'accès à internet :** Infrastructure personnelle auto-hébergée
|
||||
|
||||
## Propriété intellectuelle
|
||||
|
||||
Le **contenu éditorial** de ce site (articles, textes, images produites par l'auteur) est publié sous licence [Creative Commons Attribution 4.0 International (CC BY 4.0)](https://creativecommons.org/licenses/by/4.0/), sauf mention contraire.
|
||||
|
||||
Le **moteur du site** (*Folio*) est un logiciel libre distribué sous [licence MIT](/LICENSE).
|
||||
|
||||
Les composants tiers (Bootstrap, PHPMailer, police Inter…) sont soumis à leurs licences respectives, détaillées sur la [page des licences](/licenses).
|
||||
|
||||
## Données personnelles (RGPD)
|
||||
|
||||
Ce site est un blog personnel **sans publicité, sans pistage, sans système de commentaires** ni inscription publique.
|
||||
|
||||
Les seules données traitées automatiquement sont les **journaux de connexion du serveur web** (adresse IP, horodatage, page demandée), conservés conformément aux obligations légales (article L34-1 du Code des postes et des communications électroniques — durée maximale : 1 an).
|
||||
|
||||
Ces données ne sont ni vendues, ni transmises à des tiers, ni utilisées à des fins commerciales.
|
||||
|
||||
Conformément au RGPD (règlement UE 2016/679), vous disposez d'un droit d'accès, de rectification et de suppression des données vous concernant. Pour exercer ces droits : [formulaire de contact](/contact).
|
||||
|
||||
## Cookies
|
||||
|
||||
Ce site utilise uniquement un **cookie de session technique**, nécessaire au fonctionnement de l'authentification. Il n'est déposé que lors d'une connexion au compte d'administration et n'est pas utilisé à des fins de suivi ou de profilage. Aucun cookie tiers n'est déposé.
|
||||
|
||||
## Responsabilité
|
||||
|
||||
L'éditeur s'efforce de maintenir les informations publiées à jour et exactes, mais ne peut garantir l'exhaustivité ou l'absence d'erreurs du contenu.
|
||||
|
||||
Les liens vers des sites tiers sont fournis à titre informatif. L'éditeur n'est pas responsable du contenu de ces sites externes.
|
||||
@@ -1,18 +0,0 @@
|
||||
{
|
||||
"uuid": "fdff8ad3-d369-4bd7-bbb9-e14d433868d7",
|
||||
"slug": "licenses",
|
||||
"title": "Licences",
|
||||
"author": "cedric@abonnel.fr",
|
||||
"published": true,
|
||||
"published_at": "2021-01-16 04:02:40",
|
||||
"created_at": "2021-01-16 04:02:40",
|
||||
"updated_at": "2021-01-16 04:02:40",
|
||||
"revisions": [],
|
||||
"cover": "",
|
||||
"files_meta": [],
|
||||
"external_links": [],
|
||||
"seo_title": "",
|
||||
"seo_description": "",
|
||||
"og_image": "",
|
||||
"category": ""
|
||||
}
|
||||
@@ -1,38 +0,0 @@
|
||||
# Licences
|
||||
|
||||
Composants logiciels utilisés par ce site et leurs licences.
|
||||
|
||||
## Ce site
|
||||
|
||||
| Composant | Licence | Usage |
|
||||
|-----------|---------|-------|
|
||||
| **Folio** — moteur de blog PHP | MIT | Moteur de ce blog — par Cédric Abonnel ([voir la licence](/LICENSE)) |
|
||||
| **Contenu éditorial** | CC BY 4.0 | Articles et textes du blog — [Creative Commons Attribution 4.0](https://creativecommons.org/licenses/by/4.0/) |
|
||||
|
||||
## Bibliothèques (production)
|
||||
|
||||
| Composant | Version | Licence | Usage |
|
||||
|-----------|---------|---------|-------|
|
||||
| **Bootstrap** | 5.3.3 | MIT | Framework CSS/JS — auto-hébergé ([voir la licence](/assets/css/LICENSE-Bootstrap.txt)) |
|
||||
| **PHPMailer** | 6.12.0 | LGPL-2.1 | Envoi d'e-mails SMTP |
|
||||
| **phpdotenv** | 5.6.2 | BSD-3-Clause | Variables d'environnement |
|
||||
| **openid-connect-php** | 1.0.2 | Apache-2.0 | Authentification SSO (OIDC) |
|
||||
| **Police Inter** | v20 | OFL-1.1 | Typographie — auto-hébergée ([voir la licence](/assets/fonts/LICENSE-Inter.txt)) |
|
||||
|
||||
## Outils de développement
|
||||
|
||||
| Composant | Version | Licence | Usage |
|
||||
|-----------|---------|---------|-------|
|
||||
| **PHPStan** | 1.12.32 | MIT | Analyse statique PHP |
|
||||
| **PHP-CS-Fixer** | 3.89.1 | MIT | Formatage du code |
|
||||
| **Claude Code CLI** | — | Commercial | Outil de développement (Anthropic) — [Conditions d'utilisation](https://www.anthropic.com/legal/aup) |
|
||||
|
||||
## Infrastructure
|
||||
|
||||
| Composant | Licence | Usage |
|
||||
|-----------|---------|-------|
|
||||
| **PHP 8.3** | PHP License v3.01 | Langage côté serveur |
|
||||
| **PostgreSQL** | PostgreSQL License | Base de données relationnelle |
|
||||
| **Apache HTTP Server** | Apache-2.0 | Serveur web |
|
||||
|
||||
|
||||
@@ -0,0 +1,49 @@
|
||||
-- Schéma initial : tables créées avant la mise en place du système de migrations.
|
||||
-- Remplace tables_create.sql et interactions_create.sql.
|
||||
|
||||
CREATE TABLE IF NOT EXISTS posts (
|
||||
id SERIAL PRIMARY KEY,
|
||||
title TEXT NOT NULL,
|
||||
content TEXT,
|
||||
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
||||
updated_at TIMESTAMP,
|
||||
is_published BOOLEAN DEFAULT FALSE
|
||||
);
|
||||
|
||||
CREATE TABLE IF NOT EXISTS post_files (
|
||||
id SERIAL PRIMARY KEY,
|
||||
post_id INTEGER REFERENCES posts(id) ON DELETE CASCADE,
|
||||
file_type TEXT,
|
||||
file_path TEXT,
|
||||
original_name TEXT,
|
||||
uploaded_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
|
||||
);
|
||||
|
||||
CREATE TABLE IF NOT EXISTS article_reactions (
|
||||
id SERIAL PRIMARY KEY,
|
||||
article_uuid TEXT NOT NULL,
|
||||
reaction_type TEXT NOT NULL CHECK (reaction_type IN ('useful', 'important', 'interesting')),
|
||||
visitor_hash TEXT NOT NULL,
|
||||
created_at TIMESTAMP NOT NULL DEFAULT NOW(),
|
||||
UNIQUE (article_uuid, reaction_type, visitor_hash)
|
||||
);
|
||||
CREATE INDEX IF NOT EXISTS article_reactions_article_uuid_idx ON article_reactions (article_uuid);
|
||||
|
||||
CREATE TABLE IF NOT EXISTS comments (
|
||||
id SERIAL PRIMARY KEY,
|
||||
article_uuid TEXT NOT NULL,
|
||||
author_name TEXT NOT NULL,
|
||||
author_email TEXT NOT NULL,
|
||||
content TEXT NOT NULL CHECK (LENGTH(content) <= 2000),
|
||||
verify_token TEXT,
|
||||
verification_code TEXT,
|
||||
verify_attempts INTEGER NOT NULL DEFAULT 0,
|
||||
verified BOOLEAN NOT NULL DEFAULT FALSE,
|
||||
published BOOLEAN NOT NULL DEFAULT FALSE,
|
||||
created_at TIMESTAMP NOT NULL DEFAULT NOW(),
|
||||
ip_address TEXT,
|
||||
user_agent TEXT
|
||||
);
|
||||
CREATE INDEX IF NOT EXISTS comments_article_uuid_idx ON comments (article_uuid, verified, published);
|
||||
CREATE INDEX IF NOT EXISTS comments_verify_token_idx ON comments (verify_token)
|
||||
WHERE verified = FALSE AND verify_token IS NOT NULL;
|
||||
@@ -0,0 +1,10 @@
|
||||
CREATE TABLE IF NOT EXISTS user_profiles (
|
||||
email TEXT NOT NULL PRIMARY KEY,
|
||||
display_name TEXT NOT NULL DEFAULT '',
|
||||
updated_at TIMESTAMP DEFAULT now(),
|
||||
profile_url TEXT NOT NULL DEFAULT '',
|
||||
profile_slug TEXT NOT NULL DEFAULT '',
|
||||
bio TEXT NOT NULL DEFAULT ''
|
||||
);
|
||||
CREATE UNIQUE INDEX IF NOT EXISTS user_profiles_profile_slug_idx
|
||||
ON user_profiles (profile_slug) WHERE profile_slug <> '';
|
||||
@@ -0,0 +1,16 @@
|
||||
CREATE TABLE IF NOT EXISTS journal_smtp (
|
||||
id SERIAL PRIMARY KEY,
|
||||
created_at TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT now(),
|
||||
script_path VARCHAR(512),
|
||||
to_email VARCHAR(255) NOT NULL,
|
||||
subject VARCHAR(512),
|
||||
content_html TEXT,
|
||||
content_text TEXT,
|
||||
status VARCHAR(20) NOT NULL DEFAULT 'queued',
|
||||
ip VARCHAR(128),
|
||||
user_agent VARCHAR(512),
|
||||
error_message VARCHAR(1000),
|
||||
sent_at TIMESTAMP WITH TIME ZONE
|
||||
);
|
||||
CREATE INDEX IF NOT EXISTS idx_journal_smtp_created_at ON journal_smtp (created_at DESC);
|
||||
CREATE INDEX IF NOT EXISTS idx_journal_smtp_to_email ON journal_smtp (to_email);
|
||||
@@ -0,0 +1,5 @@
|
||||
CREATE TABLE IF NOT EXISTS role_capabilities (
|
||||
role_id INTEGER NOT NULL REFERENCES roles(id) ON DELETE CASCADE,
|
||||
capability VARCHAR(50) NOT NULL,
|
||||
PRIMARY KEY (role_id, capability)
|
||||
);
|
||||
@@ -0,0 +1,7 @@
|
||||
CREATE TABLE IF NOT EXISTS user_capabilities (
|
||||
user_email TEXT NOT NULL,
|
||||
capability TEXT NOT NULL,
|
||||
granted_by TEXT,
|
||||
granted_at TIMESTAMP WITH TIME ZONE DEFAULT now(),
|
||||
PRIMARY KEY (user_email, capability)
|
||||
);
|
||||
@@ -0,0 +1,8 @@
|
||||
CREATE TABLE IF NOT EXISTS users (
|
||||
id SERIAL PRIMARY KEY,
|
||||
email TEXT NOT NULL UNIQUE,
|
||||
password_hash TEXT NOT NULL,
|
||||
is_active BOOLEAN NOT NULL DEFAULT TRUE,
|
||||
updated_at TIMESTAMP,
|
||||
password_changed_at TIMESTAMP
|
||||
);
|
||||
@@ -0,0 +1,9 @@
|
||||
CREATE TABLE IF NOT EXISTS profiles (
|
||||
id SERIAL PRIMARY KEY,
|
||||
slug TEXT NOT NULL UNIQUE,
|
||||
label TEXT NOT NULL DEFAULT '',
|
||||
description TEXT,
|
||||
permissions JSONB NOT NULL DEFAULT '[]',
|
||||
is_system BOOLEAN NOT NULL DEFAULT FALSE,
|
||||
is_active BOOLEAN NOT NULL DEFAULT TRUE
|
||||
);
|
||||
@@ -0,0 +1,13 @@
|
||||
CREATE TABLE IF NOT EXISTS app_config (
|
||||
id INTEGER PRIMARY KEY DEFAULT 1,
|
||||
allow_password BOOLEAN NOT NULL DEFAULT TRUE,
|
||||
allow_oidc BOOLEAN NOT NULL DEFAULT FALSE,
|
||||
registrations_open BOOLEAN NOT NULL DEFAULT TRUE,
|
||||
oidc_issuer TEXT,
|
||||
oidc_name TEXT,
|
||||
oidc_client_id TEXT,
|
||||
oidc_client_secret TEXT,
|
||||
oidc_redirect_uri TEXT,
|
||||
updated_at TIMESTAMP,
|
||||
CONSTRAINT app_config_single_row CHECK (id = 1)
|
||||
);
|
||||
@@ -0,0 +1,15 @@
|
||||
CREATE TABLE IF NOT EXISTS mail_queue (
|
||||
id SERIAL PRIMARY KEY,
|
||||
to_email TEXT NOT NULL,
|
||||
subject TEXT NOT NULL,
|
||||
body TEXT NOT NULL,
|
||||
status TEXT NOT NULL DEFAULT 'pending',
|
||||
attempts INTEGER NOT NULL DEFAULT 0,
|
||||
available_at TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT now(),
|
||||
locked_at TIMESTAMP WITH TIME ZONE,
|
||||
last_error TEXT,
|
||||
created_at TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT now()
|
||||
);
|
||||
CREATE INDEX IF NOT EXISTS idx_mail_queue_pending
|
||||
ON mail_queue (available_at ASC, id ASC)
|
||||
WHERE status = 'pending';
|
||||
@@ -0,0 +1,44 @@
|
||||
-- Tables du dictionnaire de données (formulaires dynamiques)
|
||||
|
||||
CREATE TABLE IF NOT EXISTS dd_entities (
|
||||
id SERIAL PRIMARY KEY,
|
||||
code TEXT NOT NULL UNIQUE,
|
||||
label TEXT NOT NULL DEFAULT '',
|
||||
is_active BOOLEAN NOT NULL DEFAULT TRUE
|
||||
);
|
||||
|
||||
CREATE TABLE IF NOT EXISTS dd_fields (
|
||||
id SERIAL PRIMARY KEY,
|
||||
entity_id INTEGER NOT NULL REFERENCES dd_entities(id) ON DELETE CASCADE,
|
||||
code TEXT NOT NULL,
|
||||
label TEXT NOT NULL DEFAULT '',
|
||||
field_type TEXT NOT NULL DEFAULT 'text',
|
||||
ui_order INTEGER,
|
||||
is_required BOOLEAN NOT NULL DEFAULT FALSE,
|
||||
default_val TEXT,
|
||||
UNIQUE (entity_id, code)
|
||||
);
|
||||
|
||||
CREATE TABLE IF NOT EXISTS dd_rules (
|
||||
id SERIAL PRIMARY KEY,
|
||||
entity_id INTEGER NOT NULL REFERENCES dd_entities(id) ON DELETE CASCADE,
|
||||
rule_type TEXT NOT NULL,
|
||||
expression TEXT,
|
||||
message TEXT,
|
||||
active BOOLEAN NOT NULL DEFAULT TRUE
|
||||
);
|
||||
|
||||
CREATE TABLE IF NOT EXISTS dd_enums (
|
||||
id SERIAL PRIMARY KEY,
|
||||
name TEXT NOT NULL UNIQUE
|
||||
);
|
||||
|
||||
CREATE TABLE IF NOT EXISTS dd_enum_values (
|
||||
id SERIAL PRIMARY KEY,
|
||||
enum_id INTEGER NOT NULL REFERENCES dd_enums(id) ON DELETE CASCADE,
|
||||
code TEXT NOT NULL,
|
||||
label TEXT NOT NULL DEFAULT '',
|
||||
active BOOLEAN NOT NULL DEFAULT TRUE,
|
||||
sort_order INTEGER NOT NULL DEFAULT 0,
|
||||
UNIQUE (enum_id, code)
|
||||
);
|
||||
@@ -0,0 +1,115 @@
|
||||
# Déploiement et mise à jour
|
||||
|
||||
## Mise à jour via le bouton admin
|
||||
|
||||
L'interface d'administration propose un bouton **Mettre à jour** (onglet Dashboard). Il appelle `sudo /usr/local/bin/folio-upgrade.sh` depuis PHP (`www-data`) et exécute la séquence complète :
|
||||
|
||||
1. Sauvegarde du `.env`
|
||||
2. `git clone --depth=1` dans un répertoire temporaire
|
||||
3. Remplacement atomique du répertoire applicatif
|
||||
4. `chown -R www-data:www-data` + `chmod g+rwX,o=`
|
||||
5. Restauration du `.env`
|
||||
6. `composer install --no-dev --optimize-autoloader`
|
||||
7. `php database/migrate.php` (migrations SQL)
|
||||
8. Création de `.sessions/` avec les bons droits
|
||||
9. `git config --system --add safe.directory`
|
||||
|
||||
### Pré-requis serveur (à faire une fois)
|
||||
|
||||
```bash
|
||||
# 1. Installer le script (copié depuis le dépôt)
|
||||
sudo install -o root -m 750 /var/www/mon-site/scripts/server/folio-upgrade.sh \
|
||||
/usr/local/bin/folio-upgrade.sh
|
||||
|
||||
# 2. Adapter APP_DIR et REPO_URL en tête du script
|
||||
sudo nano /usr/local/bin/folio-upgrade.sh
|
||||
|
||||
# 3. Créer la règle sudoers (www-data sans mot de passe)
|
||||
echo "www-data ALL=(root) NOPASSWD: /usr/local/bin/folio-upgrade.sh" \
|
||||
| sudo tee /etc/sudoers.d/folio-upgrade
|
||||
sudo chmod 440 /etc/sudoers.d/folio-upgrade
|
||||
|
||||
# 4. Vérifier la syntaxe sudoers
|
||||
sudo visudo -c
|
||||
```
|
||||
|
||||
Variables à configurer dans le script :
|
||||
|
||||
| Variable | Exemple |
|
||||
|---|---|
|
||||
| `APP_DIR` | `/var/www/lan.acegrp.abonnel-www` |
|
||||
| `REPO_URL` | `https://git.abonnel.fr/cedricAbonnel/folio.git` |
|
||||
|
||||
> **Sans cette configuration**, le bouton retourne :
|
||||
> `sudo: a terminal is required to read the password`
|
||||
|
||||
### Fonctionnement du cache de mise à jour
|
||||
|
||||
Le résultat de la dernière mise à jour est conservé dans `DATA_PATH/.upgrade-log` et affiché en `<details>` dans l'admin.
|
||||
|
||||
---
|
||||
|
||||
## Mise à jour manuelle
|
||||
|
||||
Si le bouton admin n'est pas configuré ou si une mise à jour d'urgence est nécessaire :
|
||||
|
||||
```bash
|
||||
# Sauvegarde du .env
|
||||
cp /var/www/mon-site/.env /tmp/.env.bak
|
||||
|
||||
# Clone fresh
|
||||
sudo rm -rf /var/www/mon-site
|
||||
sudo git clone --depth=1 https://git.abonnel.fr/cedricAbonnel/folio.git /var/www/mon-site
|
||||
|
||||
# Permissions
|
||||
sudo chown -R www-data:www-data /var/www/mon-site
|
||||
sudo chmod -R g+rwX,o= /var/www/mon-site
|
||||
|
||||
# Restaurer .env
|
||||
cp /tmp/.env.bak /var/www/mon-site/.env
|
||||
|
||||
# Dépendances et migrations
|
||||
cd /var/www/mon-site
|
||||
composer install --no-dev --optimize-autoloader
|
||||
php database/migrate.php
|
||||
|
||||
# Répertoire de sessions
|
||||
sudo mkdir -p /var/www/mon-site/.sessions
|
||||
sudo chown www-data:www-data /var/www/mon-site/.sessions
|
||||
sudo chmod 700 /var/www/mon-site/.sessions
|
||||
|
||||
# Autoriser git (accès multi-utilisateurs)
|
||||
sudo git config --system --add safe.directory /var/www/mon-site
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## Flux RSS des tendances (`/trending`)
|
||||
|
||||
Le flux RSS des articles les plus consultés est alimenté par `TrendingParser` qui lit les logs Apache.
|
||||
|
||||
- **Source** : `GET /trending?period=<période>` — parse les logs et écrit `DATA_PATH/_cache/trending_<période>.json`
|
||||
- **Consommateurs** (lecture seule du cache) : page d'accueil (rubrique "Meilleures audiences") et `/tendances`
|
||||
|
||||
### Périodes disponibles
|
||||
|
||||
| Paramètre | Fenêtre | Cache TTL |
|
||||
|---|---|---|
|
||||
| `10m` | 10 min | 2 min |
|
||||
| `20m` | 20 min | 4 min |
|
||||
| `30m` | 30 min | 6 min |
|
||||
| `1h` | 1 heure | 12 min |
|
||||
| `8h` | 8 heures | 96 min |
|
||||
| `1d` | 24 heures | 5 h |
|
||||
| `7d` | 7 jours | 8 h |
|
||||
| `14d` | 14 jours | 8 h |
|
||||
| `30d` | 30 jours | 8 h |
|
||||
| `1y` | 1 an | 8 h |
|
||||
|
||||
### Prérequis
|
||||
|
||||
`www-data` doit appartenir au groupe `adm` pour lire `/var/log/apache2/` :
|
||||
|
||||
```bash
|
||||
sudo usermod -aG adm www-data
|
||||
```
|
||||
@@ -3,3 +3,4 @@
|
||||
declare(strict_types=1);
|
||||
|
||||
define('BASE_PATH', __DIR__);
|
||||
define('DATA_PATH', BASE_PATH . '/data');
|
||||
|
||||
+7
-1
@@ -15,6 +15,9 @@ RewriteRule ^ - [L]
|
||||
# URL propre pour les articles : /post/<slug>
|
||||
RewriteRule ^post/([a-z0-9][a-z0-9-]*)/?$ /index.php?action=view&slug=$1 [L,QSA]
|
||||
|
||||
# Catalogue de tous les livres : /books
|
||||
RewriteRule ^books/?$ /index.php?action=books_list [L,QSA]
|
||||
|
||||
# Livres : /book/<slug>
|
||||
RewriteRule ^book/([a-z0-9][a-z0-9-]*)/?$ /index.php?action=book&book_slug=$1 [L,QSA]
|
||||
|
||||
@@ -32,6 +35,7 @@ RewriteRule ^edit/([0-9a-f-]{36})/?$ /index.php?action=edit&uuid=$1 [L,QSA]
|
||||
RewriteRule ^new/([0-9a-f-]{36})/([1-5])/?$ /index.php?action=create&uuid=$1&step=$2 [L,QSA]
|
||||
RewriteRule ^new/?$ /index.php?action=create [L,QSA]
|
||||
RewriteRule ^delete/([0-9a-f-]{36})/?$ /index.php?action=delete&uuid=$1 [L,QSA]
|
||||
RewriteRule ^duplicate/([0-9a-f-]{36})/?$ /index.php?action=duplicate&uuid=$1 [L,QSA]
|
||||
|
||||
# Sources et diff
|
||||
RewriteRule ^sources/([0-9a-f-]{36})/?$ /index.php?action=sources&uuid=$1 [L,QSA]
|
||||
@@ -41,8 +45,9 @@ RewriteRule ^diff/([0-9a-f-]{36})/(\d+)/?$ /index.php?action=diff&uuid=$1&rev=$2
|
||||
RewriteRule ^files/([0-9a-f-]{36})/add/?$ /index.php?action=add_files&uuid=$1 [L,QSA]
|
||||
RewriteRule ^import/([0-9a-f-]{36})/?$ /index.php?action=import_image&uuid=$1 [L,QSA]
|
||||
|
||||
# Admin (regen-thumbs et role/<email> avant la règle générique admin/<tab>)
|
||||
# Admin (regen-thumbs, email-preview et role/<email> avant la règle générique admin/<tab>)
|
||||
RewriteRule ^admin/regen-thumbs/?$ /index.php?action=regen_thumbs [L,QSA]
|
||||
RewriteRule ^admin/email-preview/(\d+)/?$ /index.php?action=admin_email_preview&id=$1 [L,QSA]
|
||||
RewriteRule ^admin/role/([a-z0-9_-]+)/?$ /index.php?action=admin_role_edit&role_name=$1 [L,QSA]
|
||||
RewriteRule ^admin/([a-z0-9-]+)/?$ /index.php?action=admin&tab=$1 [L,QSA]
|
||||
RewriteRule ^admin/?$ /index.php?action=admin [L,QSA]
|
||||
@@ -57,6 +62,7 @@ RewriteRule ^verify-comment/([0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-
|
||||
RewriteRule ^categories/?$ /index.php?action=categories [L,QSA]
|
||||
RewriteRule ^profile/?$ /index.php?action=profile [L,QSA]
|
||||
RewriteRule ^search/?$ /index.php?action=search [L,QSA]
|
||||
RewriteRule ^tendances/?$ /tendances.php [L,QSA]
|
||||
RewriteRule ^flux/?$ /index.php?action=flux [L,QSA]
|
||||
RewriteRule ^feed/add/?$ /index.php?action=add_feed [L,QSA]
|
||||
RewriteRule ^feed/delete/?$ /index.php?action=delete_feed [L,QSA]
|
||||
|
||||
@@ -1266,6 +1266,40 @@ footer.mt-5 { margin-top: 0 !important; }
|
||||
letter-spacing: .01em;
|
||||
}
|
||||
|
||||
/* ─── Densité d'affichage L / M / S ──────── */
|
||||
main { transition: max-width .22s ease; }
|
||||
|
||||
/* Widget fixe haut-droite */
|
||||
.density-widget {
|
||||
position: fixed;
|
||||
top: 3.6rem;
|
||||
right: 1rem;
|
||||
z-index: 1010;
|
||||
display: flex;
|
||||
gap: 2px;
|
||||
background: var(--vl-surface);
|
||||
border: 1px solid var(--vl-border);
|
||||
border-radius: 6px;
|
||||
padding: 3px;
|
||||
box-shadow: var(--vl-shadow-sm);
|
||||
}
|
||||
.density-btn {
|
||||
background: none;
|
||||
border: 1px solid transparent;
|
||||
border-radius: 4px;
|
||||
color: var(--vl-muted);
|
||||
cursor: pointer;
|
||||
font-size: .68rem;
|
||||
font-weight: 700;
|
||||
letter-spacing: .06em;
|
||||
line-height: 1;
|
||||
padding: 4px 8px;
|
||||
transition: background .15s, color .15s, border-color .15s;
|
||||
}
|
||||
.density-btn:hover { background: rgba(0,0,0,.06); color: var(--vl-text); }
|
||||
.density-btn.active { background: var(--vl-text); color: var(--vl-bg); }
|
||||
@media (max-width: 576px) { .density-widget { display: none; } }
|
||||
|
||||
/* ─── Page de recherche ───────────────────── */
|
||||
.search-page { max-width: 780px; margin: 0 auto; }
|
||||
|
||||
@@ -1810,6 +1844,68 @@ footer.mt-5 { margin-top: 0 !important; }
|
||||
|
||||
/* ─── Livres ─────────────────────────────────────────────────────── */
|
||||
|
||||
/* Grille catalogue /books + section accueil */
|
||||
.book-grid {
|
||||
display: grid;
|
||||
grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
|
||||
gap: 1rem;
|
||||
}
|
||||
.book-home-card {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
border-radius: var(--vl-radius);
|
||||
overflow: hidden;
|
||||
text-decoration: none;
|
||||
color: inherit;
|
||||
background: var(--vl-card-bg, var(--bs-body-bg));
|
||||
box-shadow: var(--vl-shadow-sm, 0 1px 3px rgba(0,0,0,.08));
|
||||
transition: transform .15s, box-shadow .15s;
|
||||
}
|
||||
.book-home-card:hover {
|
||||
transform: translateY(-2px);
|
||||
box-shadow: var(--vl-shadow-md, 0 4px 12px rgba(0,0,0,.14));
|
||||
color: inherit;
|
||||
}
|
||||
.book-home-card-cover {
|
||||
height: 120px;
|
||||
background-size: cover;
|
||||
background-position: center;
|
||||
flex-shrink: 0;
|
||||
}
|
||||
.book-home-card-body {
|
||||
padding: .7rem;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: .2rem;
|
||||
flex: 1;
|
||||
}
|
||||
.book-home-card-title {
|
||||
font-weight: 600;
|
||||
font-size: .9rem;
|
||||
line-height: 1.3;
|
||||
}
|
||||
.book-home-card-desc {
|
||||
font-size: .78rem;
|
||||
color: var(--vl-muted);
|
||||
line-height: 1.4;
|
||||
}
|
||||
.book-home-card-meta {
|
||||
font-size: .72rem;
|
||||
color: var(--vl-muted);
|
||||
margin-top: auto;
|
||||
padding-top: .3rem;
|
||||
}
|
||||
.home-section-more {
|
||||
font-size: .75rem;
|
||||
font-weight: 400;
|
||||
margin-left: .5rem;
|
||||
color: var(--vl-accent);
|
||||
text-decoration: none;
|
||||
letter-spacing: 0;
|
||||
text-transform: none;
|
||||
}
|
||||
.home-section-more:hover { text-decoration: underline; }
|
||||
|
||||
/* Bandeau dans un article appartenant à un livre */
|
||||
.book-article-banner {
|
||||
border-radius: var(--vl-radius);
|
||||
|
||||
@@ -0,0 +1,144 @@
|
||||
/* Admin stats : groupes AS + chargement pages via flux RSS XML /trending?period=14d */
|
||||
|
||||
// ── Groupes de réseaux ────────────────────────────────────────────────────────
|
||||
(function () {
|
||||
var addBtn = document.getElementById('as-group-add');
|
||||
if (!addBtn) { return; }
|
||||
|
||||
addBtn.addEventListener('click', function () {
|
||||
var tpl = document.getElementById('as-group-tpl').content.cloneNode(true);
|
||||
document.getElementById('as-groups-list').appendChild(tpl);
|
||||
});
|
||||
|
||||
document.getElementById('as-groups-list').addEventListener('click', function (e) {
|
||||
if (e.target.classList.contains('as-group-delete')) {
|
||||
e.target.closest('.as-group-row').remove();
|
||||
}
|
||||
});
|
||||
}());
|
||||
|
||||
// ── Pages les plus visitées (RSS XML + sparklines) ───────────────────────────
|
||||
(function () {
|
||||
var container = document.getElementById('stats-pages-container');
|
||||
var badge = document.getElementById('stats-pages-count');
|
||||
var pagesByDay = (typeof FOLIO_PAGES_BY_DAY !== 'undefined') ? FOLIO_PAGES_BY_DAY : {};
|
||||
if (!container) { return; }
|
||||
|
||||
function esc(s) {
|
||||
return String(s).replace(/&/g, '&').replace(/</g, '<').replace(/>/g, '>').replace(/"/g, '"');
|
||||
}
|
||||
|
||||
function sparkline(data) {
|
||||
var W = 120, H = 28, padX = 2, padY = 3;
|
||||
var max = Math.max.apply(null, data) || 1;
|
||||
var n = data.length;
|
||||
var pts = data.map(function (v, i) {
|
||||
var x = padX + i * (W - 2 * padX) / (n - 1);
|
||||
var y = H - padY - (v / max) * (H - 2 * padY);
|
||||
return x.toFixed(1) + ',' + y.toFixed(1);
|
||||
}).join(' ');
|
||||
// Zone remplie sous la courbe
|
||||
var first = padX.toFixed(1) + ',' + (H - padY).toFixed(1);
|
||||
var last = (W - padX).toFixed(1) + ',' + (H - padY).toFixed(1);
|
||||
return '<svg xmlns="http://www.w3.org/2000/svg" width="' + W + '" height="' + H + '" style="display:block;overflow:visible">'
|
||||
+ '<defs><linearGradient id="spk-grad" x1="0" y1="0" x2="0" y2="1">'
|
||||
+ '<stop offset="0%" stop-color="var(--bs-primary,#0d6efd)" stop-opacity="0.18"/>'
|
||||
+ '<stop offset="100%" stop-color="var(--bs-primary,#0d6efd)" stop-opacity="0"/>'
|
||||
+ '</linearGradient></defs>'
|
||||
+ '<polygon points="' + first + ' ' + pts + ' ' + last + '" fill="url(#spk-grad)"/>'
|
||||
+ '<polyline points="' + pts + '" fill="none" stroke="var(--bs-primary,#0d6efd)" stroke-width="1.5" stroke-linejoin="round" stroke-linecap="round"/>'
|
||||
+ '</svg>';
|
||||
}
|
||||
|
||||
function trendChart(totals) {
|
||||
var trendEl = document.getElementById('stats-trend-container');
|
||||
if (!trendEl || !totals.length) { return; }
|
||||
|
||||
var days = totals.length;
|
||||
var maxV = Math.max.apply(null, totals) || 1;
|
||||
var W = 1000; // viewBox, s'adapte en CSS
|
||||
var H = 80;
|
||||
var padX = 4;
|
||||
var padY = 8;
|
||||
var barW = Math.floor((W - 2 * padX) / days) - 2;
|
||||
|
||||
// Dates des jours (index 0 = il y a 13 jours)
|
||||
var now = new Date();
|
||||
var labels = totals.map(function (_, i) {
|
||||
var d = new Date(now);
|
||||
d.setDate(d.getDate() - (days - 1 - i));
|
||||
return d.toLocaleDateString('fr-FR', { day: 'numeric', month: 'short' });
|
||||
});
|
||||
|
||||
var bars = totals.map(function (v, i) {
|
||||
var x = padX + i * (W - 2 * padX) / days + 1;
|
||||
var bh = Math.max(2, (v / maxV) * (H - padY - 16));
|
||||
var y = H - padY - bh;
|
||||
var lx = x + barW / 2;
|
||||
var label = labels[i];
|
||||
var showLabel = (i === 0 || i === days - 1 || i === Math.floor(days / 2));
|
||||
return '<rect x="' + x.toFixed(1) + '" y="' + y.toFixed(1) + '" width="' + barW + '" height="' + bh.toFixed(1) + '"'
|
||||
+ ' fill="var(--bs-primary,#0d6efd)" opacity="0.75" rx="2"/>'
|
||||
+ '<title>' + label + ' : ' + v + ' vis.</title>'
|
||||
+ (showLabel
|
||||
? '<text x="' + lx.toFixed(1) + '" y="' + (H - 1) + '" text-anchor="middle"'
|
||||
+ ' font-size="10" fill="var(--bs-secondary-color,#6c757d)">' + label + '</text>'
|
||||
: '');
|
||||
}).join('');
|
||||
|
||||
trendEl.innerHTML = '<p class="small text-muted mb-2 fw-semibold">Trafic total — 14 derniers jours</p>'
|
||||
+ '<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 ' + W + ' ' + H + '"'
|
||||
+ ' style="width:100%;height:80px;display:block">' + bars + '</svg>';
|
||||
}
|
||||
|
||||
fetch('/trending?period=14d')
|
||||
.then(function (r) { return r.ok ? r.text() : Promise.reject(); })
|
||||
.then(function (xml) {
|
||||
var doc = new DOMParser().parseFromString(xml, 'application/xml');
|
||||
var items = Array.from(doc.querySelectorAll('item'));
|
||||
if (!items.length) {
|
||||
container.innerHTML = '<p class="text-muted p-3 mb-0">Aucune donnée.</p>';
|
||||
return;
|
||||
}
|
||||
var rows = items.map(function (item) {
|
||||
var raw = (item.querySelector('title') || { textContent: '' }).textContent;
|
||||
var link = ((item.querySelector('link') || {}).textContent || '').trim();
|
||||
var m = raw.match(/\((\d+)\s+visiteurs?\)$/);
|
||||
var vis = m ? parseInt(m[1], 10) : 0;
|
||||
var title = raw.replace(/\s*\(\d+\s+visiteurs?\)$/, '');
|
||||
var slug = decodeURIComponent(link.replace(/.*\/post\//, ''));
|
||||
var pm = link.match(/\/post\/[^?#]*/);
|
||||
var daily = pm ? (pagesByDay[pm[0]] || null) : null;
|
||||
return { title: title, link: link, slug: slug, vis: vis, daily: daily };
|
||||
});
|
||||
|
||||
// Graphique global : somme de tous les articles par jour
|
||||
var nDays = 14;
|
||||
var totals = new Array(nDays).fill(0);
|
||||
Object.values(pagesByDay).forEach(function (arr) {
|
||||
arr.forEach(function (v, i) { if (i < nDays) { totals[i] += v; } });
|
||||
});
|
||||
trendChart(totals);
|
||||
|
||||
var html = '<div class="table-responsive"><table class="table table-sm table-hover mb-0 small w-100"><tbody>';
|
||||
rows.forEach(function (row, i) {
|
||||
var vis = row.vis.toLocaleString('fr-FR');
|
||||
var spk = row.daily ? sparkline(row.daily) : '';
|
||||
html += '<tr>'
|
||||
+ '<td class="text-muted ps-3" style="width:2rem;vertical-align:middle">' + (i + 1) + '</td>'
|
||||
+ '<td style="vertical-align:middle"><a href="' + esc(row.link) + '" target="_blank"'
|
||||
+ ' class="text-decoration-none" title="' + esc(row.slug) + '">'
|
||||
+ esc(row.title || row.slug) + '</a></td>'
|
||||
+ '<td style="width:130px;vertical-align:middle;padding:4px 8px">' + spk + '</td>'
|
||||
+ '<td class="text-end fw-semibold pe-3" style="width:5rem;vertical-align:middle">'
|
||||
+ vis + ' <span class="text-muted fw-normal">vis.</span></td>'
|
||||
+ '</tr>';
|
||||
});
|
||||
html += '</tbody></table></div>';
|
||||
if (badge) { badge.textContent = rows.length + ' URLs'; }
|
||||
container.innerHTML = html;
|
||||
})
|
||||
.catch(function () {
|
||||
container.innerHTML = '<p class="text-muted p-3 mb-0">Impossible de charger le flux.</p>';
|
||||
});
|
||||
}());
|
||||
@@ -9,6 +9,16 @@ document.addEventListener('DOMContentLoaded', function () {
|
||||
});
|
||||
});
|
||||
|
||||
// Boutons data-confirm-discard (évite onclick inline bloqué par CSP)
|
||||
document.querySelectorAll('[data-confirm-discard]').forEach(function (btn) {
|
||||
btn.addEventListener('click', function () {
|
||||
var msg = btn.getAttribute('data-confirm-msg') || 'Confirmer ?';
|
||||
if (window.confirm(msg)) {
|
||||
window.location = btn.getAttribute('data-discard-url');
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
// Sélection globale articles
|
||||
var checkAll = document.getElementById('check-all');
|
||||
if (checkAll) {
|
||||
@@ -19,6 +29,23 @@ document.addEventListener('DOMContentLoaded', function () {
|
||||
});
|
||||
}
|
||||
|
||||
// Clic sur la ligne entière pour cocher/décocher la case de sélection
|
||||
document.querySelectorAll('table tbody tr').forEach(function (tr) {
|
||||
var cb = tr.querySelector('.bulk-check');
|
||||
if (!cb) { return; }
|
||||
tr.style.cursor = 'pointer';
|
||||
tr.addEventListener('click', function (e) {
|
||||
if (e.target.closest('a, button, input, label')) { return; }
|
||||
cb.checked = !cb.checked;
|
||||
if (checkAll) {
|
||||
var total = document.querySelectorAll('.bulk-check').length;
|
||||
var checked = document.querySelectorAll('.bulk-check:checked').length;
|
||||
checkAll.checked = total > 0 && checked === total;
|
||||
checkAll.indeterminate = checked > 0 && checked < total;
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
// Indicateurs de traitement formulaire SMTP (config + tester connexion)
|
||||
var smtpForm = document.getElementById('smtp-config-form');
|
||||
if (smtpForm) {
|
||||
@@ -45,4 +72,60 @@ document.addEventListener('DOMContentLoaded', function () {
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
// Suppression groupée avec confirmation (remplace onclick inline)
|
||||
var bulkDeleteBtn = document.getElementById('bulk-delete-btn');
|
||||
if (bulkDeleteBtn) {
|
||||
bulkDeleteBtn.addEventListener('click', function (e) {
|
||||
var checked = document.querySelectorAll('.bulk-check:checked').length;
|
||||
if (checked === 0) { e.preventDefault(); return; }
|
||||
var msg = bulkDeleteBtn.getAttribute('data-confirm-bulk') || 'Confirmer ?';
|
||||
if (!window.confirm(msg)) { e.preventDefault(); }
|
||||
});
|
||||
}
|
||||
|
||||
// Ajout d'un article à un livre (remplace onchange="bookAddArticle(this)")
|
||||
var bookArticleSel = document.getElementById('book-article-select');
|
||||
if (bookArticleSel) {
|
||||
bookArticleSel.addEventListener('change', function () {
|
||||
var slug = bookArticleSel.value;
|
||||
if (!slug) { return; }
|
||||
var ta = document.getElementById('book-articles-ta');
|
||||
var lines = ta.value.split('\n').map(function (s) { return s.trim(); }).filter(Boolean);
|
||||
if (lines.indexOf(slug) === -1) { lines.push(slug); ta.value = lines.join('\n'); }
|
||||
bookArticleSel.value = '';
|
||||
});
|
||||
|
||||
// Filtre texte en temps réel pour le sélecteur d'articles
|
||||
var bookFilter = document.getElementById('book-article-filter');
|
||||
if (bookFilter) {
|
||||
var bookOptions = Array.from(bookArticleSel.options);
|
||||
bookFilter.addEventListener('input', function () {
|
||||
var q = bookFilter.value.trim().toLowerCase();
|
||||
bookArticleSel.innerHTML = '';
|
||||
bookOptions.forEach(function (opt) {
|
||||
if (opt.value === '' || q === '' || opt.textContent.toLowerCase().includes(q)) {
|
||||
bookArticleSel.appendChild(opt.cloneNode(true));
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
// Slug auto pour la création d'un livre
|
||||
var newBookTitle = document.getElementById('new-book-title');
|
||||
var newBookSlugPreview = document.getElementById('new-book-slug-preview');
|
||||
var newBookSlugHidden = document.getElementById('new-book-slug-hidden');
|
||||
if (newBookTitle && newBookSlugPreview && newBookSlugHidden) {
|
||||
function toBookSlug(s) {
|
||||
var map = { 'à':'a','â':'a','ä':'a','é':'e','è':'e','ê':'e','ë':'e','î':'i','ï':'i','ô':'o','ö':'o','ù':'u','û':'u','ü':'u','ç':'c','æ':'ae','œ':'oe' };
|
||||
s = s.toLowerCase().replace(/[àâäéèêëîïôöùûüçæœ]/g, function (c) { return map[c] || c; });
|
||||
return s.replace(/[^a-z0-9]+/g, '-').replace(/^-|-$/g, '');
|
||||
}
|
||||
newBookTitle.addEventListener('input', function () {
|
||||
var slug = toBookSlug(newBookTitle.value);
|
||||
newBookSlugPreview.value = slug;
|
||||
newBookSlugHidden.value = slug;
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
@@ -0,0 +1,78 @@
|
||||
// ai-editor.js — bouton IA dans la sidebar éditeur
|
||||
document.addEventListener('DOMContentLoaded', function () {
|
||||
var btnAnalyze = document.getElementById('btn-ai-analyze');
|
||||
if (!btnAnalyze) return;
|
||||
|
||||
var panel = document.getElementById('ai-result-panel');
|
||||
var critiqueEl = document.getElementById('ai-critique-content');
|
||||
var rewriteEl = document.getElementById('ai-rewrite-content');
|
||||
var btnApply = document.getElementById('btn-ai-apply');
|
||||
var btnClose = document.getElementById('btn-ai-close');
|
||||
var ta = document.getElementById('wz-content') || document.getElementById('content');
|
||||
var titleEl = document.getElementById('title');
|
||||
|
||||
var lastRewrite = '';
|
||||
|
||||
btnAnalyze.addEventListener('click', async function () {
|
||||
btnAnalyze.disabled = true;
|
||||
btnAnalyze._origText = btnAnalyze.textContent;
|
||||
btnAnalyze.textContent = 'En cours…';
|
||||
panel.style.display = 'none';
|
||||
lastRewrite = '';
|
||||
|
||||
try {
|
||||
var titleVal = titleEl ? titleEl.value : '';
|
||||
if (!titleVal && ta) {
|
||||
var m = ta.value.match(/^#\s+(.+)/m);
|
||||
if (m) { titleVal = m[1].trim(); }
|
||||
}
|
||||
|
||||
var res = await fetch('/?action=ai_query', {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/x-www-form-urlencoded' },
|
||||
body: new URLSearchParams({
|
||||
action: 'analyze',
|
||||
title: titleVal,
|
||||
content: ta ? ta.value : '',
|
||||
}),
|
||||
});
|
||||
var data = await res.json();
|
||||
|
||||
if (!data.ok) {
|
||||
critiqueEl.textContent = data.error || 'Erreur inconnue.';
|
||||
rewriteEl.textContent = '';
|
||||
btnApply.style.display = 'none';
|
||||
} else {
|
||||
critiqueEl.textContent = data.critique || '';
|
||||
rewriteEl.textContent = data.rewrite || '';
|
||||
lastRewrite = data.rewrite || '';
|
||||
btnApply.style.display = lastRewrite ? '' : 'none';
|
||||
}
|
||||
panel.style.display = '';
|
||||
} catch (e) {
|
||||
critiqueEl.textContent = 'Erreur de connexion.';
|
||||
rewriteEl.textContent = '';
|
||||
btnApply.style.display = 'none';
|
||||
panel.style.display = '';
|
||||
} finally {
|
||||
btnAnalyze.disabled = false;
|
||||
btnAnalyze.textContent = btnAnalyze._origText;
|
||||
}
|
||||
});
|
||||
|
||||
btnApply.addEventListener('click', function () {
|
||||
if (!lastRewrite) return;
|
||||
if (!confirm("Remplacer le contenu de l'éditeur par la proposition IA ?")) return;
|
||||
if (ta) {
|
||||
ta.value = lastRewrite;
|
||||
ta.dispatchEvent(new Event('input'));
|
||||
}
|
||||
panel.style.display = 'none';
|
||||
lastRewrite = '';
|
||||
});
|
||||
|
||||
btnClose.addEventListener('click', function () {
|
||||
panel.style.display = 'none';
|
||||
lastRewrite = '';
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,24 @@
|
||||
document.addEventListener('DOMContentLoaded', function () {
|
||||
var maxAge = 365 * 24 * 3600;
|
||||
function getCookie(name) {
|
||||
var m = document.cookie.match('(?:^|; )' + name + '=([^;]*)');
|
||||
return m ? decodeURIComponent(m[1]) : '';
|
||||
}
|
||||
function setCookie(name, value) {
|
||||
document.cookie = name + '=' + encodeURIComponent(value) + ';max-age=' + maxAge + ';path=/;SameSite=Lax';
|
||||
}
|
||||
var nameEl = document.getElementById('comment-name');
|
||||
var emailEl = document.getElementById('comment-email');
|
||||
if (!nameEl || !emailEl) { return; }
|
||||
var savedName = getCookie('cmt_name');
|
||||
var savedEmail = getCookie('cmt_email');
|
||||
if (savedName) { nameEl.value = savedName; }
|
||||
if (savedEmail) { emailEl.value = savedEmail; }
|
||||
var form = document.getElementById('comment-form');
|
||||
if (form) {
|
||||
form.addEventListener('submit', function () {
|
||||
if (nameEl.value.trim()) { setCookie('cmt_name', nameEl.value.trim()); }
|
||||
if (emailEl.value.trim()) { setCookie('cmt_email', emailEl.value.trim()); }
|
||||
});
|
||||
}
|
||||
});
|
||||
@@ -0,0 +1,11 @@
|
||||
/* Anti-FOUC densité — chargé tôt dans <head> pour appliquer max-width avant rendu de <main> */
|
||||
(function () {
|
||||
var d = localStorage.getItem('folio_density') || 'm';
|
||||
if (d !== 'l') {
|
||||
var mw = d === 'm' ? '980px' : '660px';
|
||||
var s = document.createElement('style');
|
||||
s.id = 'density-fouc';
|
||||
s.textContent = 'main[role="main"]{max-width:' + mw + '!important;margin-left:auto!important;margin-right:auto!important}';
|
||||
document.head.appendChild(s);
|
||||
}
|
||||
}());
|
||||
@@ -0,0 +1,38 @@
|
||||
/* Sélecteur de densité L/M/S — persisté dans localStorage */
|
||||
(function () {
|
||||
var KEY = 'folio_density';
|
||||
var cur = localStorage.getItem(KEY) || 'm';
|
||||
|
||||
function applyDensity(d) {
|
||||
var fouc = document.getElementById('density-fouc');
|
||||
if (d !== 'l') {
|
||||
var mw = d === 'm' ? '980px' : '660px';
|
||||
if (!fouc) {
|
||||
fouc = document.createElement('style');
|
||||
fouc.id = 'density-fouc';
|
||||
document.head.appendChild(fouc);
|
||||
}
|
||||
fouc.textContent = 'main[role="main"]{max-width:' + mw + '!important;margin-left:auto!important;margin-right:auto!important}';
|
||||
} else {
|
||||
if (fouc) { fouc.parentNode.removeChild(fouc); }
|
||||
}
|
||||
document.querySelectorAll('.density-btn').forEach(function (btn) {
|
||||
btn.classList.toggle('active', btn.getAttribute('data-d') === d);
|
||||
});
|
||||
}
|
||||
|
||||
applyDensity(cur);
|
||||
|
||||
document.addEventListener('click', function (e) {
|
||||
var el = e.target;
|
||||
while (el && el !== document) {
|
||||
if (el.classList && el.classList.contains('density-btn')) {
|
||||
cur = el.getAttribute('data-d') || 'l';
|
||||
try { localStorage.setItem(KEY, cur); } catch (ignore) {}
|
||||
applyDensity(cur);
|
||||
return;
|
||||
}
|
||||
el = el.parentNode;
|
||||
}
|
||||
});
|
||||
}());
|
||||
@@ -22,12 +22,14 @@ document.addEventListener('DOMContentLoaded', function () {
|
||||
initCounter('seo_description', 'seo_desc_counter', 155);
|
||||
|
||||
function updatePreview() {
|
||||
var seoTitle = document.getElementById('seo_title').value.trim();
|
||||
var seoDesc = document.getElementById('seo_description').value.trim();
|
||||
var slug = document.getElementById('confirm-slug').value.trim();
|
||||
var seoTitle = document.getElementById('seo_title').value.trim();
|
||||
var seoDesc = document.getElementById('seo_description').value.trim();
|
||||
var slugEl = document.getElementById('confirm-slug');
|
||||
document.getElementById('preview-title').textContent = seoTitle || defaultTitle;
|
||||
document.getElementById('preview-desc').textContent = seoDesc || defaultDesc;
|
||||
document.getElementById('preview-url').textContent = baseUrl + slug;
|
||||
if (slugEl) {
|
||||
document.getElementById('preview-url').textContent = baseUrl + slugEl.value.trim();
|
||||
}
|
||||
}
|
||||
|
||||
['seo_title', 'seo_description', 'confirm-slug'].forEach(function (id) {
|
||||
@@ -38,8 +40,14 @@ document.addEventListener('DOMContentLoaded', function () {
|
||||
var slugInput = document.getElementById('confirm-slug');
|
||||
var slugDisplay = document.getElementById('slug-display');
|
||||
|
||||
if (slugInput && slugDisplay) {
|
||||
slugInput.addEventListener('input', function () {
|
||||
slugDisplay.textContent = slugInput.value;
|
||||
});
|
||||
}
|
||||
|
||||
var btnSuggest = document.getElementById('slug-btn-suggest');
|
||||
if (btnSuggest) {
|
||||
if (btnSuggest && slugInput && slugDisplay) {
|
||||
btnSuggest.addEventListener('click', function () {
|
||||
var val = btnSuggest.dataset.slugSuggest;
|
||||
slugInput.value = val;
|
||||
@@ -49,7 +57,7 @@ document.addEventListener('DOMContentLoaded', function () {
|
||||
}
|
||||
|
||||
var btnKeep = document.getElementById('slug-btn-keep');
|
||||
if (btnKeep) {
|
||||
if (btnKeep && slugInput && slugDisplay) {
|
||||
btnKeep.addEventListener('click', function () {
|
||||
var val = btnKeep.dataset.slugKeep;
|
||||
slugInput.value = val;
|
||||
|
||||
@@ -0,0 +1,40 @@
|
||||
(function () {
|
||||
'use strict';
|
||||
|
||||
var bar = document.getElementById('share-bar');
|
||||
if (!bar) { return; }
|
||||
|
||||
var url = bar.getAttribute('data-url') || window.location.href;
|
||||
var title = bar.getAttribute('data-title') || document.title;
|
||||
|
||||
var copyBtn = document.getElementById('share-copy');
|
||||
if (copyBtn) {
|
||||
copyBtn.addEventListener('click', function () {
|
||||
if (!navigator.clipboard) {
|
||||
var ta = document.createElement('textarea');
|
||||
ta.value = url;
|
||||
document.body.appendChild(ta);
|
||||
ta.select();
|
||||
document.execCommand('copy');
|
||||
document.body.removeChild(ta);
|
||||
copyBtn.textContent = 'Copié !';
|
||||
setTimeout(function () { copyBtn.textContent = 'Copier le lien'; }, 2000);
|
||||
return;
|
||||
}
|
||||
navigator.clipboard.writeText(url).then(function () {
|
||||
copyBtn.textContent = 'Copié !';
|
||||
setTimeout(function () { copyBtn.textContent = 'Copier le lien'; }, 2000);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
var nativeBtn = document.getElementById('share-native');
|
||||
if (nativeBtn) {
|
||||
if (navigator.share) {
|
||||
nativeBtn.hidden = false;
|
||||
nativeBtn.addEventListener('click', function () {
|
||||
navigator.share({ title: title, url: url }).catch(function () {});
|
||||
});
|
||||
}
|
||||
}
|
||||
}());
|
||||
@@ -0,0 +1,51 @@
|
||||
/* Chargement AJAX de la section "Meilleures audiences" via le flux RSS XML /trending?period=1h */
|
||||
(function () {
|
||||
var grid = document.getElementById('home-audiences-grid');
|
||||
if (!grid) { return; }
|
||||
|
||||
var gradients = [
|
||||
'linear-gradient(135deg,#667eea 0%,#764ba2 100%)',
|
||||
'linear-gradient(135deg,#f093fb 0%,#f5576c 100%)',
|
||||
'linear-gradient(135deg,#4facfe 0%,#00f2fe 100%)',
|
||||
'linear-gradient(135deg,#43e97b 0%,#38f9d7 100%)',
|
||||
'linear-gradient(135deg,#fa709a 0%,#fee140 100%)',
|
||||
'linear-gradient(135deg,#a18cd1 0%,#fbc2eb 100%)'
|
||||
];
|
||||
|
||||
function esc(s) {
|
||||
return String(s).replace(/&/g, '&').replace(/</g, '<').replace(/>/g, '>').replace(/"/g, '"');
|
||||
}
|
||||
|
||||
fetch('/trending?period=1h')
|
||||
.then(function (r) { return r.ok ? r.text() : Promise.reject(); })
|
||||
.then(function (xml) {
|
||||
var doc = new DOMParser().parseFromString(xml, 'application/xml');
|
||||
var items = Array.from(doc.querySelectorAll('item')).slice(0, 6);
|
||||
if (!items.length) { return; }
|
||||
|
||||
grid.innerHTML = items.map(function (item, i) {
|
||||
var raw = (item.querySelector('title') || { textContent: '' }).textContent;
|
||||
var title = raw.replace(/\s*\(\d+\s+visiteurs?\)$/, '');
|
||||
var link = ((item.querySelector('link') || {}).textContent || '#').trim();
|
||||
var pd = (item.querySelector('pubDate') || { textContent: '' }).textContent;
|
||||
var date = '';
|
||||
try { if (pd) { date = new Date(pd).toLocaleDateString('fr-FR'); } } catch (err) {}
|
||||
var grad = gradients[i % gradients.length];
|
||||
|
||||
return '<article class="card">'
|
||||
+ '<div class="card-cover" style="background:' + grad + '"></div>'
|
||||
+ '<div class="card-body d-flex flex-column">'
|
||||
+ '<h2 class="card-title"><a href="' + esc(link) + '">' + esc(title) + '</a></h2>'
|
||||
+ '<div class="post-entry-meta mt-auto">'
|
||||
+ (date ? '<span>' + esc(date) + '</span>' : '')
|
||||
+ '<a href="' + esc(link) + '" class="post-entry-read">→ lire</a>'
|
||||
+ '</div></div>'
|
||||
+ '<a href="' + esc(link) + '" class="stretched-link"></a>'
|
||||
+ '</article>';
|
||||
}).join('');
|
||||
|
||||
var section = document.getElementById('home-audiences-section');
|
||||
if (section) { section.hidden = false; }
|
||||
})
|
||||
.catch(function () {});
|
||||
}());
|
||||
+41
-16
@@ -12,21 +12,28 @@ require_once BASE_PATH . '/src/Parsedown.php';
|
||||
|
||||
const FEED_PAGE_SIZE = 20;
|
||||
|
||||
$articles = new ArticleManager(BASE_PATH . '/data');
|
||||
$articles = new ArticleManager(DATA_PATH);
|
||||
$privateCats = $articles->getPrivateCategories();
|
||||
$Parsedown = new Parsedown();
|
||||
|
||||
$now = time();
|
||||
$base = rtrim(APP_URL, '/');
|
||||
$now = time();
|
||||
$base = rtrim(APP_URL, '/');
|
||||
$filterCat = trim($_GET['category'] ?? '');
|
||||
|
||||
$all = array_values(array_filter(
|
||||
$articles->getAll(publishedOnly: true),
|
||||
static function (array $a) use ($now, $privateCats): bool {
|
||||
static function (array $a) use ($now, $privateCats, $filterCat): bool {
|
||||
if (strtotime((string)($a['published_at'] ?? '')) > $now) {
|
||||
return false;
|
||||
}
|
||||
$cat = trim($a['category'] ?? '');
|
||||
return $cat === '' || !in_array($cat, $privateCats, true);
|
||||
if ($cat !== '' && in_array($cat, $privateCats, true)) {
|
||||
return false;
|
||||
}
|
||||
if ($filterCat !== '' && $cat !== $filterCat) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
));
|
||||
|
||||
@@ -42,13 +49,16 @@ if ($after !== '') {
|
||||
}
|
||||
}
|
||||
|
||||
$items = array_slice($all, $offset, FEED_PAGE_SIZE);
|
||||
$items = array_slice($all, $offset, FEED_PAGE_SIZE);
|
||||
$nextCursor = (count($all) > $offset + FEED_PAGE_SIZE)
|
||||
? ($all[$offset + FEED_PAGE_SIZE - 1]['uuid'] ?? null)
|
||||
: null;
|
||||
|
||||
$feedUrl = $base . '/feed';
|
||||
$feedNextUrl = $nextCursor !== null ? $base . '/feed/' . $nextCursor : null;
|
||||
$feedUrl = $base . '/feed' . ($filterCat !== '' ? '?category=' . rawurlencode($filterCat) : '');
|
||||
$feedNextUrl = $nextCursor !== null ? $base . '/feed/' . $nextCursor . ($filterCat !== '' ? '?category=' . rawurlencode($filterCat) : '') : null;
|
||||
|
||||
$channelTitle = siteTitle() . ($filterCat !== '' ? ' — ' . $filterCat : '');
|
||||
$channelDesc = $filterCat !== '' ? 'Articles de la catégorie « ' . $filterCat . ' »' : siteClaim();
|
||||
|
||||
// ─── lastBuildDate ───────────────────────────────────────────────────────────
|
||||
$lastBuild = '';
|
||||
@@ -69,11 +79,13 @@ echo '<?xml version="1.0" encoding="UTF-8"?>' . "\n";
|
||||
?>
|
||||
<rss version="2.0"
|
||||
xmlns:atom="http://www.w3.org/2005/Atom"
|
||||
xmlns:content="http://purl.org/rss/1.0/modules/content/"
|
||||
xmlns:media="http://search.yahoo.com/mrss/"
|
||||
xmlns:fh="http://purl.org/syndication/history/1.0">
|
||||
<channel>
|
||||
<title><?= htmlspecialchars(siteTitle()) ?></title>
|
||||
<title><?= htmlspecialchars($channelTitle) ?></title>
|
||||
<link><?= htmlspecialchars($base) ?></link>
|
||||
<description><?= htmlspecialchars(siteClaim()) ?></description>
|
||||
<description><?= htmlspecialchars($channelDesc) ?></description>
|
||||
<language><?= htmlspecialchars(siteLang()) ?></language>
|
||||
<lastBuildDate><?= htmlspecialchars($lastBuild) ?></lastBuildDate>
|
||||
|
||||
@@ -91,17 +103,30 @@ echo '<?xml version="1.0" encoding="UTF-8"?>' . "\n";
|
||||
<?php endif; ?>
|
||||
|
||||
<?php foreach ($items as $article):
|
||||
$pubDate = date(DATE_RSS, (int)strtotime((string)($article['published_at'] ?? $article['created_at'] ?? '')));
|
||||
$link = $base . '/post/' . rawurlencode($article['slug'] ?? '');
|
||||
$title = htmlspecialchars($article['title'] ?? '', ENT_XML1);
|
||||
$plain = preg_replace('/\s+/', ' ', strip_tags($Parsedown->text($article['content'] ?? '')));
|
||||
$desc = htmlspecialchars(mb_strimwidth(trim((string)$plain), 0, 300, '…'), ENT_XML1);
|
||||
$guid = htmlspecialchars($base . '/post/' . rawurlencode($article['slug'] ?? ''), ENT_XML1);
|
||||
$pubDate = date(DATE_RSS, (int)strtotime((string)($article['published_at'] ?? $article['created_at'] ?? '')));
|
||||
$link = $base . '/post/' . rawurlencode($article['slug'] ?? '');
|
||||
$title = htmlspecialchars($article['title'] ?? '', ENT_XML1);
|
||||
$plain = preg_replace('/\s+/', ' ', trim($article['plain'] ?? ''));
|
||||
$desc = htmlspecialchars(mb_strimwidth($plain, 0, 300, '…'), ENT_XML1);
|
||||
$guid = htmlspecialchars($base . '/post/' . rawurlencode($article['slug'] ?? ''), ENT_XML1);
|
||||
$mdPath = DATA_PATH . '/' . ($article['uuid'] ?? '') . '/index.md';
|
||||
$rawMd = file_exists($mdPath) ? (string)file_get_contents($mdPath) : '';
|
||||
$fullHtml = $rawMd !== '' ? $Parsedown->text($rawMd) : '';
|
||||
$imgUrl = trim($article['og_image'] ?? '');
|
||||
if ($imgUrl === '' && ($article['cover'] ?? '') !== '') {
|
||||
$imgUrl = $base . '/file?uuid=' . rawurlencode($article['uuid']) . '&name=' . rawurlencode($article['cover']);
|
||||
}
|
||||
?>
|
||||
<item>
|
||||
<title><?= $title ?></title>
|
||||
<link><?= htmlspecialchars($link) ?></link>
|
||||
<description><?= $desc ?></description>
|
||||
<?php if ($fullHtml !== ''): ?>
|
||||
<content:encoded><![CDATA[<?= $fullHtml ?>]]></content:encoded>
|
||||
<?php endif; ?>
|
||||
<?php if ($imgUrl !== ''): ?>
|
||||
<media:thumbnail url="<?= htmlspecialchars($imgUrl, ENT_XML1) ?>"/>
|
||||
<?php endif; ?>
|
||||
<pubDate><?= htmlspecialchars($pubDate) ?></pubDate>
|
||||
<guid isPermaLink="true"><?= $guid ?></guid>
|
||||
</item>
|
||||
|
||||
+4
-1
@@ -4,6 +4,9 @@ declare(strict_types=1);
|
||||
|
||||
define('BASE_PATH', realpath(__DIR__ . '/../'));
|
||||
|
||||
require_once BASE_PATH . '/vendor/autoload.php';
|
||||
require_once BASE_PATH . '/config/config.php';
|
||||
|
||||
$uuid = $_GET['uuid'] ?? '';
|
||||
$name = $_GET['name'] ?? '';
|
||||
|
||||
@@ -20,7 +23,7 @@ if ($name === '' || $name[0] === '.') {
|
||||
exit;
|
||||
}
|
||||
|
||||
$path = BASE_PATH . '/data/' . $uuid . '/files/' . $name;
|
||||
$path = DATA_PATH . '/' . $uuid . '/files/' . $name;
|
||||
|
||||
if (!is_file($path)) {
|
||||
http_response_code(404);
|
||||
|
||||
+508
-107
@@ -24,12 +24,14 @@ require_once BASE_PATH . '/src/auth.php';
|
||||
require_once BASE_PATH . '/src/SiteSettings.php';
|
||||
require_once BASE_PATH . '/src/ArticleManager.php';
|
||||
require_once BASE_PATH . '/src/BookManager.php';
|
||||
require_once BASE_PATH . '/src/DataGit.php';
|
||||
|
||||
$articles = new ArticleManager(BASE_PATH . '/data');
|
||||
$books = new BookManager(BASE_PATH . '/data/books');
|
||||
$_dataGit = new DataGit(DATA_PATH);
|
||||
$articles = new ArticleManager(DATA_PATH, $_dataGit);
|
||||
$books = new BookManager(DATA_PATH . '/books', $_dataGit);
|
||||
|
||||
// ─── Mode maintenance ──────────────────────────────────────────────────────
|
||||
if (file_exists(BASE_PATH . '/data/.maintenance')) {
|
||||
if (file_exists(DATA_PATH . '/.maintenance')) {
|
||||
http_response_code(503);
|
||||
header('Retry-After: 60');
|
||||
include BASE_PATH . '/templates/maintenance.php';
|
||||
@@ -37,23 +39,64 @@ if (file_exists(BASE_PATH . '/data/.maintenance')) {
|
||||
}
|
||||
|
||||
require_once BASE_PATH . '/src/UpdateChecker.php';
|
||||
$_updateChecker = new UpdateChecker(BASE_PATH . '/data', BASE_PATH);
|
||||
$_updateChecker = new UpdateChecker(DATA_PATH, BASE_PATH);
|
||||
|
||||
$action = $_GET['action'] ?? 'list';
|
||||
$uuid = $_GET['uuid'] ?? '';
|
||||
$slug = $_GET['slug'] ?? '';
|
||||
|
||||
$_noindexActions = ['create', 'edit', 'admin', 'categories', 'diff', 'add_files', 'import_image', 'import_image_step2', 'sources', 'profile', 'delete_file', 'delete_external_link', 'rename_category', 'delete_category', 'toggle_private_category', 'admin_save_site', 'not_found', 'add_feed', 'delete_feed', 'add_link', 'delete_link', 'reorder_links', 'react', 'comment', 'verify_comment', 'comment_moderate', 'comment_delete', 'comment_resend', 'create_tag_type', 'delete_tag_type', 'edit_tags', 'book_save', 'book_delete', 'admin_save_as_groups'];
|
||||
$_noindexActions = ['create', 'edit', 'admin', 'categories', 'diff', 'add_files', 'import_image', 'import_image_step2', 'sources', 'profile', 'delete_file', 'delete_external_link', 'rename_category', 'delete_category', 'toggle_private_category', 'admin_save_site', 'not_found', 'add_feed', 'delete_feed', 'add_link', 'delete_link', 'reorder_links', 'react', 'comment', 'verify_comment', 'comment_moderate', 'comment_delete', 'comment_resend', 'create_tag_type', 'delete_tag_type', 'edit_tags', 'book_save', 'book_delete', 'admin_save_as_groups', 'admin_save_folio_config', 'run_engine_update', 'run_content_migrations', 'admin_delete_feed', 'rate', 'admin_save_ai_config'];
|
||||
$metaRobots = in_array($action, $_noindexActions, true) ? 'noindex, nofollow' : null;
|
||||
unset($_noindexActions);
|
||||
|
||||
// ─── Recherche de l'article le plus proche et redirection 301 ────────────────
|
||||
function log404(string $url): void
|
||||
{
|
||||
if (!defined('DATA_PATH')) {
|
||||
return;
|
||||
}
|
||||
$logDir = DATA_PATH . '/_logs';
|
||||
$logFile = $logDir . '/not_found.jsonl';
|
||||
if (!is_dir($logDir)) {
|
||||
@mkdir($logDir, 0755, true);
|
||||
}
|
||||
$entry = json_encode([
|
||||
'ts' => date('Y-m-d H:i:s'),
|
||||
'url' => $url,
|
||||
'ref' => $_SERVER['HTTP_REFERER'] ?? '',
|
||||
'ua' => $_SERVER['HTTP_USER_AGENT'] ?? '',
|
||||
], JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES) . "\n";
|
||||
@file_put_contents($logFile, $entry, FILE_APPEND | LOCK_EX);
|
||||
}
|
||||
|
||||
function buildAutoSeoDesc(string $content, string $title = ''): string
|
||||
{
|
||||
require_once BASE_PATH . '/src/Parsedown.php';
|
||||
$_pd = new Parsedown();
|
||||
$_plain = trim((string)preg_replace(
|
||||
'/\s+/',
|
||||
' ',
|
||||
html_entity_decode(strip_tags($_pd->text($content)), ENT_QUOTES | ENT_HTML5, 'UTF-8')
|
||||
));
|
||||
if ($title !== '' && stripos($_plain, $title) === 0) {
|
||||
$_plain = ltrim(substr($_plain, strlen($title)));
|
||||
}
|
||||
return mb_strimwidth($_plain, 0, 155, '…');
|
||||
}
|
||||
|
||||
function slugToSearchQuery(string $rawPath): string
|
||||
{
|
||||
return trim((string)preg_replace('/\s{2,}/', ' ', (string)preg_replace(
|
||||
'/[^a-zA-ZÀ-ÿ0-9\s]/u',
|
||||
' ',
|
||||
str_replace(['-', '_', '/'], ' ', $rawPath)
|
||||
)));
|
||||
}
|
||||
|
||||
function searchAndRedirect(string $rawPath, ArticleManager $articles): void
|
||||
{
|
||||
require_once BASE_PATH . '/src/SearchEngine.php';
|
||||
$query = (string)preg_replace('/\s{2,}/', ' ', trim(
|
||||
(string)preg_replace('/[^a-zA-ZÀ-ÿ0-9\s]/u', ' ', str_replace(['-', '_', '/'], ' ', $rawPath))
|
||||
));
|
||||
$query = slugToSearchQuery($rawPath);
|
||||
if ($query === '') {
|
||||
return;
|
||||
}
|
||||
@@ -78,7 +121,7 @@ function searchAndRedirect(string $rawPath, ArticleManager $articles): void
|
||||
// ─── Pages statiques depuis data/site/ ──────────────────────────────────────
|
||||
function loadSitePageData(string $slug): array
|
||||
{
|
||||
$base = BASE_PATH . '/data/site';
|
||||
$base = DATA_PATH . '/site';
|
||||
$meta = [];
|
||||
$raw = @file_get_contents($base . '/' . $slug . '.json');
|
||||
if ($raw !== false) {
|
||||
@@ -627,10 +670,7 @@ switch ($action) {
|
||||
header('Location: /new');
|
||||
exit;
|
||||
}
|
||||
require_once BASE_PATH . '/src/Parsedown.php';
|
||||
$_pd = new Parsedown();
|
||||
$autoSeoDesc = mb_strimwidth(trim((string)preg_replace('/\s+/', ' ', strip_tags($_pd->text((string)($draft['content'] ?? ''))))), 0, 155, '…');
|
||||
unset($_pd);
|
||||
$autoSeoDesc = buildAutoSeoDesc((string)($draft['content'] ?? ''), trim($draft['title'] ?? ''));
|
||||
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
||||
$seoTitle = trim($_POST['seo_title'] ?? '');
|
||||
$seoDesc = trim($_POST['seo_description'] ?? '') ?: $autoSeoDesc;
|
||||
@@ -664,16 +704,15 @@ switch ($action) {
|
||||
case 'view':
|
||||
$article = $slug !== '' ? $articles->getBySlug($slug) : null;
|
||||
if (!$article) {
|
||||
searchAndRedirect($slug, $articles);
|
||||
http_response_code(404);
|
||||
echo 'Article introuvable.';
|
||||
$q = slugToSearchQuery($slug);
|
||||
header('Location: /search' . ($q !== '' ? '?q=' . urlencode($q) : ''), true, 302);
|
||||
exit;
|
||||
}
|
||||
|
||||
if (!$article['published']) {
|
||||
if (!canDoOnArticle('view_drafts', $article)) {
|
||||
http_response_code(404);
|
||||
echo 'Article introuvable.';
|
||||
include BASE_PATH . '/templates/404.php';
|
||||
exit;
|
||||
}
|
||||
}
|
||||
@@ -682,7 +721,7 @@ switch ($action) {
|
||||
if ($article['published'] && strtotime((string)($article['published_at'] ?? '')) > time()) {
|
||||
if (!hasCapability('view_previews')) {
|
||||
http_response_code(404);
|
||||
echo 'Article introuvable.';
|
||||
include BASE_PATH . '/templates/404.php';
|
||||
exit;
|
||||
}
|
||||
}
|
||||
@@ -694,10 +733,33 @@ switch ($action) {
|
||||
$isPrivateCat = $articleCat !== '' && in_array($articleCat, $privateCats, true);
|
||||
if ($isPrivateCat && !isLoggedIn()) {
|
||||
http_response_code(404);
|
||||
echo 'Article introuvable.';
|
||||
include BASE_PATH . '/templates/404.php';
|
||||
exit;
|
||||
}
|
||||
|
||||
// Cache HTTP : Last-Modified + 304 pour les articles publiés
|
||||
if ($article['published']) {
|
||||
$_uuid = $article['uuid'] ?? '';
|
||||
$_mdFile = DATA_PATH . '/' . $_uuid . '/index.md';
|
||||
$_mfFile = DATA_PATH . '/' . $_uuid . '/meta.json';
|
||||
$_lm = max(
|
||||
is_file($_mdFile) ? (int)filemtime($_mdFile) : 0,
|
||||
is_file($_mfFile) ? (int)filemtime($_mfFile) : 0
|
||||
);
|
||||
if ($_lm > 0) {
|
||||
header('Last-Modified: ' . gmdate('D, d M Y H:i:s', $_lm) . ' GMT');
|
||||
header('Cache-Control: public, max-age=60');
|
||||
$ifModSince = isset($_SERVER['HTTP_IF_MODIFIED_SINCE'])
|
||||
? strtotime($_SERVER['HTTP_IF_MODIFIED_SINCE'])
|
||||
: false;
|
||||
if ($ifModSince !== false && $_lm <= $ifModSince) {
|
||||
http_response_code(304);
|
||||
exit;
|
||||
}
|
||||
}
|
||||
unset($_uuid, $_mdFile, $_mfFile, $_lm, $ifModSince);
|
||||
}
|
||||
|
||||
$files = $articles->getFiles($article['uuid']);
|
||||
|
||||
// Résout les chemins de fichiers relatifs dans le contenu
|
||||
@@ -959,17 +1021,21 @@ switch ($action) {
|
||||
|
||||
case 5:
|
||||
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
||||
$articles->saveDraftOverlay($uuid, [
|
||||
$overlayFields = [
|
||||
'seo_title' => trim($_POST['seo_title'] ?? ''),
|
||||
'seo_description' => trim($_POST['seo_description'] ?? ''),
|
||||
]);
|
||||
];
|
||||
$coverFile = trim($_POST['cover_file'] ?? '');
|
||||
if ($coverFile !== '' && $coverFile !== ($draft['cover'] ?? '')) {
|
||||
$articles->setCover($uuid, $coverFile);
|
||||
$updatedCover = $articles->getByUuid($uuid)['cover'] ?? $coverFile;
|
||||
$overlayFields['og_image'] = rtrim(APP_URL, '/') . '/file?uuid=' . rawurlencode($uuid) . '&name=' . rawurlencode($updatedCover);
|
||||
}
|
||||
$articles->saveDraftOverlay($uuid, $overlayFields);
|
||||
header('Location: /edit/' . rawurlencode($uuid) . '/6');
|
||||
exit;
|
||||
}
|
||||
require_once BASE_PATH . '/src/Parsedown.php';
|
||||
$_pd = new Parsedown();
|
||||
$autoSeoDesc = mb_strimwidth(trim((string)preg_replace('/\s+/', ' ', strip_tags($_pd->text((string)($draft['content'] ?? ''))))), 0, 155, '…');
|
||||
unset($_pd);
|
||||
$autoSeoDesc = buildAutoSeoDesc((string)($draft['content'] ?? ''), trim($draft['title'] ?? ''));
|
||||
$title = $draft['title'];
|
||||
$seoTitle = $draft['seo_title'] ?? '';
|
||||
$seoDescription = $draft['seo_description'] ?? '';
|
||||
@@ -977,29 +1043,23 @@ switch ($action) {
|
||||
$published = (bool)($draft['published'] ?? false);
|
||||
$published_at = $draft['published_at'] ?? '';
|
||||
$category = $draft['category'] ?? '';
|
||||
$existingFiles = $articles->getFiles($uuid);
|
||||
$article = $draft;
|
||||
include BASE_PATH . '/templates/wizard/step5.php';
|
||||
break;
|
||||
|
||||
case 6:
|
||||
if ($_SERVER['REQUEST_METHOD'] === 'POST' && !empty($_POST['_confirm'])) {
|
||||
$revisionComment = trim($_POST['revision_comment'] ?? '');
|
||||
// Si le slug a été modifié dans le formulaire de confirmation, le propager
|
||||
if (!empty($_POST['slug'])) {
|
||||
$articles->saveDraftOverlay($uuid, ['slug' => trim($_POST['slug'])]);
|
||||
}
|
||||
$articles->commitDraftOverlay($uuid, $revisionComment);
|
||||
$final = $articles->getByUuid($uuid);
|
||||
header('Location: /post/' . rawurlencode($final['slug'] ?? $uuid));
|
||||
exit;
|
||||
}
|
||||
$draftData = $articles->getDraftOverlay($uuid) ?? $article;
|
||||
require_once BASE_PATH . '/src/Parsedown.php';
|
||||
$_pd = new Parsedown();
|
||||
$autoSeoDesc = mb_strimwidth(trim((string)preg_replace('/\s+/', ' ', strip_tags($_pd->text((string)($draftData['content'] ?? ''))))), 0, 155, '…');
|
||||
unset($_pd);
|
||||
$autoSeoDesc = buildAutoSeoDesc((string)($draftData['content'] ?? ''), trim($draftData['title'] ?? ''));
|
||||
$diffLines = lineDiff((string)($article['content'] ?? ''), (string)($draftData['content'] ?? ''));
|
||||
$titleChanged = ($draftData['title'] ?? '') !== ($article['title'] ?? '');
|
||||
$autoSlug = slugify($draftData['title'] ?? '');
|
||||
$postSlug = $draftData['slug'] ?? $article['slug'];
|
||||
$changes = [];
|
||||
if ($titleChanged) {
|
||||
@@ -1017,6 +1077,9 @@ switch ($action) {
|
||||
if ((bool)($draftData['published'] ?? false) !== (bool)($article['published'] ?? false)) {
|
||||
$changes[] = ($draftData['published'] ?? false) ? 'article publié' : 'article dépublié';
|
||||
}
|
||||
if (($draftData['og_image'] ?? '') !== ($article['og_image'] ?? '')) {
|
||||
$changes[] = 'image de couverture modifiée';
|
||||
}
|
||||
$autoRevisionComment = !empty($changes) ? ucfirst(implode(', ', $changes)) : '';
|
||||
$title = $draftData['title'] ?? '';
|
||||
$seoTitle = $draftData['seo_title'] ?? '';
|
||||
@@ -1109,10 +1172,37 @@ switch ($action) {
|
||||
header('Location: /edit/' . rawurlencode($uuid));
|
||||
exit;
|
||||
|
||||
case 'duplicate':
|
||||
requireAuth();
|
||||
if ($uuid !== '' && $_SERVER['REQUEST_METHOD'] === 'POST') {
|
||||
$srcArticle = $articles->getByUuid($uuid);
|
||||
if (!$srcArticle) {
|
||||
header('Location: /admin/articles');
|
||||
exit;
|
||||
}
|
||||
if (!isAdmin() && ($srcArticle['author'] ?? '') !== (currentUserEmail() ?? '')) {
|
||||
http_response_code(403);
|
||||
exit;
|
||||
}
|
||||
$newUuid = $articles->duplicate($uuid, currentUserEmail() ?? '');
|
||||
if ($newUuid) {
|
||||
header('Location: /edit/' . rawurlencode($newUuid) . '/1');
|
||||
exit;
|
||||
}
|
||||
}
|
||||
header('Location: /admin/articles');
|
||||
exit;
|
||||
|
||||
case 'delete':
|
||||
requireAuth();
|
||||
if ($uuid !== '') {
|
||||
$articles->delete($uuid);
|
||||
if (!$articles->delete($uuid)) {
|
||||
$failedArt = $articles->getByUuid($uuid);
|
||||
$failedSlug = $failedArt['slug'] ?? '';
|
||||
$back = $failedSlug !== '' ? '/post/' . rawurlencode($failedSlug) : '/';
|
||||
header('Location: ' . $back . '?delete_failed=1');
|
||||
exit;
|
||||
}
|
||||
}
|
||||
header('Location: /');
|
||||
exit;
|
||||
@@ -1383,9 +1473,10 @@ switch ($action) {
|
||||
|
||||
case 'flux':
|
||||
require_once BASE_PATH . '/src/FeedFetcher.php';
|
||||
$fetcher = new FeedFetcher(BASE_PATH . '/data/_cache/feeds');
|
||||
$fluxItems = [];
|
||||
$pdo = dbPdo();
|
||||
$fetcher = new FeedFetcher(DATA_PATH . '/_cache/feeds');
|
||||
$fluxItems = [];
|
||||
$fluxErrors = [];
|
||||
$pdo = dbPdo();
|
||||
if ($pdo) {
|
||||
try {
|
||||
$st = $pdo->query(
|
||||
@@ -1398,6 +1489,11 @@ switch ($action) {
|
||||
foreach ($st->fetchAll(PDO::FETCH_ASSOC) as $_row) {
|
||||
$data = $fetcher->get($_row['feed_url']);
|
||||
if (!$data) {
|
||||
$fluxErrors[] = [
|
||||
'feed_url' => $_row['feed_url'],
|
||||
'label' => $_row['label'],
|
||||
'user_email' => $_row['user_email'],
|
||||
];
|
||||
continue;
|
||||
}
|
||||
$feedTitle = $_row['label'] !== '' ? $_row['label'] : $data['feed_title'];
|
||||
@@ -1535,8 +1631,8 @@ switch ($action) {
|
||||
echo json_encode(['ok' => false, 'error' => 'Paramètres invalides']);
|
||||
exit;
|
||||
}
|
||||
$cfSrc = BASE_PATH . '/data/' . $cfFrom . '/files/' . $cfName;
|
||||
$cfDstDir = BASE_PATH . '/data/' . $cfTo . '/files';
|
||||
$cfSrc = DATA_PATH . '/' . $cfFrom . '/files/' . $cfName;
|
||||
$cfDstDir = DATA_PATH . '/' . $cfTo . '/files';
|
||||
$cfDst = $cfDstDir . '/' . $cfName;
|
||||
if (!file_exists($cfSrc)) {
|
||||
echo json_encode(['ok' => false, 'error' => 'Fichier source introuvable']);
|
||||
@@ -1596,6 +1692,24 @@ switch ($action) {
|
||||
echo json_encode(fetchUrlMeta(trim($_GET['url'] ?? '')));
|
||||
exit;
|
||||
|
||||
case 'ai_query':
|
||||
requireAuth();
|
||||
header('Content-Type: application/json');
|
||||
if ($_SERVER['REQUEST_METHOD'] !== 'POST') {
|
||||
echo json_encode(['ok' => false, 'error' => 'Méthode invalide']);
|
||||
exit;
|
||||
}
|
||||
$_aiAction = trim($_POST['action'] ?? '');
|
||||
$_aiTitle = trim($_POST['title'] ?? '');
|
||||
$_aiContent = str_replace("\r\n", "\n", trim($_POST['content'] ?? ''));
|
||||
if (!in_array($_aiAction, ['critique', 'rewrite', 'analyze'], true) || $_aiContent === '') {
|
||||
echo json_encode(['ok' => false, 'error' => 'Paramètres invalides']);
|
||||
exit;
|
||||
}
|
||||
require_once BASE_PATH . '/src/Service/AiService.php';
|
||||
echo json_encode((new AiService())->query($_aiAction, $_aiTitle, $_aiContent));
|
||||
exit;
|
||||
|
||||
case 'import_image_step2':
|
||||
requireAuth();
|
||||
if ($_SERVER['REQUEST_METHOD'] !== 'POST') {
|
||||
@@ -1649,7 +1763,7 @@ switch ($action) {
|
||||
// Capture d'écran pour prévisualisation (pages HTML uniquement, URL externes uniquement)
|
||||
$step2Screenshot = null;
|
||||
if (!$step2IsInternal && str_starts_with($step2Meta['mime'] ?? '', 'text/html')) {
|
||||
$filesDir = BASE_PATH . '/data/' . $uuid . '/files';
|
||||
$filesDir = DATA_PATH . '/' . $uuid . '/files';
|
||||
if (!is_dir($filesDir)) {
|
||||
mkdir($filesDir, 0755, true);
|
||||
}
|
||||
@@ -1725,7 +1839,7 @@ switch ($action) {
|
||||
header('Location: /import/' . rawurlencode($urlUuid) . '?error=1');
|
||||
exit;
|
||||
}
|
||||
$filesDir = BASE_PATH . '/data/' . $urlUuid . '/files';
|
||||
$filesDir = DATA_PATH . '/' . $urlUuid . '/files';
|
||||
$previewPath = $filesDir . '/' . $screenshotFile;
|
||||
if (!file_exists($previewPath)) {
|
||||
header('Location: /import/' . rawurlencode($urlUuid) . '?error=1');
|
||||
@@ -1744,7 +1858,7 @@ switch ($action) {
|
||||
}
|
||||
|
||||
if ($mode === 'link') {
|
||||
$filesDir = BASE_PATH . '/data/' . $urlUuid . '/files';
|
||||
$filesDir = DATA_PATH . '/' . $urlUuid . '/files';
|
||||
if (!is_dir($filesDir)) {
|
||||
mkdir($filesDir, 0755, true);
|
||||
}
|
||||
@@ -1895,7 +2009,7 @@ switch ($action) {
|
||||
$done = $fail = $skip = 0;
|
||||
foreach ($articles->getAll() as $article) {
|
||||
$artUuid = $article['uuid'];
|
||||
$filesDir = BASE_PATH . '/data/' . $artUuid . '/files';
|
||||
$filesDir = DATA_PATH . '/' . $artUuid . '/files';
|
||||
foreach ($article['external_links'] ?? [] as $link) {
|
||||
$lMeta = $link['meta'] ?? [];
|
||||
$lMime = $lMeta['mime'] ?? 'text/html';
|
||||
@@ -2145,11 +2259,44 @@ switch ($action) {
|
||||
$pdo = dbPdo();
|
||||
if ($pdo && preg_match('/^[0-9]{6}$/', $vcCode)) {
|
||||
require_once BASE_PATH . '/src/CommentManager.php';
|
||||
$cm = new CommentManager($pdo);
|
||||
$cm = new CommentManager($pdo);
|
||||
|
||||
// Récupère les données du commentaire avant vérification (le token est effacé après)
|
||||
$vcPreSt = $pdo->prepare(
|
||||
'SELECT author_name, content FROM comments WHERE verify_token = :t AND verified = FALSE LIMIT 1'
|
||||
);
|
||||
$vcPreSt->execute([':t' => $vcToken]);
|
||||
$vcPreInfo = $vcPreSt->fetch(PDO::FETCH_ASSOC) ?: null;
|
||||
|
||||
$result = $cm->verify($vcToken, $vcCode);
|
||||
if (is_string($result)) {
|
||||
$vcArticle = $articles->getByUuid($result);
|
||||
$vcSlug = $vcArticle ? ($vcArticle['slug'] ?? $result) : $result;
|
||||
|
||||
// Notification email à l'auteur de l'article
|
||||
$vcAuthorEmail = $vcArticle['author'] ?? '';
|
||||
if ($vcAuthorEmail !== '' && $vcPreInfo) {
|
||||
require_once BASE_PATH . '/src/mailer.php';
|
||||
$vcPostUrl = rtrim(APP_URL, '/') . '/post/' . rawurlencode($vcSlug) . '#comments';
|
||||
$vcAdminUrl = rtrim(APP_URL, '/') . '/admin/comments';
|
||||
$vcExcerpt = mb_strimwidth(trim((string)$vcPreInfo['content']), 0, 200, '…');
|
||||
$vcSubject = '[' . siteTitle() . '] Nouveau commentaire sur « ' . ($vcArticle['title'] ?? '') . ' »';
|
||||
$vcHtml = '<!DOCTYPE html><html><body style="font-family:sans-serif;max-width:560px;margin:0 auto">'
|
||||
. '<p>Bonjour,</p>'
|
||||
. '<p><strong>' . htmlspecialchars((string)$vcPreInfo['author_name']) . '</strong>'
|
||||
. ' a commenté votre article <em>' . htmlspecialchars($vcArticle['title'] ?? '') . '</em> :</p>'
|
||||
. '<blockquote style="border-left:3px solid #ddd;margin:0;padding:0 1em;color:#555">'
|
||||
. nl2br(htmlspecialchars($vcExcerpt)) . '</blockquote>'
|
||||
. '<p><a href="' . htmlspecialchars($vcPostUrl) . '">Voir le commentaire</a>'
|
||||
. ' · <a href="' . htmlspecialchars($vcAdminUrl) . '">Modérer</a></p>'
|
||||
. '</body></html>';
|
||||
try {
|
||||
envoyer_mail_smtp($vcAuthorEmail, $vcSubject, $vcHtml);
|
||||
} catch (\RuntimeException) {
|
||||
// Taux limité ou SMTP indisponible, on ne bloque pas le visiteur
|
||||
}
|
||||
}
|
||||
|
||||
header('Location: /post/' . rawurlencode($vcSlug) . '?verified=1#comments');
|
||||
exit;
|
||||
}
|
||||
@@ -2331,7 +2478,6 @@ switch ($action) {
|
||||
$me = currentUserEmail() ?? '';
|
||||
$allArticles = array_values(array_filter($allArticles, fn ($a) => ($a['author'] ?? '') === $me));
|
||||
}
|
||||
usort($allArticles, fn ($a, $b) => strcmp($b['updated_at'] ?? '', $a['updated_at'] ?? ''));
|
||||
|
||||
$adminData['filter_authors'] = array_values(array_unique(array_filter(array_column($allArticles, 'author'))));
|
||||
$adminData['filter_categories'] = array_values(array_unique(array_filter(array_column($allArticles, 'category'))));
|
||||
@@ -2341,9 +2487,13 @@ switch ($action) {
|
||||
$filterAuthor = trim($_GET['filter_author'] ?? '');
|
||||
$filterCategory = trim($_GET['filter_category'] ?? '');
|
||||
$filterStatus = trim($_GET['filter_status'] ?? '');
|
||||
$filterSearch = trim($_GET['filter_search'] ?? '');
|
||||
$filterFeatured = trim($_GET['filter_featured'] ?? '');
|
||||
$adminData['filter_author'] = $filterAuthor;
|
||||
$adminData['filter_category'] = $filterCategory;
|
||||
$adminData['filter_status'] = $filterStatus;
|
||||
$adminData['filter_search'] = $filterSearch;
|
||||
$adminData['filter_featured'] = $filterFeatured;
|
||||
|
||||
$nowTs = time();
|
||||
if ($filterAuthor !== '') {
|
||||
@@ -2359,8 +2509,30 @@ switch ($action) {
|
||||
} elseif ($filterStatus === 'preview') {
|
||||
$allArticles = array_values(array_filter($allArticles, fn ($a) => $a['published'] && strtotime((string)($a['published_at'] ?? '')) > $nowTs));
|
||||
}
|
||||
if ($filterSearch !== '') {
|
||||
$allArticles = array_values(array_filter($allArticles, fn ($a) => mb_stripos($a['title'] ?? '', $filterSearch) !== false));
|
||||
}
|
||||
if ($filterFeatured === 'yes') {
|
||||
$allArticles = array_values(array_filter($allArticles, fn ($a) => !empty($a['featured'])));
|
||||
}
|
||||
|
||||
$adminData['articles'] = $allArticles;
|
||||
$sortBy = in_array($_GET['sort'] ?? '', ['title', 'published', 'updated'], true) ? $_GET['sort'] : 'updated';
|
||||
$sortDir = ($_GET['dir'] ?? '') === 'asc' ? 'asc' : 'desc';
|
||||
usort($allArticles, function ($a, $b) use ($sortBy, $sortDir) {
|
||||
$cmp = match ($sortBy) {
|
||||
'title' => strcmp($a['title'] ?? '', $b['title'] ?? ''),
|
||||
'published' => strcmp(
|
||||
$a['published_at'] ?? $a['created_at'] ?? '',
|
||||
$b['published_at'] ?? $b['created_at'] ?? ''
|
||||
),
|
||||
default => strcmp($a['updated_at'] ?? '', $b['updated_at'] ?? ''),
|
||||
};
|
||||
return $sortDir === 'asc' ? $cmp : -$cmp;
|
||||
});
|
||||
|
||||
$adminData['articles'] = $allArticles;
|
||||
$adminData['sort_by'] = $sortBy;
|
||||
$adminData['sort_dir'] = $sortDir;
|
||||
}
|
||||
|
||||
if ($tab === 'roles') {
|
||||
@@ -2497,7 +2669,7 @@ switch ($action) {
|
||||
'queued' => (int)($row['queued'] ?? 0),
|
||||
];
|
||||
$adminData['emails'] = $pdo->query(
|
||||
"SELECT id, created_at, to_email, subject, status, error_message, content_text, sent_at
|
||||
"SELECT id, created_at, to_email, subject, status, error_message, content_text, content_html, sent_at
|
||||
FROM journal_smtp $whereEml
|
||||
ORDER BY created_at DESC
|
||||
LIMIT $emlLimit OFFSET $emlOffset"
|
||||
@@ -2537,9 +2709,11 @@ switch ($action) {
|
||||
exit;
|
||||
}
|
||||
require_once BASE_PATH . '/src/SearchLogParser.php';
|
||||
$parser = new SearchLogParser('/var/log/apache2', apacheAccessLog());
|
||||
$adminData['search_terms'] = $parser->topTerms(100);
|
||||
$days = in_array((int)($_GET['days'] ?? 14), [7, 14], true) ? (int)$_GET['days'] : 14;
|
||||
$parser = new SearchLogParser('/var/log/apache2', apacheAccessLog(), '', 600, $days);
|
||||
$adminData['search_terms'] = $parser->topTerms(100);
|
||||
$adminData['search_log_readable'] = $parser->isReadable();
|
||||
$adminData['search_days'] = $days;
|
||||
}
|
||||
|
||||
if ($tab === 'stats') {
|
||||
@@ -2547,20 +2721,37 @@ switch ($action) {
|
||||
http_response_code(403);
|
||||
exit;
|
||||
}
|
||||
require_once BASE_PATH . '/src/TrendingParser.php';
|
||||
require_once BASE_PATH . '/src/AccessLogParser.php';
|
||||
require_once BASE_PATH . '/src/AsnLookup.php';
|
||||
$accessParser = new AccessLogParser('/var/log/apache2', apacheAccessLog());
|
||||
$accessStats = $accessParser->stats();
|
||||
$adminData['stats_readable'] = $accessParser->isReadable();
|
||||
$adminData['stats_pages'] = array_slice($accessStats['pages'], 0, 30, true);
|
||||
$adminData['stats_books'] = array_slice($accessStats['books'], 0, 20, true);
|
||||
// Lookup AS pour les top 200 IPs
|
||||
$topIps = array_slice($accessStats['ips'], 0, 200, true);
|
||||
$asnMap = (new AsnLookup())->batchLookup(array_keys($topIps));
|
||||
$asList = AsnLookup::aggregateByAs($topIps, $asnMap);
|
||||
$adminData['stats_as'] = $asList;
|
||||
$adminData['stats_as_groups'] = AsnLookup::applyGroups($asList, asGroups());
|
||||
$adminData['as_groups'] = asGroups();
|
||||
|
||||
$statsCacheFile = DATA_PATH . '/.stats_cache.json';
|
||||
$statsRaw = null;
|
||||
if (file_exists($statsCacheFile) && (time() - filemtime($statsCacheFile)) < 60) {
|
||||
$statsRaw = json_decode((string) file_get_contents($statsCacheFile), true) ?: null;
|
||||
}
|
||||
if ($statsRaw === null) {
|
||||
$cutoff14 = strtotime('-14 days midnight') ?: (time() - 14 * 86400);
|
||||
$tParser = new TrendingParser('/var/log/apache2', apacheAccessLog());
|
||||
$accessParser = new AccessLogParser('/var/log/apache2', apacheAccessLog());
|
||||
$accessStats = $accessParser->stats();
|
||||
$topIps = array_slice($accessStats['ips'], 0, 200, true);
|
||||
$asnMap = (new AsnLookup())->batchLookup(array_keys($topIps));
|
||||
|
||||
$statsRaw = [
|
||||
'readable' => $accessParser->isReadable(),
|
||||
'books' => $tParser->top($cutoff14, 20, ['/book/']),
|
||||
'as' => AsnLookup::aggregateByAs($topIps, $asnMap),
|
||||
'pages_by_day' => $accessStats['pages_by_day'] ?? [],
|
||||
];
|
||||
@file_put_contents($statsCacheFile, json_encode($statsRaw));
|
||||
}
|
||||
$adminData['stats_readable'] = $statsRaw['readable'];
|
||||
$adminData['stats_books'] = $statsRaw['books'];
|
||||
$adminData['stats_as'] = $statsRaw['as'];
|
||||
$adminData['stats_as_groups'] = AsnLookup::applyGroups($statsRaw['as'], asGroups());
|
||||
$adminData['as_groups'] = asGroups();
|
||||
$adminData['stats_pages_by_day'] = $statsRaw['pages_by_day'] ?? [];
|
||||
}
|
||||
|
||||
if ($tab === 'categories') {
|
||||
@@ -2569,6 +2760,22 @@ switch ($action) {
|
||||
$adminData['tagTypes'] = $articles->getTagTypes();
|
||||
}
|
||||
|
||||
if ($tab === 'flux') {
|
||||
if (!isAdmin()) {
|
||||
http_response_code(403);
|
||||
exit;
|
||||
}
|
||||
$pdo = dbPdo();
|
||||
$adminData['flux_feeds'] = [];
|
||||
if ($pdo) {
|
||||
try {
|
||||
$st = $pdo->query('SELECT id, user_email, feed_url, label, created_at FROM rss_feeds ORDER BY created_at DESC');
|
||||
$adminData['flux_feeds'] = $st->fetchAll(PDO::FETCH_ASSOC);
|
||||
} catch (\Throwable) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ($tab === 'books') {
|
||||
if (!isAdmin()) {
|
||||
http_response_code(403);
|
||||
@@ -2584,9 +2791,41 @@ switch ($action) {
|
||||
}
|
||||
}
|
||||
|
||||
if ($tab === 'ia') {
|
||||
if (!isAdmin()) {
|
||||
http_response_code(403);
|
||||
exit;
|
||||
}
|
||||
require_once BASE_PATH . '/src/SiteSettings.php';
|
||||
require_once BASE_PATH . '/src/Service/AiService.php';
|
||||
$adminData['ai_provider'] = aiProvider();
|
||||
$adminData['ai_model'] = aiModel();
|
||||
$adminData['anthropic_key_set'] = (($_ENV['ANTHROPIC_API_KEY'] ?? getenv('ANTHROPIC_API_KEY') ?: '') !== '');
|
||||
$adminData['claude_cli_found'] = is_executable('/usr/local/bin/claude');
|
||||
$adminData['ai_notice'] = $_GET['notice'] ?? '';
|
||||
}
|
||||
|
||||
include BASE_PATH . '/templates/admin.php';
|
||||
break;
|
||||
|
||||
case 'admin_save_ai_config':
|
||||
requireAuth();
|
||||
if (!isAdmin() || $_SERVER['REQUEST_METHOD'] !== 'POST') {
|
||||
http_response_code(403);
|
||||
exit;
|
||||
}
|
||||
require_once BASE_PATH . '/src/SiteSettings.php';
|
||||
$allowedProviders = ['anthropic', 'claude_code'];
|
||||
$aiProvider = in_array($_POST['ai_provider'] ?? '', $allowedProviders, true)
|
||||
? $_POST['ai_provider']
|
||||
: 'anthropic';
|
||||
$ok = saveSiteSettings([
|
||||
'ai_provider' => $aiProvider,
|
||||
'ai_model' => trim($_POST['ai_model'] ?? ''),
|
||||
]);
|
||||
header('Location: /admin/ia?notice=' . ($ok ? 'saved' : 'error'));
|
||||
exit;
|
||||
|
||||
case 'admin_smtp_save':
|
||||
requireAuth();
|
||||
if (!isAdmin()) {
|
||||
@@ -2697,6 +2936,45 @@ switch ($action) {
|
||||
header('Location: /admin/smtp');
|
||||
exit;
|
||||
|
||||
case 'admin_email_preview':
|
||||
requireAuth();
|
||||
if (!isAdmin()) {
|
||||
http_response_code(403);
|
||||
exit;
|
||||
}
|
||||
$previewId = (int)($_GET['id'] ?? 0);
|
||||
$pdo = dbPdo();
|
||||
$emailRow = null;
|
||||
if ($pdo && $previewId > 0) {
|
||||
$st = $pdo->prepare('SELECT subject, content_html, content_text FROM journal_smtp WHERE id = :id');
|
||||
$st->execute([':id' => $previewId]);
|
||||
$emailRow = $st->fetch(PDO::FETCH_ASSOC) ?: null;
|
||||
}
|
||||
if (!$emailRow) {
|
||||
http_response_code(404);
|
||||
echo 'Email introuvable.';
|
||||
exit;
|
||||
}
|
||||
header('Content-Type: text/html; charset=UTF-8');
|
||||
$previewHtml = !empty($emailRow['content_html']) ? $emailRow['content_html'] : nl2br(htmlspecialchars((string)$emailRow['content_text']));
|
||||
echo '<!doctype html><html lang="fr"><head><meta charset="utf-8"><title>' . htmlspecialchars((string)$emailRow['subject']) . '</title></head><body>' . $previewHtml . '</body></html>';
|
||||
exit;
|
||||
|
||||
case 'admin_toggle_featured':
|
||||
requireAuth();
|
||||
if (!isAdmin() || $_SERVER['REQUEST_METHOD'] !== 'POST') {
|
||||
http_response_code(403);
|
||||
exit;
|
||||
}
|
||||
$uid = trim((string)($_POST['uuid'] ?? ''));
|
||||
$art = $uid !== '' ? $articles->getByUuid($uid) : null;
|
||||
if ($art) {
|
||||
$articles->setFeatured($uid, !((bool)($art['featured'] ?? false)));
|
||||
}
|
||||
$back = $_POST['_back'] ?? '/admin/articles';
|
||||
header('Location: ' . $back);
|
||||
exit;
|
||||
|
||||
case 'admin_bulk_delete':
|
||||
requireAuth();
|
||||
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
||||
@@ -2784,7 +3062,7 @@ switch ($action) {
|
||||
http_response_code(403);
|
||||
exit;
|
||||
}
|
||||
$_cmDataDir = BASE_PATH . '/data';
|
||||
$_cmDataDir = DATA_PATH;
|
||||
$_cmTrack = $_cmDataDir . '/.content_migrations.json';
|
||||
$_cmFlag = $_cmDataDir . '/.maintenance';
|
||||
$_cmApplied = file_exists($_cmTrack) ? (json_decode((string) file_get_contents($_cmTrack), true) ?? []) : [];
|
||||
@@ -2814,6 +3092,53 @@ switch ($action) {
|
||||
header('Location: /admin?tab=dashboard¬ice=' . ($_cmErrors ? 'migration_error' : 'migrated'));
|
||||
exit;
|
||||
|
||||
case 'run_engine_update':
|
||||
requireAuth();
|
||||
if (!isAdmin() || $_SERVER['REQUEST_METHOD'] !== 'POST') {
|
||||
http_response_code(403);
|
||||
exit;
|
||||
}
|
||||
|
||||
set_time_limit(0);
|
||||
ignore_user_abort(true);
|
||||
|
||||
exec('sudo /usr/local/bin/folio-upgrade.sh ' . escapeshellarg(folioUpdateBranch()) . ' 2>&1', $_upgradeOut, $_upgradeCode);
|
||||
|
||||
$_updateChecker->clearCache();
|
||||
|
||||
if ($_upgradeCode !== 0) {
|
||||
$_SESSION['_upgrade_log'] = implode("\n", $_upgradeOut);
|
||||
header('Location: /admin?tab=dashboard¬ice=upgrade_error');
|
||||
exit;
|
||||
}
|
||||
|
||||
header('Location: /admin?tab=dashboard¬ice=engine_updated');
|
||||
exit;
|
||||
|
||||
case 'force_update_check':
|
||||
requireAuth();
|
||||
if (!isAdmin() || $_SERVER['REQUEST_METHOD'] !== 'POST') {
|
||||
http_response_code(403);
|
||||
exit;
|
||||
}
|
||||
$_updateChecker->clearCache();
|
||||
header('Location: /admin?tab=dashboard');
|
||||
exit;
|
||||
|
||||
case 'admin_save_folio_config':
|
||||
requireAuth();
|
||||
if (!isAdmin() || $_SERVER['REQUEST_METHOD'] !== 'POST') {
|
||||
http_response_code(403);
|
||||
exit;
|
||||
}
|
||||
$ok = saveSiteSettings([
|
||||
'folio_repo_url' => $_POST['folio_repo_url'] ?? '',
|
||||
'folio_update_branch' => $_POST['folio_update_branch'] ?? '',
|
||||
]);
|
||||
$_updateChecker->clearCache();
|
||||
header('Location: /admin/site?notice=' . ($ok ? 'folio_saved' : 'folio_error'));
|
||||
exit;
|
||||
|
||||
case 'admin_save_site':
|
||||
requireAuth();
|
||||
if (!isAdmin() || $_SERVER['REQUEST_METHOD'] !== 'POST') {
|
||||
@@ -3114,6 +3439,25 @@ switch ($action) {
|
||||
header('Location: /profile#feeds');
|
||||
exit;
|
||||
|
||||
case 'admin_delete_feed':
|
||||
requireAuth();
|
||||
if (!isAdmin() || $_SERVER['REQUEST_METHOD'] !== 'POST') {
|
||||
http_response_code(403);
|
||||
exit;
|
||||
}
|
||||
$feedId = (int)($_POST['id'] ?? 0);
|
||||
if ($feedId > 0) {
|
||||
$pdo = dbPdo();
|
||||
if ($pdo) {
|
||||
try {
|
||||
$pdo->prepare('DELETE FROM rss_feeds WHERE id = :id')->execute([':id' => $feedId]);
|
||||
} catch (\Throwable) {
|
||||
}
|
||||
}
|
||||
}
|
||||
header('Location: /admin/flux?deleted=1');
|
||||
exit;
|
||||
|
||||
case 'search_files':
|
||||
requireAuth();
|
||||
header('Content-Type: application/json');
|
||||
@@ -3199,6 +3543,27 @@ switch ($action) {
|
||||
include BASE_PATH . '/templates/search.php';
|
||||
break;
|
||||
|
||||
case 'books_list':
|
||||
$allCats = $articles->getCategories();
|
||||
$booksData = [];
|
||||
foreach ($books->getAll() as $_bk) {
|
||||
$_published = [];
|
||||
foreach ($_bk['articles'] ?? [] as $_aSlug) {
|
||||
$_a = $articles->getBySlug($_aSlug);
|
||||
if ($_a && $_a['published'] && strtotime((string)($_a['published_at'] ?? '')) <= time()) {
|
||||
$_published[] = $_a;
|
||||
}
|
||||
}
|
||||
if (empty($_published)) {
|
||||
continue;
|
||||
}
|
||||
$booksData[] = ['book' => $_bk, 'count' => count($_published), 'first' => $_published[0]];
|
||||
}
|
||||
unset($_bk, $_published, $_aSlug, $_a);
|
||||
$seoDescription = 'Retrouvez tous les livres et séries d\'articles publiés sur ' . siteTitle() . '.';
|
||||
include BASE_PATH . '/templates/books_list.php';
|
||||
break;
|
||||
|
||||
case 'book':
|
||||
$bookSlug = trim($_GET['book_slug'] ?? '');
|
||||
$book = $books->getBySlug($bookSlug);
|
||||
@@ -3243,6 +3608,9 @@ switch ($action) {
|
||||
$bTitle = trim($_POST['title'] ?? '');
|
||||
$bDesc = trim($_POST['description'] ?? '');
|
||||
$bArts = array_values(array_filter(array_map('trim', preg_split('/[\r\n]+/', $_POST['articles'] ?? ''))));
|
||||
if ($bSlug === '' && $bTitle !== '') {
|
||||
$bSlug = $books->sanitizeSlug($bTitle);
|
||||
}
|
||||
if ($bSlug !== '' && $bTitle !== '') {
|
||||
$books->save(['slug' => $bSlug, 'title' => $bTitle, 'description' => $bDesc, 'articles' => $bArts]);
|
||||
}
|
||||
@@ -3267,23 +3635,10 @@ switch ($action) {
|
||||
(string)(parse_url($_SERVER['REDIRECT_URL'] ?? $_SERVER['REQUEST_URI'] ?? '', PHP_URL_PATH) ?? ''),
|
||||
'/'
|
||||
);
|
||||
if ($notFoundPath !== '') {
|
||||
searchAndRedirect(basename($notFoundPath), $articles);
|
||||
}
|
||||
http_response_code(404);
|
||||
ob_start();
|
||||
?>
|
||||
<div class="container py-5 text-center">
|
||||
<h1 class="h2 mb-3">Page introuvable</h1>
|
||||
<p class="text-muted mb-4">Cette adresse ne correspond à aucun article.<br>Vous avez peut-être suivi un ancien lien.</p>
|
||||
<a href="/" class="btn btn-primary">← Retour à l'accueil</a>
|
||||
</div>
|
||||
<?php
|
||||
$content = ob_get_clean();
|
||||
$title = '404 — ' . siteTitle();
|
||||
$metaRobots = 'noindex, nofollow';
|
||||
include BASE_PATH . '/templates/layout.php';
|
||||
break;
|
||||
log404('/' . $notFoundPath);
|
||||
$q = slugToSearchQuery($notFoundPath);
|
||||
header('Location: /search' . ($q !== '' ? '?q=' . urlencode($q) : ''), true, 302);
|
||||
exit;
|
||||
|
||||
case 'list':
|
||||
default:
|
||||
@@ -3383,38 +3738,64 @@ switch ($action) {
|
||||
unset($_heroUuid, $_count, $_hp);
|
||||
|
||||
$allPostsMap = array_column($allPosts, null, 'uuid');
|
||||
$_slugMap = array_column($allPosts, null, 'slug');
|
||||
|
||||
// Articles populaires (10 derniers jours) — score pondéré
|
||||
// Tendances 1 h — lecture seule du cache généré par /trending?period=1h
|
||||
$_trendCache = DATA_PATH . '/_cache/trending_1h.json';
|
||||
$_trendPaths = null;
|
||||
if (file_exists($_trendCache) && (time() - filemtime($_trendCache)) < 720) {
|
||||
$_trendPaths = json_decode((string) file_get_contents($_trendCache), true) ?: null;
|
||||
}
|
||||
if (!empty($_trendPaths)) {
|
||||
foreach ($_trendPaths as $_path => $_cnt) {
|
||||
if (count($popularPosts) >= 6) {
|
||||
break;
|
||||
}
|
||||
if (!preg_match('#^/post/([^/]+)$#', $_path, $_m)) {
|
||||
continue;
|
||||
}
|
||||
$_a = $_slugMap[rawurldecode($_m[1])] ?? null;
|
||||
if ($_a !== null) {
|
||||
$popularPosts[] = $_a;
|
||||
}
|
||||
}
|
||||
unset($_path, $_cnt, $_m, $_a);
|
||||
}
|
||||
unset($_trendCache, $_trendPaths, $_slugMap);
|
||||
|
||||
// Fallback : score pondéré DB (réactions, notes, commentaires sur 10 j)
|
||||
$_pdo = dbPdo();
|
||||
if ($_pdo) {
|
||||
try {
|
||||
$_stmt = $_pdo->query("
|
||||
SELECT article_uuid, SUM(score) AS total
|
||||
FROM (
|
||||
SELECT article_uuid, 1 AS score FROM article_reactions
|
||||
WHERE created_at >= NOW() - INTERVAL '10 days'
|
||||
UNION ALL
|
||||
SELECT article_uuid, 2 AS score FROM article_ratings
|
||||
WHERE rated_at >= NOW() - INTERVAL '10 days'
|
||||
UNION ALL
|
||||
SELECT article_uuid, 3 AS score FROM comments
|
||||
WHERE created_at >= NOW() - INTERVAL '10 days' AND published = TRUE
|
||||
) ev
|
||||
GROUP BY article_uuid
|
||||
ORDER BY total DESC
|
||||
LIMIT 20
|
||||
");
|
||||
foreach ($_stmt->fetchAll(PDO::FETCH_ASSOC) as $_row) {
|
||||
if (count($popularPosts) >= 6) {
|
||||
break;
|
||||
if (empty($popularPosts)) {
|
||||
try {
|
||||
$_stmt = $_pdo->query("
|
||||
SELECT article_uuid, SUM(score) AS total
|
||||
FROM (
|
||||
SELECT article_uuid, 1 AS score FROM article_reactions
|
||||
WHERE created_at >= NOW() - INTERVAL '10 days'
|
||||
UNION ALL
|
||||
SELECT article_uuid, 2 AS score FROM article_ratings
|
||||
WHERE rated_at >= NOW() - INTERVAL '10 days'
|
||||
UNION ALL
|
||||
SELECT article_uuid, 3 AS score FROM comments
|
||||
WHERE created_at >= NOW() - INTERVAL '10 days' AND published = TRUE
|
||||
) ev
|
||||
GROUP BY article_uuid
|
||||
ORDER BY total DESC
|
||||
LIMIT 20
|
||||
");
|
||||
foreach ($_stmt->fetchAll(PDO::FETCH_ASSOC) as $_row) {
|
||||
if (count($popularPosts) >= 6) {
|
||||
break;
|
||||
}
|
||||
$_uuid = $_row['article_uuid'];
|
||||
if (!isset($allPostsMap[$_uuid])) {
|
||||
continue;
|
||||
}
|
||||
$popularPosts[] = $allPostsMap[$_uuid];
|
||||
}
|
||||
$_uuid = $_row['article_uuid'];
|
||||
if (!isset($allPostsMap[$_uuid])) {
|
||||
continue;
|
||||
}
|
||||
$popularPosts[] = $allPostsMap[$_uuid];
|
||||
} catch (Throwable) {
|
||||
}
|
||||
} catch (Throwable) {
|
||||
}
|
||||
|
||||
// Redécouvertes : anciens articles (> 30 j) avec activité récente
|
||||
@@ -3487,6 +3868,26 @@ switch ($action) {
|
||||
$recentlyUpdated[] = $_a;
|
||||
}
|
||||
unset($_sevenDaysAgo, $_latestUuids, $_popularUuids, $_heroUuid, $_a, $allPostsMap);
|
||||
|
||||
// Books à mettre en avant (max 6, ayant ≥ 1 article publié)
|
||||
$homeBooks = [];
|
||||
foreach ($books->getAll() as $_bk) {
|
||||
$_published = [];
|
||||
foreach ($_bk['articles'] ?? [] as $_aSlug) {
|
||||
$_a = $articles->getBySlug($_aSlug);
|
||||
if ($_a && $_a['published'] && strtotime((string)($_a['published_at'] ?? '')) <= time()) {
|
||||
$_published[] = $_a;
|
||||
}
|
||||
}
|
||||
if (empty($_published)) {
|
||||
continue;
|
||||
}
|
||||
$homeBooks[] = ['book' => $_bk, 'count' => count($_published), 'first' => $_published[0]];
|
||||
if (count($homeBooks) >= 6) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
unset($_bk, $_published, $_aSlug, $_a);
|
||||
}
|
||||
// ──────────────────────────────────────────────────────────────────
|
||||
|
||||
|
||||
+17
-33
@@ -6,46 +6,21 @@ declare(strict_types=1);
|
||||
|
||||
use App\Http\Csrf;
|
||||
|
||||
// --- Helpers AVANT tout usage ---
|
||||
if (!function_exists('env')) {
|
||||
function env(string $key, ?string $default = null): ?string
|
||||
{
|
||||
if (array_key_exists($key, $_ENV) && $_ENV[$key] !== '') {
|
||||
return (string)$_ENV[$key];
|
||||
}
|
||||
$v = getenv($key);
|
||||
if ($v !== false && $v !== '') {
|
||||
return (string)$v;
|
||||
}
|
||||
return $default;
|
||||
}
|
||||
if (!defined('BASE_PATH')) {
|
||||
define('BASE_PATH', dirname(__DIR__, 2));
|
||||
}
|
||||
if (!function_exists('db')) {
|
||||
function db(): \PDO
|
||||
{
|
||||
return \App\Infrastructure\Database::get();
|
||||
}
|
||||
}
|
||||
if (!function_exists('url')) {
|
||||
function url(string $path = '/'): string
|
||||
{
|
||||
$scheme = (!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] !== 'off') ? 'https' : 'http';
|
||||
$host = $_SERVER['HTTP_HOST'] ?? 'localhost';
|
||||
return $scheme . '://' . $host . $path;
|
||||
}
|
||||
}
|
||||
|
||||
require_once dirname(__DIR__, 2) . '/vendor/autoload.php';
|
||||
require_once dirname(__DIR__, 2) . '/bootstrap.php';
|
||||
require_once dirname(__DIR__, 2) . '/config/config.php';
|
||||
require_once dirname(__DIR__, 2) . '/bootstrap.php';
|
||||
require_once dirname(__DIR__, 2) . '/src/SiteSettings.php';
|
||||
require_once dirname(__DIR__, 2) . '/src/mailer.php';
|
||||
|
||||
// Paramètres (env)
|
||||
$ttlMin = (int) env('MAGIC_LINK_TTL_MINUTES', '30');
|
||||
$coolMin = (int) env('MAGIC_COOLDOWN_MINUTES', '5');
|
||||
$winHours = (int) env('MAGIC_WINDOW_HOURS', '12');
|
||||
$maxPerWin = (int) env('MAGIC_MAX_PER_WINDOW', '5');
|
||||
$ttlMin = (int) env('MAGIC_LINK_TTL_MINUTES', '30');
|
||||
$coolMin = (int) env('MAGIC_COOLDOWN_MINUTES', '5');
|
||||
$winHours = (int) env('MAGIC_WINDOW_HOURS', '12');
|
||||
$maxPerWin = (int) env('MAGIC_MAX_PER_WINDOW', '5');
|
||||
$maxPerIpHour = (int) env('MAGIC_MAX_PER_IP_HOUR', '10');
|
||||
|
||||
// --- return_to ---
|
||||
$defaultReturn = '/';
|
||||
@@ -120,6 +95,15 @@ if (($_SERVER['REQUEST_METHOD'] ?? 'GET') === 'POST') {
|
||||
throw new RuntimeException('Quota atteint. Réessayez plus tard.');
|
||||
}
|
||||
|
||||
// 3) rate limit par IP
|
||||
$stmt = $pdo->prepare(
|
||||
"SELECT COUNT(*) FROM auth_magic_links WHERE ip = :ip AND created_at >= NOW() - INTERVAL '1 hour'"
|
||||
);
|
||||
$stmt->execute([':ip' => $ip]);
|
||||
if ((int)$stmt->fetchColumn() >= $maxPerIpHour) {
|
||||
throw new RuntimeException('Quota atteint. Réessayez plus tard.');
|
||||
}
|
||||
|
||||
// Génère et enregistre le lien avec TTL ttlMin
|
||||
$raw = random_bytes(32);
|
||||
$token = rtrim(strtr(base64_encode($raw), '+/', '-_'), '=');
|
||||
|
||||
+47
-28
@@ -1,42 +1,63 @@
|
||||
<?php
|
||||
|
||||
// projet : mug.a5l.fr
|
||||
// fichier : pages/login/magic.php
|
||||
// version : 20251011
|
||||
declare(strict_types=1);
|
||||
|
||||
if (!defined('BASE_PATH')) {
|
||||
define('BASE_PATH', dirname(__DIR__, 2));
|
||||
}
|
||||
require_once dirname(__DIR__, 2) . '/vendor/autoload.php';
|
||||
require_once dirname(__DIR__, 2) . '/bootstrap.php';
|
||||
require_once dirname(__DIR__, 2) . '/config/config.php';
|
||||
|
||||
// si tu as un service pour ouvrir une session
|
||||
|
||||
if (!function_exists('db')) {
|
||||
function db(): PDO
|
||||
{
|
||||
return \App\Infrastructure\Database::get();
|
||||
}
|
||||
}
|
||||
if (!function_exists('url')) {
|
||||
function url(string $path = '/'): string
|
||||
{
|
||||
$scheme = (!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] !== 'off') ? 'https' : 'http';
|
||||
$host = $_SERVER['HTTP_HOST'] ?? 'localhost';
|
||||
return $scheme . '://' . $host . $path;
|
||||
}
|
||||
}
|
||||
require_once dirname(__DIR__, 2) . '/bootstrap.php';
|
||||
|
||||
$token = (string)($_GET['token'] ?? '');
|
||||
if ($token === '' || preg_match('/[^A-Za-z0-9\-\_]/', $token)) {
|
||||
http_response_code(400);
|
||||
exit('Lien invalide.');
|
||||
exit(renderMagicPage('Lien invalide', '<p>Ce lien de connexion est invalide.</p>', null));
|
||||
}
|
||||
|
||||
$pdo = db();
|
||||
|
||||
// ─── Rendu minimal standalone ────────────────────────────────────────────────
|
||||
function renderMagicPage(string $title, string $body, ?string $token): string
|
||||
{
|
||||
$formHtml = $token !== null
|
||||
? '<form method="post" action="' . htmlspecialchars($_SERVER['REQUEST_URI'] ?? '') . '">'
|
||||
. '<input type="hidden" name="confirm" value="1">'
|
||||
. '<button type="submit" style="display:inline-block;padding:10px 24px;background:#0d6efd;color:#fff;border:none;border-radius:4px;font-size:1rem;cursor:pointer">Se connecter</button>'
|
||||
. '</form>'
|
||||
: '';
|
||||
return '<!doctype html><html lang="fr"><head><meta charset="utf-8"><meta name="viewport" content="width=device-width,initial-scale=1">'
|
||||
. '<title>' . htmlspecialchars($title) . '</title>'
|
||||
. '<style>body{font-family:system-ui,sans-serif;max-width:480px;margin:80px auto;padding:0 1rem;text-align:center}'
|
||||
. 'h1{font-size:1.4rem;margin-bottom:1rem}</style></head>'
|
||||
. '<body><h1>' . htmlspecialchars($title) . '</h1>' . $body . $formHtml . '</body></html>';
|
||||
}
|
||||
|
||||
// ─── GET : afficher la page de confirmation ──────────────────────────────────
|
||||
if ($_SERVER['REQUEST_METHOD'] !== 'POST') {
|
||||
$stmt = $pdo->prepare('SELECT id, expires_at, consumed_at FROM auth_magic_links WHERE token = :t');
|
||||
$stmt->execute([':t' => $token]);
|
||||
$row = $stmt->fetch(PDO::FETCH_ASSOC);
|
||||
|
||||
if (!$row) {
|
||||
http_response_code(400);
|
||||
exit(renderMagicPage('Lien inconnu', '<p>Ce lien de connexion est introuvable.</p>', null));
|
||||
}
|
||||
if ($row['consumed_at'] !== null) {
|
||||
http_response_code(400);
|
||||
exit(renderMagicPage('Lien déjà utilisé', '<p>Ce lien de connexion a déjà été utilisé.</p><p><a href="/login">Demander un nouveau lien</a></p>', null));
|
||||
}
|
||||
if (strtotime((string)$row['expires_at']) < time()) {
|
||||
http_response_code(400);
|
||||
exit(renderMagicPage('Lien expiré', '<p>Ce lien de connexion a expiré.</p><p><a href="/login">Demander un nouveau lien</a></p>', null));
|
||||
}
|
||||
|
||||
exit(renderMagicPage('Connexion', '<p style="color:#555;margin-bottom:1.5rem">Cliquez sur le bouton ci-dessous pour vous connecter.</p>', $token));
|
||||
}
|
||||
|
||||
// ─── POST : consommer le token et ouvrir la session ──────────────────────────
|
||||
$pdo->beginTransaction();
|
||||
try {
|
||||
// récupère lien non consommé et non expiré
|
||||
$sql = 'SELECT id, email, token, created_at, expires_at, consumed_at, return_to
|
||||
$sql = 'SELECT id, email, expires_at, consumed_at, return_to
|
||||
FROM auth_magic_links
|
||||
WHERE token = :t
|
||||
FOR UPDATE';
|
||||
@@ -54,7 +75,6 @@ try {
|
||||
throw new RuntimeException('Lien expiré.');
|
||||
}
|
||||
|
||||
// consomme le lien
|
||||
$pdo->prepare('UPDATE auth_magic_links SET consumed_at = NOW() WHERE id = :id')->execute([':id' => $row['id']]);
|
||||
$pdo->commit();
|
||||
|
||||
@@ -65,7 +85,6 @@ try {
|
||||
$_SESSION['user_email'] = strtolower(trim((string)$row['email']));
|
||||
|
||||
$dest = $row['return_to'] ?? '/';
|
||||
// sécurité: ne renvoyer que des chemins relatifs
|
||||
if (!is_string($dest) || !str_starts_with($dest, '/')) {
|
||||
$dest = '/';
|
||||
}
|
||||
@@ -76,5 +95,5 @@ try {
|
||||
$pdo->rollBack();
|
||||
}
|
||||
http_response_code(400);
|
||||
echo htmlspecialchars($e->getMessage(), ENT_QUOTES);
|
||||
exit(renderMagicPage('Erreur', '<p>' . htmlspecialchars($e->getMessage()) . '</p><p><a href="/login">Retour à la connexion</a></p>', null));
|
||||
}
|
||||
|
||||
+3
-5
@@ -4,12 +4,10 @@ declare(strict_types=1);
|
||||
|
||||
define('BASE_PATH', realpath(__DIR__ . '/../'));
|
||||
|
||||
if (session_status() === PHP_SESSION_NONE) {
|
||||
session_start();
|
||||
}
|
||||
|
||||
require_once BASE_PATH . '/src/auth.php';
|
||||
require_once BASE_PATH . '/vendor/autoload.php';
|
||||
require_once BASE_PATH . '/config/config.php';
|
||||
require_once BASE_PATH . '/bootstrap.php';
|
||||
require_once BASE_PATH . '/src/auth.php';
|
||||
|
||||
$logoutUrl = ssoLogoutUrl();
|
||||
|
||||
|
||||
@@ -9,20 +9,6 @@ require_once dirname(__DIR__, 2) . '/vendor/autoload.php';
|
||||
require_once dirname(__DIR__, 2) . '/config/config.php';
|
||||
require_once dirname(__DIR__, 2) . '/bootstrap.php';
|
||||
|
||||
if (!function_exists('env')) {
|
||||
function env(string $key, ?string $default = null): ?string
|
||||
{
|
||||
if (array_key_exists($key, $_ENV) && $_ENV[$key] !== '') {
|
||||
return (string)$_ENV[$key];
|
||||
}
|
||||
$v = getenv($key);
|
||||
if ($v !== false && $v !== '') {
|
||||
return (string)$v;
|
||||
}
|
||||
return $default;
|
||||
}
|
||||
}
|
||||
|
||||
$debug = (env('APP_DEBUG', '0') === '1');
|
||||
|
||||
$OIDC_ISSUER = rtrim((string)(env('OIDC_ISSUER') ?? ''), '/');
|
||||
@@ -39,7 +25,15 @@ if (!$OIDC_ISSUER || !$OIDC_CLIENT_ID || !$OIDC_REDIRECT_URI) {
|
||||
$tokenEndpoint = $OIDC_ISSUER . '/protocol/openid-connect/token';
|
||||
$userInfoEndpoint = $OIDC_ISSUER . '/protocol/openid-connect/userinfo';
|
||||
|
||||
if (session_status() !== PHP_SESSION_ACTIVE) {
|
||||
error_log('[OIDC/callback] session_start() a échoué — vérifier session.save_path');
|
||||
http_response_code(500);
|
||||
echo $debug ? 'Erreur de session (session.save_path inaccessible ?).' : 'Erreur interne.';
|
||||
exit;
|
||||
}
|
||||
|
||||
if (!isset($_GET['state'], $_SESSION['oidc_state']) || !hash_equals((string)$_SESSION['oidc_state'], (string)$_GET['state'])) {
|
||||
error_log('[OIDC/callback] State invalide — GET:' . ($_GET['state'] ?? 'absent') . ' SESSION:' . (isset($_SESSION['oidc_state']) ? 'présent' : 'absent') . ' session_id:' . session_id());
|
||||
http_response_code(400);
|
||||
echo $debug ? 'State invalide.' : 'Requête invalide.';
|
||||
exit;
|
||||
|
||||
+5
-12
@@ -9,18 +9,11 @@ require_once dirname(__DIR__, 2) . '/vendor/autoload.php';
|
||||
require_once dirname(__DIR__, 2) . '/config/config.php';
|
||||
require_once dirname(__DIR__, 2) . '/bootstrap.php';
|
||||
|
||||
if (!function_exists('env')) {
|
||||
function env(string $key, ?string $default = null): ?string
|
||||
{
|
||||
if (array_key_exists($key, $_ENV) && $_ENV[$key] !== '') {
|
||||
return (string)$_ENV[$key];
|
||||
}
|
||||
$v = getenv($key);
|
||||
if ($v !== false && $v !== '') {
|
||||
return (string)$v;
|
||||
}
|
||||
return $default;
|
||||
}
|
||||
if (session_status() !== PHP_SESSION_ACTIVE) {
|
||||
error_log('[OIDC/start] session_start() a échoué — vérifier session.save_path');
|
||||
http_response_code(500);
|
||||
echo 'Erreur de session. Contactez l\'administrateur.';
|
||||
exit;
|
||||
}
|
||||
|
||||
$flow = $_GET['flow'] ?? 'login'; // 'login' ou 'register'
|
||||
|
||||
+1
-1
@@ -8,7 +8,7 @@ require_once BASE_PATH . '/src/helpers.php';
|
||||
require_once BASE_PATH . '/config/config.php';
|
||||
require_once BASE_PATH . '/src/ArticleManager.php';
|
||||
|
||||
$articles = new ArticleManager(BASE_PATH . '/data');
|
||||
$articles = new ArticleManager(DATA_PATH);
|
||||
$privateCats = $articles->getPrivateCategories();
|
||||
|
||||
$published = array_filter($articles->getAll(true), static function (array $a) use ($privateCats): bool {
|
||||
|
||||
@@ -0,0 +1,194 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
define('BASE_PATH', realpath(__DIR__ . '/../'));
|
||||
|
||||
require_once BASE_PATH . '/src/auth.php';
|
||||
require_once BASE_PATH . '/src/SiteSettings.php';
|
||||
require_once BASE_PATH . '/config/config.php';
|
||||
require_once BASE_PATH . '/src/ArticleManager.php';
|
||||
|
||||
const TENDANCES_PERIODS = [
|
||||
'10m' => ['seconds' => 600, 'label' => '10 dernières minutes', 'short' => '10 min'],
|
||||
'20m' => ['seconds' => 1200, 'label' => '20 dernières minutes', 'short' => '20 min'],
|
||||
'30m' => ['seconds' => 1800, 'label' => '30 dernières minutes', 'short' => '30 min'],
|
||||
'1h' => ['seconds' => 3600, 'label' => 'dernière heure', 'short' => '1 h'],
|
||||
'8h' => ['seconds' => 28800, 'label' => '8 dernières heures', 'short' => '8 h'],
|
||||
'1d' => ['seconds' => 86400, 'label' => '24 dernières heures', 'short' => '24 h'],
|
||||
'7d' => ['seconds' => 604800, 'label' => '7 derniers jours', 'short' => '7 j'],
|
||||
'14d' => ['seconds' => 1209600, 'label' => '14 derniers jours', 'short' => '14 j'],
|
||||
'30d' => ['seconds' => 2592000, 'label' => '30 derniers jours', 'short' => '30 j'],
|
||||
'1y' => ['seconds' => 31536000, 'label' => 'dernière année', 'short' => '1 an'],
|
||||
];
|
||||
|
||||
// Période active (affichage du top)
|
||||
$period = $_GET['period'] ?? '1d';
|
||||
if (!array_key_exists($period, TENDANCES_PERIODS)) {
|
||||
$period = '1d';
|
||||
}
|
||||
|
||||
$seconds = TENDANCES_PERIODS[$period]['seconds'];
|
||||
$label = TENDANCES_PERIODS[$period]['label'];
|
||||
$cacheTtl = max(60, min(28800, (int) ($seconds / 5)));
|
||||
|
||||
// Lecture seule du cache généré par /trending?period=…
|
||||
$cacheFile = DATA_PATH . '/_cache/trending_' . $period . '.json';
|
||||
$topPaths = null;
|
||||
|
||||
if (file_exists($cacheFile) && (time() - filemtime($cacheFile)) < $cacheTtl) {
|
||||
$topPaths = json_decode((string) file_get_contents($cacheFile), true) ?: null;
|
||||
}
|
||||
|
||||
// Index slug → article
|
||||
$articleManager = new ArticleManager(DATA_PATH);
|
||||
$now = time();
|
||||
$privateCats = $articleManager->getPrivateCategories();
|
||||
$slugIndex = [];
|
||||
foreach ($articleManager->getAll(publishedOnly: true) as $a) {
|
||||
if (strtotime((string) ($a['published_at'] ?? '')) > $now) {
|
||||
continue;
|
||||
}
|
||||
$cat = trim($a['category'] ?? '');
|
||||
if ($cat !== '' && in_array($cat, $privateCats, true)) {
|
||||
continue;
|
||||
}
|
||||
$slugIndex[$a['slug']] = $a;
|
||||
}
|
||||
|
||||
// Top articles pour la période affichée
|
||||
$topItems = [];
|
||||
foreach ($topPaths as $path => $visitors) {
|
||||
if (!preg_match('#^/post/([^/]+)$#', $path, $m)) {
|
||||
continue;
|
||||
}
|
||||
$article = $slugIndex[rawurldecode($m[1])] ?? null;
|
||||
if ($article === null) {
|
||||
continue;
|
||||
}
|
||||
$topItems[] = ['article' => $article, 'visitors' => (int) $visitors];
|
||||
if (count($topItems) >= 20) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
$base = rtrim(APP_URL, '/');
|
||||
$pageTitle = 'Tendances — ' . siteTitle();
|
||||
|
||||
ob_start();
|
||||
?>
|
||||
<div class="container py-4" style="max-width:860px">
|
||||
|
||||
<h1 class="h3 mb-1">Tendances</h1>
|
||||
<p class="text-muted mb-4">
|
||||
Articles les plus consultés, calculés en temps réel depuis les journaux d'accès du serveur.
|
||||
Seuls les visiteurs uniques (une IP = un visiteur) sur des réponses <code>200</code> sont comptabilisés.
|
||||
Aucun cookie, aucun traceur tiers.
|
||||
</p>
|
||||
|
||||
<!-- Sélecteur de période -->
|
||||
<div class="d-flex flex-wrap gap-2 mb-4">
|
||||
<?php foreach (TENDANCES_PERIODS as $p => $info): ?>
|
||||
<a href="/tendances?period=<?= rawurlencode($p) ?>"
|
||||
class="btn btn-sm <?= $p === $period ? 'btn-primary' : 'btn-outline-secondary' ?>">
|
||||
<?= htmlspecialchars($info['short']) ?>
|
||||
</a>
|
||||
<?php endforeach; ?>
|
||||
</div>
|
||||
|
||||
<!-- Top articles -->
|
||||
<?php if (empty($topItems)): ?>
|
||||
<p class="text-muted">Aucune donnée disponible pour cette période.</p>
|
||||
<?php else: ?>
|
||||
<h2 class="h5 mb-3">Top articles — <?= htmlspecialchars($label) ?></h2>
|
||||
<ol class="list-unstyled">
|
||||
<?php foreach ($topItems as $i => ['article' => $a, 'visitors' => $v]): ?>
|
||||
<li class="d-flex align-items-baseline gap-3 py-2 border-bottom">
|
||||
<span class="text-muted" style="min-width:1.5rem;font-variant-numeric:tabular-nums"><?= $i + 1 ?></span>
|
||||
<div class="flex-grow-1 overflow-hidden">
|
||||
<a href="<?= htmlspecialchars($base . '/post/' . rawurlencode($a['slug'])) ?>"
|
||||
class="text-decoration-none fw-medium text-truncate d-block">
|
||||
<?= htmlspecialchars($a['title'] ?? '') ?>
|
||||
</a>
|
||||
<?php if (!empty($a['category'])): ?>
|
||||
<span class="badge bg-secondary fw-normal small"><?= htmlspecialchars($a['category']) ?></span>
|
||||
<?php endif; ?>
|
||||
</div>
|
||||
<span class="text-muted small text-nowrap"><?= number_format($v, 0, ',', "\u{202F}") ?> vis.</span>
|
||||
</li>
|
||||
<?php endforeach; ?>
|
||||
</ol>
|
||||
<?php endif; ?>
|
||||
|
||||
<!-- Flux RSS -->
|
||||
<div class="card mt-5">
|
||||
<div class="card-header bg-transparent py-2 small fw-semibold">Flux RSS disponibles</div>
|
||||
<div class="card-body py-2">
|
||||
<p class="small text-muted mb-3">
|
||||
Chaque flux retourne les 50 articles les plus consultés pour la période choisie,
|
||||
mis à jour automatiquement. Abonnez-vous à celui qui correspond à vos besoins.
|
||||
</p>
|
||||
<div class="table-responsive">
|
||||
<table class="table table-sm table-hover mb-0 small">
|
||||
<thead class="table-light">
|
||||
<tr>
|
||||
<th>Période</th>
|
||||
<th>Cache</th>
|
||||
<th>URL</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<?php
|
||||
$cacheTtlLabels = [
|
||||
'10m' => '2 min', '20m' => '4 min', '30m' => '6 min',
|
||||
'1h' => '12 min', '8h' => '96 min', '1d' => '5 h',
|
||||
'7d' => '8 h', '14d' => '8 h', '30d' => '8 h',
|
||||
'1y' => '8 h',
|
||||
];
|
||||
foreach (TENDANCES_PERIODS as $p => $info):
|
||||
$url = $base . '/trending?period=' . rawurlencode($p);
|
||||
?>
|
||||
<tr>
|
||||
<td><?= htmlspecialchars($info['label']) ?></td>
|
||||
<td class="text-muted"><?= $cacheTtlLabels[$p] ?></td>
|
||||
<td>
|
||||
<a href="<?= htmlspecialchars($url) ?>" class="font-monospace text-decoration-none small">
|
||||
/trending?period=<?= htmlspecialchars($p) ?>
|
||||
</a>
|
||||
</td>
|
||||
</tr>
|
||||
<?php endforeach; ?>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Méthodologie -->
|
||||
<div class="card mt-4">
|
||||
<div class="card-header bg-transparent py-2 small fw-semibold">Méthodologie</div>
|
||||
<div class="card-body small text-muted">
|
||||
<ul class="mb-0 ps-3">
|
||||
<li>Source : journaux d'accès Apache (<code>access.log</code> et rotations <code>.gz</code>).</li>
|
||||
<li>Seules les requêtes <code>GET</code> sur <code>/post/*</code> avec code <code>HTTP 200</code> sont comptabilisées.</li>
|
||||
<li>Un visiteur = une adresse IP distincte par article sur la fenêtre temporelle.</li>
|
||||
<li>Les IPs ne sont ni stockées ni transmises ; seuls les compteurs agrégés sont conservés en cache.</li>
|
||||
<li>Les articles dans des catégories privées et les avant-premières ne figurent pas dans les résultats.</li>
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
<?php
|
||||
$content = ob_get_clean();
|
||||
|
||||
http_response_code(200);
|
||||
header('Cache-Control: public, max-age=' . $cacheTtl);
|
||||
|
||||
$templateVars = [
|
||||
'title' => $pageTitle,
|
||||
'content' => $content,
|
||||
'mainClass' => '',
|
||||
];
|
||||
extract($templateVars);
|
||||
require BASE_PATH . '/templates/layout.php';
|
||||
@@ -0,0 +1,135 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
define('BASE_PATH', realpath(__DIR__ . '/../'));
|
||||
|
||||
require_once BASE_PATH . '/src/auth.php';
|
||||
require_once BASE_PATH . '/src/SiteSettings.php';
|
||||
require_once BASE_PATH . '/config/config.php';
|
||||
require_once BASE_PATH . '/src/ArticleManager.php';
|
||||
require_once BASE_PATH . '/src/TrendingParser.php';
|
||||
|
||||
// ── Périodes supportées ───────────────────────────────────────────────────────
|
||||
|
||||
const TRENDING_PERIODS = [
|
||||
'10m' => ['seconds' => 600, 'label' => '10 dernières minutes'],
|
||||
'20m' => ['seconds' => 1200, 'label' => '20 dernières minutes'],
|
||||
'30m' => ['seconds' => 1800, 'label' => '30 dernières minutes'],
|
||||
'1h' => ['seconds' => 3600, 'label' => 'dernière heure'],
|
||||
'8h' => ['seconds' => 28800, 'label' => '8 dernières heures'],
|
||||
'1d' => ['seconds' => 86400, 'label' => '24 dernières heures'],
|
||||
'7d' => ['seconds' => 604800, 'label' => '7 derniers jours'],
|
||||
'14d' => ['seconds' => 1209600, 'label' => '14 derniers jours'],
|
||||
'30d' => ['seconds' => 2592000, 'label' => '30 derniers jours'],
|
||||
'1y' => ['seconds' => 31536000, 'label' => 'dernière année'],
|
||||
];
|
||||
|
||||
$period = $_GET['period'] ?? '1d';
|
||||
|
||||
if (!array_key_exists($period, TRENDING_PERIODS)) {
|
||||
http_response_code(400);
|
||||
header('Content-Type: text/plain; charset=UTF-8');
|
||||
echo 'Période invalide. Valeurs acceptées : ' . implode(', ', array_keys(TRENDING_PERIODS));
|
||||
exit;
|
||||
}
|
||||
|
||||
$seconds = TRENDING_PERIODS[$period]['seconds'];
|
||||
$label = TRENDING_PERIODS[$period]['label'];
|
||||
$cutoff = time() - $seconds;
|
||||
$cacheTtl = max(60, min(28800, (int) ($seconds / 5)));
|
||||
|
||||
// ── Cache ─────────────────────────────────────────────────────────────────────
|
||||
|
||||
@mkdir(DATA_PATH . '/_cache', 0755, true);
|
||||
$cacheFile = DATA_PATH . '/_cache/trending_' . $period . '.json';
|
||||
$topPaths = null;
|
||||
|
||||
if (file_exists($cacheFile) && (time() - filemtime($cacheFile)) < $cacheTtl) {
|
||||
$topPaths = json_decode((string) file_get_contents($cacheFile), true) ?: null;
|
||||
}
|
||||
|
||||
if ($topPaths === null) {
|
||||
$parser = new TrendingParser('/var/log/apache2', apacheAccessLog());
|
||||
$topPaths = $parser->top($cutoff, 50);
|
||||
@file_put_contents($cacheFile, json_encode($topPaths));
|
||||
}
|
||||
|
||||
// ── Index slug → article (publiés, non privés) ────────────────────────────────
|
||||
|
||||
$articleManager = new ArticleManager(DATA_PATH);
|
||||
$now = time();
|
||||
$privateCats = $articleManager->getPrivateCategories();
|
||||
$slugIndex = [];
|
||||
|
||||
foreach ($articleManager->getAll(publishedOnly: true) as $a) {
|
||||
if (strtotime((string) ($a['published_at'] ?? '')) > $now) {
|
||||
continue;
|
||||
}
|
||||
$cat = trim($a['category'] ?? '');
|
||||
if ($cat !== '' && in_array($cat, $privateCats, true)) {
|
||||
continue;
|
||||
}
|
||||
$slugIndex[$a['slug']] = $a;
|
||||
}
|
||||
|
||||
// ── Construction des items ────────────────────────────────────────────────────
|
||||
|
||||
$base = rtrim(APP_URL, '/');
|
||||
$items = [];
|
||||
|
||||
foreach ($topPaths as $path => $visitors) {
|
||||
if (!preg_match('#^/post/([^/]+)$#', $path, $m)) {
|
||||
continue;
|
||||
}
|
||||
$slug = rawurldecode($m[1]);
|
||||
$article = $slugIndex[$slug] ?? null;
|
||||
if ($article === null) {
|
||||
continue;
|
||||
}
|
||||
$items[] = ['article' => $article, 'visitors' => (int) $visitors];
|
||||
if (count($items) >= 50) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// ── Réponse RSS ───────────────────────────────────────────────────────────────
|
||||
|
||||
header('Content-Type: application/rss+xml; charset=UTF-8');
|
||||
header('X-Content-Type-Options: nosniff');
|
||||
header('Cache-Control: public, max-age=' . $cacheTtl);
|
||||
|
||||
$feedTitle = htmlspecialchars(siteTitle() . ' — Tendances (' . $label . ')', ENT_XML1);
|
||||
$feedUrl = htmlspecialchars($base . '/trending?period=' . rawurlencode($period), ENT_XML1);
|
||||
$baseXml = htmlspecialchars($base, ENT_XML1);
|
||||
$buildDate = htmlspecialchars(date(DATE_RSS));
|
||||
$descXml = htmlspecialchars('Top 50 articles par visiteurs uniques — ' . $label, ENT_XML1);
|
||||
$langXml = htmlspecialchars(siteLang(), ENT_XML1);
|
||||
|
||||
echo '<?xml version="1.0" encoding="UTF-8"?>' . "\n";
|
||||
?>
|
||||
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
|
||||
<channel>
|
||||
<title><?= $feedTitle ?></title>
|
||||
<link><?= $baseXml ?></link>
|
||||
<description><?= $descXml ?></description>
|
||||
<language><?= $langXml ?></language>
|
||||
<lastBuildDate><?= $buildDate ?></lastBuildDate>
|
||||
<atom:link href="<?= $feedUrl ?>" rel="self" type="application/rss+xml"/>
|
||||
<?php foreach ($items as ['article' => $a, 'visitors' => $v]):
|
||||
$link = htmlspecialchars($base . '/post/' . rawurlencode($a['slug']), ENT_XML1);
|
||||
$pubDate = htmlspecialchars(date(DATE_RSS, (int) strtotime((string) ($a['published_at'] ?? $a['created_at'] ?? ''))));
|
||||
$title = htmlspecialchars(($a['title'] ?? ''), ENT_XML1);
|
||||
$plural = $v > 1 ? 's' : '';
|
||||
$desc = htmlspecialchars($title . ' — ' . $v . ' visiteur' . $plural . ' unique' . $plural . ' (' . $label . ')', ENT_XML1);
|
||||
?>
|
||||
<item>
|
||||
<title><?= $title ?> (<?= $v ?> visiteur<?= $plural ?>)</title>
|
||||
<link><?= $link ?></link>
|
||||
<description><?= $desc ?></description>
|
||||
<pubDate><?= $pubDate ?></pubDate>
|
||||
<guid isPermaLink="true"><?= $link ?></guid>
|
||||
</item>
|
||||
<?php endforeach; ?>
|
||||
</channel>
|
||||
</rss>
|
||||
+1
-1
@@ -1 +1 @@
|
||||
1.2.2
|
||||
1.6.27
|
||||
|
||||
+12
-3
@@ -1,5 +1,6 @@
|
||||
#!/usr/bin/env bash
|
||||
# Pousse le code Folio vers git.abonnel.fr/cedricAbonnel/folio
|
||||
# Pousse la branche courante vers git.abonnel.fr/cedricAbonnel/folio
|
||||
# Ne pousse JAMAIS directement sur main — passer par une PR.
|
||||
# Usage : ./scripts/push.sh "message de commit"
|
||||
set -euo pipefail
|
||||
|
||||
@@ -20,6 +21,13 @@ if [ ! -d .git ]; then
|
||||
echo "→ Dépôt git initialisé"
|
||||
fi
|
||||
|
||||
BRANCH=$(git rev-parse --abbrev-ref HEAD)
|
||||
if [[ "$BRANCH" == "main" ]]; then
|
||||
echo "✗ Refus de pousser directement sur main."
|
||||
echo " Travailler sur 'dev' ou une branche feature : git checkout dev"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Extraire la version depuis CHANGELOG.md (première entrée ## [X.Y.Z])
|
||||
FOLIO_VERSION=$(grep -m1 '^\#\# \[[0-9]' CHANGELOG.md | sed 's/.*\[\([^]]*\)\].*/\1/')
|
||||
if [[ -z "$FOLIO_VERSION" ]]; then
|
||||
@@ -32,5 +40,6 @@ echo "→ Version : $FOLIO_VERSION"
|
||||
git add -A
|
||||
git diff --cached --quiet && echo "(rien à committer)" && exit 0
|
||||
git commit -m "$MSG"
|
||||
git push origin main
|
||||
echo "✓ Poussé vers folio"
|
||||
git push origin "$BRANCH"
|
||||
echo "✓ Poussé vers folio (branche $BRANCH)"
|
||||
echo " → Ouvrir une PR sur https://git.abonnel.fr/cedricAbonnel/folio/pulls/new/$BRANCH"
|
||||
|
||||
@@ -0,0 +1,79 @@
|
||||
#!/usr/bin/env bash
|
||||
# folio-upgrade.sh — déploie Folio à la demande (appelé par PHP via sudo).
|
||||
#
|
||||
# Usage : folio-upgrade.sh <branche>
|
||||
#
|
||||
# Installation sur chaque serveur :
|
||||
# sudo install -o root -m 750 folio-upgrade.sh /usr/local/bin/folio-upgrade.sh
|
||||
#
|
||||
# Autorisation sudo (sans mot de passe) :
|
||||
# echo "www-data ALL=(root) NOPASSWD: /usr/local/bin/folio-upgrade.sh" \
|
||||
# | sudo tee /etc/sudoers.d/folio-upgrade
|
||||
#
|
||||
# ── Configuration (à adapter par site) ───────────────────────────────────────
|
||||
APP_DIR=/var/www/lan.acegrp.abonnel-www
|
||||
REPO_URL=https://git.abonnel.fr/cedricAbonnel/folio.git
|
||||
# ──────────────────────────────────────────────────────────────────────────────
|
||||
|
||||
BRANCH=${1:-main}
|
||||
|
||||
ENV_FILE="$APP_DIR/.env"
|
||||
[ -f "$ENV_FILE" ] || { echo "ERREUR : $ENV_FILE introuvable"; exit 1; }
|
||||
|
||||
DATA_DIR=$(grep -m1 '^DATA_PATH=' "$ENV_FILE" | cut -d= -f2- | tr -d '"'"'" | xargs)
|
||||
[ -n "$DATA_DIR" ] || { echo "ERREUR : DATA_PATH absent du .env"; exit 1; }
|
||||
|
||||
LOG="$DATA_DIR/.upgrade-log"
|
||||
WORK_DIR=$(mktemp -d)
|
||||
trap 'rm -rf "$WORK_DIR"' EXIT
|
||||
|
||||
{
|
||||
echo "=== $(date '+%Y-%m-%d %H:%M:%S') — démarrage ==="
|
||||
echo "Branche : $BRANCH"
|
||||
echo ""
|
||||
|
||||
# 1. Sauvegarder .env avant de toucher APP_DIR
|
||||
cp "$ENV_FILE" "$WORK_DIR/.env.bak" || { echo "ERREUR : sauvegarde .env impossible"; exit 1; }
|
||||
|
||||
# 2. Cloner dans un répertoire de travail (APP_DIR reste intact en cas d'échec du clone)
|
||||
git clone --depth=1 --branch "$BRANCH" "$REPO_URL" "$WORK_DIR/app" \
|
||||
|| { echo "ERREUR : git clone"; exit 1; }
|
||||
|
||||
# 3. Déployer
|
||||
rm -rf "$APP_DIR"
|
||||
mv "$WORK_DIR/app" "$APP_DIR"
|
||||
|
||||
# 4. Permissions (PHP-FPM tourne en www-data)
|
||||
chown -R www-data:www-data "$APP_DIR"
|
||||
chmod -R g+rwX,o= "$APP_DIR"
|
||||
|
||||
# 5. Restaurer .env
|
||||
cp "$WORK_DIR/.env.bak" "$APP_DIR/.env"
|
||||
chown www-data:www-data "$APP_DIR/.env"
|
||||
chmod 640 "$APP_DIR/.env"
|
||||
|
||||
cd "$APP_DIR"
|
||||
|
||||
# 6. Dépendances Composer
|
||||
if command -v composer > /dev/null 2>&1; then
|
||||
sudo -u www-data composer install --no-dev --optimize-autoloader \
|
||||
|| echo "AVERTISSEMENT : composer install a échoué"
|
||||
else
|
||||
echo "AVERTISSEMENT : composer introuvable — dépendances non installées"
|
||||
fi
|
||||
|
||||
# 7. Migrations SQL
|
||||
sudo -u www-data php database/migrate.php \
|
||||
|| echo "AVERTISSEMENT : migrations SQL — vérifier manuellement"
|
||||
|
||||
# 8. Répertoire de sessions PHP
|
||||
mkdir -p "$APP_DIR/.sessions"
|
||||
chown www-data:www-data "$APP_DIR/.sessions"
|
||||
chmod 700 "$APP_DIR/.sessions"
|
||||
|
||||
# 9. Autoriser git pour ce répertoire (accès multi-utilisateurs)
|
||||
git config --system --add safe.directory "$APP_DIR" 2>/dev/null || true
|
||||
|
||||
echo ""
|
||||
echo "=== $(date '+%Y-%m-%d %H:%M:%S') — succès ==="
|
||||
} > "$LOG" 2>&1
|
||||
+38
-15
@@ -30,7 +30,7 @@ class AccessLogParser
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array{pages:array<string,int>,books:array<string,int>,ips:array<string,int>}
|
||||
* @return array{pages:array<string,int>,books:array<string,int>,ips:array<string,int>,pages_by_day:array<string,list<int>>}
|
||||
*/
|
||||
public function stats(): array
|
||||
{
|
||||
@@ -44,20 +44,34 @@ class AccessLogParser
|
||||
}
|
||||
}
|
||||
|
||||
$cutoff = strtotime("-{$this->days} days midnight") ?: (time() - $this->days * 86400);
|
||||
$pages = [];
|
||||
$books = [];
|
||||
$ips = [];
|
||||
$cutoff = strtotime("-{$this->days} days midnight") ?: (time() - $this->days * 86400);
|
||||
$pages = [];
|
||||
$books = [];
|
||||
$ips = [];
|
||||
$dayPages = []; // [path => [dayOffset => count]], dayOffset 0=oldest
|
||||
|
||||
foreach ($this->logFiles() as $file) {
|
||||
$this->parseFile($file, $cutoff, $pages, $books, $ips);
|
||||
$this->parseFile($file, $cutoff, $pages, $books, $ips, $dayPages);
|
||||
}
|
||||
|
||||
arsort($pages);
|
||||
arsort($books);
|
||||
arsort($ips);
|
||||
|
||||
$result = compact('pages', 'books', 'ips');
|
||||
// Normalise dayPages : pour chaque page, tableau de $this->days entiers (index 0 = le plus ancien)
|
||||
$pagesByDay = [];
|
||||
$today = (int) strtotime('today midnight');
|
||||
foreach ($dayPages as $path => $byOffset) {
|
||||
$arr = array_fill(0, $this->days, 0);
|
||||
foreach ($byOffset as $offset => $count) {
|
||||
if ($offset >= 0 && $offset < $this->days) {
|
||||
$arr[$offset] = $count;
|
||||
}
|
||||
}
|
||||
$pagesByDay[$path] = $arr;
|
||||
}
|
||||
|
||||
$result = ['pages' => $pages, 'books' => $books, 'ips' => $ips, 'pages_by_day' => $pagesByDay];
|
||||
@mkdir(dirname($this->cacheFile), 0755, true);
|
||||
@file_put_contents($this->cacheFile, json_encode($result, JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES));
|
||||
return self::$memo = $result;
|
||||
@@ -113,7 +127,7 @@ class AccessLogParser
|
||||
return (int) strtotime("{$m[1]} {$m[2]} {$m[3]} {$m[4]} {$m[5]}");
|
||||
}
|
||||
|
||||
private function parseLine(string $line, int $cutoff, array &$pages, array &$books, array &$ips): void
|
||||
private function parseLine(string $line, int $cutoff, array &$pages, array &$books, array &$ips, array &$dayPages): void
|
||||
{
|
||||
if (!preg_match(self::RE, $line, $m)) {
|
||||
return;
|
||||
@@ -123,20 +137,29 @@ class AccessLogParser
|
||||
if ($status !== '200') {
|
||||
return;
|
||||
}
|
||||
if (self::parseTimestamp($ts) < $cutoff) {
|
||||
$tsVal = self::parseTimestamp($ts);
|
||||
if ($tsVal < $cutoff) {
|
||||
return;
|
||||
}
|
||||
|
||||
$publicIp = filter_var($ip, FILTER_VALIDATE_IP, FILTER_FLAG_NO_PRIV_RANGE | FILTER_FLAG_NO_RES_RANGE) !== false;
|
||||
|
||||
if (str_starts_with($path, '/post/') && strlen($path) > 6) {
|
||||
$pages[$path] = ($pages[$path] ?? 0) + 1;
|
||||
$ips[$ip] = ($ips[$ip] ?? 0) + 1;
|
||||
if ($publicIp) {
|
||||
$ips[$ip] = ($ips[$ip] ?? 0) + 1;
|
||||
}
|
||||
$dayOffset = (int) floor(($tsVal - $cutoff) / 86400);
|
||||
$dayPages[$path][$dayOffset] = ($dayPages[$path][$dayOffset] ?? 0) + 1;
|
||||
} elseif (str_starts_with($path, '/book/') && strlen($path) > 6) {
|
||||
$books[$path] = ($books[$path] ?? 0) + 1;
|
||||
$ips[$ip] = ($ips[$ip] ?? 0) + 1;
|
||||
if ($publicIp) {
|
||||
$ips[$ip] = ($ips[$ip] ?? 0) + 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private function parseFile(array $file, int $cutoff, array &$pages, array &$books, array &$ips): void
|
||||
private function parseFile(array $file, int $cutoff, array &$pages, array &$books, array &$ips, array &$dayPages): void
|
||||
{
|
||||
if ($file['type'] === 'tgz') {
|
||||
try {
|
||||
@@ -147,7 +170,7 @@ class AccessLogParser
|
||||
continue;
|
||||
}
|
||||
foreach (explode("\n", $content) as $line) {
|
||||
$this->parseLine($line, $cutoff, $pages, $books, $ips);
|
||||
$this->parseLine($line, $cutoff, $pages, $books, $ips, $dayPages);
|
||||
}
|
||||
}
|
||||
} catch (\Exception $e) {
|
||||
@@ -160,7 +183,7 @@ class AccessLogParser
|
||||
while (!gzeof($h)) {
|
||||
$line = gzgets($h, 8192);
|
||||
if ($line !== false) {
|
||||
$this->parseLine($line, $cutoff, $pages, $books, $ips);
|
||||
$this->parseLine($line, $cutoff, $pages, $books, $ips, $dayPages);
|
||||
}
|
||||
}
|
||||
gzclose($h);
|
||||
@@ -170,7 +193,7 @@ class AccessLogParser
|
||||
return;
|
||||
}
|
||||
while (($line = fgets($h)) !== false) {
|
||||
$this->parseLine($line, $cutoff, $pages, $books, $ips);
|
||||
$this->parseLine($line, $cutoff, $pages, $books, $ips, $dayPages);
|
||||
}
|
||||
fclose($h);
|
||||
}
|
||||
|
||||
+167
-45
@@ -9,7 +9,7 @@ class ArticleManager
|
||||
private ?array $allCache = null;
|
||||
private ?array $searchIndexCache = null;
|
||||
|
||||
public function __construct(private string $dataDir)
|
||||
public function __construct(private string $dataDir, private ?DataGit $git = null)
|
||||
{
|
||||
}
|
||||
|
||||
@@ -30,6 +30,14 @@ class ArticleManager
|
||||
|
||||
private function loadAll(): array
|
||||
{
|
||||
$cachePath = $this->allListCachePath();
|
||||
if (file_exists($cachePath)) {
|
||||
$cached = json_decode((string)file_get_contents($cachePath), true);
|
||||
if (is_array($cached) && $cached !== []) {
|
||||
return $cached;
|
||||
}
|
||||
}
|
||||
|
||||
$articles = [];
|
||||
if (!is_dir($this->dataDir)) {
|
||||
return $articles;
|
||||
@@ -44,7 +52,7 @@ class ArticleManager
|
||||
continue;
|
||||
}
|
||||
|
||||
$article = $this->loadArticle($dir);
|
||||
$article = $this->loadArticle($dir, false);
|
||||
if (!$article) {
|
||||
continue;
|
||||
}
|
||||
@@ -53,6 +61,25 @@ class ArticleManager
|
||||
|
||||
usort($articles, static fn ($a, $b) => strcmp($b['published_at'] ?? '', $a['published_at'] ?? ''));
|
||||
|
||||
// Enrichir avec le plain text pré-calculé (pour les excerpts sans charger index.md)
|
||||
$siPath = $this->dataDir . '/search_index.json';
|
||||
if (file_exists($siPath)) {
|
||||
$si = json_decode((string)file_get_contents($siPath), true);
|
||||
if (is_array($si)) {
|
||||
$plainByUuid = array_column($si, 'plain', 'uuid');
|
||||
foreach ($articles as &$a) {
|
||||
$a['plain'] = $plainByUuid[$a['uuid']] ?? '';
|
||||
}
|
||||
unset($a);
|
||||
}
|
||||
}
|
||||
|
||||
$cacheDir = dirname($cachePath);
|
||||
if (!is_dir($cacheDir)) {
|
||||
@mkdir($cacheDir, 0755, true);
|
||||
}
|
||||
@file_put_contents($cachePath, json_encode($articles, JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES));
|
||||
|
||||
return $articles;
|
||||
}
|
||||
|
||||
@@ -105,8 +132,8 @@ class ArticleManager
|
||||
$publishedAt = $publishedAt !== '' ? $publishedAt : $now;
|
||||
|
||||
$dir = $this->dataDir . '/' . $uuid;
|
||||
mkdir($dir, 0755, true);
|
||||
mkdir($dir . '/files', 0755, true);
|
||||
$this->mkArticleDir($dir);
|
||||
$this->mkArticleDir($dir . '/files');
|
||||
|
||||
$meta = [
|
||||
'uuid' => $uuid,
|
||||
@@ -132,11 +159,27 @@ class ArticleManager
|
||||
file_put_contents($dir . '/index.md', ltrim($content));
|
||||
$this->rebuildSearchIndex();
|
||||
$this->rebuildBacklinksCache();
|
||||
$this->git?->commit("add: $title");
|
||||
|
||||
return $uuid;
|
||||
}
|
||||
|
||||
public function update(string $uuid, string $title, string $content, bool $published, string $slug, string $publishedAt, string $revisionComment = '', string $seoTitle = '', string $seoDescription = '', string $ogImage = '', string $category = '', ?array $tags = null): void
|
||||
/** Crée un brouillon en copiant titre, contenu, catégorie et tags d'un article existant. */
|
||||
public function duplicate(string $sourceUuid, string $author = ''): ?string
|
||||
{
|
||||
$source = $this->getByUuid($sourceUuid);
|
||||
if (!$source) {
|
||||
return null;
|
||||
}
|
||||
$newTitle = 'Copie de ' . ($source['title'] ?? '');
|
||||
$content = $source['content'] ?? '';
|
||||
$category = $source['category'] ?? '';
|
||||
$tags = $source['tags'] ?? [];
|
||||
$newAuthor = $author !== '' ? $author : ($source['author'] ?? '');
|
||||
return $this->create($newTitle, $content, false, '', '', $newAuthor, '', '', '', $category, $tags);
|
||||
}
|
||||
|
||||
public function update(string $uuid, string $title, string $content, bool $published, string $slug, string $publishedAt, string $revisionComment = '', string $seoTitle = '', string $seoDescription = '', string $ogImage = '', string $category = '', ?array $tags = null, bool $skipGit = false): void
|
||||
{
|
||||
$article = $this->getByUuid($uuid);
|
||||
if (!$article) {
|
||||
@@ -154,7 +197,7 @@ class ArticleManager
|
||||
if ($contentChanged || $titleChanged) {
|
||||
$revDir = $this->dataDir . '/' . $uuid . '/revisions';
|
||||
if (!is_dir($revDir)) {
|
||||
mkdir($revDir, 0755, true);
|
||||
$this->mkArticleDir($revDir);
|
||||
}
|
||||
$n = count($revisions) + 1;
|
||||
$revFile = sprintf('%s/%04d.md', $revDir, $n);
|
||||
@@ -199,6 +242,9 @@ class ArticleManager
|
||||
file_put_contents($dir . '/index.md', ltrim($content));
|
||||
$this->rebuildSearchIndex();
|
||||
$this->rebuildBacklinksCache();
|
||||
if (!$skipGit) {
|
||||
$this->git?->commit("update: $title");
|
||||
}
|
||||
}
|
||||
|
||||
public function autosave(string $uuid, string $title, string $content, string $slug): bool
|
||||
@@ -247,6 +293,7 @@ class ArticleManager
|
||||
}
|
||||
$meta['updated_at'] = date('Y-m-d H:i:s');
|
||||
$this->writeMeta($dir, $meta);
|
||||
$this->git?->commit('meta: ' . ($meta['title'] ?? $uuid));
|
||||
}
|
||||
|
||||
public function saveDraftOverlay(string $uuid, array $metaFields, ?string $content = null): void
|
||||
@@ -269,6 +316,9 @@ class ArticleManager
|
||||
if ($content !== null) {
|
||||
file_put_contents($dir . '/draft_overlay.md', $content);
|
||||
}
|
||||
$raw2 = @file_get_contents($dir . '/meta.json');
|
||||
$title = is_string($raw2) ? (json_decode($raw2, true)['title'] ?? $uuid) : $uuid;
|
||||
$this->git?->commit("draft: $title");
|
||||
}
|
||||
|
||||
public function getDraftOverlay(string $uuid): ?array
|
||||
@@ -315,14 +365,22 @@ class ArticleManager
|
||||
return file_exists($this->dataDir . '/' . $uuid . '/draft_overlay.json');
|
||||
}
|
||||
|
||||
public function discardDraftOverlay(string $uuid): void
|
||||
public function discardDraftOverlay(string $uuid, bool $skipGit = false): void
|
||||
{
|
||||
if (!$this->isValidUuid($uuid)) {
|
||||
return;
|
||||
}
|
||||
$dir = $this->dataDir . '/' . $uuid;
|
||||
$dir = $this->dataDir . '/' . $uuid;
|
||||
$title = null;
|
||||
if (!$skipGit && $this->git !== null) {
|
||||
$raw = @file_get_contents($dir . '/meta.json');
|
||||
$title = is_string($raw) ? (json_decode($raw, true)['title'] ?? $uuid) : $uuid;
|
||||
}
|
||||
@unlink($dir . '/draft_overlay.json');
|
||||
@unlink($dir . '/draft_overlay.md');
|
||||
if ($title !== null) {
|
||||
$this->git->commit("discard-draft: $title");
|
||||
}
|
||||
}
|
||||
|
||||
public function commitDraftOverlay(string $uuid, string $revisionComment = ''): void
|
||||
@@ -331,9 +389,10 @@ class ArticleManager
|
||||
if (!$draft) {
|
||||
return;
|
||||
}
|
||||
$title = $draft['title'];
|
||||
$this->update(
|
||||
$uuid,
|
||||
$draft['title'],
|
||||
$title,
|
||||
$draft['content'],
|
||||
(bool)$draft['published'],
|
||||
$draft['slug'] ?? '',
|
||||
@@ -343,12 +402,14 @@ class ArticleManager
|
||||
$draft['seo_description'] ?? '',
|
||||
$draft['og_image'] ?? '',
|
||||
$draft['category'] ?? '',
|
||||
$draft['tags'] ?? []
|
||||
$draft['tags'] ?? [],
|
||||
true // skipGit — commit unique ci-dessous
|
||||
);
|
||||
$this->discardDraftOverlay($uuid);
|
||||
$this->discardDraftOverlay($uuid, skipGit: true);
|
||||
$this->git?->commit("publish: $title");
|
||||
}
|
||||
|
||||
public function addFileMeta(string $uuid, string $filename, string $author, string $sourceUrl, string $title = '', array $extraMeta = []): void
|
||||
public function addFileMeta(string $uuid, string $filename, string $author, string $sourceUrl, string $title = '', array $extraMeta = [], bool $skipGit = false): void
|
||||
{
|
||||
if (!$this->isValidUuid($uuid)) {
|
||||
return;
|
||||
@@ -377,6 +438,9 @@ class ArticleManager
|
||||
}
|
||||
$meta['files_meta'][$filename] = $entry;
|
||||
$this->writeMeta($this->dataDir . '/' . $uuid, $meta);
|
||||
if (!$skipGit) {
|
||||
$this->git?->commit("file-meta: {$uuid}/{$filename}");
|
||||
}
|
||||
}
|
||||
|
||||
public function setCover(string $uuid, string $filename): void
|
||||
@@ -424,6 +488,7 @@ class ArticleManager
|
||||
}
|
||||
$meta['cover'] = $coverName;
|
||||
$this->writeMeta($this->dataDir . '/' . $uuid, $meta);
|
||||
$this->git?->commit('cover: ' . ($article['title'] ?? $uuid));
|
||||
}
|
||||
|
||||
public function addFileFromUrl(string $uuid, string $url, bool $isCover = false, string $author = '', string $sourceUrl = '', string $title = '', array $extraMeta = []): ?string
|
||||
@@ -459,7 +524,7 @@ class ArticleManager
|
||||
$isImage = str_starts_with($mime, 'image/');
|
||||
$filesDir = $this->dataDir . '/' . $uuid . '/files';
|
||||
if (!is_dir($filesDir)) {
|
||||
mkdir($filesDir, 0755, true);
|
||||
$this->mkArticleDir($filesDir);
|
||||
}
|
||||
|
||||
if ($isImage) {
|
||||
@@ -499,7 +564,7 @@ class ArticleManager
|
||||
rename($tmp, $filesDir . '/' . $filename);
|
||||
|
||||
if ($author !== '' || $sourceUrl !== '' || $title !== '' || !empty($extraMeta)) {
|
||||
$this->addFileMeta($uuid, $filename, $author, $sourceUrl, $title, $extraMeta);
|
||||
$this->addFileMeta($uuid, $filename, $author, $sourceUrl, $title, $extraMeta, skipGit: true);
|
||||
}
|
||||
|
||||
if ($isCover && $isImage) {
|
||||
@@ -513,6 +578,7 @@ class ArticleManager
|
||||
}
|
||||
}
|
||||
|
||||
$this->git?->commit("add-file: {$uuid}/{$filename}");
|
||||
return $filename;
|
||||
}
|
||||
|
||||
@@ -553,6 +619,7 @@ class ArticleManager
|
||||
$meta['external_links'][] = $entry;
|
||||
$this->writeMeta($dir, $meta);
|
||||
$this->rebuildBacklinksCache();
|
||||
$this->git?->commit("link: {$uuid}");
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -583,6 +650,7 @@ class ArticleManager
|
||||
return false;
|
||||
}
|
||||
$this->writeMeta($dir, $meta);
|
||||
$this->git?->commit("link-meta: {$uuid}");
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -606,6 +674,7 @@ class ArticleManager
|
||||
));
|
||||
$this->writeMeta($dir, $meta);
|
||||
$this->rebuildBacklinksCache();
|
||||
$this->git?->commit("unlink: {$uuid}");
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -623,7 +692,7 @@ class ArticleManager
|
||||
return $cats;
|
||||
}
|
||||
|
||||
public function renameCategory(string $old, string $new): void
|
||||
public function renameCategory(string $old, string $new, bool $skipGit = false): void
|
||||
{
|
||||
if (!is_dir($this->dataDir)) {
|
||||
return;
|
||||
@@ -647,11 +716,15 @@ class ArticleManager
|
||||
$meta['category'] = $new;
|
||||
$this->writeMeta($this->dataDir . '/' . $entry, $meta);
|
||||
}
|
||||
if (!$skipGit) {
|
||||
$this->git?->commit("rename-cat: $old → $new");
|
||||
}
|
||||
}
|
||||
|
||||
public function deleteCategory(string $name): void
|
||||
{
|
||||
$this->renameCategory($name, '');
|
||||
$this->renameCategory($name, '', skipGit: true);
|
||||
$this->git?->commit("delete-cat: $name");
|
||||
}
|
||||
|
||||
public function getPrivateCategories(): array
|
||||
@@ -676,6 +749,7 @@ class ArticleManager
|
||||
$this->dataDir . '/private_cats.json',
|
||||
json_encode(array_values($cats), JSON_UNESCAPED_UNICODE)
|
||||
);
|
||||
$this->git?->commit("private-cat: $cat");
|
||||
}
|
||||
|
||||
// ─── Tag types ──────────────────────────────────────────────────────────────
|
||||
@@ -701,6 +775,7 @@ class ArticleManager
|
||||
$this->tagTypesPath(),
|
||||
json_encode($types, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE) . "\n"
|
||||
);
|
||||
$this->git?->commit('tag-types');
|
||||
}
|
||||
|
||||
/** Enregistre les tags d'un article directement (utile pour les scripts de migration). */
|
||||
@@ -720,6 +795,7 @@ class ArticleManager
|
||||
$meta['tags'] = $this->normalizeTags($tags);
|
||||
$this->writeMeta($dir, $meta);
|
||||
$this->rebuildSearchIndex();
|
||||
$this->git?->commit('tags: ' . ($meta['title'] ?? $uuid));
|
||||
}
|
||||
|
||||
/** @return list<string> Toutes les valeurs distinctes d'un type de tag, triées. */
|
||||
@@ -769,22 +845,34 @@ class ArticleManager
|
||||
$this->writeMeta($dir, $meta);
|
||||
$this->allCache = null;
|
||||
@unlink($this->articleCachePath($uuid));
|
||||
$this->git?->commit('featured: ' . ($meta['title'] ?? $uuid) . ' (' . ($featured ? 'on' : 'off') . ')');
|
||||
}
|
||||
|
||||
public function delete(string $uuid): void
|
||||
public function delete(string $uuid): bool
|
||||
{
|
||||
if (!$this->isValidUuid($uuid)) {
|
||||
return;
|
||||
return false;
|
||||
}
|
||||
$dir = $this->dataDir . '/' . $uuid;
|
||||
$title = null;
|
||||
if ($this->git !== null && is_dir($dir)) {
|
||||
$raw = @file_get_contents($dir . '/meta.json');
|
||||
$title = is_string($raw) ? (json_decode($raw, true)['title'] ?? null) : null;
|
||||
}
|
||||
if (is_dir($dir)) {
|
||||
$this->allCache = null;
|
||||
@unlink($this->articleCachePath($uuid));
|
||||
@unlink($this->slugIndexPath());
|
||||
@unlink($this->allListCachePath());
|
||||
$this->removeDir($dir);
|
||||
}
|
||||
if (is_dir($dir)) {
|
||||
return false;
|
||||
}
|
||||
$this->rebuildSearchIndex();
|
||||
$this->rebuildBacklinksCache();
|
||||
$this->git?->commit('delete: ' . ($title ?? $uuid));
|
||||
return true;
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------ //
|
||||
@@ -806,6 +894,11 @@ class ArticleManager
|
||||
return $this->dataDir . '/_cache/slug_index.json';
|
||||
}
|
||||
|
||||
private function allListCachePath(): string
|
||||
{
|
||||
return $this->dataDir . '/_cache/articles_list.json';
|
||||
}
|
||||
|
||||
private function buildSlugIndex(): void
|
||||
{
|
||||
$cacheDir = $this->dataDir . '/_cache';
|
||||
@@ -899,19 +992,25 @@ class ArticleManager
|
||||
{
|
||||
$index = [];
|
||||
foreach ($this->getAll() as $article) {
|
||||
$uuid = $article['uuid'] ?? '';
|
||||
$contentPath = $this->dataDir . '/' . $uuid . '/index.md';
|
||||
$content = $uuid !== '' && file_exists($contentPath)
|
||||
? (string)file_get_contents($contentPath)
|
||||
: '';
|
||||
$index[] = [
|
||||
'uuid' => $article['uuid'],
|
||||
'uuid' => $uuid,
|
||||
'slug' => $article['slug'] ?? '',
|
||||
'title' => $article['title'] ?? '',
|
||||
'category' => $article['category'] ?? '',
|
||||
'author' => $article['author'] ?? '',
|
||||
'cover' => $article['cover'] ?? '',
|
||||
'featured' => (bool)($article['featured'] ?? false),
|
||||
'published' => $article['published'],
|
||||
'published_at' => $article['published_at'] ?? '',
|
||||
'created_at' => $article['created_at'] ?? '',
|
||||
'updated_at' => $article['updated_at'] ?? '',
|
||||
'tags' => $article['tags'] ?? [],
|
||||
'plain' => $this->stripForIndex($article['content'] ?? ''),
|
||||
'plain' => $this->stripForIndex($content),
|
||||
];
|
||||
}
|
||||
file_put_contents(
|
||||
@@ -982,8 +1081,8 @@ class ArticleManager
|
||||
if (!is_array($data) || empty($data)) {
|
||||
return null;
|
||||
}
|
||||
// Rebuild automatique si le format est obsolète (champs cover/created_at absents)
|
||||
if (!array_key_exists('cover', $data[0])) {
|
||||
// Rebuild automatique si le format est obsolète (champs manquants)
|
||||
if (!array_key_exists('cover', $data[0]) || !array_key_exists('featured', $data[0])) {
|
||||
$this->rebuildSearchIndex();
|
||||
return $this->searchIndexCache;
|
||||
}
|
||||
@@ -1069,7 +1168,7 @@ class ArticleManager
|
||||
}
|
||||
$dir = $this->dataDir . '/' . $uuid . '/files';
|
||||
if (!is_dir($dir)) {
|
||||
mkdir($dir, 0755, true);
|
||||
$this->mkArticleDir($dir);
|
||||
}
|
||||
|
||||
$mime = mime_content_type($uploadedFile['tmp_name']) ?: 'application/octet-stream';
|
||||
@@ -1098,7 +1197,16 @@ class ArticleManager
|
||||
$size = filesize($uploadedFile['tmp_name']);
|
||||
$name = "{$hash}-{$size}.{$ext}";
|
||||
$dest = $dir . '/' . $name;
|
||||
if (!rename($uploadedFile['tmp_name'], $dest) && !move_uploaded_file($uploadedFile['tmp_name'], $dest)) {
|
||||
// Déduplication : si ce fichier identique existe déjà dans un autre article, crée un hardlink
|
||||
if (!file_exists($dest)) {
|
||||
$existing = glob($this->dataDir . '/*/files/' . $name);
|
||||
if (!empty($existing) && is_file($existing[0])) {
|
||||
link($existing[0], $dest) || copy($existing[0], $dest);
|
||||
@unlink($uploadedFile['tmp_name']);
|
||||
return $name;
|
||||
}
|
||||
}
|
||||
if (!file_exists($dest) && !rename($uploadedFile['tmp_name'], $dest) && !move_uploaded_file($uploadedFile['tmp_name'], $dest)) {
|
||||
return null;
|
||||
}
|
||||
return $name;
|
||||
@@ -1155,21 +1263,22 @@ class ArticleManager
|
||||
};
|
||||
}
|
||||
|
||||
private function loadArticle(string $dir): ?array
|
||||
private function loadArticle(string $dir, bool $withContent = true): ?array
|
||||
{
|
||||
$metaPath = $dir . '/meta.json';
|
||||
$metaPath = $dir . '/meta.json';
|
||||
if (!file_exists($metaPath)) {
|
||||
return null;
|
||||
}
|
||||
$uuid = basename($dir);
|
||||
$cachePath = $this->articleCachePath($uuid);
|
||||
|
||||
// Utiliser le cache si plus récent que meta.json ET index.md
|
||||
$contentMtime = file_exists($dir . '/index.md') ? filemtime($dir . '/index.md') : 0;
|
||||
if (file_exists($cachePath) && filemtime($cachePath) >= filemtime($metaPath) && filemtime($cachePath) >= $contentMtime) {
|
||||
$cached = json_decode((string) file_get_contents($cachePath), true);
|
||||
if (is_array($cached) && !empty($cached['uuid'])) {
|
||||
return $cached;
|
||||
if ($withContent) {
|
||||
$uuid = basename($dir);
|
||||
$cachePath = $this->articleCachePath($uuid);
|
||||
$contentMtime = file_exists($dir . '/index.md') ? filemtime($dir . '/index.md') : 0;
|
||||
if (file_exists($cachePath) && filemtime($cachePath) >= filemtime($metaPath) && filemtime($cachePath) >= $contentMtime) {
|
||||
$cached = json_decode((string) file_get_contents($cachePath), true);
|
||||
if (is_array($cached) && !empty($cached['uuid'])) {
|
||||
return $cached;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1182,8 +1291,11 @@ class ArticleManager
|
||||
return null;
|
||||
}
|
||||
|
||||
$contentPath = $dir . '/index.md';
|
||||
$meta['content'] = file_exists($contentPath) ? (string)file_get_contents($contentPath) : '';
|
||||
if ($withContent) {
|
||||
$contentPath = $dir . '/index.md';
|
||||
$meta['content'] = file_exists($contentPath) ? (string)file_get_contents($contentPath) : '';
|
||||
}
|
||||
|
||||
$meta['published'] = (bool)($meta['published'] ?? false);
|
||||
$meta['featured'] = (bool)($meta['featured'] ?? false);
|
||||
$meta['files_meta'] = $meta['files_meta'] ?? [];
|
||||
@@ -1197,12 +1309,15 @@ class ArticleManager
|
||||
}
|
||||
}
|
||||
|
||||
// Écrire le cache
|
||||
$cacheDir = dirname($cachePath);
|
||||
if (!is_dir($cacheDir)) {
|
||||
mkdir($cacheDir, 0755, true);
|
||||
if ($withContent) {
|
||||
$uuid = $meta['uuid'];
|
||||
$cachePath = $this->articleCachePath($uuid);
|
||||
$cacheDir = dirname($cachePath);
|
||||
if (!is_dir($cacheDir)) {
|
||||
mkdir($cacheDir, 0755, true);
|
||||
}
|
||||
file_put_contents($cachePath, json_encode($meta, JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES));
|
||||
}
|
||||
file_put_contents($cachePath, json_encode($meta, JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES));
|
||||
|
||||
return $meta;
|
||||
}
|
||||
@@ -1257,9 +1372,10 @@ class ArticleManager
|
||||
$this->searchIndexCache = null;
|
||||
$uuid = $meta['uuid'] ?? basename($dir);
|
||||
|
||||
// Invalider le cache article et le slug index
|
||||
// Invalider les caches article, liste et slug index
|
||||
@unlink($this->articleCachePath($uuid));
|
||||
@unlink($this->slugIndexPath());
|
||||
@unlink($this->allListCachePath());
|
||||
|
||||
file_put_contents(
|
||||
$dir . '/meta.json',
|
||||
@@ -1329,13 +1445,19 @@ class ArticleManager
|
||||
*/
|
||||
private function removeDir(string $dir): void
|
||||
{
|
||||
foreach (scandir($dir) as $entry) {
|
||||
foreach (@scandir($dir) ?: [] as $entry) {
|
||||
if ($entry === '.' || $entry === '..') {
|
||||
continue;
|
||||
}
|
||||
$path = $dir . '/' . $entry;
|
||||
is_dir($path) ? $this->removeDir($path) : unlink($path);
|
||||
is_dir($path) ? $this->removeDir($path) : @unlink($path);
|
||||
}
|
||||
rmdir($dir);
|
||||
@rmdir($dir);
|
||||
}
|
||||
|
||||
private function mkArticleDir(string $path): void
|
||||
{
|
||||
mkdir($path, 0777, true);
|
||||
chmod($path, 0775);
|
||||
}
|
||||
}
|
||||
|
||||
+6
-3
@@ -4,7 +4,7 @@ declare(strict_types=1);
|
||||
|
||||
class BookManager
|
||||
{
|
||||
public function __construct(private string $booksDir)
|
||||
public function __construct(private string $booksDir, private ?DataGit $git = null)
|
||||
{
|
||||
}
|
||||
|
||||
@@ -95,14 +95,17 @@ class BookManager
|
||||
$this->bookPath($slug),
|
||||
json_encode($book, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES) . "\n"
|
||||
);
|
||||
$this->git?->commit("book: " . ($book['title'] ?? $slug));
|
||||
}
|
||||
|
||||
public function delete(string $slug): void
|
||||
{
|
||||
$path = $this->bookPath($slug);
|
||||
$title = $this->getBySlug($slug)['title'] ?? $slug;
|
||||
$path = $this->bookPath($slug);
|
||||
if (file_exists($path)) {
|
||||
@unlink($path);
|
||||
}
|
||||
$this->git?->commit("delete-book: $title");
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------ //
|
||||
@@ -114,7 +117,7 @@ class BookManager
|
||||
return $this->booksDir . '/' . $slug . '.json';
|
||||
}
|
||||
|
||||
private function sanitizeSlug(string $slug): string
|
||||
public function sanitizeSlug(string $slug): string
|
||||
{
|
||||
$map = [
|
||||
'à' => 'a', 'â' => 'a', 'ä' => 'a',
|
||||
|
||||
@@ -0,0 +1,22 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
class DataGit
|
||||
{
|
||||
public function __construct(private string $dataDir) {}
|
||||
|
||||
public function commit(string $message): void
|
||||
{
|
||||
if (!is_dir($this->dataDir . '/.git')) {
|
||||
return;
|
||||
}
|
||||
$dir = escapeshellarg($this->dataDir);
|
||||
$msg = escapeshellarg($message);
|
||||
shell_exec("git -C $dir add -A 2>/dev/null");
|
||||
exec("git -C $dir diff --cached --quiet 2>/dev/null", $_, $rc);
|
||||
if ($rc !== 0) {
|
||||
shell_exec("git -C $dir commit -m $msg 2>/dev/null");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,16 +0,0 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Domain;
|
||||
|
||||
final class User
|
||||
{
|
||||
public function __construct(
|
||||
public string $id,
|
||||
public string $email,
|
||||
public string $passwordHash,
|
||||
public bool $isActive = true,
|
||||
) {
|
||||
}
|
||||
}
|
||||
@@ -1,129 +0,0 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Repository;
|
||||
|
||||
use App\Domain\User;
|
||||
use PDO;
|
||||
|
||||
final class UserRepository
|
||||
{
|
||||
public function __construct(private PDO $pdo)
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Crée (si besoin) un utilisateur OIDC.
|
||||
* - Idempotent par email : si existe, retourne l'id existant.
|
||||
* - Génère un password_hash aléatoire inutilisable (compte OIDC).
|
||||
*
|
||||
* @return string ID (uuid) sous forme de chaîne
|
||||
*/
|
||||
public function createFromOidc(string $email): string
|
||||
{
|
||||
$email = strtolower(trim($email));
|
||||
if ($email === '' || !filter_var($email, FILTER_VALIDATE_EMAIL)) {
|
||||
throw new \InvalidArgumentException('Email OIDC invalide.');
|
||||
}
|
||||
|
||||
// 1) Existe déjà ?
|
||||
$st = $this->pdo->prepare('SELECT id FROM users WHERE email = :email LIMIT 1');
|
||||
$st->execute([':email' => $email]);
|
||||
$id = $st->fetchColumn();
|
||||
if ($id !== false && $id !== null) {
|
||||
return (string)$id;
|
||||
}
|
||||
|
||||
// 2) Création
|
||||
// Génère un hash robuste sur une valeur aléatoire (aucune chance de connexion par mot de passe).
|
||||
$randomSecret = bin2hex(random_bytes(32));
|
||||
$randomHash = password_hash($randomSecret, PASSWORD_DEFAULT);
|
||||
|
||||
$sql = <<<SQL
|
||||
INSERT INTO users (email, password_hash)
|
||||
VALUES (:email, :hash)
|
||||
RETURNING id
|
||||
SQL;
|
||||
|
||||
try {
|
||||
$st = $this->pdo->prepare($sql);
|
||||
$st->execute([
|
||||
':email' => $email,
|
||||
':hash' => $randomHash,
|
||||
]);
|
||||
return (string)$st->fetchColumn();
|
||||
} catch (\PDOException $e) {
|
||||
// Unique violation sur email (23505) → on relit l’id (race condition)
|
||||
if ($e->getCode() === '23505') {
|
||||
$st = $this->pdo->prepare('SELECT id FROM users WHERE email = :email LIMIT 1');
|
||||
$st->execute([':email' => $email]);
|
||||
$id = $st->fetchColumn();
|
||||
if ($id !== false && $id !== null) {
|
||||
return (string)$id;
|
||||
}
|
||||
}
|
||||
throw $e;
|
||||
}
|
||||
}
|
||||
|
||||
public function findByEmail(string $email): ?User
|
||||
{
|
||||
$sql = 'SELECT id, email, password_hash, is_active FROM users WHERE email = :email LIMIT 1';
|
||||
$st = $this->pdo->prepare($sql);
|
||||
$st->execute([':email' => $email]);
|
||||
$row = $st->fetch(PDO::FETCH_ASSOC);
|
||||
if (!$row) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$isActive = $this->toBool($row['is_active']);
|
||||
|
||||
return new User(
|
||||
(string)$row['id'],
|
||||
(string)$row['email'],
|
||||
(string)$row['password_hash'],
|
||||
$isActive
|
||||
);
|
||||
}
|
||||
|
||||
public function create(string $email, string $passwordHash): string
|
||||
{
|
||||
// PostgreSQL
|
||||
$sql = 'INSERT INTO users (email, password_hash) VALUES (:email, :hash) RETURNING id';
|
||||
$st = $this->pdo->prepare($sql);
|
||||
$st->execute([':email' => $email, ':hash' => $passwordHash]);
|
||||
return (string)$st->fetchColumn();
|
||||
}
|
||||
|
||||
public function updatePassword(string $userId, string $newHash): void
|
||||
{
|
||||
$sql = <<<SQL
|
||||
UPDATE users
|
||||
SET password_hash = :h,
|
||||
updated_at = NOW(),
|
||||
password_changed_at = NOW()
|
||||
WHERE id = :id
|
||||
SQL;
|
||||
$st = $this->pdo->prepare($sql);
|
||||
$st->execute([':h' => $newHash, ':id' => $userId]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Normalise un bool venant de PDO/pgsql ('t','f',1,0,true,false,'1','0','true','false')
|
||||
*/
|
||||
private function toBool(mixed $v): bool
|
||||
{
|
||||
if (is_bool($v)) {
|
||||
return $v;
|
||||
}
|
||||
if (is_int($v)) {
|
||||
return $v === 1;
|
||||
}
|
||||
if (is_string($v)) {
|
||||
$v = strtolower($v);
|
||||
return in_array($v, ['t', '1', 'true', 'on', 'yes'], true);
|
||||
}
|
||||
return (bool)$v;
|
||||
}
|
||||
}
|
||||
+26
-13
@@ -8,22 +8,25 @@ class SearchLogParser
|
||||
private string $vhostBase;
|
||||
private string $cacheFile;
|
||||
private int $cacheTtl;
|
||||
private int $days;
|
||||
|
||||
public function __construct(
|
||||
string $logDir = '/var/log/apache2',
|
||||
string $vhostBase = '*-access.log',
|
||||
string $cacheFile = '',
|
||||
int $cacheTtl = 600
|
||||
int $cacheTtl = 600,
|
||||
int $days = 14
|
||||
) {
|
||||
$this->logDir = rtrim($logDir, '/');
|
||||
$this->vhostBase = $vhostBase;
|
||||
$this->days = max(1, min(30, $days));
|
||||
$this->cacheFile = $cacheFile !== ''
|
||||
? $cacheFile
|
||||
: dirname(__DIR__) . '/_cache/search_terms.json';
|
||||
: dirname(__DIR__) . '/_cache/search_terms_' . $this->days . 'd.json';
|
||||
$this->cacheTtl = $cacheTtl;
|
||||
}
|
||||
|
||||
/** @return array<string,int> terme => nombre d'occurrences, trié desc */
|
||||
/** @return array<string,int> terme => visiteurs uniques, trié desc */
|
||||
public function topTerms(int $limit = 100): array
|
||||
{
|
||||
if ($this->cacheValid()) {
|
||||
@@ -33,9 +36,14 @@ class SearchLogParser
|
||||
}
|
||||
}
|
||||
|
||||
$counts = [];
|
||||
$visitors = []; // terme => [ip => true]
|
||||
foreach ($this->logFiles() as $file) {
|
||||
$this->parseFile($file, $counts);
|
||||
$this->parseFile($file, $visitors);
|
||||
}
|
||||
|
||||
$counts = [];
|
||||
foreach ($visitors as $term => $ips) {
|
||||
$counts[$term] = count($ips);
|
||||
}
|
||||
arsort($counts);
|
||||
|
||||
@@ -61,6 +69,7 @@ class SearchLogParser
|
||||
{
|
||||
$pattern = $this->logDir . '/' . $this->vhostBase;
|
||||
$files = [];
|
||||
$cutoff = time() - $this->days * 86400;
|
||||
|
||||
// Fichiers correspondant au pattern de base (courants + rotations incluses si glob)
|
||||
$bases = glob($pattern) ?: [];
|
||||
@@ -75,6 +84,9 @@ class SearchLogParser
|
||||
if (!is_readable($path)) {
|
||||
continue;
|
||||
}
|
||||
if (@filemtime($path) < $cutoff) {
|
||||
continue;
|
||||
}
|
||||
if (str_ends_with($path, '.tar.gz')) {
|
||||
$files[] = ['path' => $path, 'type' => 'tgz'];
|
||||
} elseif (str_ends_with($path, '.gz')) {
|
||||
@@ -88,7 +100,7 @@ class SearchLogParser
|
||||
return $files;
|
||||
}
|
||||
|
||||
private function parseFile(array $file, array &$counts): void
|
||||
private function parseFile(array $file, array &$visitors): void
|
||||
{
|
||||
if ($file['type'] === 'tgz') {
|
||||
try {
|
||||
@@ -99,7 +111,7 @@ class SearchLogParser
|
||||
continue;
|
||||
}
|
||||
foreach (explode("\n", $content) as $line) {
|
||||
$this->parseLine($line, $counts);
|
||||
$this->parseLine($line, $visitors);
|
||||
}
|
||||
}
|
||||
} catch (\Exception $e) {
|
||||
@@ -113,7 +125,7 @@ class SearchLogParser
|
||||
while (!gzeof($h)) {
|
||||
$line = gzgets($h, 8192);
|
||||
if ($line !== false) {
|
||||
$this->parseLine($line, $counts);
|
||||
$this->parseLine($line, $visitors);
|
||||
}
|
||||
}
|
||||
gzclose($h);
|
||||
@@ -123,28 +135,29 @@ class SearchLogParser
|
||||
return;
|
||||
}
|
||||
while (($line = fgets($h)) !== false) {
|
||||
$this->parseLine($line, $counts);
|
||||
$this->parseLine($line, $visitors);
|
||||
}
|
||||
fclose($h);
|
||||
}
|
||||
}
|
||||
|
||||
private function parseLine(string $line, array &$counts): void
|
||||
private function parseLine(string $line, array &$visitors): void
|
||||
{
|
||||
if (!str_contains($line, 'GET /search?')) {
|
||||
return;
|
||||
}
|
||||
if (!preg_match('/"GET \/search\?([^"]*) HTTP\//', $line, $m)) {
|
||||
if (!preg_match('/^(\S+) \S+ \S+ \[[^\]]+\] "GET \/search\?([^"]*) HTTP\//', $line, $m)) {
|
||||
return;
|
||||
}
|
||||
|
||||
parse_str($m[1], $params);
|
||||
$ip = $m[1];
|
||||
parse_str($m[2], $params);
|
||||
$q = trim(urldecode($params['q'] ?? ''));
|
||||
|
||||
if ($q === '' || mb_strlen($q) > 200) {
|
||||
return;
|
||||
}
|
||||
$q = mb_strtolower($q);
|
||||
$counts[$q] = ($counts[$q] ?? 0) + 1;
|
||||
$visitors[$q][$ip] = true;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,221 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
class AiService
|
||||
{
|
||||
private const SYSTEM_CRITIQUE = <<<'PROMPT'
|
||||
Tu es un relecteur expert de blogs. Analyse l'article ci-dessous et identifie ses faiblesses : arguments insuffisamment étayés, imprécisions, manques de clarté, structure à améliorer, points à développer. Sois constructif et précis. Réponds en markdown avec des sections claires.
|
||||
PROMPT;
|
||||
|
||||
private const SYSTEM_REWRITE = <<<'PROMPT'
|
||||
Tu es un rédacteur expert. Réécris l'article ci-dessous en améliorant le style, la clarté et la structure, sans modifier le sens ni les faits. Conserve le format markdown, les liens et les références aux images. Réponds uniquement avec l'article réécrit, sans commentaire ni explication.
|
||||
PROMPT;
|
||||
|
||||
private const SYSTEM_ANALYZE = <<<'PROMPT'
|
||||
Tu es un relecteur et rédacteur expert de blogs. Pour l'article ci-dessous, fais deux choses :
|
||||
|
||||
1. Identifie ses faiblesses (arguments faibles, imprécisions, manques de clarté, structure à revoir, points à développer). Sois bref et précis — quelques lignes suffisent.
|
||||
|
||||
2. Propose une version améliorée de l'article : meilleur style, clarté, structure. Conserve le sens, les faits, le format markdown, les liens et les références aux images.
|
||||
|
||||
Réponds EXACTEMENT dans ce format (les deux séparateurs doivent être présents tels quels) :
|
||||
|
||||
===CRITIQUE===
|
||||
[ton analyse ici]
|
||||
===REWRITE===
|
||||
[l'article réécrit ici]
|
||||
PROMPT;
|
||||
|
||||
private string $apiKey;
|
||||
private string $model;
|
||||
private string $provider;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
require_once BASE_PATH . '/src/SiteSettings.php';
|
||||
$this->provider = aiProvider();
|
||||
$this->model = aiModel();
|
||||
$this->apiKey = $_ENV['ANTHROPIC_API_KEY'] ?? getenv('ANTHROPIC_API_KEY') ?: '';
|
||||
}
|
||||
|
||||
public function isConfigured(): bool
|
||||
{
|
||||
if ($this->provider === 'claude_code') {
|
||||
return is_executable('/usr/local/bin/claude');
|
||||
}
|
||||
return $this->apiKey !== '';
|
||||
}
|
||||
|
||||
/** @return array{ok: bool, text?: string, error?: string} */
|
||||
public function query(string $action, string $title, string $content): array
|
||||
{
|
||||
$content = mb_substr(trim($content), 0, 8000);
|
||||
if ($content === '') {
|
||||
return ['ok' => false, 'error' => "Contenu de l'article vide"];
|
||||
}
|
||||
|
||||
$userMsg = $title !== '' ? "# {$title}\n\n{$content}" : $content;
|
||||
|
||||
if ($action === 'analyze') {
|
||||
$raw = $this->provider === 'claude_code'
|
||||
? $this->queryClaudeCode(self::SYSTEM_ANALYZE, $userMsg)
|
||||
: $this->queryAnthropicRaw(self::SYSTEM_ANALYZE, $userMsg, 4096);
|
||||
if (!$raw['ok']) return $raw;
|
||||
return $this->parseAnalyzeResponse($raw['text'] ?? '');
|
||||
}
|
||||
|
||||
$systemPrompt = match ($action) {
|
||||
'critique' => self::SYSTEM_CRITIQUE,
|
||||
'rewrite' => self::SYSTEM_REWRITE,
|
||||
default => null,
|
||||
};
|
||||
|
||||
if ($systemPrompt === null) {
|
||||
return ['ok' => false, 'error' => 'Action inconnue'];
|
||||
}
|
||||
|
||||
if ($this->provider === 'claude_code') {
|
||||
return $this->queryClaudeCode($systemPrompt, $userMsg);
|
||||
}
|
||||
|
||||
return $this->queryAnthropic($action, $systemPrompt, $userMsg);
|
||||
}
|
||||
|
||||
/** @return array{ok: bool, critique?: string, rewrite?: string, error?: string} */
|
||||
private function parseAnalyzeResponse(string $text): array
|
||||
{
|
||||
$parts = preg_split('/===CRITIQUE===|===REWRITE===/', $text);
|
||||
if (count($parts) < 3) {
|
||||
// Fallback : pas de séparateurs trouvés, on met tout en critique
|
||||
return ['ok' => true, 'critique' => trim($text), 'rewrite' => ''];
|
||||
}
|
||||
return [
|
||||
'ok' => true,
|
||||
'critique' => trim($parts[1]),
|
||||
'rewrite' => trim($parts[2]),
|
||||
];
|
||||
}
|
||||
|
||||
/** @return array{ok: bool, text?: string, error?: string} */
|
||||
private function queryAnthropicRaw(string $systemPrompt, string $userMsg, int $maxTokens): array
|
||||
{
|
||||
if ($this->apiKey === '') {
|
||||
return ['ok' => false, 'error' => 'Clé Anthropic non configurée (ANTHROPIC_API_KEY manquante dans .env)'];
|
||||
}
|
||||
|
||||
$payload = json_encode([
|
||||
'model' => $this->model,
|
||||
'max_tokens' => $maxTokens,
|
||||
'system' => $systemPrompt,
|
||||
'messages' => [['role' => 'user', 'content' => $userMsg]],
|
||||
]);
|
||||
|
||||
$ch = curl_init('https://api.anthropic.com/v1/messages');
|
||||
curl_setopt_array($ch, [
|
||||
CURLOPT_RETURNTRANSFER => true,
|
||||
CURLOPT_POST => true,
|
||||
CURLOPT_POSTFIELDS => $payload,
|
||||
CURLOPT_TIMEOUT => 90,
|
||||
CURLOPT_HTTPHEADER => [
|
||||
'x-api-key: ' . $this->apiKey,
|
||||
'anthropic-version: 2023-06-01',
|
||||
'Content-Type: application/json',
|
||||
],
|
||||
]);
|
||||
|
||||
$resp = curl_exec($ch);
|
||||
$http = (int) curl_getinfo($ch, CURLINFO_HTTP_CODE);
|
||||
$err = curl_error($ch);
|
||||
curl_close($ch);
|
||||
|
||||
if ($err !== '') return ['ok' => false, 'error' => 'Erreur réseau : ' . $err];
|
||||
|
||||
$data = json_decode((string) $resp, true);
|
||||
if ($http !== 200) {
|
||||
return ['ok' => false, 'error' => $data['error']['message'] ?? ('Anthropic HTTP ' . $http)];
|
||||
}
|
||||
|
||||
return ['ok' => true, 'text' => $data['content'][0]['text'] ?? ''];
|
||||
}
|
||||
|
||||
/** @return array{ok: bool, text?: string, error?: string} */
|
||||
private function queryAnthropic(string $action, string $systemPrompt, string $userMsg): array
|
||||
{
|
||||
if ($this->apiKey === '') {
|
||||
return ['ok' => false, 'error' => 'Clé Anthropic non configurée (ANTHROPIC_API_KEY manquante dans .env)'];
|
||||
}
|
||||
|
||||
$maxTokens = ($action === 'rewrite') ? 4096 : 1200;
|
||||
|
||||
$payload = json_encode([
|
||||
'model' => $this->model,
|
||||
'max_tokens' => $maxTokens,
|
||||
'system' => $systemPrompt,
|
||||
'messages' => [['role' => 'user', 'content' => $userMsg]],
|
||||
]);
|
||||
|
||||
$ch = curl_init('https://api.anthropic.com/v1/messages');
|
||||
curl_setopt_array($ch, [
|
||||
CURLOPT_RETURNTRANSFER => true,
|
||||
CURLOPT_POST => true,
|
||||
CURLOPT_POSTFIELDS => $payload,
|
||||
CURLOPT_TIMEOUT => 60,
|
||||
CURLOPT_HTTPHEADER => [
|
||||
'x-api-key: ' . $this->apiKey,
|
||||
'anthropic-version: 2023-06-01',
|
||||
'Content-Type: application/json',
|
||||
],
|
||||
]);
|
||||
|
||||
$resp = curl_exec($ch);
|
||||
$http = (int) curl_getinfo($ch, CURLINFO_HTTP_CODE);
|
||||
$err = curl_error($ch);
|
||||
curl_close($ch);
|
||||
|
||||
if ($err !== '') {
|
||||
return ['ok' => false, 'error' => 'Erreur réseau : ' . $err];
|
||||
}
|
||||
|
||||
$data = json_decode((string) $resp, true);
|
||||
|
||||
if ($http !== 200) {
|
||||
$msg = $data['error']['message'] ?? ('Anthropic HTTP ' . $http);
|
||||
return ['ok' => false, 'error' => $msg];
|
||||
}
|
||||
|
||||
$text = $data['content'][0]['text'] ?? '';
|
||||
return ['ok' => true, 'text' => $text];
|
||||
}
|
||||
|
||||
/** @return array{ok: bool, text?: string, error?: string} */
|
||||
private function queryClaudeCode(string $systemPrompt, string $userMsg): array
|
||||
{
|
||||
$bin = '/usr/local/bin/claude';
|
||||
if (!is_executable($bin)) {
|
||||
return ['ok' => false, 'error' => 'Claude Code CLI introuvable (/usr/local/bin/claude)'];
|
||||
}
|
||||
|
||||
$prompt = $systemPrompt . "\n\n" . $userMsg;
|
||||
$cmd = $bin . ' --print ' . escapeshellarg($prompt) . ' 2>&1';
|
||||
$env = ['HOME' => '/var/lib/claude-www', 'PATH' => '/usr/local/bin:/usr/bin:/bin'];
|
||||
$desc = [0 => ['pipe', 'r'], 1 => ['pipe', 'w'], 2 => ['pipe', 'w']];
|
||||
$proc = proc_open($cmd, $desc, $pipes, '/tmp', $env);
|
||||
|
||||
if (!is_resource($proc)) {
|
||||
return ['ok' => false, 'error' => 'proc_open échoué'];
|
||||
}
|
||||
|
||||
fclose($pipes[0]);
|
||||
$out = stream_get_contents($pipes[1]);
|
||||
fclose($pipes[1]);
|
||||
fclose($pipes[2]);
|
||||
$code = proc_close($proc);
|
||||
|
||||
if ($code !== 0) {
|
||||
return ['ok' => false, 'error' => 'Claude Code exit ' . $code . ' : ' . trim((string)$out)];
|
||||
}
|
||||
|
||||
return ['ok' => true, 'text' => trim((string)$out)];
|
||||
}
|
||||
}
|
||||
@@ -1,105 +0,0 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Service;
|
||||
|
||||
use App\Repository\UserRepository;
|
||||
|
||||
final class AuthService
|
||||
{
|
||||
public function __construct(private UserRepository $users)
|
||||
{
|
||||
}
|
||||
|
||||
public function canAttempt(string $email, string $ip): bool
|
||||
{
|
||||
// backoff: 5 dernières tentatives/5 min
|
||||
$sql = "select count(*)
|
||||
from login_attempts
|
||||
where ip = :ip
|
||||
and attempted_at > now() - interval '5 minutes'
|
||||
and success = false";
|
||||
$st = \App\Infrastructure\Database::pdo()->prepare($sql);
|
||||
$st->execute([':ip' => $ip]);
|
||||
$fails = (int)$st->fetchColumn();
|
||||
return $fails < 10; // à ajuster
|
||||
}
|
||||
|
||||
|
||||
|
||||
public function login(string $email, string $password, string $ip): bool
|
||||
{
|
||||
$user = $this->users->findByEmail($email);
|
||||
$ok = $user && $user->isActive && password_verify($password, $user->passwordHash);
|
||||
|
||||
$pdo = \App\Infrastructure\Database::pdo();
|
||||
$st = $pdo->prepare('insert into login_attempts(email, ip, success) values(:e, :ip, :s)');
|
||||
$st->bindValue(':e', $email, \PDO::PARAM_STR);
|
||||
$st->bindValue(':ip', $ip, \PDO::PARAM_STR);
|
||||
$st->bindValue(':s', $ok, \PDO::PARAM_BOOL);
|
||||
$st->execute();
|
||||
|
||||
if ($ok) {
|
||||
\App\Infrastructure\Session::regenerate();
|
||||
$_SESSION['uid'] = $user->id;
|
||||
$_SESSION['email'] = $user->email;
|
||||
}
|
||||
return $ok;
|
||||
}
|
||||
|
||||
|
||||
public function changePassword(string $userId, string $currentPassword, string $newPassword): bool
|
||||
{
|
||||
// Récupération de l’utilisateur (rapide : requête directe ; tu peux créer findById() si tu préfères)
|
||||
$pdo = \App\Infrastructure\Database::pdo();
|
||||
$st = $pdo->prepare('select id, email, password_hash, is_active from users where id = :id');
|
||||
$st->execute([':id' => $userId]);
|
||||
$row = $st->fetch(\PDO::FETCH_ASSOC);
|
||||
if (!$row || !(bool)$row['is_active']) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Vérifier l’ancien mot de passe
|
||||
if (!password_verify($currentPassword, (string)$row['password_hash'])) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Politique minimale : longueur uniquement (espaces autorisés)
|
||||
if (mb_strlen($newPassword) < 7) {
|
||||
return false;
|
||||
}
|
||||
// (optionnel) interdire seulement le caractère NUL
|
||||
if (strpos($newPassword, "\0") !== false) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Mettre à jour le hash
|
||||
$newHash = password_hash($newPassword, PASSWORD_ARGON2ID);
|
||||
(new \App\Repository\UserRepository(\App\Infrastructure\Database::get()))->updatePassword($row['id'], $newHash);
|
||||
|
||||
// (Optionnel) rotation session
|
||||
\App\Infrastructure\Session::regenerate();
|
||||
return true;
|
||||
}
|
||||
|
||||
public function register(string $email, string $password): string
|
||||
{
|
||||
$hash = password_hash($password, PASSWORD_ARGON2ID);
|
||||
return $this->users->create($email, $hash);
|
||||
}
|
||||
|
||||
public static function requireAuth(): void
|
||||
{
|
||||
if (!isset($_SESSION['uid'])) {
|
||||
header('Location: /login');
|
||||
exit;
|
||||
}
|
||||
}
|
||||
|
||||
public static function logout(): void
|
||||
{
|
||||
$_SESSION = [];
|
||||
session_destroy();
|
||||
}
|
||||
}
|
||||
+34
-2
@@ -4,7 +4,7 @@ declare(strict_types=1);
|
||||
|
||||
function siteSettingsPath(): string
|
||||
{
|
||||
return BASE_PATH . '/data/site_settings.json';
|
||||
return DATA_PATH . '/site_settings.json';
|
||||
}
|
||||
|
||||
function siteSettings(): array
|
||||
@@ -68,6 +68,24 @@ function apacheAccessLog(): string
|
||||
return (string)($_ENV['APACHE_ACCESS_LOG'] ?? getenv('APACHE_ACCESS_LOG') ?: '*-access.log');
|
||||
}
|
||||
|
||||
function folioRepoUrl(): string
|
||||
{
|
||||
$fromSettings = siteSettings()['folio_repo_url'] ?? '';
|
||||
if ($fromSettings !== '') {
|
||||
return rtrim($fromSettings, '/');
|
||||
}
|
||||
return rtrim((string)($_ENV['FOLIO_REPO_URL'] ?? getenv('FOLIO_REPO_URL') ?: ''), '/');
|
||||
}
|
||||
|
||||
function folioUpdateBranch(): string
|
||||
{
|
||||
$fromSettings = siteSettings()['folio_update_branch'] ?? '';
|
||||
if ($fromSettings !== '') {
|
||||
return $fromSettings;
|
||||
}
|
||||
return (string)($_ENV['FOLIO_UPDATE_BRANCH'] ?? getenv('FOLIO_UPDATE_BRANCH') ?: 'main');
|
||||
}
|
||||
|
||||
/** @return list<array{label:string,patterns:list<string>}> */
|
||||
function asGroups(): array
|
||||
{
|
||||
@@ -75,10 +93,24 @@ function asGroups(): array
|
||||
return is_array($raw) ? $raw : [];
|
||||
}
|
||||
|
||||
function aiProvider(): string
|
||||
{
|
||||
$v = siteSettings()['ai_provider'] ?? '';
|
||||
if ($v !== '') return $v;
|
||||
return $_ENV['AI_PROVIDER'] ?? getenv('AI_PROVIDER') ?: 'anthropic';
|
||||
}
|
||||
|
||||
function aiModel(): string
|
||||
{
|
||||
$v = siteSettings()['ai_model'] ?? '';
|
||||
if ($v !== '') return $v;
|
||||
return $_ENV['AI_MODEL'] ?? getenv('AI_MODEL') ?: 'claude-haiku-4-5-20251001';
|
||||
}
|
||||
|
||||
function saveSiteSettings(array $data): bool
|
||||
{
|
||||
$current = siteSettings();
|
||||
$stringKeys = ['site_title', 'site_claim', 'site_lang', 'site_license_label', 'site_license_url', 'apache_access_log'];
|
||||
$stringKeys = ['site_title', 'site_claim', 'site_lang', 'site_license_label', 'site_license_url', 'apache_access_log', 'folio_repo_url', 'folio_update_branch', 'ai_provider', 'ai_model'];
|
||||
foreach ($stringKeys as $key) {
|
||||
if (array_key_exists($key, $data)) {
|
||||
$val = trim((string)$data[$key]);
|
||||
|
||||
@@ -4,7 +4,7 @@ declare(strict_types=1);
|
||||
|
||||
function smtpSettingsPath(): string
|
||||
{
|
||||
return BASE_PATH . '/data/smtp_settings.json';
|
||||
return DATA_PATH . '/smtp_settings.json';
|
||||
}
|
||||
|
||||
function smtpSettings(): array
|
||||
|
||||
@@ -0,0 +1,193 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
/**
|
||||
* Lit les logs Apache et retourne les chemins /post/* les plus consultés
|
||||
* sur une fenêtre temporelle donnée, en comptant les visiteurs uniques (IPs distinctes)
|
||||
* avec code HTTP 200 uniquement.
|
||||
*/
|
||||
class TrendingParser
|
||||
{
|
||||
// Apache COMBINED : IP - - [timestamp] "METHOD /path HTTP/x" STATUS bytes "ref" "ua"
|
||||
private const RE = '/^(\S+) \S+ \S+ \[(\d{2}\/\w+\/\d{4}:\d{2}:\d{2}:\d{2} [+-]\d{4})\] "[A-Z-]+ ([^\s"?]+)[^"]*" (\d{3}) /';
|
||||
|
||||
public function __construct(
|
||||
private string $logDir,
|
||||
private string $pattern,
|
||||
) {}
|
||||
|
||||
/**
|
||||
* Retourne les $limit chemins les plus consultés depuis $cutoff,
|
||||
* triés par nombre décroissant de visiteurs uniques.
|
||||
*
|
||||
* @param list<string> $prefixes ex. ['/post/'], ['/post/', '/book/']
|
||||
* @return array<string, int> chemin => nb visiteurs uniques
|
||||
*/
|
||||
public function top(int $cutoff, int $limit = 50, array $prefixes = ['/post/']): array
|
||||
{
|
||||
$visitors = []; // [path][ip] = true
|
||||
|
||||
foreach ($this->logFiles($cutoff) as $file) {
|
||||
$this->parseFile($file, $cutoff, $visitors, $prefixes);
|
||||
}
|
||||
|
||||
$counts = [];
|
||||
foreach ($visitors as $path => $ips) {
|
||||
$counts[$path] = count($ips);
|
||||
}
|
||||
arsort($counts);
|
||||
|
||||
return array_slice($counts, 0, $limit, true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Parse une seule fois les logs et retourne les tops séparés par préfixe.
|
||||
* Plus efficace que plusieurs appels à top() sur la même période.
|
||||
*
|
||||
* @param array<string, int> $limits préfixe => limite
|
||||
* @return array<string, array<string, int>> préfixe => (chemin => visiteurs)
|
||||
*/
|
||||
public function topGrouped(int $cutoff, array $limits): array
|
||||
{
|
||||
$prefixes = array_keys($limits);
|
||||
$visitors = []; // [path][ip] = true
|
||||
|
||||
foreach ($this->logFiles($cutoff) as $file) {
|
||||
$this->parseFile($file, $cutoff, $visitors, $prefixes);
|
||||
}
|
||||
|
||||
$result = array_fill_keys($prefixes, []);
|
||||
foreach ($visitors as $path => $ips) {
|
||||
foreach ($prefixes as $prefix) {
|
||||
if (str_starts_with($path, $prefix)) {
|
||||
$result[$prefix][$path] = count($ips);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
foreach ($prefixes as $prefix) {
|
||||
arsort($result[$prefix]);
|
||||
$result[$prefix] = array_slice($result[$prefix], 0, $limits[$prefix], true);
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
public function isReadable(): bool
|
||||
{
|
||||
return count($this->logFiles(time() - 86400)) > 0;
|
||||
}
|
||||
|
||||
// ── Fichiers de log ───────────────────────────────────────────────────────
|
||||
|
||||
/** @return list<array{path:string,type:string}> */
|
||||
private function logFiles(int $cutoff): array
|
||||
{
|
||||
$files = [];
|
||||
$oldest = $cutoff - 86400; // une journée de marge pour les rotations
|
||||
|
||||
foreach (glob($this->logDir . '/' . $this->pattern) ?: [] as $base) {
|
||||
if (str_ends_with($base, '.gz') || preg_match('/\.\d+$/', $base)) {
|
||||
continue;
|
||||
}
|
||||
foreach (array_merge([$base], glob($base . '.*') ?: []) as $path) {
|
||||
if ($path !== $base && filemtime($path) < $oldest) {
|
||||
continue;
|
||||
}
|
||||
if (!is_readable($path)) {
|
||||
continue;
|
||||
}
|
||||
if (str_ends_with($path, '.tar.gz')) {
|
||||
$files[] = ['path' => $path, 'type' => 'tgz'];
|
||||
} elseif (str_ends_with($path, '.gz')) {
|
||||
$files[] = ['path' => $path, 'type' => 'gz'];
|
||||
} else {
|
||||
$files[] = ['path' => $path, 'type' => 'plain'];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $files;
|
||||
}
|
||||
|
||||
// ── Parsing ───────────────────────────────────────────────────────────────
|
||||
|
||||
private static function parseTimestamp(string $raw): int
|
||||
{
|
||||
if (!preg_match('/(\d{2})\/(\w{3})\/(\d{4}):(\d{2}:\d{2}:\d{2}) ([+-]\d{4})/', $raw, $m)) {
|
||||
return 0;
|
||||
}
|
||||
return (int) strtotime("{$m[1]} {$m[2]} {$m[3]} {$m[4]} {$m[5]}");
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array<string, array<string, true>> $visitors
|
||||
* @param list<string> $prefixes
|
||||
*/
|
||||
private function parseLine(string $line, int $cutoff, array &$visitors, array $prefixes): void
|
||||
{
|
||||
if (!preg_match(self::RE, $line, $m)) {
|
||||
return;
|
||||
}
|
||||
[, $ip, $ts, $path, $status] = $m;
|
||||
|
||||
if ($status !== '200') {
|
||||
return;
|
||||
}
|
||||
if (self::parseTimestamp($ts) < $cutoff) {
|
||||
return;
|
||||
}
|
||||
foreach ($prefixes as $prefix) {
|
||||
if (str_starts_with($path, $prefix) && strlen($path) > strlen($prefix)) {
|
||||
$visitors[$path][$ip] = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array<string, array<string, true>> $visitors
|
||||
* @param list<string> $prefixes
|
||||
*/
|
||||
private function parseFile(array $file, int $cutoff, array &$visitors, array $prefixes): void
|
||||
{
|
||||
if ($file['type'] === 'tgz') {
|
||||
try {
|
||||
$phar = new PharData($file['path']);
|
||||
foreach ($phar as $entry) {
|
||||
$content = @file_get_contents('phar://' . $file['path'] . '/' . $entry->getFilename());
|
||||
if ($content === false) {
|
||||
continue;
|
||||
}
|
||||
foreach (explode("\n", $content) as $line) {
|
||||
$this->parseLine($line, $cutoff, $visitors, $prefixes);
|
||||
}
|
||||
}
|
||||
} catch (\Exception) {
|
||||
}
|
||||
} elseif ($file['type'] === 'gz') {
|
||||
$h = @gzopen($file['path'], 'rb');
|
||||
if (!$h) {
|
||||
return;
|
||||
}
|
||||
while (!gzeof($h)) {
|
||||
$line = gzgets($h, 8192);
|
||||
if ($line !== false) {
|
||||
$this->parseLine($line, $cutoff, $visitors, $prefixes);
|
||||
}
|
||||
}
|
||||
gzclose($h);
|
||||
} else {
|
||||
$h = @fopen($file['path'], 'rb');
|
||||
if (!$h) {
|
||||
return;
|
||||
}
|
||||
while (($line = fgets($h)) !== false) {
|
||||
$this->parseLine($line, $cutoff, $visitors, $prefixes);
|
||||
}
|
||||
fclose($h);
|
||||
}
|
||||
}
|
||||
}
|
||||
+37
-4
@@ -67,7 +67,7 @@ class UpdateChecker
|
||||
*/
|
||||
private function checkRemoteVersion(): ?string
|
||||
{
|
||||
$repoUrl = rtrim((string) ($_ENV['FOLIO_REPO_URL'] ?? getenv('FOLIO_REPO_URL') ?: ''), '/');
|
||||
$repoUrl = folioRepoUrl();
|
||||
if ($repoUrl === '') {
|
||||
return null;
|
||||
}
|
||||
@@ -89,8 +89,40 @@ class UpdateChecker
|
||||
return version_compare($remoteVer, $deployedVer, '>') ? $remoteVer : null;
|
||||
}
|
||||
|
||||
public function getBranch(): string
|
||||
{
|
||||
return folioUpdateBranch();
|
||||
}
|
||||
|
||||
public function getLastChecked(): ?int
|
||||
{
|
||||
$cacheFile = $this->dataDir . '/.version_check_cache.json';
|
||||
if (!file_exists($cacheFile)) {
|
||||
return null;
|
||||
}
|
||||
$cache = json_decode((string) file_get_contents($cacheFile), true) ?? [];
|
||||
return isset($cache['fetched_at']) ? (int) $cache['fetched_at'] : null;
|
||||
}
|
||||
|
||||
public function clearCache(): void
|
||||
{
|
||||
$cacheFile = $this->dataDir . '/.version_check_cache.json';
|
||||
if (file_exists($cacheFile)) {
|
||||
unlink($cacheFile);
|
||||
}
|
||||
}
|
||||
|
||||
public function getLastUpgradeLog(): ?string
|
||||
{
|
||||
$logFile = $this->dataDir . '/.upgrade-log';
|
||||
if (!file_exists($logFile)) {
|
||||
return null;
|
||||
}
|
||||
return (string) file_get_contents($logFile);
|
||||
}
|
||||
|
||||
/**
|
||||
* Récupère `public/version.txt` depuis le dépôt Gitea (branche main).
|
||||
* Récupère `public/version.txt` depuis le dépôt Gitea.
|
||||
* Résultat mis en cache 1 h dans `data/.version_check_cache.json`.
|
||||
*/
|
||||
private function fetchRemoteVersion(string $repoUrl): ?string
|
||||
@@ -107,8 +139,9 @@ class UpdateChecker
|
||||
}
|
||||
}
|
||||
|
||||
// URL du fichier brut : {repo}/raw/branch/main/public/version.txt
|
||||
$rawUrl = $repoUrl . '/raw/branch/main/public/version.txt';
|
||||
$branch = $this->getBranch();
|
||||
// URL du fichier brut : {repo}/raw/branch/{branch}/public/version.txt
|
||||
$rawUrl = $repoUrl . '/raw/branch/' . $branch . '/public/version.txt';
|
||||
|
||||
$token = (string) ($_ENV['GITEA_TOKEN'] ?? getenv('GITEA_TOKEN') ?: '');
|
||||
$opts = [
|
||||
|
||||
@@ -2,6 +2,27 @@
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
if (!function_exists('env')) {
|
||||
function env(string $key, ?string $default = null): ?string
|
||||
{
|
||||
if (array_key_exists($key, $_ENV) && $_ENV[$key] !== '') {
|
||||
return (string)$_ENV[$key];
|
||||
}
|
||||
$v = getenv($key);
|
||||
if ($v !== false && $v !== '') {
|
||||
return (string)$v;
|
||||
}
|
||||
return $default;
|
||||
}
|
||||
}
|
||||
|
||||
if (!function_exists('db')) {
|
||||
function db(): \PDO
|
||||
{
|
||||
return \App\Infrastructure\Database::get();
|
||||
}
|
||||
}
|
||||
|
||||
function vd($var, ...$moreVars)
|
||||
{
|
||||
ob_start();
|
||||
@@ -149,3 +170,48 @@ function _paletteGradient(array $rgb, int $tier): string
|
||||
|
||||
return "linear-gradient({$angle}deg,rgb($tr,$tg,$tb) 0%,rgb($sr,$sg,$sb) 100%)";
|
||||
}
|
||||
|
||||
/**
|
||||
* Post-traite le HTML produit par Parsedown pour y appliquer la typographie française :
|
||||
* guillemets droits → guillemets courbes, apostrophes droites → apostrophes courbes.
|
||||
* Le contenu des balises <pre> et <code> est strictement préservé.
|
||||
*/
|
||||
function typographieHtml(string $html): string
|
||||
{
|
||||
// Protéger les blocs pre/code (y compris imbriqués)
|
||||
$protected = [];
|
||||
$html = preg_replace_callback(
|
||||
'#<(pre|code)(\b[^>]*)>(.*?)</\1>#si',
|
||||
static function (array $m) use (&$protected): string {
|
||||
$key = "\x02" . count($protected) . "\x03";
|
||||
$protected[$key] = $m[0];
|
||||
return $key;
|
||||
},
|
||||
$html
|
||||
) ?? $html;
|
||||
|
||||
// Traiter uniquement les nœuds texte (entre les balises HTML)
|
||||
$html = preg_replace_callback(
|
||||
'#(<[^>]+>)|([^<]+)#s',
|
||||
static function (array $m): string {
|
||||
if ($m[1] !== '') {
|
||||
return $m[1]; // balise HTML — intacte
|
||||
}
|
||||
$t = $m[2];
|
||||
// Guillemets doubles : précédé d'un mot → fermant, sinon → ouvrant
|
||||
$t = preg_replace('/(?<=\w)"/u', "\u{201D}", $t);
|
||||
$t = str_replace('"', "\u{201C}", $t);
|
||||
// Apostrophes / guillemets simples : précédé d'un mot → fermant/apostrophe, sinon → ouvrant
|
||||
$t = preg_replace("/(?<=\w)'/u", "\u{2019}", $t);
|
||||
$t = str_replace("'", "\u{2018}", $t);
|
||||
return $t;
|
||||
},
|
||||
$html
|
||||
) ?? $html;
|
||||
|
||||
// Restaurer les blocs protégés
|
||||
if ($protected) {
|
||||
$html = str_replace(array_keys($protected), array_values($protected), $html);
|
||||
}
|
||||
return $html;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,19 @@
|
||||
<?php
|
||||
// Page d'erreur 404 — à inclure après http_response_code(404).
|
||||
// Aucune variable externe requise.
|
||||
$title = '404 — ' . siteTitle();
|
||||
$metaRobots = 'noindex, nofollow';
|
||||
ob_start();
|
||||
?>
|
||||
<div class="container py-5 text-center">
|
||||
<p class="display-1 fw-bold text-muted mb-0">404</p>
|
||||
<h1 class="h3 mb-3">Page introuvable</h1>
|
||||
<p class="text-muted mb-4">
|
||||
Cette adresse ne correspond à aucun contenu.<br>
|
||||
Vous avez peut-être suivi un ancien lien.
|
||||
</p>
|
||||
<a href="/" class="btn btn-primary">← Retour à l'accueil</a>
|
||||
</div>
|
||||
<?php
|
||||
$content = ob_get_clean();
|
||||
include __DIR__ . '/layout.php';
|
||||
+364
-56
@@ -69,6 +69,14 @@ function adminStatusBadge(array $a, int $now): string
|
||||
<a class="nav-link <?= $tab === 'books' ? 'active' : '' ?>"
|
||||
href="/admin/books">Livres</a>
|
||||
</li>
|
||||
<li class="nav-item">
|
||||
<a class="nav-link <?= $tab === 'flux' ? 'active' : '' ?>"
|
||||
href="/admin/flux">Flux</a>
|
||||
</li>
|
||||
<li class="nav-item">
|
||||
<a class="nav-link <?= $tab === 'ia' ? 'active' : '' ?>"
|
||||
href="/admin/ia">IA</a>
|
||||
</li>
|
||||
<li class="nav-item">
|
||||
<a class="nav-link <?= $tab === 'stats' ? 'active' : '' ?>"
|
||||
href="/admin/stats">Statistiques</a>
|
||||
@@ -103,7 +111,11 @@ function adminStatusBadge(array $a, int $now): string
|
||||
<?php
|
||||
$_deployedVer = trim((string) @file_get_contents(BASE_PATH . '/public/version.txt'));
|
||||
$_deployedLabel = $_deployedVer !== '' ? $_deployedVer : '—';
|
||||
$_notices = isset($_updateChecker) ? $_updateChecker->adminNotices() : [];
|
||||
$_notices = isset($_updateChecker) ? $_updateChecker->adminNotices() : [];
|
||||
$_branch = isset($_updateChecker) ? $_updateChecker->getBranch() : 'main';
|
||||
$_lastChecked = isset($_updateChecker) ? $_updateChecker->getLastChecked() : null;
|
||||
$_upgradeLog = isset($_updateChecker) ? $_updateChecker->getLastUpgradeLog() : null;
|
||||
$_repoConfigured = folioRepoUrl() !== '';
|
||||
$_remoteLabel = '—';
|
||||
foreach ($_notices as $_n) {
|
||||
if ($_n['type'] === 'info' && preg_match('/v([\d]+\.[\d]+\.[\d]+)/', $_n['message'], $_m)) {
|
||||
@@ -122,26 +134,48 @@ function adminStatusBadge(array $a, int $now): string
|
||||
</tr>
|
||||
<tr>
|
||||
<th class="text-muted fw-normal ps-0 pe-2 text-nowrap">Dernière version disponible</th>
|
||||
<td><?= htmlspecialchars($_remoteLabel) ?><?= $_remoteLabel !== '—' && $_remoteLabel !== $_deployedLabel ? ' <span class="badge bg-warning text-dark ms-1">Mise à jour disponible</span>' : '' ?></td>
|
||||
</tr>
|
||||
<?php if (!empty($_notices)): ?>
|
||||
<tr>
|
||||
<th class="text-muted fw-normal ps-0 pe-2 align-top">Actions requises</th>
|
||||
<td class="d-flex flex-wrap gap-2 align-items-center">
|
||||
<?php foreach ($_notices as $_n): ?>
|
||||
<?php if ($_n['type'] === 'warning'): ?>
|
||||
<form method="POST" action="/?action=run_content_migrations">
|
||||
<button type="submit" class="btn btn-warning btn-sm">Mettre à jour le contenu</button>
|
||||
<td class="d-flex align-items-center gap-2 flex-wrap">
|
||||
<span><?= htmlspecialchars($_remoteLabel) ?></span>
|
||||
<?php if ($_remoteLabel !== '—' && $_remoteLabel !== $_deployedLabel): ?>
|
||||
<form method="POST" action="/?action=run_engine_update" class="d-inline">
|
||||
<button type="submit" class="btn btn-primary btn-sm">Mettre à jour vers v<?= htmlspecialchars($_remoteLabel) ?></button>
|
||||
</form>
|
||||
<?php endif; ?>
|
||||
<?php endforeach; ?>
|
||||
<?php elseif ($_repoConfigured): ?>
|
||||
<form method="POST" action="/?action=force_update_check" class="d-inline">
|
||||
<button type="submit" class="btn btn-outline-secondary btn-sm py-0">Vérifier</button>
|
||||
</form>
|
||||
<?php else: ?>
|
||||
<span class="text-muted small">(<code>FOLIO_REPO_URL</code> non configuré)</span>
|
||||
<?php endif; ?>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th class="text-muted fw-normal ps-0 pe-2 text-nowrap">Branche suivie</th>
|
||||
<td><code><?= htmlspecialchars($_branch) ?></code><?= $_lastChecked !== null ? ' <span class="text-muted ms-2">· vérifié le ' . date('d/m/Y à H:i', $_lastChecked) . '</span>' : '' ?></td>
|
||||
</tr>
|
||||
<?php if (($_GET['notice'] ?? '') === 'engine_updated'): ?>
|
||||
<tr><td colspan="2"><div class="alert alert-success py-1 mb-0 small">Moteur mis à jour avec succès.</div></td></tr>
|
||||
<?php elseif (($_GET['notice'] ?? '') === 'upgrade_error'): ?>
|
||||
<tr><td colspan="2">
|
||||
<div class="alert alert-danger py-1 mb-0 small">
|
||||
Erreur lors de la mise à jour.
|
||||
<?php if (!empty($_SESSION['_upgrade_log'])): ?>
|
||||
<pre class="mt-1 mb-0 small"><?= htmlspecialchars($_SESSION['_upgrade_log']) ?></pre>
|
||||
<?php unset($_SESSION['_upgrade_log']); ?>
|
||||
<?php endif; ?>
|
||||
</div>
|
||||
</td></tr>
|
||||
<?php endif; ?>
|
||||
<?php if (($_GET['notice'] ?? '') === 'migrated'): ?>
|
||||
<tr><td colspan="2"><div class="alert alert-success py-1 mb-0 small">Migrations appliquées avec succès.</div></td></tr>
|
||||
<?php elseif (($_GET['notice'] ?? '') === 'migration_error'): ?>
|
||||
<tr><td colspan="2"><div class="alert alert-danger py-1 mb-0 small">Une erreur est survenue pendant la migration.</div></td></tr>
|
||||
<?php if ($_upgradeLog !== null): ?>
|
||||
<tr>
|
||||
<th class="text-muted fw-normal ps-0 pe-2 text-nowrap align-top">Journal</th>
|
||||
<td>
|
||||
<details>
|
||||
<summary class="small text-muted" style="cursor:pointer">Dernière mise à jour</summary>
|
||||
<pre class="mt-1 mb-0 small"><?= htmlspecialchars($_upgradeLog) ?></pre>
|
||||
</details>
|
||||
</td>
|
||||
</tr>
|
||||
<?php endif; ?>
|
||||
</tbody>
|
||||
</table>
|
||||
@@ -179,8 +213,32 @@ function adminStatusBadge(array $a, int $now): string
|
||||
<!-- ─────────────────────────── ARTICLES ─────────────────────────── -->
|
||||
<?php elseif ($tab === 'articles'): ?>
|
||||
|
||||
<?php
|
||||
$_sortBy = $adminData['sort_by'] ?? 'updated';
|
||||
$_sortDir = $adminData['sort_dir'] ?? 'desc';
|
||||
$_mkSortUrl = function (string $col) use ($_sortBy, $_sortDir, $adminData): string {
|
||||
$dir = ($_sortBy === $col && $_sortDir === 'asc') ? 'desc' : 'asc';
|
||||
$p = array_filter([
|
||||
'filter_author' => $adminData['filter_author'] ?? '',
|
||||
'filter_category' => $adminData['filter_category'] ?? '',
|
||||
'filter_status' => $adminData['filter_status'] ?? '',
|
||||
'filter_search' => $adminData['filter_search'] ?? '',
|
||||
'filter_featured' => $adminData['filter_featured'] ?? '',
|
||||
], fn ($v) => $v !== '');
|
||||
$p['sort'] = $col;
|
||||
$p['dir'] = $dir;
|
||||
return '/admin/articles?' . http_build_query($p);
|
||||
};
|
||||
$_sortIcon = function (string $col) use ($_sortBy, $_sortDir): string {
|
||||
if ($_sortBy !== $col) { return '<span class="text-muted ms-1" style="font-size:.75em">↕</span>'; }
|
||||
return '<span class="ms-1" style="font-size:.75em">' . ($_sortDir === 'asc' ? '↑' : '↓') . '</span>';
|
||||
};
|
||||
?>
|
||||
|
||||
<!-- Filtres -->
|
||||
<form class="row g-2 align-items-center mb-3" method="get" action="/admin/articles">
|
||||
<input type="hidden" name="sort" value="<?= htmlspecialchars($_sortBy) ?>">
|
||||
<input type="hidden" name="dir" value="<?= htmlspecialchars($_sortDir) ?>">
|
||||
<?php if (isAdmin() && !empty($adminData['filter_authors'])): ?>
|
||||
<div class="col-auto">
|
||||
<select name="filter_author" class="form-select form-select-sm">
|
||||
@@ -215,9 +273,19 @@ function adminStatusBadge(array $a, int $now): string
|
||||
<option value="preview" <?= ($adminData['filter_status'] ?? '') === 'preview' ? 'selected' : '' ?>>Avant-première</option>
|
||||
</select>
|
||||
</div>
|
||||
<div class="col-auto">
|
||||
<select name="filter_featured" class="form-select form-select-sm">
|
||||
<option value="">Tous</option>
|
||||
<option value="yes" <?= ($adminData['filter_featured'] ?? '') === 'yes' ? 'selected' : '' ?>>★ À la une</option>
|
||||
</select>
|
||||
</div>
|
||||
<div class="col-auto">
|
||||
<input type="text" name="filter_search" class="form-control form-control-sm"
|
||||
placeholder="Rechercher…" value="<?= htmlspecialchars($adminData['filter_search'] ?? '') ?>">
|
||||
</div>
|
||||
<div class="col-auto d-flex gap-2">
|
||||
<button type="submit" class="btn btn-secondary btn-sm">Filtrer</button>
|
||||
<?php $hasFilter = ($adminData['filter_author'] ?? '') !== '' || ($adminData['filter_category'] ?? '') !== '' || ($adminData['filter_status'] ?? '') !== ''; ?>
|
||||
<?php $hasFilter = ($adminData['filter_author'] ?? '') !== '' || ($adminData['filter_category'] ?? '') !== '' || ($adminData['filter_status'] ?? '') !== '' || ($adminData['filter_search'] ?? '') !== '' || ($adminData['filter_featured'] ?? '') !== ''; ?>
|
||||
<?php if ($hasFilter): ?>
|
||||
<a href="/admin/articles" class="btn btn-link btn-sm p-0">Réinitialiser</a>
|
||||
<?php endif; ?>
|
||||
@@ -238,8 +306,8 @@ function adminStatusBadge(array $a, int $now): string
|
||||
<input class="form-check-input" type="checkbox" id="check-all">
|
||||
<label class="form-check-label small text-muted" for="check-all">Tout sélectionner</label>
|
||||
</div>
|
||||
<button type="submit" class="btn btn-danger btn-sm"
|
||||
onclick="return document.querySelectorAll('.bulk-check:checked').length > 0 && confirm('Supprimer les articles sélectionnés ? Cette action est irréversible.')">
|
||||
<button type="submit" id="bulk-delete-btn" class="btn btn-danger btn-sm"
|
||||
data-confirm-bulk="Supprimer les articles sélectionnés ? Cette action est irréversible.">
|
||||
Supprimer la sélection
|
||||
</button>
|
||||
</div>
|
||||
@@ -247,11 +315,22 @@ function adminStatusBadge(array $a, int $now): string
|
||||
<thead>
|
||||
<tr>
|
||||
<th style="width:2rem"></th>
|
||||
<th>Titre</th>
|
||||
<th>
|
||||
<a href="<?= htmlspecialchars($_mkSortUrl('title')) ?>"
|
||||
class="text-decoration-none text-reset">
|
||||
Titre<?= $_sortIcon('title') ?>
|
||||
</a>
|
||||
</th>
|
||||
<?php if (isAdmin()): ?><th>Auteur</th><?php endif; ?>
|
||||
<th>Catégorie</th>
|
||||
<th>Statut</th>
|
||||
<th>Date</th>
|
||||
<th title="À la une">★</th>
|
||||
<th>
|
||||
<a href="<?= htmlspecialchars($_mkSortUrl('published')) ?>"
|
||||
class="text-decoration-none text-reset">
|
||||
Date<?= $_sortIcon('published') ?>
|
||||
</a>
|
||||
</th>
|
||||
<th></th>
|
||||
</tr>
|
||||
</thead>
|
||||
@@ -272,18 +351,53 @@ function adminStatusBadge(array $a, int $now): string
|
||||
<?php endif; ?>
|
||||
<td class="text-muted small"><?= htmlspecialchars($a['category'] ?? '–') ?></td>
|
||||
<td><?= adminStatusBadge($a, $now) ?></td>
|
||||
<td class="text-center">
|
||||
<?php if (isAdmin()): ?>
|
||||
<?php $_isFeatured = !empty($a['featured']); ?>
|
||||
<button type="submit" form="toggle-featured-<?= htmlspecialchars($a['uuid']) ?>"
|
||||
class="btn btn-link p-0 border-0 lh-1 fs-6"
|
||||
title="<?= $_isFeatured ? 'Retirer de la une' : 'Mettre à la une' ?>">
|
||||
<?= $_isFeatured ? '★' : '<span class="text-muted">☆</span>' ?>
|
||||
</button>
|
||||
<?php else: ?>
|
||||
<?= !empty($a['featured']) ? '★' : '' ?>
|
||||
<?php endif; ?>
|
||||
</td>
|
||||
<td class="text-muted small text-nowrap">
|
||||
<?= htmlspecialchars(date('d/m/Y', strtotime((string)($a['published_at'] ?? $a['created_at'] ?? '')))) ?>
|
||||
</td>
|
||||
<td class="text-end text-nowrap">
|
||||
<a href="/edit/<?= htmlspecialchars($a['uuid']) ?>"
|
||||
class="btn btn-outline-secondary btn-sm">Modifier</a>
|
||||
<button type="submit" form="dup-<?= htmlspecialchars($a['uuid']) ?>"
|
||||
class="btn btn-outline-secondary btn-sm ms-1"
|
||||
title="Dupliquer en brouillon">⧉</button>
|
||||
</td>
|
||||
</tr>
|
||||
<?php endforeach; ?>
|
||||
</tbody>
|
||||
</table>
|
||||
</form>
|
||||
<?php
|
||||
/* Formulaires hors bulk-form (nested forms invalides en HTML) */
|
||||
$_backUrl = '/admin/articles?' . http_build_query(array_filter([
|
||||
'filter_author' => $adminData['filter_author'] ?? '',
|
||||
'filter_category' => $adminData['filter_category'] ?? '',
|
||||
'filter_status' => $adminData['filter_status'] ?? '',
|
||||
'filter_search' => $adminData['filter_search'] ?? '',
|
||||
'filter_featured' => $adminData['filter_featured'] ?? '',
|
||||
'sort' => $_sortBy,
|
||||
'dir' => $_sortDir,
|
||||
], fn ($v) => $v !== ''));
|
||||
foreach ($adminData['articles'] as $_fa):
|
||||
?>
|
||||
<form id="toggle-featured-<?= htmlspecialchars($_fa['uuid']) ?>" method="post" action="/?action=admin_toggle_featured" hidden>
|
||||
<input type="hidden" name="uuid" value="<?= htmlspecialchars($_fa['uuid']) ?>">
|
||||
<input type="hidden" name="_back" value="<?= htmlspecialchars($_backUrl) ?>">
|
||||
</form>
|
||||
<form id="dup-<?= htmlspecialchars($_fa['uuid']) ?>" method="post" action="/duplicate/<?= htmlspecialchars($_fa['uuid']) ?>" hidden>
|
||||
</form>
|
||||
<?php endforeach; ?>
|
||||
<script src="/assets/js/admin.js" defer></script>
|
||||
<?php endif; ?>
|
||||
|
||||
@@ -531,6 +645,33 @@ function adminStatusBadge(array $a, int $now): string
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<?php if (($_GET['notice'] ?? '') === 'folio_saved'): ?>
|
||||
<div class="alert alert-success py-2 mt-3 small">Configuration Folio enregistrée.</div>
|
||||
<?php elseif (($_GET['notice'] ?? '') === 'folio_error'): ?>
|
||||
<div class="alert alert-danger py-2 mt-3 small">Impossible d'enregistrer.</div>
|
||||
<?php endif; ?>
|
||||
<div class="card mt-4" style="max-width:540px">
|
||||
<div class="card-header bg-transparent py-2 small fw-semibold">Mises à jour du moteur</div>
|
||||
<div class="card-body">
|
||||
<form method="POST" action="/?action=admin_save_folio_config">
|
||||
<div class="mb-3">
|
||||
<label class="form-label small fw-semibold mb-1">URL du dépôt Folio</label>
|
||||
<input type="url" name="folio_repo_url" class="form-control form-control-sm font-monospace"
|
||||
placeholder="https://git.abonnel.fr/cedricAbonnel/folio"
|
||||
value="<?= htmlspecialchars(folioRepoUrl()) ?>">
|
||||
<div class="form-text">Sans slash final. Laissez vide pour utiliser <code>FOLIO_REPO_URL</code> du .env.</div>
|
||||
</div>
|
||||
<div class="mb-3">
|
||||
<label class="form-label small fw-semibold mb-1">Branche suivie</label>
|
||||
<input type="text" name="folio_update_branch" class="form-control form-control-sm font-monospace"
|
||||
placeholder="main"
|
||||
value="<?= htmlspecialchars(folioUpdateBranch()) ?>">
|
||||
</div>
|
||||
<button type="submit" class="btn btn-primary btn-sm">Enregistrer</button>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<?php endif; ?>
|
||||
|
||||
<!-- ─────────────────────────── CATÉGORIES & TAGS ─────────────────── -->
|
||||
@@ -891,17 +1032,13 @@ foreach (COLOR_PALETTE_16 as $_i => $_rgb):
|
||||
<td class="small"><?= htmlspecialchars((string)$em['subject']) ?></td>
|
||||
<td><?= $emBadge ?></td>
|
||||
<td>
|
||||
<details>
|
||||
<summary class="btn btn-outline-secondary btn-sm" style="display:inline;cursor:pointer">Voir</summary>
|
||||
<div class="mt-2 p-2 border rounded bg-light" style="max-width:600px">
|
||||
<?php if (!empty($em['error_message'])): ?>
|
||||
<p class="text-danger small mb-2"><strong>Erreur :</strong> <?= htmlspecialchars((string)$em['error_message']) ?></p>
|
||||
<?php endif; ?>
|
||||
<?php if (!empty($em['content_text'])): ?>
|
||||
<pre class="mb-0 small" style="white-space:pre-wrap;font-size:0.75rem"><?= htmlspecialchars((string)$em['content_text']) ?></pre>
|
||||
<?php endif; ?>
|
||||
</div>
|
||||
</details>
|
||||
<?php if (!empty($em['content_html']) || !empty($em['content_text'])): ?>
|
||||
<a href="/admin/email-preview/<?= (int)$em['id'] ?>" target="_blank" rel="noopener"
|
||||
class="btn btn-outline-secondary btn-sm">Voir ↗</a>
|
||||
<?php endif; ?>
|
||||
<?php if (!empty($em['error_message'])): ?>
|
||||
<span class="text-danger small d-block mt-1" title="<?= htmlspecialchars((string)$em['error_message']) ?>">⚠ Erreur</span>
|
||||
<?php endif; ?>
|
||||
</td>
|
||||
</tr>
|
||||
<?php endforeach; ?>
|
||||
@@ -1093,7 +1230,15 @@ foreach (COLOR_PALETTE_16 as $_i => $_rgb):
|
||||
<h5 class="mb-0">Termes recherchés
|
||||
<span class="badge bg-secondary ms-1"><?= count($adminData['search_terms'] ?? []) ?></span>
|
||||
</h5>
|
||||
<span class="text-muted small">Derniers 14 jours de logs · cache 10 min</span>
|
||||
<div class="d-flex align-items-center gap-3">
|
||||
<span class="text-muted small">Derniers <?= (int)($adminData['search_days'] ?? 14) ?> jours · cache 10 min</span>
|
||||
<div class="btn-group btn-group-sm" role="group">
|
||||
<a href="/admin/searches?days=7"
|
||||
class="btn <?= ($adminData['search_days'] ?? 14) === 7 ? 'btn-primary' : 'btn-outline-secondary' ?>">7 j</a>
|
||||
<a href="/admin/searches"
|
||||
class="btn <?= ($adminData['search_days'] ?? 14) === 14 ? 'btn-primary' : 'btn-outline-secondary' ?>">14 j</a>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<?php if (!($adminData['search_log_readable'] ?? false)): ?>
|
||||
@@ -1114,7 +1259,7 @@ foreach (COLOR_PALETTE_16 as $_i => $_rgb):
|
||||
<tr>
|
||||
<th style="width:3rem">#</th>
|
||||
<th>Terme recherché</th>
|
||||
<th style="width:6rem" class="text-end">Fois</th>
|
||||
<th style="width:6rem" class="text-end">Visiteurs</th>
|
||||
<th style="width:12rem"></th>
|
||||
</tr>
|
||||
</thead>
|
||||
@@ -1145,6 +1290,57 @@ foreach (COLOR_PALETTE_16 as $_i => $_rgb):
|
||||
|
||||
<?php endif; ?>
|
||||
|
||||
<!-- ─────────────────────────── FLUX RSS ─────────────────────────── -->
|
||||
<?php if ($tab === 'flux' && isAdmin()): ?>
|
||||
|
||||
<?php if (($_GET['deleted'] ?? '') === '1'): ?>
|
||||
<div class="alert alert-success py-2 small">Flux supprimé.</div>
|
||||
<?php endif; ?>
|
||||
|
||||
<h5>Flux RSS agrégés</h5>
|
||||
<p class="text-muted small">Tous les flux enregistrés par les utilisateurs. Seul un administrateur peut les supprimer.</p>
|
||||
|
||||
<?php if (empty($adminData['flux_feeds'] ?? [])): ?>
|
||||
<p class="text-muted">Aucun flux enregistré.</p>
|
||||
<?php else: ?>
|
||||
<div class="table-responsive">
|
||||
<table class="table table-sm table-hover align-middle">
|
||||
<thead class="table-light">
|
||||
<tr>
|
||||
<th>Utilisateur</th>
|
||||
<th>Libellé</th>
|
||||
<th>URL</th>
|
||||
<th>Ajouté le</th>
|
||||
<th></th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<?php foreach ($adminData['flux_feeds'] as $_feed): ?>
|
||||
<tr>
|
||||
<td class="small"><?= htmlspecialchars($_feed['user_email'] ?? '') ?></td>
|
||||
<td class="small"><?= htmlspecialchars($_feed['label'] ?? '') ?></td>
|
||||
<td class="small text-truncate" style="max-width:260px">
|
||||
<a href="<?= htmlspecialchars($_feed['feed_url'] ?? '') ?>" target="_blank" rel="noopener" class="text-muted">
|
||||
<?= htmlspecialchars($_feed['feed_url'] ?? '') ?>
|
||||
</a>
|
||||
</td>
|
||||
<td class="small text-nowrap"><?= htmlspecialchars(substr($_feed['created_at'] ?? '', 0, 10)) ?></td>
|
||||
<td>
|
||||
<form method="POST" action="/?action=admin_delete_feed"
|
||||
data-confirm="Supprimer ce flux ?">
|
||||
<input type="hidden" name="id" value="<?= (int)$_feed['id'] ?>">
|
||||
<button type="submit" class="btn btn-outline-danger btn-sm py-0">Supprimer</button>
|
||||
</form>
|
||||
</td>
|
||||
</tr>
|
||||
<?php endforeach; ?>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
|
||||
<?php endif; ?>
|
||||
|
||||
<!-- ─────────────────────────── LIVRES ─────────────────────────── -->
|
||||
<?php if ($tab === 'books' && isAdmin()): ?>
|
||||
|
||||
@@ -1220,7 +1416,9 @@ foreach (COLOR_PALETTE_16 as $_i => $_rgb):
|
||||
</div>
|
||||
<div class="mb-3">
|
||||
<label class="form-label small fw-medium">Ajouter une page existante</label>
|
||||
<select class="form-select" onchange="bookAddArticle(this)">
|
||||
<input type="text" id="book-article-filter" class="form-control form-control-sm mb-1"
|
||||
placeholder="Filtrer les articles…" autocomplete="off">
|
||||
<select class="form-select" id="book-article-select">
|
||||
<option value="">— Choisir un article —</option>
|
||||
<?php
|
||||
$alreadyIn = $eb['articles'] ?? [];
|
||||
@@ -1251,32 +1449,20 @@ foreach (COLOR_PALETTE_16 as $_i => $_rgb):
|
||||
<button type="submit" class="btn btn-outline-danger btn-sm">🗑 Supprimer ce livre</button>
|
||||
</form>
|
||||
|
||||
<script>
|
||||
function bookAddArticle(sel) {
|
||||
var slug = sel.value;
|
||||
if (!slug) return;
|
||||
var ta = document.getElementById('book-articles-ta');
|
||||
var lines = ta.value.split('\n').map(function(s) { return s.trim(); }).filter(Boolean);
|
||||
if (lines.indexOf(slug) === -1) {
|
||||
lines.push(slug);
|
||||
ta.value = lines.join('\n');
|
||||
}
|
||||
sel.value = '';
|
||||
}
|
||||
</script>
|
||||
|
||||
<?php elseif (isset($_GET['new'])): ?>
|
||||
<h5>Nouveau livre</h5>
|
||||
<form method="POST" action="/?action=book_save">
|
||||
<div class="mb-3">
|
||||
<label class="form-label small fw-medium">Slug (identifiant URL)</label>
|
||||
<input type="text" name="slug" class="form-control" required
|
||||
placeholder="mon-livre" pattern="[a-z0-9][a-z0-9-]*">
|
||||
<div class="form-text">Minuscules, chiffres, tirets. Exemple : <code>esp8266</code></div>
|
||||
</div>
|
||||
<input type="hidden" name="slug" id="new-book-slug-hidden">
|
||||
<div class="mb-3">
|
||||
<label class="form-label small fw-medium">Titre</label>
|
||||
<input type="text" name="title" class="form-control" required placeholder="Titre du livre">
|
||||
<input type="text" name="title" id="new-book-title" class="form-control" required placeholder="Titre du livre">
|
||||
</div>
|
||||
<div class="mb-2">
|
||||
<label class="form-label small fw-medium">Slug (généré automatiquement)</label>
|
||||
<input type="text" id="new-book-slug-preview" class="form-control form-control-sm bg-light font-monospace"
|
||||
readonly placeholder="slug-du-livre">
|
||||
<div class="form-text">Minuscules, chiffres, tirets — basé sur le titre.</div>
|
||||
</div>
|
||||
<div class="mb-3">
|
||||
<label class="form-label small fw-medium">Description (optionnelle)</label>
|
||||
@@ -1301,6 +1487,128 @@ foreach (COLOR_PALETTE_16 as $_i => $_rgb):
|
||||
</div>
|
||||
|
||||
</div>
|
||||
<script src="/assets/js/admin.js" defer></script>
|
||||
|
||||
<?php endif; ?>
|
||||
|
||||
<?php if ($tab === 'ia' && isAdmin()): ?>
|
||||
|
||||
<?php
|
||||
$_aiNotice = $adminData['ai_notice'] ?? '';
|
||||
$_aiProvider = $adminData['ai_provider'] ?? 'anthropic';
|
||||
$_aiModel = $adminData['ai_model'] ?? '';
|
||||
$_anthropicOk = $adminData['anthropic_key_set'] ?? false;
|
||||
$_cliOk = $adminData['claude_cli_found'] ?? false;
|
||||
?>
|
||||
|
||||
<?php if ($_aiNotice === 'saved'): ?>
|
||||
<div class="alert alert-success py-2 small">Configuration IA enregistrée.</div>
|
||||
<?php elseif ($_aiNotice === 'error'): ?>
|
||||
<div class="alert alert-danger py-2 small">Erreur lors de l'enregistrement.</div>
|
||||
<?php endif; ?>
|
||||
|
||||
<h5 class="mb-3">Intelligence artificielle</h5>
|
||||
|
||||
<!-- Section 1 — Statut -->
|
||||
<div class="card mb-4">
|
||||
<div class="card-header fw-semibold small">Statut</div>
|
||||
<div class="card-body p-0">
|
||||
<table class="table table-sm mb-0">
|
||||
<tbody>
|
||||
<tr>
|
||||
<th class="ps-3" scope="row">Clé Anthropic (<code>ANTHROPIC_API_KEY</code>)</th>
|
||||
<td><?= $_anthropicOk ? '<span class="text-success">✓ Configurée</span>' : '<span class="text-danger">✗ Absente</span>' ?></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th class="ps-3" scope="row">Claude Code CLI (<code>/usr/local/bin/claude</code>)</th>
|
||||
<td><?= $_cliOk ? '<span class="text-success">✓ Trouvé</span>' : '<span class="text-danger">✗ Introuvable</span>' ?></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th class="ps-3" scope="row">Provider actif</th>
|
||||
<td><code><?= htmlspecialchars($_aiProvider) ?></code></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th class="ps-3" scope="row">Modèle actif</th>
|
||||
<td><code><?= htmlspecialchars($_aiModel ?: 'claude-haiku-4-5-20251001 (défaut)') ?></code></td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Section 2 — Configuration -->
|
||||
<div class="card mb-4">
|
||||
<div class="card-header fw-semibold small">Configuration</div>
|
||||
<div class="card-body">
|
||||
<form method="POST" action="/?action=admin_save_ai_config">
|
||||
<div class="mb-3">
|
||||
<label class="form-label fw-semibold small">Provider</label>
|
||||
<div class="d-flex gap-3">
|
||||
<div class="form-check">
|
||||
<input class="form-check-input" type="radio" name="ai_provider" id="ai_provider_anthropic"
|
||||
value="anthropic" <?= $_aiProvider === 'anthropic' ? 'checked' : '' ?>>
|
||||
<label class="form-check-label" for="ai_provider_anthropic">Anthropic (API)</label>
|
||||
</div>
|
||||
<div class="form-check">
|
||||
<input class="form-check-input" type="radio" name="ai_provider" id="ai_provider_claude_code"
|
||||
value="claude_code" <?= $_aiProvider === 'claude_code' ? 'checked' : '' ?>>
|
||||
<label class="form-check-label" for="ai_provider_claude_code">Claude Code CLI</label>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="mb-3">
|
||||
<label for="ai_model" class="form-label fw-semibold small">Modèle Anthropic</label>
|
||||
<input type="text" class="form-control form-control-sm font-monospace" id="ai_model" name="ai_model"
|
||||
value="<?= htmlspecialchars($_aiModel) ?>"
|
||||
placeholder="claude-haiku-4-5-20251001">
|
||||
<div class="form-text">Laisser vide pour utiliser le défaut (<code>claude-haiku-4-5-20251001</code>). Ignoré si le provider est Claude Code CLI.</div>
|
||||
</div>
|
||||
<button type="submit" class="btn btn-primary btn-sm">Enregistrer</button>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Section 3 — Clé Anthropic -->
|
||||
<div class="card mb-4">
|
||||
<div class="card-header fw-semibold small">Clé API Anthropic</div>
|
||||
<div class="card-body">
|
||||
<div class="alert alert-warning py-2 small mb-0">
|
||||
<strong>La clé API Anthropic ne peut pas être saisie ici.</strong><br>
|
||||
Elle doit être définie dans le fichier <code>.env</code> du serveur :
|
||||
<pre class="mt-2 mb-0 small"><code>ANTHROPIC_API_KEY=sk-ant-...</code></pre>
|
||||
<div class="mt-2">Statut actuel : <?= $_anthropicOk ? '<span class="text-success">✓ Configurée</span>' : '<span class="text-danger">✗ Absente</span>' ?></div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Section 4 — Procédure Claude Code CLI -->
|
||||
<div class="card mb-4">
|
||||
<div class="card-header fw-semibold small">Procédure d'installation de Claude Code CLI</div>
|
||||
<div class="card-body">
|
||||
<?php if ($_cliOk): ?>
|
||||
<div class="alert alert-success py-2 small mb-3">✓ <code>/usr/local/bin/claude</code> détecté.</div>
|
||||
<?php else: ?>
|
||||
<div class="alert alert-secondary py-2 small mb-3">✗ <code>/usr/local/bin/claude</code> introuvable — suivez les étapes ci-dessous.</div>
|
||||
<?php endif; ?>
|
||||
<p class="small text-muted">À exécuter en SSH sur le serveur (en root ou via sudo) :</p>
|
||||
<pre class="bg-dark text-light p-3 rounded small"><code># 1. Installer Claude Code CLI (en root)
|
||||
sudo npm install -g @anthropic-ai/claude-code
|
||||
|
||||
# Vérifier l'installation
|
||||
/usr/local/bin/claude --version
|
||||
|
||||
# 2. Créer le répertoire HOME de www-data pour Claude
|
||||
sudo mkdir -p /var/lib/claude-www
|
||||
sudo chown www-data:www-data /var/lib/claude-www
|
||||
|
||||
# 3. Authentifier Claude en tant que www-data
|
||||
sudo -u www-data HOME=/var/lib/claude-www /usr/local/bin/claude auth login
|
||||
# → Suivre les instructions (OAuth navigateur ou clé API)
|
||||
|
||||
# 4. Vérifier que ça fonctionne
|
||||
sudo -u www-data HOME=/var/lib/claude-www /usr/local/bin/claude --print "Réponds juste OK"</code></pre>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<?php endif; ?>
|
||||
|
||||
|
||||
+27
-69
@@ -1,12 +1,12 @@
|
||||
<?php
|
||||
$_statsSaved = isset($_GET['saved']);
|
||||
$_statsError = ($_GET['error'] ?? '') === 'write';
|
||||
$_readable = $adminData['stats_readable'] ?? false;
|
||||
$_pages = $adminData['stats_pages'] ?? [];
|
||||
$_books = $adminData['stats_books'] ?? [];
|
||||
$_asList = $adminData['stats_as'] ?? [];
|
||||
$_asGroups = $adminData['stats_as_groups'] ?? [];
|
||||
$_groups = $adminData['as_groups'] ?? [];
|
||||
$_statsSaved = isset($_GET['saved']);
|
||||
$_statsError = ($_GET['error'] ?? '') === 'write';
|
||||
$_readable = $adminData['stats_readable'] ?? false;
|
||||
$_books = $adminData['stats_books'] ?? [];
|
||||
$_asList = $adminData['stats_as'] ?? [];
|
||||
$_asGroups = $adminData['stats_as_groups'] ?? [];
|
||||
$_groups = $adminData['as_groups'] ?? [];
|
||||
$_pagesByDay = $adminData['stats_pages_by_day'] ?? [];
|
||||
$_activeGroup = trim($_GET['group'] ?? '');
|
||||
?>
|
||||
|
||||
@@ -23,55 +23,23 @@ $_activeGroup = trim($_GET['group'] ?? '');
|
||||
</div>
|
||||
<?php else: ?>
|
||||
|
||||
<p class="text-muted small mb-4">14 derniers jours · cache 10 min</p>
|
||||
<p class="text-muted small mb-4">14 derniers jours · visiteurs uniques · flux RSS XML</p>
|
||||
|
||||
<script>var FOLIO_PAGES_BY_DAY = <?= json_encode($_pagesByDay, JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE) ?>;</script>
|
||||
|
||||
<div class="card mb-4">
|
||||
<div class="card-header bg-transparent py-2 small fw-semibold d-flex justify-content-between">
|
||||
<span>Pages les plus visitées</span>
|
||||
<span class="text-muted" id="stats-pages-count"></span>
|
||||
</div>
|
||||
<div class="card-body p-0" id="stats-pages-container">
|
||||
<p class="text-muted p-3 mb-0">Chargement…</p>
|
||||
</div>
|
||||
<div class="card-footer bg-transparent border-top px-3 pt-3 pb-2" id="stats-trend-container"></div>
|
||||
</div>
|
||||
|
||||
<div class="row g-4">
|
||||
|
||||
<!-- Pages -->
|
||||
<div class="col-lg-6">
|
||||
<div class="card h-100">
|
||||
<div class="card-header bg-transparent py-2 small fw-semibold d-flex justify-content-between">
|
||||
<span>Pages les plus visitées</span>
|
||||
<span class="text-muted"><?= count($_pages) ?> URLs</span>
|
||||
</div>
|
||||
<div class="card-body p-0">
|
||||
<?php if (empty($_pages)): ?>
|
||||
<p class="text-muted p-3 mb-0">Aucune donnée.</p>
|
||||
<?php else: ?>
|
||||
<div class="table-responsive">
|
||||
<table class="table table-sm table-hover mb-0 small">
|
||||
<tbody>
|
||||
<?php
|
||||
$maxP = max($_pages) ?: 1;
|
||||
$rankP = 0;
|
||||
foreach ($_pages as $url => $hits):
|
||||
$rankP++;
|
||||
$slug = rawurldecode(substr($url, 6));
|
||||
$pct = round($hits / $maxP * 100);
|
||||
?>
|
||||
<tr>
|
||||
<td class="text-muted ps-3" style="width:2rem"><?= $rankP ?></td>
|
||||
<td>
|
||||
<a href="<?= htmlspecialchars($url) ?>" target="_blank"
|
||||
class="text-decoration-none text-truncate d-block" style="max-width:260px"
|
||||
title="<?= htmlspecialchars($slug) ?>">
|
||||
<?= htmlspecialchars($slug) ?>
|
||||
</a>
|
||||
<div class="progress mt-1" style="height:3px">
|
||||
<div class="progress-bar" style="width:<?= $pct ?>%"></div>
|
||||
</div>
|
||||
</td>
|
||||
<td class="text-end fw-semibold pe-3"><?= number_format($hits, 0, ',', '\u{202F}') ?></td>
|
||||
</tr>
|
||||
<?php endforeach; ?>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Livres -->
|
||||
<div class="col-lg-6">
|
||||
<div class="card h-100">
|
||||
@@ -93,7 +61,7 @@ $_activeGroup = trim($_GET['group'] ?? '');
|
||||
$rankB++;
|
||||
$slug = rawurldecode(substr($url, 6));
|
||||
$pct = round($hits / $maxB * 100);
|
||||
?>
|
||||
?>
|
||||
<tr>
|
||||
<td class="text-muted ps-3" style="width:2rem"><?= $rankB ?></td>
|
||||
<td>
|
||||
@@ -106,7 +74,7 @@ $_activeGroup = trim($_GET['group'] ?? '');
|
||||
<div class="progress-bar bg-success" style="width:<?= $pct ?>%"></div>
|
||||
</div>
|
||||
</td>
|
||||
<td class="text-end fw-semibold pe-3"><?= number_format($hits, 0, ',', '\u{202F}') ?></td>
|
||||
<td class="text-end fw-semibold pe-3"><?= number_format($hits, 0, ',', '\u{202F}') ?> <span class="text-muted fw-normal">vis.</span></td>
|
||||
</tr>
|
||||
<?php endforeach; ?>
|
||||
</tbody>
|
||||
@@ -145,7 +113,7 @@ $_activeGroup = trim($_GET['group'] ?? '');
|
||||
} else {
|
||||
$displayAs = $_asList;
|
||||
}
|
||||
?>
|
||||
?>
|
||||
<?php if (empty($displayAs)): ?>
|
||||
<p class="text-muted p-3 mb-0">
|
||||
<?= empty($_asList) ? 'Aucune IP résolue (LAN ou logs vides).' : 'Aucun AS dans ce groupe.' ?>
|
||||
@@ -186,7 +154,7 @@ $_activeGroup = trim($_GET['group'] ?? '');
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<?php endif; // readable ?>
|
||||
<?php endif; // readable?>
|
||||
|
||||
<!-- Groupes de réseaux -->
|
||||
<div class="card mt-4" style="max-width:600px">
|
||||
@@ -228,14 +196,4 @@ $_activeGroup = trim($_GET['group'] ?? '');
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
document.getElementById('as-group-add').addEventListener('click', () => {
|
||||
const tpl = document.getElementById('as-group-tpl').content.cloneNode(true);
|
||||
document.getElementById('as-groups-list').appendChild(tpl);
|
||||
});
|
||||
document.getElementById('as-groups-list').addEventListener('click', e => {
|
||||
if (e.target.classList.contains('as-group-delete')) {
|
||||
e.target.closest('.as-group-row').remove();
|
||||
}
|
||||
});
|
||||
</script>
|
||||
<script src="/assets/js/admin-stats.js" defer></script>
|
||||
|
||||
@@ -1,6 +1,4 @@
|
||||
<?php
|
||||
require_once BASE_PATH . '/src/Parsedown.php';
|
||||
$Parsedown = new Parsedown();
|
||||
|
||||
$_apName = $authorRow['display_name'] ?? '';
|
||||
$_apSlug = $authorRow['profile_slug'] ?? '';
|
||||
@@ -19,8 +17,7 @@ ob_start();
|
||||
<?php else: ?>
|
||||
<div class="post-grid">
|
||||
<?php foreach ($posts as $post):
|
||||
$html = $Parsedown->text($post['content']);
|
||||
$preview = mb_strimwidth(strip_tags($html), 0, 120, '…');
|
||||
$preview = mb_strimwidth($post['plain'] ?? '', 0, 120, '…');
|
||||
$category = trim((string)($post['category'] ?? ''));
|
||||
$gradient = coverGradient($category !== '' ? $category : $post['uuid'], $allCats ?? []);
|
||||
$postUrl = '/post/' . rawurlencode($post['slug']);
|
||||
|
||||
@@ -1,6 +1,4 @@
|
||||
<?php
|
||||
require_once BASE_PATH . '/src/Parsedown.php';
|
||||
$Parsedown = new Parsedown();
|
||||
|
||||
ob_start();
|
||||
|
||||
@@ -36,8 +34,7 @@ $_initials = mb_strtoupper(mb_substr($_apName, 0, 1, 'UTF-8'), 'UTF-8');
|
||||
<?php else: ?>
|
||||
<div class="post-grid">
|
||||
<?php foreach (array_slice($authorArticles, 0, 6) as $post):
|
||||
$html = $Parsedown->text($post['content']);
|
||||
$preview = mb_strimwidth(strip_tags($html), 0, 120, '…');
|
||||
$preview = mb_strimwidth($post['plain'] ?? '', 0, 120, '…');
|
||||
$category = trim((string)($post['category'] ?? ''));
|
||||
$gradient = coverGradient($category !== '' ? $category : $post['uuid'], $allCats ?? []);
|
||||
$postUrl = '/post/' . rawurlencode($post['slug']);
|
||||
|
||||
@@ -0,0 +1,49 @@
|
||||
<?php
|
||||
ob_start();
|
||||
?>
|
||||
|
||||
<div class="container py-4">
|
||||
|
||||
<div class="d-flex align-items-baseline justify-content-between mb-4">
|
||||
<h1 class="h3 mb-0">Livres</h1>
|
||||
<span class="text-muted small"><?= count($booksData) ?> livre<?= count($booksData) > 1 ? 's' : '' ?></span>
|
||||
</div>
|
||||
|
||||
<?php if (empty($booksData)): ?>
|
||||
<p class="text-muted">Aucun livre disponible pour l'instant.</p>
|
||||
<?php else: ?>
|
||||
|
||||
<div class="book-grid">
|
||||
<?php foreach ($booksData as $_bd):
|
||||
$_book = $_bd['book'];
|
||||
$_first = $_bd['first'];
|
||||
$_count = $_bd['count'];
|
||||
$_cover = $_first['cover'] ?? '';
|
||||
$_cat = trim($_first['category'] ?? '');
|
||||
$_coverStyle = $_cover !== ''
|
||||
? "background-image:url('/file?uuid=" . rawurlencode($_first['uuid']) . "&name=" . rawurlencode($_cover) . "')"
|
||||
: 'background:' . coverGradient($_cat !== '' ? $_cat : $_first['uuid'], $allCats ?? []);
|
||||
?>
|
||||
<a href="/book/<?= rawurlencode($_book['slug']) ?>" class="book-home-card">
|
||||
<div class="book-home-card-cover" style="<?= $_coverStyle ?>"></div>
|
||||
<div class="book-home-card-body">
|
||||
<div class="book-home-card-title"><?= htmlspecialchars($_book['title']) ?></div>
|
||||
<?php if (!empty($_book['description'])): ?>
|
||||
<div class="book-home-card-desc"><?= htmlspecialchars(mb_strimwidth($_book['description'], 0, 100, '…')) ?></div>
|
||||
<?php endif; ?>
|
||||
<div class="book-home-card-meta"><?= $_count ?> page<?= $_count > 1 ? 's' : '' ?></div>
|
||||
</div>
|
||||
</a>
|
||||
<?php endforeach; ?>
|
||||
</div>
|
||||
|
||||
<?php endif; ?>
|
||||
|
||||
</div>
|
||||
|
||||
<?php
|
||||
$content = ob_get_clean();
|
||||
$title = 'Livres — ' . siteTitle();
|
||||
$metaRobots = 'index, follow';
|
||||
$canonical = rtrim((string)($_ENV['APP_URL'] ?? getenv('APP_URL') ?: ''), '/') . '/books';
|
||||
include BASE_PATH . '/templates/layout.php';
|
||||
@@ -142,3 +142,4 @@ setcookie('_csrf_c', $_csrfToken, [
|
||||
</div>
|
||||
|
||||
</div>
|
||||
<script src="/assets/js/comments.js" defer></script>
|
||||
|
||||
@@ -97,8 +97,10 @@ $_typeLabel = $isCatField ? 'Catégorie' : ($tagTypes[$tagType] ?? ucfirst($tag
|
||||
|
||||
<?php renderTagGroup('Déjà taggués', $_current, true); ?>
|
||||
<?php renderTagGroup('Valeurs connues dans d\'autres articles', $_known, false); ?>
|
||||
<?php if (empty($_known)): ?>
|
||||
<?php renderTagGroup('Abréviations détectées', $_abbrevs, false, true); ?>
|
||||
<?php renderTagGroup('Noms composés détectés', $_camel + $_proper, false, true); ?>
|
||||
<?php endif; ?>
|
||||
|
||||
<?php if (empty($suggestions)): ?>
|
||||
<p class="text-muted">Aucun terme détecté dans cet article.</p>
|
||||
|
||||
@@ -4,6 +4,21 @@
|
||||
<h1 class="h4 mb-0">Flux agrégés</h1>
|
||||
</div>
|
||||
|
||||
<?php if (!empty($fluxErrors) && function_exists('isAdmin') && isAdmin()): ?>
|
||||
<div class="alert alert-warning py-2 mb-4">
|
||||
<strong><?= count($fluxErrors) ?> flux en erreur</strong>
|
||||
<ul class="mb-0 mt-1 small">
|
||||
<?php foreach ($fluxErrors as $_err): ?>
|
||||
<li>
|
||||
<?= htmlspecialchars($_err['label'] !== '' ? $_err['label'] : $_err['feed_url']) ?>
|
||||
— <code><?= htmlspecialchars($_err['feed_url']) ?></code>
|
||||
<span class="text-muted">(<?= htmlspecialchars($_err['user_email']) ?>)</span>
|
||||
</li>
|
||||
<?php endforeach; ?>
|
||||
</ul>
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
|
||||
<?php if (empty($fluxItems)): ?>
|
||||
<p class="text-muted">Aucun article disponible pour l'instant.</p>
|
||||
<?php else: ?>
|
||||
|
||||
@@ -60,7 +60,7 @@ $preSource = $step2Meta['canonical'] ?? $step2Meta['source'] ?? $step2Url;
|
||||
<div class="mb-4">
|
||||
<p class="fw-semibold small mb-2">Aperçu de la page</p>
|
||||
<?php
|
||||
$previewMtime = @filemtime(BASE_PATH . '/data/' . $step2Article['uuid'] . '/files/' . $step2Screenshot) ?: time();
|
||||
$previewMtime = @filemtime(DATA_PATH . '/' . $step2Article['uuid'] . '/files/' . $step2Screenshot) ?: time();
|
||||
?>
|
||||
<img src="/file?uuid=<?= rawurlencode($step2Article['uuid']) ?>&name=<?= rawurlencode($step2Screenshot) ?>&v=<?= $previewMtime ?>"
|
||||
class="img-fluid rounded shadow-sm d-block"
|
||||
|
||||
+19
-3
@@ -46,10 +46,20 @@
|
||||
|
||||
<!-- CSS -->
|
||||
<link href="/assets/css/bootstrap.min.css" rel="stylesheet">
|
||||
<link rel="stylesheet" href="/assets/css/style.css">
|
||||
<?php
|
||||
$_pub = BASE_PATH . '/public/assets/';
|
||||
if (!function_exists('_av')) {
|
||||
function _av(string $base, string $rel): string {
|
||||
$f = $base . $rel;
|
||||
return '/assets/' . $rel . (is_file($f) ? '?v=' . substr(md5_file($f), 0, 8) : '');
|
||||
}
|
||||
}
|
||||
?>
|
||||
<link rel="stylesheet" href="<?= _av($_pub, 'css/style.css') ?>">
|
||||
</head>
|
||||
|
||||
<body<?php if (!empty($bodyClass ?? '')): ?> class="<?= htmlspecialchars($bodyClass) ?>"<?php endif; ?>>
|
||||
<script src="<?= _av($_pub, 'js/density-fouc.js') ?>"></script>
|
||||
|
||||
<header>
|
||||
<nav class="navbar navbar-expand-lg navbar-dark mb-0" role="navigation" aria-label="Navigation principale">
|
||||
@@ -149,9 +159,15 @@ $_layoutCurrentCat = trim($_GET['cat'] ?? '');
|
||||
|
||||
<!-- JS -->
|
||||
<script src="/assets/js/bootstrap.bundle.min.js"></script>
|
||||
<script src="/assets/js/app.js"></script>
|
||||
<script src="<?= _av($_pub, 'js/app.js') ?>"></script>
|
||||
<?php if (isset($reactionStats)): ?>
|
||||
<script src="/assets/js/reactions.js"></script>
|
||||
<script src="<?= _av($_pub, 'js/reactions.js') ?>"></script>
|
||||
<?php endif; ?>
|
||||
<?php if (!empty($shareBar ?? false)): ?>
|
||||
<script src="<?= _av($_pub, 'js/share.js') ?>" defer></script>
|
||||
<?php endif; ?>
|
||||
<?php if (!empty($aiEditor ?? false)): ?>
|
||||
<script src="<?= _av($_pub, 'js/ai-editor.js') ?>"></script>
|
||||
<?php endif; ?>
|
||||
|
||||
</body>
|
||||
|
||||
@@ -115,8 +115,7 @@ $slugOriginal = $postSlug;
|
||||
</label>
|
||||
<input type="text" class="form-control form-control-sm font-monospace" id="confirm-slug" name="slug"
|
||||
value="<?= htmlspecialchars($slugDefault) ?>"
|
||||
pattern="[a-z0-9][a-z0-9\-]*"
|
||||
oninput="document.getElementById('slug-display').textContent=this.value">
|
||||
pattern="[a-z0-9][a-z0-9\-]*">
|
||||
<?php if ($titleChanged && $autoSlug !== $slugOriginal): ?>
|
||||
<div class="mt-2 d-flex align-items-center gap-2 flex-wrap">
|
||||
<small class="text-muted">Slug recalculé depuis le nouveau titre. Slug initial :</small>
|
||||
|
||||
@@ -9,6 +9,7 @@ $dateValue = isset($published_at)
|
||||
?>
|
||||
|
||||
<?php if ($action === 'edit'): ?>
|
||||
<?php $aiEditor = true; ?>
|
||||
<div id="vl-page"
|
||||
data-uuid="<?= htmlspecialchars($uuid) ?>"
|
||||
data-insert-url="<?= htmlspecialchars($insertUrl ?? '') ?>"
|
||||
@@ -221,6 +222,38 @@ $dateValue = isset($published_at)
|
||||
|
||||
<hr class="my-3">
|
||||
|
||||
<div class="mb-3">
|
||||
<p class="fw-semibold small mb-2">IA</p>
|
||||
<div class="d-flex flex-column gap-2">
|
||||
<button type="button" id="btn-ai-critique"
|
||||
class="btn btn-outline-secondary btn-sm">
|
||||
Analyse critique
|
||||
</button>
|
||||
<button type="button" id="btn-ai-rewrite"
|
||||
class="btn btn-outline-secondary btn-sm">
|
||||
Réécrire l'article
|
||||
</button>
|
||||
</div>
|
||||
<div id="ai-result-panel" class="mt-3" style="display:none">
|
||||
<div class="d-flex align-items-center justify-content-between mb-1">
|
||||
<span id="ai-result-label" class="fw-semibold small"></span>
|
||||
<button type="button" id="btn-ai-close" class="btn-close btn-sm"
|
||||
aria-label="Fermer"></button>
|
||||
</div>
|
||||
<div id="ai-result-content"
|
||||
class="border rounded p-2 small"
|
||||
style="max-height:400px;overflow-y:auto;white-space:pre-wrap;font-family:inherit;background:#f8f9fa">
|
||||
</div>
|
||||
<button type="button" id="btn-ai-apply"
|
||||
class="btn btn-warning btn-sm mt-2"
|
||||
style="display:none">
|
||||
Appliquer dans l'éditeur
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<hr class="my-3">
|
||||
|
||||
<?php if (!empty($existingFiles)): ?>
|
||||
<?php $coverFile = $article['cover'] ?? ''; ?>
|
||||
<?php $filesMeta = $article['files_meta'] ?? []; ?>
|
||||
|
||||
+53
-14
@@ -17,7 +17,13 @@ function _cardCoverStyle(array $post, array $allCats): string
|
||||
|
||||
function _cardExcerpt(array $post, \Parsedown $pd, int $len = 120): string
|
||||
{
|
||||
return mb_strimwidth(strip_tags($pd->text($post['content'])), 0, $len, '…');
|
||||
if (($post['plain'] ?? '') !== '') {
|
||||
return mb_strimwidth($post['plain'], 0, $len, '…');
|
||||
}
|
||||
if (($post['content'] ?? '') !== '') {
|
||||
return mb_strimwidth(strip_tags($pd->text($post['content'])), 0, $len, '…');
|
||||
}
|
||||
return '';
|
||||
}
|
||||
|
||||
function _renderCard(array $post, array $privateCats, array $allCats, \Parsedown $pd): void
|
||||
@@ -88,9 +94,7 @@ function _renderCard(array $post, array $privateCats, array $allCats, \Parsedown
|
||||
</form>
|
||||
<p class="hero-search-stats">
|
||||
<?= $totalPublished ?> article<?= $totalPublished > 1 ? 's' : '' ?>
|
||||
<?php if ($totalUpcoming > 0): ?>
|
||||
· <?= $totalUpcoming ?> à venir
|
||||
<?php endif; ?>
|
||||
<?php if ($totalUpcoming > 0): ?>· <?= $totalUpcoming ?> à venir<?php endif; ?>
|
||||
</p>
|
||||
</div>
|
||||
|
||||
@@ -155,19 +159,14 @@ function _renderCard(array $post, array $privateCats, array $allCats, \Parsedown
|
||||
</section>
|
||||
<?php endif; ?>
|
||||
|
||||
<?php /* ─── Tendances ───────────────────────────────────────────────────── */ ?>
|
||||
<?php if (!empty($popularPosts)): ?>
|
||||
<section class="home-section">
|
||||
<?php /* ─── Meilleures audiences (AJAX — flux RSS XML /trending?period=1h) ── */ ?>
|
||||
<section class="home-section" id="home-audiences-section" hidden>
|
||||
<h2 class="home-section-title">
|
||||
Tendances <span class="home-section-title-sub">· 10 derniers jours</span>
|
||||
Meilleures audiences <span class="home-section-title-sub">· 1 heure</span>
|
||||
</h2>
|
||||
<div class="post-grid">
|
||||
<?php foreach ($popularPosts as $_pp): ?>
|
||||
<?php _renderCard($_pp, $privateCats ?? [], $allCats ?? [], $Parsedown); ?>
|
||||
<?php endforeach; ?>
|
||||
</div>
|
||||
<div class="post-grid" id="home-audiences-grid"></div>
|
||||
</section>
|
||||
<?php endif; ?>
|
||||
<script src="/assets/js/trending-home.js"></script>
|
||||
|
||||
<?php /* ─── Récemment mis à jour ──────────────────────────────────────── */ ?>
|
||||
<?php if (!empty($recentlyUpdated)): ?>
|
||||
@@ -215,6 +214,38 @@ function _renderCard(array $post, array $privateCats, array $allCats, \Parsedown
|
||||
</section>
|
||||
<?php endif; ?>
|
||||
|
||||
<?php if (!empty($homeBooks ?? [])): ?>
|
||||
<section class="home-section">
|
||||
<h2 class="home-section-title">
|
||||
Livres
|
||||
<a href="/books" class="home-section-more">Voir tous →</a>
|
||||
</h2>
|
||||
<div class="book-grid">
|
||||
<?php foreach ($homeBooks as $_hb):
|
||||
$_book = $_hb['book'];
|
||||
$_first = $_hb['first'];
|
||||
$_count = $_hb['count'];
|
||||
$_cover = $_first['cover'] ?? '';
|
||||
$_cat = trim($_first['category'] ?? '');
|
||||
$_coverStyle = $_cover !== ''
|
||||
? "background-image:url('/file?uuid=" . rawurlencode($_first['uuid']) . "&name=" . rawurlencode($_cover) . "')"
|
||||
: 'background:' . coverGradient($_cat !== '' ? $_cat : $_first['uuid'], $allCats ?? []);
|
||||
?>
|
||||
<a href="/book/<?= rawurlencode($_book['slug']) ?>" class="book-home-card">
|
||||
<div class="book-home-card-cover" style="<?= $_coverStyle ?>"></div>
|
||||
<div class="book-home-card-body">
|
||||
<div class="book-home-card-title"><?= htmlspecialchars($_book['title']) ?></div>
|
||||
<?php if (!empty($_book['description'])): ?>
|
||||
<div class="book-home-card-desc"><?= htmlspecialchars(mb_strimwidth($_book['description'], 0, 80, '…')) ?></div>
|
||||
<?php endif; ?>
|
||||
<div class="book-home-card-meta"><?= $_count ?> page<?= $_count > 1 ? 's' : '' ?></div>
|
||||
</div>
|
||||
</a>
|
||||
<?php endforeach; ?>
|
||||
</div>
|
||||
</section>
|
||||
<?php endif; ?>
|
||||
|
||||
<?php else: /* ─── VUE PAGINÉE / FILTRÉE ─────────────────────────────── */ ?>
|
||||
|
||||
<?php if ($cursor === '' && $filterCat === ''): ?>
|
||||
@@ -302,6 +333,14 @@ if (!empty($_tagCats)):
|
||||
<a href="/new" class="fab-new" title="Nouvel article" aria-label="Nouvel article">+</a>
|
||||
<?php endif; ?>
|
||||
|
||||
<div class="density-widget" id="density-toggle-widget" role="group" aria-label="Taille d'affichage">
|
||||
<button type="button" class="density-btn" data-d="l" title="Pleine largeur">L</button>
|
||||
<button type="button" class="density-btn" data-d="m" title="Normal">M</button>
|
||||
<button type="button" class="density-btn" data-d="s" title="Compact">S</button>
|
||||
</div>
|
||||
|
||||
<script src="/assets/js/density.js"></script>
|
||||
|
||||
<?php
|
||||
$content = ob_get_clean();
|
||||
$title = siteTitle();
|
||||
|
||||
+145
-26
@@ -9,32 +9,62 @@ $_accentMap = [
|
||||
];
|
||||
$_tocItems = [];
|
||||
$_tocSeen = [];
|
||||
// Le titre H1 est déjà affiché par le template ; on le retire du rendu.
|
||||
$_rawForRender = preg_replace('/^\s*# [^\n]*\n*/u', '', $rawContent);
|
||||
$_renderedContent = preg_replace_callback(
|
||||
'/<(h[23])>(.+?)<\/h[23]>/i',
|
||||
function ($m) use (&$_tocItems, &$_tocSeen, $_accentMap) {
|
||||
$tag = $m[1];
|
||||
$inner = $m[2];
|
||||
$level = (int) substr($tag, 1);
|
||||
$plain = strip_tags($inner);
|
||||
$slug = trim(preg_replace(
|
||||
'/[^a-z0-9]+/',
|
||||
'-',
|
||||
mb_strtolower(strtr($plain, $_accentMap), 'UTF-8')
|
||||
), '-') ?: 'section';
|
||||
if (isset($_tocSeen[$slug])) {
|
||||
$_tocSeen[$slug]++;
|
||||
$id = $slug . '-' . $_tocSeen[$slug];
|
||||
} else {
|
||||
$_tocSeen[$slug] = 0;
|
||||
$id = $slug;
|
||||
}
|
||||
$_tocItems[] = ['level' => $level, 'text' => $plain, 'id' => $id];
|
||||
return "<{$tag} id=\"" . htmlspecialchars($id) . "\">{$inner}</{$tag}>";
|
||||
},
|
||||
$Parsedown->text($_rawForRender)
|
||||
);
|
||||
|
||||
// Cache du rendu Markdown (invalidé si index.md est plus récent)
|
||||
$_mdFile = defined('DATA_PATH') ? DATA_PATH . '/' . ($article['uuid'] ?? '') . '/index.md' : '';
|
||||
$_cacheFile = defined('DATA_PATH') ? DATA_PATH . '/' . ($article['uuid'] ?? '') . '/_cache/content_rendered.json' : '';
|
||||
$_mdMtime = ($_mdFile !== '' && file_exists($_mdFile)) ? (int)filemtime($_mdFile) : 0;
|
||||
|
||||
$_renderedContent = null;
|
||||
if ($_cacheFile !== '' && file_exists($_cacheFile)) {
|
||||
$_tmp = json_decode((string)file_get_contents($_cacheFile), true);
|
||||
if (is_array($_tmp) && isset($_tmp['ts'], $_tmp['html'], $_tmp['toc'])
|
||||
&& (int)$_tmp['ts'] >= $_mdMtime && $_mdMtime > 0) {
|
||||
$_renderedContent = $_tmp['html'];
|
||||
$_tocItems = $_tmp['toc'];
|
||||
}
|
||||
}
|
||||
|
||||
if ($_renderedContent === null) {
|
||||
// Le titre H1 est déjà affiché par le template ; on le retire du rendu.
|
||||
$_rawForRender = preg_replace('/^\s*# [^\n]*\n*/u', '', $rawContent);
|
||||
$_renderedContent = preg_replace_callback(
|
||||
'/<(h[23])>(.+?)<\/h[23]>/i',
|
||||
function ($m) use (&$_tocItems, &$_tocSeen, $_accentMap) {
|
||||
$tag = $m[1];
|
||||
$inner = $m[2];
|
||||
$level = (int) substr($tag, 1);
|
||||
$plain = strip_tags($inner);
|
||||
$slug = trim(preg_replace(
|
||||
'/[^a-z0-9]+/',
|
||||
'-',
|
||||
mb_strtolower(strtr($plain, $_accentMap), 'UTF-8')
|
||||
), '-') ?: 'section';
|
||||
if (isset($_tocSeen[$slug])) {
|
||||
$_tocSeen[$slug]++;
|
||||
$id = $slug . '-' . $_tocSeen[$slug];
|
||||
} else {
|
||||
$_tocSeen[$slug] = 0;
|
||||
$id = $slug;
|
||||
}
|
||||
$_tocItems[] = ['level' => $level, 'text' => $plain, 'id' => $id];
|
||||
return "<{$tag} id=\"" . htmlspecialchars($id) . "\">{$inner}</{$tag}>";
|
||||
},
|
||||
$Parsedown->text($_rawForRender)
|
||||
);
|
||||
$_renderedContent = typographieHtml($_renderedContent ?? '');
|
||||
// Lazy loading sur toutes les images du contenu
|
||||
$_renderedContent = preg_replace('/<img\b([^>]*)>/i', '<img$1 loading="lazy">', $_renderedContent ?? '') ?? $_renderedContent;
|
||||
|
||||
// Écriture du cache
|
||||
if ($_cacheFile !== '' && $_mdMtime > 0) {
|
||||
@mkdir(dirname($_cacheFile), 0755, true);
|
||||
@file_put_contents($_cacheFile, json_encode(
|
||||
['ts' => $_mdMtime, 'html' => $_renderedContent, 'toc' => $_tocItems],
|
||||
JSON_UNESCAPED_UNICODE
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
ob_start();
|
||||
|
||||
@@ -95,6 +125,14 @@ $authorName = ($authorEmail !== '' && function_exists('authorDisplayName')
|
||||
$authorProfileUrl = ($authorEmail !== '' && function_exists('authorProfileUrl')) ? authorProfileUrl($authorEmail) : '';
|
||||
$authorSlugVal = ($authorEmail !== '' && function_exists('authorSlug')) ? authorSlug($authorEmail) : '';
|
||||
$pubDate = htmlspecialchars(date('d/m/Y', strtotime((string)($article['published_at'] ?? $article['created_at'] ?? ''))));
|
||||
$modDate = '';
|
||||
$_updatedTs = strtotime((string)($article['updated_at'] ?? ''));
|
||||
$_publishedTs = strtotime((string)($article['published_at'] ?? $article['created_at'] ?? ''));
|
||||
if ($_updatedTs > 0 && $_publishedTs > 0 && $_updatedTs > $_publishedTs) {
|
||||
$_frMonths = ['janvier','février','mars','avril','mai','juin','juillet','août','septembre','octobre','novembre','décembre'];
|
||||
$modDate = 'Modifié le ' . (int)date('j', $_updatedTs) . ' ' . $_frMonths[(int)date('n', $_updatedTs) - 1]
|
||||
. ' ' . date('Y', $_updatedTs) . ' à ' . date('H', $_updatedTs) . 'h' . date('i', $_updatedTs);
|
||||
}
|
||||
$hasCover = $coverFile !== '';
|
||||
$heroExtraClass = $hasCover ? '' : ' article-cover--gradient';
|
||||
$heroStyle = $hasCover ? '' : ' style="background:' . htmlspecialchars($gradient) . '"';
|
||||
@@ -136,6 +174,9 @@ $hasSources = (!empty($externalLinks) || !empty($files))
|
||||
<span class="mx-1 opacity-50">·</span>
|
||||
<?php endif; ?>
|
||||
<?= $pubDate ?>
|
||||
<?php if ($modDate !== ''): ?>
|
||||
<br><small class="opacity-75"><?= htmlspecialchars($modDate) ?></small>
|
||||
<?php endif; ?>
|
||||
</p>
|
||||
</div>
|
||||
<div class="article-hero-right">
|
||||
@@ -173,6 +214,12 @@ $hasSources = (!empty($externalLinks) || !empty($files))
|
||||
</div>
|
||||
</div>
|
||||
<div class="card-body">
|
||||
<?php if (($_GET['delete_failed'] ?? '') === '1' && function_exists('isAdmin') && isAdmin()): ?>
|
||||
<div class="alert alert-danger alert-dismissible fade show" role="alert">
|
||||
Suppression impossible — droits insuffisants sur le répertoire de données.
|
||||
<button type="button" class="btn-close" data-bs-dismiss="alert"></button>
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
<div class="card-text post-content">
|
||||
<?= $_renderedContent ?>
|
||||
</div>
|
||||
@@ -214,6 +261,59 @@ $hasSources = (!empty($externalLinks) || !empty($files))
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<?php if (($ratingStats['count'] ?? 0) > 0 || isLoggedIn()): ?>
|
||||
<div class="d-flex align-items-center flex-wrap gap-3 my-3 py-2 border-top small">
|
||||
<span class="text-muted">Note :</span>
|
||||
<?php if (($ratingStats['avg'] ?? null) !== null): ?>
|
||||
<span>
|
||||
<strong><?= number_format((float)$ratingStats['avg'], 1) ?></strong>/5
|
||||
<span class="text-muted">(<?= (int)$ratingStats['count'] ?> vote<?= (int)$ratingStats['count'] > 1 ? 's' : '' ?>)</span>
|
||||
</span>
|
||||
<?php else: ?>
|
||||
<span class="text-muted">Pas encore noté</span>
|
||||
<?php endif; ?>
|
||||
<?php if (isLoggedIn()): ?>
|
||||
<form method="POST" action="/?action=rate" class="d-flex align-items-center gap-1 mb-0">
|
||||
<input type="hidden" name="uuid" value="<?= htmlspecialchars($article['uuid']) ?>">
|
||||
<?php for ($_s = 1; $_s <= 5; $_s++): ?>
|
||||
<button type="submit" name="rating" value="<?= $_s ?>"
|
||||
class="btn btn-link p-0 lh-1 text-decoration-none<?= (($userRating ?? 0) >= $_s) ? ' text-warning' : ' text-muted' ?>"
|
||||
title="<?= $_s ?> étoile<?= $_s > 1 ? 's' : '' ?>">
|
||||
<?= (($userRating ?? 0) >= $_s) ? '★' : '☆' ?>
|
||||
</button>
|
||||
<?php endfor; ?>
|
||||
<?php if (($userRating ?? null) !== null): ?>
|
||||
<span class="text-muted ms-1">(votre note)</span>
|
||||
<?php endif; ?>
|
||||
</form>
|
||||
<?php else: ?>
|
||||
<span class="text-muted fst-italic">Connectez-vous pour noter</span>
|
||||
<?php endif; ?>
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
|
||||
<?php if ($article['published'] ?? false): ?>
|
||||
<?php
|
||||
$_shareUrl = rtrim(defined('APP_URL') ? APP_URL : '', '/') . '/post/' . rawurlencode($article['slug'] ?? '');
|
||||
$_shareTitle = $article['title'] ?? '';
|
||||
?>
|
||||
<div class="d-flex flex-wrap align-items-center gap-2 my-3 py-2 border-top"
|
||||
id="share-bar"
|
||||
data-url="<?= htmlspecialchars($_shareUrl) ?>"
|
||||
data-title="<?= htmlspecialchars($_shareTitle) ?>">
|
||||
<span class="text-muted small me-1">Partager :</span>
|
||||
<a href="mailto:?subject=<?= rawurlencode($_shareTitle) ?>&body=<?= rawurlencode($_shareUrl) ?>"
|
||||
class="btn btn-outline-secondary btn-sm" title="Par e-mail">✉ Mail</a>
|
||||
<a href="https://x.com/intent/tweet?text=<?= rawurlencode($_shareTitle) ?>&url=<?= rawurlencode($_shareUrl) ?>"
|
||||
class="btn btn-outline-secondary btn-sm" target="_blank" rel="noopener noreferrer" title="X / Twitter">X</a>
|
||||
<a href="https://www.linkedin.com/sharing/share-offsite/?url=<?= rawurlencode($_shareUrl) ?>"
|
||||
class="btn btn-outline-secondary btn-sm" target="_blank" rel="noopener noreferrer" title="LinkedIn">in</a>
|
||||
<a href="https://mastodon.social/share?text=<?= rawurlencode($_shareTitle . ' ' . $_shareUrl) ?>"
|
||||
class="btn btn-outline-secondary btn-sm" target="_blank" rel="noopener noreferrer" title="Mastodon">🐘</a>
|
||||
<button type="button" class="btn btn-outline-secondary btn-sm" id="share-copy">Copier le lien</button>
|
||||
<button type="button" class="btn btn-outline-primary btn-sm" id="share-native" hidden>⬆ Partager</button>
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
|
||||
<?php include __DIR__ . '/comments_section.php'; ?>
|
||||
|
||||
@@ -340,6 +440,24 @@ $hasSources = (!empty($externalLinks) || !empty($files))
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
|
||||
<?php
|
||||
$_revisions = array_reverse($article['revisions'] ?? []);
|
||||
if (!empty($_revisions) && isLoggedIn()):
|
||||
?>
|
||||
<h6 class="related-sidebar-title mt-3">Historique</h6>
|
||||
<ul class="toc-list small">
|
||||
<?php foreach (array_slice($_revisions, 0, 10) as $_rev): ?>
|
||||
<li>
|
||||
<a href="/diff/<?= rawurlencode($article['uuid']) ?>/<?= (int)$_rev['n'] ?>">
|
||||
<?= htmlspecialchars(substr($_rev['date'] ?? '', 0, 10)) ?>
|
||||
<?php if (($_rev['comment'] ?? '') !== ''): ?>
|
||||
— <span class="text-muted"><?= htmlspecialchars(mb_strimwidth($_rev['comment'], 0, 40, '…')) ?></span>
|
||||
<?php endif; ?>
|
||||
</a>
|
||||
</li>
|
||||
<?php endforeach; ?>
|
||||
</ul>
|
||||
<?php endif; ?>
|
||||
|
||||
</aside>
|
||||
</div>
|
||||
@@ -350,6 +468,7 @@ $hasSources = (!empty($externalLinks) || !empty($files))
|
||||
|
||||
<?php
|
||||
$content = ob_get_clean();
|
||||
$shareBar = (bool)($article['published'] ?? false);
|
||||
$title = htmlspecialchars($article['title']);
|
||||
$seoTitle = ($article['seo_title'] ?? '') ?: $article['title'];
|
||||
$ogType = 'article';
|
||||
|
||||
@@ -38,7 +38,7 @@ function renderMetaCell(string $key, mixed $val, array $row = []): string
|
||||
?>
|
||||
|
||||
<div class="d-flex align-items-center gap-3 mb-1">
|
||||
<a href="/edit/<?= rawurlencode($article['uuid']) ?>" class="btn btn-secondary btn-sm">← Modifier</a>
|
||||
<a href="/post/<?= rawurlencode($article['slug'] ?? $article['uuid']) ?>" class="btn btn-secondary btn-sm">← Retour à l'article</a>
|
||||
<h1 class="h4 mb-0">Sources & médias</h1>
|
||||
</div>
|
||||
<p class="text-muted small mb-4"><?= htmlspecialchars($article['title']) ?></p>
|
||||
|
||||
@@ -49,15 +49,44 @@ $_hasUuid = $_wizUuid !== '';
|
||||
|
||||
</div><!-- /col-lg-9 -->
|
||||
|
||||
<!-- Plan (TOC dynamique) ───────────────────────────────────────────────── -->
|
||||
<!-- Sidebar droite : TOC + IA ──────────────────────────────────────────── -->
|
||||
<div class="col-lg-3 d-none d-lg-block">
|
||||
<div class="position-sticky" style="top:1rem">
|
||||
<div class="card border-secondary-subtle">
|
||||
<div class="card border-secondary-subtle mb-3">
|
||||
<div class="card-header bg-transparent py-2 small fw-semibold text-muted">Plan</div>
|
||||
<div class="card-body p-2" style="max-height:80vh;overflow-y:auto">
|
||||
<div class="card-body p-2" style="max-height:40vh;overflow-y:auto">
|
||||
<ul id="wz-toc-list" class="list-unstyled mb-0"></ul>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<?php if ($mode === 'edit'): ?>
|
||||
<div class="card border-secondary-subtle">
|
||||
<div class="card-header bg-transparent py-2 small fw-semibold text-muted">IA</div>
|
||||
<div class="card-body p-2">
|
||||
<button type="button" id="btn-ai-analyze" class="btn btn-outline-secondary btn-sm w-100">
|
||||
Analyser et proposer
|
||||
</button>
|
||||
<div id="ai-result-panel" class="mt-2" style="display:none">
|
||||
<div class="d-flex align-items-center justify-content-between mb-1">
|
||||
<span class="fw-semibold small">Ce qui n'allait pas</span>
|
||||
<button type="button" id="btn-ai-close" class="btn-close btn-sm" aria-label="Fermer"></button>
|
||||
</div>
|
||||
<div id="ai-critique-content"
|
||||
class="border rounded p-2 small mb-2"
|
||||
style="max-height:220px;overflow-y:auto;white-space:pre-wrap;font-family:inherit;background:#f8f9fa">
|
||||
</div>
|
||||
<div class="fw-semibold small mb-1">Proposition</div>
|
||||
<div id="ai-rewrite-content"
|
||||
class="border rounded p-2 small"
|
||||
style="max-height:220px;overflow-y:auto;white-space:pre-wrap;font-family:inherit;background:#f8f9fa">
|
||||
</div>
|
||||
<button type="button" id="btn-ai-apply" class="btn btn-warning btn-sm mt-2 w-100" style="display:none">
|
||||
Appliquer la proposition
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
</div>
|
||||
</div>
|
||||
</div><!-- /row -->
|
||||
@@ -172,4 +201,5 @@ $_hasUuid = $_wizUuid !== '';
|
||||
<?php
|
||||
$content = ob_get_clean();
|
||||
$title = ($mode === 'create' ? 'Nouvel article' : 'Modifier') . ' — Étape 1/' . $totalSteps;
|
||||
if ($mode === 'edit') { $aiEditor = true; }
|
||||
include BASE_PATH . '/templates/layout.php';
|
||||
|
||||
@@ -98,7 +98,7 @@ $_catVal = trim($category ?? '');
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<?php if ($mode === 'create' && !empty($existingFiles ?? [])): ?>
|
||||
<?php if (!empty($existingFiles ?? [])): ?>
|
||||
<?php $_imgFiles = array_filter($existingFiles, fn ($_f) => $_f['is_image']); ?>
|
||||
<?php if ($_imgFiles): ?>
|
||||
<div class="mb-0">
|
||||
|
||||
@@ -2,19 +2,17 @@
|
||||
// Attendu (edit only) : $uuid, $step, $totalSteps, $mode='edit', $article (original),
|
||||
// $draftData, $diffLines, $changes, $autoRevisionComment,
|
||||
// $seoTitle, $seoDescription, $autoSeoDesc, $title (draft), $postSlug,
|
||||
// $titleChanged, $autoSlug, $published, $published_at, $category
|
||||
// $titleChanged, $published, $published_at, $category
|
||||
ob_start();
|
||||
$_CONTEXT = 3;
|
||||
$_backUrl = '/edit/' . rawurlencode($uuid) . '/5';
|
||||
$_formAction = '/edit/' . rawurlencode($uuid) . '/6';
|
||||
$_slugFinal = ($titleChanged && $autoSlug !== $postSlug) ? $autoSlug : $postSlug;
|
||||
?>
|
||||
<?php include __DIR__ . '/nav.php'; ?>
|
||||
|
||||
<!-- En-tête : titre + boutons à droite ─────────────────────────────────── -->
|
||||
<form method="POST" action="<?= htmlspecialchars($_formAction) ?>">
|
||||
<input type="hidden" name="_confirm" value="1">
|
||||
<input type="hidden" name="slug" value="<?= htmlspecialchars($_slugFinal) ?>">
|
||||
|
||||
<div class="d-flex align-items-start justify-content-between gap-3 mb-4 flex-wrap">
|
||||
<div>
|
||||
@@ -28,7 +26,9 @@ $_slugFinal = ($titleChanged && $autoSlug !== $postSlug) ? $autoSlug : $postSlu
|
||||
<div class="d-flex gap-2 flex-wrap align-items-center">
|
||||
<a href="<?= htmlspecialchars($_backUrl) ?>" class="btn btn-outline-secondary btn-sm">← Retour</a>
|
||||
<button type="button" class="btn btn-outline-danger btn-sm"
|
||||
onclick="if(confirm('Abandonner les modifications et supprimer ce brouillon ?')) window.location='/edit/<?= rawurlencode($uuid) ?>/discard'">
|
||||
data-confirm-discard
|
||||
data-discard-url="/edit/<?= rawurlencode($uuid) ?>/discard"
|
||||
data-confirm-msg="Abandonner les modifications et supprimer ce brouillon ?">
|
||||
Abandonner
|
||||
</button>
|
||||
<button type="submit" class="btn btn-success">✓ Confirmer et enregistrer</button>
|
||||
|
||||
Reference in New Issue
Block a user