View difference between Paste ID: f7ac7cc00 and
SHOW:
|
|
- or go back to the newest paste.
1 | - | |
1 | + | <?php |
2 | // Brightkite Info | |
3 | $username = ''; // Brightkite username | |
4 | $password = ''; // Brightkite password | |
5 | $place = ''; // Brightkite PlaceID | |
6 | ||
7 | // Bit.ly Info | |
8 | $login = ''; // Bit.ly Login | |
9 | $apikey = ''; // bit.ly API key | |
10 | ||
11 | // Google Info | |
12 | $key = ''; // Post-Commit Authentication Key | |
13 | $project = ''; | |
14 | $ignorecommits = array('Edited wiki page through web user interface.'); | |
15 | ||
16 | // No need to modify past this line unless your customizing | |
17 | $data = file_get_contents("php://input"); | |
18 | $digest = hash_hmac("md5", $data, $key); | |
19 | ||
20 | $hook = $_SERVER["HTTP_GOOGLE_CODE_PROJECT_HOSTING_HOOK_HMAC"]; | |
21 | if ($hook && ($hook == $digest)) { | |
22 | $data = json_decode($data, true); | |
23 | if (!in_array($data['revisions'][0]['message'], $ignorecommits)) { | |
24 | $ch = curl_init(); | |
25 | $url = shorturl('http://code.google.com/p/' . $project . '/source/detail?r=' . $data['revisions'][0]['revision']); | |
26 | $message = ' @' . $data['revisions'][0]['author'] . ' just made a commit - ' . $data['revisions'][0]['message']; | |
27 | if (strlen($message)+strlen($url)+1 > 140) { | |
28 | $end = 140-(strlen($url)+1); | |
29 | $message = substr($message, 0, $end); | |
30 | $message = $message . ' ' . $url; | |
31 | } else { | |
32 | $message = $message . ' ' . $url; | |
33 | } | |
34 | $note = array('note[body]' => $message); | |
35 | curl_setopt($ch, CURLOPT_USERPWD, $username . ':' . $password); | |
36 | curl_setopt($ch, CURLOPT_URL, 'http://brightkite.com/places/' . $place . '/notes.json'); | |
37 | curl_setopt($ch, CURLOPT_POST, 1); | |
38 | curl_setopt($ch, CURLOPT_POSTFIELDS, $note); | |
39 | curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE); | |
40 | $response = curl_exec($ch); | |
41 | curl_close($ch); | |
42 | $json = json_decode($response, TRUE); | |
43 | } | |
44 | } | |
45 | ||
46 | function shorturl ($url) { | |
47 | global $login, $apikey; | |
48 | $data['version'] = '2.0.1'; | |
49 | $data['longUrl'] = $url; | |
50 | $data['login'] = $login; | |
51 | $data['apiKey'] = $apikey; | |
52 | $data['format'] = 'json'; | |
53 | $ch = curl_init(); | |
54 | curl_setopt($ch, CURLOPT_URL, 'http://api.bit.ly/shorten'); | |
55 | curl_setopt($ch, CURLOPT_POST, 1); | |
56 | curl_setopt($ch, CURLOPT_POSTFIELDS, $data); | |
57 | curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE); | |
58 | $response = curl_exec($ch); | |
59 | curl_close($ch); | |
60 | $json = json_decode($response, TRUE); | |
61 | return $json['results'][$url]['shortUrl']; | |
62 | } | |
63 | ?> |