Version Description
- Initial load of the plugin.
Download this release
Release Info
Developer | halgatewood |
Plugin | Awesome Weather Widget |
Version | 1.0 |
Comparing to | |
See all releases |
Version 1.0
- awesome-weather.css +99 -0
- awesome-weather.php +340 -0
- readme.txt +50 -0
awesome-weather.css
ADDED
@@ -0,0 +1,99 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
@import url(http://fonts.googleapis.com/css?Open+Sans:400,300);
|
2 |
+
|
3 |
+
.awecf:before, .awecf:after { content: " "; display: table; }
|
4 |
+
.awecf:after { clear: both; }
|
5 |
+
.awecf { *zoom: 1; }
|
6 |
+
|
7 |
+
.awesome-weather-wrap {
|
8 |
+
background: #333;
|
9 |
+
text-shadow: 0 1px 1px rgba(0,0,0,0.4);
|
10 |
+
-webkit-transition: background 0.5s ease-in;
|
11 |
+
-moz-transition: background 0.5s ease-in;
|
12 |
+
-o-transition: background 0.5s ease-in;
|
13 |
+
transition: background 0.5s ease-in;
|
14 |
+
color: #fff;
|
15 |
+
font-family: 'Open Sans', sans-serif;
|
16 |
+
font-weight: 400;
|
17 |
+
font-size: 14px;
|
18 |
+
line-height: 14px;
|
19 |
+
clear: both;
|
20 |
+
max-width: 400px;
|
21 |
+
margin: 0 auto 20px auto;
|
22 |
+
}
|
23 |
+
.awesome-weather-wrap.temp1 { background: #43adff; }
|
24 |
+
.awesome-weather-wrap.temp2 { background: #629BE0; }
|
25 |
+
.awesome-weather-wrap.temp3 { background: #8289C1; }
|
26 |
+
.awesome-weather-wrap.temp4 { background: #A178A3; }
|
27 |
+
.awesome-weather-wrap.temp5 { background: #C06684; }
|
28 |
+
.awesome-weather-wrap.temp6 { background: #E05465; }
|
29 |
+
.awesome-weather-wrap.temp7 { background: #ff4246; }
|
30 |
+
|
31 |
+
.awesome-weather-header {
|
32 |
+
padding: 5px 10px;
|
33 |
+
text-align: center;
|
34 |
+
background: rgba(0,0,0,0.1);
|
35 |
+
text-transform: uppercase;
|
36 |
+
}
|
37 |
+
|
38 |
+
.awesome-weather-current-temp {
|
39 |
+
padding: 10px 5%;
|
40 |
+
width: 30%;
|
41 |
+
float: left;
|
42 |
+
font-size: 66px;
|
43 |
+
line-height: 1em;
|
44 |
+
font-weight: 300;
|
45 |
+
}
|
46 |
+
|
47 |
+
.awesome-weather-current-temp sup { font-size: 24px; top: -1.3em; padding-left: 3px; }
|
48 |
+
|
49 |
+
.awesome-weather-todays-stats {
|
50 |
+
float: right;
|
51 |
+
text-align: right;
|
52 |
+
padding: 14px 5%;
|
53 |
+
line-height: 1.4em;
|
54 |
+
width: 50%;
|
55 |
+
}
|
56 |
+
|
57 |
+
.awesome-weather-forecast {
|
58 |
+
border-top: solid 1px rgba(0,0,0,0.1);
|
59 |
+
width: 90%;
|
60 |
+
margin: 20px auto;
|
61 |
+
padding-top: 20px;
|
62 |
+
clear: both;
|
63 |
+
}
|
64 |
+
|
65 |
+
.awesome-weather-forecast-day {
|
66 |
+
width: 18%;
|
67 |
+
margin: 0 1%;
|
68 |
+
float: left;
|
69 |
+
text-align: center;
|
70 |
+
font-weight: 300;
|
71 |
+
}
|
72 |
+
|
73 |
+
.awe_days_2 .awesome-weather-forecast-day { width: 48%; }
|
74 |
+
.awe_days_3 .awesome-weather-forecast-day { width: 31%; }
|
75 |
+
.awe_days_4 .awesome-weather-forecast-day { width: 23%; }
|
76 |
+
|
77 |
+
.awesome-weather-forecast-day-temp { font-size: 1.8em; font-weight: 300; }
|
78 |
+
.awesome-weather-forecast-day-temp sup { font-size: 0.6em; padding-left: 2px; }
|
79 |
+
.awesome-weather-forecast-day-abbr { text-transform: uppercase; font-size: 0.8em; margin-top: 5px; padding-right: 4px; }
|
80 |
+
|
81 |
+
.awe_tall .awesome-weather-current-temp,
|
82 |
+
.awe_tall .awesome-weather-todays-stats,
|
83 |
+
.awe_without_stats .awesome-weather-current-temp { text-align: center; width: 90%; float: none; }
|
84 |
+
.awe_tall .awesome-weather-todays-stats { padding: 0 5%; }
|
85 |
+
|
86 |
+
.awe_without_stats .awesome-weather-forecast { margin-top: 0; }
|
87 |
+
|
88 |
+
#sidebar .awe_wide .awesome-weather-current-temp,
|
89 |
+
#secondary .awe_wide .awesome-weather-current-temp { font-size: 50px; }
|
90 |
+
|
91 |
+
#sidebar .awe_wide .awesome-weather-current-temp sup,
|
92 |
+
#secondary .awe_wide .awesome-weather-current-temp sup { font-size: 18px; }
|
93 |
+
|
94 |
+
#sidebar .awe_wide .awesome-weather-todays-stats,
|
95 |
+
#secondary .awe_wide .awesome-weather-todays-stats { font-size: 12px; }
|
96 |
+
|
97 |
+
|
98 |
+
|
99 |
+
|
awesome-weather.php
ADDED
@@ -0,0 +1,340 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/*
|
3 |
+
Plugin Name: Awesome Weather Widget
|
4 |
+
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.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 |
+
|
16 |
+
|
17 |
+
SHORTCODE USAGE
|
18 |
+
[awesome-weather location="Oklahoma City, OK" units="F"]
|
19 |
+
[awesome-weather location="London, UK" units="C" width=220]
|
20 |
+
*/
|
21 |
+
|
22 |
+
|
23 |
+
// SETTINGS
|
24 |
+
$awesome_weather_sizes = apply_filters( 'awesome_weather_sizes' , array( 'tall', 'wide' ) );
|
25 |
+
|
26 |
+
|
27 |
+
|
28 |
+
// HAS SHORTCODE - by pippin
|
29 |
+
function awesome_weather_wp_head( $posts )
|
30 |
+
{
|
31 |
+
wp_enqueue_style( 'awesome-weather', plugins_url( '/awesome-weather.css', __FILE__ ) );
|
32 |
+
}
|
33 |
+
add_action('wp_enqueue_scripts', 'awesome_weather_wp_head');
|
34 |
+
|
35 |
+
|
36 |
+
//THE SHORTCODE
|
37 |
+
add_shortcode( 'awesome-weather', 'awesome_weather_shortcode' );
|
38 |
+
function awesome_weather_shortcode( $atts )
|
39 |
+
{
|
40 |
+
return awesome_weather_logic( $atts );
|
41 |
+
}
|
42 |
+
|
43 |
+
|
44 |
+
// THE LOGIC
|
45 |
+
function awesome_weather_logic( $atts )
|
46 |
+
{
|
47 |
+
global $awesome_weather_sizes;
|
48 |
+
|
49 |
+
$rtn = "";
|
50 |
+
$weather_data = array();
|
51 |
+
$location = isset($atts['location']) ? $atts['location'] : false;
|
52 |
+
$size = (isset($atts['size']) AND $atts['size'] == "tall") ? 'tall' : 'wide';
|
53 |
+
$units = (isset($atts['units']) AND strtoupper($atts['units']) == "C") ? "metric" : "imperial";
|
54 |
+
$units_display = $units == "metric" ? __('C', 'awesome-weather') : __('F', 'awesome-weather');
|
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 |
+
|
61 |
+
|
62 |
+
//FIND AND CACHE CITY ID
|
63 |
+
$city_id = false;
|
64 |
+
$city_name_slug = sanitize_title( $location );
|
65 |
+
$city_id_transient_name = 'awesome-weather-cityid-' . $city_name_slug;
|
66 |
+
$weather_transient_name = 'awesome-weather-' . $units . '-' . $city_name_slug;
|
67 |
+
|
68 |
+
if( get_transient( $city_id_transient_name ) )
|
69 |
+
{
|
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 |
+
echo $city_id;
|
92 |
+
|
93 |
+
// NO CITY ID
|
94 |
+
if( !$city_id ) { return awesome_weather_error( __('City could not be found', 'awesome-weather') ); }
|
95 |
+
|
96 |
+
if( get_transient( $weather_transient_name ) )
|
97 |
+
{
|
98 |
+
$weather_data = get_transient( $weather_transient_name );
|
99 |
+
}
|
100 |
+
|
101 |
+
|
102 |
+
if(!isset($weather_data['today']))
|
103 |
+
{
|
104 |
+
$weather_data['today'] = json_decode(file_get_contents("http://api.openweathermap.org/data/2.3/weather/city/" . $city_id . "?units=" . $units) );
|
105 |
+
set_transient( $weather_transient_name, $weather_data, apply_filters( 'awesome_weather_cache', 3600 ) ); // CACHE FOR AN HOUR
|
106 |
+
}
|
107 |
+
|
108 |
+
if(!isset($weather_data['forecast']) AND $days_to_show != "hide")
|
109 |
+
{
|
110 |
+
$weather_data['forecast'] = json_decode(file_get_contents("http://api.openweathermap.org/data/2.3/forecast/city/" . $city_id . "?mode=daily_compact&units=" . $units) );
|
111 |
+
set_transient( $weather_transient_name, $weather_data, apply_filters( 'awesome_weather_cache', 3600 ) ); // CACHE FOR AN HOUR
|
112 |
+
}
|
113 |
+
|
114 |
+
// NO WEATHER
|
115 |
+
if( !$weather_data OR !$weather_data['today']) { return awesome_weather_error(); }
|
116 |
+
|
117 |
+
|
118 |
+
// TODAYS TEMPS
|
119 |
+
$today = $weather_data['today'];
|
120 |
+
$today_temp = (int) $today->main->temp;
|
121 |
+
$today_high = (int) $today->main->temp_max;
|
122 |
+
$today_low = (int) $today->main->temp_min;
|
123 |
+
|
124 |
+
|
125 |
+
// COLOR OF WIDGET
|
126 |
+
$bg_color = "temp1";
|
127 |
+
if($units_display == "F")
|
128 |
+
{
|
129 |
+
if($today_temp > 31 AND $today_temp < 40) $bg_color = "temp2";
|
130 |
+
if($today_temp >= 40 AND $today_temp < 50) $bg_color = "temp3";
|
131 |
+
if($today_temp >= 50 AND $today_temp < 60) $bg_color = "temp4";
|
132 |
+
if($today_temp >= 60 AND $today_temp < 80) $bg_color = "temp5";
|
133 |
+
if($today_temp >= 80 AND $today_temp < 90) $bg_color = "temp6";
|
134 |
+
if($today_temp >= 90) $bg_color = "temp7";
|
135 |
+
}
|
136 |
+
else
|
137 |
+
{
|
138 |
+
if($today_temp > 1 AND $today_temp < 4) $bg_color = "temp2";
|
139 |
+
if($today_temp >= 4 AND $today_temp < 10) $bg_color = "temp3";
|
140 |
+
if($today_temp >= 10 AND $today_temp < 15) $bg_color = "temp4";
|
141 |
+
if($today_temp >= 15 AND $today_temp < 26) $bg_color = "temp5";
|
142 |
+
if($today_temp >= 26 AND $today_temp < 32) $bg_color = "temp6";
|
143 |
+
if($today_temp >= 32) $bg_color = "temp7";
|
144 |
+
}
|
145 |
+
|
146 |
+
|
147 |
+
|
148 |
+
|
149 |
+
// DATA
|
150 |
+
$header_title = $override_title ? $override_title : $today->name;
|
151 |
+
|
152 |
+
$today->main->humidity = (int) $today->main->humidity;
|
153 |
+
$today->wind->speed = (int) $today->wind->speed;
|
154 |
+
|
155 |
+
$wind_label = array (
|
156 |
+
__('N', 'awesome-weather'),
|
157 |
+
__('NNE', 'awesome-weather'),
|
158 |
+
__('NE', 'awesome-weather'),
|
159 |
+
__('ENE', 'awesome-weather'),
|
160 |
+
__('E', 'awesome-weather'),
|
161 |
+
__('ESE', 'awesome-weather'),
|
162 |
+
__('SE', 'awesome-weather'),
|
163 |
+
__('SSE', 'awesome-weather'),
|
164 |
+
__('S', 'awesome-weather'),
|
165 |
+
__('SSW', 'awesome-weather'),
|
166 |
+
__('SW', 'awesome-weather'),
|
167 |
+
__('WSW', 'awesome-weather'),
|
168 |
+
__('W', 'awesome-weather'),
|
169 |
+
__('WNW', 'awesome-weather'),
|
170 |
+
__('NW', 'awesome-weather'),
|
171 |
+
__('NNW', 'awesome-weather')
|
172 |
+
);
|
173 |
+
|
174 |
+
$wind_direction = $wind_label[ fmod((($today->wind->deg + 11) / 22.5),16) ];
|
175 |
+
|
176 |
+
$show_stats_class = ($show_stats) ? "awe_with_stats" : "awe_without_stats";
|
177 |
+
|
178 |
+
|
179 |
+
// DISPLAY WIDGET
|
180 |
+
$rtn .= "
|
181 |
+
|
182 |
+
<div id=\"awesome-weather-{$city_name_slug}\" class=\"awesome-weather-wrap awecf {$bg_color} {$show_stats_class} awe_{$size}\">
|
183 |
+
|
184 |
+
<div class=\"awesome-weather-header\">{$header_title}</div>
|
185 |
+
|
186 |
+
<div class=\"awesome-weather-current-temp\">
|
187 |
+
$today_temp<sup>{$units_display}</sup>
|
188 |
+
</div> <!-- /.awesome-weather-current-temp -->
|
189 |
+
";
|
190 |
+
|
191 |
+
if($show_stats)
|
192 |
+
{
|
193 |
+
$rtn .= "
|
194 |
+
|
195 |
+
<div class=\"awesome-weather-todays-stats\">
|
196 |
+
<div class=\"awe_desc\">{$today->weather[0]->description}</div>
|
197 |
+
<div class=\"awe_humidty\">humidity: {$today->main->humidity}% </div>
|
198 |
+
<div class=\"awe_wind\">wind: {$today->wind->speed}mph {$wind_direction}</div>
|
199 |
+
<div class=\"awe_highlow\"> H {$today_high} • L {$today_low} </div>
|
200 |
+
</div> <!-- /.awesome-weather-todays-stats -->
|
201 |
+
";
|
202 |
+
}
|
203 |
+
|
204 |
+
if($days_to_show != "hide")
|
205 |
+
{
|
206 |
+
$rtn .= "<div class=\"awesome-weather-forecast awe_days_{$days_to_show} awecf\">";
|
207 |
+
$c = 1;
|
208 |
+
$dt_today = date('Ymd');
|
209 |
+
$forecast = $weather_data['forecast'];
|
210 |
+
$days_to_show = (int) $days_to_show;
|
211 |
+
|
212 |
+
foreach( (array) $forecast->list as $forecast )
|
213 |
+
{
|
214 |
+
if( $dt_today > date('Ymd', $forecast->dt)) continue;
|
215 |
+
|
216 |
+
$forecast->temp = (int) $forecast->temp;
|
217 |
+
$day_of_week = date('D', $forecast->dt);
|
218 |
+
$rtn .= "
|
219 |
+
<div class=\"awesome-weather-forecast-day\">
|
220 |
+
<div class=\"awesome-weather-forecast-day-temp\">{$forecast->temp}<sup>{$units_display}</sup></div>
|
221 |
+
<div class=\"awesome-weather-forecast-day-abbr\">$day_of_week</div>
|
222 |
+
</div>
|
223 |
+
";
|
224 |
+
if($c == $days_to_show) break;
|
225 |
+
$c++;
|
226 |
+
}
|
227 |
+
$rtn .= " </div> <!-- /.awesome-weather-forecast -->";
|
228 |
+
}
|
229 |
+
|
230 |
+
|
231 |
+
$rtn .= "</div> <!-- /.awesome-weather-wrap -->";
|
232 |
+
return $rtn;
|
233 |
+
|
234 |
+
}
|
235 |
+
|
236 |
+
|
237 |
+
// RETURN ERROR
|
238 |
+
function awesome_weather_error( $msg = false )
|
239 |
+
{
|
240 |
+
if(!$msg) $msg = __('No weather information available', 'awesome-weather');
|
241 |
+
return apply_filters( 'awesome_weather_error', "<p class='error'>" . $msg . "</p>" );
|
242 |
+
}
|
243 |
+
|
244 |
+
|
245 |
+
|
246 |
+
// TEXT BLOCK WIDGET
|
247 |
+
class AwesomeWeatherWidget extends WP_Widget
|
248 |
+
{
|
249 |
+
function AwesomeWeatherWidget() { parent::WP_Widget(false, $name = 'Awesome Weather Widget'); }
|
250 |
+
|
251 |
+
function widget($args, $instance)
|
252 |
+
{
|
253 |
+
extract( $args );
|
254 |
+
|
255 |
+
$location = isset($instance['location']) ? $instance['location'] : false;
|
256 |
+
$override_title = isset($instance['override_title']) ? $instance['override_title'] : false;
|
257 |
+
$units = isset($instance['units']) ? $instance['units'] : false;
|
258 |
+
$size = isset($instance['size']) ? $instance['size'] : false;
|
259 |
+
$forecast_days = isset($instance['forecast_days']) ? $instance['forecast_days'] : false;
|
260 |
+
$hide_stats = (isset($instance['hide_stats']) AND $instance['hide_stats'] == 1) ? 1 : 0;
|
261 |
+
|
262 |
+
echo $before_widget;
|
263 |
+
echo awesome_weather_logic( array( 'location' => $location, 'override_title' => $override_title, 'size' => $size, 'units' => $units, 'forecast_days' => $forecast_days, 'hide_stats' => $hide_stats));
|
264 |
+
echo $after_widget;
|
265 |
+
}
|
266 |
+
|
267 |
+
function update($new_instance, $old_instance)
|
268 |
+
{
|
269 |
+
$instance = $old_instance;
|
270 |
+
$instance['location'] = strip_tags($new_instance['location']);
|
271 |
+
$instance['override_title'] = strip_tags($new_instance['override_title']);
|
272 |
+
$instance['units'] = strip_tags($new_instance['units']);
|
273 |
+
$instance['size'] = strip_tags($new_instance['size']);
|
274 |
+
$instance['forecast_days'] = strip_tags($new_instance['forecast_days']);
|
275 |
+
$instance['hide_stats'] = strip_tags($new_instance['hide_stats']);
|
276 |
+
return $instance;
|
277 |
+
}
|
278 |
+
|
279 |
+
function form($instance)
|
280 |
+
{
|
281 |
+
global $awesome_weather_sizes;
|
282 |
+
|
283 |
+
$location = isset($instance['location']) ? esc_attr($instance['location']) : "";
|
284 |
+
$override_title = isset($instance['override_title']) ? esc_attr($instance['override_title']) : "";
|
285 |
+
$selected_size = isset($instance['size']) ? esc_attr($instance['size']) : "wide";
|
286 |
+
$units = isset($instance['units']) ? esc_attr($instance['units']) : "imperial";
|
287 |
+
$forecast_days = isset($instance['forecast_days']) ? esc_attr($instance['forecast_days']) : 5;
|
288 |
+
$hide_stats = (isset($instance['hide_stats']) AND $instance['hide_stats'] == 1) ? 1 : 0;
|
289 |
+
|
290 |
+
?>
|
291 |
+
<p>
|
292 |
+
<label for="<?php echo $this->get_field_id('location'); ?>"><?php _e('Location:'); ?></label>
|
293 |
+
<input class="widefat" id="<?php echo $this->get_field_id('location'); ?>" name="<?php echo $this->get_field_name('location'); ?>" type="text" value="<?php echo $location; ?>" />
|
294 |
+
</p>
|
295 |
+
|
296 |
+
<p>
|
297 |
+
<label for="<?php echo $this->get_field_id('override_title'); ?>"><?php _e('Override Title:'); ?></label>
|
298 |
+
<input class="widefat" id="<?php echo $this->get_field_id('override_title'); ?>" name="<?php echo $this->get_field_name('override_title'); ?>" type="text" value="<?php echo $override_title; ?>" />
|
299 |
+
</p>
|
300 |
+
|
301 |
+
<p>
|
302 |
+
<label for="<?php echo $this->get_field_id('units'); ?>"><?php _e('Units:'); ?></label>
|
303 |
+
<input id="<?php echo $this->get_field_id('units'); ?>" name="<?php echo $this->get_field_name('units'); ?>" type="radio" value="imperial" <?php if($units == "imperial") echo ' checked="checked"'; ?> /> F
|
304 |
+
<input id="<?php echo $this->get_field_id('units'); ?>" name="<?php echo $this->get_field_name('units'); ?>" type="radio" value="metric" <?php if($units == "metric") echo ' checked="checked"'; ?> /> C
|
305 |
+
</p>
|
306 |
+
|
307 |
+
<p>
|
308 |
+
<label for="<?php echo $this->get_field_id('size'); ?>"><?php _e('Size:'); ?></label>
|
309 |
+
<select class="widefat" id="<?php echo $this->get_field_id('size'); ?>" name="<?php echo $this->get_field_name('size'); ?>">
|
310 |
+
<?php foreach($awesome_weather_sizes as $size) { ?>
|
311 |
+
<option value="<?php echo $size; ?>"<?php if($selected_size == $size) echo " selected=\"selected\""; ?>><?php echo $size; ?></option>
|
312 |
+
<?php } ?>
|
313 |
+
</select>
|
314 |
+
</p>
|
315 |
+
|
316 |
+
<p>
|
317 |
+
<label for="<?php echo $this->get_field_id('forecast_days'); ?>"><?php _e('Forecast:'); ?></label>
|
318 |
+
<select class="widefat" id="<?php echo $this->get_field_id('forecast_days'); ?>" name="<?php echo $this->get_field_name('forecast_days'); ?>">
|
319 |
+
<option value="5"<?php if($forecast_days == 5) echo " selected=\"selected\""; ?>>5 Days</option>
|
320 |
+
<option value="4"<?php if($forecast_days == 4) echo " selected=\"selected\""; ?>>4 Days</option>
|
321 |
+
<option value="3"<?php if($forecast_days == 3) echo " selected=\"selected\""; ?>>3 Days</option>
|
322 |
+
<option value="2"<?php if($forecast_days == 2) echo " selected=\"selected\""; ?>>2 Days</option>
|
323 |
+
<option value="1"<?php if($forecast_days == 1) echo " selected=\"selected\""; ?>>1 Days</option>
|
324 |
+
<option value="hide"<?php if($forecast_days == 'hide') echo " selected=\"selected\""; ?>>Don't Show</option>
|
325 |
+
</select>
|
326 |
+
</p>
|
327 |
+
|
328 |
+
<p>
|
329 |
+
<label for="<?php echo $this->get_field_id('hide_stats'); ?>"><?php _e('Hide Stats:'); ?></label>
|
330 |
+
<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"'; ?> />
|
331 |
+
</p>
|
332 |
+
|
333 |
+
<?php
|
334 |
+
}
|
335 |
+
}
|
336 |
+
|
337 |
+
add_action( 'widgets_init', create_function('', 'return register_widget("AwesomeWeatherWidget");') );
|
338 |
+
|
339 |
+
|
340 |
+
|
readme.txt
ADDED
@@ -0,0 +1,50 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
=== Plugin Name ===
|
2 |
+
Contributors: halgatewood
|
3 |
+
Donate link: http://halgatewood.com/awesome-weather/
|
4 |
+
Tags: widgets, sidebar, shortcode, openweathermap, weather, weather widget, forecast, global
|
5 |
+
Requires at least: 3.5
|
6 |
+
Tested up to: 3.6
|
7 |
+
Stable tag: trunk
|
8 |
+
License: GPLv2 or later
|
9 |
+
License URI: http://www.gnu.org/licenses/gpl-2.0.html
|
10 |
+
|
11 |
+
Finally beautiful weather widgets for your site.
|
12 |
+
|
13 |
+
== Description ==
|
14 |
+
|
15 |
+
This plugin allows you to easily add super clean weather widgets to your site. The design is based off the site: http://weatherrr.net/ and the widget changes colors based on the current temp.
|
16 |
+
|
17 |
+
Use the built in widget or add it somewhere else with this shortcode: (all settings shown)
|
18 |
+
|
19 |
+
`[awesome-weather location="Montreal" units="F" size="tall" override_title="MTL" forecast_days=2 hide_stats=true]`
|
20 |
+
|
21 |
+
Settings:
|
22 |
+
|
23 |
+
* Location: Enter like Montreal, CA or just Montreal. You may need to try different variations to get the right city
|
24 |
+
* Units: F (default) or C
|
25 |
+
* Size: wide (default) or tall
|
26 |
+
* Override Title: Change the title in the header bar to whatever, sometimes it pulls weather from a close city
|
27 |
+
* Forecast Days: How many days to show in the forecast bar
|
28 |
+
* Hide stats: Hide the text stats like humidity, wind, high and lows, etc
|
29 |
+
|
30 |
+
All weather data is provided by http://openweathermap.org and is cached for one hour.
|
31 |
+
|
32 |
+
|
33 |
+
== Installation ==
|
34 |
+
|
35 |
+
1. Add plugin to the `/wp-content/plugins/` directory
|
36 |
+
1. Activate the plugin through the 'Plugins' menu in WordPress
|
37 |
+
1. Use shortcode or widget
|
38 |
+
|
39 |
+
|
40 |
+
== Screenshots ==
|
41 |
+
|
42 |
+
1. Basic wide layout
|
43 |
+
2. Basic tall layout
|
44 |
+
3. Micro no features
|
45 |
+
4. Widget Settings
|
46 |
+
|
47 |
+
== Changelog ==
|
48 |
+
|
49 |
+
= 1.0 =
|
50 |
+
* Initial load of the plugin.
|