108 lines
4.8 KiB
PHP
108 lines
4.8 KiB
PHP
<?php
|
|
$article_id = $_GET['id'];
|
|
$stmt = $pdo->prepare("SELECT * FROM articles WHERE id = ?");
|
|
$stmt->execute([$article_id]);
|
|
$article = $stmt->fetch();
|
|
?>
|
|
<!DOCTYPE html>
|
|
<html lang="zh">
|
|
<!-- TODO: Markdown渲染,文章美化 -->
|
|
<head>
|
|
<meta charset="UTF-8">
|
|
<meta charset="UTF-8">
|
|
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=5.0, shrink-to-fit=no">
|
|
<meta http-equiv="x-ua-compatible" content="ie=edge">
|
|
<meta name="theme-color" content="#2f4154">
|
|
<meta name="author" content="mei">
|
|
<meta name="keywords" content="油二黑子站,油田二中黑子站,东营市胜利第二中学,东营市油田二中,东营市胜利第二中学黑子站,东营市油田二中黑子站,二中,油田二中,林七二中">
|
|
<meta name="description" content="油二学生搭建的非官方综合服务及吐槽平台 - https://ez.mei.lv">
|
|
<meta property="og:type" content="website">
|
|
<meta property="og:title" content="<?php echo "{$article['title']} - 油田二中黑子站"; ?>">
|
|
<meta property="og:url" content="https://ez.mei.lv/index.php">
|
|
<meta property="og:site_name" content="油二黑子站">
|
|
<meta property="og:description" content="油二学生搭建的非官方综合服务及吐槽平台 - https://ez.mei.lv">
|
|
<meta property="og:locale" content="zh_CN">
|
|
<meta property="article:author" content="mei">
|
|
<meta property="article:tag" content="油二黑子站,油田二中黑子站,东营市胜利第二中学,东营市油田二中,东营市胜利第二中学黑子站,东营市油田二中黑子站,二中,油田二中,林七二中">
|
|
<meta name="twitter:card" content="summary_large_image">
|
|
<title><?php echo "{$article['title']} - 油田二中黑子站"; ?></title>
|
|
<link rel="stylesheet" href="style.css">
|
|
<link rel="stylesheet" href="/assets/css/article.min.css">
|
|
<link rel="stylesheet" href="<?php echo $icon_font;?>">
|
|
<?php echo $umami;?>
|
|
</head>
|
|
|
|
<body>
|
|
<nav>
|
|
<a href="/">
|
|
<strong class="logo">油二黑子站</strong>
|
|
</a>
|
|
<ul>
|
|
<li><a href="/?page=home">首页</a></li>
|
|
<li><a href="/?page=account">账户</a></li>
|
|
<li><a href="/?page=admin">管理</a></li>
|
|
<li><a href="/?page=love">表白墙</a></li>
|
|
</ul>
|
|
</nav>
|
|
<div class="container">
|
|
<?php
|
|
echo "<h2>{$article['title']}</h2>";
|
|
echo "<center><small>发布于: {$article['created_at']}</small></center>";
|
|
echo "<center><small>分类: {$article_type[$article['type']]}</small><hr></center>";
|
|
echo "<p>{$article['content']}</p>";
|
|
?>
|
|
<!-- TODO: 回复评论 -->
|
|
<h2 class="comment">评论区</h2>
|
|
<div id="comments">
|
|
<?php
|
|
$commentStmt = $pdo->prepare("SELECT comments.content, users.username FROM comments JOIN users ON comments.user_id = users.id WHERE article_id = ? ORDER BY comments.created_at DESC");
|
|
$commentStmt->execute([$article_id]);
|
|
while ($comment = $commentStmt->fetch()) {
|
|
echo "<div class='comment'><strong>{$comment['username']}:</strong> {$comment['content']}</div>";
|
|
}
|
|
?>
|
|
</div>
|
|
|
|
<?php if (isset($_SESSION['user_id'])): ?>
|
|
<form method="POST" id="commentForm" action="/?api=submit_comment">
|
|
<textarea name="commentContent" placeholder="发表评论..." required></textarea>
|
|
<button type="submit">评论</button>
|
|
</form>
|
|
<?php else: ?>
|
|
<p>请<a href="?page=account">登录</a>后发表评论。</p>
|
|
<?php endif; ?>
|
|
</div>
|
|
|
|
<script>
|
|
document.getElementById('commentForm').addEventListener('submit', function (event) {
|
|
event.preventDefault(); // 防止表单默认提交
|
|
|
|
var formData = new FormData(this);
|
|
formData.append('article_id', <?php echo $article_id; ?>); // 添加文章 ID
|
|
|
|
fetch('/?api=submit_comment', {
|
|
method: 'POST',
|
|
body: formData
|
|
})
|
|
.then(response => response.text())
|
|
.then(data => {
|
|
// 清空文本框
|
|
this.querySelector('textarea[name="commentContent"]').value = '';
|
|
// 暴力刷新
|
|
location.replace(location.href);
|
|
})
|
|
.catch(error => console.error('Error:', error));
|
|
});
|
|
|
|
function loadComments(articleId) {
|
|
fetch('/?api=load_comments.php?&article_id=' + articleId)
|
|
.then(response => response.text())
|
|
.then(data => {
|
|
document.getElementById('comments').innerHTML = data;
|
|
})
|
|
.catch(error => console.error('Error:', error));
|
|
}
|
|
</script>
|
|
</body>
|
|
|
|
</html>
|