Plugin Directory

Changeset 331563


Ignore:
Timestamp:
01/12/2011 03:34:07 AM (15 years ago)
Author:
rjune
Message:

Update to 0.4

Location:
wunderground/branches/wordpress-weather
Files:
14 added
4 edited
1 moved

Legend:

Unmodified
Added
Removed
  • wunderground/branches/wordpress-weather/wordpress-weather.php

    r331384 r331563  
    11<?php
    22/*
    3 Plugin Name: Wordpress Weather
     3Plugin Name: WP Wunderground
    44Plugin URI: http://www.seodenver.com/wunderground/
    55Description: Get accurate and beautiful weather forecasts powered by Wunderground.com for your content or your sidebar.
    6 Version: 0.2
     6Version: 2.0
    77Author:
    88Author URI:
     
    1010require_once("wpw-weatherdata.inc");
    1111define('WPW_CACHETIME', 5);
     12add_action('wp_head', 'wp_forecast_css');
    1213
     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 */
    1324class 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;
    1758    }
    1859
     
    2162                    'source'      =>  "base"
    2263                  , 'location'    =>  "46534"
    23                   , 'displaytemp' =>  "fahrenheit"
     64                  , 'measurement' =>  "F"
    2465                  , 'caption'     =>  "Knox, Indiana"
    2566                  , 'numdays'     =>  5
     67                  , 'linkdays'    =>  "true"
    2668                  , 'datelabel'   =>  "%%weekday%%"
    2769                  , 'todaylabel'  =>  "Today"
     
    5395        }
    5496        $wpw_obj->setLocation(esc_html($settings['location']));
    55         switch(strtolower($settings['displaytemp'])) {
    56             case "celsius":
     97        switch(strtolower($settings['measurement'])) {
     98            case "c":
    5799                $wpw_obj->setTScale($GLOBALS['TSCALE']->CELSIUS);
     100                $wpw_obj->setMScale($GLOBALS['MSCALE']->METRIC);
    58101                break;
    59102            default:
    60103                $wpw_obj->setTScale($GLOBALS['TSCALE']->FAHRENHEIT);
     104                $wpw_obj->setMScale($GLOBALS['MSCALE']->ENGLISH);
    61105                break;
    62106        }
    63107        $wpw_obj->setCaption(esc_html($settings['caption']));
    64108        $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']));
    65119        switch(strtolower($settings['cache'])) {
    66120            case "true":
     
    81135
    82136        $wpw_obj->getFeed();
    83         return $wpw_obj->displayFeed();
     137        $output = $this->css($wpw_obj);
     138        $output .= $wpw_obj->displayFeed();
     139        return $output;
    84140    }
    85141}
  • wunderground/branches/wordpress-weather/wpw-backaccuweather.inc

    r331384 r331563  
    66    function __construct() {
    77        parent::__construct();
     8        // URL to the data feed
    89        $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=";
    912    }
     13    /*
     14     * Translates AccuWeather Condition code to the internal code
     15     */
    1016    function awCond($icon) {
    1117        switch($icon) {
    1218            case 1:
    1319            case 2:
    14                 $condition = $GLOBALS['CONDITION']->SUNNY;
     20                $condition = $GLOBALS['CONDITION']->CLEAR;
    1521                break;
    1622            case 3:
    1723            case 4:
    1824                $condition = $GLOBALS['CONDITION']->PARTCLOUD;
     25                break;
     26            case 5:
     27                $condition = $GLOBALS['CONDITION']->HAZY;
    1928                break;
    2029            case 6:
     
    2332                $condition = $GLOBALS['CONDITION']->CLOUDY;
    2433                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;
    2546            case 19:
    2647            case 20:
     
    2849            case 22:
    2950            case 23:
     51            case 24:
     52            case 25:
     53            case 26:
    3054            case 29:
    3155                $condition = $GLOBALS['CONDITION']->SNOW;
    3256                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;
    3390            default:
    34                 $condition = $GLOBALS['CONDITION']->SUNNY;
     91                $condition = $GLOBALS['CONDITION']->UNKNOWN;
    3592                break;
    3693        }
     
    60117                $wind = (int)$data->daytime->windspeed;
    61118                $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;
    63135            }
    64136            $i++;
    65137        }
    66138    }
     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    }
    67147}
  • wunderground/branches/wordpress-weather/wpw-backbase.inc

    r331384 r331563  
    8383    protected $caption     = '';
    8484    protected $numdays     = '';
     85    protected $dayslink     = '';
    8586    protected $datelabel   = '';
    8687    protected $todaylabel  = '';
     
    109110        $this->highlow = '%%high%%&deg;/%%low%%&deg;';
    110111        $this->caption = 'Knox, Indiana';
    111         $this->numdays = 5;
     112        $this->setDays(5);
     113        $this->setDaysLink(true);
    112114        $this->setDateLabel('%%weekday%%');
    113115        $this->setTodayLabel('Today');
     116        $this->setClass('wordpress_weather');
    114117        $this->showlink = '';
    115118        $this->cache = true;
    116119        $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__)));
    118122        $this->weather = Array();
    119123       
     
    161165        return $this->icons;
    162166    }
     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    }
    163173    function getIconUrl() {
    164174        if(in_array($this->icons, $this->icon_sets))
     
    195205        $this->weather = Array();
    196206        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;
    199210        }
    200211        return false;
     
    209220        $fp = fopen($fname, 'w');
    210221        $cacheData = Array('serial' => time(), 'data' => $this->weather);
    211 print_r($cacheData);
    212222        fwrite($fp, json_encode($cacheData));
    213223        fclose($fp);
     
    216226        if($this->displayDir == $GLOBALS['ORIENT']->VERT) {
    217227            $css="display:block;";
     228            $class = "wpw-vert";
    218229        }
    219230        else {
    220231            $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;
    223236        foreach($this->weather as $data) {
     237            if($this->getDaysLink()) {
     238                $linkStart = "<a target='_blank' href='" . $this->getForecastLink($dayCount) . "'>";
     239                $linkEnd = "</a>";
     240            }
    224241            if(date('Ymd') == date('Ymd', $data->getDate())) {
    225242                $label = $this->getTodayLabel();
     
    231248            $temp = str_replace('%%low%%', $data->getLow($this->getTScale()), $temp);               
    232249
    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>"
    237255                    .  "<div class='temp'>" . $temp . "</div>"
     256                    .  $linkEnd
    238257                    .  "</li>";
     258            $dayCount++;
    239259        }
    240260        $output .= "</div>";
    241261        return $output;
     262    }
     263    function getForecastLink($day) {
     264        return("");
    242265    }
    243266    function getTodayLabel() {
     
    269292        return $this->displayTemp;
    270293    }
     294    function getMScale() {
     295        return $this->displayMeas;
     296    }
     297    function setMScale($mscale) {
     298        $this->displayMeas = $mscale;
     299        return $this->displayMeas;
     300    }
    271301    function getTimezone() {
    272302        return($this->timezone);
     
    290320        return($this->numdays);
    291321    }
     322    function getDaysLink() {
     323        return($this->dayslink);
     324    }
     325    function setDaysLink($dayslink) {
     326        $this->dayslink = $dayslink;
     327        return($this->dayslink);
     328    }
    292329    function getCache() {
    293330        return($this->cache);
     
    304341        return($this->caption);
    305342    }
     343    function getClass() {
     344        return($this->class);
     345    }
     346    function setClass($class) {
     347        $this->class = $class;
     348        return($this->class);
     349    }
    306350}
  • wunderground/branches/wordpress-weather/wpw-weatherdata.inc

    r331384 r331563  
    55$GLOBALS['ORIENT'] = new Enum('VERT', 'HORIZ');           // Orientation (vertical / horitzontal
    66$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                                 );
    811$GLOBALS['CONDDATA'] = new DefinedEnum(Array(
    9      $GLOBALS['CONDITION']->SUNNY     => Array('slug' =>'sunny',     'text' => 'Sunny')
     12     $GLOBALS['CONDITION']->CLEAR     => Array('slug' =>'clear',     'text' => 'Clear')
    1013   , $GLOBALS['CONDITION']->PARTCLOUD => Array('slug' =>'partcloud', 'text' => 'Partly Cloudy')
    1114   , $GLOBALS['CONDITION']->CLOUDY    => Array('slug' =>'cloudy',    'text' => 'Cloudy')
    1215   , $GLOBALS['CONDITION']->SNOW      => Array('slug' =>'snow',      'text' => 'Snow')
    1316   , $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')
    1430));
    1531
     
    2137        $this->setCondition($condition);
    2238        $this->setDate($date);
     39        $this->setPrecip(0);
    2340    }
    2441    function setHigh($high) {
     
    5572        return ceil($rval);
    5673    }
     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    }
    57117    function setWindspeed($windspeed) {
    58118        $this->windspeed = $windspeed;
Note: See TracChangeset for help on using the changeset viewer.