ez-site/includes/home.php
2024-10-19 21:33:47 +08:00

61 lines
2.7 KiB
PHP

<div class="icons">
<div class="icon">
<a>
<?php
function startCountdown($startDate, $firstPeriodDays, $secondPeriodDays, $extraHours)
{
$totalDays = $firstPeriodDays + $secondPeriodDays;
$currentTime = time();
$elapsedDays = floor(($currentTime - strtotime($startDate)) / (60 * 60 * 24));
$currentPeriod = $elapsedDays % $totalDays;
if ($currentPeriod < $firstPeriodDays) {
$remainingDays = $firstPeriodDays - $currentPeriod;
$remainingTime = $remainingDays * (60 * 60 * 24) + $extraHours * (60 * 60);
$days = floor($remainingTime / (60 * 60 * 24));
echo '<p>距离下一次大休还有</p><a style="font-size:30px;color:#66ccff;">' . $days . '</a><p>天</p>';
} else {
$remainingDays = $firstPeriodDays - $currentPeriod;
$remainingTime = $remainingDays * (60 * 60 * 24) + $extraHours * (60 * 60);
$days = floor($remainingTime / (60 * 60 * 24));
echo '<p>距离开学还有</p><a style="font-size:30px;color:red;">1</a><p>天</p>';
}
}
$startDate = '2024-10-06 16:25:00'; // 开始计时的日期
$firstPeriodDays = 12; // 第一阶段的天数
$secondPeriodDays = 2; // 第二阶段的天数
$extraHours = 0; // 额外的小时数
$countdownText = startCountdown($startDate, $firstPeriodDays, $secondPeriodDays, $extraHours);
?>
</div>
<div class="icon">
<p>今天油二</p>
<a style="font-size:30px;color:#66ccff;">没有爆炸</a>
</div>
<!-- TODO: 课程表下载(一课表) -->
</div>
<div class="articles">
<div class="left-column">
<h2>活动一览</h2>
<?php
$stmt = $pdo->query("SELECT * FROM articles WHERE type = 'activity' ORDER BY created_at DESC");
while ($row = $stmt->fetch()) {
echo "<a href='/article/{$row['id']}.html'><h3>{$row['title']}</h3></a>";
echo "<p>{$row['content']}</p>";
echo "<small>发布于: {$row['created_at']}</small><hr>";
}
?>
</div>
<div class="right-column">
<h2>新闻动态</h2>
<?php
$stmt = $pdo->query("SELECT * FROM articles WHERE type = 'news' ORDER BY created_at DESC");
while ($row = $stmt->fetch()) {
echo "<a href='/article/{$row['id']}.html'><h3>{$row['title']}</h3></a>";
echo "<p>{$row['content']}</p>";
echo "<small>发布于: {$row['created_at']}</small><hr>";
}
?>
</div>
</div>