feat: clean URLs + fix addFileMeta silent failure
This commit is contained in:
@@ -11,6 +11,35 @@ 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]
|
||||
|
||||
# Édition / création
|
||||
RewriteRule ^edit/([0-9a-f-]{36})/?$ /index.php?action=edit&uuid=$1 [L,QSA]
|
||||
RewriteRule ^new/?$ /index.php?action=create [L,QSA]
|
||||
RewriteRule ^delete/([0-9a-f-]{36})/?$ /index.php?action=delete&uuid=$1 [L,QSA]
|
||||
|
||||
# Sources et diff
|
||||
RewriteRule ^sources/([0-9a-f-]{36})/?$ /index.php?action=sources&uuid=$1 [L,QSA]
|
||||
RewriteRule ^diff/([0-9a-f-]{36})/(\d+)/?$ /index.php?action=diff&uuid=$1&rev=$2 [L,QSA]
|
||||
|
||||
# Fichiers / import
|
||||
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 avant la règle générique admin/<tab>)
|
||||
RewriteRule ^admin/regen-thumbs/?$ /index.php?action=regen_thumbs [L,QSA]
|
||||
RewriteRule ^admin/([a-z0-9-]+)/?$ /index.php?action=admin&tab=$1 [L,QSA]
|
||||
RewriteRule ^admin/?$ /index.php?action=admin [L,QSA]
|
||||
|
||||
# Pages de gestion
|
||||
RewriteRule ^categories/?$ /index.php?action=categories [L,QSA]
|
||||
RewriteRule ^profile/?$ /index.php?action=profile [L,QSA]
|
||||
RewriteRule ^search/?$ /index.php?action=search [L,QSA]
|
||||
|
||||
# Pages statiques
|
||||
RewriteRule ^about/?$ /index.php?action=about [L,QSA]
|
||||
RewriteRule ^legal/?$ /index.php?action=legal [L,QSA]
|
||||
RewriteRule ^licenses/?$ /index.php?action=licenses [L,QSA]
|
||||
RewriteRule ^contact/?$ /index.php?action=contact [L,QSA]
|
||||
|
||||
# Flux RSS — /feed, /rss et /rss.xml pointent tous vers feed.php
|
||||
RewriteRule ^feed/?$ /feed.php [L,QSA]
|
||||
RewriteRule ^rss/?$ /feed.php [L,QSA]
|
||||
|
||||
+52
-29
@@ -463,7 +463,7 @@ switch ($action) {
|
||||
}
|
||||
}
|
||||
|
||||
$formAction = '/?action=create';
|
||||
$formAction = '/new';
|
||||
$action = 'create';
|
||||
include BASE_PATH . '/templates/post_form.php';
|
||||
break;
|
||||
@@ -637,7 +637,7 @@ switch ($action) {
|
||||
}
|
||||
}
|
||||
|
||||
$formAction = '/?action=edit&uuid=' . rawurlencode($uuid);
|
||||
$formAction = '/edit/' . rawurlencode($uuid);
|
||||
$action = 'edit';
|
||||
$existingFiles = $articles->getFiles($uuid);
|
||||
$insertUrl = '';
|
||||
@@ -653,7 +653,7 @@ switch ($action) {
|
||||
if ($uuid !== '' && $fileName !== '' && $fileName[0] !== '.') {
|
||||
$articles->deleteFile($uuid, $fileName);
|
||||
}
|
||||
header('Location: /?action=edit&uuid=' . rawurlencode($uuid));
|
||||
header('Location: /edit/' . rawurlencode($uuid));
|
||||
exit;
|
||||
|
||||
case 'delete':
|
||||
@@ -664,6 +664,30 @@ switch ($action) {
|
||||
header('Location: /');
|
||||
exit;
|
||||
|
||||
case 'delete_revision':
|
||||
requireAuth();
|
||||
if (!isAdmin()) {
|
||||
http_response_code(403);
|
||||
exit;
|
||||
}
|
||||
if ($uuid !== '' && isset($_POST['rev_n'])) {
|
||||
$articles->deleteRevision($uuid, (int)$_POST['rev_n']);
|
||||
}
|
||||
header('Location: /edit/' . rawurlencode($uuid) . '#historyPanel');
|
||||
exit;
|
||||
|
||||
case 'delete_all_revisions':
|
||||
requireAuth();
|
||||
if (!isAdmin()) {
|
||||
http_response_code(403);
|
||||
exit;
|
||||
}
|
||||
if ($uuid !== '') {
|
||||
$articles->deleteAllRevisions($uuid);
|
||||
}
|
||||
header('Location: /edit/' . rawurlencode($uuid));
|
||||
exit;
|
||||
|
||||
case 'categories':
|
||||
requireAuth();
|
||||
$cats = $articles->getCategories();
|
||||
@@ -680,7 +704,7 @@ switch ($action) {
|
||||
$articles->renameCategory($old, $new);
|
||||
}
|
||||
}
|
||||
header('Location: /?action=categories');
|
||||
header('Location: /categories');
|
||||
exit;
|
||||
|
||||
case 'delete_category':
|
||||
@@ -691,7 +715,7 @@ switch ($action) {
|
||||
$articles->deleteCategory($cat);
|
||||
}
|
||||
}
|
||||
header('Location: /?action=categories');
|
||||
header('Location: /categories');
|
||||
exit;
|
||||
|
||||
case 'toggle_private_category':
|
||||
@@ -702,7 +726,7 @@ switch ($action) {
|
||||
$articles->togglePrivateCategory($cat);
|
||||
}
|
||||
}
|
||||
header('Location: /?action=categories');
|
||||
header('Location: /categories');
|
||||
exit;
|
||||
|
||||
case 'about':
|
||||
@@ -740,7 +764,7 @@ switch ($action) {
|
||||
}
|
||||
}
|
||||
if ($revIndex === null || $revN < 1) {
|
||||
header('Location: /?action=edit&uuid=' . rawurlencode($uuid));
|
||||
header('Location: /edit/' . rawurlencode($uuid));
|
||||
exit;
|
||||
}
|
||||
$oldContent = $articles->getRevisionContent($uuid, $revN);
|
||||
@@ -789,7 +813,7 @@ switch ($action) {
|
||||
]);
|
||||
}
|
||||
}
|
||||
header('Location: /?action=edit&uuid=' . rawurlencode($uuid));
|
||||
header('Location: /edit/' . rawurlencode($uuid));
|
||||
exit;
|
||||
}
|
||||
include BASE_PATH . '/templates/add_files.php';
|
||||
@@ -816,7 +840,7 @@ switch ($action) {
|
||||
case 'import_image_step2':
|
||||
requireAuth();
|
||||
if ($_SERVER['REQUEST_METHOD'] !== 'POST') {
|
||||
header('Location: /?action=import_image&uuid=' . rawurlencode($uuid));
|
||||
header('Location: /import/' . rawurlencode($uuid));
|
||||
exit;
|
||||
}
|
||||
$step2Article = $articles->getByUuid($uuid);
|
||||
@@ -827,12 +851,12 @@ switch ($action) {
|
||||
}
|
||||
$step2Url = trim($_POST['image_url'] ?? '');
|
||||
if (!filter_var($step2Url, FILTER_VALIDATE_URL) || !preg_match('#^https?://#i', $step2Url)) {
|
||||
header('Location: /?action=import_image&uuid=' . rawurlencode($uuid) . '&error=1');
|
||||
header('Location: /import/' . rawurlencode($uuid) . '?error=1');
|
||||
exit;
|
||||
}
|
||||
$step2Meta = fetchUrlMeta($step2Url);
|
||||
if (!($step2Meta['ok'] ?? false)) {
|
||||
header('Location: /?action=import_image&uuid=' . rawurlencode($uuid) . '&error=1');
|
||||
header('Location: /import/' . rawurlencode($uuid) . '?error=1');
|
||||
exit;
|
||||
}
|
||||
// Capture d'écran pour prévisualisation (pages HTML uniquement)
|
||||
@@ -862,7 +886,7 @@ switch ($action) {
|
||||
$ackUrl = filter_var($_GET['image_url'] ?? '', FILTER_VALIDATE_URL)
|
||||
? $_GET['image_url'] : '';
|
||||
if ($ackUrl === '') {
|
||||
header('Location: /?action=import_image&uuid=' . rawurlencode($uuid));
|
||||
header('Location: /import/' . rawurlencode($uuid));
|
||||
exit;
|
||||
}
|
||||
$ackTitle = $_GET['img_title'] ?? '';
|
||||
@@ -903,7 +927,7 @@ switch ($action) {
|
||||
|
||||
$urlArticle = $articles->getByUuid($urlUuid);
|
||||
if (!$urlArticle || $imageUrl === '' || !filter_var($imageUrl, FILTER_VALIDATE_URL)) {
|
||||
header('Location: /?action=import_image&uuid=' . rawurlencode($urlUuid));
|
||||
header('Location: /import/' . rawurlencode($urlUuid));
|
||||
exit;
|
||||
}
|
||||
|
||||
@@ -911,13 +935,13 @@ switch ($action) {
|
||||
|
||||
if ($mode === 'screenshot') {
|
||||
if ($screenshotFile === '' || $screenshotFile !== '_preview.png') {
|
||||
header('Location: /?action=import_image&uuid=' . rawurlencode($urlUuid) . '&error=1');
|
||||
header('Location: /import/' . rawurlencode($urlUuid) . '?error=1');
|
||||
exit;
|
||||
}
|
||||
$filesDir = BASE_PATH . '/data/' . $urlUuid . '/files';
|
||||
$previewPath = $filesDir . '/' . $screenshotFile;
|
||||
if (!file_exists($previewPath)) {
|
||||
header('Location: /?action=import_image&uuid=' . rawurlencode($urlUuid) . '&error=1');
|
||||
header('Location: /import/' . rawurlencode($urlUuid) . '?error=1');
|
||||
exit;
|
||||
}
|
||||
$hash = substr(hash_file('sha256', $previewPath), 0, 16);
|
||||
@@ -928,7 +952,7 @@ switch ($action) {
|
||||
if ($isCover) {
|
||||
$articles->setCover($urlUuid, $destName);
|
||||
}
|
||||
header('Location: /?action=edit&uuid=' . rawurlencode($urlUuid));
|
||||
header('Location: /edit/' . rawurlencode($urlUuid));
|
||||
exit;
|
||||
}
|
||||
|
||||
@@ -993,7 +1017,7 @@ switch ($action) {
|
||||
@unlink($filesDir . '/' . $screenshotFile);
|
||||
}
|
||||
$articles->addExternalLink($urlUuid, $imageUrl, $imgTitle, $imgAuthor, $importedMeta);
|
||||
header('Location: /?action=edit&uuid=' . rawurlencode($urlUuid));
|
||||
header('Location: /edit/' . rawurlencode($urlUuid));
|
||||
exit;
|
||||
}
|
||||
|
||||
@@ -1013,9 +1037,9 @@ switch ($action) {
|
||||
|
||||
$imported = $articles->addFileFromUrl($urlUuid, $imageUrl, $isCover, $imgAuthor, $imgSource, $imgTitle, $importedMeta);
|
||||
if ($imported) {
|
||||
header('Location: /?action=edit&uuid=' . rawurlencode($urlUuid));
|
||||
header('Location: /edit/' . rawurlencode($urlUuid));
|
||||
} else {
|
||||
header('Location: /?action=import_image&uuid=' . rawurlencode($urlUuid) . '&error=1&mode=download');
|
||||
header('Location: /import/' . rawurlencode($urlUuid) . '?error=1&mode=download');
|
||||
}
|
||||
exit;
|
||||
|
||||
@@ -1044,8 +1068,7 @@ switch ($action) {
|
||||
ob_start();
|
||||
?>
|
||||
<h1 class="h4 mb-4">Génération des aperçus de liens</h1>
|
||||
<form method="get" action="/">
|
||||
<input type="hidden" name="action" value="regen_thumbs">
|
||||
<form method="get" action="/admin/regen-thumbs">
|
||||
<input type="hidden" name="run" value="1">
|
||||
<div class="card p-4 mb-4" style="max-width:480px">
|
||||
<div class="form-check mb-3">
|
||||
@@ -1195,7 +1218,7 @@ switch ($action) {
|
||||
echo $done . ' capturé' . ($done > 1 ? 's' : '') . ', ';
|
||||
echo $fail . ' échec' . ($fail > 1 ? 's' : '') . ', ';
|
||||
echo $skip . ' ignoré' . ($skip > 1 ? 's' : '') . '.</p>';
|
||||
echo '<a href="/?action=regen_thumbs" class="btn btn-secondary btn-sm">← Retour</a>';
|
||||
echo '<a href="/admin/regen-thumbs" class="btn btn-secondary btn-sm">← Retour</a>';
|
||||
echo '</body></html>';
|
||||
exit;
|
||||
|
||||
@@ -1207,7 +1230,7 @@ switch ($action) {
|
||||
$articles->removeExternalLink($uuid, $linkUrl);
|
||||
}
|
||||
}
|
||||
header('Location: /?action=edit&uuid=' . rawurlencode($uuid));
|
||||
header('Location: /edit/' . rawurlencode($uuid));
|
||||
exit;
|
||||
|
||||
case 'rate':
|
||||
@@ -1368,7 +1391,7 @@ switch ($action) {
|
||||
$st->execute([':email' => $targetEmail, ':role' => $roleName, ':by' => currentUserEmail()]);
|
||||
}
|
||||
}
|
||||
header('Location: /?action=admin&tab=users');
|
||||
header('Location: /admin/users');
|
||||
exit;
|
||||
|
||||
case 'admin_revoke_role':
|
||||
@@ -1390,7 +1413,7 @@ switch ($action) {
|
||||
$st->execute([':email' => $targetEmail, ':role' => $roleName]);
|
||||
}
|
||||
}
|
||||
header('Location: /?action=admin&tab=users');
|
||||
header('Location: /admin/users');
|
||||
exit;
|
||||
|
||||
case 'admin_create_role':
|
||||
@@ -1411,7 +1434,7 @@ switch ($action) {
|
||||
}
|
||||
}
|
||||
}
|
||||
header('Location: /?action=admin&tab=roles');
|
||||
header('Location: /admin/roles');
|
||||
exit;
|
||||
|
||||
case 'admin_update_role':
|
||||
@@ -1429,7 +1452,7 @@ switch ($action) {
|
||||
$st->execute([':l' => $roleLabel, ':id' => $roleId]);
|
||||
}
|
||||
}
|
||||
header('Location: /?action=admin&tab=roles');
|
||||
header('Location: /admin/roles');
|
||||
exit;
|
||||
|
||||
case 'admin_delete_role':
|
||||
@@ -1446,7 +1469,7 @@ switch ($action) {
|
||||
$st->execute([':id' => $roleId]);
|
||||
}
|
||||
}
|
||||
header('Location: /?action=admin&tab=roles');
|
||||
header('Location: /admin/roles');
|
||||
exit;
|
||||
|
||||
case 'admin_update_role_caps':
|
||||
@@ -1469,7 +1492,7 @@ switch ($action) {
|
||||
unset($_SESSION['user_capabilities']);
|
||||
}
|
||||
}
|
||||
header('Location: /?action=admin&tab=roles');
|
||||
header('Location: /admin/roles');
|
||||
exit;
|
||||
|
||||
case 'profile':
|
||||
|
||||
@@ -2,10 +2,6 @@
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
if (session_status() !== PHP_SESSION_ACTIVE) {
|
||||
session_start();
|
||||
}
|
||||
|
||||
require_once dirname(__DIR__, 2) . '/vendor/autoload.php';
|
||||
require_once dirname(__DIR__, 2) . '/bootstrap.php';
|
||||
require_once dirname(__DIR__, 2) . '/config/config.php';
|
||||
@@ -29,7 +25,7 @@ $debug = (env('APP_DEBUG', '0') === '1');
|
||||
$OIDC_ISSUER = rtrim((string)(env('OIDC_ISSUER') ?? ''), '/');
|
||||
$OIDC_CLIENT_ID = (string)(env('OIDC_CLIENT_ID') ?? '');
|
||||
$OIDC_CLIENT_SECRET = (string)(env('OIDC_CLIENT_SECRET') ?? '');
|
||||
$OIDC_REDIRECT_URI = (string)(env('OIDC_REDIRECT_URI') ?: url('oidc/callback.php'));
|
||||
$OIDC_REDIRECT_URI = (string)(env('OIDC_REDIRECT_URI') ?: url('oidc/callback'));
|
||||
|
||||
if (!$OIDC_ISSUER || !$OIDC_CLIENT_ID || !$OIDC_REDIRECT_URI) {
|
||||
http_response_code(500);
|
||||
|
||||
@@ -4,10 +4,6 @@
|
||||
// version : 20251005
|
||||
declare(strict_types=1);
|
||||
|
||||
if (session_status() !== PHP_SESSION_ACTIVE) {
|
||||
session_start();
|
||||
}
|
||||
|
||||
require_once dirname(__DIR__, 2) . '/vendor/autoload.php';
|
||||
require_once dirname(__DIR__, 2) . '/bootstrap.php';
|
||||
require_once dirname(__DIR__, 2) . '/config/config.php';
|
||||
|
||||
@@ -2,10 +2,6 @@
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
if (session_status() !== PHP_SESSION_ACTIVE) {
|
||||
session_start();
|
||||
}
|
||||
|
||||
require_once dirname(__DIR__, 2) . '/vendor/autoload.php';
|
||||
require_once dirname(__DIR__, 2) . '/bootstrap.php';
|
||||
require_once dirname(__DIR__, 2) . '/config/config.php';
|
||||
|
||||
Reference in New Issue
Block a user