forked from fooleap/disqus-php-api
/
getcomments.php
55 lines (47 loc) · 1.41 KB
/
getcomments.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
<?php
/**
* 获取评论列表
* 暂以 50 条每页,倒序为准
*
* @param link 页面链接
* @param cursor 当前评论位置
*
* @author fooleap <fooleap@gmail.com>
* @version 2018-04-26 17:16:59
* @link https://github.com/fooleap/disqus-php-api
*
*/
namespace Emojione;
require_once('init.php');
$thread = 'ident:'.$_GET['ident'];
$fields = (object) array(
'forum' => DISQUS_SHORTNAME,
'cursor' => $_GET['cursor'],
'limit' => 50,
'order' => 'desc',
'thread' => $thread
);
$curl_url = '/api/3.0/threads/listPostsThreaded?';
$data = curl_get($curl_url, $fields);
$fields = (object) array(
'forum' => DISQUS_SHORTNAME,
'thread' => $thread
);
$curl_url = '/api/3.0/threads/details.json?';
$detail = curl_get($curl_url, $fields);
$posts = array();
if (is_array($data -> response) || is_object($data -> response)){
foreach ( $data -> response as $key => $post ) {
$posts[$key] = post_format($post);
}
}
$output = $data -> code == 0 ? (object) array(
'code' => $detail -> code,
'cursor' => $data -> cursor,
'forum' => $forum_data -> forum,
'link' => 'https://disqus.com/home/discussion/'.DISQUS_SHORTNAME.'/'.$detail -> response -> slug.'/?l=zh',
'posts' => $detail -> response -> posts,
'response' => $posts,
'thread' => $detail -> response -> id
) : $data;
print_r(json_encode($output));