Skip to content

Commit c694cf1

Browse files
committedMar 12, 2016
sync hacpai to wordpress
1 parent ec2ab45 commit c694cf1

File tree

3 files changed

+36
-4
lines changed

3 files changed

+36
-4
lines changed
 

‎README.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,15 @@
66
* [x] 博客发布博文 -> 社区发布帖子
77
* [x] 博客更新博文 -> 社区更新帖子
88
* [x] 博客发布评论 -> 社区发布回帖
9-
* [o] 社区发布回帖 -> 博客发布评论 <small>不知道Wordpress插件里面怎么调用方法库</small>
9+
* [x] 社区发布回帖 -> 博客发布评论
1010

1111
## 使用
1212
1. 放置插件到 Wordpress 的插件目录;
1313
2. 使用编辑器或者在 Wordpress 管理面板编辑`config.php`文件
1414

1515
## TODO
16-
* [o] 配置面板
17-
* [o] 错误反馈
16+
* [] 配置面板
17+
* [] 错误反馈
1818

1919
###### Plugin License
2020
> Copyright © 2016 [zonghua](https://applehater.cn)

‎config.php

+2-1
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,6 @@
88
/**
99
* 评论同步接口
1010
* 在 https://hacpai.com/settings#soloCmtURL 配置
11-
* 参数为 YOUR_BLOG_URI/wp-content/plugins/hacpai-sync-wordpress/sync.php
11+
* 参数为 YOUR_BLOG_URI/?hacpai-api=sync-comment
12+
* Wordpress 评论默认要经过审核,可以更改审核规则
1213
*/

‎index.php

+31
Original file line numberDiff line numberDiff line change
@@ -130,3 +130,34 @@ function post_comment($commentdata)
130130

131131
add_filter('preprocess_comment', 'post_comment');
132132

133+
/**
134+
* 黑客派同步到博客
135+
* 指定参数 hacpai-api = sync-comment
136+
*/
137+
function sync_comment()
138+
{
139+
if ($_GET['hacpai-api'] === 'sync-comment') {//判断是不是同步的接口
140+
$data = json_decode(file_get_contents("php://input"));
141+
$comment = $data->comment;
142+
$key = $data->client->key;
143+
if ($key == $GLOBALS['client']['key']) {//判断是否配置了正确的key
144+
$commentdata = array(
145+
'comment_post_ID' => $comment->articleId,
146+
'comment_author' => $comment->authorName,
147+
'comment_author_email' => $comment->authorEmail,
148+
'comment_author_url' => $comment->authorURL,
149+
'comment_content' => $comment->content,
150+
'comment_type' => '', //empty for regular comments, 'pingback' for pingbacks, 'trackback' for trackbacks
151+
'comment_parent' => 0, //0 if it's not a reply to another comment; if it's a reply, mention the parent comment ID here
152+
'user_id' => 0, //passing current user ID or any predefined as per the demand
153+
);
154+
//Insert new comment and get the comment ID
155+
$comment_id = wp_new_comment($commentdata);
156+
test($comment_id);
157+
} else {
158+
echo 'Key not match';
159+
}
160+
}
161+
}
162+
163+
add_action('template_redirect', 'sync_comment');

0 commit comments

Comments
 (0)
Please sign in to comment.