Changeset 1744670
- Timestamp:
- 10/11/2017 10:25:27 AM (8 years ago)
- Location:
- wcp-openweather/trunk
- Files:
-
- 5 edited
-
classes/RPw.class.php (modified) (1 diff)
-
classes/api/OpenWeather.class.php (modified) (4 diffs)
-
classes/persistence/Convertor.class.php (modified) (1 diff)
-
readme.txt (modified) (1 diff)
-
wcp-openweather.php (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
wcp-openweather/trunk/classes/RPw.class.php
r1700159 r1744670 12 12 * @var type 13 13 */ 14 private $version = '2. 4.1';14 private $version = '2.5.0'; 15 15 16 16 /** -
wcp-openweather/trunk/classes/api/OpenWeather.class.php
r1267549 r1744670 6 6 7 7 class OpenWeather extends Agp_Curl { 8 9 private $sunrise; 10 11 private $sunset; 8 12 9 13 private $currentSessionId; … … 97 101 public function getForecast() { 98 102 $response = $this->get(array(), 'forecast'); 103 $weather = $this->get(array(), 'weather'); 104 $this->sunrise = $weather->sys->sunrise; 105 $this->sunset = $weather->sys->sunset; 99 106 100 107 if (isset($response->city->id) && empty($response->city->id)) { … … 114 121 115 122 $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; 134 170 } 135 $data['items'] = $items;136 137 171 $repository = new WeatherRepository($data); 138 172 return $repository; … … 190 224 return $repository; 191 225 } 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 } 194 241 } 195 242 -
wcp-openweather/trunk/classes/persistence/Convertor.class.php
r1267549 r1744670 18 18 switch ($unit) { 19 19 case 'c': 20 $value = round(($value - 273.15), 0);20 $value = isset($value) ? round(($value - 273.15), 0) : '-'; 21 21 break; 22 22 case 'f': 23 $value = round(($value * 9 / 5 - 459.67), 0);23 $value = isset($value) ? round(($value * 9 / 5 - 459.67), 0) : '-'; 24 24 break; 25 25 } -
wcp-openweather/trunk/readme.txt
r1700159 r1744670 216 216 217 217 == 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 218 222 = 2.4.1 = 219 223 * Added translation to the Danish (Denmark) language -
wcp-openweather/trunk/wcp-openweather.php
r1700159 r1744670 4 4 * Plugin URI: https://wordpress.org/plugins/wcp-openweather/ 5 5 * Description: The weather forecast plugin based on OpenWeatherMap API that includes various sidebar widgets and shortcodes 6 * Version: 2. 4.16 * Version: 2.5.0 7 7 * Author: Webcodin 8 8 * Author URI: https://profiles.wordpress.org/webcodin/
Note: See TracChangeset
for help on using the changeset viewer.