postModel = new PostModel(); $this->tagModel = new TagModel(); } // Control panel index page public function index() { if (!isAdmin()) { header('Location: ' . HOME_DIRECTORY . 'index.php?url=auth/login'); exit; } $postsPerPage = MAX_POSTS_PER_PAGE; if ($postsPerPage < 1) { $postsPerPage = 5; // fallback } // Get the current page $page = isset($_GET['page']) ? (int)$_GET['page'] : 1; if ($page < 1) { $page = 1; } $totalPosts = $this->postModel->countAll(); $totalPages = ceil($totalPosts / $postsPerPage); if ($totalPages < 1) { $totalPages = 1; } $offset = ($page - 1) * $postsPerPage; $posts = $this->postModel->getPaginated($offset, $postsPerPage); $this->view->render('admin/index.php', [ 'posts' => $posts, 'totalPages' => $totalPages, 'currentPage' => $page ]); } // Creating new post // controllers/AdminController.php public function create() { if (!isAdmin()) { die("Access denied"); } if ($_SERVER['REQUEST_METHOD'] === 'POST') { $title = $_POST['title'] ?? ''; $content = $_POST['content'] ?? ''; $tags = $_POST['tags'] ?? ''; // Date handling $created_at_input = $_POST['created_at'] ?? ''; // Если админ ничего не ввёл, мы передадим null => модель сама подставит текущую дату // Если ввёл, преобразуем к формату Y-m-d H:i:s $created_at = null; if (!empty($created_at_input)) { $created_at = date('Y-m-d H:i:s', strtotime($created_at_input)); } // TODO: move allowed tags to the config file $allowed_tags = '