forked from perdedora/nicochan
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdelete.php
69 lines (62 loc) · 2.01 KB
/
delete.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
<?php
require_once 'inc/bootstrap.php';
$isJson = (isset($_GET['format']) && $_GET['format'] === 'json') ||
(isset($_SERVER['HTTP_ACCEPT']) && strpos($_SERVER['HTTP_ACCEPT'], 'application/json') !== false);
$post = isset($_GET['post']) && ctype_digit($_GET['post']) ? (int) $_GET['post'] : false;
$board = isset($_GET['board']) && preg_match('/^[\w]+$/', $_GET['board']) ? (string) $_GET['board'] : false;
$num_files = isset($_GET['nf']) && ctype_digit($_GET['nf']) ? (int) $_GET['nf'] : -1;
if (!$post) {
if ($isJson) {
header('Content-Type: application/json');
echo json_encode(['status' => 'error', 'message' => _('Post not found')]);
} else {
header('HTTP/1.1 400 Bad Request');
error(_('Post not found'));
}
exit;
}
if (!$board || !openBoard($board)) {
if ($isJson) {
header('Content-Type: application/json');
echo json_encode(['status' => 'error', 'message' => _('Invalid board!')]);
} else {
header('HTTP/1.1 400 Bad Request');
error(_('Invalid board!'));
}
exit;
}
if ($num_files > $config['max_images']) {
if ($isJson) {
header('Content-Type: application/json');
echo json_encode(['status' => 'error', 'message' => _('Invalid request')]);
} else {
header('HTTP/1.1 400 Bad Request');
error(_('Invalid request'));
}
exit;
}
$title = sprintf(_("Deleting Post %d from %s"), htmlspecialchars($post), $board['url']);
$body = Element('delete.html', [
'post' => $post,
'num_files' => $num_files,
'board' => $board,
'json' => $isJson,
'delete_file' => $num_files === -1 ? false : true,
'title' => $title,
'config' => $config
]);
if ($isJson) {
header('Content-Type: application/json');
$response = json_encode([
'status' => 'success',
'body' => $body
]);
echo $response;
} else {
echo Element('page.html', [
'config' => $config,
'body' => $body,
'title' => $title,
'boardlist' => createBoardlist()
]);
}