From 332344cff07e9fc89bfcde3717888128cf1edd5e Mon Sep 17 00:00:00 2001 From: Jacek Kowalski <Jacek@jacekk.info> Date: Fri, 24 Aug 2012 11:26:28 +0000 Subject: [PATCH] 1. Przeportowanie modułu version (wersja) do nowej wersji API. 2. Przeportowanie modułu czesc do nowej wersji API. 3. Zmiana kolejności ładowania modułu legacy (zmiana numeru). --- modules/30_pogoda.php | 50 +++++++++++++++++++++++++++----------------------- 1 files changed, 27 insertions(+), 23 deletions(-) diff --git a/modules/30_pogoda.php b/modules/30_pogoda.php index b80f8d5..60cb39e 100644 --- a/modules/30_pogoda.php +++ b/modules/30_pogoda.php @@ -87,7 +87,27 @@ } } + static function putIcon($icon) { + if(!empty($icon)) { + if(!file_exists('./data/pogoda/'.basename($icon))) { + if(substr($icon, 0, 1) == '/') { + $icon = 'http://www.google.com'.$icon; + } + $img = @file_get_contents($icon); + if($img) { + file_put_contents('./data/pogoda/'.basename($icon), $img); + } + } + + GGapi::putImage('./data/pogoda/'.basename($icon)); + GGapi::putText("\n"); + } + + } + static function cmd_pogoda($name, $arg) { + $forced = FALSE; + if(empty($arg)) { $arg = database::get($_GET['from'], 'pogoda', 'miasto'); if(empty($arg)) { @@ -97,7 +117,7 @@ $arg = 'Warszawa'; $forced = TRUE; } - GGapi::putText('Nie ustawiono miasta (pomoc - wpisz: help miasto) - '.(!$forced ? 'na podstawie danych z katalogu publicznego ' : '').'wybieram '.$arg."\n\n"); + GGapi::putText('Nie ustawiono miasta (pomoc - wpisz: help miasto) - '.(!$forced ? 'na podstawie danych z katalogu publicznego ' : '').'wybieram miasto '.$arg."\n\n"); } } @@ -144,32 +164,16 @@ GGapi::putRichText('Pogoda dla miasta '.$miasto.', '.$region."\n\n", TRUE); GGapi::putRichText('Teraz'."\n", TRUE); - $icon = (string)$dane->weather->current_conditions->icon['data']; - if(!empty($icon)) { - if(!file_exists('./data/pogoda/'.basename($icon))) { - $img = @file_get_contents($icon); - if($img) { - file_put_contents('./data/pogoda/'.basename($icon), $img); - } - } - - GGapi::putImage('./data/pogoda/'.basename($icon)); - $txt = "\n"; - } + self::putIcon((string)$dane->weather->current_conditions->icon['data']); + $condition = (string)$dane->weather->current_conditions->condition['data']; - GGapi::putRichText($txt.($condition ? $condition."\n" : '').'Temp.: '.($dane->weather->current_conditions->temp_c['data']).'°C'."\n".($dane->weather->current_conditions->humidity['data'])."\n".($dane->weather->current_conditions->wind_condition['data'])); + GGapi::putRichText(($condition ? $condition."\n" : '').'Temp.: '.($dane->weather->current_conditions->temp_c['data']).'°C'."\n".($dane->weather->current_conditions->humidity['data'])."\n".($dane->weather->current_conditions->wind_condition['data'])); $num = TRUE; foreach($dane->weather->forecast_conditions as $day) { GGapi::putRichText("\n\n".($num ? 'Później' : $short2day[(string)$day->day_of_week['data']])."\n", TRUE); - if(!file_exists('./data/pogoda/'.basename($day->icon['data']))) { - $img = @file_get_contents($day->icon['data']); - if($img) { - file_put_contents('./data/pogoda/'.basename($day->icon['data']), $img); - } - } - GGapi::putImage('./data/pogoda/'.basename($day->icon['data'])); - GGapi::putRichText("\n".($day->condition['data'])."\n".'Temp. od '.($day->low['data']).'°C do '.($day->high['data']).'°C'); + self::putIcon((string)$day->icon['data']); + GGapi::putRichText(($day->condition['data'])."\n".'Temp. od '.($day->low['data']).'°C do '.($day->high['data']).'°C'); $num = FALSE; } @@ -226,4 +230,4 @@ database::add($_GET['from'], 'pogoda', 'geo', array('lat' => (string)$data->lat, 'lon' => (string)$data->lng)); } } -?> \ No newline at end of file +?> -- Gitblit v1.9.1