Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion discussion.php
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ function formatDate($id) {
<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>
Expand Down Expand Up @@ -151,7 +152,7 @@ function formatDate($id) {

<div class="footer">
<div onclick="location.href='/'"><i class="fas fa-home"></i><span>首页</span></div>
<div><i class="fas fa-user"></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>
Expand Down
3 changes: 2 additions & 1 deletion index.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ function formatDate($id) {
<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</title>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.0.0/css/all.min.css">
<link rel="manifest" href="/manifest.json">
Expand Down Expand Up @@ -137,7 +138,7 @@ function formatDate($id) {

<div class="footer">
<div class="active"><i class="fas fa-home"></i><span>首页</span></div>
<div><i class="fas fa-user"></i><span>我的</span></div>
<div onclick="location.href='me.php'"><i class="fas fa-user"></i><span>我的</span></div>
<div onclick="location.href='discussion.php'"><i class="fas fa-water"></i><span>海水</span></div>
<div onclick="location.href='model.php'"><i class="fas fa-cube"></i><span>模型库</span></div>
<div onclick="location.href='nof.php'"><i class="fas fa-bell"></i><span>通知</span></div>
Expand Down
179 changes: 179 additions & 0 deletions me.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,179 @@
<?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=me.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'] !== '点击登录';

// 获取API数据
function getCommunityData() {
$baseUrl = "http://nlm-api-cn.turtlesim.com/";

// 准备请求数据
$requestData = [
'Identifier' => 'Workspace',
'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' => 4, 'featured' => false, 'type' => 'explore', 'category' => 'Local'],
['title' => '创建模型', 'count' => 3, 'featured' => true, 'type' => 'featured', 'category' => 'Model'],
['title' => '我的模型', 'count' => 4, 'featured' => false, 'type' => 'daily', 'category' => 'Model'],
['title' => '我的实验', 'count' => 4, 'featured' => false, 'type' => 'hot', 'category' => 'Experiment'],
['title' => '我的讨论', 'count' => 4, 'featured' => false, 'type' => 'new', 'category' => 'Discussion'],
['title' => '我支持的模型', 'count' => 4, 'featured' => false, 'type' => 'daily', 'category' => 'Model'],
['title' => '我支持的实验', 'count' => 4, 'featured' => false, 'type' => 'hot', 'category' => 'Experiment'],
['title' => '我支持的讨论', 'count' => 4, 'featured' => false, 'type' => 'new', 'category' => 'Discussion'],
['title' => '我收藏的模型', 'count' => 4, 'featured' => false, 'type' => 'daily', 'category' => 'Model'],
['title' => '我收藏的实验', 'count' => 4, 'featured' => false, 'type' => 'hot', 'category' => 'Experiment'],
['title' => '我收藏的讨论', 'count' => 4, 'featured' => false, 'type' => 'new', '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 - Workspace</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 class="active"><i class="fas fa-user"></i><span>我的</span></div>
<div onclick="location.href='discussion.php'"><i class="fas fa-water"></i><span>海水</span></div>
<div onclick="location.href='model.php'"><i class="fas fa-cube"></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>
7 changes: 5 additions & 2 deletions med.php
Original file line number Diff line number Diff line change
Expand Up @@ -472,14 +472,17 @@ function remixExperiment() {
alert('改编功能即将开放');
}
// 使用JavaScript动态加载评论
fetch('/comment/?category=<?= $category ?>&id=<?= $contentId ?>')
setInterval(()=>{
fetch('/comment/?category=<?= $category ?>&id=<?= $contentId ?>')
.then(response => response.text())
.then(html => {
document.getElementById('comments').innerHTML = html;
})
.catch(error => {
document.getElementById('comments').innerHTML = '<div class="error">加载评论失败</div>';
});
});
}, 10000);
//每10s更新一次
</script>
<script>
setInterval(()=>{
Expand Down
3 changes: 2 additions & 1 deletion model.php
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ function formatDate($id) {
<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 - Model Library</title>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.0.0/css/all.min.css">
<style>
Expand Down Expand Up @@ -155,7 +156,7 @@ function formatDate($id) {

<div class="footer">
<div><i class="fas fa-home" onclick="location.href='/'"></i><span>首页</span></div>
<div><i class="fas fa-user"></i><span>我的</span></div>
<div onclick="location.href='me.php'"><i class="fas fa-user"></i><span>我的</span></div>
<div onclick="location.href='discussion.php'"><i class="fas fa-water"></i><span>海水</span></div>
<div class="active"><i class="fas fa-cube"></i><span>模型库</span></div>
<div onclick="location.href='nof.php'"><i class="fas fa-bell"></i><span>通知</span></div>
Expand Down
2 changes: 1 addition & 1 deletion nof.php
Original file line number Diff line number Diff line change
Expand Up @@ -646,7 +646,7 @@ function displayNotificationsPage() {

<div class="footer">
<div onclick="location.href='index.php'"><i class="fas fa-home"></i><span>首页</span></div>
<div><i class="fas fa-user"></i><span>我的</span></div>
<div onclick="location.href='me.php'"><i class="fas fa-user"></i><span>我的</span></div>
<div><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 class="active" onclick="location.href='nof.php'"><i class="fas fa-bell"></i><span>通知</span></div>
Expand Down