From 24e1100a1bb3e72e90cf60b3849761ca200dca12 Mon Sep 17 00:00:00 2001 From: Dylan Wu Date: Mon, 4 Aug 2025 10:23:35 -0400 Subject: [PATCH] fix Plugins active --- Plugin.php | 28 +++++++++++++++++----------- 1 file changed, 17 insertions(+), 11 deletions(-) diff --git a/Plugin.php b/Plugin.php index d828a44..1192ce8 100644 --- a/Plugin.php +++ b/Plugin.php @@ -3,21 +3,27 @@ * 页面黑白显示插件(支持时间段、指定日期、每月/每年循环) * * @package GrayModePlugin - * @author Your - * @version 1.1.0 + * @author DylanWu + * @version 1.1.1 * @link https://your.site */ -class GrayModePlugin implements Typecho_Plugin_Interface +class GrayMode_Plugin implements Typecho_Plugin_Interface { - public static function activate() - { - Typecho_Plugin::factory('Widget_Archive')->header = [__CLASS__, 'changeheader']; - } + public static function activate() + { + Typecho_Plugin::factory('Widget_Archive')->header = __CLASS__ . '::render'; + } public static function deactivate() {} public static function config(Typecho_Widget_Helper_Form $form) { + try { + $options = Typecho_Widget::widget('Widget_Options')->plugin('GrayModePlugin'); + // 可选:读取配置值 + } catch (Exception $e) { + // 不处理配置读取错误 + } $start = new Typecho_Widget_Helper_Form_Element_Text( 'startTime', NULL, '00:00', '开始时间', '格式如 08:00' ); @@ -42,13 +48,13 @@ class GrayModePlugin implements Typecho_Plugin_Interface public static function personalConfig(Typecho_Widget_Helper_Form $form) {} - public static function changeheader() + public static function render($archive) { $options = Typecho_Widget::widget('Widget_Options')->plugin('GrayModePlugin'); - $start = $options->startTime; - $end = $options->endTime; - $dates = trim($options->specialDates); + $start = $options->startTime ?? '00:00'; + $end = $options->endTime ?? '23:59'; + $dates = isset($options->specialDates) ? trim($options->specialDates) : ''; $now = date('H:i'); // 判断是否在时间区间内