Skip to content

Commit ca76551

Browse files
authored
Merge pull request #6 from buzhangjiuzhou/main
add: sync support
2 parents e8066f0 + 766704c commit ca76551

3 files changed

Lines changed: 39 additions & 1 deletion

File tree

Log.php

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<?php
2+
/**
3+
* CommentToMail
4+
* 调试日志工具
5+
*
6+
* Copied from https://stackoverflow.com/a/47235990
7+
*/
8+
9+
function get_log($log_msg)
10+
{
11+
$log_filename = __DIR__ . "/log";
12+
if (!file_exists($log_filename))
13+
{
14+
// create directory/folder uploads.
15+
mkdir($log_filename, 0777, true);
16+
}
17+
$log_file_data = $log_filename . '/log.txt';
18+
// if you don't add `FILE_APPEND`, the file will be erased each time you add a log
19+
file_put_contents($log_file_data, "CommentToMail: " . $log_msg . "\n", FILE_APPEND);
20+
}
21+
22+
// call to function
23+
// get_log("this is my log message");

Plugin.php

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@
1919

2020
if (!defined('__TYPECHO_ROOT_DIR__')) exit;
2121

22+
require_once 'Log.php';
23+
2224
/**
2325
* Plugin
2426
*
@@ -203,6 +205,7 @@ public static function config(\Typecho\Widget\Helper\Form $form)
203205
'to_owner' => '有评论及回复时, 发邮件通知博主.',
204206
'to_guest' => '评论被回复时, 发邮件通知评论者.',
205207
'to_me' => '自己回复自己的评论时, 发邮件通知. (同时针对博主和访客)',
208+
'isSync' => '同步发送邮件,否则需要手动(或者用定时任务自动)执行发送任务',
206209
],
207210
['to_owner', 'to_guest'],
208211
'其他设置',
@@ -302,8 +305,19 @@ public static function parseComment($comment)
302305
'sent' => '0'
303306
])
304307
);
305-
}
306308

309+
// 如果同步就直接发邮件,否则添加至队列
310+
$keySync = Helper::options()->plugin('CommentToMail')->key;
311+
$optionsSync = Widget::widget('Widget_Options');
312+
$entryUrlSync = ($optionsSync->rewrite) ? $optionsSync->siteUrl : $optionsSync->siteUrl . 'index.php'; // 博客网址
313+
$deliverUrlSync = rtrim($entryUrlSync, '/') . '/action/' . self::$_action . '?do=deliverMail&key=' . $keySync;;
314+
315+
$isSync = Helper::options()->plugin('CommentToMail')->other;
316+
if (in_array('isSync', $isSync)){
317+
file_get_contents($deliverUrlSync);
318+
}
319+
}
320+
307321
/**
308322
* 通过邮件 博主 通过邮件后 回调函数
309323
*
@@ -316,6 +330,7 @@ public static function passComment($comment, $edit, $status)
316330
if ($status !== 'approved') return;
317331
$edit->status = 'approved';
318332
$edit->type = '1'; //标记 approved后的邮件 仅发送给访客 避免重复发送给博主
333+
319334
self::parseComment($edit);
320335
}
321336
}

log/.gitkeep

Whitespace-only changes.

0 commit comments

Comments
 (0)