Version Description
Download this release
Release Info
Developer | halgatewood |
Plugin | Awesome Weather Widget |
Version | 1.5.15 |
Comparing to | |
See all releases |
Code changes from version 1.5.14 to 1.5.15
- awesome-weather.php +41 -25
- widget.php +1 -2
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.
|
9 |
Text Domain: awesome-weather
|
10 |
Domain Path: /languages
|
11 |
|
@@ -13,7 +13,6 @@ Domain Path: /languages
|
|
13 |
Hi DEVS!
|
14 |
FILTERS AVAILABLE:
|
15 |
https://halgatewood.com/docs/plugins/awesome-weather-widget/available-filters
|
16 |
-
|
17 |
*/
|
18 |
|
19 |
|
@@ -91,7 +90,7 @@ function awesome_weather_logic( $atts )
|
|
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'] :
|
95 |
$show_stats = (isset($atts['hide_stats']) AND $atts['hide_stats'] == 1) ? 0 : 1;
|
96 |
$show_attribution = (isset($atts['hide_attribution']) AND $atts['hide_attribution'] == 1) ? 0 : 1;
|
97 |
$background_by_weather = (isset($atts['background_by_weather']) AND $atts['background_by_weather'] == 1) ? 1 : 0;
|
@@ -105,6 +104,9 @@ function awesome_weather_logic( $atts )
|
|
105 |
$sytem_locale = get_locale();
|
106 |
$available_locales = apply_filters('awesome_weather_available_locales', array( 'en', 'es', 'sp', 'fr', 'it', 'de', 'pt', 'ro', 'pl', 'ru', 'uk', 'ua', 'fi', 'nl', 'bg', 'sv', 'se', 'sk', 'ca', 'tr', 'hr', 'zh', 'zh_tw', 'zh_cn', 'hu' ) );
|
107 |
|
|
|
|
|
|
|
108 |
|
109 |
// CHECK FOR LOCALE
|
110 |
if( in_array( $sytem_locale, $available_locales ) ) $locale = $sytem_locale;
|
@@ -155,11 +157,6 @@ function awesome_weather_logic( $atts )
|
|
155 |
|
156 |
// TRANSIENT NAME
|
157 |
$weather_transient_name = 'awe_' . $city_name_slug . "_" . $days_to_show . "_" . strtolower($units) . '_' . $locale;
|
158 |
-
|
159 |
-
|
160 |
-
// TWO APIS USED (VERSION 2.5)
|
161 |
-
//http://api.openweathermap.org/data/2.5/weather?q=London,uk&units=metric&cnt=7&lang=fr
|
162 |
-
//http://api.openweathermap.org/data/2.5/forecast?q=London&units=metric&cnt=7&lang=fr
|
163 |
|
164 |
|
165 |
// CLEAR THE TRANSIENT
|
@@ -183,7 +180,7 @@ function awesome_weather_logic( $atts )
|
|
183 |
$weather_data['forecast'] = array();
|
184 |
|
185 |
// NOW
|
186 |
-
$now_ping = "
|
187 |
$now_ping_get = wp_remote_get( $now_ping );
|
188 |
|
189 |
|
@@ -205,7 +202,7 @@ function awesome_weather_logic( $atts )
|
|
205 |
|
206 |
|
207 |
// FORECAST
|
208 |
-
$forecast_ping = "
|
209 |
$forecast_ping_get = wp_remote_get( $forecast_ping );
|
210 |
|
211 |
if( is_wp_error( $forecast_ping_get ) )
|
@@ -231,7 +228,6 @@ function awesome_weather_logic( $atts )
|
|
231 |
}
|
232 |
}
|
233 |
|
234 |
-
|
235 |
|
236 |
// NO WEATHER
|
237 |
if( !$weather_data OR !isset($weather_data['now'])) return awesome_weather_error();
|
@@ -300,6 +296,7 @@ function awesome_weather_logic( $atts )
|
|
300 |
}
|
301 |
}
|
302 |
|
|
|
303 |
// DATA
|
304 |
$header_title = $override_title ? $override_title : $today->name;
|
305 |
|
@@ -426,35 +423,54 @@ function awesome_weather_logic( $atts )
|
|
426 |
$c = 1;
|
427 |
$forecast = $weather_data['forecast'];
|
428 |
|
429 |
-
$last_day_visible = 0;
|
430 |
|
|
|
431 |
$days_to_show = (int) $days_to_show;
|
|
|
|
|
|
|
|
|
432 |
$days_of_week = apply_filters( 'awesome_weather_days_of_week', array( __('Sun' ,'awesome-weather'), __('Mon' ,'awesome-weather'), __('Tue' ,'awesome-weather'), __('Wed' ,'awesome-weather'), __('Thu' ,'awesome-weather'), __('Fri' ,'awesome-weather'), __('Sat' ,'awesome-weather') ) );
|
433 |
|
434 |
-
if(!isset($forecast->list)) $forecast->list = array();
|
435 |
|
436 |
-
|
|
|
|
|
437 |
{
|
438 |
// GET DAY OF WEEK NUMBER
|
439 |
-
$day_of_week_number = date('w', $
|
440 |
-
|
441 |
-
// ONLY SHOW ONE FORCAST PER DAY
|
442 |
-
if( $day_of_week_number == $last_day_visible ) continue;
|
443 |
-
$last_day_visible = $day_of_week_number;
|
444 |
|
445 |
// IF TODAY IS GREATER THAN FORECAST DAY, SKIP
|
446 |
-
if( $dt_today >= date('Ymd', $
|
447 |
|
448 |
|
449 |
-
|
450 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
451 |
$rtn .= "
|
452 |
<div class=\"awesome-weather-forecast-day\">
|
453 |
<div class=\"awesome-weather-forecast-day-temp\">{$forecast->temp}<sup>{$units_display_symbol}</sup></div>
|
454 |
-
<div class=\"awesome-weather-forecast-day-abbr\">{$day_of_week}</div>
|
455 |
</div>";
|
456 |
-
if($c == $days_to_show) break;
|
457 |
-
$c++;
|
458 |
}
|
459 |
$rtn .= "</div><!-- /.awesome-weather-forecast -->";
|
460 |
}
|
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 |
|
13 |
Hi DEVS!
|
14 |
FILTERS AVAILABLE:
|
15 |
https://halgatewood.com/docs/plugins/awesome-weather-widget/available-filters
|
|
|
16 |
*/
|
17 |
|
18 |
|
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;
|
95 |
$show_attribution = (isset($atts['hide_attribution']) AND $atts['hide_attribution'] == 1) ? 0 : 1;
|
96 |
$background_by_weather = (isset($atts['background_by_weather']) AND $atts['background_by_weather'] == 1) ? 1 : 0;
|
104 |
$sytem_locale = get_locale();
|
105 |
$available_locales = apply_filters('awesome_weather_available_locales', array( 'en', 'es', 'sp', 'fr', 'it', 'de', 'pt', 'ro', 'pl', 'ru', 'uk', 'ua', 'fi', 'nl', 'bg', 'sv', 'se', 'sk', 'ca', 'tr', 'hr', 'zh', 'zh_tw', 'zh_cn', 'hu' ) );
|
106 |
|
107 |
+
// SANITIZE
|
108 |
+
if( $days_to_show > 4 ) $days_to_show = 4;
|
109 |
+
|
110 |
|
111 |
// CHECK FOR LOCALE
|
112 |
if( in_array( $sytem_locale, $available_locales ) ) $locale = $sytem_locale;
|
157 |
|
158 |
// TRANSIENT NAME
|
159 |
$weather_transient_name = 'awe_' . $city_name_slug . "_" . $days_to_show . "_" . strtolower($units) . '_' . $locale;
|
|
|
|
|
|
|
|
|
|
|
160 |
|
161 |
|
162 |
// CLEAR THE TRANSIENT
|
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 |
|
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 ) )
|
228 |
}
|
229 |
}
|
230 |
|
|
|
231 |
|
232 |
// NO WEATHER
|
233 |
if( !$weather_data OR !isset($weather_data['now'])) return awesome_weather_error();
|
296 |
}
|
297 |
}
|
298 |
|
299 |
+
|
300 |
// DATA
|
301 |
$header_title = $override_title ? $override_title : $today->name;
|
302 |
|
423 |
$c = 1;
|
424 |
$forecast = $weather_data['forecast'];
|
425 |
|
|
|
426 |
|
427 |
+
// SANITIZE
|
428 |
$days_to_show = (int) $days_to_show;
|
429 |
+
if(!isset($forecast->list)) $forecast->list = array();
|
430 |
+
|
431 |
+
|
432 |
+
// TEXT: days of the week
|
433 |
$days_of_week = apply_filters( 'awesome_weather_days_of_week', array( __('Sun' ,'awesome-weather'), __('Mon' ,'awesome-weather'), __('Tue' ,'awesome-weather'), __('Wed' ,'awesome-weather'), __('Thu' ,'awesome-weather'), __('Fri' ,'awesome-weather'), __('Sat' ,'awesome-weather') ) );
|
434 |
|
|
|
435 |
|
436 |
+
// LOOP TO GET DAY HIGH
|
437 |
+
$forecast_days = array();
|
438 |
+
foreach( (array) $forecast->list as $forecast_hour )
|
439 |
{
|
440 |
// GET DAY OF WEEK NUMBER
|
441 |
+
$day_of_week_number = date('w', $forecast_hour->dt);
|
442 |
+
|
|
|
|
|
|
|
443 |
|
444 |
// IF TODAY IS GREATER THAN FORECAST DAY, SKIP
|
445 |
+
if( $dt_today >= date('Ymd', $forecast_hour->dt)) continue;
|
446 |
|
447 |
|
448 |
+
// CREATE OBJECT OFF FIRST OCCURENCE OF THE DAY
|
449 |
+
if( !isset($forecast_days[$day_of_week_number]) )
|
450 |
+
{
|
451 |
+
$forecast_days[$day_of_week_number] = new stdclass;
|
452 |
+
$forecast_days[$day_of_week_number]->temp = round($forecast_hour->main->temp_max);
|
453 |
+
$forecast_days[$day_of_week_number]->day_of_week = $days_of_week[ date('w', $forecast_hour->dt) ];
|
454 |
+
}
|
455 |
+
|
456 |
+
// IF MAX TEMP IS HIGHER THAN THE CURRENT ONE, USE IT
|
457 |
+
if( $forecast_hour->main->temp_max > $forecast_days[$day_of_week_number]->temp )
|
458 |
+
{
|
459 |
+
$forecast_days[$day_of_week_number]->temp = round($forecast_hour->main->temp_max);
|
460 |
+
}
|
461 |
+
}
|
462 |
+
|
463 |
+
// GET ONLY THE AMOUNT OF DAYS TO SHOW, BASED ON ATTRIBUTE: forecast_days
|
464 |
+
$forecast_days = array_slice( $forecast_days, 0, $days_to_show );
|
465 |
+
|
466 |
+
// LOOP ACTUAL DAYS
|
467 |
+
foreach( $forecast_days as $forecast )
|
468 |
+
{
|
469 |
$rtn .= "
|
470 |
<div class=\"awesome-weather-forecast-day\">
|
471 |
<div class=\"awesome-weather-forecast-day-temp\">{$forecast->temp}<sup>{$units_display_symbol}</sup></div>
|
472 |
+
<div class=\"awesome-weather-forecast-day-abbr\">{$forecast->day_of_week}</div>
|
473 |
</div>";
|
|
|
|
|
474 |
}
|
475 |
$rtn .= "</div><!-- /.awesome-weather-forecast -->";
|
476 |
}
|
widget.php
CHANGED
@@ -74,7 +74,7 @@ class AwesomeWeatherWidget extends WP_Widget
|
|
74 |
$widget_title = isset($instance['widget_title']) ? esc_attr($instance['widget_title']) : "";
|
75 |
$selected_size = isset($instance['size']) ? esc_attr($instance['size']) : "wide";
|
76 |
$units = (isset($instance['units']) AND strtoupper($instance['units']) == "C") ? "C" : "F";
|
77 |
-
$forecast_days = isset($instance['forecast_days']) ? esc_attr($instance['forecast_days']) :
|
78 |
$hide_stats = (isset($instance['hide_stats']) AND $instance['hide_stats'] == 1) ? 1 : 0;
|
79 |
$hide_attribution = (isset($instance['hide_attribution']) AND $instance['hide_attribution'] == 1) ? 1 : 0;
|
80 |
$background_by_weather = (isset($instance['background_by_weather']) AND $instance['background_by_weather'] == 1) ? 1 : 0;
|
@@ -161,7 +161,6 @@ class AwesomeWeatherWidget extends WP_Widget
|
|
161 |
<p>
|
162 |
<label for="<?php echo $this->get_field_id('forecast_days'); ?>"><?php _e('Forecast:', 'awesome-weather'); ?></label>
|
163 |
<select class="widefat" id="<?php echo $this->get_field_id('forecast_days'); ?>" name="<?php echo $this->get_field_name('forecast_days'); ?>">
|
164 |
-
<option value="5"<?php if($forecast_days == 5) echo " selected=\"selected\""; ?>>5 Days</option>
|
165 |
<option value="4"<?php if($forecast_days == 4) echo " selected=\"selected\""; ?>>4 Days</option>
|
166 |
<option value="3"<?php if($forecast_days == 3) echo " selected=\"selected\""; ?>>3 Days</option>
|
167 |
<option value="2"<?php if($forecast_days == 2) echo " selected=\"selected\""; ?>>2 Days</option>
|
74 |
$widget_title = isset($instance['widget_title']) ? esc_attr($instance['widget_title']) : "";
|
75 |
$selected_size = isset($instance['size']) ? esc_attr($instance['size']) : "wide";
|
76 |
$units = (isset($instance['units']) AND strtoupper($instance['units']) == "C") ? "C" : "F";
|
77 |
+
$forecast_days = isset($instance['forecast_days']) ? esc_attr($instance['forecast_days']) : 4;
|
78 |
$hide_stats = (isset($instance['hide_stats']) AND $instance['hide_stats'] == 1) ? 1 : 0;
|
79 |
$hide_attribution = (isset($instance['hide_attribution']) AND $instance['hide_attribution'] == 1) ? 1 : 0;
|
80 |
$background_by_weather = (isset($instance['background_by_weather']) AND $instance['background_by_weather'] == 1) ? 1 : 0;
|
161 |
<p>
|
162 |
<label for="<?php echo $this->get_field_id('forecast_days'); ?>"><?php _e('Forecast:', 'awesome-weather'); ?></label>
|
163 |
<select class="widefat" id="<?php echo $this->get_field_id('forecast_days'); ?>" name="<?php echo $this->get_field_name('forecast_days'); ?>">
|
|
|
164 |
<option value="4"<?php if($forecast_days == 4) echo " selected=\"selected\""; ?>>4 Days</option>
|
165 |
<option value="3"<?php if($forecast_days == 3) echo " selected=\"selected\""; ?>>3 Days</option>
|
166 |
<option value="2"<?php if($forecast_days == 2) echo " selected=\"selected\""; ?>>2 Days</option>
|