Plugin Directory

Changeset 527059


Ignore:
Timestamp:
04/04/2012 04:23:29 AM (14 years ago)
Author:
rxn
Message:

refactored to use date_sun_info()

Location:
sunrise-sunset/trunk
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • sunrise-sunset/trunk/cities.txt

    r525899 r527059  
    1 Arizona:33.29:-122.04
    2 Atlanta:33.65:-84.42
    3 Charlotte,NC:35.22:-80.93
    4 Chicago:41.51:-87.39
    5 Crossville,TN:35.95:-85.08
    6 Los Angeles:34.30:-118.15
    7 Lexington, KY:38.05:-85.00
    8 Miami:25.82:-80.28
    9 Nashville,TN:36.12:-86.68
    10 Orlando,FL:28.55:-81.33
    11 Richmond,VA:37.50:-77.33
    12 Roanoke Muni,VA:37.32:-79.97
     1city:latitude:longitude:timezone:summertimezone
     2Tucson, AZ:33.29:-122.04:MST:none
     3Atlanta, GA:33.65:-84.42:EST:EDT
     4Charlotte,NC:35.22:-80.93:EST:EDT
     5Chicago, IL:41.51:-87.39:CST:CDT
     6Crossville,TN:35.95:-85.08:CST:CDT
     7Los Angeles, CA:34.30:-118.15:PST:PDT
     8Lexington, KY:38.05:-85.00:EST:EDT
     9Miami, FL:25.82:-80.28:EST:EDT
     10Nashville,TN:36.12:-86.68:CST:CDT
     11Orlando,FL:28.55:-81.33:EST:EDT
     12Richmond,VA:37.50:-77.33:EST:EDT
     13Roanoke Muni,VA:37.32:-79.97:EST:EDT
  • sunrise-sunset/trunk/city.php

    r525899 r527059  
    33class City
    44{
     5    private $_name;
     6    private $_latitude;
     7    private $_longitude;
     8    private $_timezone;
     9    private $_summerTimezone;
    510
    6     private $name;
    7     private $latitude;
    8     private $longitude;
    9 
    10     function __construct($name, $latitude, $longitude)
     11    function __construct($name, $latitude, $longitude, $timezone, $summerTimezone)
    1112    {
    12         $this->name = $name;
    13         $this->latitude = $latitude;
    14         $this->longitude = $longitude;
     13        $this->_name = $name;
     14        $this->_latitude = $latitude;
     15        $this->_longitude = $longitude;
     16        $this->_timezone = $timezone;
     17        $this->_summerTimezone = $summerTimezone;
    1518    }
    1619
    1720
     21    public function setSummerTimezone($summerTimezone)
     22    {
     23        $this->_summerTimezone = $summerTimezone;
     24    }
     25
     26    public function getSummerTimezone()
     27    {
     28        return $this->_summerTimezone;
     29    }
     30
     31    public function setTimezone($timezone)
     32    {
     33        $this->_timezone = $timezone;
     34    }
     35
     36    public function getTimezone()
     37    {
     38        return $this->_timezone;
     39    }
     40
    1841    public function setLatitude($latitude)
    1942    {
    20         $this->latitude = $latitude;
     43        $this->_latitude = $latitude;
    2144    }
    2245
    2346    public function getLatitude()
    2447    {
    25         return $this->latitude;
     48        return $this->_latitude;
    2649    }
    2750
    2851    public function setLongitude($longitude)
    2952    {
    30         $this->longitude = $longitude;
     53        $this->_longitude = $longitude;
    3154    }
    3255
    3356    public function getLongitude()
    3457    {
    35         return $this->longitude;
     58        return $this->_longitude;
    3659    }
    3760
    3861    public function setName($name)
    3962    {
    40         $this->name = $name;
     63        $this->_name = $name;
    4164    }
    4265
    4366    public function getName()
    4467    {
    45         return $this->name;
     68        return $this->_name;
    4669    }
    4770}
  • sunrise-sunset/trunk/functions.php

    r519692 r527059  
    22
    33
    4 
    5 function populateLatitude()
    6 {
    7     //    $latitude = array('America/Chicago' => 41.51, 'America/Los_Angeles' => 34.30, 'America/New_York' => 40.47, 'US/Arizona' => 33.29);
    8 
    9     $latitude = array();
    10 
    11     global $CITIES;
    12     foreach ($CITIES as $city) {
    13         $latitude[$city->getTimezone] = $city->getLatitude();
    14     }
    15     return $latitude;
    16 
    17 }
    18 
  • sunrise-sunset/trunk/readme.txt

    r525899 r527059  
    44Requires at least: 3.0
    55Tested up to: 3.3.1
    6 Stable tag: 1.0.8
     6Stable tag: 1.0.9
    77License: GPLv2
    88
     
    1414using a drop down list.
    1515
    16 In order to add a city please add a line to the cities.txt file. The file formate is:
    17 <cityname>:<timezone>:<latitude>:<longitude>
     16To Add a city go to city.txt and add a line with the following format:
     17<city>:<latitude>:<longitude>:<timezone>:<summertimezone>
    1818
    1919For example:
    20 Orlando,FL:America/New_York:28.55:-81.33
     20Miami, FL:25.82:-80.28:EST:EDT
    2121
    22 Logitude is always negative for cities in the United States.  This plugin should handle cities from different
     22Logitude is always negative for cities  in the United States.  This plugin should handle cities from different
    2323countries, but it has not been tested.
    2424
     
    4848= How do I add more cities to this list? =
    4949Add a line in the cities.txt file with the following format:
    50 <cityname>:<timezone>:<latitude>:<longitude>
     50<city>:<latitude>:<longitude>:<timezone>:<summertimezone>
    5151
    5252For example:
    53 Orlando,FL:America/New_York:28.55:-81.33
     53Miami, FL:25.82:-80.28:EST:EDT
    5454
    5555
     
    6060
    6161== Changelog ==
     62= 1.0.9 =
     63* Fixed times for most cities.
     64
    6265= 1.0.8 =
    6366* Removed hacked code - reported to WordPress.org forums
  • sunrise-sunset/trunk/sunrisesunset.php

    r525899 r527059  
    44Plugin URI: http://wordpress.org/extend/plugins/sunrise-sunset/
    55Description: Displays Sunrise and Sunset Times
    6 Version: 1.0.8
     6Version:  1.0.9
    77Author: Rex Posadas ([email protected])
    88Author URI: http://www.rxnfx.com/ss-plugin
     
    3737class sunrise_sunset extends WP_Widget
    3838{
    39 
    4039    private $_cities;
    41     private $_latitude;
    42     private $_longitude;
    4340
    4441    private function populateCities()
     
    4744        foreach ($lines as $line) {
    4845            $pieces = explode(":", $line);
    49             $this->_cities[$pieces[0]] = new City($pieces[0], $pieces[1], $pieces[2]);
     46            if ($pieces[0] == 'city') continue;
     47            $this->_cities[$pieces[0]] = new City($pieces[0], $pieces[1], $pieces[2], $pieces[3], $pieces[4]);
    5048        }
    5149    }
     
    166164    }
    167165
     166    private function convertTimezone($timestamp, $city)
     167    {
     168        $newTimestamp = 0;
     169
     170        switch ($city->getTimezone()) {
     171            case 'EST':
     172                $newTimestamp = $timestamp - (5 * 60 * 60);
     173                break;
     174            case 'EDT':
     175                $newTimestamp = $timestamp - (4 * 60 * 60);
     176                break;
     177            case 'MST':
     178                $newTimestamp = $timestamp - (7 * 60 * 60);
     179                break;
     180            case 'CST':
     181                $newTimestamp = $timestamp - (6 * 60 * 60);
     182                break;
     183            case 'CDT':
     184                $newTimestamp = $timestamp - (5 * 60 * 60);
     185                break;
     186            case 'PST':
     187                $newTimestamp = $timestamp - (8 * 60 * 60);
     188                break;
     189            case 'PDT':
     190                $newTimestamp = $timestamp - (7 * 60 * 60);
     191                break;
     192        }
     193
     194        $time_format = 'h:i A';
     195
     196        $olddate = date($time_format, $timestamp);
     197        $newdate = date($time_format, $newTimestamp);
     198
     199
     200        return $newTimestamp;
     201    }
     202
    168203
    169204    function ss_get_times($instance)
    170205    {
    171206        $time_format = 'h:i A';
    172 
    173         $lat = $this->_cities[$instance['city']]->getLatitude();
    174         $long = $this->_cities[$instance['city']]->getLongitude();
    175 
    176 //        $suninfo = date_sun_info(time(), floatval($lat), floatval($long));
    177         $suninfo = date_sun_info(time(), floatval($long), floatval($lat));
    178 
    179         $sunrise_time = date($time_format, $suninfo['sunrise']);
    180         $sunset_time = date($time_format, $suninfo['sunset']);
     207        $targetCity = $this->_cities[$instance['city']];
     208
     209        $lat = $targetCity->getLatitude();
     210        $long = $targetCity->getLongitude();
     211
     212        $suninfo = date_sun_info(time(), $lat, $long);
     213
     214        $sunrise_time = date($time_format, $this->convertTimezone($suninfo['sunrise'], $targetCity));
     215        $sunset_time = date($time_format, $this->convertTimezone($suninfo['sunset'], $targetCity));
    181216
    182217        return array('sunrise' => $sunrise_time, 'sunset' => $sunset_time);
Note: See TracChangeset for help on using the changeset viewer.