post.php

(开头部分) 12KB

这里只显示每个文件的开头 60 行。登录后可以解锁完整代码。

<?php
require_once __DIR__ . '/core/Session.php';
require_once __DIR__ . '/core/Security.php';
require_once __DIR__ . '/core/Logger.php';
require_once __DIR__ . '/app/models/Post.php';
require_once __DIR__ . '/app/models/Category.php';
require_once __DIR__ . '/app/models/Tag.php';
require_once __DIR__ . '/app/models/Comment.php';
require_once __DIR__ . '/app/models/Setting.php';
require_once __DIR__ . '/app/models/Page.php';

Session::start();

$id = (int)($_GET['id'] ?? 0);
$slug = $_GET['slug'] ?? '';

$postModel = new Post();
$categoryModel = new Category();
$tagModel = new Tag();
$commentModel = new Comment();
$settingModel = new Setting();

if ($slug) {
    $post = $postModel->getPostBySlug($slug);
} else {
    $post = $postModel->getPostWithDetails($id);
}

if (!$post || ($post['status'] !== 'published' && !Session::isAdmin())) {
    header('HTTP/1.0 404 Not Found');
    include '404.php';
    exit;
}

$postModel->incrementViewCount($post['id']);

$settings = $settingModel->getAllSettings();
$categories = $categoryModel->getActiveCategories();
$tags = $tagModel->getTagsForPost($post['id']);
$comments = $commentModel->getCommentTree($post['id']);
$adjacentPosts = $postModel->getAdjacentPosts($post['id']);

$error = '';
$success = Session::getFlash('success');

if ($_SERVER['REQUEST_METHOD'] === 'POST' && ($settings['allow_comment'] ?? 1)) {
    $content = trim($_POST['content'] ?? '');
    $authorName = trim($_POST['author_name'] ?? '');
    $authorEmail = trim($_POST['author_email'] ?? '');
    $authorUrl = trim($_POST['author_url'] ?? '');
    $parentId = (int)($_POST['parent_id'] ?? 0);
    $csrfToken = $_POST['csrf_token'] ?? '';
    
    if (!Security::verifyCSRFToken($csrfToken)) {
        $error = '安全验证失败';
    } elseif (empty($content)) {
        $error = '请输入评论内容';
    } elseif (mb_strlen($content) > 1000) {
        $error = '评论内容不能超过1000字';
    } else {
后面还有 224 行代码,解锁后查看完整代码

24 小时内免费解锁 3 个项目,之后 1 算力/个。 规则说明

AI 解读 AI

登录后可用,每次 10 算力,解读结果公开显示在下面。

还没有人解读过这个文件。