From f9c887e24df56d3ef46beae065f55a9ec3caaaf5 Mon Sep 17 00:00:00 2001 From: Tobias Diekershoff Date: Mon, 13 Jul 2015 07:05:55 +0200 Subject: [PATCH] move widget HTML into smarty3 template and update styling --- curweather/curweather.css | 11 ++++------- curweather/curweather.php | 33 ++++++++++++++++++++------------- curweather/templates/widget.tpl | 15 +++++++++++++++ 3 files changed, 39 insertions(+), 20 deletions(-) create mode 100644 curweather/templates/widget.tpl diff --git a/curweather/curweather.css b/curweather/curweather.css index 6c127963..a0b7c8fb 100644 --- a/curweather/curweather.css +++ b/curweather/curweather.css @@ -1,10 +1,7 @@ - -#curtemp-settings-label, #curtemp-location-label, #curtemp-enable-label { - float: left; - width: 200px; - margin-bottom: 25px; +ul.curweather-details li { + list-type: none; } -#curtemp-network { - float: left; +p.curweather-footer { + font-size: 0.8em; } diff --git a/curweather/curweather.php b/curweather/curweather.php index 6db89428..29b16512 100644 --- a/curweather/curweather.php +++ b/curweather/curweather.php @@ -34,10 +34,11 @@ function curweather_uninstall() { // the caching time depending on the plans they got from openweathermap.org // and the usage of the friendica temppath -class ExampleCache extends AbstractCache +class CWCache extends AbstractCache { private function urlToPath($url) { + // take friendicas tmp directory as base for the cache $tmp = get_config('system','temppath'); $dir = $tmp . DIRECTORY_SEPARATOR . "OpenWeatherMapPHPAPI"; if (!is_dir($dir)) { @@ -104,7 +105,7 @@ function curweather_network_mod_init(&$fk_app,&$b) { // Get OpenWeatherMap object. Don't use caching (take a look into // Example_Cache.php to see how it works). //$owm = new OpenWeatherMap(); - $owm = new OpenWeatherMap(null, new ExampleCache(), $cachetime); + $owm = new OpenWeatherMap(null, new CWCache(), $cachetime); try { $weather = $owm->getWeather($rpt, $units, $lang, $appid); @@ -118,23 +119,29 @@ function curweather_network_mod_init(&$fk_app,&$b) { $pressure = $weather->pressure; $wind = $weather->wind->speed->getDescription().', '.$weather->wind->speed . " " . $weather->wind->direction; $description = $weather->clouds->getDescription(); + $city = array( + 'name'=>$weather->city->name, + 'lon' =>$weather->city->lon, + 'lat' =>$weather->city->lat + ); } catch(OWMException $e) { info ( 'OpenWeatherMap exception: ' . $e->getMessage() . ' (Code ' . $e->getCode() . ').'); } catch(\Exception $e) { info ('General exception: ' . $e->getMessage() . ' (Code ' . $e->getCode() . ').'); } - $curweather = '
-
-

'.t("Current Weather").': '.$weather->city->name.'

'; - - $curweather .= "$description; $temp
"; - $curweather .= t('Relative Humidity').": $rhumid
"; - $curweather .= t('Pressure').": $pressure
"; - $curweather .= t('Wind').": $wind
"; - $curweather .= ''. t('Data by').': OpenWeatherMap. '.t('Show on map').''; - - $curweather .= '
'; + $t = get_markup_template("widget.tpl", "addon/curweather/" ); + $curweather = replace_macros ($t, array( + '$title' => t("Current Weather"), + '$city' => $city, + '$description' => $description, + '$temp' => $temp, + '$relhumidity' => array('caption'=>t('Relative Humidity'), 'val'=>$rhumid), + '$pressure' => array('caption'=>t('Pressure'), 'val'=>$pressure), + '$wind' => array('caption'=>t('Wind'), 'val'=> $wind), + '$databy' => t('Data by'), + '$showonmap' => t('Show on map') + )); $fk_app->page['aside'] = $curweather.$fk_app->page['aside']; diff --git a/curweather/templates/widget.tpl b/curweather/templates/widget.tpl new file mode 100644 index 00000000..e90a348f --- /dev/null +++ b/curweather/templates/widget.tpl @@ -0,0 +1,15 @@ +
+
+

{{$title}}: {{$city['name']}}

+
+

{{$description}}, {{$temp}} +

+ +
+
-- 2.39.5