feat: 添加开发者社交链接功能和管理员系统信息页面

- 在developers表中添加social_links字段用于存储开发者社交链接
- 新增开发者个人资料编辑页面(profile.php)
- 在开发者应用页面展示社交链接
- 新增管理员系统信息页面(system_info.php)用于管理上传文件
- 更新导航菜单添加相关功能入口
- 修复平台图标显示问题并优化Font Awesome引用方式
This commit is contained in:
2025-07-08 12:40:13 +08:00
parent 06c8f549d3
commit b4b96a444b
8 changed files with 431 additions and 14 deletions

View File

@@ -80,6 +80,9 @@ if (!$resultApps) {
<li class="nav-item">
<a class="nav-link" href="manage_developers.php">管理开发者</a>
</li>
<li class="nav-item">
<a class="nav-link" href="system_info.php">系统信息</a>
</li>
<li class="nav-item">
<a class="nav-link" href="?logout=true">退出登录</a>
</li>

194
admin/system_info.php Normal file
View File

@@ -0,0 +1,194 @@
<?php
session_start();
require_once '../config.php';
// 删除文件
function delete_file($file_path) {
if (file_exists($file_path)) {
return unlink($file_path);
}
return false;
}
// 处理删除请求
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
$upload_dirs = [
'../uploads/apps',
'../uploads/images'
];
// 全量删除
if (isset($_POST['delete_all'])) {
foreach ($upload_dirs as $dir) {
if (is_dir($dir)) {
$files = scandir($dir);
foreach ($files as $file) {
if ($file !== '.' && $file !== '..') {
$file_path = $dir . '/' . $file;
if (is_file($file_path)) {
delete_file($file_path);
}
}
}
}
}
header('Location: ' . $_SERVER['PHP_SELF']);
exit;
}
// 单个删除
if (isset($_POST['delete_files'])) {
foreach ($_POST['delete_files'] as $file_info) {
list($type, $filename) = explode('|', $file_info);
$dir = $type === '图片' ? '../uploads/images' : '../uploads/apps';
$file_path = $dir . '/' . $filename;
delete_file($file_path);
}
header('Location: ' . $_SERVER['PHP_SELF']);
exit;
}
}
// 验证管理员权限
if (!isset($_SESSION['admin'])) {
header('Location: login.php');
exit;
}
// 获取上传文件和图片信息
function get_uploaded_files_info() {
$uploaded_files = [];
// 上传目录配置
$upload_dirs = [
'../uploads/apps',
'../uploads/images'
];
foreach ($upload_dirs as $dir) {
if (is_dir($dir)) {
$files = scandir($dir);
foreach ($files as $file) {
if ($file !== '.' && $file !== '..') {
$file_path = $dir . '/' . $file;
if (is_file($file_path)) {
$file_size = filesize($file_path);
$uploaded_files[] = [
'name' => $file,
'size' => $file_size,
'type' => strpos($dir, 'images') !== false ? '图片' : '文件'
];
}
}
}
}
}
return $uploaded_files;
}
$uploaded_files = get_uploaded_files_info();
?>
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>系统信息 - 上传文件列表</title>
<!-- Bootstrap CSS -->
<link href="../css/bootstrap.min.css" rel="stylesheet">
<!-- 自定义CSS -->
<link rel="stylesheet" href="../styles.css">
</head>
<body>
<!-- 导航栏 -->
<nav class="navbar navbar-expand-lg navbar-light bg-light">
<div class="container">
<a class="navbar-brand" href="index.php">管理员面板</a>
<button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="navbarNav" aria-controls="navbarNav" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse" id="navbarNav">
<ul class="navbar-nav">
<li class="nav-item">
<a class="nav-link" href="index.php">首页</a>
</li>
<li class="nav-item">
<a class="nav-link" href="system_info.php">系统信息</a>
</li>
</ul>
</div>
</div>
</nav>
<div class="container mt-4">
<form method="post">
<h2>上传文件信息</h2>
<table class="table table-striped">
<thead>
<tr>
<th><input type="checkbox" id="selectAll"></th>
<th>文件名</th>
<th>大小</th>
</tr>
</thead>
<tbody>
<?php foreach ($uploaded_files as $file): ?>
<?php if ($file['type'] === '文件'): ?>
<tr>
<td><input type="checkbox" name="delete_files[]" value="<?php echo $file['type'] . '|' . $file['name']; ?>"></td>
<td><?php echo htmlspecialchars($file['name']); ?></td>
<td><?php echo round($file['size'] / 1024, 2); ?> KB</td>
</tr>
<?php endif; ?>
<?php endforeach; ?>
</tbody>
</table>
<h2>上传图片信息</h2>
<table class="table table-striped">
<thead>
<tr>
<th><input type="checkbox" id="selectAllImages"></th>
<th>文件名</th>
<th>大小</th>
</tr>
</thead>
<tbody>
<?php foreach ($uploaded_files as $file): ?>
<?php if ($file['type'] === '图片'): ?>
<tr>
<td><input type="checkbox" name="delete_files[]" value="<?php echo $file['type'] . '|' . $file['name']; ?>"></td>
<td><?php echo htmlspecialchars($file['name']); ?></td>
<td><?php echo round($file['size'] / 1024, 2); ?> KB</td>
</tr>
<?php endif; ?>
<?php endforeach; ?>
</tbody>
</table>
<button type="submit" name="delete_all" class="btn btn-danger" onclick="return confirm('确定要删除所有文件吗?')">全量删除</button>
<button type="submit" class="btn btn-danger ms-2" onclick="return confirm('确定要删除选中的文件吗?')">删除选中</button>
</form>
</div>
</form>
</div>
<!-- Bootstrap JS Bundle with Popper -->
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/js/bootstrap.bundle.min.js"></script>
<script>
document.getElementById('selectAll').addEventListener('change', function() {
const checkboxes = document.querySelectorAll('input[name="delete_files[]"]');
checkboxes.forEach(checkbox => {
checkbox.checked = this.checked;
});
});
document.getElementById('selectAllImages').addEventListener('change', function() {
const checkboxes = document.querySelectorAll('input[name="delete_files[]"]');
checkboxes.forEach(checkbox => {
checkbox.checked = this.checked;
});
});
</script>
</body>
</html>

14
app.php
View File

@@ -65,7 +65,7 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['rating'])) {
<!-- Bootstrap CSS -->
<link href="css/bootstrap.min.css" rel="stylesheet">
<!-- Font Awesome -->
<link rel="stylesheet" href="css/all.min.css">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css">
<!-- 本地 Chart.js -->
<script src="js/charts.js"></script>
<!-- 自定义CSS -->
@@ -116,11 +116,11 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['rating'])) {
<p>适用平台: <?php
$platforms = json_decode($app['platforms'], true) ?? [];
$platformIcons = [
'Windows' => '<i class="fab fa-windows"></i>',
'Mac' => '<i class="fab fa-apple"></i>',
'Linux' => '<i class="fab fa-linux"></i>',
'Android' => '<i class="fab fa-android"></i>',
'iOS' => '<i class="fab fa-app-store-ios"></i>'
'windows' => '<i class="fab fa-windows"></i>',
'macos' => '<i class="fab fa-apple"></i>',
'linux' => '<i class="fab fa-linux"></i>',
'android' => '<i class="fab fa-android"></i>',
'ios' => '<i class="fab fa-app-store-ios"></i>'
];
$platformMap = [
'android' => 'Android',
@@ -134,7 +134,7 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['rating'])) {
$platformTexts = [];
foreach ($platforms as $platform) {
$icon = $platformIcons[ucfirst($platform)] ?? '';
$icon = $platformIcons[strtolower($platform)] ?? '';
$readableName = $platformMap[strtolower($platform)] ?? ucfirst($platform);
$platformTexts[] = $icon . ' ' . $readableName;
}

View File

@@ -198,6 +198,10 @@ EXECUTE stmt;
DEALLOCATE PREPARE stmt;
SET @exist_fk = (SELECT COUNT(*) FROM INFORMATION_SCHEMA.KEY_COLUMN_USAGE WHERE TABLE_SCHEMA = DATABASE() AND TABLE_NAME = 'apps' AND COLUMN_NAME = 'developer_id' AND CONSTRAINT_NAME = 'fk_apps_developers');
-- 添加 social_links 字段到 developers 表
ALTER TABLE developers
ADD COLUMN social_links VARCHAR(255) DEFAULT '' AFTER password;
SET @sql = IF(@exist_fk = 0, 'ALTER TABLE apps ADD CONSTRAINT fk_apps_developers FOREIGN KEY (developer_id) REFERENCES developers(id) ON DELETE SET NULL', 'SELECT 1');
PREPARE stmt FROM @sql;
EXECUTE stmt;

3
app_store_update.sql Normal file
View File

@@ -0,0 +1,3 @@
-- 添加 social_links 字段到 developers 表
ALTER TABLE developers
ADD COLUMN social_links VARCHAR(255) DEFAULT '' AFTER password;

View File

@@ -145,11 +145,14 @@ if (!($conn instanceof mysqli)) {
<a class="nav-link active" aria-current="page" href="dashboard.php">应用仪表盘</a>
</li>
<li class="nav-item">
<a class="nav-link" href="upload_app.php">上传应用</a>
</li>
<li class="nav-item">
<a class="nav-link" href="logout.php">退出登录</a>
</li>
<a class="nav-link" href="upload_app.php">上传应用</a>
</li>
<li class="nav-item">
<a class="nav-link" href="profile.php">更改信息</a>
</li>
<li class="nav-item">
<a class="nav-link" href="logout.php">退出登录</a>
</li>
</ul>
</div>
</div>

189
developer/profile.php Normal file
View File

@@ -0,0 +1,189 @@
<?php
// 引入配置文件
require_once '../config.php';
session_start();
// 检查开发者是否已登录
if (!isset($_SESSION['developer_id'])) {
header('Location: login.php');
exit;
}
$developerId = $_SESSION['developer_id'];
$error = '';
$success = '';
// 检查数据库连接是否为 MySQLi 对象
if (!($conn instanceof mysqli)) {
log_error('数据库连接错误: 连接不是MySQLi实例', __FILE__, __LINE__);
$error = '数据库连接错误,请检查配置';
} else {
// 获取开发者信息
$stmt = $conn->prepare('SELECT username, email, social_links FROM developers WHERE id = ?');
if (!$stmt) {
log_error('获取开发者信息查询准备失败: ' . $conn->error, __FILE__, __LINE__);
$error = '获取开发者信息时发生错误,请稍后再试';
} else {
$stmt->bind_param('i', $developerId);
if (!$stmt->execute()) {
log_error('获取开发者信息查询执行失败: ' . $stmt->error, __FILE__, __LINE__);
$error = '获取开发者信息时发生错误,请稍后再试';
} else {
$result = $stmt->get_result();
$developer = $result->fetch_assoc();
}
}
// 处理表单提交
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
$newUsername = trim($_POST['username']);
$newEmail = trim($_POST['email']);
$newPassword = $_POST['password'];
$newSocialLinks = trim($_POST['social_links']);
// 更新用户名和邮箱
$stmt = $conn->prepare('UPDATE developers SET username = ?, email = ?, social_links = ? WHERE id = ?');
if (!$stmt) {
log_error('更新开发者信息查询准备失败: ' . $conn->error, __FILE__, __LINE__);
$error = '更新信息时发生错误,请稍后再试';
} else {
$stmt->bind_param('sssi', $newUsername, $newEmail, $newSocialLinks, $developerId);
if (!$stmt->execute()) {
log_error('更新开发者信息查询执行失败: ' . $stmt->error, __FILE__, __LINE__);
$error = '更新信息时发生错误,请稍后再试';
} else {
// 更新密码
if (!empty($newPassword)) {
$hashedPassword = password_hash($newPassword, PASSWORD_DEFAULT);
$stmt = $conn->prepare('UPDATE developers SET password = ? WHERE id = ?');
if (!$stmt) {
log_error('更新密码查询准备失败: ' . $conn->error, __FILE__, __LINE__);
$error = '更新密码时发生错误,请稍后再试';
} else {
$stmt->bind_param('si', $hashedPassword, $developerId);
if (!$stmt->execute()) {
log_error('更新密码查询执行失败: ' . $stmt->error, __FILE__, __LINE__);
$error = '更新密码时发生错误,请稍后再试';
}
}
}
if (empty($error)) {
$success = '信息更新成功';
$_SESSION['developer_username'] = $newUsername;
// 重新获取开发者信息
$stmt = $conn->prepare('SELECT username, email, social_links FROM developers WHERE id = ?');
if ($stmt) {
$stmt->bind_param('i', $developerId);
if ($stmt->execute()) {
$result = $stmt->get_result();
$developer = $result->fetch_assoc();
}
}
}
}
}
}
}
?>
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>开发者信息 - <?php echo APP_STORE_NAME; ?></title>
<!-- Bootstrap CSS -->
<link href="../css/bootstrap.min.css" rel="stylesheet">
<!-- 自定义CSS -->
<link rel="stylesheet" href="../styles.css">
<style>
body {
font-family: Arial, sans-serif;
background-color: #f4f4f4;
margin: 0;
padding: 20px;
}
.profile-container {
max-width: 800px;
margin: 0 auto;
background-color: #fff;
padding: 20px;
border-radius: 5px;
box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
}
h1 {
text-align: center;
}
.form-group {
margin-bottom: 1rem;
}
.error {
color: red;
}
.success {
color: green;
}
</style>
</head>
<body>
<!-- 导航栏 -->
<nav class="navbar navbar-expand-lg navbar-light blur-bg">
<div class="container">
<a class="navbar-brand" href="../index.php"><?php echo APP_STORE_NAME; ?></a>
<button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarNav" aria-controls="navbarNav" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse" id="navbarNav">
<ul class="navbar-nav">
<li class="nav-item">
<a class="nav-link" href="dashboard.php">应用仪表盘</a>
</li>
<li class="nav-item">
<a class="nav-link" href="upload_app.php">上传应用</a>
</li>
<li class="nav-item">
<a class="nav-link" href="logout.php">退出登录</a>
</li>
<li class="nav-item">
<a class="nav-link active" href="profile.php">开发者信息</a>
</li>
</ul>
</div>
</div>
</nav>
<div class="profile-container mt-4">
<?php if (!empty($error)): ?>
<div class="error"><?php echo $error; ?></div>
<?php endif; ?>
<?php if (!empty($success)): ?>
<div class="success"><?php echo $success; ?></div>
<?php endif; ?>
<h1>开发者信息</h1>
<form method="post">
<div class="form-group">
<label for="username">用户名</label>
<input type="text" class="form-control" id="username" name="username" value="<?php echo htmlspecialchars($developer['username']); ?>" placeholder="请输入用户名">
</div>
<button type="submit" class="btn btn-primary">保存更改</button>
?>" required>
</div>
<div class="form-group">
<label for="email">邮箱</label>
<input type="email" class="form-control" id="email" name="email" value="<?php echo htmlspecialchars($developer['email']); ?>" required>
</div>
<div class="form-group">
<label for="password">新密码 (留空则不修改)</label>
<input type="password" class="form-control" id="password" name="password">
</div>
<div class="form-group">
<label for="social_links">社交媒体链接 (多个链接用逗号分隔)</label>
<input type="text" class="form-control" id="social_links" name="social_links" value="<?php echo htmlspecialchars($developer['social_links']); ?>" placeholder="请输入社交媒体链接,多个链接用逗号分隔">
</div>
<button type="submit" class="btn btn-primary">保存更改</button>
</form>
</div>
</body>
</html>

View File

@@ -11,7 +11,7 @@ if (!isset($_GET['id']) || !is_numeric($_GET['id'])) {
$developerId = intval($_GET['id']);
// 获取开发者信息
$sqlDeveloper = "SELECT username FROM developers WHERE id = $developerId";
$sqlDeveloper = "SELECT username, social_links FROM developers WHERE id = $developerId";
$resultDeveloper = $conn->query($sqlDeveloper);
$developer = $resultDeveloper->fetch_assoc();
@@ -40,7 +40,7 @@ $resultApps = $conn->query($sqlApps);
<!-- Bootstrap CSS -->
<link href="css/bootstrap.min.css" rel="stylesheet">
<!-- Font Awesome -->
<link rel="stylesheet" href="css/all.min.css">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css">
<!-- 自定义CSS -->
<link rel="stylesheet" href="styles.css">
<!-- Fluent Design 模糊效果 -->
@@ -96,6 +96,27 @@ $resultApps = $conn->query($sqlApps);
</div>
<h1><?php echo $developerName; ?> 的应用</h1>
<hr>
<?php if (isset($developer['social_links']) && !empty($developer['social_links'])): ?>
<div class="mb-4">
<h5>开发者链接</h5>
<div class="d-flex flex-wrap gap-2">
<?php
$socialLinks = explode(',', $developer['social_links']);
foreach ($socialLinks as $link):
$link = trim($link);
if (!empty($link)):
?>
<a href="<?php echo htmlspecialchars($link); ?>" target="_blank" class="btn btn-outline-primary btn-sm">
<i class="fas fa-link me-1"></i>
<?php echo parse_url($link, PHP_URL_HOST) ?: $link; ?>
</a>
<?php
endif;
endforeach;
?>
</div>
</div>
<?php endif; ?>
<?php if ($resultApps && $resultApps->num_rows > 0): ?>
<div class="row">