PluginProbe
Event Post / 5.0
Event Post v5.0
6.1.1 6.1.0 6.0.1 6.0.0 5.12.0 trunk 3.9 4.0 4.2 4.3 4.4 4.5 5.0 5.1 5.10.0 5.10.1 5.10.2 5.10.3 5.10.4 5.11.0 5.11.1 5.2 5.5 5.6 5.6.1 All 46 releases
← All changes | inc/openweathermap.php +67 -98 5.10.25.0 View file →
@@ -1,17 +1,7 @@
1 1 <?php
2 -/**
3 - * Weather support
4 - *
5 - * @package event-post
6 - * @version 5.10.2
7 - * @since 4.3.0
8 - */
2 +$EventPostWeather = new EventPostWeather();
9 3
10 -namespace EventPost;
11 -
12 -$EventPostWeather = new Weather();
13 -
14 4 /**
15 5 * Provides weather support thanks to OpenWeatherMap
16 6 * http://openweathermap.org
17 7 *
@@ -20,10 +10,11 @@
20 10 *
21 11 *
22 12 * Get an API key
23 13 * http://openweathermap.org/appid#get
14 + *
24 15 */
25 -class Weather {
16 +class EventPostWeather {
26 17
27 18 var $META_WEATHER;
28 19
29 20 var $api_key;
@@ -41,9 +32,9 @@
41 32
42 33 /**
43 34 * PHP4 constructor
44 35 */
45 - function Weather() {
36 + function EventPostWeather() {
46 37 $this->__construct();
47 38 }
48 39
49 40 /**
@@ -48,9 +39,9 @@
48 39
49 40 /**
50 41 * Only for localization
51 42 *
52 - * Available values:
43 + * available values:
53 44 *
54 45 * - clear sky
55 46 * - few clouds
56 47 * - scattered clouds
@@ -74,10 +65,9 @@
74 65
75 66 }
76 67
77 68 /**
78 - * Get settings
79 - *
69 + *
80 70 * @param array reference &$ep_settings
81 71 * @param boolean reference &$reg_settings
82 72 */
83 73 function get_settings(&$ep_settings, &$reg_settings) {
@@ -95,16 +85,14 @@
95 85 }
96 86 }
97 87
98 88 /**
99 - * Settings form
100 - *
89 + *
101 90 * @param type $ep_settings
102 91 */
103 92 function settings_form($ep_settings) {
104 93 ?>
105 94 <h2><?php _e('Weather', 'event-post'); ?></h2>
106 - <?php // Translators: %s is a link to openweathermap.org ?>
107 95 <p class="description"><?php printf(__('Provided thanks to %s', 'event-post'), '<a href="http://openweathermap.org" target="_blank">openweathermap.org</a>'); ?></p>
108 96 <table class="form-table" id="eventpost-settings-table-weather">
109 97 <tbody>
110 98 <tr>
@@ -156,12 +144,10 @@
156 144 <?php
157 145 }
158 146
159 147 /**
160 - * Initialization of weather support
161 - *
148 + *
162 149 * @param object $EP
163 - *
164 150 * @return void
165 151 */
166 152 function init($EP) {
167 153 // Ensure OpenWeatherMap is required and available.
@@ -191,12 +177,10 @@
191 177
192 178 }
193 179
194 180 /**
195 - * Alters parameters
196 - *
181 + *
197 182 * @param array $params
198 - *
199 183 * @return array
200 184 */
201 185 function params($params = array()) {
202 186 $params['weather'] = true;
@@ -203,12 +187,10 @@
203 187 return $params;
204 188 }
205 189
206 190 /**
207 - * Alters an event object
208 - *
191 + *
209 192 * @param WP_Post $event
210 - *
211 193 * @return WP_Post
212 194 */
213 195 function retreive($event) {
214 196 $event->weather = get_post_meta($event->ID, $this->META_WEATHER, true);
@@ -215,12 +197,10 @@
215 197 return $event;
216 198 }
217 199
218 200 /**
219 - * Alters schema entities
220 - *
201 + *
221 202 * @param array $attr
222 - *
223 203 * @return array
224 204 */
225 205 function scheme_entities($attr = array()) {
226 206 array_push($attr, '%event_weather%');
@@ -227,12 +207,10 @@
227 207 return $attr;
228 208 }
229 209
230 210 /**
231 - * Alters schema values
232 - *
211 + *
233 212 * @param array $values
234 - *
235 213 * @return array
236 214 */
237 215 function scheme_values($values = array(), $post = null) {
238 216 array_push($values, $this->get_weather($post));
@@ -239,12 +217,10 @@
239 217 return $values;
240 218 }
241 219
242 220 /**
243 - * Alters default schema
244 - *
221 + *
245 222 * @param array $schema
246 - *
247 223 * @return array
248 224 */
249 225 function default_shema($schema) {
250 226 $schema['item'] = str_replace('</%child%>', "%event_weather%\n</%child%>", $schema['item']);
@@ -254,9 +230,11 @@
254 230 function get_single($event_datas, $post = null) {
255 231 return $event_datas . $this->get_weather($post);
256 232 }
257 233
258 - //From here, methods intends to get datas
234 + /**
235 + * From here, methods intends to get datas
236 + */
259 237
260 238 function get_weather_icons($weather){
261 239 $string = '';
262 240 foreach((array) $weather as $item){
@@ -268,12 +246,10 @@
268 246 }
269 247 return $string;
270 248 }
271 249 /**
272 - * Get weather item
273 - *
250 + *
274 251 * @param object $item
275 - *
276 252 * @return string
277 253 */
278 254 function get_weather_item($item){
279 255 $string = '';
@@ -285,12 +261,10 @@
285 261 return $string;
286 262 }
287 263
288 264 /**
289 - * Get weather
290 - *
265 + *
291 266 * @param type $post
292 - *
293 267 * @return string
294 268 */
295 269 function get_weather($post = null, $echo=false) {
296 270 global $EventPost;
@@ -335,12 +309,10 @@
335 309 return $string;
336 310 }
337 311
338 312 /**
339 - * Get weather datas
340 - *
313 + *
341 314 * @param type $event
342 - *
343 315 * @return type
344 316 */
345 317 function get_weather_datas($event){
346 318 if (!$event->lat || !$event->long || !is_numeric($event->time_start) || !is_numeric($event->time_end)) {
@@ -383,12 +355,10 @@
383 355
384 356
385 357 /**
386 358 * Generates the URL to call the API
387 - *
388 359 * @param type $method
389 360 * @param type $params
390 - *
391 361 * @return type
392 362 */
393 363 function get_url($method = 'weather', $params = array()) {
394 364 $params['APPID']= $this->api_key;
@@ -396,27 +366,26 @@
396 366 return 'http://api.openweathermap.org/data/2.5/' . $method . '?' . http_build_query($params);
397 367 }
398 368
399 369 /**
400 - * Current weather
370 + * ### current
401 371 * http://api.openweathermap.org/data/2.5/weather?lat={lat}&lon={lon}&APPID=XXXX
402 372 *
403 - * Return:
373 + * return:
404 374 *
405 - * {"coord":{"lon":139,"lat":35},
406 - * "sys":{"country":"JP","sunrise":1369769524,"sunset":1369821049},
407 - * "weather":[{"id":804,"main":"clouds","description":"overcast clouds","icon":"04n"}],
408 - * "main":{"temp":289.5,"humidity":89,"pressure":1013,"temp_min":287.04,"temp_max":292.04},
409 - * "wind":{"speed":7.31,"deg":187.002},
410 - * "rain":{"3h":0},
411 - * "clouds":{"all":92},
412 - * "dt":1369824698,
413 - * "id":1851632,
414 - * "name":"Shuzenji",
415 - * "cod":200}
375 + {"coord":{"lon":139,"lat":35},
376 + "sys":{"country":"JP","sunrise":1369769524,"sunset":1369821049},
377 + "weather":[{"id":804,"main":"clouds","description":"overcast clouds","icon":"04n"}],
378 + "main":{"temp":289.5,"humidity":89,"pressure":1013,"temp_min":287.04,"temp_max":292.04},
379 + "wind":{"speed":7.31,"deg":187.002},
380 + "rain":{"3h":0},
381 + "clouds":{"all":92},
382 + "dt":1369824698,
383 + "id":1851632,
384 + "name":"Shuzenji",
385 + "cod":200}
416 386 *
417 387 * @param type $event
418 - *
419 388 * @return object
420 389 */
421 390 function get_current($event){
422 391 if (!$event->lat || !$event->long) {
@@ -432,39 +401,38 @@
432 401 ));
433 402 }
434 403
435 404 /**
436 - * Forecast
405 + * ### forecast
437 406 * api.openweathermap.org/data/2.5/forecast?lat={lat}&lon={lon}&APPID=XXXX
438 407 *
439 - * Return:
408 + * return:
440 409 *
441 - * {"city":{"id":1851632,"name":"Shuzenji",
442 - * "coord":{"lon":138.933334,"lat":34.966671},
443 - * "country":"JP",
444 - * "cod":"200",
445 - * "message":0.0045,
446 - * "cnt":38,
447 - * "list":[{
448 - * "dt":1406106000,
449 - * "main":{
450 - * "temp":298.77,
451 - * "temp_min":298.77,
452 - * "temp_max":298.774,
453 - * "pressure":1005.93,
454 - * "sea_level":1018.18,
455 - * "grnd_level":1005.93,
456 - * "humidity":87
457 - * "temp_kf":0.26},
458 - * "weather":[{"id":804,"main":"Clouds","description":"overcast clouds","icon":"04d"}],
459 - * "clouds":{"all":88},
460 - * "wind":{"speed":5.71,"deg":229.501},
461 - * "sys":{"pod":"d"},
462 - * "dt_txt":"2014-07-23 09:00:00"}
463 - * ]}
410 + {"city":{"id":1851632,"name":"Shuzenji",
411 + "coord":{"lon":138.933334,"lat":34.966671},
412 + "country":"JP",
413 + "cod":"200",
414 + "message":0.0045,
415 + "cnt":38,
416 + "list":[{
417 + "dt":1406106000,
418 + "main":{
419 + "temp":298.77,
420 + "temp_min":298.77,
421 + "temp_max":298.774,
422 + "pressure":1005.93,
423 + "sea_level":1018.18,
424 + "grnd_level":1005.93,
425 + "humidity":87
426 + "temp_kf":0.26},
427 + "weather":[{"id":804,"main":"Clouds","description":"overcast clouds","icon":"04d"}],
428 + "clouds":{"all":88},
429 + "wind":{"speed":5.71,"deg":229.501},
430 + "sys":{"pod":"d"},
431 + "dt_txt":"2014-07-23 09:00:00"}
432 + ]}
464 433 *
465 434 * @param type $event
466 - *
467 435 * @return type
468 436 */
469 437 function get_forecast($event){
470 438 if (!$event->lat || !$event->long) {
@@ -489,20 +457,21 @@
489 457 * type type of the call, keep this parameter in the API call as 'hour'
490 458 * start start date (unix time, UTC time zone), e.g. start=1369728000
491 459 * end end date (unix time, UTC time zone), e.g. end=1369789200
492 460 * cnt amount of returned data (one per hour, can be used instead of 'end') *
461 + *
493 462 * return:
494 - * {"message":"","cod":"200","type":"tick","station_id":39419,"cnt":30,
495 - * "list":[
496 - * {"dt":1345291920,
497 - * "main":{"temp":291.55,"humidity":95,"pressure":1009.3},
498 - * "wind":{"speed":0,"gust":0.3},
499 - * "rain":{"1h":0.6,"today":2.7},
500 - * "calc":{"dewpoint":17.6} }
501 - * ]}
463 + {"message":"","cod":"200","type":"tick","station_id":39419,"cnt":30,
464 + "list":[
465 + {"dt":1345291920,
466 + "main":{"temp":291.55,"humidity":95,"pressure":1009.3},
467 + "wind":{"speed":0,"gust":0.3},
468 + "rain":{"1h":0.6,"today":2.7},
469 + "calc":{"dewpoint":17.6} }
470 + ]}
502 471 *
472 + *
503 473 * @param type $event
504 - *
505 474 * @return type
506 475 */
507 476 function get_history($event) {
508 477 if (!$event->start || !$event->end || !$event->lat || !$event->long) {