新闻发布
This commit is contained in:
parent
ada18eb162
commit
80ef98ed7e
116
display.php
Normal file
116
display.php
Normal file
@ -0,0 +1,116 @@
|
||||
<?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>
|
220
news.php
Normal file
220
news.php
Normal file
@ -0,0 +1,220 @@
|
||||
<?php
|
||||
session_start();
|
||||
|
||||
// 初始化新闻存储数组
|
||||
if (!isset($_SESSION['news'])) {
|
||||
$_SESSION['news'] = [];
|
||||
}
|
||||
|
||||
// 处理删除请求
|
||||
if (isset($_GET['action']) && $_GET['action'] === 'delete' && isset($_GET['id'])) {
|
||||
$id = $_GET['id'];
|
||||
if (isset($_SESSION['news'][$id])) {
|
||||
unset($_SESSION['news'][$id]);
|
||||
}
|
||||
header('Location: ' . $_SERVER['PHP_SELF']);
|
||||
exit;
|
||||
}
|
||||
|
||||
// 处理表单提交
|
||||
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
||||
$title = trim($_POST['title'] ?? '');
|
||||
$content = trim($_POST['content'] ?? '');
|
||||
$categories = $_POST['categories'] ?? [];
|
||||
|
||||
if (!empty($title) && !empty($content) && !empty($categories)) {
|
||||
$id = uniqid();
|
||||
$_SESSION['news'][$id] = [
|
||||
'title' => $title,
|
||||
'content' => $content,
|
||||
'categories' => $categories,
|
||||
'time' => date('Y-m-d H:i:s')
|
||||
];
|
||||
}
|
||||
}
|
||||
?>
|
||||
|
||||
<!DOCTYPE html>
|
||||
<html lang="zh-CN">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>新闻发布系统</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;
|
||||
--success-color: #27ae60;
|
||||
--danger-color: #e74c3c;
|
||||
}
|
||||
|
||||
body {
|
||||
background-color: #f8f9fa;
|
||||
min-height: 100vh;
|
||||
}
|
||||
|
||||
.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;
|
||||
}
|
||||
|
||||
.main-container {
|
||||
max-width: 800px;
|
||||
margin: 0 auto;
|
||||
padding: 2rem;
|
||||
}
|
||||
|
||||
.time-stamp {
|
||||
color: #95a5a6;
|
||||
font-size: 0.9em;
|
||||
}
|
||||
|
||||
.gradient-header {
|
||||
background: linear-gradient(135deg, var(--primary-color), var(--secondary-color));
|
||||
color: white;
|
||||
padding: 2rem;
|
||||
border-radius: 12px;
|
||||
margin-bottom: 2rem;
|
||||
}
|
||||
|
||||
.form-control-custom {
|
||||
border: 2px solid #e0e0e0;
|
||||
border-radius: 8px;
|
||||
padding: 12px;
|
||||
transition: border-color 0.3s ease;
|
||||
}
|
||||
|
||||
.form-control-custom:focus {
|
||||
border-color: var(--secondary-color);
|
||||
box-shadow: none;
|
||||
}
|
||||
|
||||
.form-check-label {
|
||||
user-select: none;
|
||||
}
|
||||
|
||||
.submit-btn {
|
||||
background-color: var(--success-color);
|
||||
color: white;
|
||||
padding: 12px 30px;
|
||||
border: none;
|
||||
border-radius: 25px;
|
||||
font-weight: bold;
|
||||
transition: transform 0.2s ease;
|
||||
}
|
||||
|
||||
.submit-btn:hover {
|
||||
transform: scale(1.05);
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<nav class="navbar navbar-dark bg-primary">
|
||||
<div class="container">
|
||||
<a class="navbar-brand" href="#">新闻发布系统</a>
|
||||
</div>
|
||||
</nav>
|
||||
|
||||
<div class="main-container">
|
||||
<div class="gradient-header text-center">
|
||||
<h1>发布新闻</h1>
|
||||
<p class="mb-0">分享最新资讯</p>
|
||||
</div>
|
||||
|
||||
<form method="post" class="bg-white p-4 rounded-3 shadow-sm mb-5">
|
||||
<div class="mb-4">
|
||||
<label class="form-label fw-bold">标题</label>
|
||||
<input type="text" name="title" class="form-control form-control-custom" required>
|
||||
</div>
|
||||
|
||||
<div class="mb-4">
|
||||
<label class="form-label fw-bold">内容</label>
|
||||
<textarea name="content" class="form-control form-control-custom" rows="4" required></textarea>
|
||||
</div>
|
||||
|
||||
<div class="mb-4">
|
||||
<label class="form-label fw-bold">选择类别</label>
|
||||
<div class="d-flex flex-wrap gap-3">
|
||||
<div class="form-check">
|
||||
<input class="form-check-input" type="checkbox" name="categories[]" value="科技" id="tech">
|
||||
<label class="form-check-label" for="tech">科技</label>
|
||||
</div>
|
||||
<div class="form-check">
|
||||
<input class="form-check-input" type="checkbox" name="categories[]" value="体育" id="sports">
|
||||
<label class="form-check-label" for="sports">体育</label>
|
||||
</div>
|
||||
<div class="form-check">
|
||||
<input class="form-check-input" type="checkbox" name="categories[]" value="娱乐" id="entertainment">
|
||||
<label class="form-check-label" for="entertainment">娱乐</label>
|
||||
</div>
|
||||
<div class="form-check">
|
||||
<input class="form-check-input" type="checkbox" name="categories[]" value="财经" id="finance">
|
||||
<label class="form-check-label" for="finance">财经</label>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="text-center">
|
||||
<button type="submit" class="submit-btn">发布新闻</button>
|
||||
</div>
|
||||
</form>
|
||||
|
||||
<h2 class="mb-4 fw-bold text-primary">最新动态</h2>
|
||||
|
||||
<?php foreach ($_SESSION['news'] as $id => $news): ?>
|
||||
<div class="news-card mb-4 p-4">
|
||||
<div class="d-flex justify-content-between align-items-start mb-3">
|
||||
<h3 class="mb-0 fw-bold"><?php echo htmlspecialchars($news['title']); ?></h3>
|
||||
<a href="?action=delete&id=<?php echo $id; ?>" class="delete-btn">删除</a>
|
||||
</div>
|
||||
<p class="text-muted mb-3"><?php echo nl2br(htmlspecialchars($news['content'])); ?></p>
|
||||
<div class="d-flex flex-wrap gap-2 align-items-center">
|
||||
<?php foreach ($news['categories'] as $category): ?>
|
||||
<span class="category-badge"><?php echo htmlspecialchars($category); ?></span>
|
||||
<?php endforeach; ?>
|
||||
<span class="time-stamp ms-auto"><?php echo $news['time']; ?></span>
|
||||
</div>
|
||||
</div>
|
||||
<?php endforeach; ?>
|
||||
</div>
|
||||
|
||||
<footer class="bg-light text-center py-3 mt-5">
|
||||
<div class="container">
|
||||
<span class="text-muted">© 2023 新闻发布系统 版权所有</span>
|
||||
</div>
|
||||
</footer>
|
||||
|
||||
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/js/bootstrap.bundle.min.js"></script>
|
||||
</body>
|
||||
</html>
|
156
submit.php
Normal file
156
submit.php
Normal file
@ -0,0 +1,156 @@
|
||||
<?php
|
||||
session_start();
|
||||
|
||||
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
||||
$title = trim($_POST['title'] ?? '');
|
||||
$content = trim($_POST['content'] ?? '');
|
||||
$category = $_POST['category'] ?? '';
|
||||
|
||||
if (!empty($title) && !empty($content) && !empty($category)) {
|
||||
$id = uniqid();
|
||||
$_SESSION['news'][$id] = [
|
||||
'title' => $title,
|
||||
'content' => $content,
|
||||
'category' => $category,
|
||||
'time' => date('Y-m-d H:i:s')
|
||||
];
|
||||
$success = true;
|
||||
} else {
|
||||
$error = true;
|
||||
}
|
||||
}
|
||||
?>
|
||||
|
||||
<!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;
|
||||
--success-color: #27ae60;
|
||||
--danger-color: #e74c3c;
|
||||
}
|
||||
|
||||
body {
|
||||
background-color: #f8f9fa;
|
||||
min-height: 100vh;
|
||||
}
|
||||
|
||||
.gradient-header {
|
||||
background: linear-gradient(135deg, var(--primary-color), var(--secondary-color));
|
||||
color: white;
|
||||
padding: 2rem;
|
||||
border-radius: 12px;
|
||||
margin-bottom: 2rem;
|
||||
}
|
||||
|
||||
.form-control-custom {
|
||||
border: 2px solid #e0e0e0;
|
||||
border-radius: 8px;
|
||||
padding: 12px;
|
||||
transition: border-color 0.3s ease;
|
||||
}
|
||||
|
||||
.submit-btn {
|
||||
background-color: var(--success-color);
|
||||
color: white;
|
||||
padding: 12px 30px;
|
||||
border: none;
|
||||
border-radius: 25px;
|
||||
font-weight: bold;
|
||||
transition: transform 0.2s ease;
|
||||
}
|
||||
|
||||
.alert-message {
|
||||
position: fixed;
|
||||
top: 20px;
|
||||
right: 20px;
|
||||
z-index: 1000;
|
||||
animation: slideIn 0.3s ease-out;
|
||||
}
|
||||
|
||||
@keyframes slideIn {
|
||||
from { transform: translateX(100%); }
|
||||
to { transform: translateX(0); }
|
||||
}
|
||||
</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: 800px;">
|
||||
<?php if(isset($success)): ?>
|
||||
<div class="alert alert-success alert-message">
|
||||
新闻发布成功!<a href="display.php" class="alert-link">查看新闻</a>
|
||||
</div>
|
||||
<?php elseif(isset($error)): ?>
|
||||
<div class="alert alert-danger alert-message">
|
||||
请填写所有必填字段!
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
|
||||
<div class="gradient-header text-center">
|
||||
<h1>发布新闻</h1>
|
||||
<p class="mb-0">分享2025最新资讯</p>
|
||||
</div>
|
||||
|
||||
<form method="post" class="bg-white p-4 rounded-3 shadow-sm">
|
||||
<div class="mb-4">
|
||||
<label class="form-label fw-bold">新闻标题</label>
|
||||
<input type="text" name="title" class="form-control form-control-custom" required>
|
||||
</div>
|
||||
|
||||
<div class="mb-4">
|
||||
<label class="form-label fw-bold">新闻内容</label>
|
||||
<textarea name="content" class="form-control form-control-custom" rows="5" required></textarea>
|
||||
</div>
|
||||
|
||||
<div class="mb-4">
|
||||
<label class="form-label fw-bold">新闻类别</label>
|
||||
<div class="d-flex flex-wrap gap-3">
|
||||
<?php foreach(['A', 'B', 'C', 'D'] as $type): ?>
|
||||
<div class="form-check">
|
||||
<input class="form-check-input" type="radio" name="category"
|
||||
value="<?= $type ?>" id="<?= $type ?>" required>
|
||||
<label class="form-check-label" for="<?= $type ?>"><?= $type ?></label>
|
||||
</div>
|
||||
<?php endforeach; ?>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="text-center mt-4">
|
||||
<button type="submit" class="submit-btn">立即发布</button>
|
||||
</div>
|
||||
</form>
|
||||
</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>
|
||||
<script>
|
||||
// 自动隐藏提示信息
|
||||
setTimeout(() => {
|
||||
document.querySelectorAll('.alert-message').forEach(alert => {
|
||||
alert.remove();
|
||||
});
|
||||
}, 5000);
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
Loading…
Reference in New Issue
Block a user