Plugin Directory

Changeset 1744670


Ignore:
Timestamp:
10/11/2017 10:25:27 AM (8 years ago)
Author:
webcodin
Message:

version 2.5.0

Location:
wcp-openweather/trunk
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • wcp-openweather/trunk/classes/RPw.class.php

    r1700159 r1744670  
    1212     * @var type
    1313     */
    14     private $version = '2.4.1';
     14    private $version = '2.5.0';
    1515   
    1616    /**
  • wcp-openweather/trunk/classes/api/OpenWeather.class.php

    r1267549 r1744670  
    66
    77class OpenWeather extends Agp_Curl {
     8   
     9    private $sunrise;
     10
     11    private $sunset;         
    812   
    913    private $currentSessionId;       
     
    97101    public function getForecast() {
    98102        $response = $this->get(array(), 'forecast');
     103        $weather = $this->get(array(), 'weather');
     104        $this->sunrise = $weather->sys->sunrise;
     105        $this->sunset = $weather->sys->sunset;
    99106       
    100107        if (isset($response->city->id) && empty($response->city->id)) {
     
    114121
    115122            $items = array();
    116             foreach ($response->list as $item) {
    117                 $weather = $item->weather[0];
    118                 $items[] = array(
    119                     'ID' => $item->dt,
    120                     'temperature' => $item->main->temp,   
    121                     'pressure' => $item->main->pressure,
    122                     'humidity' => $item->main->humidity,
    123                     'windSpeed' => $item->wind->speed,
    124                     'windDeg' => !empty($item->wind->deg) ? $item->wind->deg : NULL,   
    125                     'weatherId' => $weather->id,   
    126                     'weatherMain' => $weather->main,   
    127                     'weatherDescription' => $weather->description,   
    128                     'weatherIcon' => $weather->icon,
    129                     'weatherIconUrl' => 'http://openweathermap.org/img/w/'. $weather->icon .'.png',
    130                     'clouds' => $item->clouds->all,
    131                     'sunrise' => NULL,
    132                     'sunset' => NULL,                   
    133                 );
     123            if (!empty($response->list)) {
     124                $aitems = array();
     125                foreach ($response->list as $item) {
     126                    $index = strtotime(date('Y-m-d 00:00:00', $item->dt));
     127                    $times = $this->getForecastTimesByDt( $item->dt );
     128                   
     129                    if (!$aitems[ $index ]['temp'][ $times ]) {
     130                        $aitems[ $index ]['temp'][ $times ] = array();
     131                    }
     132                    array_push($aitems[ $index ]['temp'][ $times ], $item->main->temp);
     133                   
     134                    if ( empty($aitems[ $index ]['item']) && $this->getForecastTimesByDt($item->dt) == 'day' ) {                       
     135                        $aitems[ $index ]['item'] = $item;
     136                        $aitems[ $index ]['item_date'] = date('c', $item->dt);
     137                    }
     138                   
     139                }
     140               
     141                $cnt = 0;
     142                foreach ($aitems as $index => $value) {
     143                    $item = $value['item'];
     144                    $temps = $value['temp'];
     145                    $temp = new \stdClass();
     146                   
     147                    $temp->day = !empty($temps['day']) ? max( $temps['day'] ) : $item->main->temp;
     148                    $temp->night = !empty($temps['night']) ? min( $temps['night'] ) : $item->main->temp;
     149                   
     150                    $weather = $item->weather[0];
     151                    $items[] = array(
     152                        'ID' => $index,
     153                        'temperature' => $temp,   
     154                        'pressure' => $item->main->pressure,
     155                        'humidity' => $item->main->humidity,
     156                        'windSpeed' => $item->wind->speed,
     157                        'windDeg' => !empty($item->wind->deg) ? $item->wind->deg : NULL,   
     158                        'weatherId' => $weather->id,   
     159                        'weatherMain' => $weather->main,   
     160                        'weatherDescription' => $weather->description,   
     161                        'weatherIcon' => $weather->icon,
     162                        'weatherIconUrl' => 'http://openweathermap.org/img/w/'. $weather->icon .'.png',
     163                        'clouds' => $item->clouds->all,
     164                        'sunrise' => NULL,
     165                        'sunset' => NULL,                   
     166                    );
     167                    if ( ++$cnt >=5 ) break;
     168                }
     169                $data['items'] = $items;
    134170            }
    135             $data['items'] = $items;
    136 
    137171            $repository = new WeatherRepository($data);
    138172            return $repository;
     
    190224            return $repository;
    191225        } else {
    192             $this->session->reset($this->currentSessionId);
    193         }
     226            $repository = $this->getForecast();
     227            return $repository;
     228        }
     229    }
     230   
     231    private function getForecastTimesByDt ( $dt ) {
     232        $sunrise = date('Gi', $this->sunrise);
     233        $sunset = date('Gi', $this->sunset);
     234        $hour = date('Gi', $dt);
     235       
     236        if ($hour >= $sunrise && $hour < $sunset ) {
     237            return 'day';
     238        } else {
     239            return 'night';
     240        }       
    194241    }
    195242   
  • wcp-openweather/trunk/classes/persistence/Convertor.class.php

    r1267549 r1744670  
    1818        switch ($unit) {
    1919            case 'c':
    20                 $value = round(($value - 273.15), 0);
     20                $value = isset($value) ? round(($value - 273.15), 0) : '-';
    2121            break;
    2222            case 'f':
    23                 $value = round(($value * 9 / 5 - 459.67), 0);
     23                $value = isset($value) ? round(($value * 9 / 5 - 459.67), 0) :  '-';
    2424            break;       
    2525        }
  • wcp-openweather/trunk/readme.txt

    r1700159 r1744670  
    216216
    217217== Changelog ==
     218= 2.5.0 =
     219* Fixed issue with displaying 5-day weather forecast for API-keys of new registered OpenWeathwerMap users
     220* Minor changes
     221
    218222= 2.4.1 =
    219223* Added translation to the Danish (Denmark) language
  • wcp-openweather/trunk/wcp-openweather.php

    r1700159 r1744670  
    44 * Plugin URI: https://wordpress.org/plugins/wcp-openweather/
    55 * Description: The weather forecast plugin based on OpenWeatherMap API that includes various sidebar widgets and shortcodes
    6  * Version: 2.4.1
     6 * Version: 2.5.0
    77 * Author: Webcodin
    88 * Author URI: https://profiles.wordpress.org/webcodin/
Note: See TracChangeset for help on using the changeset viewer.