diff --git a/database/migration_002_profile_url.sql b/database/migration_002_profile_url.sql new file mode 100644 index 0000000..b9b4421 --- /dev/null +++ b/database/migration_002_profile_url.sql @@ -0,0 +1 @@ +ALTER TABLE user_profiles ADD COLUMN IF NOT EXISTS profile_url TEXT NOT NULL DEFAULT ''; diff --git a/public/index.php b/public/index.php index 9a61996..fb052bb 100644 --- a/public/index.php +++ b/public/index.php @@ -1775,6 +1775,10 @@ switch ($action) { $profileSuccess = false; if ($_SERVER['REQUEST_METHOD'] === 'POST') { $newName = trim($_POST['display_name'] ?? ''); + $newUrl = trim($_POST['profile_url'] ?? ''); + if ($newUrl !== '' && !filter_var($newUrl, FILTER_VALIDATE_URL)) { + $newUrl = ''; + } if ($newName === '') { $profileError = 'Le nom ne peut pas être vide.'; } else { @@ -1782,11 +1786,11 @@ switch ($action) { if ($pdo) { try { $st = $pdo->prepare( - 'INSERT INTO user_profiles (email, display_name, updated_at) - VALUES (:e, :n, now()) - ON CONFLICT (email) DO UPDATE SET display_name = :n, updated_at = now()' + 'INSERT INTO user_profiles (email, display_name, profile_url, updated_at) + VALUES (:e, :n, :u, now()) + ON CONFLICT (email) DO UPDATE SET display_name = :n, profile_url = :u, updated_at = now()' ); - $st->execute([':e' => currentUserEmail(), ':n' => $newName]); + $st->execute([':e' => currentUserEmail(), ':n' => $newName, ':u' => $newUrl]); $_SESSION['user_display_name'] = $newName; $profileSuccess = true; } catch (\Throwable $ex) { @@ -1796,6 +1800,7 @@ switch ($action) { } } $profileCurrentName = currentUserName(); + $profileCurrentUrl = authorProfileUrl(currentUserEmail() ?? ''); include BASE_PATH . '/templates/profile.php'; break; diff --git a/src/auth.php b/src/auth.php index bf9c99a..97a39ed 100644 --- a/src/auth.php +++ b/src/auth.php @@ -35,11 +35,21 @@ function currentUserName(): string } function authorDisplayName(string $email): string +{ + return authorProfile($email)['name']; +} + +function authorProfileUrl(string $email): string +{ + return authorProfile($email)['url']; +} + +function authorProfile(string $email): array { static $cache = []; $key = strtolower(trim($email)); if ($key === '') { - return ''; + return ['name' => '', 'url' => '']; } if (array_key_exists($key, $cache)) { return $cache[$key]; @@ -47,15 +57,20 @@ function authorDisplayName(string $email): string $pdo = dbPdo(); if ($pdo) { try { - $st = $pdo->prepare('SELECT display_name FROM user_profiles WHERE email = :e'); + $st = $pdo->prepare('SELECT display_name, profile_url FROM user_profiles WHERE email = :e'); $st->execute([':e' => $key]); - $name = $st->fetchColumn(); - $cache[$key] = ($name !== false && $name !== '') ? $name : explode('@', $key)[0]; - return $cache[$key]; + $row = $st->fetch(PDO::FETCH_ASSOC); + if ($row) { + $cache[$key] = [ + 'name' => ($row['display_name'] !== '') ? $row['display_name'] : explode('@', $key)[0], + 'url' => $row['profile_url'] ?? '', + ]; + return $cache[$key]; + } } catch (\Throwable) { } } - $cache[$key] = explode('@', $key)[0]; + $cache[$key] = ['name' => explode('@', $key)[0], 'url' => '']; return $cache[$key]; } diff --git a/templates/layout.php b/templates/layout.php index d7e7d4f..b3f319e 100644 --- a/templates/layout.php +++ b/templates/layout.php @@ -28,7 +28,9 @@ - + + + diff --git a/templates/post_view.php b/templates/post_view.php index 4ec505a..0e6493d 100644 --- a/templates/post_view.php +++ b/templates/post_view.php @@ -43,8 +43,9 @@ $externalLinks = $article['external_links'] ?? [];
Privé
$canonical, 'datePublished' => date('c', strtotime((string)$articlePublishedAt)), 'dateModified' => date('c', strtotime((string)($article['updated_at'] ?? $articlePublishedAt))), - 'author' => ['@type' => 'Person', 'name' => $metaAuthor !== '' ? $metaAuthor : (siteAuthor() !== '' ? siteAuthor() : siteTitle())], + 'author' => array_filter([ + '@type' => 'Person', + 'name' => $metaAuthor !== '' ? $metaAuthor : (siteAuthor() !== '' ? siteAuthor() : siteTitle()), + 'url' => $metaAuthorUrl !== '' ? $metaAuthorUrl : null, + ]), 'publisher' => [ '@type' => 'Person', 'name' => siteAuthor() !== '' ? siteAuthor() : siteTitle(), diff --git a/templates/profile.php b/templates/profile.php index bd749ab..4da7669 100644 --- a/templates/profile.php +++ b/templates/profile.php @@ -24,6 +24,14 @@ placeholder="Prénom Nom" required>
Affiché comme auteur sur vos articles.
+
+ + +
Utilisée dans les métadonnées de vos articles (article:author, JSON-LD).
+