Awesome Weather Widget - Version 2.0

Version Description

  • Improvements to City Lookup
  • Either location attribute or owm_city_id is required, not both now!
  • Code cleanup
Download this release

Release Info

Developer halgatewood
Plugin Icon 128x128 Awesome Weather Widget
Version 2.0
Comparing to
See all releases

Code changes from version 1.5.15 to 2.0

Files changed (3) hide show
  1. awesome-weather.php +89 -80
  2. readme.txt +26 -16
  3. widget.php +7 -3
awesome-weather.php CHANGED
@@ -5,7 +5,7 @@ Plugin URI: https://halgatewood.com/awesome-weather
5
  Description: A weather widget that actually looks cool
6
  Author: Hal Gatewood
7
  Author URI: https://www.halgatewood.com
8
- Version: 1.5.15
9
  Text Domain: awesome-weather
10
  Domain Path: /languages
11
 
@@ -16,6 +16,7 @@ https://halgatewood.com/docs/plugins/awesome-weather-widget/available-filters
16
  */
17
 
18
 
 
19
 
20
  // SETTINGS
21
  $awesome_weather_sizes = apply_filters( 'awesome_weather_sizes' , array( 'tall', 'wide' ) );
@@ -25,7 +26,7 @@ $awesome_weather_sizes = apply_filters( 'awesome_weather_sizes' , array( 'tall',
25
  function awesome_weather_setup()
26
  {
27
  $locale = apply_filters('plugin_locale', get_locale(), 'awesome-weather');
28
- $mofile = WP_LANG_DIR . "/awesome-weather/awesome-weather-" . $locale . '.mo';
29
 
30
  if( file_exists( $mofile ) )
31
  {
@@ -82,13 +83,13 @@ function awesome_weather_logic( $atts )
82
 
83
  $dt_today = date( 'Ymd', current_time( 'timestamp', 0 ) );
84
 
85
- $rtn = "";
86
  $weather_data = array();
87
- $location = isset($atts['location']) ? $atts['location'] : false;
88
  $owm_city_id = isset($atts['owm_city_id']) ? $atts['owm_city_id'] : false;
89
  $size = (isset($atts['size']) AND $atts['size'] == "tall") ? 'tall' : 'wide';
90
- $units = (isset($atts['units']) AND strtoupper($atts['units']) == "C") ? "metric" : "imperial";
91
- $units_display = $units == "metric" ? __('C', 'awesome-weather') : __('F', 'awesome-weather');
92
  $override_title = isset($atts['override_title']) ? $atts['override_title'] : false;
93
  $days_to_show = isset($atts['forecast_days']) ? $atts['forecast_days'] : 4;
94
  $show_stats = (isset($atts['hide_stats']) AND $atts['hide_stats'] == 1) ? 0 : 1;
@@ -123,41 +124,40 @@ function awesome_weather_logic( $atts )
123
  // DISPLAY SYMBOL
124
  $units_display_symbol = apply_filters('awesome_weather_units_display', '°' );
125
  if( isset($atts['units_display_symbol']) ) $units_display_symbol = $atts['units_display_symbol'];
126
-
127
-
128
- // NO LOCATION, ABORT ABORT!!!1!
129
- if( !$location ) return awesome_weather_error();
130
 
131
 
132
  //FIND AND CACHE CITY ID
 
 
133
  if( $owm_city_id )
134
  {
135
- $city_name_slug = sanitize_title( $location );
136
- $api_query = "id=" . $owm_city_id;
137
  }
138
  else if( is_numeric($location) )
139
  {
140
- $city_name_slug = sanitize_title( $location );
141
- $api_query = "id=" . urlencode($location);
142
  }
143
  else
144
  {
145
- $city_name_slug = sanitize_title( $location );
146
- $api_query = "q=" . urlencode($location);
147
  }
148
 
149
 
150
  // OVERRIDE WITH LONG LAT, WHEN AVAILABLE
151
  if( isset($atts['lat']) AND isset($atts['lon']) )
152
  {
153
- $city_name_slug = str_replace(".","-", $atts['lat']) . "-" . str_replace(".","-", $atts['lon']);
154
- $api_query = "lat=" . $atts['lat'] . "&lon=" . $atts['lon'];
155
  }
156
 
157
 
158
  // TRANSIENT NAME
159
- $weather_transient_name = 'awe_' . $city_name_slug . "_" . $days_to_show . "_" . strtolower($units) . '_' . $locale;
160
-
161
 
162
  // CLEAR THE TRANSIENT
163
  if( isset($_GET['clear_awesome_widget']) ) delete_transient( $weather_transient_name );
@@ -180,7 +180,7 @@ function awesome_weather_logic( $atts )
180
  $weather_data['forecast'] = array();
181
 
182
  // NOW
183
- $now_ping = "https://api.openweathermap.org/data/2.5/weather?" . $api_query . "&lang=" . $locale . "&units=" . $units . $appid_string;
184
  $now_ping_get = wp_remote_get( $now_ping );
185
 
186
 
@@ -202,7 +202,7 @@ function awesome_weather_logic( $atts )
202
 
203
 
204
  // FORECAST
205
- $forecast_ping = "https://api.openweathermap.org/data/2.5/forecast?" . $api_query . "&lang=" . $locale . "&units=" . $units . $appid_string;
206
  $forecast_ping_get = wp_remote_get( $forecast_ping );
207
 
208
  if( is_wp_error( $forecast_ping_get ) )
@@ -222,7 +222,7 @@ function awesome_weather_logic( $atts )
222
  $weather_data['forecast'] = $forecast_data;
223
  }
224
 
225
- if($weather_data['now'] OR $weather_data['forecast'])
226
  {
227
  set_transient( $weather_transient_name, $weather_data, apply_filters( 'awesome_weather_cache', 1800 ) );
228
  }
@@ -255,44 +255,44 @@ function awesome_weather_logic( $atts )
255
 
256
 
257
  // TEXT COLOR
258
- if( substr(trim($text_color), 0, 1) != "#" ) $text_color = "#" . $text_color;
259
  $inline_style .= " color: {$text_color}; ";
260
 
261
 
262
  // BACKGROUND DATA, CLASSES AND OR IMAGES
263
  $background_classes = array();
264
- $background_classes[] = "awesome-weather-wrap";
265
- $background_classes[] = "awecf";
266
- $background_classes[] = "awe_" . $size;
267
 
268
  if( $custom_bg_color )
269
  {
270
- if( substr(trim($custom_bg_color), 0, 1) != "#" AND substr(trim(strtolower($custom_bg_color)), 0, 3) != "rgb" ) { $custom_bg_color = "#" . $custom_bg_color; }
271
  $inline_style .= " background-color: {$custom_bg_color}; ";
272
- $background_classes[] = "awe_custom";
273
  }
274
  else if( $today_temp )
275
  {
276
  // COLOR OF WIDGET
277
- if($units == "imperial")
278
  {
279
- if($today_temp > 31 AND $today_temp < 40) $background_classes[] = "temp2";
280
- else if($today_temp >= 40 AND $today_temp < 50) $background_classes[] = "temp3";
281
- else if($today_temp >= 50 AND $today_temp < 60) $background_classes[] = "temp4";
282
- else if($today_temp >= 60 AND $today_temp < 80) $background_classes[] = "temp5";
283
- else if($today_temp >= 80 AND $today_temp < 90) $background_classes[] = "temp6";
284
- else if($today_temp >= 90) $background_classes[] = "temp7";
285
- else $background_classes[] = "temp1";
286
  }
287
  else
288
  {
289
- if($today_temp > 1 AND $today_temp < 4) $background_classes[] = "temp2";
290
- else if($today_temp >= 4 AND $today_temp < 10) $background_classes[] = "temp3";
291
- else if($today_temp >= 10 AND $today_temp < 15) $background_classes[] = "temp4";
292
- else if($today_temp >= 15 AND $today_temp < 26) $background_classes[] = "temp5";
293
- else if($today_temp >= 26 AND $today_temp < 32) $background_classes[] = "temp6";
294
- else if($today_temp >= 32) $background_classes[] = "temp7";
295
- else $background_classes[] = "temp1";
296
  }
297
  }
298
 
@@ -308,7 +308,7 @@ function awesome_weather_logic( $atts )
308
  if( isset($today->wind->deg) ) $wind_direction = apply_filters('awesome_weather_wind_direction', $wind_label[ fmod((($today->wind->deg + 11) / 22.5),16) ]);
309
 
310
 
311
- $background_classes[] = ($show_stats) ? "awe_with_stats" : "awe_without_stats";
312
 
313
 
314
  // ADD WEATHER CONDITIONS CLASSES TO WRAP
@@ -317,25 +317,25 @@ function awesome_weather_logic( $atts )
317
  $weather_code = $today->weather[0]->id;
318
  $weather_description_slug = sanitize_title( $today->weather[0]->description );
319
 
320
- $background_classes[] = "awe-code-" . $weather_code;
321
- $background_classes[] = "awe-desc-" . $weather_description_slug;
322
  }
323
 
324
  // CHECK FOR BACKGROUND BY WEATHER
325
  if( $background_by_weather AND ( $weather_code OR $weather_description_slug ) )
326
  {
327
- if( file_exists( untrailingslashit(get_stylesheet_directory()) . "/awe-backgrounds" ) )
328
  {
329
  $bg_ext = apply_filters('awesome_weather_bg_ext', 'jpg' );
330
 
331
  // CHECK FOR CODE
332
- if( $weather_code AND file_exists( untrailingslashit(get_stylesheet_directory()) . "/awe-backgrounds/" . $weather_code . "." . $bg_ext))
333
  {
334
- $background = untrailingslashit(get_stylesheet_directory_uri()) . "/awe-backgrounds/" . $weather_code . "." . $bg_ext;
335
  }
336
- else if( $weather_description_slug AND file_exists( untrailingslashit(get_stylesheet_directory()) . "/awe-backgrounds/" . $weather_description_slug . "." . $bg_ext))
337
  {
338
- $background = untrailingslashit(get_stylesheet_directory_uri()) . "/awe-backgrounds/" . $weather_description_slug . "." . $bg_ext;
339
  }
340
  else
341
  {
@@ -344,8 +344,8 @@ function awesome_weather_logic( $atts )
344
 
345
  if( $preset_background_img_name )
346
  {
347
- $background_classes[] = "awe-preset-" . $preset_background_img_name;
348
- if( file_exists( untrailingslashit(get_stylesheet_directory()) . "/awe-backgrounds/" . $preset_background_img_name . "." . $bg_ext) ) $background = untrailingslashit(get_stylesheet_directory_uri()) . "/awe-backgrounds/" . $preset_background_img_name . "." . $bg_ext;
349
  }
350
  }
351
  }
@@ -356,19 +356,19 @@ function awesome_weather_logic( $atts )
356
 
357
  if( $preset_background_img_name )
358
  {
359
- $background_classes[] = "awe-preset-" . $preset_background_img_name;
360
- if( file_exists( untrailingslashit(dirname(__FILE__)) . "/img/awe-backgrounds/" . $preset_background_img_name . ".jpg") ) $background = untrailingslashit(plugin_dir_url( __FILE__ )) . "/img/awe-backgrounds/" . $preset_background_img_name . ".jpg";
361
  }
362
  }
363
  }
364
 
365
 
366
  // EXTRA STYLES
367
- if($background) $background_classes[] = "darken";
368
- if($inline_style != "") $inline_style = " style=\"{$inline_style}\"";
369
 
370
 
371
- $background_class_string = @implode( " ", apply_filters( 'awesome_weather_background_classes', $background_classes ));
372
 
373
 
374
  // ATTR: data_only = BAIL OUT WITH JUST THE WEATHER DATA
@@ -560,14 +560,13 @@ add_action( 'wp_ajax_awe_ping_owm_for_id', 'awe_ping_owm_for_id');
560
  function awe_ping_owm_for_id( )
561
  {
562
  $appid_string = '';
563
- $appid = apply_filters('awesome_weather_appid', awe_get_appid());
564
- if($appid) $appid_string = '&APPID=' . $appid;
565
-
566
  $location = urlencode($_GET['location']);
567
- $units = $_GET['units'] == "C" ? "metric" : "imperial";
568
- $owm_ping = "http://api.openweathermap.org/data/2.5/find?q=" . $location ."&units=" . $units . "&mode=json" . $appid_string;
569
  $owm_ping_get = wp_remote_get( $owm_ping );
570
- header("Content-Type: application/json");
571
  echo $owm_ping_get['body'];
572
  die;
573
  }
@@ -576,24 +575,34 @@ function awe_ping_owm_for_id( )
576
  // PRESET WEATHER BACKGROUND NAMES
577
  function awesome_weather_preset_condition_names_openweathermaps( $weather_code )
578
  {
579
- if( substr($weather_code,0,1) == "2" ) return "thunderstorm";
580
- else if( substr($weather_code,0,1) == "3" ) return "drizzle";
581
- else if( substr($weather_code,0,1) == "5" ) return "rain";
582
- else if( $weather_code == 611 ) return "sleet";
583
- else if( substr($weather_code,0,1) == "6" OR $weather_code == 903 ) return "snow";
584
- else if( $weather_code == 781 OR $weather_code == 900 ) return "tornado";
585
- else if( $weather_code == 800 OR $weather_code == 904 ) return "sunny";
586
- else if( substr($weather_code,0,1) == "7" ) return "atmosphere";
587
- else if( substr($weather_code,0,1) == "8" ) return "cloudy";
588
- else if( $weather_code == 901 ) return "tropical-storm";
589
- else if( $weather_code == 902 OR $weather_code == 962 ) return "hurricane";
590
- else if( $weather_code == 905 ) return "windy";
591
- else if( $weather_code == 906 ) return "hail";
592
- else if( $weather_code == 951 ) return "calm";
593
- else if( $weather_code > 951 AND $weather_code < 962 ) return "breeze";
594
  }
595
 
596
 
 
 
 
 
 
 
 
 
 
 
597
 
598
 
599
  // WIDGET
5
  Description: A weather widget that actually looks cool
6
  Author: Hal Gatewood
7
  Author URI: https://www.halgatewood.com
8
+ Version: 2.0
9
  Text Domain: awesome-weather
10
  Domain Path: /languages
11
 
16
  */
17
 
18
 
19
+ define( 'AWESOME_WEATHER_OWM_API_URL', 'https://api.openweathermap.org/data/2.5/' );
20
 
21
  // SETTINGS
22
  $awesome_weather_sizes = apply_filters( 'awesome_weather_sizes' , array( 'tall', 'wide' ) );
26
  function awesome_weather_setup()
27
  {
28
  $locale = apply_filters('plugin_locale', get_locale(), 'awesome-weather');
29
+ $mofile = WP_LANG_DIR . '/awesome-weather/awesome-weather-' . $locale . '.mo';
30
 
31
  if( file_exists( $mofile ) )
32
  {
83
 
84
  $dt_today = date( 'Ymd', current_time( 'timestamp', 0 ) );
85
 
86
+ $rtn = '';
87
  $weather_data = array();
88
+ $location = isset($atts['location']) ? awesome_weather_prep_location($atts['location']) : false;
89
  $owm_city_id = isset($atts['owm_city_id']) ? $atts['owm_city_id'] : false;
90
  $size = (isset($atts['size']) AND $atts['size'] == "tall") ? 'tall' : 'wide';
91
+ $units = (isset($atts['units']) AND strtoupper($atts['units']) == 'C') ? 'metric' : 'imperial';
92
+ $units_display = $units == 'metric' ? __('C', 'awesome-weather') : __('F', 'awesome-weather');
93
  $override_title = isset($atts['override_title']) ? $atts['override_title'] : false;
94
  $days_to_show = isset($atts['forecast_days']) ? $atts['forecast_days'] : 4;
95
  $show_stats = (isset($atts['hide_stats']) AND $atts['hide_stats'] == 1) ? 0 : 1;
124
  // DISPLAY SYMBOL
125
  $units_display_symbol = apply_filters('awesome_weather_units_display', '&deg;' );
126
  if( isset($atts['units_display_symbol']) ) $units_display_symbol = $atts['units_display_symbol'];
127
+
128
+
129
+ // NEED SOMETHING TO WORK WITH, IF NOT, RETURN ERROR
130
+ if( !$location AND !$owm_city_id ) { return awesome_weather_error( __('City Not Found', 'awesome-weather-pro') ); }
131
 
132
 
133
  //FIND AND CACHE CITY ID
134
+ $city_name_slug = sanitize_title( $location );
135
+
136
  if( $owm_city_id )
137
  {
138
+ if( !$city_name_slug ) $city_name_slug = $owm_city_id;
139
+ $api_query = 'id=' . $owm_city_id;
140
  }
141
  else if( is_numeric($location) )
142
  {
143
+ $api_query = 'id=' . urlencode($location);
 
144
  }
145
  else
146
  {
147
+ $api_query = 'q=' . urlencode($location);
 
148
  }
149
 
150
 
151
  // OVERRIDE WITH LONG LAT, WHEN AVAILABLE
152
  if( isset($atts['lat']) AND isset($atts['lon']) )
153
  {
154
+ $city_name_slug = str_replace('.', '-', $atts['lat']) . '-' . str_replace('.', '-', $atts['lon']);
155
+ $api_query = 'lat=' . $atts['lat'] . '&lon=' . $atts['lon'];
156
  }
157
 
158
 
159
  // TRANSIENT NAME
160
+ $weather_transient_name = 'awe_' . $city_name_slug . '_' . $days_to_show . '_' . strtolower($units) . '_' . $locale;
 
161
 
162
  // CLEAR THE TRANSIENT
163
  if( isset($_GET['clear_awesome_widget']) ) delete_transient( $weather_transient_name );
180
  $weather_data['forecast'] = array();
181
 
182
  // NOW
183
+ $now_ping = AWESOME_WEATHER_OWM_API_URL . 'weather?' . $api_query . '&lang=' . $locale . '&units=' . $units . $appid_string;
184
  $now_ping_get = wp_remote_get( $now_ping );
185
 
186
 
202
 
203
 
204
  // FORECAST
205
+ $forecast_ping = AWESOME_WEATHER_OWM_API_URL . 'forecast?' . $api_query . '&lang=' . $locale . '&units=' . $units . $appid_string;
206
  $forecast_ping_get = wp_remote_get( $forecast_ping );
207
 
208
  if( is_wp_error( $forecast_ping_get ) )
222
  $weather_data['forecast'] = $forecast_data;
223
  }
224
 
225
+ if( $weather_data['now'] OR $weather_data['forecast'])
226
  {
227
  set_transient( $weather_transient_name, $weather_data, apply_filters( 'awesome_weather_cache', 1800 ) );
228
  }
255
 
256
 
257
  // TEXT COLOR
258
+ if( substr(trim($text_color), 0, 1) != '#' ) $text_color = '#' . $text_color;
259
  $inline_style .= " color: {$text_color}; ";
260
 
261
 
262
  // BACKGROUND DATA, CLASSES AND OR IMAGES
263
  $background_classes = array();
264
+ $background_classes[] = 'awesome-weather-wrap';
265
+ $background_classes[] = 'awecf';
266
+ $background_classes[] = 'awe_' . $size;
267
 
268
  if( $custom_bg_color )
269
  {
270
+ if( substr(trim($custom_bg_color), 0, 1) != '#' AND substr(trim(strtolower($custom_bg_color)), 0, 3) != 'rgb' ) { $custom_bg_color = '#' . $custom_bg_color; }
271
  $inline_style .= " background-color: {$custom_bg_color}; ";
272
+ $background_classes[] = 'awe_custom';
273
  }
274
  else if( $today_temp )
275
  {
276
  // COLOR OF WIDGET
277
+ if( $units == 'imperial' )
278
  {
279
+ if($today_temp > 31 AND $today_temp < 40) $background_classes[] = 'temp2';
280
+ else if($today_temp >= 40 AND $today_temp < 50) $background_classes[] = 'temp3';
281
+ else if($today_temp >= 50 AND $today_temp < 60) $background_classes[] = 'temp4';
282
+ else if($today_temp >= 60 AND $today_temp < 80) $background_classes[] = 'temp5';
283
+ else if($today_temp >= 80 AND $today_temp < 90) $background_classes[] = 'temp6';
284
+ else if($today_temp >= 90) $background_classes[] = 'temp7';
285
+ else $background_classes[] = 'temp1';
286
  }
287
  else
288
  {
289
+ if($today_temp > 1 AND $today_temp < 4) $background_classes[] = 'temp2';
290
+ else if($today_temp >= 4 AND $today_temp < 10) $background_classes[] = 'temp3';
291
+ else if($today_temp >= 10 AND $today_temp < 15) $background_classes[] = 'temp4';
292
+ else if($today_temp >= 15 AND $today_temp < 26) $background_classes[] = 'temp5';
293
+ else if($today_temp >= 26 AND $today_temp < 32) $background_classes[] = 'temp6';
294
+ else if($today_temp >= 32) $background_classes[] = 'temp7';
295
+ else $background_classes[] = 'temp';
296
  }
297
  }
298
 
308
  if( isset($today->wind->deg) ) $wind_direction = apply_filters('awesome_weather_wind_direction', $wind_label[ fmod((($today->wind->deg + 11) / 22.5),16) ]);
309
 
310
 
311
+ $background_classes[] = ($show_stats) ? 'awe_with_stats' : 'awe_without_stats';
312
 
313
 
314
  // ADD WEATHER CONDITIONS CLASSES TO WRAP
317
  $weather_code = $today->weather[0]->id;
318
  $weather_description_slug = sanitize_title( $today->weather[0]->description );
319
 
320
+ $background_classes[] = 'awe-code-' . $weather_code;
321
+ $background_classes[] = 'awe-desc-' . $weather_description_slug;
322
  }
323
 
324
  // CHECK FOR BACKGROUND BY WEATHER
325
  if( $background_by_weather AND ( $weather_code OR $weather_description_slug ) )
326
  {
327
+ if( file_exists( untrailingslashit(get_stylesheet_directory()) . '/awe-backgrounds' ) )
328
  {
329
  $bg_ext = apply_filters('awesome_weather_bg_ext', 'jpg' );
330
 
331
  // CHECK FOR CODE
332
+ if( $weather_code AND file_exists( untrailingslashit(get_stylesheet_directory()) . '/awe-backgrounds/' . $weather_code . '.' . $bg_ext))
333
  {
334
+ $background = untrailingslashit(get_stylesheet_directory_uri()) . '/awe-backgrounds/' . $weather_code . '.' . $bg_ext;
335
  }
336
+ else if( $weather_description_slug AND file_exists( untrailingslashit(get_stylesheet_directory()) . '/awe-backgrounds/' . $weather_description_slug . "." . $bg_ext))
337
  {
338
+ $background = untrailingslashit(get_stylesheet_directory_uri()) . '/awe-backgrounds/' . $weather_description_slug . '.' . $bg_ext;
339
  }
340
  else
341
  {
344
 
345
  if( $preset_background_img_name )
346
  {
347
+ $background_classes[] = 'awe-preset-' . $preset_background_img_name;
348
+ if( file_exists( untrailingslashit(get_stylesheet_directory()) . '/awe-backgrounds/' . $preset_background_img_name . '.' . $bg_ext) ) $background = untrailingslashit(get_stylesheet_directory_uri()) . '/awe-backgrounds/' . $preset_background_img_name . '.' . $bg_ext;
349
  }
350
  }
351
  }
356
 
357
  if( $preset_background_img_name )
358
  {
359
+ $background_classes[] = 'awe-preset-' . $preset_background_img_name;
360
+ if( file_exists( untrailingslashit(dirname(__FILE__)) . '/img/awe-backgrounds/' . $preset_background_img_name . '.jpg') ) $background = untrailingslashit(plugin_dir_url( __FILE__ )) . '/img/awe-backgrounds/' . $preset_background_img_name . '.jpg';
361
  }
362
  }
363
  }
364
 
365
 
366
  // EXTRA STYLES
367
+ if($background) $background_classes[] = 'darken';
368
+ if($inline_style != '') $inline_style = ' style="' . $inline_style . '"';
369
 
370
 
371
+ $background_class_string = @implode( ' ', apply_filters( 'awesome_weather_background_classes', $background_classes ));
372
 
373
 
374
  // ATTR: data_only = BAIL OUT WITH JUST THE WEATHER DATA
560
  function awe_ping_owm_for_id( )
561
  {
562
  $appid_string = '';
563
+ $appid = awe_get_appid();
564
+ if( $appid ) $appid_string = '&APPID=' . $appid;
565
+
566
  $location = urlencode($_GET['location']);
567
+ $units = strtoupper($_GET['location']) == 'C' ? 'metric' : 'imperial';
568
+ $owm_ping = AWESOME_WEATHER_OWM_API_URL . 'find?q=' . $location . '&units=' . $units . '&mode=json' . $appid_string;
569
  $owm_ping_get = wp_remote_get( $owm_ping );
 
570
  echo $owm_ping_get['body'];
571
  die;
572
  }
575
  // PRESET WEATHER BACKGROUND NAMES
576
  function awesome_weather_preset_condition_names_openweathermaps( $weather_code )
577
  {
578
+ if( substr($weather_code,0,1) == '2' ) return 'thunderstorm';
579
+ else if( substr($weather_code,0,1) == '3' ) return 'drizzle';
580
+ else if( substr($weather_code,0,1) == '5' ) return 'rain';
581
+ else if( $weather_code == 611 ) return 'sleet';
582
+ else if( substr($weather_code,0,1) == '6' OR $weather_code == 903 ) return 'snow';
583
+ else if( $weather_code == 781 OR $weather_code == 900 ) return 'tornado';
584
+ else if( $weather_code == 800 OR $weather_code == 904 ) return 'sunny';
585
+ else if( substr($weather_code,0,1) == '7' ) return 'atmosphere';
586
+ else if( substr($weather_code,0,1) == '8' ) return 'cloudy';
587
+ else if( $weather_code == 901 ) return 'tropical-storm';
588
+ else if( $weather_code == 902 OR $weather_code == 962 ) return 'hurricane';
589
+ else if( $weather_code == 905 ) return 'windy';
590
+ else if( $weather_code == 906 ) return 'hail';
591
+ else if( $weather_code == 951 ) return 'calm';
592
+ else if( $weather_code > 951 AND $weather_code < 962 ) return 'breeze';
593
  }
594
 
595
 
596
+ // HELP CLEAN UP TITLE FOR API
597
+ function awesome_weather_prep_location($text)
598
+ {
599
+ $text = stripslashes($text);
600
+ $text = str_replace(array("\xe2\x80\x98", "\xe2\x80\x99", "\xe2\x80\x9c", "\xe2\x80\x9d", "\xe2\x80\x93", "\xe2\x80\x94", "\xe2\x80\xa6"), array("'", "'", '', '', '-', '--', '...'), $text);
601
+ $text = str_replace(array(chr(145), chr(146), chr(147), chr(148), chr(150), chr(151), chr(133)), array("'", "'", '', '', '-', '--', '...'), $text);
602
+ return $text;
603
+ }
604
+
605
+
606
 
607
 
608
  // WIDGET
readme.txt CHANGED
@@ -3,7 +3,7 @@ Contributors: halgatewood
3
  Donate link: https://halgatewood.com/donate/
4
  Tags: widgets, sidebar, shortcode, openweathermap, weather, weather widget, forecast, global, temp, local weather,local forecast
5
  Requires at least: 3.5
6
- Tested up to: 4.8
7
  Stable tag: trunk
8
  License: GPLv2 or later
9
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
@@ -12,26 +12,31 @@ Finally beautiful weather widgets for your beautiful site.
12
 
13
  == Description ==
14
 
15
- >[Pro Version](https://halgatewood.com/downloads/awesome-weather-widget-pro/) available. Weather icons, 5 New Layouts and Custom Templates, Weather by Yahoo! (no API key required), User Location Detection, Email Support.
16
 
17
  This plugin allows you to easily add super clean (and awesome) weather widgets to your site.
18
 
19
- The weather data is provided for free by http://openweathermap.org and as of October 2015, they require an [API Key](http://openweathermap.org/appid#get) to access their weather.
20
- Once you have the API Key you can simply add it in 'Settings' -> 'Awesome Weather' and you're ready to go.
21
 
22
- [View the API Key Help Document](https://halgatewood.com/docs/plugins/awesome-weather-widget/register-for-an-openweathermap-api-key-appid)
 
23
 
24
- Use the built in widget with all of its marvelous settings or add it to a page or theme with the shortcode:
25
-
26
- Easiest:
27
- `[awesome-weather location="Oklahoma City"]`
 
28
 
29
- [All Available Parameters](https://halgatewood.com/docs/plugins/awesome-weather-widget/using-shortcode):
30
- `[awesome-weather location="Montreal" units="F" owm_city_id="6077243" size="tall" override_title="MTL" forecast_days="3" hide_stats="1" background="http://urltoanimage.jpg" custom_bg_color="#cccccc" inline_style="width: 200px; margin: 20px; float: left;" background_by_weather="1" text_color="#000" locale="fr"]`
31
 
32
- = Settings =
 
 
33
 
34
- * Location: Enter a string like "Montreal, CA" or just "Montreal". You can even get the City ID from OpenWeatherMap and use that.
 
35
  * Units: F (default) or C
36
  * Size: wide (default) or tall
37
  * Override Title: Change the title in the header bar to whatever, sometimes it pulls weather from a close city
@@ -39,9 +44,9 @@ Easiest:
39
  * Hide stats: Hide the text stats like humidity, wind, high and lows, etc
40
  * Background: URL to an image that will be used as the background of the entire widget
41
  * Custom Background Color: Add a hex color to override the default colors
42
- * Inline Styles: Add inline CSS styles to your widget to float around text and whatever else
43
- * Background Image Based on Weather (v1.5+): Set this to 1 if you want to use different images for different weather types, How to: https://halgatewood.com/awesome-weather-bgs
44
- * Text Color: Easily change the text color of the widget without CSS
45
  * Locale: New locale attribute for shortcodes allows you to change the weather description text without having to change your whole WordPress installation.
46
 
47
  = Translations =
@@ -91,6 +96,11 @@ The easiest shortcode setting is just: `[awesome-weather location="Oklahoma City
91
 
92
  == Changelog ==
93
 
 
 
 
 
 
94
  = 1.5.14 =
95
  * As per consensus in the support forums, we have changed the forecast temp to use the max temp instead of the generic variable returned from the weather data
96
 
3
  Donate link: https://halgatewood.com/donate/
4
  Tags: widgets, sidebar, shortcode, openweathermap, weather, weather widget, forecast, global, temp, local weather,local forecast
5
  Requires at least: 3.5
6
+ Tested up to: 5.0
7
  Stable tag: trunk
8
  License: GPLv2 or later
9
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
12
 
13
  == Description ==
14
 
15
+ >[Pro Version](https://halgatewood.com/downloads/awesome-weather-widget-pro/) available. Weather icons, AJAX loading, 5 New Layouts, Ability to make Custom Templates, User Location Detection.
16
 
17
  This plugin allows you to easily add super clean (and awesome) weather widgets to your site.
18
 
19
+ = Weather by OpenWeatherMap =
20
+ The weather data is generated by [OpenWeatherMap](https://openweathermap.org). They require a free [API Key](http://openweathermap.org/appid#get) to access the data. Once you have the API Key, you can save it in the WordPress admin under `'Settings' -> 'Awesome Weather'`
21
 
22
+ = Help Guides =
23
+ There are lots of juicy [Help Guides on my website](https://halgatewood.com/docs/plugins/awesome-weather-widget). These will answer most of the questions you have. Some popular ones include:
24
 
25
+ * [Adding a Widget](https://halgatewood.com/docs/plugins/awesome-weather-widget/adding-widget)
26
+ * [Shotcode Attributes](https://halgatewood.com/docs/plugins/awesome-weather-widget/using-shortcode)
27
+ * [Available Filters](https://halgatewood.com/docs/plugins/awesome-weather-widget/available-filters)
28
+ * [Cache Settings](https://halgatewood.com/docs/plugins/awesome-weather-widget/clearing-weather-cache)
29
+ * [API Key Settings](https://halgatewood.com/docs/plugins/awesome-weather-widget/register-for-an-openweathermap-api-key-appid)
30
 
31
+ = About the Developer =
32
+ The development of this plugin was done by [Hal Gatewood](https://halgatewood.com) mostly when I should be sleeping. I have a full time job that is not building WordPress plugins, so please remember that we you submit your support tickets. I also **do not work for OpenWeatherMap** and have no control over the quality of the weather data returned from them. Sorry.
33
 
34
+ = Setup =
35
+ Use the built in widget with all of its marvelous settings or add it to a page or theme with the shortcode:
36
+ `[awesome-weather owm_city_id="4544349"]` or `[awesome-weather location="Oklahoma City"]`
37
 
38
+ = Settings Overview =
39
+ * Location: Enter a string like "Montreal". You can even [get your City ID from OpenWeatherMap](https://halgatewood.com/docs/plugins/awesome-weather-widget/finding-city-id) and use that.
40
  * Units: F (default) or C
41
  * Size: wide (default) or tall
42
  * Override Title: Change the title in the header bar to whatever, sometimes it pulls weather from a close city
44
  * Hide stats: Hide the text stats like humidity, wind, high and lows, etc
45
  * Background: URL to an image that will be used as the background of the entire widget
46
  * Custom Background Color: Add a hex color to override the default colors
47
+ * Inline Styles: Add inline CSS styles to your widget
48
+ * Background Image Based on Weather: Use different images for different weather types [Help Guide](https://halgatewood.com/awesome-weather-bgs)
49
+ * Text Color: Change the text color of the widget without CSS
50
  * Locale: New locale attribute for shortcodes allows you to change the weather description text without having to change your whole WordPress installation.
51
 
52
  = Translations =
96
 
97
  == Changelog ==
98
 
99
+ = 2.0 =
100
+ * Improvements to City Lookup
101
+ * Either location attribute or owm_city_id is required, not both now!
102
+ * Code cleanup
103
+
104
  = 1.5.14 =
105
  * As per consensus in the support forums, we have changed the forecast temp to use the max temp instead of the generic variable returned from the weather data
106
 
widget.php CHANGED
@@ -98,8 +98,8 @@ class AwesomeWeatherWidget extends WP_Widget
98
  <?php if(!$appid) { ?>
99
  <div style="background: #dc3232; color: #fff; padding: 10px; margin: 10px;">
100
  <?php
101
- echo __("As of October 2015, OpenWeatherMap requires an APP ID key to access their weather data.", 'awesome-weather');
102
- echo " <a href='http://openweathermap.org/appid' target='_blank' style='color: #fff;'>";
103
  echo __('Get your APPID', 'awesome-weather');
104
  echo "</a> ";
105
  echo __("and add it to the new settings page.");
@@ -229,4 +229,8 @@ class AwesomeWeatherWidget extends WP_Widget
229
  }
230
  }
231
 
232
- add_action( 'widgets_init', create_function('', 'return register_widget("AwesomeWeatherWidget");') );
 
 
 
 
98
  <?php if(!$appid) { ?>
99
  <div style="background: #dc3232; color: #fff; padding: 10px; margin: 10px;">
100
  <?php
101
+ echo __("OpenWeatherMap requires an APP ID key to access their weather data.", 'awesome-weather');
102
+ echo " <a href='https://openweathermap.org/appid' target='_blank' style='color: #fff;'>";
103
  echo __('Get your APPID', 'awesome-weather');
104
  echo "</a> ";
105
  echo __("and add it to the new settings page.");
229
  }
230
  }
231
 
232
+ function awe_widgets_register()
233
+ {
234
+ register_widget( 'AwesomeWeatherWidget' );
235
+ }
236
+ add_action( 'widgets_init', 'awe_widgets_register' );