places.php
8.48 KB
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
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
<?php
/**
* @package Joomla.Platform
* @subpackage Twitter
*
* @copyright Copyright (C) 2005 - 2019 Open Source Matters, Inc. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE
*/
defined('JPATH_PLATFORM') or die();
/**
* Twitter API Places & Geo class for the Joomla Platform.
*
* @since 3.1.4
* @deprecated 4.0 Use the `joomla/twitter` package via Composer instead
*/
class JTwitterPlaces extends JTwitterObject
{
/**
* Method to get all the information about a known place.
*
* @param string $id A place in the world. These IDs can be retrieved using getGeocode.
*
* @return array The decoded JSON response
*
* @since 3.1.4
*/
public function getPlace($id)
{
// Check the rate limit for remaining hits
$this->checkRateLimit('geo', 'id/:place_id');
// Set the API path
$path = '/geo/id/' . $id . '.json';
// Send the request.
return $this->sendRequest($path);
}
/**
* Method to get up to 20 places that can be used as a place_id when updating a status.
*
* @param float $lat The latitude to search around.
* @param float $long The longitude to search around.
* @param string $accuracy A hint on the "region" in which to search. If a number, then this is a radius in meters,
* but it can also take a string that is suffixed with ft to specify feet.
* @param string $granularity This is the minimal granularity of place types to return and must be one of: poi, neighborhood,
* city, admin or country.
* @param integer $max_results A hint as to the number of results to return.
* @param string $callback If supplied, the response will use the JSONP format with a callback of the given name.
*
* @return array The decoded JSON response
*
* @since 3.1.4
*/
public function getGeocode($lat, $long, $accuracy = null, $granularity = null, $max_results = 0, $callback = null)
{
// Check the rate limit for remaining hits
$this->checkRateLimit('geo', 'reverse_geocode');
// Set the API path
$path = '/geo/reverse_geocode.json';
// Set the request parameters
$data['lat'] = $lat;
$data['long'] = $long;
// Check if accuracy is specified
if ($accuracy)
{
$data['accuracy'] = $accuracy;
}
// Check if granularity is specified
if ($granularity)
{
$data['granularity'] = $granularity;
}
// Check if max_results is specified
if ($max_results)
{
$data['max_results'] = $max_results;
}
// Check if callback is specified
if ($callback)
{
$data['callback'] = $callback;
}
// Send the request.
return $this->sendRequest($path, 'GET', $data);
}
/**
* Method to search for places that can be attached to a statuses/update.
*
* @param float $lat The latitude to search around.
* @param float $long The longitude to search around.
* @param string $query Free-form text to match against while executing a geo-based query, best suited for finding nearby
* locations by name.
* @param string $ip An IP address.
* @param string $granularity This is the minimal granularity of place types to return and must be one of: poi, neighborhood, city,
* admin or country.
* @param string $accuracy A hint on the "region" in which to search. If a number, then this is a radius in meters, but it can
* also take a string that is suffixed with ft to specify feet.
* @param integer $max_results A hint as to the number of results to return.
* @param string $within This is the place_id which you would like to restrict the search results to.
* @param string $attribute This parameter searches for places which have this given street address.
* @param string $callback If supplied, the response will use the JSONP format with a callback of the given name.
*
* @return array The decoded JSON response
*
* @since 3.1.4
* @throws RuntimeException
*/
public function search($lat = null, $long = null, $query = null, $ip = null, $granularity = null, $accuracy = null, $max_results = 0,
$within = null, $attribute = null, $callback = null)
{
// Check the rate limit for remaining hits
$this->checkRateLimit('geo', 'search');
// Set the API path
$path = '/geo/search.json';
// At least one of the following parameters must be provided: lat, long, ip, or query.
if ($lat == null && $long == null && $ip == null && $query == null)
{
throw new RuntimeException('At least one of the following parameters must be provided: lat, long, ip, or query.');
}
// Check if lat is specified.
if ($lat)
{
$data['lat'] = $lat;
}
// Check if long is specified.
if ($long)
{
$data['long'] = $long;
}
// Check if query is specified.
if ($query)
{
$data['query'] = rawurlencode($query);
}
// Check if ip is specified.
if ($ip)
{
$data['ip'] = $ip;
}
// Check if granularity is specified
if ($granularity)
{
$data['granularity'] = $granularity;
}
// Check if accuracy is specified
if ($accuracy)
{
$data['accuracy'] = $accuracy;
}
// Check if max_results is specified
if ($max_results)
{
$data['max_results'] = $max_results;
}
// Check if within is specified
if ($within)
{
$data['contained_within'] = $within;
}
// Check if attribute is specified
if ($attribute)
{
$data['attribute:street_address'] = rawurlencode($attribute);
}
// Check if callback is specified
if ($callback)
{
$data['callback'] = $callback;
}
// Send the request.
return $this->sendRequest($path, 'GET', $data);
}
/**
* Method to locate places near the given coordinates which are similar in name.
*
* @param float $lat The latitude to search around.
* @param float $long The longitude to search around.
* @param string $name The name a place is known as.
* @param string $within This is the place_id which you would like to restrict the search results to.
* @param string $attribute This parameter searches for places which have this given street address.
* @param string $callback If supplied, the response will use the JSONP format with a callback of the given name.
*
* @return array The decoded JSON response
*
* @since 3.1.4
*/
public function getSimilarPlaces($lat, $long, $name, $within = null, $attribute = null, $callback = null)
{
// Check the rate limit for remaining hits
$this->checkRateLimit('geo', 'similar_places');
// Set the API path
$path = '/geo/similar_places.json';
$data['lat'] = $lat;
$data['long'] = $long;
$data['name'] = rawurlencode($name);
// Check if within is specified
if ($within)
{
$data['contained_within'] = $within;
}
// Check if attribute is specified
if ($attribute)
{
$data['attribute:street_address'] = rawurlencode($attribute);
}
// Check if callback is specified
if ($callback)
{
$data['callback'] = $callback;
}
// Send the request.
return $this->sendRequest($path, 'GET', $data);
}
/**
* Method to create a new place object at the given latitude and longitude.
*
* @param float $lat The latitude to search around.
* @param float $long The longitude to search around.
* @param string $name The name a place is known as.
* @param string $geo_token The token found in the response from geo/similar_places.
* @param string $within This is the place_id which you would like to restrict the search results to.
* @param string $attribute This parameter searches for places which have this given street address.
* @param string $callback If supplied, the response will use the JSONP format with a callback of the given name.
*
* @return array The decoded JSON response
*
* @since 3.1.4
*/
public function createPlace($lat, $long, $name, $geo_token, $within, $attribute = null, $callback = null)
{
// Check the rate limit for remaining hits
$this->checkRateLimit('geo', 'place');
$data['lat'] = $lat;
$data['long'] = $long;
$data['name'] = rawurlencode($name);
$data['token'] = $geo_token;
$data['contained_within'] = $within;
// Check if attribute is specified
if ($attribute)
{
$data['attribute:street_address'] = rawurlencode($attribute);
}
// Check if callback is specified
if ($callback)
{
$data['callback'] = $callback;
}
// Set the API path
$path = '/geo/place.json';
// Send the request.
return $this->sendRequest($path, 'POST', $data);
}
}