-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathdiscussion.php
More file actions
173 lines (159 loc) · 13 KB
/
discussion.php
File metadata and controls
173 lines (159 loc) · 13 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
<?php
session_start();
$dt = null;
if (isset($_SESSION['responseBody'])) {
$dt = is_string($_SESSION['responseBody']) ? json_decode($_SESSION['responseBody'], true) : $_SESSION['responseBody'];
} else {
$redirectUrl = '/getv.php?r=discussion.php';
if (!headers_sent()) {
header('Location: ' . $redirectUrl);
exit;
} else {
// 如果已经有输出,使用JavaScript重定向作为备用
echo '<script>window.location.href = "' . $redirectUrl . '";</script>';
exit;
}
}
// 检查登录状态
$isLoggedIn = isset($dt['Data']['User']['Nickname']) && $dt['Data']['User']['Nickname'] !== '点击登录';
function getCommunityData() {
$baseUrl = "http://nlm-api-cn.turtlesim.com/";
// 准备请求数据
$requestData = [
'Identifier' => 'Discussions',
'Language' => "Chinese"
];
// 准备请求头
$headers = [
'Content-Type: application/json',
'Accept: application/json',
'Accept-Language: zh-CN',
];
// 添加认证头(修复了多余的大括号)
$headers[] = 'x-API-Token: ' . $_SESSION['token'];
$headers[] = 'x-API-AuthCode: ' . $_SESSION['authCode'];
// 发送POST请求
$url = $baseUrl . 'Contents/GetLibrary';
$ch = curl_init();
curl_setopt_array($ch, [
CURLOPT_URL => $url,
CURLOPT_POST => true,
CURLOPT_POSTFIELDS => json_encode($requestData, JSON_UNESCAPED_UNICODE),
CURLOPT_HTTPHEADER => $headers,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_SSL_VERIFYPEER => false,
CURLOPT_TIMEOUT => 30,
]);
$response = curl_exec($ch);
curl_close($ch);
$data = json_decode($response, true);
return $data;
}
// 处理日期格式
function formatDate($id) {
return (strlen($id) >= 8) ? date('m/d', hexdec(substr($id, 0, 8)) * 1000 / 1000) : '未知日期';
}
// 获取数据
$communityData = getCommunityData();
// 模块配置
$modules = [
['title' => '海水公告', 'count' => 3, 'featured' => true, 'type' => 'explore', 'category' => 'Discussion'],
['title' => '海水精选', 'count' => 3, 'featured' => true, 'type' => 'featured', 'category' => 'Discussion'],
['title' => '热门交流', 'count' => 4, 'featured' => false, 'type' => 'daily', 'category' => 'Discussion'],
['title' => '最新交流', 'count' => 4, 'featured' => false, 'type' => 'hot', 'category' => 'Discussion'],
['title' => '社区知识库', 'count' => 4, 'featured' => false, 'type' => 'new', 'category' => 'Discussion'],
['title' => '海水模版', 'count' => 4, 'featured' => false, 'type' => 'visual', 'category' => 'Discussion']
];
?>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="referrer" content="no-referrer">
<title>Turtle Universe Web - Discussion</title>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.0.0/css/all.min.css">
<style>
*{margin:0;padding:0;box-sizing:border-box}body{font-family:'Arial','Microsoft YaHei',sans-serif;background-color:#f5f7fa;color:#333;line-height:1.6;padding:0;margin:0}.header{background:linear-gradient(135deg,#667eea 0%,#764ba2 100%);color:white;padding:15px 20px;display:flex;justify-content:space-between;align-items:center;box-shadow:0 2px 10px rgba(0,0,0,0.1);position:sticky;top:0;z-index:1000}.user-info{display:flex;align-items:center;gap:12px;cursor:pointer;transition:opacity 0.3s ease}.user-info:hover{opacity:0.8}.user-info.login-prompt{cursor:pointer}.avatar{width:45px;height:45px;background:rgba(255,255,255,0.2);border-radius:50%;display:flex;align-items:center;justify-content:center;font-size:20px}.user-details{display:flex;flex-direction:column}.nickname{font-weight:bold;font-size:16px}.level{font-size:12px;opacity:0.8}.resources{display:flex;gap:15px}.coin,.diamond{display:flex;align-items:center;gap:5px;font-size:14px}.coin i{color:#ffd700}.diamond i{color:#b9f2ff}.content{padding:20px 15px 70px;max-width:1200px;margin:0 auto}.page-title{text-align:center;margin-bottom:25px;color:#333}.page-title h1{font-size:24px;margin-bottom:8px;color:#667eea}.page-title p{color:#666;font-size:14px}.community-grid{display:grid;grid-template-columns:repeat(auto-fit,minmax(300px,1fr));gap:20px;margin-top:20px}.block{background:white;border-radius:15px;padding:20px;box-shadow:0 4px 15px rgba(0,0,0,0.1);transition:transform 0.3s ease,box-shadow 0.3s ease;position:relative;overflow:hidden}.block:hover{transform:translateY(-5px);box-shadow:0 8px 25px rgba(0,0,0,0.15)}.block-header{color:#667eea;font-size:18px;font-weight:bold;margin-bottom:15px;padding-bottom:10px;border-bottom:2px solid #f0f0f0}.block-content{max-height:400px;overflow-y:auto}.item{display:flex;align-items:center;padding:12px 0;border-bottom:1px solid #f5f5f5;transition:background-color 0.3s ease;cursor:pointer}.item:hover{background-color:#f8f9ff;border-radius:8px;padding:12px 8px}.item:last-child{border-bottom:none}.item-img{width:60px;height:60px;border-radius:10px;object-fit:cover;margin-right:15px;flex-shrink:0;border:2px solid #e0e0e0}.item-details{flex:1}.item-title{font-weight:bold;font-size:14px;margin-bottom:5px;color:#333;line-height:1.3}.item-meta{font-size:12px;color:#666;margin-bottom:5px}.item-tags{display:flex;flex-wrap:wrap;gap:5px}.tag{background:#e3f2fd;color:#1976d2;padding:2px 8px;border-radius:12px;font-size:10px;font-weight:500}.featured-block{background:linear-gradient(135deg,#667eea 0%,#764ba2 100%);color:white}.featured-block .block-header{color:white;border-bottom-color:rgba(255,255,255,0.3)}.featured-block .item-title{color:white}.featured-block .item-meta{color:rgba(255,255,255,0.8)}.footer{position:fixed;bottom:0;left:0;right:0;background:white;display:flex;justify-content:space-around;padding:10px 0;box-shadow:0 -2px 10px rgba(0,0,0,0.1);z-index:1000}.footer div{display:flex;flex-direction:column;align-items:center;gap:5px;font-size:12px;color:#666;transition:color 0.3s ease;cursor:pointer}.footer div.active{color:#667eea}.footer i{font-size:20px}.error{text-align:center;padding:40px 20px;color:#e74c3c}.retry-btn{background:#667eea;color:white;border:none;padding:10px 20px;border-radius:20px;margin-top:15px;cursor:pointer;transition:background 0.3s ease}.retry-btn:hover{background:#5a6fd8}.more-button-container{text-align:center;margin-top:15px;padding-top:15px;border-top:1px solid rgba(255,255,255,0.3)}.featured-block .more-button-container{border-top-color:rgba(255,255,255,0.3)}.more-button{background:rgba(255,255,255,0.2);color:white;border:1px solid rgba(255,255,255,0.5);padding:8px 20px;border-radius:20px;cursor:pointer;font-size:14px;transition:all 0.3s ease}.more-button:hover{background:rgba(255,255,255,0.3);transform:translateY(-2px)}.block:not(.featured-block) .more-button-container{border-top-color:#f0f0f0}.block:not(.featured-block) .more-button{background:#667eea;color:white;border:none}.block:not(.featured-block) .more-button:hover{background:#5a6fd8}@media (max-width:768px){.community-grid{grid-template-columns:1fr}.header{padding:12px 15px}.content{padding:15px 10px 70px}.avatar{width:40px;height:40px;font-size:18px}.nickname{font-size:14px}.resources{gap:10px}}@media (max-width:480px){.block{padding:15px}.item-img{width:50px;height:50px;margin-right:12px}.item-title{font-size:13px}}.block-content::-webkit-scrollbar{width:4px}.block-content::-webkit-scrollbar-track{background:#f1f1f1;border-radius:2px}.block-content::-webkit-scrollbar-thumb{background:#c1c1c1;border-radius:2px}.block-content::-webkit-scrollbar-thumb:hover{background:#a8a8a8}
</style>
</head>
<body>
<header class="header">
<h2>海水</h2>
</header>
<main class="content">
<?php if ($communityData && isset($communityData['Data']['Blocks'])): ?>
<?php $blocks = $communityData['Data']['Blocks']; ?>
<div class="community-grid">
<?php foreach ($modules as $index => $module): ?>
<?php if (isset($blocks[$index])): ?>
<?php
$block = $blocks[$index];
$summaries = $block['Summaries'] ?? [];
?>
<div class="block <?= $module['featured'] ? 'featured-block' : '' ?>">
<div class="block-header"><?= $module['title'] ?></div>
<div class="block-content">
<?php foreach (array_slice($summaries, 0, $module['count']) as $exp): ?>
<?php
$subject = $exp['Subject'] ?? ($exp['LocalizedSubject']['Chinese'] ?? '未知主题');
$author = $exp['User']['Nickname'] ?? '未知作者';
$date = formatDate($exp['ID'] ?? '');
$tags = $exp['Tags'] ?? [];
$imgSrc = 'http://netlogo-cn.oss-cn-hongkong.aliyuncs.com/experiments/images/' .
substr($exp['ID'] ?? '0000000000000000', 0, 4) . '/' .
substr($exp['ID'] ?? '0000000000000000', 4, 2) . '/' .
substr($exp['ID'] ?? '0000000000000000', 6, 2) . '/' .
substr($exp['ID'] ?? '0000000000000000', 8, 16) . '/' .
($exp['Image'] ?? 'default') . '.jpg!full';
?>
<div class="item" onclick="window.location='med.php?category=<?= $module['category'] ?>&id=<?= $exp['ID'] ?>'">
<img src="<?= htmlspecialchars($imgSrc) ?>" alt="<?= htmlspecialchars($subject) ?>" class="item-img" onerror="this.src='data:image/svg+xml;base64,PHN2ZyB3aWR0aD0iNjAiIGhlaWdodD0iNjAiIHZpZXdCb3g9IjAgMCA2MCA2MCIgZmlsbD0ibm9uZSIgeG1sbnM9Imh0dHA6Ly93d3cudzMub3JnLzIwMDAvc3ZnIj4KPHJlY3Qgd2lkdGg9IjYwIiBoZWlnaHQ9IjYwIiBmaWxsPSIjRjBGMEYwIi8+CjxwYXRoIGQ9Ik0zMCAzNEMzMy4zMTM3IDM0IDM2IDMxLjMxMzcgMzYgMjhDMzYgMjQuNjg2MyAzMy4zMTM3IDIyIDMwIDIyQzI2LjY4NjMgMjIgMjQgMjQuNjg2MyAyNCAyOEMyNCAzMS4zMTM3IDI2LjY4NjMgMzQgMzAgMzRaIiBmaWxsPSIjQ0VDRUNFIi8+CjxwYXRoIGQ9Ik0zNiAzOEgyNEMyMi44OTU0IDM4IDIyIDM3LjEwNDYgMjIgMzZWMjRDMjIgMjIuODk1NCAyMi44OTU0IDIyIDI0IDIySDM2QzM3LjEwNDYgMjIgMzggMjIuODk1NCAzOCAyNFYzNkMzOCAzNy4xMDQ2IDM3LjEwNDYgMzggMzYgMzhaTTI0IDI0VjM2SDM2VjI0SDI0WiIgZmlsbD0iI0NFQ0VDRSIvPgo8L3N2Zz4K'">
<div class="item-details">
<div class="item-title"><?= htmlspecialchars($subject) ?></div>
<div class="item-meta"><?= htmlspecialchars($author) ?> - <?= $date ?></div>
<?php if (!empty($tags)): ?>
<div class="item-tags">
<?php foreach (array_slice($tags, 0, 3) as $tag): ?>
<span class="tag"><?= htmlspecialchars($tag) ?></span>
<?php endforeach; ?>
</div>
<?php endif; ?>
</div>
</div>
<?php endforeach; ?>
</div>
<div class="more-button-container">
<button class="more-button" onclick="window.location='med.php?category=<?= $module['category'] ?>&type=<?= $module['type'] ?>'">查看更多</button>
</div>
</div>
<?php endif; ?>
<?php endforeach; ?>
</div>
<?php else: ?>
<div class="error">
<p>无法加载社区数据,请检查网络连接或稍后重试</p>
<button class="retry-btn" onclick="window.location.reload()">重新加载</button>
</div>
<?php endif; ?>
</main>
<div class="footer">
<div onclick="location.href='/'"><i class="fas fa-home"></i><span>首页</span></div>
<div onclick="location.href='me.php'"><i class="fas fa-user"></i><span>我的</span></div>
<div class="active"><i class="fas fa-water"></i><span>海水</span></div>
<div><i class="fas fa-cube" onclick="location.href='model.php'"></i><span>模型库</span></div>
<div onclick="location.href='nof.php'"><i class="fas fa-bell"></i><span>通知</span></div>
</div>
<script>
document.addEventListener('DOMContentLoaded', function() {
const footerItems = document.querySelectorAll('.footer div');
footerItems.forEach(item => {
item.addEventListener('click', function() {
footerItems.forEach(i => i.classList.remove('active'));
this.classList.add('active');
});
});
});
</script>
</body>
</html>