getPrefix(); $tableName = $prefix . 'memo'; // 检查表是否存在 $tables = $db->fetchAll($db->query("SHOW TABLES LIKE '{$tableName}'")); if (empty($tables)) { // 创建新表 $sql = "CREATE TABLE `{$tableName}` ( `id` INT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY, `content` TEXT NOT NULL COMMENT '内容', `category` VARCHAR(100) DEFAULT '默认' COMMENT '分类', `event_date` DATE NULL COMMENT '事件日期(可选)', `post_cids` VARCHAR(255) DEFAULT '' COMMENT '关联文章CID,多个用逗号分隔', `original_url` VARCHAR(500) DEFAULT '' COMMENT '原文链接', `created` DATETIME NOT NULL COMMENT '创建时间', `modified` DATETIME NOT NULL COMMENT '修改时间', `status` TINYINT(1) DEFAULT 1 COMMENT '状态:1正常' ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='备忘录记录表';"; try { $db->query($sql); } catch (Typecho_Db_Exception $e) { throw new Typecho_Plugin_Exception('创建数据表失败: ' . $e->getMessage()); } } else { // 检查表结构,如果缺少original_url字段则添加 $columns = $db->fetchAll($db->query("SHOW COLUMNS FROM `{$tableName}`")); $hasOriginalUrl = false; foreach ($columns as $column) { if ($column['Field'] == 'original_url') { $hasOriginalUrl = true; break; } } if (!$hasOriginalUrl) { // 添加original_url字段 try { $db->query("ALTER TABLE `{$tableName}` ADD COLUMN `original_url` VARCHAR(500) DEFAULT '' COMMENT '原文链接' AFTER `post_cids`"); } catch (Typecho_Db_Exception $e) { error_log("添加original_url字段失败: " . $e->getMessage()); } } } // 添加管理菜单 Helper::addPanel(3, 'Memo/manage-panel.php', '知识备忘', '备忘管理', 'administrator'); return _t('备忘录插件已激活,请到插件设置中进行配置'); } /** * 禁用插件 */ public static function deactivate() { Helper::removePanel(3, 'Memo/manage-panel.php'); return _t('备忘录插件已禁用'); } /** * 插件配置面板 */ public static function config(Typecho_Widget_Helper_Form $form) { // 每页显示数量 $perPage = new Typecho_Widget_Helper_Form_Element_Text( 'perPage', NULL, '30', _t('后台每页显示数量'), _t('后台管理页面每页显示的备忘录数量') ); $perPage->input->setAttribute('class', 'mini'); $form->addInput($perPage->addRule('isInteger', _t('请输入整数'))); // 前端每页显示数量 $frontPerPage = new Typecho_Widget_Helper_Form_Element_Text( 'frontPerPage', NULL, '20', _t('主题调用每页显示数量'), _t('在主题中调用时每页显示的备忘录数量') ); $frontPerPage->input->setAttribute('class', 'mini'); $form->addInput($frontPerPage->addRule('isInteger', _t('请输入整数'))); // 默认分类设置 $defaultCategories = new Typecho_Widget_Helper_Form_Element_Textarea( 'defaultCategories', NULL, "技术/经验\n公司/副业\n户外/亲子\n主题/插件\n兴趣/爱好\n工作/效率\n创作/媒体\n个人/成长\n程序/应用", _t('默认分类'), _t('每行一个分类,回车分隔。这些分类将在发布和编辑时显示在下拉框中。') ); $form->addInput($defaultCategories); // 是否显示事件时间 $showEventDate = new Typecho_Widget_Helper_Form_Element_Radio( 'showEventDate', array( '1' => _t('显示'), '0' => _t('不显示') ), '1', _t('显示事件时间'), _t('是否在备忘录中显示事件时间(如果设置了的话)') ); $form->addInput($showEventDate); // 是否显示关联文章 $showRelatedPosts = new Typecho_Widget_Helper_Form_Element_Radio( 'showRelatedPosts', array( '1' => _t('显示'), '0' => _t('不显示') ), '1', _t('显示关联文章'), _t('是否在备忘录下方显示关联的文章链接') ); $form->addInput($showRelatedPosts); // 关联文章标题 $relatedPostsTitle = new Typecho_Widget_Helper_Form_Element_Text( 'relatedPostsTitle', NULL, '相关文章', _t('关联文章标题'), _t('关联文章部分的标题文本') ); $form->addInput($relatedPostsTitle); } /** * 个人用户配置 */ public static function personalConfig(Typecho_Widget_Helper_Form $form) { // 个人配置(如果需要) } /** * 插件配置面板 */ public static function configPanel($panel) { // 配置面板 } /** * 渲染方法(用于在主题模板中调用) */ public static function render() { // 获取配置 $options = Typecho_Widget::widget('Widget_Options'); $config = $options->plugin('Memo'); // 引入Action类 require_once dirname(__FILE__) . '/Action.php'; $action = new Memo_Action(); // 参数处理 $currentFile = basename($_SERVER['PHP_SELF']); $selectedCategory = isset($_GET['cat']) ? trim($_GET['cat']) : ''; $searchKeyword = isset($_GET['search']) ? trim(urldecode($_GET['search'])) : ''; $currentPage = isset($_GET['page']) && $_GET['page'] > 0 ? intval($_GET['page']) : 1; $perPage = isset($config->frontPerPage) ? intval($config->frontPerPage) : 20; // 获取分类列表 $categories = $action->getAllCategories(); $categoryCounts = $action->getCategoryCounts(); // 获取备忘录数据 $memos = $action->getMemos($currentPage, $perPage, $searchKeyword, $selectedCategory); $total = $action->getTotalCount($searchKeyword, $selectedCategory); $totalPages = ceil($total / $perPage); // 如果没有数据 if (empty($memos) && empty($searchKeyword) && empty($selectedCategory)) { echo '
暂无备忘录记录
'; return; } // 为每条记录获取关联的文章信息 foreach ($memos as &$memo) { if (!empty($memo['post_cids'])) { $cids = array_filter(array_map('trim', explode(',', $memo['post_cids']))); $posts = array(); foreach ($cids as $cid) { if (is_numeric($cid)) { $post = $action->getPostByCid($cid); if ($post) { $posts[] = $post; } } } $memo['posts'] = $posts; } else { $memo['posts'] = array(); } } ?>

备忘录

搜索"",分类"",共找到 条记录 搜索"",共找到 条记录 分类"",共 条记录
showEventDate) && $config->showEventDate == 1): ?>
' . htmlspecialchars($url) . '' . $suffix; }, $content ); if (!empty($searchKeyword)) { $searchEncoded = htmlspecialchars($searchKeyword); $content = preg_replace( '/(' . preg_quote($searchEncoded, '/') . ')/i', '$1', $content ); } echo nl2br($content); ?>
showRelatedPosts) && $config->showRelatedPosts == 1 && !empty($memo['posts'])): ?>
1): ?>
1): ?> 上一页 1): ?> 1 2): ?>... ... 下一页
没有找到符合条件的备忘录 暂无备忘录记录