-
Notifications
You must be signed in to change notification settings - Fork 1
/
lib_enplacify_foursquare.php
104 lines (73 loc) · 1.94 KB
/
lib_enplacify_foursquare.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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
<?php
#
# $Id$
#
######################################################
# venue HTML pages also contain lots of crunchy good
# og: properties (20101205/straup)
######################################################
function enplacify_foursquare_uri($uri){
$venue_id = enplacify_foursquare_uri_to_id($uri);
if (! $venue_id){
return array(
'ok' => 0,
'error' => 'failed to recognize venue id',
);
}
$rsp = enplacify_foursquare_get_venue($venue_id);
if (! $rsp['ok']){
return $rsp;
}
$address = $rsp['venue']['address'];
if ($rsp['venue']['crossstreet']){
$address .= " ({$rsp['venue']['crossstreet']})";
}
$place = array(
'latitude' => $rsp['venue']['geolat'],
'longitude' => $rsp['venue']['geolong'],
'name' => $rsp['venue']['name'],
'address' => $address,
'derived_from' => 'foursquare',
'derived_from_id' => $rsp['venue']['id'],
);
$others = array(
'phone' => 'phone',
'url' => 'url',
);
foreach ($others as $theirs => $ours){
if (isset($rsp['venue'][$theirs])){
$place[$ours] = $rsp['venue'][$theirs];
}
}
return array(
'ok' => 1,
'place' => $place,
'venue' => $rsp['venue'],
);
}
######################################################
function enplacify_foursquare_uri_to_id($uri){
return enplacify_service_uri_to_id('foursquare', $uri);
}
######################################################
function enplacify_foursquare_get_venue($venue_id){
$cache_key = "enplacify_4sq_venue_{$venue_id}";
$cache = cache_get($cache_key);
if ($cache['ok']){
return $cache['data'];
}
$url = "https://api.foursquare.com/v1/venue.json?vid={$venue_id}";
$rsp = http_get($url);
if (! $rsp['ok']){
return $rsp;
}
$json = json_decode($rsp['body'], "fuck off php");
$rsp = array(
'ok' => 1,
'venue' => $json['venue'],
);
cache_set($cache_key, $rsp);
return $rsp;
}
######################################################
?>