PDO::ERRMODE_EXCEPTION, PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC, ]); // Ensure posts table exists $pdo->exec(" CREATE TABLE IF NOT EXISTS posts ( id INT UNSIGNED AUTO_INCREMENT PRIMARY KEY, title VARCHAR(255) NOT NULL, meta VARCHAR(255) DEFAULT NULL, body TEXT NOT NULL, is_published TINYINT(1) NOT NULL DEFAULT 1, created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4; "); return $pdo; } catch (PDOException $e) { $dbErrorOut = $e->getMessage(); return null; } } // --- Handle login / logout --- if (isset($_GET['logout'])) { unset($_SESSION['mk_admin_logged_in']); header('Location: admin_posts.php'); exit; } if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['login_password'])) { if (hash_equals($adminPassword, $_POST['login_password'])) { $_SESSION['mk_admin_logged_in'] = true; header('Location: admin_posts.php'); exit; } else { $message = 'Invalid admin password.'; } } $loggedIn = !empty($_SESSION['mk_admin_logged_in']); // Connect once logged in and ensure table exists if ($loggedIn) { $pdo = mk_get_pdo_and_bootstrap_admin($dbError); } // --- Handle CRUD actions --- if ($loggedIn && $pdo && $_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['action'])) { if (!hash_equals($csrfToken, $_POST['csrf_token'] ?? '')) { $message = 'Invalid CSRF token.'; } else { $action = $_POST['action']; if ($action === 'create') { $title = trim($_POST['title'] ?? ''); $meta = trim($_POST['meta'] ?? ''); $body = trim($_POST['body'] ?? ''); $is_published = isset($_POST['is_published']) ? 1 : 0; if ($title && $body) { $stmt = $pdo->prepare(" INSERT INTO posts (title, meta, body, is_published) VALUES (:title, :meta, :body, :is_published) "); $stmt->execute([ ':title' => $title, ':meta' => $meta ?: null, ':body' => $body, ':is_published' => $is_published, ]); $message = 'Post created.'; } else { $message = 'Title and body are required.'; } } if ($action === 'update') { $id = (int)($_POST['id'] ?? 0); $title = trim($_POST['title'] ?? ''); $meta = trim($_POST['meta'] ?? ''); $body = trim($_POST['body'] ?? ''); $is_published = isset($_POST['is_published']) ? 1 : 0; if ($id > 0 && $title && $body) { $stmt = $pdo->prepare(" UPDATE posts SET title = :title, meta = :meta, body = :body, is_published = :is_published WHERE id = :id LIMIT 1 "); $stmt->execute([ ':id' => $id, ':title' => $title, ':meta' => $meta ?: null, ':body' => $body, ':is_published' => $is_published, ]); $message = "Post #{$id} updated."; } else { $message = 'Title and body are required.'; } } } } // Handle delete via GET (with CSRF) if ($loggedIn && $pdo && isset($_GET['delete'], $_GET['token'])) { if (hash_equals($csrfToken, $_GET['token'])) { $id = (int)$_GET['delete']; if ($id > 0) { $stmt = $pdo->prepare("DELETE FROM posts WHERE id = :id LIMIT 1"); $stmt->execute([':id' => $id]); $message = "Post #{$id} deleted."; } } else { $message = 'Invalid CSRF token for delete.'; } } // Fetch posts + maybe a single post to edit $posts = []; $editPost = null; if ($loggedIn && $pdo) { // List $stmt = $pdo->query(" SELECT id, title, meta, is_published, created_at FROM posts ORDER BY created_at DESC, id DESC "); $posts = $stmt->fetchAll(); // Edit if (isset($_GET['edit'])) { $id = (int)$_GET['edit']; if ($id > 0) { $stmt = $pdo->prepare(" SELECT id, title, meta, body, is_published FROM posts WHERE id = :id LIMIT 1 "); $stmt->execute([':id' => $id]); $editPost = $stmt->fetch(); } } } ?> Mediakor — Admin Posts

Mediakor Admin

Command Feed • Login

Mediakor Admin

Manage posts that power the Command Feed on your homepage.
Logged in as Operator
← View Site · Logout
DB Error:

/>

Existing Posts

No posts found yet. Create one using the form on the left.

ID Title Meta State Created Actions
Published Hidden Edit Delete