%s
%s
" "%s%sdiff --git a/forum/forum.py b/forum/forum.py
index 251d513..7d936b3 100644
--- a/forum/forum.py
+++ b/forum/forum.py
@@ -256,18 +256,26 @@ class Forum:
raise Invalide("%s vide ou trop long" % nom)
return s
- def _nouveau_sujet(self, user, titre, corps, ip, status="publie", station=None):
- cur = self.con.execute("INSERT INTO topics(title, author_id, status, station) VALUES (?, ?, ?, ?)",
- (titre, user["id"], status, station))
- post = self.con.execute("INSERT INTO posts(topic_id, author_id, body, ip) VALUES (?, ?, ?, ?)",
- (cur.lastrowid, user["id"], corps, ip))
- self.con.commit()
+ def _nouveau_sujet(self, user, titre, corps, ip, status="publie", station=None, prets=()):
+ # Les fichiers sont deja valides ; aucune publication partielle si le
+ # stockage echoue. Des fichiers sans reference peuvent rester sur disque.
+ with self.con:
+ cur = self.con.execute("INSERT INTO topics(title, author_id, status, station) VALUES (?, ?, ?, ?)",
+ (titre, user["id"], status, station))
+ post = self.con.execute("INSERT INTO posts(topic_id, author_id, body, ip) VALUES (?, ?, ?, ?)",
+ (cur.lastrowid, user["id"], corps, ip))
+ for nom, mime, propre in prets:
+ empreinte, chemin = self._stocker(self.dossier_photos, mime, propre)
+ self.con.execute("INSERT INTO attachments(post_id, filename, mime, size, sha256, stored_path) VALUES (?, ?, ?, ?, ?, ?)",
+ (post.lastrowid, nom, mime, len(propre), empreinte, chemin))
return cur.lastrowid, post.lastrowid
- def creer_sujet(self, user, titre, corps, ip=None):
- """Adhérents et propriétaires (un membre écrit seulement dans les sujets existants)."""
+ def creer_sujet(self, user, titre, corps, ip=None, fichiers=()):
+ """Adherents et proprietaires ; photos validees avant creation du sujet."""
self._exiger(user, "creer_sujet")
- return self._nouveau_sujet(user, self._texte(titre, TITRE_MAX, "titre"), self._texte(corps, CORPS_MAX, "message"), ip)[0]
+ titre, corps = self._texte(titre, TITRE_MAX, "titre"), self._texte(corps, CORPS_MAX, "message")
+ prets = self._preparer_photos(list(fichiers), illimite=self._peut(user, "photos_illimitees")) if fichiers else []
+ return self._nouveau_sujet(user, titre, corps, ip, prets=prets)[0]
def creer_sujet_station(self, user, station, corps, ip=None):
"""Propriétaire de station : un seul sujet pour sa station, titre préconfiguré, à valider."""
diff --git a/forum/panneau.py b/forum/panneau.py
index c760ce8..aca5cd6 100644
--- a/forum/panneau.py
+++ b/forum/panneau.py
@@ -83,12 +83,12 @@ class Handler(BaseHTTPRequestHandler):
return server._cookie(nom, valeur, age, "/", secure)
def envoyer(self, code, corps, type_="text/html; charset=utf-8", extra=()):
- data = corps if isinstance(corps, bytes) else corps.encode("utf-8")
+ data = corps if isinstance(corps, bytes) else corps.replace("__POLICES__", "/polices").encode("utf-8")
self.send_response(code)
self.send_header("Content-Type", type_)
self.send_header("Content-Length", str(len(data)))
self.send_header("Content-Security-Policy",
- "default-src 'none'; style-src 'unsafe-inline'; img-src 'self'; form-action 'self'; frame-ancestors 'none'")
+ "default-src 'none'; style-src 'unsafe-inline'; img-src 'self'; font-src 'self'; form-action 'self'; frame-ancestors 'none'")
self.send_header("X-Content-Type-Options", "nosniff")
self.send_header("Referrer-Policy", "no-referrer")
self.send_header("Cache-Control", "private, no-store")
@@ -249,6 +249,8 @@ class Handler(BaseHTTPRequestHandler):
return
u = urlparse(self.path)
user = self.utilisateur()
+ if u.path.startswith("/polices/"):
+ return server.servir_police(self, u.path)
try:
if u.path == "/connexion/gastinel":
return self.connexion_depart(user)
diff --git a/forum/polices/bitter-normal.woff2 b/forum/polices/bitter-normal.woff2
new file mode 100644
index 0000000..c18148f
Binary files /dev/null and b/forum/polices/bitter-normal.woff2 differ
diff --git a/forum/polices/outfit-normal.woff2 b/forum/polices/outfit-normal.woff2
new file mode 100644
index 0000000..85e3332
Binary files /dev/null and b/forum/polices/outfit-normal.woff2 differ
diff --git a/forum/server.py b/forum/server.py
index cca9108..343081e 100644
--- a/forum/server.py
+++ b/forum/server.py
@@ -35,6 +35,32 @@ import connexion # noqa: E402
import roles # noqa: E402
from forum import FICHE_PHOTOS_MAX, OCTETS_MAX, PHOTOS_MAX, SESSION_JOURS, ETAT_MINUTES, Forum, Invalide, Refus # noqa: E402
+
+MOIS_FR = ("janv.", "févr.", "mars", "avr.", "mai", "juin", "juil.", "août", "sept.", "oct.", "nov.", "déc.")
+
+
+def _dernier_dimanche(annee, mois):
+ import datetime as dt
+ j = dt.date(annee, mois + 1, 1) - dt.timedelta(days=1) if mois < 12 else dt.date(annee, 12, 31)
+ return j - dt.timedelta(days=(j.weekday() + 1) % 7)
+
+
+def date_fr(texte, heure=False):
+ """Date SQLite UTC ('AAAA-MM-JJ HH:MM:SS') -> '5 nov. 2026' (heure de Paris), sans tzdata."""
+ import datetime as dt
+ try:
+ d = dt.datetime.strptime((texte or "")[:19], "%Y-%m-%d %H:%M:%S")
+ except ValueError:
+ try:
+ d = dt.datetime.strptime((texte or "")[:10], "%Y-%m-%d")
+ except ValueError:
+ return texte or ""
+ ete_debut = dt.datetime.combine(_dernier_dimanche(d.year, 3), dt.time(1))
+ ete_fin = dt.datetime.combine(_dernier_dimanche(d.year, 10), dt.time(1))
+ d = d + dt.timedelta(hours=2 if ete_debut <= d < ete_fin else 1)
+ jour = "%d %s %d" % (d.day, MOIS_FR[d.month - 1], d.year)
+ return "%s à %d h %02d" % (jour, d.hour, d.minute) if heure else jour
+
SESSION = "forum_session"
ETAT = "forum_etat"
JETON_OK = re.compile(r"^[A-Za-z0-9_-]{20,100}$")
@@ -129,6 +155,53 @@ form.inline{display:inline;margin:0 6px 0 0}form.inline button{font-size:12px;pa
.sujets li{flex-wrap:wrap;gap:4px 12px}
button,input,select,summary,.nav a{min-height:42px}
}
+/* Lecture confortable, surfaces et hierarchie communes au forum et au panneau. */
+@font-face{font-family:Bitter;font-style:normal;font-weight:500 700;font-display:swap;src:url('__POLICES__/bitter-normal.woff2') format('woff2')}
+@font-face{font-family:Outfit;font-style:normal;font-weight:400 600;font-display:swap;src:url('__POLICES__/outfit-normal.woff2') format('woff2')}
+body{font-size:16px;line-height:1.6}
+.haut{padding:24px 24px 18px;max-width:1160px;border-bottom:1px solid #b9bdb3}
+.haut .nom{font:600 20px Bitter,Georgia,serif;letter-spacing:0}
+main{max-width:1160px;padding:24px 24px 64px}
+h1{font-size:42px;line-height:1.15;max-width:24ch;overflow-wrap:anywhere}
+h2{font-size:26px;line-height:1.25;margin-top:32px}
+.haut,.haut form button,.haut .gastinel,.chapeau,.meta,.essai,.badge,.etat,label,.pied,.msg aside,.galerie figure button,form.inline button{font-size:16px}
+.haut form button{text-transform:none;letter-spacing:0;padding:8px 12px}
+.badge{letter-spacing:0;text-transform:none;padding:2px 8px}
+.chapeau{font-size:18px;margin:12px 0 24px}
+.nav{gap:8px;margin-bottom:24px;border-bottom:1px solid #b9bdb3;padding-bottom:16px}
+.nav a{padding:10px 14px;text-decoration:none;border:1px solid transparent}
+.nav a:hover{border-color:var(--sapin);background:#e8ede6}
+.hero{display:flex;align-items:center;justify-content:space-between;gap:24px;border-bottom:1px solid #b9bdb3;padding:12px 0 28px;margin-bottom:24px}
+.hero .chapeau{margin-bottom:0}.hero .bouton{flex:none}
+.kicker{color:var(--sapin);font-weight:600;margin:0 0 12px}
+.bouton,button{padding:10px 16px;min-height:44px}
+.bouton:hover{background:#e8ede6}.bouton.principal{margin:0;background:var(--sapin);color:white}
+.bouton.principal:hover{background:#163a2b}
+.sujets{border:0;display:grid;gap:12px;margin:16px 0 28px}
+.sujets li{display:block;border:1px solid #a5afa1;background:#fff;padding:0;position:relative}
+.sujets li:hover{border-color:var(--sapin);background:#fafbf8}
+.sujet-lien{display:block;padding:20px 24px;color:var(--roche);font-family:Outfit,system-ui,sans-serif!important;font-weight:400!important;font-size:16px!important}
+.sujet-lien:focus-visible{outline:3px solid var(--sapin);outline-offset:3px}
+.sujet-titre{display:block;font:600 23px/1.3 Bitter,Georgia,serif;color:var(--sapin);margin:8px 0}
+.sujet-extrait{display:block;margin:10px 0 14px;max-width:80ch}
+.sujet-meta{display:flex;flex-wrap:wrap;gap:4px 20px;color:var(--gris)}
+.bulletin .sujets li{border-left:5px solid var(--sapin);background:#edf1e9}
+.section-intro{color:var(--gris);margin:0 0 16px;max-width:75ch}
+.boite,.fiche{background:white;border:1px solid #a5afa1;padding:24px}
+.vide{padding:24px;border:1px dashed #7b8876;background:#fff}
+.msg{background:white;border:1px solid #a5afa1;margin:16px 0;grid-template-columns:190px minmax(0,1fr)}
+.msg aside{padding:24px 18px;background:#edf1e9}.msg .corps{padding:24px}
+.msg aside b{font-size:18px}.msg .actions{border-top:1px solid var(--pierre);padding-top:12px;margin-top:24px}
+input,textarea,select{padding:12px;border-color:#7b8876}textarea{min-height:190px}
+label{font-weight:600;margin-top:20px}input[type=file]{width:100%;min-width:0}
+input[type=file]::file-selector-button{font:inherit;padding:6px;border:1px solid #7b8876;background:var(--calcaire)}
+.formulaire{max-width:780px}.formulaire .chapeau{font-size:16px}
+.formulaire button{margin-top:24px}.formulaire textarea{min-height:240px}
+.info{border:1px solid #a5afa1;border-left:4px solid var(--sapin);padding:16px 20px}
+.pied{padding:28px max(24px,calc((100% - 1112px)/2));border-top-color:#b9bdb3}
+:focus-visible{outline:3px solid var(--sapin);outline-offset:3px}
+@media(max-width:640px){main{padding:20px 16px 40px}.haut{padding:20px 16px;gap:16px}.haut .moi{width:100%}h1{font-size:32px}h2{font-size:24px}.hero{align-items:stretch;flex-direction:column;gap:16px}.hero .bouton{text-align:center}.nav{gap:4px}.nav a{padding:8px 10px}.sujet-lien{padding:18px}.sujet-titre{font-size:21px}.sujet-meta{display:grid;gap:4px}.boite,.fiche{padding:18px}.msg{grid-template-columns:minmax(0,1fr)}.msg aside,.msg .corps{padding:18px}.haut .gastinel{padding:8px}.grille{grid-template-columns:minmax(0,1fr)}}
+
"""
# Badges : pictogrammes sobres (trait 1,5, angles vifs), couleur du texte du badge. Membre reste en texte seul.
@@ -142,6 +215,18 @@ _PICTOS = {
}
+def servir_police(handler, chemin):
+ nom = chemin.removeprefix("/polices/")
+ if nom not in ("bitter-normal.woff2", "outfit-normal.woff2"):
+ return handler.envoyer(404, "Police introuvable", "text/plain; charset=utf-8")
+ try:
+ with open(os.path.join(os.path.dirname(__file__), "polices", nom), "rb") as fichier:
+ data = fichier.read()
+ except OSError:
+ return handler.envoyer(404, "Police indisponible", "text/plain; charset=utf-8")
+ handler.envoyer(200, data, "font/woff2")
+
+
def e(s):
return html.escape(str(s), quote=True)
@@ -217,7 +302,7 @@ def demandes_html(forum, acteur, csrf=""):
badges = "".join(badge(r, nom) for r, nom in forum.badges(demande["user_id"]))
cartes.append(" %s%s
Motif
" "Extrait du message
" "Ouvrir le message dans le forum
" - % (signalement["post_id"], e(signalement["created_at"][:10]), signalement["topic_id"], + % (signalement["post_id"], e(date_fr(signalement["created_at"])), signalement["topic_id"], e(signalement["reason"]), e(extrait), e(lien), signalement["topic_id"], signalement["post_id"])) return "".join(cartes) or etat_vide("Aucun signalement à examiner.") @@ -365,7 +450,7 @@ class Handler(BaseHTTPRequestHandler): self.send_header("Content-Type", type_) self.send_header("Content-Length", str(len(data))) self.send_header("Content-Security-Policy", - "default-src 'none'; style-src 'unsafe-inline'; img-src 'self'; form-action 'self'; frame-ancestors 'none'") + "default-src 'none'; style-src 'unsafe-inline'; img-src 'self'; font-src 'self'; form-action 'self'; frame-ancestors 'none'") self.send_header("X-Content-Type-Options", "nosniff") self.send_header("Referrer-Policy", "same-origin") for k, v in extra: @@ -390,7 +475,7 @@ class Handler(BaseHTTPRequestHandler): def page(self, titre, contenu, user, code=200, extra=()): f = self.app.forum actif = self.chemin_sans_prefixe(urlparse(self.path).path) - liens = [("/", "Sujets")] + liens = [("/", "Sujets"), ("/stations", "Stations"), ("/profil", "Mon compte" if user is not None else "Se connecter")] if user is None: qui = BOUTON_GASTINEL if self.app.reglages.configuree or self.essai_permis() else ( "Connexion bientôt disponible") @@ -418,7 +503,7 @@ class Handler(BaseHTTPRequestHandler): "