117 lines
3.7 KiB
PHP
117 lines
3.7 KiB
PHP
<?php
|
|
session_start();
|
|
|
|
if (isset($_GET['action']) && $_GET['action'] === 'delete' && isset($_GET['id'])) {
|
|
$id = $_GET['id'];
|
|
if (isset($_SESSION['news'][$id])) {
|
|
unset($_SESSION['news'][$id]);
|
|
}
|
|
header('Location: display.php');
|
|
exit;
|
|
}
|
|
?>
|
|
|
|
<!DOCTYPE html>
|
|
<html lang="zh-CN">
|
|
<head>
|
|
<meta charset="UTF-8">
|
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
<title>新闻列表 - 2025</title>
|
|
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css" rel="stylesheet">
|
|
<style>
|
|
:root {
|
|
--primary-color: #2c3e50;
|
|
--secondary-color: #3498db;
|
|
--danger-color: #e74c3c;
|
|
}
|
|
|
|
.news-card {
|
|
transition: transform 0.3s ease, box-shadow 0.3s ease;
|
|
border: none;
|
|
border-radius: 12px;
|
|
background: linear-gradient(145deg, #ffffff, #f8f9fa);
|
|
box-shadow: 0 4px 6px rgba(0, 0, 0, 0.05);
|
|
}
|
|
|
|
.news-card:hover {
|
|
transform: translateY(-5px);
|
|
box-shadow: 0 8px 15px rgba(0, 0, 0, 0.1);
|
|
}
|
|
|
|
.category-badge {
|
|
background-color: var(--secondary-color);
|
|
color: white;
|
|
padding: 5px 12px;
|
|
border-radius: 20px;
|
|
font-size: 0.9em;
|
|
}
|
|
|
|
.delete-btn {
|
|
transition: all 0.3s ease;
|
|
color: var(--danger-color);
|
|
border: 2px solid var(--danger-color);
|
|
padding: 5px 15px;
|
|
border-radius: 25px;
|
|
text-decoration: none;
|
|
}
|
|
|
|
.delete-btn:hover {
|
|
background-color: var(--danger-color);
|
|
color: white;
|
|
}
|
|
|
|
.time-stamp {
|
|
color: #95a5a6;
|
|
font-size: 0.9em;
|
|
}
|
|
</style>
|
|
</head>
|
|
<body>
|
|
<nav class="navbar navbar-dark bg-primary">
|
|
<div class="container">
|
|
<a class="navbar-brand" href="#">Placeholder</a>
|
|
<div class="d-flex">
|
|
<a href="submit.php" class="text-white me-3">发布新闻</a>
|
|
<a href="display.php" class="text-white">查看新闻</a>
|
|
</div>
|
|
</div>
|
|
</nav>
|
|
|
|
<div class="container py-5" style="max-width: 1000px;">
|
|
<h1 class="mb-4 fw-bold text-primary">最新新闻</h1>
|
|
|
|
<?php if(empty($_SESSION['news'])): ?>
|
|
<div class="alert alert-info">
|
|
暂无新闻,<a href="submit.php" class="alert-link">点击发布第一条新闻</a>
|
|
</div>
|
|
<?php else: ?>
|
|
<div class="row g-4">
|
|
<?php foreach ($_SESSION['news'] as $id => $news): ?>
|
|
<div class="col-12">
|
|
<div class="news-card p-4">
|
|
<div class="d-flex justify-content-between align-items-start mb-3">
|
|
<h3 class="mb-0 fw-bold"><?= htmlspecialchars($news['title']) ?></h3>
|
|
<a href="?action=delete&id=<?= $id ?>" class="delete-btn">删除</a>
|
|
</div>
|
|
<p class="text-muted mb-3"><?= nl2br(htmlspecialchars($news['content'])) ?></p>
|
|
<div class="d-flex flex-wrap gap-2 align-items-center">
|
|
<span class="category-badge"><?= htmlspecialchars($news['category']) ?></span>
|
|
<span class="time-stamp ms-auto"><?= $news['time'] ?></span>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
<?php endforeach; ?>
|
|
</div>
|
|
<?php endif; ?>
|
|
</div>
|
|
|
|
<footer class="bg-light text-center py-3 mt-5">
|
|
<div class="container">
|
|
<span class="text-muted">© 2025 @Theresa.ltd</span>
|
|
</div>
|
|
</footer>
|
|
|
|
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/js/bootstrap.bundle.min.js"></script>
|
|
</body>
|
|
</html>
|