From 6d0060111afed6e587e5410a9495bd0140219a6d Mon Sep 17 00:00:00 2001 From: Jacek Kowalski <Jacek@jacekk.info> Date: Wed, 29 Aug 2012 12:55:32 +0000 Subject: [PATCH] Dodanie informacji o pogodzie pod wyświetlanymi ikonami w module pogoda. --- modules/30_pogoda/api_yrno.php | 28 ++++++++++++++-------------- modules/30_pogoda/handler.php | 19 ++++++++++++++----- 2 files changed, 28 insertions(+), 19 deletions(-) diff --git a/modules/30_pogoda/api_yrno.php b/modules/30_pogoda/api_yrno.php index 70e3b5a..d10944e 100644 --- a/modules/30_pogoda/api_yrno.php +++ b/modules/30_pogoda/api_yrno.php @@ -3,7 +3,7 @@ protected $xml; protected $dane; - var $symbols = array( + static $symbols = array( 1 => 'Słonecznie', 2 => 'Lekkie zachmurzenie', 3 => 'Częściowe zachmurzenie', @@ -29,7 +29,7 @@ 23 => 'Deszcz ze śniegiem, burze' ); - var $wind = array( + static $wind = array( 'N' => 'północny', 'NW' => 'północno-zachodni', 'W' => 'zachodni', @@ -39,6 +39,16 @@ 'E' => 'wschodni', 'NE' => 'północno-wschodni', ); + + static function wind($dir) { + if(isset(self::$wind[$dir])) { + return self::$wind[$dir]; + } + else + { + return ''; + } + } function __construct($xml) { libxml_use_internal_errors(); @@ -52,16 +62,6 @@ 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() { @@ -96,8 +96,8 @@ } $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( diff --git a/modules/30_pogoda/handler.php b/modules/30_pogoda/handler.php index 3a71211..40a1691 100644 --- a/modules/30_pogoda/handler.php +++ b/modules/30_pogoda/handler.php @@ -73,13 +73,14 @@ $out->a('<p>Pogoda dla '.htmlspecialchars($loc['name']).', '.htmlspecialchars($loc['countryName']).'.</p>'."\n\n"); - $icon = $api->symbols[$api->getCurrentIcon()]; + $icon = (int)$api->getCurrentIcon(); $weather = $api->getCurrentWeather(); $out->a('<p><b>Teraz</b><br />'."\n" - . $icon.'<br />'."\n" + . '<img src="./data/pogoda/'.$icon.'.png" />'."\n" + . api_yrno_parse::$symbols[$icon].'<br />'."\n" . 'Temp.: '.htmlspecialchars($weather['temp']).'°C<br />'."\n" - . 'Wiatr: '.htmlspecialchars($weather['wind']).' km/h, '.$api->wind($weather['wind']).'<br />'."\n" + . 'Wiatr: '.htmlspecialchars($weather['wind_speed']).' km/h, '.api_yrno_parse::wind($weather['wind_direction']).'<br />'."\n" . 'Ciśnienie: '.htmlspecialchars($weather['pressure']).' hPa</p>'."\n\n"); $when = time(); @@ -104,12 +105,20 @@ function getHTMLforWeather($name, $icons, $weather) { $html = '<p><b>'.$name.'</b><br />'."\n"; + $desc = array(); + $curr = 0; foreach($icons as $icon) { - if(is_file('./data/pogoda/'.htmlspecialchars($icon).'.png')) { - $html .= '<img src="./data/pogoda/'.htmlspecialchars($icon).'.png" alt="" /> '; + $icon = (int)$icon; + if(is_file('./data/pogoda/'.$icon.'.png')) { + $html .= '<img src="./data/pogoda/'.$icon.'.png" alt="" /> '; + if($icon != $curr) { + $desc[] = api_yrno_parse::$symbols[$icon]; + $curr = $icon; + } } } $html .= '<br />'."\n" + . implode(' / ', $desc).'<br />'."\n" . 'Temp.: '.$this->getHTMLforRange($weather['temp']['day']).'°C (w nocy: '.$this->getHTMLforRange($weather['temp']['night']).'°C)<br />'."\n" . 'Wiatr: '.$this->getHTMLforRange($weather['wind']['day']).' km/h (w nocy: '.$this->getHTMLforRange($weather['wind']['night']).' km/h)</p>'."\n\n"; -- Gitblit v1.9.1