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

446 lines 13.9 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 parameter fuer open in new window berücksichtigen
160 $servicelink="";
161 $servicelink_end="";
162 if (substr($dispconfig,25,1) == "1") {
163 $servicelink= '<a href="'.$w['servicelink'].'"';
164 $servicelink_end="</a>";
165
166 if (substr($dispconfig,26,1) == "1")
167 $servicelink= $servicelink . ' target="_blank" >';
168 else
169 $servicelink= $servicelink.' >';
170 }
171
172
173 $out .= '<div class="wp-forecast-curr-head">';
174 if ( $w['location'] == "" )
175 $out .= "<div>".$servicelink.$w['locname']. $servicelink_end."</div>\n";
176 else if ( trim($w['location']) !="" and $w['location'] != "&nbsp;")
177 $out .= "<div>".$servicelink.$w['location'].$servicelink_end."</div>\n";
178
179 // show date / time
180 // if current time should be used
181 if ($currtime=="1")
182 {
183 $cd = $w['blogdate'];
184 $ct = $w['blogtime'];
185 } else if ($service=="accu")
186 {
187 // else take given accuweather time
188 $cd = $w['accudate'];
189 $ct = $w['accutime'];
190 } else if ($service=="bug")
191 {
192 // else take given weatherbug time
193 $cd = $w['bugdate'];
194 $ct = $w['bugtime'];
195 }
196
197 if (substr($dispconfig,18,1) == "1" or substr($dispconfig,1,1) == "1") {
198 $out .= "<div>";
199 if (substr($dispconfig,18,1) == "1")
200 $out .= $cd;
201 else
202 $out .= __('time',"wp-forecast_".$wpf_language).": ";
203
204 if (substr($dispconfig,18,1) == "1" and substr($dispconfig,1,1) == "1")
205 $out .= ", ";
206
207 if (substr($dispconfig,1,1) == "1")
208 $out .= $ct;
209 $out .= "</div>\n";
210 }
211 $out .= "</div>\n";
212
213 $out .= '<div class="wp-forecast-curr-block">';
214
215 // show icon
216 if (substr($dispconfig,0,1) == "1") {
217 if ($service=="accu")
218 $out .= "<div class='wp-forecast-curr-left'><img class='wp-forecast-curr-left' src='" . $plugin_path . "/" . $w['icon']."' alt='".$w['shorttext']."' /></div>\n";
219 if ($service=="bug")
220 $out .= "<div class='wp-forecast-curr-left'><img class='wp-forecast-curr-left' src='" . $w['icon']."' alt='".$w['shorttext']."' /></div>\n";
221 }
222
223 $out .= "<div class='wp-forecast-curr-right'>";
224
225 // show short description
226 if (substr($dispconfig,2,1) == "1")
227 $out .= "<div>". $w["shorttext"]."</div>";
228
229 // show temperatur
230 if (substr($dispconfig,3,1) == "1")
231 $out .= $w["temperature"];
232 //$out .= __('tmp',"wp-forecast_".$wpf_language).": ".$w["temperature"];
233 $out .= "</div>\n"; // end of right
234 $out .= "</div>\n"; // end of block
235
236 $out .= "<div class=\"wp-forecast-curr-details\">";
237 // show realfeel
238 if (substr($dispconfig,4,1) == "1")
239 $out .= "<div>".__('flik',"wp-forecast_".$wpf_language).": ".$w["realfeel"]."</div>\n";
240 // show pressure
241 if (substr($dispconfig,5,1) == "1")
242 $out .= "<div>".__('barr',"wp-forecast_".$wpf_language).": ".$w["pressure"]."</div>\n";
243
244 // show humiditiy
245 if (substr($dispconfig,6,1) == "1")
246 //
247 // you can change the decimals of humditiy by switching
248 // the 0 to whatever you need
249 //
250 $out .= "<div>".__('hmid',"wp-forecast_".$wpf_language).": ".$w["humidity"]."%</div>\n";
251
252 // show wind
253 if (substr($dispconfig,7,1) == "1")
254 $out .= "<div>".__('winds',"wp-forecast_".$wpf_language).": ".$w['windspeed']." " . $w['winddir']."</div>\n";
255
256
257 // show windgusts
258 if (substr($dispconfig,22,1) == "1")
259 $out .= "<div>".__('Windgusts',"wp-forecast_".$wpf_language).": ".$w['windgusts']."</div>\n";
260
261
262 // show sunrise
263 if (substr($dispconfig,8,1) == "1")
264 $out .="<div>". __('sunrise',"wp-forecast_".$wpf_language).": ".$w['sunrise']."</div>\n";
265
266 // show sunset
267 if (substr($dispconfig,9,1) == "1")
268 $out .= "<div>".__('sunset',"wp-forecast_".$wpf_language).": ".$w['sunset']."</div>\n";
269
270 // show copyright
271 if (substr($dispconfig,21,1) == "1")
272 $out .= "<div class=\"wp-forecast-copyright\">".$w['copyright']."</div>";
273
274 $out .="</div>\n"; // end of details
275 $out .="</div>\n"; // end of curr
276
277
278 }
279
280
281 // ------------------
282 //
283 // output forecast
284 //
285 // -------------------
286 // calc max forecast days depending on provider
287 switch ($service)
288 {
289 case "accu":
290 $maxdays=9; break;
291 case "bug":
292 $maxdays=7; break;
293 case "com":
294 // to be done
295 break;
296 }
297
298 $out1 = "<div class=\"wp-forecast-fc\">\n";
299 $out2 = "";
300 for ($i = 1; $i <= $maxdays; $i++)
301 {
302 // check active forecast for day number i
303 if (substr($daytime,$i-1,1)=="1" or substr($nighttime,$i-1,1) =="1")
304 {
305 $out1 .="<div class=\"wp-forecast-fc-oneday\">\n";
306
307 $out1 .="<div class=\"wp-forecast-fc-head\">";
308 $out1 .= __("Forecast","wp-forecast_".$wpf_language)." ";
309 $out1 .= $w['fc_obsdate_'.$i]."</div>\n";
310 }
311
312 // check for daytime information
313 if (substr($daytime,$i-1,1)=="1" )
314 {
315 $out1 .="<div class=\"wp-forecast-fc-block\">\n";
316 $out1 .="<div class=\"wp-forecast-fc-left\">\n";
317 $out1 .= "<div>".__('day',"wp-forecast_".$wpf_language)."</div>\n";
318
319 // show icon
320 if (substr($dispconfig,10,1) == "1")
321 {
322 if ($service=="accu")
323 $out1 .= "<img class='wp-forecast-fc-left' src='".$plugin_path."/".
324 $w['fc_dt_icon_'.$i]."' alt='".
325 __($w["fc_dt_iconcode_".$i],"wp-forecast_".$wpf_language)."' />";
326
327 if ($service=="bug")
328 $out1 .= "<img class='wp-forecast-fc-left' src='".$w['fc_dt_icon_'.$i].
329 "' alt='".$w["fc_dt_desc_".$i]."' />";
330 }
331 else
332 {
333 $out1 .= "&nbsp;";
334 }
335 $out1 .= "\n</div>\n"; // end of wp-forecast-fc-left
336 $out1 .= "<div class='wp-forecast-fc-right'>";
337
338 // show short description
339 if (substr($dispconfig,11,1) == "1")
340 $out1 .= "<div>".$w["fc_dt_desc_".$i]."</div>";
341
342 // show temperature
343 if (substr($dispconfig,12,1) == "1")
344 {
345 $out1 .= "<div>";
346 $out1 .= ($service=="bug" ? $w["fc_dt_ltemp_".$i]." - ":"");
347 $out1 .= $w["fc_dt_htemp_".$i]. "</div>";
348 }
349
350 // show wind
351 if (substr($dispconfig,13,1) == "1")
352 $out1 .= "<div>".__('winds',"wp-forecast_".$wpf_language).": ".
353 $w["fc_dt_windspeed_".$i]." ".$w["fc_dt_winddir_".$i]."</div>";
354
355 // show windgusts
356 if (substr($dispconfig,23,1) == "1")
357 $out1 .= "<div>".__('Windgusts',"wp-forecast_".$wpf_language).": ".
358 $w["fc_dt_wgusts_".$i]."</div>\n";
359
360 $out1 .= "</div></div>\n"; // end of wp-forecast-fc-right / block
361 }
362
363
364 // check for nighttime information
365 if (substr($nighttime,$i-1,1)=="1" and $service != "bug")
366 {
367 $out1 .="<div class=\"wp-forecast-fc-block\">\n";
368 $out1 .="<div class=\"wp-forecast-fc-left\">\n";
369 $out1 .= "<div>". __('night',"wp-forecast_".$wpf_language)."</div>\n";
370 if (substr($dispconfig,14,1) == "1")
371 {
372 $iconfile=find_icon($w["fc_nt_icon_".$i]);
373 $out1 .= "<img class='wp-forecast-fc-left' src='"
374 .$plugin_path."/".$w['fc_nt_icon_'.$i]."' alt='"
375 .__($w["fc_nt_iconcode_".$i],"wp-forecast_".$wpf_language)."' />";
376 }
377 else
378 {
379 $out1 .= "&nbsp;";
380 }
381 $out1 .= "\n</div>\n<div class='wp-forecast-fc-right'>";
382
383 // show short description
384 if (substr($dispconfig,15,1) == "1")
385 $out1 .= "<div>".$w["fc_nt_desc_".$i]."</div>";
386
387 // show temperature
388 if (substr($dispconfig,16,1) == "1")
389 $out1 .= "<div>".$w["fc_nt_ltemp_".$i]."</div>";
390
391
392 // show wind
393 if (substr($dispconfig,17,1) == "1")
394 $out1 .= "<div>".__('winds',"wp-forecast_".$wpf_language)
395 .": ".$w["fc_nt_windspeed_".$i]." "
396 . $w["fc_nt_winddir_".$i] ."</div>";
397
398
399 // show windgusts
400 if (substr($dispconfig,24,1) == "1")
401 $out1 .= "<div>".__('Windgusts',"wp-forecast_".$wpf_language)
402 .": ".$w["fc_nt_wgusts_".$i]."</div>\n";
403
404
405 $out1 .= "</div></div>\n"; // end of wp-forecast-fc-right / block
406 }
407
408
409
410 // close div block
411 if (substr($daytime,$i-1,1)=="1" or substr($nighttime,$i-1,1) =="1")
412 $out1 .="</div>\n";
413
414 // store first shown forecast in case pulldown is active
415 if ( $pdforecast == 1 and $pdfirstday == $i ) {
416 $out2 = $out1 . "</div>\n";
417 }
418 }
419
420 $out1 .= "</div>\n"; // end of wp-forecast-fc
421
422 // wrap a div around for pulldown and switch off complete forecast
423 if ( $pdforecast == 1 ) {
424 $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";
425 $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";
426
427 $out1 = '<div id="wpfc1" style="display:none;">' . $out1 . "</div>\n";
428 $out2 = '<div id="wpfc2" style="display:block;">' . $out2 . "</div>\n";
429 }
430
431
432 // print it
433 if ( $show_from_widget == 1 )
434 echo $before_widget . $before_title . $title . $after_title;
435
436 echo '<div class="wp-forecast">' . $out . $out1 . $out2 . '</div>'."\n";
437 // to come back to theme floating status
438 echo '<div style="clear:inherit;">&nbsp;</div>';
439
440 if ( $show_from_widget == 1 )
441 echo $after_widget;
442
443 pdebug(1,"End of show ()");
444
445 }
446 ?>