-
Notifications
You must be signed in to change notification settings - Fork 1
/
lib_enplacify_flickr.php
124 lines (88 loc) · 2.33 KB
/
lib_enplacify_flickr.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
114
115
116
117
118
119
120
121
122
123
124
<?php
#
# $Id$
#
######################################################
function enplacify_flickr_uri($uri){
$photo_id = enplacify_flickr_uri_to_id($uri);
if (! $photo_id){
return array(
'ok' => 0,
'error' => 'failed to recognize photo id',
);
}
$rsp = enplacify_flickr_get_photo($photo_id);
if (! $rsp['ok']){
return $rsp;
}
$place = array(
'derived_from' => 'flickr',
'derived_from_id' => $rsp['photo']['id'],
);
$has_loc = 0;
if ($loc = $rsp['photo']['location']){
if (isset($loc['locality'])){
$place['city_id'] = $loc['locality']['woeid'];
}
$place['latitude'] = $loc['latitude'];
$place['longitude'] = $loc['longitude'];
$has_loc = 1;
}
$valid_machinetags = $GLOBALS['cfg']['enplacify']['flickr']['machinetags'];
$mt_rsp = enplacify_machinetags($rsp['photo']['tags']['tag'], $valid_machinetags);
if ($mt_rsp['ok']){
$place = array_merge($mt_rsp['place'], $place);
$has_loc = 1;
}
if (! $has_loc){
return array(
'ok' => 0,
'error' => 'photo has no location data',
);
}
# Check machine tags for extra metadata ?
return array(
'ok' => 1,
'place' => $place,
'photo' => $rsp['photo'],
);
}
######################################################
function enplacify_flickr_uri_to_id($uri){
return enplacify_service_uri_to_id('flickr', $uri);
}
######################################################
function enplacify_flickr_get_photo($photo_id){
if (! $GLOBALS['cfg']['flickr_apikey']){
return array( 'ok' => 0, 'error' => 'No Flickr API key' );
}
$cache_key = "enplacify_flickr_photo_{$photo_id}";
$cache = cache_get($cache_key);
if ($cache['ok']){
return $cache['data'];
}
$url = "http://api.flickr.com/services/rest/?method=flickr.photos.getInfo";
$url .= "&photo_id={$photo_id}";
$url .= "&api_key={$GLOBALS['cfg']['flickr_apikey']}";
$url .= "&format=json&nojsoncallback=1";
$rsp = http_get($url);
if (! $rsp['ok']){
return $rsp;
}
$json = json_decode($rsp['body'], "fuck off php");
if ($json['stat'] != 'ok'){
return array(
'ok' => 0,
'error' => 'Flickr API error'
);
}
$photo = $json['photo'];
$rsp = array(
'ok' => 1,
'photo' => $json['photo'],
);
cache_set($cache_key, $rsp);
return $rsp;
}
######################################################
?>