导出数据
导出所有历史记录为文本文件格式
2025.12.21 网站正式上线 2025.12.25 新增用户注册功能 2025.12.28 优化了网站性能
导入数据
从文本文件导入历史记录
每行一条记录,格式为:日期 内容日期格式:YYYY.M[M].D[D](支持单数字月份和日期) 例如:2023.12.9 网站更新例如:2023.8.8 新功能上线
提示:请确保文件编码为 UTF-8,每行一条记录
plugin('DevelopmentHistory');
// 引入Action类
require_once __DIR__ . '/Action.php';
$action = new DevelopmentHistory_Action();
// 获取当前页码
$page = isset($_GET['page']) ? intval($_GET['page']) : 1;
$perPage = isset($config->perPage) ? intval($config->perPage) : 10;
// 处理表单提交
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
// 处理新增 - 关键:处理完后不重定向,刷新当前页面
// 在manage-panel.php中修改发布处理部分(第29-38行):
// 处理新增
if (!empty($_POST['content'])) {
try {
$action->addHistory(array(
'content' => $_POST['content'],
'event_date' => $_POST['event_date'],
'post_cids' => isset($_POST['post_cids']) ? $_POST['post_cids'] : ''
));
$successMsg = '记录添加成功!';
// 添加滚动到列表的锚点
header('Location: ' . $_SERVER['PHP_SELF'] . '?panel=DevelopmentHistory/manage-panel.php&page=' . $page . '#history-list-anchor');
exit;
} catch (Exception $e) {
// 如果数据已保存但出现错误,只显示警告
$successMsg = '记录已添加,但出现警告:' . htmlspecialchars($e->getMessage());
}
}
// 处理批量删除
if (!empty($_POST['delete_ids']) && is_array($_POST['delete_ids'])) {
$action->deleteHistories($_POST['delete_ids']);
$successMsg = '删除成功!';
// 添加滚动到列表的锚点
header('Location: ' . $_SERVER['PHP_SELF'] . '?panel=DevelopmentHistory/manage-panel.php&page=' . $page . '#history-list-anchor');
exit;
}
// 处理编辑
if (!empty($_POST['edit_id'])) {
$action->updateHistory(array(
'edit_id' => $_POST['edit_id'],
'edit_content' => $_POST['edit_content'],
'edit_event_date' => $_POST['edit_event_date'],
'edit_post_cids' => isset($_POST['edit_post_cids']) ? $_POST['edit_post_cids'] : ''
));
$successMsg = '记录更新成功!';
// 添加滚动到列表的锚点
header('Location: ' . $_SERVER['PHP_SELF'] . '?panel=DevelopmentHistory/manage-panel.php&page=' . $page . '#history-list-anchor');
exit;
}
// 处理导出
if (isset($_POST['export'])) {
$exportContent = $action->exportData();
$filename = 'development_history_' . 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]) . '
';
}
}
}
}
}
// 获取记录
$histories = $action->getHistories($page, $perPage);
$total = $action->getTotalCount();
$totalPages = ceil($total / $perPage);
?>
导出所有历史记录为文本文件格式
2025.12.21 网站正式上线 2025.12.25 新增用户注册功能 2025.12.28 优化了网站性能
从文本文件导入历史记录
每行一条记录,格式为:日期 内容日期格式:YYYY.M[M].D[D](支持单数字月份和日期) 例如:2023.12.9 网站更新例如:2023.8.8 新功能上线
提示:请确保文件编码为 UTF-8,每行一条记录