first commit

This commit is contained in:
root
2026-03-21 17:04:18 +08:00
commit 3c38481573
617 changed files with 65539 additions and 0 deletions

View File

@@ -0,0 +1,26 @@
<?php
/**
* 文章目录
*
* @author 星语社长
* @link https://biibii.cn
* @update 2024-7-6 18:00:04
*/
if ( ! defined('__TYPECHO_ROOT_DIR__')) {
exit;
}
?>
<?php $tocData = getCatalog();
if ($this->is('post') && $tocData): ?>
<!-- 文章目录 -->
<div class="hh-widget widget-toc-main mt-3 p-3">
<div class="widget-title mb-2">
<div class="widget-title-top-bg" style="background:var(--atoc-h-bg);"></div>
<i class="iconfont icon-mulu mr-1"></i>文章目录
</div>
<div class="atoc-content ml-2">
<?php echo $tocData; ?>
</div>
</div>
<?php endif; ?>

View File

@@ -0,0 +1,61 @@
<?php
/**
* 博主信息
*
* @author 星语社长
* @link https://biibii.cn
* @update 2024-7-6 18:00:04
*/
if (! defined('__TYPECHO_ROOT_DIR__')) {
exit;
}
?>
<?php if (! empty($this->options->sidebarBlock) && in_array('ShowAboutMe', $this->options->sidebarBlock)): ?>
<?php $stat = Typecho_Widget::widget('Widget_Stat'); ?>
<?php $isOnline = isAdminOnline(); // 是否在线
?>
<!-- 博主信息 -->
<div class="hh-widget">
<div class="author-content p-3 d-flex flex-column justify-content-center">
<div class="author-info-avatar">
<img class="avatar-img widget-lazy" src="<?php getLazyload(); ?>"
data-original="<?php echo getGravatar($this->authorId ? $this->author->mail : $this->user->mail) ?>"
alt="<?php $this->authorId ? $this->author->screenName() : $this->user->screenName(); ?>" />
<span class="author-oneline<?php echo $isOnline ? '' : ' author-offline' ?>"
title="博主今天<?php echo $isOnline ? '在线' : '离线' ?>"></span>
</div>
<div class="d-flex flex-column my-2">
<span
class="author-nickname text-center"><?php $this->authorId ? $this->author->screenName() : $this->user->screenName(); ?></span>
<span class="author-text text-center"><?php $this->options->blogmeabout(); ?></span>
</div>
<div class="row blog-count-box no-gutters">
<div class="col-3">
<div class="blog-count-item d-flex flex-column align-items-center justify-content-center">
<span>文章</span>
<span><?php $stat->publishedPostsNum() ?></span>
</div>
</div>
<div class="col-3">
<div class="blog-count-item d-flex flex-column align-items-center justify-content-center">
<span>分类</span>
<span><?php $stat->categoriesNum() ?></span>
</div>
</div>
<div class="col-3">
<div class="blog-count-item d-flex flex-column align-items-center justify-content-center">
<span>评论</span>
<span><?php $stat->publishedCommentsNum() ?></span>
</div>
</div>
<div class="col-3">
<div class="blog-count-item d-flex flex-column align-items-center justify-content-center">
<span>标签</span>
<span><?php $stat->TagsNum() ?></span>
</div>
</div>
</div>
</div>
</div>
<?php endif; ?>

View File

@@ -0,0 +1,27 @@
<?php
/**
* 博客路牌
*
* @author 星语社长
* @link https://biibii.cn
* @update 2025-9-22 14:39:24
*/
if ( ! defined('__TYPECHO_ROOT_DIR__')) {
exit;
}
?>
<?php if ( ! empty($this->options->sidebarBlock) && in_array('ShowBlogSignage', $this->options->sidebarBlock)): ?>
<!-- 博客路牌 -->
<div class="hh-widget mt-3">
<div class="blogsignage-widget">
<div class="blogsignage-head d-flex justify-content-center align-items-center font-weight-bold">
<?php $this->options->blogSignageText(); ?></div>
<div class="blogsignage-foot p-2 d-flex justify-content-between align-items-center">
<div class="blogsignage-foot-west"><i class="iconfont icon-xiala"></i>西</div>
<div class="blogsignage-foot-center"><?php $this->options->title(); ?>站</div>
<div class="blogsignage-foot-east">东<i class="iconfont icon-xiala"></i></div>
</div>
</div>
</div>
<?php endif; ?>

View File

@@ -0,0 +1,29 @@
<?php
/**
* 恶魔之眼
*
* @author 星语社长
* @link https://biibii.cn
* @update 2025-5-29 16:36:08
*/
if (! defined('__TYPECHO_ROOT_DIR__')) {
exit;
}
?>
<?php if (! empty($this->options->sidebarBlock) && in_array('ShowDevilEyes', $this->options->sidebarBlock)): ?>
<!-- 恶魔之眼 -->
<div class="hh-widget mt-3">
<div class="devil-widget py-2">
<div class="devil-content d-flex flex-row align-items-center justify-content-around">
<div class="devil-eye-left px-2">
<div class="devil-eye-o"></div>
</div>
<div class="devil-eye-right px-2">
<div class="devil-eye-o"></div>
</div>
</div>
<div class="devil-text text-center">小恶魔已巡视站点<?php echo getWebsiteAgeInDays($this->options->sitedate); ?>天</div>
</div>
</div>
<?php endif; ?>

View File

@@ -0,0 +1,30 @@
<?php
/**
* 首页底部Hello
*
* @author 星语社长
* @link https://biibii.cn
* @update 2024-7-6 18:00:04
*/
if (! defined('__TYPECHO_ROOT_DIR__')) {
exit;
}
?>
<?php if (! empty($this->options->indexBlock) && in_array('ShowHello', $this->options->indexBlock) && $this->is('index')): ?>
<?php $helloTxt = $this->options->helloText; ?>
<div class="hh-widget mb-3">
<div class="hello-widget">
<img class="widget-lazy" src="<?php getLazyload(); ?>" data-original="<?php getRandImg(); ?>"
alt="<?php echo $helloTxt ?>" />
<div class="hello-content d-flex flex-column justify-content-center align-items-center">
<span class="hello-text"><?php echo $helloTxt; ?></span>
</div>
<div class="hello-btn-group">
<a href="/harmonyhues.html" class="py-1 px-2 hello-btn-item" title="关于主题" target="_self">@主题</a>
<a href="/about.html" class="py-1 px-2 hello-btn-item" title="关于博主" target="_self">@博主</a>
<a href="/links.html" class="py-1 px-2 hello-btn-item" title="友情链接" target="_self">@朋友</a>
</div>
</div>
</div>
<?php endif; ?>

View File

@@ -0,0 +1,52 @@
<?php
/**
* 热门文章
*
* @author 星语社长
* @link https://biibii.cn
* @update 2024-7-6 18:00:04
*/
if ( ! defined('__TYPECHO_ROOT_DIR__')) {
exit;
}
?>
<?php if ( ! empty($this->options->sidebarBlock) && in_array('ShowHotPosts', $this->options->sidebarBlock)): ?>
<?php
function getHotPostsCid($limit = 10) {
$db = Typecho_Db::get();
$select = $db->select('cid')
->from('table.contents')
->where('type = ?', 'post')
->where('status = ?', 'publish')
->order('views', Typecho_Db::SORT_DESC)
->limit($limit);
$posts = $db->fetchAll($select);
return $posts;
}
$hotPostsCid = getHotPostsCid(6);
?>
<!-- 热门文章 -->
<div class="hh-widget mt-3 p-3">
<div class="widget-title mb-3">
<div class="widget-title-top-bg" style="background:var(--hotposts-h-bg);"></div>
<i class="iconfont icon-remen mr-1"></i>热门文章
</div>
<div class="widget-content hotposts-widget scroll-cover">
<ul class="hotposts-list">
<?php foreach ($hotPostsCid as $index => $postcid): ?>
<?php $post = Helper::widgetById('Contents', $postcid['cid']); ?>
<?php $postTitle = htmlspecialchars($post->title); ?>
<li class="hotposts-item">
<a class="hotposts-title" href="<?php $post->permalink(); ?>" title="<?php echo $postTitle; ?>">
<span class="hotposts-number mr-1"><?php echo $index + 1; ?></span><?php echo $postTitle; ?>
</a>
</li>
<?php endforeach; ?>
</ul>
</div>
</div>
<?php endif; ?>

View File

@@ -0,0 +1,58 @@
<?php
/**
* 最新评论
*
* @author 星语社长
* @link https://biibii.cn
* @update 2024-7-6 18:00:04
*/
if ( ! defined('__TYPECHO_ROOT_DIR__')) {
exit;
}
?>
<?php if ( ! empty($this->options->sidebarBlock) && in_array('ShowSidebarComments', $this->options->sidebarBlock) && ! $this->is('post')): ?>
<?php
function parseCommentContens($content) {
$content = parseContens($content);
$content = preg_replace('#<br>#si', '', $content); // 去除换行
return $content;
}
?>
<!-- 最新评论 -->
<div class="hh-widget mt-3 p-3">
<div class="widget-title mb-3">
<div class="widget-title-top-bg" style="background:var(--newreply-h-bg);"></div>
<i class="iconfont icon-pinglun1 mr-1"></i>最新评论
</div>
<div class="widget-content newreply-widget scroll-cover">
<!-- 评论项模板 -->
<?php $this->widget('Widget_Comments_Recent', 'ignoreAuthor=true&pageSize=5')->to($item); ?>
<?php if ($item->have()): ?>
<?php while ($item->next()): ?>
<div class="newreply-item mb-2">
<div class="comment-info d-flex align-items-center">
<div class="comment-avatar">
<img class="avatar-img widget-lazy" src="<?php getLazyload(); ?>"
data-original="<?php echo getGravatar($item->mail); ?>" alt="<?php $item->author(false)?>">
</div>
<div class="comment-name ml-2">
<a href="<?php $item->url()?>" title="<?php $item->author(false)?>"
target="_blank"><?php $item->author(false)?></a>
</div>
</div>
<div class="comment-content mt-1 p-2">
<a href="<?php echo $item->permalink; ?>" title="<?php echo $item->title.'评论' ?>">
<div class="comment-content-text"><?php echo parseCommentContens($item->content); ?></div>
</a>
</div>
</div>
<?php endwhile; ?>
<?php else: ?>
<div class="empty text-center">人气很差!一条回复都没有!</div>
<?php endif; ?>
</div>
</div>
<?php endif; ?>

View File

@@ -0,0 +1,101 @@
<?php
/**
* 轮播幻灯片
*
* @author 星语社长
* @link https://biibii.cn
* @update 2025-2-11 17:12:15
*/
if (! defined('__TYPECHO_ROOT_DIR__')) {
exit;
}
?>
<?php if (! empty($this->options->indexBlock) && in_array('ShowSwiper', $this->options->indexBlock) && $this->is('index')): ?>
<?php
function slidesHtml($content)
{
// 预处理输入内容
$cleanedContent = trim($content ?? '');
if ($cleanedContent === '') {
echo '幻灯片的数据为空或格式无效';
return;
}
$slidesHtml = '';
foreach (preg_split('/\r?\n|\r/', $cleanedContent) as $line) {
// 忽略空行
$line = trim($line);
if ($line === '') {
continue;
}
// 分割并处理字段
$parts = explode('|', $line);
if (count($parts) !== 5) {
continue;
}
// 字段处理管道
$fields = array_map(function ($field) {
$field = trim($field);
return $field === 'NULL' ? '' : $field;
}, $parts);
$title = @htmlspecialchars($fields[0]);
$description = @htmlspecialchars($fields[1]);
$label = @htmlspecialchars($fields[2]);
$image = @htmlspecialchars($fields[3] ?: getRandImg(false));
$link = @htmlspecialchars($fields[4]);
// 获取文件扩展名
$extension = strtolower(pathinfo($image, PATHINFO_EXTENSION));
// 生成HTML
$slidesHtml .= '<div class="swiper-slide">';
$slidesHtml .= '<a href="' . $link . '" target="_blank" title="' . ($title ?: $description) . ' - 点击前往">';
if ($extension === 'mp4') {
$slidesHtml .= '<video class="swiper-slide-video" autoplay loop muted playsinline>';
$slidesHtml .= '<source src="' . $image . '" type="video/mp4">';
$slidesHtml .= '</video>';
} else {
$slidesHtml .= '<img class="swiper-lazy" src="' . getLazyload(false) . '" data-src="' . $image . '" alt="' . ($title ?: $description) . '图片">';
}
$slidesHtml .= empty($label) ? '' : '<div class="px-2 py-1 swiper-slide-label">' . $label . '</div>';
if (! empty($title) || ! empty($description)) {
$slidesHtml .= '<div class="swiper-slide-content px-2 pb-2">';
$slidesHtml .= empty($title) ? '' : '<div class="swiper-slide-title font-weight-bold" data-swiper-parallax-x="-200" data-swiper-parallax-duration="1200">' . $title . '</div>';
$slidesHtml .= empty($description) ? '' : '<p class="swiper-slide-description m-0" data-swiper-parallax-x="-210" data-swiper-parallax-duration="1200">' . $description . '</p>';
$slidesHtml .= '</div>';
}
$slidesHtml .= '</a></div>';
}
// 检查生成的HTML是否为空
if ($slidesHtml === '') {
echo '幻灯片的数据为空或格式无效';
return;
}
echo $slidesHtml;
}
$swiperText = $this->options->swiperText;
?>
<!-- 轮播幻灯片 -->
<div class="card w-auto m-1 m-md-2 swiper-widget">
<div class="swiper-container">
<div class="swiper-wrapper"><?php slidesHtml($swiperText) ?></div>
<div class="swiper-pagination d-flex align-items-center mx-1"></div>
<div class="d-flex justify-content-center align-items-center m-2 swiper-button-wrapper">
<div class="swiper-button-prev d-flex justify-content-center align-items-center" title="上一张"><i
class="iconfont icon-shangyizhang p-1"></i></div>
<div class="swiper-button-next d-flex justify-content-center align-items-center" title="下一张"><i
class="iconfont icon-xiayizhang p-1"></i></div>
</div>
</div>
</div>
<?php endif; ?>

View File

@@ -0,0 +1,144 @@
<?php
/**
* 首页底部时间之旅
*
* @author 星语社长
* @link https://biibii.cn
* @update 2024-7-6 18:00:04
*/
if (! defined('__TYPECHO_ROOT_DIR__')) {
exit;
}
?>
<?php if (! empty($this->options->indexBlock) && in_array('ShowTimeJourney', $this->options->indexBlock) && $this->is('index')): ?>
<?php
// 获取建站日期比如2023-08-20
$siteCreationDate = new DateTime($this->options->sitedate);
/**
* 计算日期进度(已过去天数、剩余天数、百分比)
*/
function calculateDateProgress(DateTime $startDate, DateTime $endDate, DateTime $currentDate): array
{
// 计算从开始日期到结束日期的总时间间隔
$totalInterval = $startDate->diff($endDate);
// 获取总天数
$totalDays = $totalInterval->days;
// 计算从开始日期到当前日期的时间间隔
$passedInterval = $startDate->diff($currentDate);
// 获取已过去的天数
$passedDays = $passedInterval->days;
// 计算剩余的天数
$remainingDays = $totalDays - $passedDays;
// 计算已过去的天数占总天数的百分比
$passedPercentage = ($passedDays / $totalDays) * 100;
// 计算剩余的天数占总天数的百分比
$remainingPercentage = ($remainingDays / $totalDays) * 100;
// 返回一个包含所有计算结果的数组
return array(
'total_days' => $totalDays, // 总天数
'passed_days' => $passedDays, // 已过去的天数
'remaining_days' => $remainingDays, // 剩余的天数
'passed_percentage' => round($passedPercentage, 0), // 已过去的天数百分比,四舍五入到整数
'remaining_percentage' => round($remainingPercentage, 0), // 剩余的天数百分比,四舍五入到整数
);
}
/**
* 替换字符串中的占位符
*/
function replacePlaceholders(string $description, float $remainingPercentage, float $passedPercentage): string
{
// 替换剩余百分比占位符
$description = str_replace('{remainingPercentage}', $remainingPercentage, $description);
// 替换已过去百分比占位符
$description = str_replace('{progressPercentage}', $passedPercentage, $description);
return $description;
}
/**
* 处理输入字符串并返回处理后的结果
*/
function processEventString(string $input, DateTime $siteCreationDate)
{
// 分割字符串
$parts = explode('|', $input);
// 检查是否分割为4个部分
if (count($parts) !== 4) {
return false; // 输入格式不正确
}
// 提取并验证日期部分
$eventDate = trim($parts[0]);
if (! preg_match('/^\d{4}-\d{2}-\d{2}$/', $eventDate)) {
return false; // 日期格式不正确
}
// 将事件日期转换为 DateTime 对象
$eventDate = new DateTime($eventDate);
// 获取当前日期
$currentDate = new DateTime();
// 计算日期进度
$progress = calculateDateProgress($siteCreationDate, $eventDate, $currentDate);
// 替换描述中的占位符
$description = $parts[3];
$description = replacePlaceholders($description, $progress['remaining_percentage'], $progress['passed_percentage']);
// 返回处理后的结果
return array(
'date' => $eventDate->format('Y-m-d'),
'unit' => trim($parts[1]),
'title' => trim($parts[2]),
'description' => $description,
'progress' => $progress,
);
}
// 例如2025-03-26|天|星际旅行|{remainingPercentage|progressPercentage}
$timeJourneyText = $this->options->timeJourneyText;
$processedEvent = processEventString($timeJourneyText, $siteCreationDate);
// 测试->输出处理后的结果
// echo '事件日期: '.$processedEvent['date']."\n";
// echo '单位: '.$processedEvent['unit']."\n";
// echo '标题: '.$processedEvent['title']."\n";
// echo '描述: '.$processedEvent['description']."\n";
// echo '总天数: '.$processedEvent['progress']['total_days']."\n";
// echo '已过去天数: '.$processedEvent['progress']['passed_days']."\n";
// echo '剩余天数: '.$processedEvent['progress']['remaining_days']."\n";
// echo '已过去百分比: '.$processedEvent['progress']['passed_percentage']."%\n";
// echo '剩余百分比: '.$processedEvent['progress']['remaining_percentage']."%\n";
?>
<div class="hh-widget mb-3">
<?php if ($processedEvent): ?>
<?php $passedPercentage = $processedEvent['progress']['passed_percentage']; ?>
<div class="timejourney-widget">
<div id="timejourney-progress" class="timejourney-progress d-flex align-items-center justify-content-end p-2"
data-percentage="<?php echo $passedPercentage; ?>">
<?php echo $passedPercentage . '%'; ?>
</div>
<div class="timejourney-content px-2 py-1">
<div class="timejourney-text">
<span class="timejourney-day"><?php echo $processedEvent['progress']['passed_days']; ?></span>
<span class="timejourney-unit"><?php echo $processedEvent['unit']; ?></span>
</div>
<div class="timejourney-desc"><?php echo $processedEvent['title'] . ' | '; ?>
<?php echo $processedEvent['description']; ?></div>
</div>
</div>
<?php else: ?>
<div class="text-center">时间之旅格式不正确或日期验证失败。请输入正确的格式例如2025-03-26|天|星际旅行|本站服务器燃料剩余{remainingPercentage}%</div>
<?php endif; ?>
</div>
<?php endif; ?>

View File

@@ -0,0 +1,111 @@
<?php
/**
* 天气小部件
*
* @author 星语社长
* @link https://biibii.cn
* @update 2026-03-03
*/
if ( ! defined('__TYPECHO_ROOT_DIR__')) {
exit;
}
// 只有在侧边栏开启且不是文章页面时显示
if ( ! empty($this->options->sidebarBlock) && in_array('ShowSidebarWeather', $this->options->sidebarBlock) && ! $this->is('post')): ?>
<?php
// 获取配置信息
$city = trim($this->options->weatherCity ?: 'Beijing');
$apiKey = trim($this->options->weatherApiKey ?: '');
$cacheFile = dirname(__DIR__, 2) . '/assets/weather_cache.json';
// 缓存机制:记录城市和时间,过期 1 小时,城市变更时自动失效
function hh_fetch_weather($city, $apiKey, $cacheFile) {
if (file_exists($cacheFile)) {
$raw = @file_get_contents($cacheFile);
$cached = $raw ? json_decode($raw, true) : null;
// 缓存结构:{"city":"xxx","timestamp":12345678,"data":{…}}
if ($cached && isset($cached['city'], $cached['timestamp'], $cached['data'])) {
if ($cached['city'] === $city && time() - $cached['timestamp'] < 3600) {
return $cached['data'];
}
}
}
if (empty($apiKey) || empty($city)) {
return null;
}
$url = 'https://api.openweathermap.org/data/2.5/weather?q=' . urlencode($city)
. '&appid=' . $apiKey . '&units=metric&lang=zh_cn';
$json = @file_get_contents($url);
if ($json) {
$payload = json_encode([
'city' => $city,
'timestamp' => time(),
'data' => json_decode($json, true),
]);
@file_put_contents($cacheFile, $payload);
return json_decode($json, true);
}
return null;
}
$weather = hh_fetch_weather($city, $apiKey, $cacheFile);
// 用于调试:在 HTML 注释中输出参数和值,方便查看
$reqUrl = 'https://api.openweathermap.org/data/2.5/weather?q=' . urlencode($city)
. '&appid=' . $apiKey . '&units=metric&lang=zh_cn';
?>
<!-- weather widget debug: city=<?php echo htmlspecialchars($city, ENT_QUOTES); ?>, key_len=<?php echo strlen($apiKey); ?>, url=<?php echo htmlspecialchars($reqUrl, ENT_QUOTES); ?>, allow_url_fopen=<?php echo ini_get('allow_url_fopen') ? 'on' : 'off'; ?>, last_err=<?php $e = error_get_last(); echo $e ? htmlspecialchars($e['message'], ENT_QUOTES) : 'none'; ?> -->
<div class="hh-widget mt-3 weather-widget" style="font-size:0.9rem;line-height:1.4;">
<?php if ($weather && isset($weather['weather'][0])): ?>
<?php
// 语言友好的城市显示(中英文互译)
function hh_display_city($inputCity, $weather) {
static $map = [
'Beijing' => '北京',
'Guangzhou' => '广州',
'Shenzhen' => '深圳',
'Shanghai' => '上海',
'Chengdu' => '成都',
// 可根据需要继续添加
];
if (isset($map[$inputCity])) {
return $map[$inputCity];
}
if (isset($map[$weather['name']])) {
return $map[$weather['name']];
}
return $weather['name'];
}
$displayCity = hh_display_city($city, $weather);
$w = $weather['weather'][0];
$m = $weather['main'];
$wind = $weather['wind'] ?? [];
$iconUrl = 'https://openweathermap.org/img/wn/' . $w['icon'] . '@2x.png';
?>
<div class="weather-header" style="display:flex;align-items:center;justify-content:center;">
<img src="<?php echo $iconUrl; ?>"
alt="<?php echo htmlspecialchars($w['description'], ENT_QUOTES); ?>"
style="width:48px;height:48px;margin-right:8px;">
<div style="text-align:left;">
<p style="margin:0;font-weight:bold;line-height:1;"><?php echo $displayCity; ?></p>
<p style="margin:0;line-height:1;"><?php echo $w['description']; ?> <?php echo $m['temp']; ?>°C</p>
</div>
</div>
<div class="weather-details" style="font-size:0.85rem;color:#555;text-align:center;margin-top:4px;">
<p style="margin:0;">体感:<?php echo $m['feels_like']; ?>°C湿度<?php echo $m['humidity']; ?>%;气压:<?php echo $m['pressure']; ?> hPa</p>
<?php if (!empty($wind)): ?>
<p style="margin:0;">风速:<?php echo $wind['speed']; ?> m/s<?php
if (isset($wind['deg'])) echo ',方向:' . $wind['deg'] . '°'; ?></p>
<?php endif; ?>
</div>
<?php elseif ($weather && isset($weather['cod']) && $weather['cod'] != 200): ?>
<p>天气接口错误:<?php echo htmlspecialchars($weather['message'] ?? '未知', ENT_QUOTES); ?></p>
<?php else: ?>
<p>天气获取失败</p>
<?php endif; ?>
</div>
<?php endif; ?>

View File

@@ -0,0 +1,80 @@
<?php
/**
* 一言
*
* @author 星语社长
* @link https://biibii.cn
* @update 2024-7-6 18:00:04
*/
if ( ! defined('__TYPECHO_ROOT_DIR__')) {
exit;
}
?>
<?php if ( ! empty($this->options->sidebarBlock) && in_array('ShowSidebarYiyan', $this->options->sidebarBlock) && ! $this->is('post')): ?>
<?php
function getYiyan() {
// 主题根目录绝对路径(本文件在 components/widgets
$themeRoot = dirname(__DIR__, 2);
// 获取句子文件的本地路径,避免通过 HTTP 请求
$filePath = $themeRoot . '/assets/yiyan/yiyan.txt';
// 读取文件内容,忽略空行
$lines = @file($filePath, FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES);
if ($lines) {
// 随机选择一句
$randomLine = $lines[array_rand($lines)];
return explode('——', $randomLine);
} else {
return array('一言为空或读取失败。', '——');
}
}
function getGreeting() {
// 获取当前时间的小时数24 小时制)
$hour = date('H');
// 根据时间判断问候语
if ($hour >= 5 && $hour < 9) {
return '早上好!';
} elseif ($hour >= 9 && $hour < 12) {
return '上午好!';
} elseif ($hour >= 12 && $hour < 14) {
return '中午好!';
} elseif ($hour >= 14 && $hour < 18) {
return '下午好!';
} elseif ($hour >= 18 && $hour < 23) {
return '晚上好!';
} else {
return '夜深了,早点休息哦!';
}
}
// 随机一言图
$randImg = getAssets('assets/yiyan/'.rand(1, 20).'.webp', false);
?>
<!-- 一言 -->
<div class="hh-widget mt-3">
<div class="yiyan-widget">
<div class="yiyan-date p-2">
<p class="m-0"><?php echo getGreeting(); ?></p>
<p class="m-0"><span class="yiyan-day"><?php echo date('d'); ?></span>/<span
class="yiyan-month"><?php echo date('m'); ?></span></p>
</div>
<div class="yiyan-refresh-btn" title="刷新一言"><i onclick="location.reload()" class="iconfont icon-yuan"></i></div>
<div class="yiyan-content d-flex flex-column justify-content-between">
<div class="yiyan-cover">
<img data-original="<?php echo $randImg; ?>" src="<?php getLazyload(); ?>" alt="一言壁纸"
class="yiyan-img widget-lazy" />
</div>
<?php $yiyan = getYiyan(); ?>
<div class="yiyan-text p-2">
<p class="yiyan-quote m-0" title="<?php echo $yiyan[0]; ?>"><?php echo $yiyan[0]; ?></p>
<p class="yiyan-author text-right m-0" title="<?php echo $yiyan[1]; ?>">——<?php echo $yiyan[1]; ?></p>
</div>
</div>
</div>
</div>
<?php endif; ?>