PluginProbe
wp-forecast / 1.6
wp-forecast v1.6
10.0 trunk 1.4 1.6 1.7 1.8 1.9 2.0 2.1 2.2 2.3 2.4 2.5 2.6 2.7 2.8 2.9 3..5 3..8 3.0 3.1 3.2 3.3 3.4 3.6 All 86 releases
wp-forecast / wp-forecast-show.php

wp-forecast-show.php in wp-forecast 1.6, at wp-forecast-show.php

335 lines 11.0 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 /* Copyright 2006,2007,2008 Hans Matzen (email : webmaster at tuxlog.de)
4
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2 of the License, or
8 (at your option) any later version.
9
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
14
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 */
19
20 //
21 // display the weather-data
22 //
23 // the following structure will be used:
24 //
25 // <div class=wp-forecast">
26 // <div class="wp-forecast-curr">
27 // <div class="wp-forecast-curr-details">
28 // </div>
29 // <div class="wp-forecast-copyright">
30 // </div>
31 // </div>
32 // <div class="wp-forecast-fc">
33 // <div class="wp-forecast-fc-details">
34 // </div>
35 // </div>
36 // </div>
37 //
38 //
39 //
40
41 // if called directly, get parameters from GET and output the forecast html
42 if(preg_match('#' . basename(__FILE__) . '#', $_SERVER['PHP_SELF'])) {
43 require_once("funclib.php");
44 require_once( dirname(__FILE__) . '/../../../wp-config.php');
45
46 $wpfcid = attribute_escape($_GET['wpfcid']);
47 $language_override = attribute_escape($_GET['language_override']);
48 $args=array();
49
50 $wpf_vars=get_wpf_opts($wpfcid);
51 if (!empty($language_override)) {
52 $wpf_vars['wpf_language']=$language_override;
53 }
54 $weather=str2arr(get_option("wp-forecast-cache".$wpfcid));
55
56 wp_forecast_css_nowp($wpfcid);
57 show($wpfcid,$weather,$args,$wpf_vars);
58 }
59
60 function show($wpfcid,$w,$args,$wpfvars)
61 {
62 global $wpf_debug;
63
64 if ($wpf_debug > 0)
65 pdebug("Start of show ()");
66
67 // check how we are called as a widget or from sidebar
68 if (sizeof($args)==0)
69 $show_from_widget=0;
70 else
71 $show_from_widget=1;
72
73 extract($args);
74 extract($wpfvars);
75
76 $plugin_path = get_settings('siteurl') . '/wp-content/plugins/wp-forecast';
77
78 // get translations
79 if(function_exists('load_textdomain'))
80 load_textdomain("wp-forecast_".$wpf_language, ABSPATH . "wp-content/plugins/wp-forecast/lang/".$wpf_language.".mo");
81
82 // current conditions nur ausgeben, wenn mindestens ein feld aktiv ist
83 if ( strpos(substr($dispconfig,0,9),"1") > 0 or substr($dispconfig,18,1) == "1" or substr($dispconfig,21,1) == "1" or substr($dispconfig,22,1) == "1" ) {
84 // ouput current conditions
85 $out ="";
86 $out .="\n<div class=\"wp-forecast-curr\">\n";
87
88
89 // if error print an error message and return
90 if ( count($w)<=0) {
91 $out .= __("Sorry, no valid weather data available.","wp-forecast_".$wpf_language)."<br /></div>";
92 $out .= __("Please try again later.","wp-forecast_".$wpf_language)."</div>";
93 // print it
94 if ( $show_from_widget == 1 )
95 echo $before_widget . $before_title . $title . $after_title . $out . $after_widget;
96 else
97 echo $out;
98
99 return false;
100 }
101
102 // ortsnamen ausgeben
103 if ( $locname == "" )
104 $out .= "<div>" . $w["city"]." ".$w["state"]."</div>\n";
105 else if ( trim($locname) !="")
106 $out .= "<div>" . $locname."</div>\n";
107
108
109 $out .="<table class=\"wp-forecast-curr\">\n";
110
111 // show date / time
112
113 // if current time should be used calc current local time
114 if ($currtime=="1") {
115
116 $lt = time() - date("Z"); // this is the GMT
117 $ct = $lt + (3600 * ($w['gmtdiff'])); // local time
118 if ( $w['gmtdiffdls'] == 1)
119 $ct += 3600; // time with daylightsavings
120 } else {
121 // else take given accuweather time
122 $cts = $w['fc_obsdate_1']." ".$w['time'];
123 $ct = strtotime($cts);
124 }
125
126 if (substr($dispconfig,18,1) == "1" or substr($dispconfig,1,1) == "1") {
127 $out .= "<tr><td colspan=\"2\">";
128 if (substr($dispconfig,18,1) == "1")
129 $out .= date_i18n($fc_date_format, $ct);
130 else
131 $out .= __('time',"wp-forecast_".$wpf_language).": ";
132
133 if (substr($dispconfig,18,1) == "1" and substr($dispconfig,1,1) == "1")
134 $out .= ", ";
135
136 if (substr($dispconfig,1,1) == "1")
137 $out .= date_i18n($fc_time_format, $ct)."<br />";
138 $out .= "</td></tr>";
139 }
140
141 // show icon
142 if (substr($dispconfig,0,1) == "1") {
143 $out .= "<tr><td><img src='".$plugin_path."/icons/".$w["weathericon"].".gif' alt='".__($w["weathericon"],"wp-forecast_".$wpf_language)."' /></td>\n";
144 } else {
145 $out .= "<tr><td></td>\n";
146 }
147
148
149 $out .= "<td>";
150
151 // show short description
152 if (substr($dispconfig,2,1) == "1")
153 $out .= __($w["weathericon"],"wp-forecast_".$wpf_language)."<br />";
154
155 // show temperatur
156 if (substr($dispconfig,3,1) == "1") {
157 $out .= __('tmp',"wp-forecast_".$wpf_language).": ".$w["temperature"]."&deg;";
158 $out .= $w['un_temp']."</td></tr>\n";
159 } else {
160 $out .="</td></tr>\n";
161 }
162
163 $out .= "</table>\n";
164
165
166 $out .= "<div class=\"wp-forecast-curr-details\">";
167 // show realfeel
168 if (substr($dispconfig,4,1) == "1")
169 $out .= __('flik',"wp-forecast_".$wpf_language).": ".$w["realfeel"]."&deg;".$w['un_temp']."<br />\n";
170 // show pressure
171 if (substr($dispconfig,5,1) == "1")
172 $out .= __('barr',"wp-forecast_".$wpf_language).": ".$w["pressure"]." ".$w["un_pres"]."<br />\n";
173
174 // show humiditiy
175 if (substr($dispconfig,6,1) == "1")
176 //
177 // you can change the decimals of humditiy by switching
178 // the 0 to whatever you need
179 //
180 $out .= __('hmid',"wp-forecast_".$wpf_language).": ".round($w["humidity"],0)."%<br />\n";
181
182 // show wind
183 if (substr($dispconfig,7,1) == "1") {
184 $wstr=windstr($metric,$w["windspeed"],$windunit);
185 $winddir=$w["winddirection"];
186 // for german language replace East with Ost or E with O
187 if ($wpf_language=="de_DE")
188 $winddir=str_replace("E","O",$winddir);
189
190 $out .= __('winds',"wp-forecast_".$wpf_language).": ".$wstr." " . $winddir."<br />\n";
191 }
192
193 // show windgusts
194 if (substr($dispconfig,22,1) == "1") {
195 $wstr=windstr($metric,$w["wgusts"],$windunit);
196 $out .= __('Windgusts',"wp-forecast_".$wpf_language).": ".$wstr."<br />\n";
197 }
198
199 $sunarr = explode(" ",$w["sun"]);
200 // show sunrise
201 if (substr($dispconfig,8,1) == "1")
202 $out .= __('sunrise',"wp-forecast_".$wpf_language).": ".$sunarr[0]."<br />\n";
203
204 // show sunset
205 if (substr($dispconfig,9,1) == "1")
206 $out .= __('sunset',"wp-forecast_".$wpf_language).": ".$sunarr[1]."<br />\n";
207
208 // show copyright
209 if (substr($dispconfig,21,1) == "1")
210 $out .= "<div class=\"wp-forecast-copyright\"><a href=\"http://www.accuweather.com\">&copy; 2007 AccuWeather, Inc.</a></div>";
211
212 $out .="</div></div>\n";
213 }
214
215 // ------------------
216 //
217 // output forecast
218 //
219 // -------------------
220 $out1="";
221 for ($i = 1; $i < 10; $i++) {
222
223 // check active forecast for day number i
224 if (substr($daytime,$i-1,1)=="1" or substr($nighttime,$i-1,1) =="1") {
225 $out1 .="\n<div class=\"wp-forecast-fc\">\n";
226 $out1 .="<table class=\"wp-forecast-fc-head\" cellpadding='3' cellspacing='2'><tr><td>\n";
227 $out1 .= __("Forecast","wp-forecast_".$wpf_language)." ";
228 $out1 .= date_i18n($fc_date_format, strtotime($w['fc_obsdate_'.$i]))."</td></tr></table>";
229 }
230
231 // check for daytime information
232 if (substr($daytime,$i-1,1)=="1" ) {
233 $out1 .="<table class=\"wp-forecast-fc\" cellpadding='3' cellspacing='2'>\n";
234 $out1 .= "<tr><td>".__('day',"wp-forecast_".$wpf_language)."<br />";
235
236 // show icon
237 if (substr($dispconfig,10,1) == "1") {
238 $out1 .= "<img src='".$plugin_path."/icons/".$w["fc_dt_icon_".$i].".gif' width='48' alt='".__($w["fc_dt_icon_".$i],"wp-forecast_".$wpf_language)."' />";
239 } else {
240 $out1 .= "&nbsp;";
241 }
242 $out1 .= "</td><td>\n";
243
244 // show short description
245 if (substr($dispconfig,11,1) == "1")
246 $out1 .= __($w["fc_dt_icon_".$i],"wp-forecast_".$wpf_language)."<br />";
247
248 // show temperature
249 if (substr($dispconfig,12,1) == "1")
250 $out1 .= $w["fc_dt_htemp_".$i]."&deg;".$w['un_temp']."<br />";
251
252
253 // show wind
254 if (substr($dispconfig,13,1) == "1") {
255 $wstr=windstr($metric,$w["fc_dt_windspeed_".$i],$windunit);
256 $winddir=$w["fc_dt_winddir_".$i];
257 // for german language replace East with Ost or E with O
258 if ($wpf_language=="de_DE")
259 $winddir=str_replace("E","O",$winddir);
260
261 $out1 .= __('winds',"wp-forecast_".$wpf_language).": ".$wstr." " . $winddir."<br />\n";
262 }
263
264 // show windgusts
265 if (substr($dispconfig,23,1) == "1") {
266 $wstr=windstr($metric,$w["fc_dt_wgusts_".$i],$windunit);
267 $out1 .= __('Windgusts',"wp-forecast_".$wpf_language).": ".$wstr."\n";
268 }
269
270 $out1 .= "</td></tr></table>\n";
271 }
272
273 // open div class for css if applicable
274 if (substr($daytime,$i-1,1)=="1" or substr($nighttime,$i-1,1) =="1")
275 $out1.="<div class=\"wp-forecast-fc-details\">";
276
277 // check for nighttime information
278 if (substr($nighttime,$i-1,1)=="1" ) {
279 $out1 .="<table class=\"wp-forecast-fc\" cellpadding='3' cellspacing='2'>\n";
280 $out1 .= "<tr><td>".__('night',"wp-forecast_".$wpf_language)."<br />";
281 if (substr($dispconfig,14,1) == "1") {
282 $out1 .= "<img src='".$plugin_path."/icons/".$w["fc_nt_icon_".$i].".gif' width='48' alt='".__($w["fc_nt_icon_".$i],"wp-forecast_".$wpf_language)."' />";
283 } else {
284 $out1 .= "&nbsp;";
285 }
286 $out1 .= "</td><td>\n";
287
288 // show short description
289 if (substr($dispconfig,15,1) == "1")
290 $out1 .= __($w["fc_nt_icon_".$i],"wp-forecast_".$wpf_language)."<br />";
291
292 // show temperature
293 if (substr($dispconfig,16,1) == "1") {
294 $out1 .= $w["fc_nt_ltemp_".$i]."&deg;".$w['un_temp']."<br />";
295 }
296
297 // show wind
298 if (substr($dispconfig,17,1) == "1") {
299 $wstr=windstr($metric,$w["fc_nt_windspeed_".$i],$windunit);
300 $winddir=$w["fc_nt_winddir_".$i];
301 // for german language replace East with Ost or E with O
302 if ($wpf_language=="de_DE")
303 $winddir=str_replace("E","O",$winddir);
304
305 $out1 .= __('winds',"wp-forecast_".$wpf_language).": ".$wstr." " . $winddir."<br />\n";
306 }
307
308 // show windgusts
309 if (substr($dispconfig,24,1) == "1") {
310 $wstr=windstr($metric,$w["fc_nt_wgusts_".$i],$windunit);
311 $out1 .= __('Windgusts',"wp-forecast_".$wpf_language).": ".$wstr."\n";
312 }
313
314 $out1 .= "</td></tr></table>\n";
315 }
316 // close div block
317 if (substr($daytime,$i-1,1)=="1" or substr($nighttime,$i-1,1) =="1")
318 $out1 .="</div></div>\n";
319 }
320
321
322 // print it
323 if ( $show_from_widget == 1 )
324 echo $before_widget . $before_title . $title . $after_title;
325
326 echo "<div class=\"wp-forecast\">" . $out . $out1 . "</div><br />";;
327
328 if ( $show_from_widget == 1 )
329 echo $after_widget;
330
331 if ($wpf_debug > 0)
332 pdebug("End of show ()");
333
334 }
335 ?>