Awesome Weather Widget - Version 1.1

Version Description

Errors are now commented out. Look in the source to see what the problem is.

Download this release

Release Info

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

Code changes from version 1.0.2 to 1.1

Files changed (3) hide show
  1. awesome-weather.css +2 -1
  2. awesome-weather.php +36 -15
  3. readme.txt +7 -0
awesome-weather.css CHANGED
@@ -95,5 +95,6 @@
95
  #secondary .awe_wide .awesome-weather-todays-stats { font-size: 12px; }
96
 
97
 
98
-
 
99
 
95
  #secondary .awe_wide .awesome-weather-todays-stats { font-size: 12px; }
96
 
97
 
98
+ .awesome-weather-more-weather-link { padding: 5px; text-align: center; }
99
+ .awesome-weather-more-weather-link a { color: #fff !important; text-decoration: none !important; font-size: 0.8em; }
100
 
awesome-weather.php CHANGED
@@ -5,13 +5,14 @@ Plugin URI: http://halgatewood.com/awesome-weather
5
  Description: A weather widget that actually looks cool
6
  Author: Hal Gatewood
7
  Author URI: http://www.halgatewood.com
8
- Version: 1.0.2
9
 
10
 
11
  FILTERS AVAILABLE:
12
- awesome_weather_cache = How many seconds to cache weather: default 3600 (one hour).
13
- awesome_weather_error = Error message if weather is not found.
14
- awesome_weather_sizes = array of sizes for widget
 
15
 
16
 
17
  SHORTCODE USAGE
@@ -55,6 +56,7 @@ function awesome_weather_logic( $atts )
55
  $override_title = isset($atts['override_title']) ? $atts['override_title'] : false;
56
  $days_to_show = isset($atts['forecast_days']) ? $atts['forecast_days'] : 5;
57
  $show_stats = (isset($atts['hide_stats']) AND $atts['hide_stats'] == 1) ? 0 : 1;
 
58
 
59
  if( !$location ) { return awesome_weather_error(); }
60
 
@@ -70,24 +72,30 @@ function awesome_weather_logic( $atts )
70
  $city_id = get_transient( $city_id_transient_name );
71
  }
72
 
73
-
74
  // NOT AN ElSE JUST IN CASE THE TRANSIENT
75
  // HAS AN EMPTY CITY_ID FOR WHATEVER REASON
76
  if(!$city_id)
77
  {
78
- $data = json_decode( file_get_contents( "http://api.openweathermap.org/data/2.1/find/name?q=" . $city_name_slug ) );
 
79
 
80
- if( !$data ) { return awesome_weather_error( __('City could not be found', 'awesome-weather') ); }
 
 
 
81
 
82
- $city = $data->list[0];
83
- $city_id = $city->id;
 
 
 
 
84
 
85
  if($city_id)
86
  {
87
  set_transient( $city_id_transient_name, $city_id, 2629743); // CACHE FOR A MONTH
88
  }
89
  }
90
-
91
 
92
  // NO CITY ID
93
  if( !$city_id ) { return awesome_weather_error( __('City could not be found', 'awesome-weather') ); }
@@ -143,8 +151,6 @@ function awesome_weather_logic( $atts )
143
  }
144
 
145
 
146
-
147
-
148
  // DATA
149
  $header_title = $override_title ? $override_title : $today->name;
150
 
@@ -225,11 +231,18 @@ function awesome_weather_logic( $atts )
225
  }
226
  $rtn .= " </div> <!-- /.awesome-weather-forecast -->";
227
  }
 
 
 
 
228
 
 
 
 
 
229
 
230
  $rtn .= "</div> <!-- /.awesome-weather-wrap -->";
231
  return $rtn;
232
-
233
  }
234
 
235
 
@@ -237,7 +250,7 @@ function awesome_weather_logic( $atts )
237
  function awesome_weather_error( $msg = false )
238
  {
239
  if(!$msg) $msg = __('No weather information available', 'awesome-weather');
240
- return apply_filters( 'awesome_weather_error', "<p class='error'>" . $msg . "</p>" );
241
  }
242
 
243
 
@@ -257,9 +270,10 @@ class AwesomeWeatherWidget extends WP_Widget
257
  $size = isset($instance['size']) ? $instance['size'] : false;
258
  $forecast_days = isset($instance['forecast_days']) ? $instance['forecast_days'] : false;
259
  $hide_stats = (isset($instance['hide_stats']) AND $instance['hide_stats'] == 1) ? 1 : 0;
 
260
 
261
  echo $before_widget;
262
- echo awesome_weather_logic( array( 'location' => $location, 'override_title' => $override_title, 'size' => $size, 'units' => $units, 'forecast_days' => $forecast_days, 'hide_stats' => $hide_stats));
263
  echo $after_widget;
264
  }
265
 
@@ -272,6 +286,7 @@ class AwesomeWeatherWidget extends WP_Widget
272
  $instance['size'] = strip_tags($new_instance['size']);
273
  $instance['forecast_days'] = strip_tags($new_instance['forecast_days']);
274
  $instance['hide_stats'] = strip_tags($new_instance['hide_stats']);
 
275
  return $instance;
276
  }
277
 
@@ -285,6 +300,7 @@ class AwesomeWeatherWidget extends WP_Widget
285
  $units = isset($instance['units']) ? esc_attr($instance['units']) : "imperial";
286
  $forecast_days = isset($instance['forecast_days']) ? esc_attr($instance['forecast_days']) : 5;
287
  $hide_stats = (isset($instance['hide_stats']) AND $instance['hide_stats'] == 1) ? 1 : 0;
 
288
 
289
  ?>
290
  <p>
@@ -329,6 +345,11 @@ class AwesomeWeatherWidget extends WP_Widget
329
  <input id="<?php echo $this->get_field_id('hide_stats'); ?>" name="<?php echo $this->get_field_name('hide_stats'); ?>" type="checkbox" value="1" <?php if($hide_stats) echo ' checked="checked"'; ?> />
330
  </p>
331
 
 
 
 
 
 
332
  <?php
333
  }
334
  }
5
  Description: A weather widget that actually looks cool
6
  Author: Hal Gatewood
7
  Author URI: http://www.halgatewood.com
8
+ Version: 1.1
9
 
10
 
11
  FILTERS AVAILABLE:
12
+ awesome_weather_cache = How many seconds to cache weather: default 3600 (one hour).
13
+ awesome_weather_error = Error message if weather is not found.
14
+ awesome_weather_sizes = array of sizes for widget
15
+ awesome_weather_extended_forecast_text = Change text of footer link
16
 
17
 
18
  SHORTCODE USAGE
56
  $override_title = isset($atts['override_title']) ? $atts['override_title'] : false;
57
  $days_to_show = isset($atts['forecast_days']) ? $atts['forecast_days'] : 5;
58
  $show_stats = (isset($atts['hide_stats']) AND $atts['hide_stats'] == 1) ? 0 : 1;
59
+ $show_link = (isset($atts['show_link']) AND $atts['show_link'] == 1) ? 1 : 0;
60
 
61
  if( !$location ) { return awesome_weather_error(); }
62
 
72
  $city_id = get_transient( $city_id_transient_name );
73
  }
74
 
 
75
  // NOT AN ElSE JUST IN CASE THE TRANSIENT
76
  // HAS AN EMPTY CITY_ID FOR WHATEVER REASON
77
  if(!$city_id)
78
  {
79
+ $city_ping = "http://api.openweathermap.org/data/2.1/find/name?q=" . $city_name_slug;
80
+ $data = json_decode( file_get_contents( $city_ping ) );
81
 
82
+ if( isset($data->message) AND $data->message == "not found" )
83
+ {
84
+ return awesome_weather_error( __('City could not be found:' . $city_ping , 'awesome-weather') );
85
+ }
86
 
87
+ if($data AND $data->list)
88
+ {
89
+
90
+ $city = $data->list[0];
91
+ $city_id = $city->id;
92
+ }
93
 
94
  if($city_id)
95
  {
96
  set_transient( $city_id_transient_name, $city_id, 2629743); // CACHE FOR A MONTH
97
  }
98
  }
 
99
 
100
  // NO CITY ID
101
  if( !$city_id ) { return awesome_weather_error( __('City could not be found', 'awesome-weather') ); }
151
  }
152
 
153
 
 
 
154
  // DATA
155
  $header_title = $override_title ? $override_title : $today->name;
156
 
231
  }
232
  $rtn .= " </div> <!-- /.awesome-weather-forecast -->";
233
  }
234
+
235
+ if($show_link AND $city_id)
236
+ {
237
+ $show_link_text = apply_filters('awesome_weather_extended_forecast_text' , "extended forecast" );
238
 
239
+ $rtn .= "<div class=\"awesome-weather-more-weather-link\">";
240
+ $rtn .= "<a href=\"http://openweathermap.org/city/{$city_id}\" target=\"_blank\">{$show_link_text}</a>";
241
+ $rtn .= "</div> <!-- /.awesome-weather-more-weather-link -->";
242
+ }
243
 
244
  $rtn .= "</div> <!-- /.awesome-weather-wrap -->";
245
  return $rtn;
 
246
  }
247
 
248
 
250
  function awesome_weather_error( $msg = false )
251
  {
252
  if(!$msg) $msg = __('No weather information available', 'awesome-weather');
253
+ return apply_filters( 'awesome_weather_error', "<!-- AWESOME WEATHER ERROR: " . $msg . " -->" );
254
  }
255
 
256
 
270
  $size = isset($instance['size']) ? $instance['size'] : false;
271
  $forecast_days = isset($instance['forecast_days']) ? $instance['forecast_days'] : false;
272
  $hide_stats = (isset($instance['hide_stats']) AND $instance['hide_stats'] == 1) ? 1 : 0;
273
+ $show_link = (isset($instance['show_link']) AND $instance['show_link'] == 1) ? 1 : 0;
274
 
275
  echo $before_widget;
276
+ echo awesome_weather_logic( array( 'location' => $location, 'override_title' => $override_title, 'size' => $size, 'units' => $units, 'forecast_days' => $forecast_days, 'hide_stats' => $hide_stats, 'show_link' => $show_link));
277
  echo $after_widget;
278
  }
279
 
286
  $instance['size'] = strip_tags($new_instance['size']);
287
  $instance['forecast_days'] = strip_tags($new_instance['forecast_days']);
288
  $instance['hide_stats'] = strip_tags($new_instance['hide_stats']);
289
+ $instance['show_link'] = strip_tags($new_instance['show_link']);
290
  return $instance;
291
  }
292
 
300
  $units = isset($instance['units']) ? esc_attr($instance['units']) : "imperial";
301
  $forecast_days = isset($instance['forecast_days']) ? esc_attr($instance['forecast_days']) : 5;
302
  $hide_stats = (isset($instance['hide_stats']) AND $instance['hide_stats'] == 1) ? 1 : 0;
303
+ $show_link = (isset($instance['show_link']) AND $instance['show_link'] == 1) ? 1 : 0;
304
 
305
  ?>
306
  <p>
345
  <input id="<?php echo $this->get_field_id('hide_stats'); ?>" name="<?php echo $this->get_field_name('hide_stats'); ?>" type="checkbox" value="1" <?php if($hide_stats) echo ' checked="checked"'; ?> />
346
  </p>
347
 
348
+ <p>
349
+ <label for="<?php echo $this->get_field_id('show_link'); ?>"><?php _e('Link to OpenWeatherMap:'); ?></label> &nbsp;
350
+ <input id="<?php echo $this->get_field_id('show_link'); ?>" name="<?php echo $this->get_field_name('show_link'); ?>" type="checkbox" value="1" <?php if($show_link) echo ' checked="checked"'; ?> />
351
+ </p>
352
+
353
  <?php
354
  }
355
  }
readme.txt CHANGED
@@ -46,6 +46,9 @@ All weather data is provided by http://openweathermap.org and is cached for one
46
 
47
  == Upgrade Notice ==
48
 
 
 
 
49
  = 1.0.2 =
50
  Removed debugging code, sorry!
51
 
@@ -54,6 +57,10 @@ Changed API endpoints. Might not find weather without update.
54
 
55
  == Changelog ==
56
 
 
 
 
 
57
  = 1.0.2 =
58
  * Removed debugging code, sorry!
59
 
46
 
47
  == Upgrade Notice ==
48
 
49
+ = 1.1 =
50
+ Errors are now commented out. Look in the source to see what the problem is.
51
+
52
  = 1.0.2 =
53
  Removed debugging code, sorry!
54
 
57
 
58
  == Changelog ==
59
 
60
+ = 1.1 =
61
+ * Errors are now commented out. Look in the source to see what the problem is.
62
+ * Ability to add link to openweathermap for extended forecast
63
+
64
  = 1.0.2 =
65
  * Removed debugging code, sorry!
66