-
Notifications
You must be signed in to change notification settings - Fork 1
/
hl.php
58 lines (52 loc) · 1.45 KB
/
hl.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
<?php
require_once('workflows.php');
$wf = new Workflows();
date_default_timezone_set('Asia/Tokyo');
function trimAll($str) {
return str_replace(array("\r\n","\n","\r"), " ", $str);
}
function get_userinfo() {
$filename = "~/.hatebulist";
$str = exec('cat '.$filename, $output);
$userinfo_array = explode(" ", $output[0]);
return array(
'user_name' => $userinfo_array[0],
'api_key' => $userinfo_array[1]
);
}
$user = get_userinfo();
$user_name = $user['user_name'];
$api_key = $user['api_key'];
#http://d.hatena.ne.jp/i_ogi/20100214/wsse
$url = "http://b.hatena.ne.jp/".$user_name."/search/json?q=".$query."&sort=date&limit=20";
$nonce = md5(mt_rand());
$created = date(DATE_ISO8601);
$x_wsse = sprintf('UsernameToken Username="%s", PasswordDigest="%s", Nonce="%s", Created="%s"',
$user_name,
base64_encode(sha1($nonce . $created . $api_key, true)),
base64_encode($nonce),
$created);
$context = stream_context_create(
array('http' => array('header' => "X-WSSE: $x_wsse\r\n"."User-Agent: HatebuList.alfredworkflow"))
);
$file = file_get_contents($url, 0, $context);
$json = json_decode($file);
$dataList = $json;
foreach($dataList->bookmarks as $data) {
$entry = $data->entry;
$title = $entry->title;
$count = $entry->count;
$snippet = trimAll($entry->snippet);
$wf_url = $entry->url;
$wf_title = $title;
$wf_description = $snippet;
$wf->result(
time(),
$wf_url,
$wf_title,
$wf_description,
'icon.png'
);
}
echo $wf->toxml();
?>