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

504 lines 16.1 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 /* Copyright 2006-2010 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 = esc_attr($_GET['wpfcid']);
69 $language_override = esc_attr($_GET['language_override']);
70 $header = esc_attr($_GET['header']);
71 $selector = esc_attr($_GET['selector']);
72 if ($selector == "1")
73 $selector = "?";
74 $args=array();
75
76 $wpf_vars=get_wpf_opts($wpfcid);
77 if (!empty($language_override)) {
78 $wpf_vars['wpf_language']=$language_override;
79 }
80 $weather=maybe_unserialize(wpf_get_option("wp-forecast-cache".$wpfcid));
81
82
83 if ($header) {
84 echo '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">'."\n";
85 echo '<html xmlns="http://www.w3.org/1999/xhtml" dir="ltr" lang="de-DE">'."\n";
86 echo "<head><title>wp-forecast iframe</title>\n";
87 echo '<meta http-equiv="content-type" content="text/html; charset=utf-8" />'."\n";
88 }
89
90 if ($header)
91 {
92 wp_forecast_css_nowp($wpfcid);
93 echo "</head>\n<body>\n";
94 }
95
96 show($selector . $wpfcid,$args,$wpf_vars);
97
98 if ($header)
99 echo "</body></html>\n";
100 }
101
102 function show($wpfcid,$args,$wpfvars)
103 {
104 pdebug(1,"Start of show ()");
105
106 // check how we are called as a widget or from sidebar
107 if (sizeof($args)==0)
108 $show_from_widget=0;
109 else
110 $show_from_widget=1;
111
112 // order is important to override old title in wpfvars with new in args
113 extract($wpfvars);
114 extract($args);
115
116 // get translations
117 if(function_exists('load_textdomain')) {
118 global $l10n;
119 if (!isset($l10n["wp-forecast_".$wpf_language]))
120 load_textdomain("wp-forecast_".$wpf_language, ABSPATH . "wp-content/plugins/wp-forecast/lang/".$wpf_language.".mo");
121 }
122
123 $plugin_path = get_settings('siteurl') . '/wp-content/plugins/wp-forecast';
124
125 // show location selection dialog and handle it ajax like
126 $fout="";
127 $selector = substr($wpfcid,0,1);
128 if ($selector == "?")
129 {
130 $wpfcid = substr($wpfcid,1);
131 if ($wpfcid == "")
132 $wpfcid = "A";
133
134 $count = wpf_get_option('wp-forecast-count');
135 $fout .= "<div class='wpf-selector'><form action=''>" .
136 __("Locations:","wp-forecast_".$wpf_language);
137 $fout .= "<select id='wpf_selector' size='1' onchange='wpf_update();' >";
138 for ($i=0;$i<$count;$i++) {
139 $id = get_widget_id( $i );
140 $v = get_wpf_opts($id);
141 $fout .="<option value='".$id."' ";
142 if ($id == $wpfcid)
143 $fout .= "selected='selected' ";
144 $fout .=">".$v['locname']."</option>";
145 }
146 $fout .= "</select>";
147 $fout .="<input id='wpf_selector_site' type='hidden' value='" .
148 site_url("/wp-content/plugins/wp-forecast")."' />";
149 $fout .="<input id='wpf_language' type='hidden' value='" . $wpf_language ."' />";
150 $fout .= "</form>";
151 $fout .='<script type="text/javascript">window.onDomReady(wpf_load);</script>';
152 $fout .= "</div>";
153
154 }
155
156 $w = wp_forecast_data($wpfcid, $wpf_language);
157
158 // current conditions nur ausgeben, wenn mindestens ein feld aktiv ist
159 if ( strpos(substr($dispconfig,0,9),"1") >= 0 or
160 substr($dispconfig,18,1) == "1" or
161 substr($dispconfig,21,1) == "1" or
162 substr($dispconfig,22,1) == "1" )
163 {
164 // ouput current conditions
165 $out ="";
166 $out .="\n<div class=\"wp-forecast-curr\">\n";
167
168 // if the provider sends us a failure notice print it and return
169 if ( $w['failure'] != "" )
170 {
171 $out .= __("Failure notice from provider","wp-forecast_".$wpf_language).":<br />";
172 $out .= $w['failure']."</div>";
173
174 // print it
175 if ( $show_from_widget == 1 )
176 echo $before_widget . $before_title . $title . $after_title
177 . $out . $after_widget;
178 else
179 echo $out;
180
181 return false;
182 }
183
184
185 // if error print an error message and return
186 if ( count($w)<=0)
187 {
188 $out .= __("Sorry, no valid weather data available.","wp-forecast_".$wpf_language)."<br />";
189 $out .= __("Please try again later.","wp-forecast_".$wpf_language)."</div>";
190 // print it
191 if ( $show_from_widget == 1 )
192 echo $before_widget . $before_title . $title . $after_title .
193 $out . $after_widget;
194 else
195 echo $out;
196
197 return false;
198 }
199
200 // ortsnamen ausgeben parameter fuer open in new window berücksichtigen
201 $servicelink="";
202 $servicelink_end="";
203 if (substr($dispconfig,25,1) == "1") {
204 $servicelink= '<a href="'.$w['servicelink'].'"';
205 $servicelink_end="</a>";
206
207 if (substr($dispconfig,26,1) == "1")
208 $servicelink= $servicelink . ' target="_blank" >';
209 else
210 $servicelink= $servicelink.' >';
211 }
212
213
214 $out .= '<div class="wp-forecast-curr-head">';
215 if ( $w['location'] == "" )
216 $out .= "<div>".$servicelink.$w['locname']. $servicelink_end."</div>\n";
217 else if ( trim($w['location']) !="" and $w['location'] != "&nbsp;")
218 $out .= "<div>".$servicelink.$w['location'].$servicelink_end."</div>\n";
219
220 // show date / time
221 // if current time should be used
222 if ($currtime=="1")
223 {
224 $cd = $w['blogdate'];
225 $ct = $w['blogtime'];
226 } else if ($service=="accu")
227 {
228 // else take given accuweather time
229 $cd = $w['accudate'];
230 $ct = $w['accutime'];
231 } else if ($service=="bug")
232 {
233 // else take given weatherbug time
234 $cd = $w['bugdate'];
235 $ct = $w['bugtime'];
236 } else if ($service=="google")
237 {
238 // else take given weatherbug time
239 $cd = $w['googledate'];
240 $ct = $w['googletime'];
241 }
242
243 if (substr($dispconfig,18,1) == "1" or substr($dispconfig,1,1) == "1") {
244 $out .= "<div>";
245 if (substr($dispconfig,18,1) == "1")
246 $out .= $cd;
247 else
248 $out .= __('time',"wp-forecast_".$wpf_language).": ";
249
250 if (substr($dispconfig,18,1) == "1" and substr($dispconfig,1,1) == "1")
251 $out .= ", ";
252
253 if (substr($dispconfig,1,1) == "1")
254 $out .= $ct;
255 $out .= "</div>\n";
256 }
257 $out .= "</div>\n";
258
259 $out .= '<div class="wp-forecast-curr-block">';
260
261 // show icon
262 if (substr($dispconfig,0,1) == "1") {
263 if ($service=="accu")
264 $out .= "<div class='wp-forecast-curr-left'><img class='wp-forecast-curr-left' src='" . $plugin_path . "/" . $w['icon']."' alt='".$w['shorttext']."' /></div>\n";
265 if ($service=="bug")
266 $out .= "<div class='wp-forecast-curr-left'><img class='wp-forecast-curr-left' src='" . $w['icon']."' alt='".$w['shorttext']."' /></div>\n";
267
268 if ($service=="google")
269 $out .= "<div class='wp-forecast-curr-left'><img class='wp-forecast-curr-left' src='" . $w['icon']."' alt='".$w['shorttext']."' /></div>\n";
270 }
271
272 $out .= "<div class='wp-forecast-curr-right'>";
273
274 // show short description
275 if (substr($dispconfig,2,1) == "1")
276 $out .= "<div>". $w["shorttext"]."</div>";
277
278 // show temperatur
279 if (substr($dispconfig,3,1) == "1")
280 $out .= $w["temperature"];
281 //$out .= __('tmp',"wp-forecast_".$wpf_language).": ".$w["temperature"];
282 $out .= "</div>\n"; // end of right
283 $out .= "</div>\n"; // end of block
284
285 $out .= "<div class=\"wp-forecast-curr-details\">";
286 // show realfeel
287 if (substr($dispconfig,4,1) == "1")
288 $out .= "<div>".__('flik',"wp-forecast_".$wpf_language).": ".$w["realfeel"]."</div>\n";
289 // show pressure
290 if (substr($dispconfig,5,1) == "1")
291 $out .= "<div>".__('barr',"wp-forecast_".$wpf_language).": ".$w["pressure"]."</div>\n";
292
293 // show humiditiy
294 if (substr($dispconfig,6,1) == "1")
295 //
296 // you can change the decimals of humditiy by switching
297 // the 0 to whatever you need
298 //
299 $out .= "<div>".__('hmid',"wp-forecast_".$wpf_language).": ".$w["humidity"]."%</div>\n";
300
301 // show wind
302 if (substr($dispconfig,7,1) == "1")
303 $out .= "<div>".__('winds',"wp-forecast_".$wpf_language).": ".$w['windspeed']." " . $w['winddir']."</div>\n";
304
305
306 // show windgusts
307 if (substr($dispconfig,22,1) == "1")
308 $out .= "<div>".__('Windgusts',"wp-forecast_".$wpf_language).": ".$w['windgusts']."</div>\n";
309
310
311 // show sunrise
312 if (substr($dispconfig,8,1) == "1")
313 $out .="<div>". __('sunrise',"wp-forecast_".$wpf_language).": ".$w['sunrise']."</div>\n";
314
315 // show sunset
316 if (substr($dispconfig,9,1) == "1")
317 $out .= "<div>".__('sunset',"wp-forecast_".$wpf_language).": ".$w['sunset']."</div>\n";
318
319 // show copyright
320 if (substr($dispconfig,21,1) == "1")
321 $out .= "<div class=\"wp-forecast-copyright\">".$w['copyright']."</div>";
322
323 $out .="</div>\n"; // end of details
324 $out .="</div>\n"; // end of curr
325
326
327 }
328
329
330 // ------------------
331 //
332 // output forecast
333 //
334 // -------------------
335 // calc max forecast days depending on provider
336 switch ($service)
337 {
338 case "accu":
339 $maxdays=9; break;
340 case "bug":
341 $maxdays=7; break;
342 case "com":
343 // to be done
344 case "google":
345 $maxdays=4; break;
346 }
347
348 $out1 = "<div class=\"wp-forecast-fc\">\n";
349 $out2 = "";
350 for ($i = 1; $i <= $maxdays; $i++)
351 {
352 // check active forecast for day number i
353 if (substr($daytime,$i-1,1)=="1" or substr($nighttime,$i-1,1) =="1")
354 {
355 $out1 .="<div class=\"wp-forecast-fc-oneday\">\n";
356
357 $out1 .="<div class=\"wp-forecast-fc-head\">";
358 $out1 .= __("Forecast","wp-forecast_".$wpf_language)." ";
359 $out1 .= $w['fc_obsdate_'.$i]."</div>\n";
360 }
361
362 // check for daytime information
363 if (substr($daytime,$i-1,1)=="1" )
364 {
365 $out1 .="<div class=\"wp-forecast-fc-block\">\n";
366 $out1 .="<div class=\"wp-forecast-fc-left\">\n";
367 $out1 .= "<div>".__('day',"wp-forecast_".$wpf_language)."</div>\n";
368
369 // show icon
370 if (substr($dispconfig,10,1) == "1")
371 {
372 if ($service=="accu")
373 $out1 .= "<img class='wp-forecast-fc-left' src='".$plugin_path."/".
374 $w['fc_dt_icon_'.$i]."' alt='".
375 __($w["fc_dt_iconcode_".$i],"wp-forecast_".$wpf_language)."' />";
376
377 if ($service=="bug")
378 $out1 .= "<img class='wp-forecast-fc-left' src='".$w['fc_dt_icon_'.$i].
379 "' alt='".$w["fc_dt_desc_".$i]."' />";
380
381 if ($service=="google")
382 $out1 .= "<img class='wp-forecast-fc-left' src='".$w['fc_dt_icon_'.$i].
383 "' alt='".$w["fc_dt_desc_".$i]."' />";
384 }
385 else
386 {
387 $out1 .= "&nbsp;";
388 }
389 $out1 .= "\n</div>\n"; // end of wp-forecast-fc-left
390 $out1 .= "<div class='wp-forecast-fc-right'>";
391
392 // show short description
393 if (substr($dispconfig,11,1) == "1")
394 $out1 .= "<div>".$w["fc_dt_desc_".$i]."</div>";
395
396 // show temperature
397 if (substr($dispconfig,12,1) == "1")
398 {
399 $out1 .= "<div>";
400 $out1 .= ($service=="bug" ? $w["fc_dt_ltemp_".$i]." - ":"");
401 $out1 .= $w["fc_dt_htemp_".$i]. "</div>";
402 }
403
404 // show wind
405 if (substr($dispconfig,13,1) == "1")
406 $out1 .= "<div>".__('winds',"wp-forecast_".$wpf_language).": ".
407 $w["fc_dt_windspeed_".$i]." ".$w["fc_dt_winddir_".$i]."</div>";
408
409 // show windgusts
410 if (substr($dispconfig,23,1) == "1")
411 $out1 .= "<div>".__('Windgusts',"wp-forecast_".$wpf_language).": ".
412 $w["fc_dt_wgusts_".$i]."</div>\n";
413
414 $out1 .= "</div></div>\n"; // end of wp-forecast-fc-right / block
415 }
416
417
418 // check for nighttime information
419 if (substr($nighttime,$i-1,1)=="1" and $service != "bug")
420 {
421 $out1 .="<div class=\"wp-forecast-fc-block\">\n";
422 $out1 .="<div class=\"wp-forecast-fc-left\">\n";
423 $out1 .= "<div>". __('night',"wp-forecast_".$wpf_language)."</div>\n";
424 if (substr($dispconfig,14,1) == "1")
425 {
426 $iconfile=find_icon($w["fc_nt_icon_".$i]);
427 $out1 .= "<img class='wp-forecast-fc-left' src='"
428 .$plugin_path."/".$w['fc_nt_icon_'.$i]."' alt='"
429 .__($w["fc_nt_iconcode_".$i],"wp-forecast_".$wpf_language)."' />";
430 }
431 else
432 {
433 $out1 .= "&nbsp;";
434 }
435 $out1 .= "\n</div>\n<div class='wp-forecast-fc-right'>";
436
437 // show short description
438 if (substr($dispconfig,15,1) == "1")
439 $out1 .= "<div>".$w["fc_nt_desc_".$i]."</div>";
440
441 // show temperature
442 if (substr($dispconfig,16,1) == "1")
443 $out1 .= "<div>".$w["fc_nt_ltemp_".$i]."</div>";
444
445
446 // show wind
447 if (substr($dispconfig,17,1) == "1")
448 $out1 .= "<div>".__('winds',"wp-forecast_".$wpf_language)
449 .": ".$w["fc_nt_windspeed_".$i]." "
450 . $w["fc_nt_winddir_".$i] ."</div>";
451
452
453 // show windgusts
454 if (substr($dispconfig,24,1) == "1")
455 $out1 .= "<div>".__('Windgusts',"wp-forecast_".$wpf_language)
456 .": ".$w["fc_nt_wgusts_".$i]."</div>\n";
457
458
459 $out1 .= "</div></div>\n"; // end of wp-forecast-fc-right / block
460 }
461
462
463
464 // close div block
465 if (substr($daytime,$i-1,1)=="1" or substr($nighttime,$i-1,1) =="1")
466 $out1 .="</div>\n";
467
468 // store first shown forecast in case pulldown is active
469 if ( $pdforecast == 1 and $pdfirstday == $i ) {
470 $out2 = $out1 . "</div>\n";
471 }
472 }
473
474 $out1 .= "</div>\n"; // end of wp-forecast-fc
475
476 //
477 // wrap a div around for pulldown and switch off complete forecast
478 //
479 // mark ids: wpfbl wpfc1 wpfc2 wpfbm with widget id have disjunct ods when using more than one pulldown widget
480 if ( $pdforecast == 1 ) {
481 $out1 .= "<div class='wpff_nav' id='wpfbl1".$wpfcid."' onclick=\"document.getElementById('wpfc1".$wpfcid."').style.display='none';document.getElementById('wpfc2".$wpfcid."').style.display='block';return false;\">" . __("Less forecast...","wp-forecast_" . $wpf_language) . "</div>\n";
482 $out1 = "<div class='wpff_nav' id='wpfbl2".$wpfcid."' onclick=\"document.getElementById('wpfc1".$wpfcid."').style.display='none';document.getElementById('wpfc2".$wpfcid."').style.display='block';return false;\">" . __("Less forecast...","wp-forecast_" . $wpf_language) . "</div>\n" . $out1;
483 $out2 .= "<div class='wpff_nav' id='wpfbm".$wpfcid."' onclick=\"document.getElementById('wpfc2".$wpfcid."').style.display='none';document.getElementById('wpfc1".$wpfcid."').style.display='block';return false;\">" . __("More forecast...","wp-forecast_" . $wpf_language) . "</div>\n";
484
485 $out1 = '<div id="wpfc1'.$wpfcid.'" style="display:none;">' . $out1 . "</div>\n";
486 $out2 = '<div id="wpfc2'.$wpfcid.'" style="display:block;">' . $out2 . "</div>\n";
487 }
488
489
490 // print it
491 if ( $show_from_widget == 1 )
492 echo $before_widget . $before_title . $title . $after_title;
493
494 echo '<div id="wp-forecast'.$wpfcid.'" class="wp-forecast">' . $fout . $out . $out1 . $out2 . '</div>'."\n";
495 // to come back to theme floating status
496 echo '<div style="clear:inherit;">&nbsp;</div>';
497
498 if ( $show_from_widget == 1 )
499 echo $after_widget;
500
501 pdebug(1,"End of show ()");
502
503 }
504 ?>