SOURCE DOWNLOAD

木漏茶室源码下载中心

整站 PHP 源码:可浏览文件、复制路径、下载单文件或打包 ZIP。

发布版本 v6.25.231 升级后自动生成独立源码包,下载中心只发送这份冻结包 已排除 config.php / 用户数据 / 上传文件 / 升级备份
komorebi-forum 183 个节点 · PHP 8.3.37 · 完整源码 ZIP 1.31 MB
下载完整源码 ZIP 源码包大小:1.31 MB 安装教程 作者主页 免费开源 免费下载 ↓
COMMUNITY DEPLOYMENTS

已经跑起来的木漏茶室

从源码下载中心下载、完成安装并回传验证的站外站点。每个站点只计 1 次部署下载量;已记录站点会实时读取名称、版本、Logo 与在线状态,本机、内网和证书异常站点无法完成回传。

实时检测
2 个站点已部署

已展示全部 2 个站点。

pages/ext_manage.php 12.7 KB · 发布包 v6.25.231
下载
<?php
/**
 * 扩展管理:所有登录用户可用
 * 系统扩展保持默认;个人排序、隐藏和添加的网站扩展只影响本人。
 */
require_login();
$me = current_user();
$uid = (int) $me['id'];
$isSuper = is_superadmin($me);

if ($_SERVER['REQUEST_METHOD'] === 'POST') {
    check_csrf();
    $act = (string) input('act');

    if ($act === 'reset_layout') {
        DB::run('DELETE FROM ' . DB::table('user_ext_prefs') . ' WHERE user_id = ?', [$uid]);
        flash('已恢复系统默认布局');
        redirect(page_url('ext_manage'));
    }

    if ($act === 'save_layout') {
        $rows = extension_list_for_user($me);
        $allowed = [];
        foreach ($rows as $r) { $allowed[(int) $r['id']] = true; }
        $sorts = (array) ($_POST['sort'] ?? []);
        $shows = (array) ($_POST['show'] ?? []);
        foreach ($sorts as $eid => $val) {
            $eid = (int) $eid;
            if (!isset($allowed[$eid])) { continue; }
            $sort = (int) $val;
            $hidden = isset($shows[$eid]) ? 0 : 1;
            $exists = DB::val('SELECT COUNT(*) FROM ' . DB::table('user_ext_prefs') . ' WHERE user_id = ? AND extension_id = ?', [$uid, $eid], 0);
            if ($exists) {
                DB::run('UPDATE ' . DB::table('user_ext_prefs') . ' SET sort = ?, hidden = ?, updated_at = ? WHERE user_id = ? AND extension_id = ?',
                    [$sort, $hidden, now(), $uid, $eid]);
            } else {
                DB::run('INSERT INTO ' . DB::table('user_ext_prefs') . ' (user_id, extension_id, sort, hidden, updated_at) VALUES (?,?,?,?,?)',
                    [$uid, $eid, $sort, $hidden, now()]);
            }
        }
        flash('我的扩展布局已保存,仅对你的账号生效');
        redirect(page_url('ext_manage'));
    }

    if ($act === 'add_site') {
        $name = trim((string) input('name'));
        $url = trim((string) input('url'));
        if ($name === '' || mb_strlen($name) > 60) {
            flash('请填写扩展名称,最多 60 字', 'err');
            redirect(page_url('ext_manage'));
        }
        if (!preg_match('#^https?://#i', $url)) {
            flash('网站地址需以 http:// 或 https:// 开头', 'err');
            redirect(page_url('ext_manage'));
        }
        $icon = '';
        try {
            if (!empty($_FILES['site_icon_file']['name'])) {
                $stored = upload_store('site_icon_file', 'extensions', ['image' => true, 'max' => 2 * 1024 * 1024]);
                $icon = $stored['path'];
            } else {
                $iconUrl = trim((string) input('site_icon_url'));
                if ($iconUrl !== '') {
                    if (!preg_match('#^https?://#i', $iconUrl)) {
                        throw new Exception('网络图标链接需以 http:// 或 https:// 开头');
                    }
                    $icon = $iconUrl;
                }
            }
        } catch (Exception $e) {
            flash('图标保存失败:' . $e->getMessage(), 'err');
            redirect(page_url('ext_manage'));
        }
        do {
            $slug = 'u' . $uid . '_site_' . substr(bin2hex(random_bytes(4)), 0, 8);
            $exists = DB::val('SELECT COUNT(*) FROM ' . DB::table('extensions') . ' WHERE slug = ?', [$slug], 0);
        } while ($exists);
        DB::run('INSERT INTO ' . DB::table('extensions')
            . ' (slug, name, description, icon, url, is_builtin, owner_id, status, sort, created_at) VALUES (?,?,?,?,?,?,?,?,?,?)',
            [$slug, $name, '', $icon, $url, 0, $uid, 1, (int) input('sort', 999), now()]);
        flash('网站扩展已添加,只显示在你的扩展中心');
        redirect(page_url('ext_manage'));
    }

    if ($act === 'edit_site' || $act === 'delete_site') {
        $id = (int) input('id');
        $row = DB::one('SELECT * FROM ' . DB::table('extensions') . ' WHERE id = ?', [$id]);
        if (!$row || (int) ($row['owner_id'] ?? 0) !== $uid || (int) ($row['is_builtin'] ?? 1) === 1) {
            flash('只能管理你自己添加的网站扩展', 'err');
            redirect(page_url('ext_manage'));
        }
        if ($act === 'delete_site') {
            $icon = (string) ($row['icon'] ?? '');
            if ($icon !== '' && !preg_match('#^https?://#i', $icon)) {
                delete_upload($icon);
            }
            DB::delete('extensions', 'id = ?', [$id]);
            DB::run('DELETE FROM ' . DB::table('user_ext_prefs') . ' WHERE extension_id = ?', [$id]);
            flash('你的网站扩展已删除');
            redirect(page_url('ext_manage'));
        }
        $name = trim((string) input('name'));
        $url = trim((string) input('url'));
        if ($name === '' || mb_strlen($name) > 60) {
            flash('请填写扩展名称,最多 60 字', 'err');
            redirect(page_url('ext_manage'));
        }
        if (!preg_match('#^https?://#i', $url)) {
            flash('网站地址需以 http:// 或 https:// 开头', 'err');
            redirect(page_url('ext_manage'));
        }
        $icon = (string) ($row['icon'] ?? '');
        if (input('icon_clear') === '1') {
            $icon = '';
        } elseif (!empty($_FILES['site_icon_file']['name'])) {
            try {
                $stored = upload_store('site_icon_file', 'extensions', ['image' => true, 'max' => 2 * 1024 * 1024]);
                $icon = $stored['path'];
            } catch (Exception $e) {
                flash('图标上传失败:' . $e->getMessage(), 'err');
                redirect(page_url('ext_manage'));
            }
        } else {
            $iconUrl = trim((string) input('site_icon_url'));
            if ($iconUrl !== '') {
                if (!preg_match('#^https?://#i', $iconUrl)) {
                    flash('网络图标链接需以 http:// 或 https:// 开头', 'err');
                    redirect(page_url('ext_manage'));
                }
                $icon = $iconUrl;
            }
        }
        DB::run('UPDATE ' . DB::table('extensions') . ' SET name = ?, icon = ?, url = ? WHERE id = ?',
            [$name, $icon, $url, $id]);
        flash('你的网站扩展已保存');
        redirect(page_url('ext_manage'));
    }

    redirect(page_url('ext_manage'));
}

$rows = extension_list_for_user($me);
$mine = [];
foreach ($rows as $r) {
    if ((int) ($r['owner_id'] ?? 0) === $uid && (int) ($r['is_builtin'] ?? 1) !== 1) {
        $mine[] = $r;
    }
}
$GLOBALS['PAGE'] = 'extensions';
render_header('扩展管理');
?>
<section class="admin-head">
  <div>
    <h1>扩展管理</h1>
    <p>共 <?= count($rows) ?> 个可用扩展 · 排序和显示只影响你的账号</p>
  </div>
  <div class="admin-quick">
    <form method="post">
      <?= csrf_field() ?><input type="hidden" name="act" value="reset_layout">
      <button class="btn-mini ghost" type="submit" data-confirm="恢复为系统默认布局?">恢复默认布局</button>
    </form>
    <button class="btn-primary btn-mini" type="button" data-ext-add-jump>添加网络扩展</button>
  </div>
</section>

<section class="panel" id="add-site">
  <div class="panel-head">
    <h2>添加网站扩展</h2>
    <p>可添加任意数量,添加后只出现在你自己的扩展中心,点击进入带「返回扩展中心」的中转页。其他用户仍看系统默认。</p>
  </div>
  <form method="post" enctype="multipart/form-data" class="form-card">
    <?= csrf_field() ?>
    <input type="hidden" name="act" value="add_site">
    <div class="field-row">
      <div class="field"><label>名称</label><input type="text" name="name" maxlength="60" placeholder="例如:蓝奏云" required></div>
      <div class="field grow"><label>网站地址</label><input type="url" name="url" maxlength="255" placeholder="https://example.com/" required></div>
      <div class="field"><label>排序</label><input type="number" name="sort" value="999" step="1"></div>
    </div>
    <div class="field-row">
      <div class="field"><label>本地上传图标</label><input type="file" name="site_icon_file" accept="image/*"></div>
      <div class="field grow"><label>或网络图标链接</label><input type="url" name="site_icon_url" maxlength="255" placeholder="https://example.com/icon.png"></div>
    </div>
    <p class="muted" style="font-size:12px;margin:0 0 12px">图标可留空,前台会显示默认地球图标。</p>
    <button class="btn-primary" type="submit">添加网站扩展</button>
  </form>
</section>

<?php if ($mine): ?>
<section class="panel">
  <h2 class="section-title">我的网站扩展</h2>
  <div class="ext-edit-list">
    <?php foreach ($mine as $r): ?>
      <?php $editIcon = extension_icon_src((string) ($r['icon'] ?? '')); ?>
      <form method="post" enctype="multipart/form-data" class="ext-edit-row">
        <?= csrf_field() ?>
        <input type="hidden" name="act" value="edit_site">
        <input type="hidden" name="id" value="<?= (int) $r['id'] ?>">
        <div class="ext-edit-slug">
          <span class="ext-edit-icon"><?php if ($editIcon !== ''): ?><img src="<?= e($editIcon) ?>" alt=""><?php else: ?>🌐<?php endif; ?></span>
          <strong><?= e($r['name']) ?></strong><i><?= e($r['slug']) ?></i>
        </div>
        <div class="ext-edit-fields">
          <div class="field ext-field"><label>名称</label><input type="text" name="name" maxlength="60" required value="<?= e($r['name']) ?>"></div>
          <div class="field ext-field"><label>上传本地图标</label><input type="file" name="site_icon_file" accept="image/*"></div>
          <div class="field ext-field ext-url"><label>网站地址</label><input type="url" name="url" maxlength="255" required value="<?= e($r['url'] ?? '') ?>"></div>
          <div class="field ext-field ext-url">
            <label>网络图标链接</label>
            <div class="ext-url-line">
              <input type="url" name="site_icon_url" maxlength="255" value="<?= preg_match('#^https?://#i', (string) ($r['icon'] ?? '')) ? e($r['icon']) : '' ?>" placeholder="https://... 留空则保留当前图标">
              <label class="inline-check ext-icon-clear"><input type="checkbox" name="icon_clear" value="1"> 清除图标</label>
            </div>
          </div>
        </div>
        <div style="display:flex;flex-direction:column;gap:6px">
          <button class="btn-mini ext-save" type="submit">保存</button>
          <button class="btn-mini danger" type="submit" name="act" value="delete_site" formnovalidate onclick="return confirm('删除这个网站扩展?');">删除</button>
        </div>
      </form>
    <?php endforeach; ?>
  </div>
</section>
<?php endif; ?>

<section class="panel">
  <div class="panel-head">
    <h2>我的扩展布局</h2>
    <p>数字越小越靠前;取消勾选后,该扩展只从你的扩展中心隐藏。不会影响其他用户。</p>
  </div>
  <form method="post" class="ext-sort-form">
    <?= csrf_field() ?><input type="hidden" name="act" value="save_layout">
    <div class="ext-sort-list">
      <?php foreach ($rows as $r): ?>
        <label class="ext-sort-row">
          <span><?= e($r['name']) ?> <i><?= e($r['slug']) ?></i></span>
          <span style="display:inline-flex;align-items:center;gap:8px">
            <label class="inline-check"><input type="checkbox" name="show[<?= (int) $r['id'] ?>]" value="1" <?= empty($r['_hidden']) ? 'checked' : '' ?>> 显示</label>
            <input type="number" name="sort[<?= (int) $r['id'] ?>]" value="<?= (int) $r['_sort'] ?>" step="1" aria-label="排序">
          </span>
        </label>
      <?php endforeach; ?>
    </div>
    <button class="btn-primary" type="submit">保存我的布局</button>
  </form>
</section>

<?php if ($isSuper): ?>
<section class="panel">
  <div class="panel-head">
    <h2>系统扩展设置</h2>
    <p class="muted">超级管理员可修改系统扩展名称、图标和网址,或进入后台启停。</p>
  </div>
  <div class="admin-quick">
    <a class="btn-mini ghost" href="<?= e(page_url('admin', ['s' => 'extensions'])) ?>">打开系统扩展后台 →</a>
  </div>
</section>
<?php endif; ?>

<section class="panel">
  <h2 class="section-title">说明</h2>
  <p class="muted">系统扩展不能被普通用户修改或删除。个人排序、隐藏和添加的网站扩展只保存在你的账号下;其他用户看到的仍是系统默认布局。</p>
</section>

<script>
(function () {
  var jump = document.querySelector('[data-ext-add-jump]');
  if (!jump) return;
  jump.addEventListener('click', function () {
    var panel = document.getElementById('add-site');
    if (!panel) return;
    panel.scrollIntoView({ behavior: 'smooth', block: 'start' });
    var name = panel.querySelector('input[name="name"]');
    if (name) {
      setTimeout(function () {
        try { name.focus({ preventScroll: true }); } catch (e) { name.focus(); }
      }, 500);
    }
  });
})();
</script>

<?php render_footer(); ?>
主题