Skip to content
Merged
Show file tree
Hide file tree
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
23 changes: 23 additions & 0 deletions Log.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?php
/**
* CommentToMail
* 调试日志工具
*
* Copied from https://stackoverflow.com/a/47235990
*/

function get_log($log_msg)
{
$log_filename = __DIR__ . "/log";
if (!file_exists($log_filename))
{
// create directory/folder uploads.
mkdir($log_filename, 0777, true);
}
$log_file_data = $log_filename . '/log.txt';
// if you don't add `FILE_APPEND`, the file will be erased each time you add a log
file_put_contents($log_file_data, "CommentToMail: " . $log_msg . "\n", FILE_APPEND);
}

// call to function
// get_log("this is my log message");
17 changes: 16 additions & 1 deletion Plugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@

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

require_once 'Log.php';

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

// 如果同步就直接发邮件,否则添加至队列
$keySync = Helper::options()->plugin('CommentToMail')->key;
$optionsSync = Widget::widget('Widget_Options');
$entryUrlSync = ($optionsSync->rewrite) ? $optionsSync->siteUrl : $optionsSync->siteUrl . 'index.php'; // 博客网址
$deliverUrlSync = rtrim($entryUrlSync, '/') . '/action/' . self::$_action . '?do=deliverMail&key=' . $keySync;;

$isSync = Helper::options()->plugin('CommentToMail')->other;
if (in_array('isSync', $isSync)){
file_get_contents($deliverUrlSync);
}
}

/**
* 通过邮件 博主 通过邮件后 回调函数
*
Expand All @@ -316,6 +330,7 @@ public static function passComment($comment, $edit, $status)
if ($status !== 'approved') return;
$edit->status = 'approved';
$edit->type = '1'; //标记 approved后的邮件 仅发送给访客 避免重复发送给博主

self::parseComment($edit);
}
}
Empty file removed log/.gitkeep
Empty file.