-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtopic_pin_toggle.php
More file actions
39 lines (30 loc) · 1.02 KB
/
Copy pathtopic_pin_toggle.php
File metadata and controls
39 lines (30 loc) · 1.02 KB
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
<?php
declare(strict_types = 1);
ini_set('display_errors', '1');
ini_set('display_startup_errors', '1');
error_reporting(E_ALL);
if (session_status() !== PHP_SESSION_ACTIVE) session_start();
require_once __DIR__ . '/includes/db.php';
require_once __DIR__ . '/includes/auth.php';
$user = auth_require($conn, ['admin']); // role-gated
$topicId = (int)($_POST['topic_id'] ?? 0);
$csrf = (string)($_POST['csrf_token'] ?? '');
if ($topicId <= 0) { http_response_code(400); exit('Bad request'); }
if (empty($_SESSION['csrf_token']) || !hash_equals($_SESSION['csrf_token'], $csrf)) {
http_response_code(403);
exit('CSRF failed');
}
$stmt = $conn->prepare("
UPDATE forum_topics
SET is_pinned = IF(is_pinned = 1, 0, 1),
pinned_at = IF(is_pinned = 1, NULL, NOW())
WHERE id = ?
LIMIT 1
");
if (!$stmt) { http_response_code(500); exit('DB error: '.$conn->error); }
$stmt->bind_param("i", $topicId);
$stmt->execute();
$stmt->close();
$back = $_SERVER['HTTP_REFERER'] ?? '/index.php';
header("Location: " . $back);
exit;