diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..8d7d96a
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1,24 @@
+# Runtime data, cache and logs
+data/
+cache/
+*.log
+
+# Backups and temporary files
+备份/
+*.bak
+*.tmp
+.DS_Store
+
+# Environment and secrets
+.env
+.env.*
+*key*.txt
+credentials*.json
+
+# Editor and build artifacts
+.idea/
+.vscode/
+node_modules/
+vendor/
+dist/
+build/
diff --git a/Action.php b/Action.php
new file mode 100644
index 0000000..94e92e1
--- /dev/null
+++ b/Action.php
@@ -0,0 +1,599 @@
+db = Typecho_Db::get();
+ $this->prefix = $this->db->getPrefix();
+ $this->request = $request ?: Typecho_Request::getInstance();
+ $this->response = $response ?: Typecho_Response::getInstance();
+
+ // 老版本 event_date 是 DATE 类型,会丢掉时分秒,这里做一次自动升级
+ $this->ensureEventDateColumn();
+ }
+
+ /**
+ * 当前站点是不是 SQLite(与 Plugin::isSqlite() 同口径)
+ *
+ * @return bool
+ */
+ private function isSqliteDb()
+ {
+ try {
+ return stripos(get_class($this->db->getAdapter()), 'sqlite') !== false;
+ } catch (Throwable $e) {
+ return false;
+ }
+ }
+
+ /**
+ * 确保 event_date 列已升级为 DATETIME
+ *
+ * 旧版本建表时 event_date 是 DATE,只存年月日。插件文件更新后如果没有
+ * 重新启用插件,activate() 不会执行,这里做一次轻量结构检查并自动升级,
+ * 避免写入的时分秒被 DATE 列悄悄截断。每个请求最多检查一次。
+ *
+ * @return void
+ */
+ private function ensureEventDateColumn()
+ {
+ static $checked = false;
+
+ if ($checked) {
+ return;
+ }
+ $checked = true;
+
+ // 2.0.1:SQLite 必须在这里早退。
+ // 2.0.0 及以前无条件跑 MySQL 的 SHOW COLUMNS,SQLite 不认这种语法,
+ // 于是每走一次 Action(后台增删改、导入导出)就往 error_log 写一条
+ // 「near "SHOW": syntax error」。功能本来就没事:SQLite 建表时
+ // event_date 就是 DATETIME,而且列类型只是「亲和性」,写 'Y-m-d H:i:s'
+ // 不会被截断,没有升级的必要。Plugin::getTableColumns() 早就分了
+ // PRAGMA / SHOW 两条路,这里当时漏了。
+ if ($this->isSqliteDb()) {
+ return;
+ }
+
+ try {
+ $tableName = $this->prefix . 'changelog';
+ $columns = $this->db->fetchAll($this->db->query("SHOW COLUMNS FROM `{$tableName}` LIKE 'event_date'"));
+
+ if (empty($columns)) {
+ return;
+ }
+
+ $type = isset($columns[0]['Type']) ? strtolower($columns[0]['Type']) : '';
+ if ($type === 'datetime') {
+ return;
+ }
+
+ $this->db->query("ALTER TABLE `{$tableName}` MODIFY `event_date` DATETIME NOT NULL COMMENT '事件日期时间'");
+ } catch (Throwable $e) {
+ // 升级失败不阻断页面,写入时仍按原逻辑执行
+ error_log('ChangeLog ensureEventDateColumn Error: ' . $e->getMessage());
+ }
+ }
+
+ /**
+ * 归一化事件日期时间为 Y-m-d H:i:s
+ *
+ * 支持的写法:
+ * 2026-10-27
+ * 2026-10-27 11:07:16 / 2026-10-27 11:07
+ * 2026-10-27T11:07:16(datetime-local 的提交格式)
+ * 2026.10.27 11:07:16(导入文本里常见的写法)
+ * 不带时间部分时按 00:00:00 处理。
+ *
+ * @param string $value
+ * @return string
+ * @throws Exception 日期或时间非法时抛出
+ */
+ private function normalizeEventDate($value)
+ {
+ $value = trim((string) $value);
+
+ // 统一分隔符:T、点、斜杠都换成标准写法
+ $normalized = str_replace(array('T', '.', '/'), array(' ', '-', '-'), $value);
+ $normalized = preg_replace('/\s+/', ' ', $normalized);
+
+ if (!preg_match('/^(\d{4})-(\d{1,2})-(\d{1,2})(?: (\d{1,2}):(\d{1,2})(?::(\d{1,2}))?)?$/', $normalized, $matches)) {
+ throw new Exception("日期格式错误,应为 YYYY-MM-DD HH:MM:SS(时间可省略)");
+ }
+
+ $year = intval($matches[1]);
+ $month = intval($matches[2]);
+ $day = intval($matches[3]);
+ $hour = (isset($matches[4]) && $matches[4] !== '') ? intval($matches[4]) : 0;
+ $minute = (isset($matches[5]) && $matches[5] !== '') ? intval($matches[5]) : 0;
+ $second = (isset($matches[6]) && $matches[6] !== '') ? intval($matches[6]) : 0;
+
+ if (!checkdate($month, $day, $year)) {
+ throw new Exception("无效的日期:{$value}");
+ }
+
+ if ($hour > 23 || $minute > 59 || $second > 59) {
+ throw new Exception("无效的时间:{$value}");
+ }
+
+ return sprintf('%04d-%02d-%02d %02d:%02d:%02d', $year, $month, $day, $hour, $minute, $second);
+ }
+
+ /**
+ * 格式化事件日期时间:日期后空格显示时分秒
+ *
+ * 升级前的老记录只存了日期(时间为 00:00:00),这类记录只显示日期,
+ * 不显示没有意义的 00:00:00。
+ *
+ * @param string $value 数据库中的 event_date
+ * @param string $dateFormat PHP 日期格式
+ * @return string
+ */
+ private function formatEventDate($value, $dateFormat = 'Y-m-d')
+ {
+ $timestamp = strtotime((string) $value);
+
+ if ($timestamp === false) {
+ return '';
+ }
+
+ $date = date($dateFormat, $timestamp);
+ $time = date('H:i:s', $timestamp);
+
+ return $time === '00:00:00' ? $date : $date . ' ' . $time;
+ }
+
+ /**
+ * 添加更新记录 - 修复:使用Typecho正确的SQL构建方法
+ */
+ public function addEntry($data)
+ {
+ try {
+ $now = new Typecho_Date(Typecho_Date::gmtTime());
+
+ $insert = array(
+ 'content' => $data['content'],
+ 'event_date' => $data['event_date'],
+ 'post_cids' => isset($data['post_cids']) ? $this->cleanCids($data['post_cids']) : '',
+ 'created' => $now->format('Y-m-d H:i:s'),
+ 'modified' => $now->format('Y-m-d H:i:s'),
+ 'status' => 1
+ );
+
+ // 使用Typecho的查询构建器,但先验证数据
+ $this->validateInsertData($insert);
+
+ // 修复:正确构建并执行插入查询
+ // 在Typecho中,insert()->rows()需要调用query()方法来执行
+ $query = $this->db->insert($this->prefix . 'changelog')->rows($insert);
+
+ // 执行查询
+ $this->db->query($query);
+
+ // 获取自增ID
+ // 注意:不能写成 $db->select('LAST_INSERT_ID() as id') 而不带 from(),
+ // Typecho 的查询构建器会生成 "SELECT LAST_INSERT_ID() as id FROM"(表名缺失),
+ // MySQL 直接报 1064 near '' at line 1,于是数据已经插入成功却抛出"发布失败"
+ return $this->getLastInsertId();
+
+ } catch (Exception $e) {
+ error_log("addEntry Error: " . $e->getMessage());
+ error_log("Data: " . print_r($data, true));
+ throw new Exception("发布失败: " . $e->getMessage());
+ }
+ }
+
+ /**
+ * 安全地获取刚插入记录的自增ID
+ *
+ * 走数据库适配器的 lastInsertId(),而不是拼一条 SELECT 查询;
+ * 取不到时退回"查最大 id"的兜底方案,保证不会因为取 ID 失败而让
+ * 已经成功的插入操作报错。
+ *
+ * @return int
+ */
+ private function getLastInsertId()
+ {
+ if (method_exists($this->db, 'getAdapter')) {
+ try {
+ $adapter = $this->db->getAdapter();
+ if (is_object($adapter) && method_exists($adapter, 'lastInsertId')) {
+ $id = (int) $adapter->lastInsertId();
+ if ($id > 0) {
+ return $id;
+ }
+ }
+ } catch (Throwable $e) {
+ // 适配器不支持时忽略,继续走兜底方案
+ }
+ }
+
+ // 兜底:取当前最大 id(表按 id 自增,刚插入的即最大 id)
+ $query = $this->db->select('id')
+ ->from($this->prefix . 'changelog')
+ ->order('id', Typecho_Db::SORT_DESC)
+ ->limit(1);
+ $row = $this->db->fetchRow($query);
+
+ return $row && isset($row['id']) ? (int) $row['id'] : 0;
+ }
+
+ /**
+ * 验证插入数据
+ */
+ private function validateInsertData(&$data)
+ {
+ // 确保所有必需字段都有值
+ if (empty($data['content'])) {
+ throw new Exception("内容不能为空");
+ }
+
+ if (empty($data['event_date'])) {
+ throw new Exception("日期不能为空");
+ }
+
+ // 验证日期时间并统一成 Y-m-d H:i:s(只填日期时按 00:00:00 处理)
+ $data['event_date'] = $this->normalizeEventDate($data['event_date']);
+
+ // 清理和转义内容
+ $data['content'] = trim($data['content']);
+ if (empty($data['content'])) {
+ throw new Exception("内容不能为空");
+ }
+
+ // 确保所有字段都是字符串
+ foreach ($data as $key => $value) {
+ if (!is_string($value) && !is_numeric($value)) {
+ $data[$key] = (string)$value;
+ }
+ }
+ }
+
+ /**
+ * 批量添加更新记录(按事件时间排序插入,越近的ID越大)
+ */
+ public function batchAddEntries($entries)
+ {
+ // 按事件时间排序,越近的时间越晚插入,这样ID越大
+ usort($entries, function($a, $b) {
+ return strtotime($a['event_date']) - strtotime($b['event_date']);
+ });
+
+ $now = new Typecho_Date(Typecho_Date::gmtTime());
+ $nowStr = $now->format('Y-m-d H:i:s');
+
+ foreach ($entries as $entry) {
+ $insert = array(
+ 'content' => $entry['content'],
+ 'event_date' => $this->normalizeEventDate($entry['event_date']),
+ 'post_cids' => '',
+ 'created' => $nowStr,
+ 'modified' => $nowStr,
+ 'status' => 1
+ );
+
+ $query = $this->db->insert($this->prefix . 'changelog')->rows($insert);
+ $this->db->query($query);
+ }
+ }
+
+ /**
+ * 更新更新记录
+ */
+ public function updateEntry($data)
+ {
+ try {
+ $now = new Typecho_Date(Typecho_Date::gmtTime());
+
+ $update = array(
+ 'content' => $data['edit_content'],
+ 'event_date' => $this->normalizeEventDate($data['edit_event_date']),
+ 'post_cids' => isset($data['edit_post_cids']) ? $this->cleanCids($data['edit_post_cids']) : '',
+ 'modified' => $now->format('Y-m-d H:i:s')
+ );
+
+ $query = $this->db->update($this->prefix . 'changelog')
+ ->rows($update)
+ ->where('id = ?', intval($data['edit_id']));
+
+ $this->db->query($query);
+
+ } catch (Exception $e) {
+ error_log("updateEntry Error: " . $e->getMessage());
+ throw new Exception("更新失败: " . $e->getMessage());
+ }
+ }
+
+ /**
+ * 删除更新记录
+ */
+ public function deleteEntry($id)
+ {
+ $query = $this->db->delete($this->prefix . 'changelog')->where('id = ?', intval($id));
+ $this->db->query($query);
+ }
+
+ /**
+ * 批量删除
+ */
+ public function deleteEntries($ids)
+ {
+ foreach ($ids as $id) {
+ $this->deleteEntry(intval($id));
+ }
+ }
+
+ /**
+ * 获取更新记录
+ *
+ * 2.0.10:$keyword 非空时按「内容」模糊匹配(后台管理列表的搜索框用)。
+ * 关键词一律走参数绑定,不拼进 SQL;% 和 _ 不做转义 —— 这样搜
+ * xiaoaji_2026 这类带下划线的内容能按字面量命中,代价只是手输 % 会变成
+ * 模糊通配(等于放宽条件,不会出错)。
+ */
+ public function getEntries($page = 1, $perPage = 10, $keyword = '')
+ {
+ $offset = ($page - 1) * $perPage;
+
+ // 2.0.2:与前台同口径,按事件时间倒序,id 只做同刻稳定次序
+ $query = $this->db->select()
+ ->from($this->prefix . 'changelog')
+ ->where('status = ?', 1);
+
+ $keyword = trim((string) $keyword);
+ if ($keyword !== '') {
+ $query->where('content LIKE ?', '%' . $keyword . '%');
+ }
+
+ $query->order('event_date', Typecho_Db::SORT_DESC)
+ ->order('id', Typecho_Db::SORT_ASC)
+ ->limit($perPage)
+ ->offset($offset);
+
+ return $this->db->fetchAll($query);
+ }
+
+ /**
+ * 获取所有更新记录(用于导出)
+ */
+ public function getAllEntries()
+ {
+ // 2.0.2:导出也按事件时间倒序(与页面一致);再导入时 batchAddEntries
+ // 会按时间升序重新插入,同刻条目保持原相对顺序,来回导不会打乱
+ $query = $this->db->select()
+ ->from($this->prefix . 'changelog')
+ ->where('status = ?', 1)
+ ->order('event_date', Typecho_Db::SORT_DESC)
+ ->order('id', Typecho_Db::SORT_ASC);
+
+ return $this->db->fetchAll($query);
+ }
+
+ /**
+ * 获取总记录数
+ *
+ * 2.0.10:传了 $keyword 就只数匹配的记录(后台分页要用),不传则是全库总数
+ * (统计卡片「总记录数」用,搜索时不应该跟着变小)。
+ */
+ public function getTotalCount($keyword = '')
+ {
+ $query = $this->db->select('COUNT(*) as count')
+ ->from($this->prefix . 'changelog')
+ ->where('status = ?', 1);
+
+ $keyword = trim((string) $keyword);
+ if ($keyword !== '') {
+ $query->where('content LIKE ?', '%' . $keyword . '%');
+ }
+
+ $result = $this->db->fetchRow($query);
+ return $result['count'];
+ }
+
+ /**
+ * 获取单条记录
+ */
+ public function getEntry($id)
+ {
+ $query = $this->db->select()
+ ->from($this->prefix . 'changelog')
+ ->where('id = ?', $id)
+ ->limit(1);
+
+ return $this->db->fetchRow($query);
+ }
+
+ /**
+ * 根据文章CID获取文章信息
+ */
+ public function getPostByCid($cid)
+ {
+ try {
+ $query = $this->db->select('cid, title, slug, created')
+ ->from($this->prefix . 'contents')
+ ->where('cid = ?', intval($cid))
+ ->where('type = ?', 'post')
+ ->where('status = ?', 'publish')
+ ->limit(1);
+
+ $post = $this->db->fetchRow($query);
+
+ if ($post) {
+ $options = Typecho_Widget::widget('Widget_Options');
+ if (!empty($post['slug'])) {
+ $post['url'] = Typecho_Common::url($post['slug'] . '.html', $options->index);
+ } else {
+ $post['url'] = Typecho_Common::url('archives/' . $post['cid'], $options->index);
+ }
+ }
+
+ return $post;
+ } catch (Exception $e) {
+ return null;
+ }
+ }
+
+ /**
+ * 清理CID字符串
+ */
+ private function cleanCids($cids)
+ {
+ if (empty($cids)) {
+ return '';
+ }
+
+ $cidsArray = array_filter(array_map('trim', explode(',', $cids)));
+ $validCids = array();
+
+ foreach ($cidsArray as $cid) {
+ if (is_numeric($cid) && $cid > 0) {
+ $validCids[] = intval($cid);
+ }
+ }
+
+ // 去重并返回逗号分隔的字符串
+ return implode(',', array_unique($validCids));
+ }
+
+ /**
+ * 导出数据为文本格式
+ */
+ public function exportData()
+ {
+ $entries = $this->getAllEntries();
+ $content = '';
+
+ foreach ($entries as $entry) {
+ // 使用 Y.m.d H:i:s 格式导出,日期后空格接时分秒
+ $date = $this->formatEventDate($entry['event_date'], 'Y.m.d');
+ $text = str_replace(array("\r\n", "\r", "\n"), " ", $entry['content']);
+ $content .= $date . ' ' . $text . "\n";
+ }
+
+ return $content;
+ }
+
+ /**
+ * 导入数据(增强版,支持调试)
+ */
+ public function importData($text)
+ {
+ // 标准化换行符
+ $text = str_replace("\r\n", "\n", $text);
+ $text = str_replace("\r", "\n", $text);
+
+ $lines = explode("\n", $text);
+ $imported = 0;
+ $failed = 0;
+ $failReasons = array(); // 记录失败原因
+ $entries = array();
+
+ foreach ($lines as $lineNum => $line) {
+ $line = trim($line);
+ if (empty($line)) continue;
+
+ // 移除行尾的分号(如果有)
+ if (substr($line, -1) === ';') {
+ $line = substr($line, 0, -1);
+ $line = trim($line);
+ }
+
+ // 找到第一个空格的位置来分割日期和内容
+ $firstSpacePos = strpos($line, ' ');
+ if ($firstSpacePos === false) {
+ $failed++;
+ $failReasons[] = "第 " . ($lineNum + 1) . " 行:找不到空格分隔日期和内容 - '{$line}'";
+ continue;
+ }
+
+ $date = trim(substr($line, 0, $firstSpacePos));
+ $content = trim(substr($line, $firstSpacePos + 1));
+
+ // 验证日期格式 - 支持单个数字的月份和日期
+ // 允许的格式:YYYY.M.D, YYYY.MM.D, YYYY.M.DD, YYYY.MM.DD
+ $datePattern = '/^(\d{4})\.(\d{1,2})\.(\d{1,2})$/';
+ if (!preg_match($datePattern, $date, $matches)) {
+ $failed++;
+ $failReasons[] = "第 " . ($lineNum + 1) . " 行:日期格式错误,应为 YYYY.M[M].D[D] - '{$date}'";
+ continue;
+ }
+
+ // 检查日期是否有效
+ $year = intval($matches[1]);
+ $month = intval($matches[2]);
+ $day = intval($matches[3]);
+
+ if (!checkdate($month, $day, $year)) {
+ $failed++;
+ $failReasons[] = "第 " . ($lineNum + 1) . " 行:无效的日期 - {$date}";
+ continue;
+ }
+
+ // 日期后可能紧跟时分秒(导出文件就是这种格式),有就取出来,没有按 00:00:00 处理
+ $timePart = '00:00:00';
+ $restParts = preg_split('/\s+/', $content, 2);
+ $maybeTime = isset($restParts[0]) ? trim($restParts[0]) : '';
+
+ if (preg_match('/^(\d{1,2}):(\d{1,2})(?::(\d{1,2}))?$/', $maybeTime, $timeMatches)) {
+ $hour = intval($timeMatches[1]);
+ $minute = intval($timeMatches[2]);
+ $second = (isset($timeMatches[3]) && $timeMatches[3] !== '') ? intval($timeMatches[3]) : 0;
+
+ if ($hour > 23 || $minute > 59 || $second > 59) {
+ $failed++;
+ $failReasons[] = "第 " . ($lineNum + 1) . " 行:无效的时间 - {$maybeTime}";
+ continue;
+ }
+
+ $timePart = sprintf('%02d:%02d:%02d', $hour, $minute, $second);
+ $content = isset($restParts[1]) ? trim($restParts[1]) : '';
+ }
+
+ // 转换日期格式为 Y-m-d H:i:s 以便数据库存储,补零成两位数字
+ $dbDate = sprintf('%04d-%02d-%02d', $year, $month, $day) . ' ' . $timePart;
+
+ // 验证内容
+ if (empty($content)) {
+ $failed++;
+ $failReasons[] = "第 " . ($lineNum + 1) . " 行:内容为空";
+ continue;
+ }
+
+ $entries[] = array(
+ 'event_date' => $dbDate,
+ 'content' => $content
+ );
+ $imported++;
+ }
+
+ if (!empty($entries)) {
+ $this->batchAddEntries($entries);
+ }
+
+ // 返回包含失败原因的结果
+ return array(
+ 'imported' => $imported,
+ 'failed' => $failed,
+ 'fail_reasons' => $failReasons
+ );
+ }
+}
\ No newline at end of file
diff --git a/CHANGELOG.md b/CHANGELOG.md
new file mode 100644
index 0000000..ae2bb96
--- /dev/null
+++ b/CHANGELOG.md
@@ -0,0 +1,169 @@
+# ChangeLog 更新日志
+
+> 本文件记录本插件的所有修改与变化。本次整理(2026-11-22)为规范化记录起点。
+
+## 插件信息
+
+- 名称:ChangeLog
+- 版本:2.0.10
+- 作者:石头厝
+- 说明:更新日志插件
+
+## 记录格式约定
+
+每次修改按如下格式在**最上方**追加一条记录(新的在上):
+
+```
+## YYYY-MM-DD · 版本号 —— 一句话概述
+
+- 改动点 1
+- 改动点 2
+- 影响范围 / 注意事项(若有)
+- 对应备份:备份/YYYY-MM-DD-修改内容简短说明修改前/
+```
+
+## 2026-11-23 · 2.0.10 —— 后台管理列表加搜索框(居中放在「已选择」与「删除选中」之间)
+
+- 需求:后台更新记录列表在「已选择 N 条」和「删除选中」中间放一个搜索框,实现记录搜索
+- 位置:表头批量操作栏正中间。该栏原来是 `flex + space-between`,中间放东西会因左右宽度
+ 不等而偏,改成三列 grid(`1fr auto 1fr`),搜索框落在真正的水平中心
+- 搜索实现(**后端过滤,跨页生效**,不是只过滤当前页):
+ - `Action::getEntries($page, $perPage, $keyword)` 与 `getTotalCount($keyword)` 增加关键词参数,
+ `content LIKE ?` 走参数绑定;`%` `_` 不转义,这样搜 `xiaoaji_2026` 这类带下划线的能按字面量命中
+ - 关键词从 `?q=` 读取,长度上限 50 字;分页链接、删除/编辑/新增后的重定向都带上 `&q=`,
+ 搜索状态下翻页、删记录不会丢关键词
+ - 统计卡片的「总记录数」始终显示全库总数,不跟着搜索结果变小;列表标题旁另显示
+ 「搜索「xxx」· 匹配 N 条」
+- **避免误删的关键处理**:搜索框位于 `#mainForm` 内部,如果做成真正的 form 提交,勾选了记录时
+ 按回车会连带提交 `delete_ids` 直接删数据。所以:input 用 `form="cl-no-form"`(指向不存在的 id)
+ 脱离表单,回车由 JS `preventDefault` 后手工拼 URL 跳转,全程不触发 submit
+- 顺手修的两处:
+ - 搜索页表格整块不渲染时,`updateSelectedCount()` 里 `getElementById(...).textContent` 会报错,已判空
+ - 页码超出范围(例如停在第 5 页时搜到只有 1 页的关键词、删除后当前页空了)会把页码夹回
+ `1 ~ totalPages`,不再出现「明明有记录却显示空列表」
+- 无结果时(搜索框所在表单不渲染)单独输出一份搜索框,可直接改关键词;配「查看全部记录」链接
+- 样式:亮/暗两套(`#newadmin.dark` 用深色输入框 + 橙色焦点环),≤768px 恢复纵向堆叠、搜索框占满一行
+- 验证:抽真实 `
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ 0 || !empty($searchKeyword)): ?>
+
+
+
+ 搜索 "":找到 条记录 0): ?>(在 年中)
+
+ 当前筛选: 年( 条记录)
+
+
+ 清除筛选
+
+
+
+
+
+
+ 0)): ?>
+
+ 0): ?>
+ 未找到包含 "
" 的 年更新记录
+
+ 未找到包含 "
" 的更新记录
+ 0): ?>
+ 年暂无更新记录
+
+
+
+
+
+
+
+
+
+
+
+ dateFormat) ? $config->dateFormat : 'Y.m.d'); ?>
+
+
+
+ $1',
+ $content
+ );
+ }
+ echo nl2br($content);
+ ?>
+
+
+ showRelatedPosts) && $config->showRelatedPosts == 1 && !empty($entry['posts'])):
+ ?>
+
+
+ relatedPostsTitle) ? $config->relatedPostsTitle : '相关文章'; ?>
+
+
+
+
+
+
+
+
+
+ 1): ?>
+
+
+
+
+
+
+ 仓库:`ChangeLog` · 类型:Typecho 插件 · 版本:`2.0.10` · 作者:石头厝
+
+Typecho 站点更新日志插件,用于在后台维护站点更新记录,并在前端展示。本仓库仅包含插件实现代码与必要文档,不包含备份、运行时数据与调试日志。
+
+## 功能
+
+- 后台管理更新记录列表,支持批量选择与删除。
+- 列表搜索框位于批量操作栏正中,采用后端过滤,跨页生效。
+- 通过 `manage-panel.php` 提供后台管理面板,`Action.php` 处理管理端动作。
+- 版本与变更详情见 [CHANGELOG.md](CHANGELOG.md)。
+
+## 目录结构
+
+- `Plugin.php` —— 插件入口、钩子注册与前台展示逻辑
+- `Action.php` —— 后台管理动作处理
+- `manage-panel.php` —— 后台管理面板视图
+
+## 安装与使用
+
+1. 将本仓库目录复制到 Typecho 站点的 `usr/plugins/ChangeLog/`。
+2. 在 Typecho 后台「插件」管理中启用插件。
+3. 进入插件管理面板添加、编辑或删除更新记录;列表顶部搜索框可按关键词检索记录。
+
+## 开发与贡献
+
+详见 [CONTRIBUTING.md](CONTRIBUTING.md)。
+
+## 授权
+
+授权条款见 [LICENSE](LICENSE)(MIT License)。第三方组件版权归各自作者所有。
+
+## 变更记录
+
+详见 [CHANGELOG.md](CHANGELOG.md)。
diff --git a/manage-panel.php b/manage-panel.php
new file mode 100644
index 0000000..22cdeb1
--- /dev/null
+++ b/manage-panel.php
@@ -0,0 +1,2102 @@
+plugin('ChangeLog');
+
+/**
+ * 把表单里的"日期"和"时间"两个输入拼成 event_date
+ *
+ * 日期输入框给 Y-m-d,时间输入框给 H:i(:s),拼成 Y-m-d H:i:s;
+ * 时间没填时只传日期,由 Action 按 00:00:00 处理。
+ * 同时兼容直接提交 2026-10-27T11:07:16 这种 datetime 字符串的情况。
+ */
+if (!function_exists('changelogJoinDateTime')) {
+ function changelogJoinDateTime($date, $time = '')
+ {
+ $date = trim((string) $date);
+ $time = trim((string) $time);
+
+ if ($date === '') {
+ return '';
+ }
+
+ if (strpos($date, ' ') !== false || strpos($date, 'T') !== false) {
+ return str_replace('T', ' ', $date);
+ }
+
+ return $time === '' ? $date : $date . ' ' . $time;
+ }
+}
+
+/**
+ * 后台列表的日期时间显示:日期后空格显示时分秒
+ *
+ * 老数据只存了日期(时间为 00:00:00),这类记录只显示日期。
+ */
+if (!function_exists('changelogFormatDateTime')) {
+ function changelogFormatDateTime($value, $dateFormat = 'Y-m-d')
+ {
+ $timestamp = strtotime((string) $value);
+
+ if ($timestamp === false) {
+ return '';
+ }
+
+ $date = date($dateFormat, $timestamp);
+ $time = date('H:i:s', $timestamp);
+
+ return $time === '00:00:00' ? $date : $date . ' ' . $time;
+ }
+}
+
+/**
+ * 后台列表的搜索框(2.0.10)
+ *
+ * 有记录时放在表头工具栏的正中间(「已选择 N 条」与「删除选中」之间);
+ * 搜索无结果时整个表单不渲染,所以再单独输出一份($standalone = true),
+ * 让用户能直接改关键词,而不是只能点「查看全部记录」。
+ *
+ * 注意:这个 input 落在 mainForm 内部,用 form="cl-no-form"(指向不存在的 id)
+ * 让它脱离表单——否则按回车会提交 mainForm,勾选了记录时会误触发批量删除。
+ *
+ * @param string $keyword 当前搜索词
+ * @param string $panelPath 本面板地址(不含 query)
+ * @param bool $standalone 是否用于无结果时单独一行
+ * @return string
+ */
+if (!function_exists('changelogSearchBox')) {
+ function changelogSearchBox($keyword, $panelPath, $standalone = false)
+ {
+ $kw = htmlspecialchars((string) $keyword, ENT_QUOTES, 'UTF-8');
+ $path = htmlspecialchars((string) $panelPath, ENT_QUOTES, 'UTF-8');
+ $idSuffix = $standalone ? '-empty' : '';
+
+ $clear = '';
+ if ($keyword !== '') {
+ $clear = '清除';
+ }
+
+ return ''
+ . ''
+ . ''
+ . $clear
+ . '
';
+ }
+}
+
+// 引入Action类
+require_once __DIR__ . '/Action.php';
+$action = new ChangeLog_Action();
+
+// 获取当前页码
+$page = isset($_GET['page']) ? intval($_GET['page']) : 1;
+$perPage = isset($config->perPage) ? intval($config->perPage) : 10;
+if ($perPage < 1) {
+ $perPage = 10;
+}
+
+// 搜索关键词(2.0.10:后台列表按「内容」过滤,跨页生效)
+// 长度限一下,避免超长串拼进 LIKE;% 和 _ 不转义,理由见 Action::getEntries()
+$keyword = isset($_GET['q']) ? trim((string) $_GET['q']) : '';
+if (mb_strlen($keyword, 'UTF-8') > 50) {
+ $keyword = mb_substr($keyword, 0, 50, 'UTF-8');
+}
+// 拼在分页 / 重定向链接后面的参数(带 & 前缀,空搜索时不加)
+$keywordParam = $keyword === '' ? '' : '&q=' . urlencode($keyword);
+// 本面板自己的地址:后台目录可能被改过(/admin/ 或别的),统一从当前请求取路径
+$panelPath = strtok((string) $_SERVER['REQUEST_URI'], '?');
+if (!$panelPath) {
+ $panelPath = (string) $_SERVER['PHP_SELF'];
+}
+
+// 处理表单提交
+if ($_SERVER['REQUEST_METHOD'] === 'POST') {
+ // 处理新增 - 关键:处理完后不重定向,刷新当前页面
+ // 在manage-panel.php中修改发布处理部分(第29-38行):
+ // 处理新增
+ if (!empty($_POST['content'])) {
+ try {
+ $action->addEntry(array(
+ 'content' => $_POST['content'],
+ 'event_date' => changelogJoinDateTime(
+ isset($_POST['event_date']) ? $_POST['event_date'] : '',
+ isset($_POST['event_time']) ? $_POST['event_time'] : ''
+ ),
+ 'post_cids' => isset($_POST['post_cids']) ? $_POST['post_cids'] : ''
+ ));
+
+ $successMsg = '记录添加成功!';
+ // 添加滚动到列表的锚点(新记录排在最前,固定回到第 1 页)
+ header('Location: ' . $_SERVER['PHP_SELF'] . '?panel=ChangeLog/manage-panel.php&page=1' . $keywordParam . '#cl-list-anchor');
+ exit;
+ } catch (Exception $e) {
+ // 走到这里是插入前的校验失败或插入本身失败,数据并没有写入,
+ // 因此必须按"错误"提示,不能再显示成"已添加但有警告"
+ $errorMsg = htmlspecialchars($e->getMessage());
+ }
+ }
+
+ // 处理批量删除
+ if (!empty($_POST['delete_ids']) && is_array($_POST['delete_ids'])) {
+ $action->deleteEntries($_POST['delete_ids']);
+ $successMsg = '删除成功!';
+ // 添加滚动到列表的锚点
+ header('Location: ' . $_SERVER['PHP_SELF'] . '?panel=ChangeLog/manage-panel.php&page=' . $page . $keywordParam . '#cl-list-anchor');
+ exit;
+ }
+
+ // 处理编辑
+ if (!empty($_POST['edit_id'])) {
+ $action->updateEntry(array(
+ 'edit_id' => $_POST['edit_id'],
+ 'edit_content' => $_POST['edit_content'],
+ 'edit_event_date' => changelogJoinDateTime(
+ isset($_POST['edit_event_date']) ? $_POST['edit_event_date'] : '',
+ isset($_POST['edit_event_time']) ? $_POST['edit_event_time'] : ''
+ ),
+ 'edit_post_cids' => isset($_POST['edit_post_cids']) ? $_POST['edit_post_cids'] : ''
+ ));
+ $successMsg = '记录更新成功!';
+ // 添加滚动到列表的锚点
+ header('Location: ' . $_SERVER['PHP_SELF'] . '?panel=ChangeLog/manage-panel.php&page=' . $page . $keywordParam . '#cl-list-anchor');
+ exit;
+ }
+
+ // 处理导出
+ if (isset($_POST['export'])) {
+ $exportContent = $action->exportData();
+ $filename = 'changelog_' . date('Ymd_His') . '.txt';
+
+ header('Content-Type: text/plain');
+ header('Content-Disposition: attachment; filename="' . $filename . '"');
+ header('Content-Length: ' . strlen($exportContent));
+ echo $exportContent;
+ exit;
+ }
+
+ // 处理导入
+ if (isset($_POST['import']) && !empty($_FILES['import_file']['tmp_name'])) {
+ $fileContent = file_get_contents($_FILES['import_file']['tmp_name']);
+ $result = $action->importData($fileContent);
+
+ if ($result['imported'] > 0) {
+ $successMsg = '导入成功!成功导入 ' . $result['imported'] . ' 条记录';
+ if ($result['failed'] > 0) {
+ $successMsg .= ',失败 ' . $result['failed'] . ' 条记录';
+
+ // 显示失败原因(限制显示前10条)
+ if (!empty($result['fail_reasons'])) {
+ $errorDetails = '失败原因:
';
+ $displayCount = min(10, count($result['fail_reasons']));
+ for ($i = 0; $i < $displayCount; $i++) {
+ $errorDetails .= htmlspecialchars($result['fail_reasons'][$i]) . '
';
+ }
+ if (count($result['fail_reasons']) > 10) {
+ $errorDetails .= '...还有 ' . (count($result['fail_reasons']) - 10) . ' 条失败记录';
+ }
+ $errorMsg = $errorDetails;
+ }
+ }
+ } else {
+ $errorMsg = '导入失败!未找到可导入的记录或格式不正确';
+ if (!empty($result['fail_reasons'])) {
+ $errorMsg .= '
失败原因:
';
+ $displayCount = min(10, count($result['fail_reasons']));
+ for ($i = 0; $i < $displayCount; $i++) {
+ $errorMsg .= htmlspecialchars($result['fail_reasons'][$i]) . '
';
+ }
+ }
+ }
+ }
+}
+
+// 获取记录
+// 先数总数再查列表:搜索/删除后页码可能超界(比如停在第 5 页时搜到只有 1 页的关键词),
+// 这里把页码夹回有效范围,避免看到「明明有记录却显示空列表」。
+$total = $action->getTotalCount($keyword); // 搜索时为匹配条数,供分页用
+$totalAll = $action->getTotalCount(); // 全库总数,统计卡片用(搜索时不该跟着变小)
+$totalPages = max(1, (int) ceil($total / $perPage));
+
+if ($page < 1) {
+ $page = 1;
+} elseif ($page > $totalPages) {
+ $page = $totalPages;
+}
+
+$entries = $action->getEntries($page, $perPage, $keyword);
+?>
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
导出数据
+
导出所有更新记录为文本文件格式
+
+
+
+
+
+
+
导入数据
+
从文本文件导入更新记录
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ 更新记录列表
+
+
+ 搜索「」· 匹配 条
+
+
+
+
+
+
+
+
+
+
+ 暂无更新记录,请先添加记录
+
+
+
+
+
+
+ 1): ?>
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file