Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 35 additions & 17 deletions Plugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);


Expand Down Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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为待审核评论
}
}
Expand All @@ -405,20 +421,22 @@ 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)
{
// 获取系统配置选项
$options = Options::alloc();
$plugin = $options->plugin('CommentNotifier');
if($plugin->zznotice==1&&$param['to']==$plugin->adminfrom){return;}//不通知站长邮箱

if($plugin->yibu==1){
Helper::requestService('send', $param);
Expand Down