feat: clean URLs + fix addFileMeta silent failure
This commit is contained in:
+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':
|
||||
|
||||
Reference in New Issue
Block a user