Changeset 331563
- Timestamp:
- 01/12/2011 03:34:07 AM (15 years ago)
- Location:
- wunderground/branches/wordpress-weather
- Files:
-
- 14 added
- 4 edited
- 1 moved
-
icons/humanity (moved) (moved from wunderground/branches/wordpress-weather/icons/Humanity)
-
icons/humanity/clear.png (added)
-
icons/humanity/cold.png (added)
-
icons/humanity/fog.png (added)
-
icons/humanity/hazy.png (added)
-
icons/humanity/hot.png (added)
-
icons/humanity/nclear.png (added)
-
icons/humanity/ncloudy.png (added)
-
icons/humanity/nhazy.png (added)
-
icons/humanity/npartcloud.png (added)
-
icons/humanity/nrain.png (added)
-
icons/humanity/nsnow.png (added)
-
icons/humanity/unknown.png (added)
-
icons/humanity/warning.png (added)
-
icons/humanity/windy.png (added)
-
wordpress-weather.php (modified) (5 diffs)
-
wpw-backaccuweather.inc (modified) (4 diffs)
-
wpw-backbase.inc (modified) (10 diffs)
-
wpw-weatherdata.inc (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
-
wunderground/branches/wordpress-weather/wordpress-weather.php
r331384 r331563 1 1 <?php 2 2 /* 3 Plugin Name: W ordpress Weather3 Plugin Name: WP Wunderground 4 4 Plugin URI: http://www.seodenver.com/wunderground/ 5 5 Description: Get accurate and beautiful weather forecasts powered by Wunderground.com for your content or your sidebar. 6 Version: 0.26 Version: 2.0 7 7 Author: 8 8 Author URI: … … 10 10 require_once("wpw-weatherdata.inc"); 11 11 define('WPW_CACHETIME', 5); 12 add_action('wp_head', 'wp_forecast_css'); 12 13 14 15 /** 16 * \class wordpressWeather 17 * \brief Wordpress plugin to display the weather 18 * 19 * This class extends the normal Wordpress Widget class into a weather widget. 20 * It can also be called using the shortcode [forecast], Here is the current 21 * list of supported parameters: source, location, measurement, caption, 22 * numdays, linkdays, datelabel, todaylabel, cache, class, highlow, iconset. 23 */ 13 24 class wordpressWeather extends WP_Widget { 14 function wordpressWeather() { 15 parent::WP_Widget(false, $name = 'GcalSidebar'); 16 add_shortcode('wordpress-weather', array(&$this, 'shortcode')); 25 function __construct() { 26 parent::WP_Widget(false, $name = 'WP_Widget'); 27 add_shortcode('forecast', array(&$this, 'shortcode')); 28 //add_action('wp_head', array(&$this, 'css')); 29 } 30 31 function do_css($wpw_obj) { 32 /** 33 * \todo CSS should be moved into a plugin configuration option with %% codes to replace certain items. 34 */ 35 $widthp = floor((100 - ($wpw_obj->getDays() * 2)) / $wpw_obj->getDays()); 36 list($width, $height) = getimagesize($wpw_obj->getIconPath() . "/clear.png"); 37 return " 38 .wpw-horitz { 39 display:inline-block; 40 vertical-align:top; 41 align:center; 42 margin: 0 1%; 43 min-width: " . $width . "px; 44 /*width: " . $widthp . "%;*/ 45 } 46 47 .wpw-vert { 48 display:block; 49 } 50 "; 51 } 52 53 function css($wpw_obj) { 54 $output = "<style type='text/css'>"; 55 $output .= $this->do_css($wpw_obj); 56 $output .= "</style>"; 57 return $output; 17 58 } 18 59 … … 21 62 'source' => "base" 22 63 , 'location' => "46534" 23 , ' displaytemp' => "fahrenheit"64 , 'measurement' => "F" 24 65 , 'caption' => "Knox, Indiana" 25 66 , 'numdays' => 5 67 , 'linkdays' => "true" 26 68 , 'datelabel' => "%%weekday%%" 27 69 , 'todaylabel' => "Today" … … 53 95 } 54 96 $wpw_obj->setLocation(esc_html($settings['location'])); 55 switch(strtolower($settings[' displaytemp'])) {56 case "c elsius":97 switch(strtolower($settings['measurement'])) { 98 case "c": 57 99 $wpw_obj->setTScale($GLOBALS['TSCALE']->CELSIUS); 100 $wpw_obj->setMScale($GLOBALS['MSCALE']->METRIC); 58 101 break; 59 102 default: 60 103 $wpw_obj->setTScale($GLOBALS['TSCALE']->FAHRENHEIT); 104 $wpw_obj->setMScale($GLOBALS['MSCALE']->ENGLISH); 61 105 break; 62 106 } 63 107 $wpw_obj->setCaption(esc_html($settings['caption'])); 64 108 $wpw_obj->setDays(absint($settings['numdays'])); 109 switch(strtolower($settings['linkdays'])) { 110 case "false": 111 case "off": 112 $wpw_obj->setDaysLink(false); 113 break; 114 default: 115 $wpw_obj->setDaysLink(true); 116 break; 117 } 118 $wpw_obj->setClass(absint($settings['class'])); 65 119 switch(strtolower($settings['cache'])) { 66 120 case "true": … … 81 135 82 136 $wpw_obj->getFeed(); 83 return $wpw_obj->displayFeed(); 137 $output = $this->css($wpw_obj); 138 $output .= $wpw_obj->displayFeed(); 139 return $output; 84 140 } 85 141 } -
wunderground/branches/wordpress-weather/wpw-backaccuweather.inc
r331384 r331563 6 6 function __construct() { 7 7 parent::__construct(); 8 // URL to the data feed 8 9 $this->furl = 'http://forecastfox.accuweather.com/adcbin/forecastfox/weather_data.asp?metric=1&location='; 10 // URL to the forecast for a given day 11 $this->fcurl = "http://www.accuweather.com/us/in/knox/46534/forecast-details.asp?fday="; 9 12 } 13 /* 14 * Translates AccuWeather Condition code to the internal code 15 */ 10 16 function awCond($icon) { 11 17 switch($icon) { 12 18 case 1: 13 19 case 2: 14 $condition = $GLOBALS['CONDITION']-> SUNNY;20 $condition = $GLOBALS['CONDITION']->CLEAR; 15 21 break; 16 22 case 3: 17 23 case 4: 18 24 $condition = $GLOBALS['CONDITION']->PARTCLOUD; 25 break; 26 case 5: 27 $condition = $GLOBALS['CONDITION']->HAZY; 19 28 break; 20 29 case 6: … … 23 32 $condition = $GLOBALS['CONDITION']->CLOUDY; 24 33 break; 34 case 11: 35 $condition = $GLOBALS['CONDITION']->FOG; 36 break; 37 case 12: 38 case 13: 39 case 14: 40 case 15: 41 case 16: 42 case 17: 43 case 18: 44 $condition = $GLOBALS['CONDITION']->RAIN; 45 break; 25 46 case 19: 26 47 case 20: … … 28 49 case 22: 29 50 case 23: 51 case 24: 52 case 25: 53 case 26: 30 54 case 29: 31 55 $condition = $GLOBALS['CONDITION']->SNOW; 32 56 break; 57 case 30: 58 $condition = $GLOBALS['CONDITION']->HOT; 59 break; 60 case 31: 61 $condition = $GLOBALS['CONDITION']->COLD; 62 break; 63 case 32: 64 $condition = $GLOBALS['CONDITION']->WINDY; 65 break; 66 case 33: 67 case 34: 68 $condition = $GLOBALS['CONDITION']->NCLEAR; 69 break; 70 case 35: 71 $condition = $GLOBALS['CONDITION']->NPARTCLOUD; 72 break; 73 case 36: 74 case 38: 75 $condition = $GLOBALS['CONDITION']->NCLOUDY; 76 break; 77 case 37: 78 $condition = $GLOBALS['CONDITION']->NHAZY; 79 break; 80 case 39: 81 case 40: 82 case 41: 83 case 42: 84 $condition = $GLOBALS['CONDITION']->NRAIN; 85 break; 86 case 43: 87 case 44: 88 $condition = $GLOBALS['CONDITION']->NSNOW; 89 break; 33 90 default: 34 $condition = $GLOBALS['CONDITION']-> SUNNY;91 $condition = $GLOBALS['CONDITION']->UNKNOWN; 35 92 break; 36 93 } … … 60 117 $wind = (int)$data->daytime->windspeed; 61 118 $condition = $this->awCond($data->daytime->weathericon); 62 $this->weather[] = new wpw_weatherData($high, $condition, $date, $low, $wind); 119 switch($condition) { 120 case $GLOBALS['CONDITION']->SNOW: 121 case $GLOBALS['CONDITION']->NSNOW: 122 $precip = $data->daytime->snowamount + $data->nighttime->snowamount; 123 break; 124 case $GLOBALS['CONDITION']->RAIN: 125 case $GLOBALS['CONDITION']->NRAIN: 126 $precip = $data->daytime->rainamount + $data->nighttime->rainamount; 127 break; 128 default: 129 $precip = 0; 130 break; 131 } 132 $newData = new wpw_weatherData($high, $condition, $date, $low, $wind); 133 $newData->setPrecip($precip); 134 $this->weather[] = $newData; 63 135 } 64 136 $i++; 65 137 } 66 138 } 139 function getForecastLink($day) { 140 $opts = ''; 141 if($this->getMScale() == $GLOBALS['MSCALE']->METRIC) 142 $opts .= "&metric=1"; 143 else if($this->getMScale() == $GLOBALS['MSCALE']->ENGLISH) 144 $opts .= "&metric=0"; 145 return($this->fcurl . $day . $opts); 146 } 67 147 } -
wunderground/branches/wordpress-weather/wpw-backbase.inc
r331384 r331563 83 83 protected $caption = ''; 84 84 protected $numdays = ''; 85 protected $dayslink = ''; 85 86 protected $datelabel = ''; 86 87 protected $todaylabel = ''; … … 109 110 $this->highlow = '%%high%%°/%%low%%°'; 110 111 $this->caption = 'Knox, Indiana'; 111 $this->numdays = 5; 112 $this->setDays(5); 113 $this->setDaysLink(true); 112 114 $this->setDateLabel('%%weekday%%'); 113 115 $this->setTodayLabel('Today'); 116 $this->setClass('wordpress_weather'); 114 117 $this->showlink = ''; 115 118 $this->cache = true; 116 119 $this->width = '100%'; 117 $this->icon_url = sprintf("%s/plugins/%sicons" , WP_CONTENT_URL , str_replace(basename( __FILE__),"",plugin_basename(__FILE__))); 120 $this->icon_url = sprintf("%s/plugins/%sicons" , WP_CONTENT_URL , str_replace(basename( __FILE__),"",plugin_basename(__FILE__))); 121 $this->icon_path = sprintf("%s/plugins/%sicons" , WP_CONTENT_DIR , str_replace(basename( __FILE__),"",plugin_basename(__FILE__))); 118 122 $this->weather = Array(); 119 123 … … 161 165 return $this->icons; 162 166 } 167 function getIconPath() { 168 if(in_array($this->icons, $this->icon_sets)) 169 return $this->icon_path . "/" . $this->icons; 170 else 171 return $this->icon_path . "/Humanity"; 172 } 163 173 function getIconUrl() { 164 174 if(in_array($this->icons, $this->icon_sets)) … … 195 205 $this->weather = Array(); 196 206 foreach($cacheData->data as $data) { 197 198 $this->weather[] = new wpw_weatherData($data->high, $data->condition, $data->date, $data->low, $data->windspeed); 207 $newData = new wpw_weatherData($data->high, $data->condition, $data->date, $data->low, $data->windspeed); 208 $newData->setPrecip($data->precip); 209 $this->weather[] = $newData; 199 210 } 200 211 return false; … … 209 220 $fp = fopen($fname, 'w'); 210 221 $cacheData = Array('serial' => time(), 'data' => $this->weather); 211 print_r($cacheData);212 222 fwrite($fp, json_encode($cacheData)); 213 223 fclose($fp); … … 216 226 if($this->displayDir == $GLOBALS['ORIENT']->VERT) { 217 227 $css="display:block;"; 228 $class = "wpw-vert"; 218 229 } 219 230 else { 220 231 $css="display:inline-block;"; 221 } 222 $output = "<div class='wordpress_weather'><h2>" . $this->getCaption() . "</h2><ul class='forecast'>"; 232 $class = "wpw-horitz"; 233 } 234 $output = "<div class='" . $this->getClass() . "'><h2>" . $this->getCaption() . "</h2><ul class='forecast'>"; 235 $dayCount = 1; 223 236 foreach($this->weather as $data) { 237 if($this->getDaysLink()) { 238 $linkStart = "<a target='_blank' href='" . $this->getForecastLink($dayCount) . "'>"; 239 $linkEnd = "</a>"; 240 } 224 241 if(date('Ymd') == date('Ymd', $data->getDate())) { 225 242 $label = $this->getTodayLabel(); … … 231 248 $temp = str_replace('%%low%%', $data->getLow($this->getTScale()), $temp); 232 249 233 $output .= "<li style='" . $css . "'>" 234 . "<h3>" . $label ."</h3>" 235 . "<div class='img'><img src='" . $this->getIconUrl() . '/' . $data->getConditionSlug() . ".png'></div>" 236 . "<div class='text'>" . $data->getConditionText() . "</div>" 250 $output .= "<li class='" . $class . "'>" 251 . $linkStart 252 . "<h4>" . $label ."</h4>" 253 . "<div class='img'>" . "<img src='" . $this->getIconUrl() . '/' . $data->getConditionSlug() . ".png'></div>" 254 . "<div class='text'>" . $data->getPrecip($this->getMScale()) . " " . $data->getConditionText() . "</div>" 237 255 . "<div class='temp'>" . $temp . "</div>" 256 . $linkEnd 238 257 . "</li>"; 258 $dayCount++; 239 259 } 240 260 $output .= "</div>"; 241 261 return $output; 262 } 263 function getForecastLink($day) { 264 return(""); 242 265 } 243 266 function getTodayLabel() { … … 269 292 return $this->displayTemp; 270 293 } 294 function getMScale() { 295 return $this->displayMeas; 296 } 297 function setMScale($mscale) { 298 $this->displayMeas = $mscale; 299 return $this->displayMeas; 300 } 271 301 function getTimezone() { 272 302 return($this->timezone); … … 290 320 return($this->numdays); 291 321 } 322 function getDaysLink() { 323 return($this->dayslink); 324 } 325 function setDaysLink($dayslink) { 326 $this->dayslink = $dayslink; 327 return($this->dayslink); 328 } 292 329 function getCache() { 293 330 return($this->cache); … … 304 341 return($this->caption); 305 342 } 343 function getClass() { 344 return($this->class); 345 } 346 function setClass($class) { 347 $this->class = $class; 348 return($this->class); 349 } 306 350 } -
wunderground/branches/wordpress-weather/wpw-weatherdata.inc
r331384 r331563 5 5 $GLOBALS['ORIENT'] = new Enum('VERT', 'HORIZ'); // Orientation (vertical / horitzontal 6 6 $GLOBALS['ALIGN'] = new Enum('LEFT', 'RIGHT', 'CENTER'); // Alignment (left / right / center) 7 $GLOBALS['CONDITION'] = new Enum('SUNNY', 'PARTCLOUD', 'CLOUDY', 'SNOW', 'RAIN'); 7 $GLOBALS['CONDITION'] = new Enum( 'CLEAR', 'PARTCLOUD', 'CLOUDY', 'SNOW', 'RAIN', 'HAZY' 8 , 'NCLEAR', 'NPARTCLOUD', 'NCLOUDY', 'NSNOW', 'NRAIN', 'NHAZY' 9 , 'FOG', 'HOT', 'COLD', 'WINDY' , 'WARNING', 'UNKNOWN' 10 ); 8 11 $GLOBALS['CONDDATA'] = new DefinedEnum(Array( 9 $GLOBALS['CONDITION']-> SUNNY => Array('slug' =>'sunny', 'text' => 'Sunny')12 $GLOBALS['CONDITION']->CLEAR => Array('slug' =>'clear', 'text' => 'Clear') 10 13 , $GLOBALS['CONDITION']->PARTCLOUD => Array('slug' =>'partcloud', 'text' => 'Partly Cloudy') 11 14 , $GLOBALS['CONDITION']->CLOUDY => Array('slug' =>'cloudy', 'text' => 'Cloudy') 12 15 , $GLOBALS['CONDITION']->SNOW => Array('slug' =>'snow', 'text' => 'Snow') 13 16 , $GLOBALS['CONDITION']->RAIN => Array('slug' =>'rain', 'text' => 'Rain') 17 , $GLOBALS['CONDITION']->HAZY => Array('slug' =>'hazy', 'text' => 'Hazy') 18 , $GLOBALS['CONDITION']->NCLEAR => Array('slug' =>'nclear', 'text' => 'Clear') 19 , $GLOBALS['CONDITION']->NPARTCLOUD=> Array('slug' =>'npartcloud','text' => 'Partly Cloudy') 20 , $GLOBALS['CONDITION']->NCLOUDY => Array('slug' =>'ncloudy', 'text' => 'Clear') 21 , $GLOBALS['CONDITION']->NSNOW => Array('slug' =>'nsnow', 'text' => 'Snow') 22 , $GLOBALS['CONDITION']->NRAIN => Array('slug' =>'nrain', 'text' => 'Rain') 23 , $GLOBALS['CONDITION']->NHAZY => Array('slug' =>'nhazy', 'text' => 'Hazy') 24 , $GLOBALS['CONDITION']->FOG => Array('slug' =>'fog', 'text' => 'Fog') 25 , $GLOBALS['CONDITION']->HOT => Array('slug' =>'hot', 'text' => 'Hot') 26 , $GLOBALS['CONDITION']->COLD => Array('slug' =>'cold', 'text' => 'Cold') 27 , $GLOBALS['CONDITION']->WINDY => Array('slug' =>'windy', 'text' => 'Windy') 28 , $GLOBALS['CONDITION']->WARNING => Array('slug' =>'warning', 'text' => 'Warning') 29 , $GLOBALS['CONDITION']->UNKNOWN => Array('slug' =>'unknown', 'text' => 'Unknown') 14 30 )); 15 31 … … 21 37 $this->setCondition($condition); 22 38 $this->setDate($date); 39 $this->setPrecip(0); 23 40 } 24 41 function setHigh($high) { … … 55 72 return ceil($rval); 56 73 } 74 function setSnow($snow) { 75 $this->snow = $snow; 76 return $this->snow; 77 } 78 function getSnow($displayFormat) { 79 return $this->snow; 80 } 81 function displaySnow($displayFormat) { 82 global $MSCALE; 83 if($this->snow < 1) { 84 return ''; 85 } 86 switch($displayFormat) { 87 case $GLOBALS['MSCALE']->ENGLISH: 88 $rval = sprintf("%d in", ceil($this->snow / 2.54)); 89 break; 90 default: 91 $rval = sprintf("%d cm", round($this->snow)); 92 break; 93 } 94 95 return $rval; 96 } 97 function setPrecip($precip) { 98 $this->precip = $precip; 99 return $this->precip; 100 } 101 function getPrecip($displayFormat) { 102 global $MSCALE; 103 if($this->precip < 1) { 104 return ''; 105 } 106 switch($displayFormat) { 107 case $GLOBALS['MSCALE']->ENGLISH: 108 $rval = sprintf("%d\"", round($this->precip / 2.54)); 109 break; 110 default: 111 $rval = sprintf("%dcm", round($this->precip)); 112 break; 113 } 114 115 return $rval; 116 } 57 117 function setWindspeed($windspeed) { 58 118 $this->windspeed = $windspeed;
Note: See TracChangeset
for help on using the changeset viewer.