| | |
| | | protected $xml; |
| | | protected $dane; |
| | | |
| | | var $symbols = array( |
| | | public static $symbols = array( |
| | | 1 => 'Słonecznie', |
| | | 2 => 'Lekkie zachmurzenie', |
| | | 3 => 'Częściowe zachmurzenie', |
| | |
| | | 23 => 'Deszcz ze śniegiem, burze' |
| | | ); |
| | | |
| | | var $wind = array( |
| | | public static $wind = array( |
| | | 'N' => 'północny', |
| | | 'NW' => 'północno-zachodni', |
| | | 'W' => 'zachodni', |
| | |
| | | 'NE' => 'północno-wschodni', |
| | | ); |
| | | |
| | | function __construct($xml) { |
| | | public static function wind($dir) { |
| | | if(isset(self::$wind[$dir])) { |
| | | return self::$wind[$dir]; |
| | | } |
| | | else |
| | | { |
| | | return ''; |
| | | } |
| | | } |
| | | |
| | | public function __construct($xml) { |
| | | libxml_use_internal_errors(); |
| | | $this->xml = simplexml_load_string($xml); |
| | | libxml_clear_errors(); |
| | |
| | | } |
| | | } |
| | | |
| | | function mktime($time) { |
| | | public function mktime($time) { |
| | | return strtotime(substr($time, 0, -1)); |
| | | } |
| | | |
| | | function wind($dir) { |
| | | if(isset($this->wind[$dir])) { |
| | | return $this->wind[$dir]; |
| | | } |
| | | else |
| | | { |
| | | return ''; |
| | | } |
| | | } |
| | | |
| | | function parseForecast() { |
| | | public function parseForecast() { |
| | | $this->dane = array( |
| | | '0h' => array(), |
| | | '3h' => array(), |
| | |
| | | } |
| | | |
| | | $icon = (int)$time->symbol->attributes()->number; |
| | | if(is_int($this->symbols[$icon])) { |
| | | $icon = $this->symbols[$icon]; |
| | | if(is_int(self::$symbols[$icon])) { |
| | | $icon = self::$symbols[$icon]; |
| | | } |
| | | |
| | | $this->dane[$put][$to] = array( |
| | |
| | | } |
| | | } |
| | | |
| | | function getCurrentIcon() { |
| | | public function getCurrentIcon() { |
| | | $now = time(); |
| | | foreach($this->dane['3h'] as $value) { |
| | | if($value['from'] <= $now && $now < $value['to']) { |
| | |
| | | return NULL; |
| | | } |
| | | |
| | | function getCurrentWeather() { |
| | | public function getCurrentWeather() { |
| | | $dist = PHP_INT_MAX; |
| | | $current = NULL; |
| | | foreach($this->dane['0h'] as $time => $value) { |
| | |
| | | return $current; |
| | | } |
| | | |
| | | function getDaypartWeather($timestamp) { |
| | | public function getDaypartWeather($timestamp) { |
| | | $start = strtotime('6:00', $timestamp); |
| | | $dayend = strtotime('19:30', $timestamp); |
| | | $end = $start + 22*3600; |
| | |
| | | return array('temp' => $temp, 'wind' => $wind); |
| | | } |
| | | |
| | | function getDaypartIcon($timestamp) { |
| | | public function getDaypartIcon($timestamp) { |
| | | $start = strtotime('6:00', $timestamp); |
| | | $end = strtotime('24:00', $timestamp); |
| | | |