PluginProbe
wp-forecast / 2.5
wp-forecast v2.5
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 2.5, at wp-forecast-show.php

440 lines 13.7 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 /* Copyright 2006-2009 Hans Matzen (email : webmaster at tuxlog dot 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-head">
28 </div>
29 <div class="wp-forecast-curr-block">
30 <div class='wp-forecast-curr-left'>
31 </div>
32 <div class='wp-forecast-curr-right'>
33 </div>
34 </div>
35 <div class="wp-forecast-curr-details">
36 <div class="wp-forecast-copyright">
37 </div>
38 </div>
39 </div>
40 <div class="wp-forecast-fc">
41
42 <div class="wp-forecast-fc-oneday">
43 <div class="wp-forecast-fc-head">
44 </div>
45 <div class="wp-forecast-fc-block">
46 <div class="wp-forecast-fc-left">
47 </div>
48 <div class='wp-forecast-fc-right'>
49 </div>
50 </div>
51 <div class="wp-forecast-fc-block">
52 <div class="wp-forecast-fc-left">
53 </div>
54 <div class='wp-forecast-fc-right'>
55 </div>
56 </div>
57 </div>
58 ... repetead for everey forecast day ...
59 </div>
60 </div>
61 */
62
63 // if called directly, get parameters from GET and output the forecast html
64 if(preg_match('#' . basename(__FILE__) . '#', $_SERVER['PHP_SELF'])) {
65 require_once("funclib.php");
66 require_once( dirname(__FILE__) . '/../../../wp-config.php');
67
68 $wpfcid = attribute_escape($_GET['wpfcid']);
69 $language_override = attribute_escape($_GET['language_override']);
70 $header = attribute_escape($_GET['header']);
71 $args=array();
72
73 $wpf_vars=get_wpf_opts($wpfcid);
74 if (!empty($language_override)) {
75 $wpf_vars['wpf_language']=$language_override;
76 }
77 $weather=unserialize(get_option("wp-forecast-cache".$wpfcid));
78
79
80 if ($header) {
81 echo '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">'."\n";
82 echo '<html xmlns="http://www.w3.org/1999/xhtml" dir="ltr" lang="de-DE">'."\n";
83 echo "<head><title>wp-forecast iframe</title>\n";
84 echo '<meta http-equiv="content-type" content="text/html; charset=utf-8" />'."\n";
85 }
86 wp_forecast_css_nowp($wpfcid);
87 echo "</head>\n<body>\n";
88 show($wpfcid,$args,$wpf_vars);
89 echo "</body></html>\n";
90 }
91
92 function show($wpfcid,$args,$wpfvars)
93 {
94 pdebug(1,"Start of show ()");
95
96 // check how we are called as a widget or from sidebar
97 if (sizeof($args)==0)
98 $show_from_widget=0;
99 else
100 $show_from_widget=1;
101
102 // order is important to override old title in wpfvars with new in args
103 extract($wpfvars);
104 extract($args);
105
106 $w = wp_forecast_data($wpfcid, $wpf_language);
107
108 $plugin_path = get_settings('siteurl') . '/wp-content/plugins/wp-forecast';
109
110 // get translations
111 if(function_exists('load_textdomain')) {
112 global $l10n;
113 if (!isset($l10n["wp-forecast_".$wpf_language]))
114 load_textdomain("wp-forecast_".$wpf_language, ABSPATH . "wp-content/plugins/wp-forecast/lang/".$wpf_language.".mo");
115 }
116
117 // current conditions nur ausgeben, wenn mindestens ein feld aktiv ist
118 if ( strpos(substr($dispconfig,0,9),"1") >= 0 or
119 substr($dispconfig,18,1) == "1" or
120 substr($dispconfig,21,1) == "1" or
121 substr($dispconfig,22,1) == "1" )
122 {
123 // ouput current conditions
124 $out ="";
125 $out .="\n<div class=\"wp-forecast-curr\">\n";
126
127 // if the provider sends us a failure notice print it and return
128 if ( $w['failure'] != "" )
129 {
130 $out .= __("Failure notice from provider","wp-forecast_".$wpf_language).":<br />";
131 $out .= $w['failure']."</div>";
132
133 // print it
134 if ( $show_from_widget == 1 )
135 echo $before_widget . $before_title . $title . $after_title
136 . $out . $after_widget;
137 else
138 echo $out;
139
140 return false;
141 }
142
143
144 // if error print an error message and return
145 if ( count($w)<=0)
146 {
147 $out .= __("Sorry, no valid weather data available.","wp-forecast_".$wpf_language)."<br />";
148 $out .= __("Please try again later.","wp-forecast_".$wpf_language)."</div>";
149 // print it
150 if ( $show_from_widget == 1 )
151 echo $before_widget . $before_title . $title . $after_title .
152 $out . $after_widget;
153 else
154 echo $out;
155
156 return false;
157 }
158
159 // ortsnamen ausgeben
160 $servicelink="";
161 $servicelink_end="";
162 if (substr($dispconfig,25,1) == "1") {
163 $servicelink= '<a href="'.urlencode($w['servicelink']).'">';
164 $servicelink_end="</a>";
165 }
166
167 $out .= '<div class="wp-forecast-curr-head">';
168 if ( $w['location'] == "" )
169 $out .= "<div>".$servicelink.$w['locname']. $servicelink_end."</div>\n";
170 else if ( trim($w['location']) !="" and $w['location'] != "&nbsp;")
171 $out .= "<div>".$servicelink.$w['location'].$servicelink_end."</div>\n";
172
173 // show date / time
174 // if current time should be used
175 if ($currtime=="1")
176 {
177 $cd = $w['blogdate'];
178 $ct = $w['blogtime'];
179 } else if ($service=="accu")
180 {
181 // else take given accuweather time
182 $cd = $w['accudate'];
183 $ct = $w['accutime'];
184 } else if ($service=="bug")
185 {
186 // else take given weatherbug time
187 $cd = $w['bugdate'];
188 $ct = $w['bugtime'];
189 }
190
191 if (substr($dispconfig,18,1) == "1" or substr($dispconfig,1,1) == "1") {
192 $out .= "<div>";
193 if (substr($dispconfig,18,1) == "1")
194 $out .= $cd;
195 else
196 $out .= __('time',"wp-forecast_".$wpf_language).": ";
197
198 if (substr($dispconfig,18,1) == "1" and substr($dispconfig,1,1) == "1")
199 $out .= ", ";
200
201 if (substr($dispconfig,1,1) == "1")
202 $out .= $ct;
203 $out .= "</div>\n";
204 }
205 $out .= "</div>\n";
206
207 $out .= '<div class="wp-forecast-curr-block">';
208
209 // show icon
210 if (substr($dispconfig,0,1) == "1") {
211 if ($service=="accu")
212 $out .= "<div class='wp-forecast-curr-left'><img class='wp-forecast-curr-left' src='" . $plugin_path . "/" . $w['icon']."' alt='".$w['shorttext']."' /></div>\n";
213 if ($service=="bug")
214 $out .= "<div class='wp-forecast-curr-left'><img class='wp-forecast-curr-left' src='" . $w['icon']."' alt='".$w['shorttext']."' /></div>\n";
215 }
216
217 $out .= "<div class='wp-forecast-curr-right'>";
218
219 // show short description
220 if (substr($dispconfig,2,1) == "1")
221 $out .= "<div>". $w["shorttext"]."</div>";
222
223 // show temperatur
224 if (substr($dispconfig,3,1) == "1")
225 $out .= $w["temperature"];
226 //$out .= __('tmp',"wp-forecast_".$wpf_language).": ".$w["temperature"];
227 $out .= "</div>\n"; // end of right
228 $out .= "</div>\n"; // end of block
229
230 $out .= "<div class=\"wp-forecast-curr-details\">";
231 // show realfeel
232 if (substr($dispconfig,4,1) == "1")
233 $out .= "<div>".__('flik',"wp-forecast_".$wpf_language).": ".$w["realfeel"]."</div>\n";
234 // show pressure
235 if (substr($dispconfig,5,1) == "1")
236 $out .= "<div>".__('barr',"wp-forecast_".$wpf_language).": ".$w["pressure"]."</div>\n";
237
238 // show humiditiy
239 if (substr($dispconfig,6,1) == "1")
240 //
241 // you can change the decimals of humditiy by switching
242 // the 0 to whatever you need
243 //
244 $out .= "<div>".__('hmid',"wp-forecast_".$wpf_language).": ".$w["humidity"]."%</div>\n";
245
246 // show wind
247 if (substr($dispconfig,7,1) == "1")
248 $out .= "<div>".__('winds',"wp-forecast_".$wpf_language).": ".$w['windspeed']." " . $w['winddir']."</div>\n";
249
250
251 // show windgusts
252 if (substr($dispconfig,22,1) == "1")
253 $out .= "<div>".__('Windgusts',"wp-forecast_".$wpf_language).": ".$w['windgusts']."</div>\n";
254
255
256 // show sunrise
257 if (substr($dispconfig,8,1) == "1")
258 $out .="<div>". __('sunrise',"wp-forecast_".$wpf_language).": ".$w['sunrise']."</div>\n";
259
260 // show sunset
261 if (substr($dispconfig,9,1) == "1")
262 $out .= "<div>".__('sunset',"wp-forecast_".$wpf_language).": ".$w['sunset']."</div>\n";
263
264 // show copyright
265 if (substr($dispconfig,21,1) == "1")
266 $out .= "<div class=\"wp-forecast-copyright\">".$w['copyright']."</div>";
267
268 $out .="</div>\n"; // end of details
269 $out .="</div>\n"; // end of curr
270
271
272 }
273
274
275 // ------------------
276 //
277 // output forecast
278 //
279 // -------------------
280 // calc max forecast days depending on provider
281 switch ($service)
282 {
283 case "accu":
284 $maxdays=9; break;
285 case "bug":
286 $maxdays=7; break;
287 case "com":
288 // to be done
289 break;
290 }
291
292 $out1 = "<div class=\"wp-forecast-fc\">\n";
293 $out2 = "";
294 for ($i = 1; $i <= $maxdays; $i++)
295 {
296 // check active forecast for day number i
297 if (substr($daytime,$i-1,1)=="1" or substr($nighttime,$i-1,1) =="1")
298 {
299 $out1 .="<div class=\"wp-forecast-fc-oneday\">\n";
300
301 $out1 .="<div class=\"wp-forecast-fc-head\">";
302 $out1 .= __("Forecast","wp-forecast_".$wpf_language)." ";
303 $out1 .= $w['fc_obsdate_'.$i]."</div>\n";
304 }
305
306 // check for daytime information
307 if (substr($daytime,$i-1,1)=="1" )
308 {
309 $out1 .="<div class=\"wp-forecast-fc-block\">\n";
310 $out1 .="<div class=\"wp-forecast-fc-left\">\n";
311 $out1 .= "<div>".__('day',"wp-forecast_".$wpf_language)."</div>\n";
312
313 // show icon
314 if (substr($dispconfig,10,1) == "1")
315 {
316 if ($service=="accu")
317 $out1 .= "<img class='wp-forecast-fc-left' src='".$plugin_path."/".
318 $w['fc_dt_icon_'.$i]."' alt='".
319 __($w["fc_dt_iconcode_".$i],"wp-forecast_".$wpf_language)."' />";
320
321 if ($service=="bug")
322 $out1 .= "<img class='wp-forecast-fc-left' src='".$w['fc_dt_icon_'.$i].
323 "' alt='".$w["fc_dt_desc_".$i]."' />";
324 }
325 else
326 {
327 $out1 .= "&nbsp;";
328 }
329 $out1 .= "\n</div>\n"; // end of wp-forecast-fc-left
330 $out1 .= "<div class='wp-forecast-fc-right'>";
331
332 // show short description
333 if (substr($dispconfig,11,1) == "1")
334 $out1 .= "<div>".$w["fc_dt_desc_".$i]."</div>";
335
336 // show temperature
337 if (substr($dispconfig,12,1) == "1")
338 {
339 $out1 .= "<div>";
340 $out1 .= ($service=="bug" ? $w["fc_dt_ltemp_".$i]." - ":"");
341 $out1 .= $w["fc_dt_htemp_".$i]. "</div>";
342 }
343
344 // show wind
345 if (substr($dispconfig,13,1) == "1")
346 $out1 .= "<div>".__('winds',"wp-forecast_".$wpf_language).": ".
347 $w["fc_dt_windspeed_".$i]." ".$w["fc_dt_winddir_".$i]."</div>";
348
349 // show windgusts
350 if (substr($dispconfig,23,1) == "1")
351 $out1 .= "<div>".__('Windgusts',"wp-forecast_".$wpf_language).": ".
352 $w["fc_dt_wgusts_".$i]."</div>\n";
353
354 $out1 .= "</div></div>\n"; // end of wp-forecast-fc-right / block
355 }
356
357
358 // check for nighttime information
359 if (substr($nighttime,$i-1,1)=="1" and $service != "bug")
360 {
361 $out1 .="<div class=\"wp-forecast-fc-block\">\n";
362 $out1 .="<div class=\"wp-forecast-fc-left\">\n";
363 $out1 .= "<div>". __('night',"wp-forecast_".$wpf_language)."</div>\n";
364 if (substr($dispconfig,14,1) == "1")
365 {
366 $iconfile=find_icon($w["fc_nt_icon_".$i]);
367 $out1 .= "<img class='wp-forecast-fc-left' src='"
368 .$plugin_path."/".$w['fc_nt_icon_'.$i]."' alt='"
369 .__($w["fc_nt_iconcode_".$i],"wp-forecast_".$wpf_language)."' />";
370 }
371 else
372 {
373 $out1 .= "&nbsp;";
374 }
375 $out1 .= "\n</div>\n<div class='wp-forecast-fc-right'>";
376
377 // show short description
378 if (substr($dispconfig,15,1) == "1")
379 $out1 .= "<div>".$w["fc_nt_desc_".$i]."</div>";
380
381 // show temperature
382 if (substr($dispconfig,16,1) == "1")
383 $out1 .= "<div>".$w["fc_nt_ltemp_".$i]."</div>";
384
385
386 // show wind
387 if (substr($dispconfig,17,1) == "1")
388 $out1 .= "<div>".__('winds',"wp-forecast_".$wpf_language)
389 .": ".$w["fc_nt_windspeed_".$i]." "
390 . $w["fc_nt_winddir_".$i] ."</div>";
391
392
393 // show windgusts
394 if (substr($dispconfig,24,1) == "1")
395 $out1 .= "<div>".__('Windgusts',"wp-forecast_".$wpf_language)
396 .": ".$w["fc_nt_wgusts_".$i]."</div>\n";
397
398
399 $out1 .= "</div></div>\n"; // end of wp-forecast-fc-right / block
400 }
401
402
403
404 // close div block
405 if (substr($daytime,$i-1,1)=="1" or substr($nighttime,$i-1,1) =="1")
406 $out1 .="</div>\n";
407
408 // store first shown forecast in case pulldown is active
409 if ( $pdforecast == 1 and $pdfirstday == $i ) {
410 $out2 = $out1 . "</div>\n";
411 }
412 }
413
414 $out1 .= "</div>\n"; // end of wp-forecast-fc
415
416 // wrap a div around for pulldown and switch off complete forecast
417 if ( $pdforecast == 1 ) {
418 $out1 .= "<div class='wpff_nav' id='wpfbl' onclick=\"document.getElementById('wpfc1').style.display='none';document.getElementById('wpfc2').style.display='block';return false;\">" . __("Less forecast...","wp-forecast_" . $wpf_language) . "</div>\n";
419 $out2 .= "<div class='wpff_nav' id='wpfbm' onclick=\"document.getElementById('wpfc2').style.display='none';document.getElementById('wpfc1').style.display='block';return false;\">" . __("More forecast...","wp-forecast_" . $wpf_language) . "</div>\n";
420
421 $out1 = '<div id="wpfc1" style="display:none;">' . $out1 . "</div>\n";
422 $out2 = '<div id="wpfc2" style="display:block;">' . $out2 . "</div>\n";
423 }
424
425
426 // print it
427 if ( $show_from_widget == 1 )
428 echo $before_widget . $before_title . $title . $after_title;
429
430 echo '<div class="wp-forecast">' . $out . $out1 . $out2 . '</div>'."\n";
431 // to come back to theme floating status
432 echo '<div style="clear:inherit;">&nbsp;</div>';
433
434 if ( $show_from_widget == 1 )
435 echo $after_widget;
436
437 pdebug(1,"End of show ()");
438
439 }
440 ?>