<?php
// Brightkite Info
$username = ''; // Brightkite username
$password = ''; // Brightkite password
$place = ''; // Brightkite PlaceID
// Bit.ly Info
$login = ''; // Bit.ly Login
$apikey = ''; // bit.ly API key
// Google Info
$key = ''; // Post-Commit Authentication Key
$project = '';
$ignorecommits = array('Edited wiki page through web user interface.');
// No need to modify past this line unless your customizing
$data = file_get_contents("php://input");
$digest = hash_hmac("md5", $data, $key);
$hook = $_SERVER["HTTP_GOOGLE_CODE_PROJECT_HOSTING_HOOK_HMAC"];
if ($hook && ($hook == $digest)) {
$data = json_decode($data, true);
if (!in_array($data['revisions'][0]['message'], $ignorecommits)) {
$ch = curl_init();
$url = shorturl('http://code.google.com/p/' . $project . '/source/detail?r=' . $data['revisions'][0]['revision']);
$message = ' @' . $data['revisions'][0]['author'] . ' just made a commit - ' . $data['revisions'][0]['message'];
if (strlen($message)+strlen($url)+1 > 140) {
$end = 140-(strlen($url)+1);
$message = substr($message, 0, $end);
$message = $message . ' ' . $url;
} else {
$message = $message . ' ' . $url;
}
$note = array('note[body]' => $message);
curl_setopt($ch, CURLOPT_USERPWD, $username . ':' . $password);
curl_setopt($ch, CURLOPT_URL, 'http://brightkite.com/places/' . $place . '/notes.json');
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $note);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
$response = curl_exec($ch);
curl_close($ch);
$json = json_decode($response, TRUE);
}
}
function shorturl ($url) {
global $login, $apikey;
$data['version'] = '2.0.1';
$data['longUrl'] = $url;
$data['login'] = $login;
$data['apiKey'] = $apikey;
$data['format'] = 'json';
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'http://api.bit.ly/shorten');
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
$response = curl_exec($ch);
curl_close($ch);
$json = json_decode($response, TRUE);
return $json['results'][$url]['shortUrl'];
}
?>