木漏茶室源码下载中心
整站 PHP 源码:可浏览文件、复制路径、下载单文件或打包 ZIP。
发布版本 v6.25.232
升级后自动生成独立源码包,下载中心只发送这份冻结包
已排除 config.php / 用户数据 / 上传文件 / 升级备份
COMMUNITY DEPLOYMENTS
已经跑起来的木漏茶室
从源码下载中心下载、完成安装并回传验证的站外站点。每个站点只计 1 次部署下载量;已记录站点会实时读取名称、版本、Logo 与在线状态,本机、内网和证书异常站点无法完成回传。
实时检测
2
个站点已部署
木
木漏茶室
mlcs.xnn.lol · v6.25.232
访问 ↗
2026.11.21
在线
木
木漏茶室
mlcs.nbnb.mom · v6.25.232
访问 ↗
2026.11.20
在线
已展示全部 2 个站点。
pages/links.php
8.8 KB · 发布包 v6.25.232
<?php
/**
* 友情链接
*/
$isAdmin = is_admin(current_user());
if ($_SERVER['REQUEST_METHOD'] === 'POST' && $isAdmin) {
check_csrf();
$act = input('act');
if ($act === 'save') {
$name = mb_substr(trim((string) ($_POST['name'] ?? '')), 0, 40);
$url = trim((string) ($_POST['url'] ?? ''));
$sort = (int) input('sort', 0);
if ($name === '' || !preg_match('#^https?://#i', $url)) {
flash('请填写名称,并以 http:// 或 https:// 开头填写网址', 'err');
redirect(page_url('links'));
}
$id = (int) input('id');
$oldLogo = '';
if ($id > 0) {
$old = DB::one('SELECT * FROM ' . DB::table('links') . ' WHERE id = ?', [$id]);
if (!$old) {
flash('友情链接不存在', 'err');
redirect(page_url('links'));
}
$oldLogo = (string) ($old['logo'] ?? '');
}
$logo = $oldLogo;
$removeLogo = input('remove_logo') === '1';
$logoUrl = trim((string) ($_POST['logo_url'] ?? ''));
try {
if (!empty($_FILES['logo']['name'])) {
$stored = upload_store('logo', 'links', ['image' => true, 'max' => 2 * 1024 * 1024]);
if ($oldLogo !== '') {
delete_upload($oldLogo);
}
$logo = $stored['path'];
} elseif ($removeLogo) {
if ($oldLogo !== '') {
delete_upload($oldLogo);
}
$logo = '';
} elseif ($logoUrl !== '') {
if (!preg_match('#^(http|https)://#i', $logoUrl)) {
throw new Exception('网络 logo 需以 http:// 或 https:// 开头');
}
if ($oldLogo !== '' && $oldLogo !== $logoUrl) {
delete_upload($oldLogo);
}
$logo = $logoUrl;
}
} catch (Exception $e) {
flash('Logo 保存失败:' . $e->getMessage(), 'err');
redirect(page_url('links', $id > 0 ? ['edit' => $id] : []));
}
if ($id > 0) {
DB::update('links', ['name' => $name, 'url' => $url, 'logo' => $logo, 'sort' => $sort, 'status' => 1], 'id = ?', [$id]);
} else {
DB::insert('links', ['name' => $name, 'url' => $url, 'logo' => $logo, 'sort' => $sort, 'status' => 1]);
}
flash('友情链接已保存');
redirect(page_url('links'));
}
if ($act === 'delete') {
$row = DB::one('SELECT * FROM ' . DB::table('links') . ' WHERE id = ?', [(int) input('id')]);
if ($row && !empty($row['logo'])) {
delete_upload($row['logo']);
}
DB::delete('links', 'id = ?', [(int) input('id')]);
flash('链接已删除');
redirect(page_url('links'));
}
if ($act === 'move') {
$id = (int) input('id');
$dir = input('dir') === 'up' ? 'up' : 'down';
$rows = DB::all('SELECT id FROM ' . DB::table('links') . ' WHERE status = 1 ORDER BY sort ASC, id ASC');
$ids = array_map('intval', array_column($rows, 'id'));
$pos = array_search($id, $ids, true);
$newPos = $pos === false ? false : ($dir === 'up' ? $pos - 1 : $pos + 1);
if ($pos !== false && $newPos !== false && isset($ids[$newPos])) {
// 先归一化为连续排序值,避免老数据 sort 全是 0 时无法移动
foreach ($ids as $index => $linkId) {
DB::run('UPDATE ' . DB::table('links') . ' SET sort = ? WHERE id = ?', [$index, $linkId]);
}
$otherId = $ids[$newPos];
DB::run('UPDATE ' . DB::table('links') . ' SET sort = ? WHERE id = ?', [$newPos, $id]);
DB::run('UPDATE ' . DB::table('links') . ' SET sort = ? WHERE id = ?', [$pos, $otherId]);
flash('排序已更新');
}
redirect(page_url('links'));
}
}
$links = DB::all('SELECT * FROM ' . DB::table('links') . ' WHERE status = 1 ORDER BY sort ASC, id ASC');
$editing = $isAdmin && (int) input('edit') > 0 ? DB::one('SELECT * FROM ' . DB::table('links') . ' WHERE id = ?', [(int) input('edit')]) : null;
$GLOBALS['PAGE'] = 'links';
render_header('友情链接');
?>
<section class="ext-hero small">
<span class="hero-kicker">FRIENDS</span>
<h1>友情链接</h1>
<p>茶室外面的路,通向一些朋友的屋檐。</p>
</section>
<section class="link-grid">
<?php if (!$links): ?>
<?php empty_state('还没有友情链接', '管理员可在下方添加'); ?>
<?php else: ?>
<?php foreach ($links as $l): ?>
<?php
$logoUrl = trim((string) ($l['logo'] ?? '')) !== '' ? upload_url($l['logo']) : '';
$fallback = mb_substr((string) $l['name'], 0, 1);
?>
<div class="link-card">
<a class="link-main" href="<?= e(page_url('link_out', ['id' => (int) $l['id']])) ?>">
<span class="link-logo-wrap">
<?php if ($logoUrl !== ''): ?>
<img class="link-logo" src="<?= e($logoUrl) ?>" alt="<?= e($l['name']) ?> logo" loading="lazy"
onerror="this.style.display='none';var f=this.parentElement.querySelector('.link-logo-fallback');if(f){f.style.display='grid';}">
<span class="link-logo-fallback" style="display:none"><?= e($fallback) ?></span>
<?php else: ?>
<span class="link-logo-fallback"><?= e($fallback) ?></span>
<?php endif; ?>
</span>
<span class="link-info">
<strong><?= e($l['name']) ?></strong>
<span class="link-url" title="<?= e($l['url']) ?>"><?= e($l['url']) ?></span>
</span>
</a>
<?php if ($isAdmin): ?>
<div class="link-ops">
<span class="link-sort">排序 <?= (int) $l['sort'] ?></span>
<form method="post" class="inline-form">
<?= csrf_field() ?><input type="hidden" name="act" value="move"><input type="hidden" name="dir" value="up"><input type="hidden" name="id" value="<?= (int) $l['id'] ?>">
<button class="link-btn" type="submit" title="上移">↑</button>
</form>
<form method="post" class="inline-form">
<?= csrf_field() ?><input type="hidden" name="act" value="move"><input type="hidden" name="dir" value="down"><input type="hidden" name="id" value="<?= (int) $l['id'] ?>">
<button class="link-btn" type="submit" title="下移">↓</button>
</form>
<a class="link-btn" href="<?= e(page_url('links', ['edit' => $l['id']])) ?>">编辑</a>
<form method="post" class="inline-form" data-confirm="删除该链接?">
<?= csrf_field() ?><input type="hidden" name="act" value="delete"><input type="hidden" name="id" value="<?= (int) $l['id'] ?>">
<button class="link-btn danger" type="submit">删除</button>
</form>
</div>
<?php endif; ?>
</div>
<?php endforeach; ?>
<?php endif; ?>
</section>
<?php if ($isAdmin): ?>
<section class="panel">
<h2 class="section-title"><?= $editing ? '编辑链接' : '添加链接' ?></h2>
<form method="post" enctype="multipart/form-data" class="form-card">
<?= csrf_field() ?>
<input type="hidden" name="act" value="save">
<input type="hidden" name="id" value="<?= $editing ? (int) $editing['id'] : 0 ?>">
<div class="field-row">
<div class="field"><label>名称</label><input type="text" name="name" maxlength="40" value="<?= e($editing['name'] ?? '') ?>" required></div>
<div class="field grow"><label>网址</label><input type="url" name="url" value="<?= e($editing['url'] ?? '') ?>" placeholder="https://" required></div>
<div class="field"><label>排序</label><input type="number" name="sort" value="<?= (int) ($editing['sort'] ?? 0) ?>"></div>
</div>
<?php if (!empty($editing['logo'])): ?>
<div class="link-logo-current">
<img src="<?= e(upload_url($editing['logo'])) ?>" alt="当前 logo">
<label class="inline-check"><input type="checkbox" name="remove_logo" value="1"> 移除当前 logo</label>
</div>
<?php endif; ?>
<div class="field-row">
<div class="field"><label>本地上传 logo</label><input type="file" name="logo" accept="image/*"></div>
<div class="field grow"><label>或网络 logo 链接</label><input type="url" name="logo_url" value="<?= e(!empty($editing['logo']) && preg_match('#^http#i', $editing['logo']) ? $editing['logo'] : '') ?>" placeholder="https://example.com/logo.png"></div>
</div>
<p class="muted link-logo-hint">Logo 可留空,留空时自动使用名称第一个字。本地上传与网络链接同时填写时,优先使用本地上传。</p>
<button class="btn-primary" type="submit">保存</button>
<?php if ($editing): ?><a class="btn-ghost" href="<?= e(page_url('links')) ?>">取消编辑</a><?php endif; ?>
</form>
</section>
<?php endif; ?>
<?php render_footer(); ?>