Created
April 13, 2011 13:27
-
-
Save dubrod/917539 to your computer and use it in GitHub Desktop.
Show the 5 Recent Checkins with Name and Photo from your Gowalla Spot
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function nicetime($date) | |
{ | |
if(empty($date)) { | |
return "No date provided"; | |
} | |
$periods = array("second", "minute", "hour", "day", "week", "month", "year", "decade"); | |
$lengths = array("60","60","24","7","4.35","12","10"); | |
$now = time(); | |
$unix_date = strtotime($date); | |
if(empty($unix_date)) { | |
return "some time ago"; | |
} | |
if($now > $unix_date) { | |
$difference = $now - $unix_date; | |
$tense = "ago"; | |
} else { | |
$difference = $unix_date - $now; | |
$tense = "from now"; | |
} | |
for($j = 0; $difference >= $lengths[$j] && $j < count($lengths)-1; $j++) { | |
$difference /= $lengths[$j]; | |
} | |
$difference = round($difference); | |
if($difference != 1) { | |
$periods[$j].= "s"; | |
} | |
return "<small>$difference $periods[$j] {$tense}</small>"; | |
} | |
function gowalla_spotter() { | |
$spot_id = 579937; // just change this # | |
if ($spot_id != "") { | |
$ch = curl_init(); | |
curl_setopt($ch, CURLOPT_URL, "http://api.gowalla.com/spots/$spot_id"); | |
curl_setopt($ch,CURLOPT_HTTPHEADER, array ("Content-Type: application/json;charset=utf-8","Accept: application/json")); | |
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); | |
curl_setopt($ch, CURLOPT_HEADER, 0); | |
$json = curl_exec($ch); | |
curl_close($ch); | |
$json = json_decode($json); | |
$place = $json->name; | |
$output = ""; | |
$output .= "<b>Latest activity at <a href=\"http://gowalla.com/spots/" . $spot_id . "\">" . $place . "</a> from <a href=\"http://gowalla.com\">Gowalla</a> </b><br/>"; | |
foreach ($json->last_checkins as $checkin) { | |
$output .= sprintf( | |
'<img src="%s" alt="" width="25" height="25" /> <a href="%s">%s %s</a> %s (%s)<br />', | |
$checkin->user->image_url, | |
'http://gowalla.com' . $checkin->user->url, | |
$checkin->user->first_name, | |
$checkin->user->last_name, | |
$checkin->message, | |
nicetime($checkin->created_at) | |
); | |
} | |
echo $output; | |
} | |
} | |
if (function_exists('gowalla_spotter')) gowalla_spotter(); | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment