-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathlib_enplacify_chowhound.php
113 lines (79 loc) · 2.22 KB
/
lib_enplacify_chowhound.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
105
106
107
108
109
110
111
112
113
<?php
#
# $Id$
#
loadlib("opengraph");
loadlib("vcard");
# http://www.chow.com/restaurants/919858/masala-cuisine
######################################################
function enplacify_chowhound_uri($uri){
$restaurant_id = enplacify_chowhound_uri_to_id($uri);
if (! $restaurant_id){
return array(
'ok' => 0,
'error' => 'failed to recognize restaurant id',
);
}
$rsp = enplacify_chowhound_get_restaurant($restaurant_id);
if (! $rsp['ok']){
return $rsp;
}
$title = $rsp['restaurant']['title'];
if (! $title){
$title = $rsp['restaurant']['fn org'];
}
$place = array(
'latitude' => $rsp['restaurant']['latitude'],
'longitude' => $rsp['restaurant']['longitude'],
'name' => $title,
'phone' => $rsp['restaurant']['tel'],
'url' => $rsp['restaurant']['url'],
'address' => $rsp['restaurant']['street-address'],
'derived_from' => 'chowhound',
'derived_from_id' => $restaurant_id,
);
return array(
'ok' => 1,
'place' => $place,
'restaurant' => $rsp['restaurant'],
);
}
######################################################
function enplacify_chowhound_uri_to_id($uri){
return enplacify_service_uri_to_id('chowhound', $uri);
}
######################################################
function enplacify_chowhound_get_restaurant($restaurant_id){
$cache_key = "enplacify_chowhound_restaurant_{$restaurant_id}";
$cache = cache_get($cache_key);
if ($cache['ok']){
return $cache['data'];
}
$url = "http://www.chow.com/restaurants/" . urlencode($restaurant_id);
$headers = array();
$more = array('follow_redirects' => 1);
$rsp = http_get($url, $headers, $more);
if (! $rsp['ok']){
return $rsp;
}
$vcard_rsp = vcard_parse_html($rsp['body']);
$graph_rsp = opengraph_parse_html($rsp['body']);
if ((! $vcard_rsp['ok']) && (! $graph_rsp['ok'])){
$rsp = array(
'ok' => 0,
'error' => 'Failed to parse restaurant'
);
}
else {
$restaurant = array_merge($vcard_rsp['vcard'], $graph_rsp['graph']);
$restaurant['id'] = $restaurant_id;
$rsp = array(
'ok' => 1,
'restaurant' => $restaurant
);
}
cache_set($cache_key, $rsp);
return $rsp;
}
######################################################
?>