From d5bf3072f4f0e62c66e66368b47da209df5801cb Mon Sep 17 00:00:00 2001 From: Cedric Abonnel Date: Tue, 12 May 2026 23:53:09 +0200 Subject: [PATCH] =?UTF-8?q?feat:=20bio=20profil=20+=20URL=20publique=20pr?= =?UTF-8?q?=C3=A9-remplie=20dans=20/profile?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- database/migration_004_profile_bio.sql | 1 + public/assets/css/style.css | 6 ++++++ public/index.php | 18 +++++++++++++----- src/auth.php | 5 +++-- templates/author_profile.php | 6 +++++- templates/profile.php | 19 +++++++++++++++---- 6 files changed, 43 insertions(+), 12 deletions(-) create mode 100644 database/migration_004_profile_bio.sql diff --git a/database/migration_004_profile_bio.sql b/database/migration_004_profile_bio.sql new file mode 100644 index 0000000..0b96126 --- /dev/null +++ b/database/migration_004_profile_bio.sql @@ -0,0 +1 @@ +ALTER TABLE user_profiles ADD COLUMN IF NOT EXISTS bio TEXT NOT NULL DEFAULT ''; diff --git a/public/assets/css/style.css b/public/assets/css/style.css index c4a13b1..d6c446b 100644 --- a/public/assets/css/style.css +++ b/public/assets/css/style.css @@ -1277,3 +1277,9 @@ footer.mt-5 { margin-top: 0 !important; } } .author-profile-link:hover { color: var(--vl-accent); } + +.author-profile-bio { + max-width: 56rem; + color: var(--vl-muted); + line-height: 1.7; +} diff --git a/public/index.php b/public/index.php index d2d88bb..cb0b85d 100644 --- a/public/index.php +++ b/public/index.php @@ -1809,6 +1809,7 @@ switch ($action) { if ($newUrl !== '' && !filter_var($newUrl, FILTER_VALIDATE_URL)) { $newUrl = ''; } + $newBio = trim($_POST['bio'] ?? ''); if ($newName === '') { $profileError = 'Le nom ne peut pas être vide.'; } else { @@ -1817,11 +1818,11 @@ switch ($action) { try { $newSlug = slugify($newName); $st = $pdo->prepare( - 'INSERT INTO user_profiles (email, display_name, profile_url, profile_slug, updated_at) - VALUES (:e, :n, :u, :s, now()) - ON CONFLICT (email) DO UPDATE SET display_name = :n, profile_url = :u, profile_slug = :s, updated_at = now()' + 'INSERT INTO user_profiles (email, display_name, profile_url, profile_slug, bio, updated_at) + VALUES (:e, :n, :u, :s, :b, now()) + ON CONFLICT (email) DO UPDATE SET display_name = :n, profile_url = :u, profile_slug = :s, bio = :b, updated_at = now()' ); - $st->execute([':e' => currentUserEmail(), ':n' => $newName, ':u' => $newUrl, ':s' => $newSlug]); + $st->execute([':e' => currentUserEmail(), ':n' => $newName, ':u' => $newUrl, ':s' => $newSlug, ':b' => $newBio]); $_SESSION['user_display_name'] = $newName; $profileSuccess = true; } catch (\Throwable $ex) { @@ -1831,7 +1832,14 @@ switch ($action) { } } $profileCurrentName = currentUserName(); - $profileCurrentUrl = authorProfileUrl(currentUserEmail() ?? ''); + $_profileData = authorProfile(currentUserEmail() ?? ''); + $profileCurrentUrl = $_profileData['url']; + $profileCurrentBio = $_profileData['bio']; + $profileCurrentSlug = $_profileData['slug']; + // Pré-remplir l'URL avec l'URL de profil public si vide + if ($profileCurrentUrl === '' && $profileCurrentSlug !== '') { + $profileCurrentUrl = rtrim(APP_URL, '/') . '/profil/' . rawurlencode($profileCurrentSlug); + } include BASE_PATH . '/templates/profile.php'; break; diff --git a/src/auth.php b/src/auth.php index 5fe42e8..a4efb25 100644 --- a/src/auth.php +++ b/src/auth.php @@ -57,7 +57,7 @@ function authorProfile(string $email): array $pdo = dbPdo(); if ($pdo) { try { - $st = $pdo->prepare('SELECT display_name, profile_url, profile_slug FROM user_profiles WHERE email = :e'); + $st = $pdo->prepare('SELECT display_name, profile_url, profile_slug, bio FROM user_profiles WHERE email = :e'); $st->execute([':e' => $key]); $row = $st->fetch(PDO::FETCH_ASSOC); if ($row) { @@ -65,6 +65,7 @@ function authorProfile(string $email): array 'name' => ($row['display_name'] !== '') ? $row['display_name'] : explode('@', $key)[0], 'url' => $row['profile_url'] ?? '', 'slug' => $row['profile_slug'] ?? '', + 'bio' => $row['bio'] ?? '', ]; return $cache[$key]; } @@ -90,7 +91,7 @@ function profileBySlug(string $slug): ?array return null; } try { - $st = $pdo->prepare('SELECT email, display_name, profile_url, profile_slug FROM user_profiles WHERE profile_slug = :s'); + $st = $pdo->prepare('SELECT email, display_name, profile_url, profile_slug, bio FROM user_profiles WHERE profile_slug = :s'); $st->execute([':s' => $slug]); $row = $st->fetch(PDO::FETCH_ASSOC); return $row ?: null; diff --git a/templates/author_profile.php b/templates/author_profile.php index 956ceac..86fc875 100644 --- a/templates/author_profile.php +++ b/templates/author_profile.php @@ -7,10 +7,11 @@ ob_start(); $_apName = $authorRow['display_name'] ?? ''; $_apUrl = $authorRow['profile_url'] ?? ''; $_apSlug = $authorRow['profile_slug'] ?? ''; +$_apBio = $authorRow['bio'] ?? ''; $_initials = mb_strtoupper(mb_substr($_apName, 0, 1, 'UTF-8'), 'UTF-8'); ?> -
+

@@ -21,6 +22,9 @@ $_initials = mb_strtoupper(mb_substr($_apName, 0, 1, 'UTF-8'), 'UTF-8');
+ +

+

Aucun article publié.

diff --git a/templates/profile.php b/templates/profile.php index 4da7669..66819fb 100644 --- a/templates/profile.php +++ b/templates/profile.php @@ -22,15 +22,26 @@ class="form-control" value="" placeholder="Prénom Nom" required> -
Affiché comme auteur sur vos articles.
+
+ Affiché comme auteur sur vos articles. + + Page publique : /profil/ + +
- + + +
Affichée sur votre page de profil public.
+
+
+ -
Utilisée dans les métadonnées de vos articles (article:author, JSON-LD).
+
Lien vers un site ou profil externe (utilisé dans les métadonnées article:author, JSON-LD).