From 767ae06724683fa94fc0082ee2b2064ef14215ab Mon Sep 17 00:00:00 2001 From: NHPT Date: Mon, 17 Aug 2026 01:44:40 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=EF=BC=9A=E5=88=86=E7=A6=BB?= =?UTF-8?q?=E7=AB=99=E9=95=BF=E4=B8=8E=E4=BD=9C=E8=80=85=E8=AF=84=E8=AE=BA?= =?UTF-8?q?=E9=80=9A=E7=9F=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Plugin.php | 52 +++++++++++++++++++++++++++++++++++----------------- 1 file changed, 35 insertions(+), 17 deletions(-) diff --git a/Plugin.php b/Plugin.php index cadb000..06e8235 100644 --- a/Plugin.php +++ b/Plugin.php @@ -197,10 +197,18 @@ public static function config(Form $form) // 收件邮箱 $adminfrom = new Form\Element\Text('adminfrom', NULL, NULL, _t('站长收件邮箱'), _t('遇到待审核评论或文章作者邮箱为空时,评论提醒会发送到此邮箱地址!')); - $form->addInput($adminfrom->addRule('required', _t('收件邮箱必填!'))); - - $zznotice = new Form\Element\Radio('zznotice', array('0' => _t('通知'), '1' => _t('不通知'),), '0', _t('是否通知站长'), _t('因为站长可能有其他接受评论通知的方式,不想在重复接受邮件通知可选择不通知')); + + $zznoticeValue = \Typecho\Request::getInstance()->get('zznotice'); + if (null === $zznoticeValue && empty($_GET['activate'])) { + $plugin = Helper::options()->plugin('CommentNotifier'); + $zznoticeValue = isset($plugin->zznotice) ? $plugin->zznotice : '0'; + } + if ('1' !== (string) $zznoticeValue) { + $adminfrom->addRule('required', _t('启用站长通知时必须填写收件邮箱!')); + } + $adminfrom->addRule('email', _t('站长收件邮箱格式错误!')); + $form->addInput($adminfrom); $form->addInput($zznotice); @@ -317,7 +325,6 @@ public static function mark($comment, $edit, $status) { $recipients = []; $plugin = Options::alloc()->plugin('CommentNotifier'); - $from = $plugin->adminfrom; // 站长邮箱 // 在后台标记评论状态为[approved 审核通过]时, 发信给上级评论人或作者 if ($status == 'approved') { $type = 0; @@ -333,10 +340,6 @@ public static function mark($comment, $edit, $status) if ($recipients[0]['mail'] == $edit->mail) { return; } - // 如果上级是博主, 不做任何操作 - if ($recipients[0]['mail'] == $from) { - return; - } //邮箱为空时就不发邮件 if (empty($recipients[0]['mail'])) { return; @@ -380,8 +383,21 @@ public static function refinishComment($comment) } self::sendMail($comment, $recipients, $type); } else { - // 如果所有评论必须经过审核, 通知博主审核评论 - $recipients[] = ['name' => $fromName, 'mail' => $from]; + // 待审评论通知文章作者 + if ($comment->status == 'waiting') { + $author = self::getAuthor($comment); + if ($comment->authorId != $comment->ownerId && $comment->mail != $author['mail'] && !empty($author['mail'])) { + $recipients[] = $author; + } + } + + // 按配置额外通知站长, 并避免与作者重复 + if ('1' !== (string) $plugin->zznotice && !empty($from)) { + $recipientMails = array_column($recipients, 'mail'); + if (!in_array($from, $recipientMails, true)) { + $recipients[] = ['name' => $fromName, 'mail' => $from]; + } + } self::sendMail($comment, $recipients, 2);//2为待审核评论 } } @@ -405,12 +421,15 @@ private static function sendMail($comment, array $recipients, $type) $Subject = '你的《' . $comment->title . '》文章有了新的评论'; } foreach ($recipients as $recipient) { - $param['to']=$recipient['mail']; // 收件地址 - $param['fromName']=$recipient['name']; // 收件人名称 - $param['subject']=$Subject; // 邮件标题 - $param['html']=self::mailBody($comment, $options, $type); // 邮件内容 - self::resendMail($param); - } + if (empty($recipient['mail'])) { + continue; + } + $param['to']=$recipient['mail']; // 收件地址 + $param['fromName']=$recipient['name']; // 收件人名称 + $param['subject']=$Subject; // 邮件标题 + $param['html']=self::mailBody($comment, $options, $type); // 邮件内容 + self::resendMail($param); + } } public static function resendMail($param) @@ -418,7 +437,6 @@ public static function resendMail($param) // 获取系统配置选项 $options = Options::alloc(); $plugin = $options->plugin('CommentNotifier'); - if($plugin->zznotice==1&&$param['to']==$plugin->adminfrom){return;}//不通知站长邮箱 if($plugin->yibu==1){ Helper::requestService('send', $param);