forked from fooleap/disqus-php-api
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathremovecomment.php
71 lines (66 loc) · 1.71 KB
/
removecomment.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
<?php
/**
* 删除评论
*
* @param id 评论 ID
*
* @author fooleap <fooleap@gmail.com>
* @version 2018-03-10 14:02:49
* @link https://github.com/fooleap/disqus-php-api
*
*/
namespace Emojione;
date_default_timezone_set('UTC');
require_once('init.php');
$fields_data = (object) array(
'api_key' => DISQUS_PUBKEY,
'post' => $_POST['id']
);
$curl_url = '/api/3.0/posts/details.json?'.http_build_query($fields_data);
$data = curl_get($curl_url);
$duration = time() - strtotime($data->response->createdAt);
$output = array();
if($data->code !== 0){
$output = array(
'code' => 2,
'response' => '请求方式有误或不存在此 post'
);
print_r(json_encode($output));
return;
}
if( $data->response->isDeleted ){
// 已删除
$output = array(
'code' => 0,
'response' => array(
'isDeleted' => true,
'message' => '该留言已删除'
)
);
} else {
if( $duration < 600 ){
// 十分钟内
$post_data = (object) array(
'post' => $_POST['id']
);
$curl_url = '/api/3.0/posts/remove.json';
curl_post($curl_url, $post_data);
$output = array(
'code' => 0,
'response' => array(
'isDeleted' => true,
'message' => '删除成功'
)
);
} else {
// 十分钟外
$output = array(
'code' => 0,
'response' => array(
'isDeleted' => false,
'message' => '删除失败,留言时间已超过十分钟'
)
);
}
}
print_r(json_encode($output));