-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest.php
More file actions
52 lines (37 loc) · 1.3 KB
/
test.php
File metadata and controls
52 lines (37 loc) · 1.3 KB
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
<?php
include_once('workflows.php');
$wf = new workflows;
$clean = trim("{query}");
$ps = explode("|", $clean);
$version = 2.2;
$page = 10;
$url = "https://api.stackexchange.com/2.2/search?key=U4DMV*8nvpm3EOpvf69Rxw((&site=stackoverflow&order=desc&sort=votes&filter=default";
$params = [
'intitle' => isset($ps[1]) ? $ps[1] : '',
'tagged' => isset($ps[0]) ? $ps[0] : ''
];
$params = http_build_query($params);
$url .= '&'. $params;
$ch = curl_init();
$opts = [
CURLOPT_URL => $url,
CURLOPT_HEADER => false,
CURLOPT_ENCODING => "gzip",
CURLOPT_RETURNTRANSFER => true
];
curl_setopt_array($ch, $opts);
if ($result = curl_exec($ch)) {
$result = json_decode($result, true);
$result = $result['items'];
if (count($result)) {
while( list($key, $val) = each($result)) {
$wf->result("1PM", $val['link'], $val['title'], "回答数:{$val['answer_count']} | 分数: {$val['score']}" , 'icon.png', "yes");
}
}
else {
$wf->result("1PM", "http://www.stackoverflow.com", "没有找到", "请输入别的进行查询" , 'icon.png', "yes");
}
} else {
$wf->result("1PM", "basic", "出错", "当前网络连接错误" , 'icon.png', "yes");
}
echo $wf->toxml();