| 1 |
<?php |
| 2 |
|
| 3 |
// |
| 4 |
// display the weather-data |
| 5 |
// |
| 6 |
// the following structure will be used: |
| 7 |
// |
| 8 |
// <div class=wp-forecast"> |
| 9 |
// <div class="wp-forecast-curr"> |
| 10 |
// <div class="wp-forecast-curr-details"> |
| 11 |
// </div> |
| 12 |
// <div class="wp-forecast-copyright"> |
| 13 |
// </div> |
| 14 |
// </div> |
| 15 |
// <div class="wp-forecast-fc"> |
| 16 |
// <div class="wp-forecast-fc-details"> |
| 17 |
// </div> |
| 18 |
// </div> |
| 19 |
// </div> |
| 20 |
// |
| 21 |
// |
| 22 |
// |
| 23 |
function show($wpfcid,$w,$args,$wpfvars) |
| 24 |
{ |
| 25 |
global $wpf_debug; |
| 26 |
|
| 27 |
if ($wpf_debug > 0) |
| 28 |
pdebug("Start of show ()"); |
| 29 |
|
| 30 |
// check how we are called as a widget or from sidebar |
| 31 |
if (sizeof($args)==0) |
| 32 |
$show_from_widget=0; |
| 33 |
else |
| 34 |
$show_from_widget=1; |
| 35 |
|
| 36 |
|
| 37 |
extract($args); |
| 38 |
extract($wpfvars); |
| 39 |
|
| 40 |
$plugin_path = get_settings('siteurl') . '/wp-content/plugins/wp-forecast'; |
| 41 |
|
| 42 |
// get translations |
| 43 |
if(function_exists('load_textdomain')) |
| 44 |
load_textdomain("wp-forecast_".$wpf_language, ABSPATH . "wp-content/plugins/wp-forecast/lang/".$wpf_language.".mo"); |
| 45 |
|
| 46 |
|
| 47 |
// ouput current conditions |
| 48 |
$out =""; |
| 49 |
$out .="\n<div class=\"wp-forecast-curr\">\n"; |
| 50 |
|
| 51 |
|
| 52 |
// if error print an error message and return |
| 53 |
if ( count($w)<=0) { |
| 54 |
$out .= __("Sorry, no valid weather data available.","wp-forecast_".$wpf_language)."<br /></div>"; |
| 55 |
$out .= __("Please try again later.","wp-forecast_".$wpf_language)."</div>"; |
| 56 |
// print it |
| 57 |
if ( $show_from_widget == 1 ) |
| 58 |
echo $before_widget . $before_title . $title . $after_title . $out . $after_widget; |
| 59 |
else |
| 60 |
echo $out; |
| 61 |
|
| 62 |
return false; |
| 63 |
} |
| 64 |
|
| 65 |
$out .= "<div>"; |
| 66 |
|
| 67 |
if ( $locname != "" ) |
| 68 |
$out .= $locname."</div>\n"; |
| 69 |
else |
| 70 |
$out .= $w["city"]." ".$w["state"]."</div>\n"; |
| 71 |
|
| 72 |
$out .="<table class=\"wp-forecast-curr\">\n"; |
| 73 |
|
| 74 |
// show date / time |
| 75 |
|
| 76 |
// if current time should be used calc current local time |
| 77 |
if ($currtime=="1") { |
| 78 |
|
| 79 |
$lt = time() - date("Z"); // this is the GMT |
| 80 |
$ct = $lt + (3600 * ($w['gmtdiff'])); // local time |
| 81 |
if ( $w['gmtdiffdls'] == 1) |
| 82 |
$ct += 3600; // time with daylightsavings |
| 83 |
} else { |
| 84 |
// else take given accuweather time |
| 85 |
$cts = $w['fc_obsdate_1']." ".$w['time']; |
| 86 |
$ct = strtotime($cts); |
| 87 |
} |
| 88 |
|
| 89 |
if (substr($dispconfig,18,1) == "1" or substr($dispconfig,1,1) == "1") { |
| 90 |
$out .= "<tr align=\"center\"><td colspan=\"2\">"; |
| 91 |
if (substr($dispconfig,18,1) == "1") |
| 92 |
$out .= date_i18n($fc_date_format, $ct); |
| 93 |
else |
| 94 |
$out .= __('time',"wp-forecast_".$wpf_language).": "; |
| 95 |
|
| 96 |
if (substr($dispconfig,18,1) == "1" and substr($dispconfig,1,1) == "1") |
| 97 |
$out .= ", "; |
| 98 |
|
| 99 |
if (substr($dispconfig,1,1) == "1") |
| 100 |
$out .= date_i18n($fc_time_format, $ct)."<br />"; |
| 101 |
$out .= "</td></tr>"; |
| 102 |
} |
| 103 |
|
| 104 |
// show icon |
| 105 |
if (substr($dispconfig,0,1) == "1") { |
| 106 |
$out .= "<tr><td><img src='".$plugin_path."/icons/".$w["weathericon"].".gif' alt='".__($w["weathericon"],"wp-forecast_".$wpf_language)."' /></td>\n"; |
| 107 |
} else { |
| 108 |
$out .= "<tr><td></td>\n"; |
| 109 |
} |
| 110 |
|
| 111 |
$out .= "<td>"; |
| 112 |
|
| 113 |
// show short description |
| 114 |
if (substr($dispconfig,2,1) == "1") |
| 115 |
$out .= __($w["weathericon"],"wp-forecast_".$wpf_language)."<br />"; |
| 116 |
|
| 117 |
// show temperatur |
| 118 |
if (substr($dispconfig,3,1) == "1") { |
| 119 |
$out .= __('tmp',"wp-forecast_".$wpf_language).": ".$w["temperature"]."°"; |
| 120 |
$out .= $w['un_temp']."</td></tr></table>\n"; |
| 121 |
} else { |
| 122 |
$out .="</td></tr></table>\n"; |
| 123 |
} |
| 124 |
|
| 125 |
$out .= "<div class=\"wp-forecast-curr-details\">"; |
| 126 |
// show realfeel |
| 127 |
if (substr($dispconfig,4,1) == "1") |
| 128 |
$out .= __('flik',"wp-forecast_".$wpf_language).": ".$w["realfeel"]."°".$w['un_temp']."<br />\n"; |
| 129 |
// show pressure |
| 130 |
if (substr($dispconfig,5,1) == "1") |
| 131 |
$out .= __('barr',"wp-forecast_".$wpf_language).": ".$w["pressure"]." ".$w["un_pres"]."<br />\n"; |
| 132 |
|
| 133 |
// show humiditiy |
| 134 |
if (substr($dispconfig,6,1) == "1") |
| 135 |
$out .= __('hmid',"wp-forecast_".$wpf_language).": ".$w["humidity"]."<br />\n"; |
| 136 |
|
| 137 |
// show wind |
| 138 |
if (substr($dispconfig,7,1) == "1") { |
| 139 |
$wstr=windstr($metric,$w["windspeed"],$windunit); |
| 140 |
$winddir=$w["winddirection"]; |
| 141 |
// for german language replace East with Ost or E with O |
| 142 |
if ($wpf_language=="de_DE") |
| 143 |
$winddir=str_replace("E","O",$winddir); |
| 144 |
|
| 145 |
$out .= __('winds',"wp-forecast_".$wpf_language).": ".$wstr." " . $winddir."<br />\n"; |
| 146 |
} |
| 147 |
|
| 148 |
// show windgusts |
| 149 |
if (substr($dispconfig,22,1) == "1") { |
| 150 |
$wstr=windstr($metric,$w["wgusts"],$windunit); |
| 151 |
$out .= __('Windgusts',"wp-forecast_".$wpf_language).": ".$wstr."<br />\n"; |
| 152 |
} |
| 153 |
|
| 154 |
|
| 155 |
$sunarr = explode(" ",$w["sun"]); |
| 156 |
|
| 157 |
// show sunrise |
| 158 |
if (substr($dispconfig,8,1) == "1") |
| 159 |
$out .= __('sunrise',"wp-forecast_".$wpf_language).": ".$sunarr[0]."<br />\n"; |
| 160 |
|
| 161 |
// show sunset |
| 162 |
if (substr($dispconfig,9,1) == "1") |
| 163 |
$out .= __('sunset',"wp-forecast_".$wpf_language).": ".$sunarr[1]."<br />\n"; |
| 164 |
|
| 165 |
// show copyright |
| 166 |
if (substr($dispconfig,21,1) == "1") |
| 167 |
$out .= "<div class=\"wp-forecast-copyright\"><a href=\"http://www.accuweather.com\">© 2007 AccuWeather, Inc.</a></div>"; |
| 168 |
|
| 169 |
$out .="</div></div>\n"; |
| 170 |
|
| 171 |
|
| 172 |
// ------------------ |
| 173 |
// |
| 174 |
// output forecast |
| 175 |
// |
| 176 |
// ------------------- |
| 177 |
$out1=""; |
| 178 |
for ($i = 1; $i < 10; $i++) { |
| 179 |
|
| 180 |
// check active forecast for day number i |
| 181 |
if (substr($daytime,$i-1,1)=="1" or substr($nighttime,$i-1,1) =="1") { |
| 182 |
$out1 .="\n<div class=\"wp-forecast-fc\">\n"; |
| 183 |
$out1 .= __("Forecast","wp-forecast_".$wpf_language)." "; |
| 184 |
$out1 .= date_i18n($fc_date_format, strtotime($w['fc_obsdate_'.$i]))."<br />"; |
| 185 |
} |
| 186 |
|
| 187 |
// check for daytime information |
| 188 |
if (substr($daytime,$i-1,1)=="1" ) { |
| 189 |
$out1 .="<table class=\"wp-forecast-fc\" cellpadding='3' cellspacing='2'>\n"; |
| 190 |
$out1 .= "<tr><td valign='top' align='center'>".__('day',"wp-forecast_".$wpf_language)."<br />"; |
| 191 |
|
| 192 |
// show icon |
| 193 |
if (substr($dispconfig,10,1) == "1") { |
| 194 |
$out1 .= "<img src='".$plugin_path."/icons/".$w["fc_dt_icon_".$i].".gif' width='48' alt='".__($w["fc_dt_icon_".$i],"wp-forecast_".$wpf_language)."' />"; |
| 195 |
} else { |
| 196 |
$out1 .= " "; |
| 197 |
} |
| 198 |
$out1 .= "</td><td>\n"; |
| 199 |
|
| 200 |
// show short description |
| 201 |
if (substr($dispconfig,11,1) == "1") |
| 202 |
$out1 .= __($w["fc_dt_icon_".$i],"wp-forecast_".$wpf_language)."<br />"; |
| 203 |
|
| 204 |
// show temperature |
| 205 |
if (substr($dispconfig,12,1) == "1") |
| 206 |
$out1 .= $w["fc_dt_htemp_".$i]."°".$w['un_temp']."<br />"; |
| 207 |
|
| 208 |
|
| 209 |
// show wind |
| 210 |
if (substr($dispconfig,13,1) == "1") { |
| 211 |
$wstr=windstr($metric,$w["fc_dt_windspeed_".$i],$windunit); |
| 212 |
$winddir=$w["fc_dt_winddir_".$i]; |
| 213 |
// for german language replace East with Ost or E with O |
| 214 |
if ($wpf_language=="de_DE") |
| 215 |
$winddir=str_replace("E","O",$winddir); |
| 216 |
|
| 217 |
$out1 .= __('winds',"wp-forecast_".$wpf_language).": ".$wstr." " . $winddir."<br />\n"; |
| 218 |
} |
| 219 |
|
| 220 |
// show windgusts |
| 221 |
if (substr($dispconfig,23,1) == "1") { |
| 222 |
$wstr=windstr($metric,$w["fc_dt_wgusts_".$i],$windunit); |
| 223 |
$out1 .= __('Windgusts',"wp-forecast_".$wpf_language).": ".$wstr."\n"; |
| 224 |
} |
| 225 |
|
| 226 |
$out1 .= "</td></tr></table>\n"; |
| 227 |
} |
| 228 |
|
| 229 |
// open div class for css if applicable |
| 230 |
if (substr($daytime,$i-1,1)=="1" or substr($nighttime,$i-1,1) =="1") |
| 231 |
$out1.="<div class=\"wp-forecast-fc-details\">"; |
| 232 |
|
| 233 |
// check for nighttime information |
| 234 |
if (substr($nighttime,$i-1,1)=="1" ) { |
| 235 |
$out1 .="<table class=\"wp-forecast-fc\" cellpadding='3' cellspacing='2'>\n"; |
| 236 |
$out1 .= "<tr><td valign='top' align='center'>".__('night',"wp-forecast_".$wpf_language)."<br />"; |
| 237 |
if (substr($dispconfig,14,1) == "1") { |
| 238 |
$out1 .= "<img src='".$plugin_path."/icons/".$w["fc_nt_icon_".$i].".gif' width='48' alt='".__($w["fc_nt_icon_".$i],"wp-forecast_".$wpf_language)."' />"; |
| 239 |
} else { |
| 240 |
$out1 .= " "; |
| 241 |
} |
| 242 |
$out1 .= "</td><td>\n"; |
| 243 |
|
| 244 |
// show short description |
| 245 |
if (substr($dispconfig,15,1) == "1") |
| 246 |
$out1 .= __($w["fc_nt_icon_".$i],"wp-forecast_".$wpf_language)."<br />"; |
| 247 |
|
| 248 |
// show temperature |
| 249 |
if (substr($dispconfig,16,1) == "1") { |
| 250 |
$out1 .= $w["fc_nt_ltemp_".$i]."°".$w['un_temp']."<br />"; |
| 251 |
} |
| 252 |
|
| 253 |
// show wind |
| 254 |
if (substr($dispconfig,17,1) == "1") { |
| 255 |
$wstr=windstr($metric,$w["fc_nt_windspeed_".$i],$windunit); |
| 256 |
$winddir=$w["fc_nt_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,24,1) == "1") { |
| 266 |
$wstr=windstr($metric,$w["fc_nt_wgusts_".$i],$windunit); |
| 267 |
$out1 .= __('Windgusts',"wp-forecast_".$wpf_language).": ".$wstr."\n"; |
| 268 |
} |
| 269 |
|
| 270 |
$out1 .= "</td></tr></table>\n"; |
| 271 |
} |
| 272 |
// close div block |
| 273 |
if (substr($daytime,$i-1,1)=="1" or substr($nighttime,$i-1,1) =="1") |
| 274 |
$out1 .="</div></div>\n"; |
| 275 |
} |
| 276 |
|
| 277 |
|
| 278 |
// print it |
| 279 |
if ( $show_from_widget == 1 ) |
| 280 |
echo $before_widget . $before_title . $title . $after_title; |
| 281 |
|
| 282 |
echo "<div class=\"wp-forecast\">" . $out . $out1 . "</div><br />";; |
| 283 |
|
| 284 |
if ( $show_from_widget == 1 ) |
| 285 |
echo $after_widget; |
| 286 |
|
| 287 |
if ($wpf_debug > 0) |
| 288 |
pdebug("End of show ()"); |
| 289 |
|
| 290 |
} |
| 291 |
?> |