From 631476ff6e3f75a06cc5da7cfa6e9e5517d8d079 Mon Sep 17 00:00:00 2001 From: Tobias Diekershoff Date: Sat, 11 Jul 2015 20:17:33 +0200 Subject: [PATCH 01/28] use smarty3 for config forms --- curweather/templates/admin.tpl | 2 ++ curweather/templates/settings.tpl | 17 +++++++++++++++++ 2 files changed, 19 insertions(+) create mode 100644 curweather/templates/admin.tpl create mode 100644 curweather/templates/settings.tpl diff --git a/curweather/templates/admin.tpl b/curweather/templates/admin.tpl new file mode 100644 index 00000000..5f0c11bf --- /dev/null +++ b/curweather/templates/admin.tpl @@ -0,0 +1,2 @@ +{{include file="field_input.tpl" field=$appid}} +
diff --git a/curweather/templates/settings.tpl b/curweather/templates/settings.tpl new file mode 100644 index 00000000..1453b210 --- /dev/null +++ b/curweather/templates/settings.tpl @@ -0,0 +1,17 @@ + +

{{$header}}

+
+ From cda0d59060f8b9228b723d3118b51f9a799fa1cc Mon Sep 17 00:00:00 2001 From: Tobias Diekershoff Date: Sat, 11 Jul 2015 20:17:54 +0200 Subject: [PATCH 02/28] added README for curweather --- curweather/README.md | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 curweather/README.md diff --git a/curweather/README.md b/curweather/README.md new file mode 100644 index 00000000..720f92cf --- /dev/null +++ b/curweather/README.md @@ -0,0 +1,27 @@ +Current Weather +=============== + +If activated by your user this addon adds a widget to the users network tab +sidebar showing current weather informations from +[OpenWeatherMap](http://openweathermap.org). The user can configure the +location as e.g. *Berlin,DE* or the zip code "14476,DE". + +The language for the request at OpenWeatherMap is set to the UI language of +friendica. If the string for the description of the current weather conditions +is available in this language depends on OpenWeatherMap. + +**You should get an APPID from OpenWeatherMap if you want to use this widget.** +You can register [here](http://openweathermap.org/register). + +Credits +------- + +* Tony Baldvin wrote the original addon for Friendica +* Fabio Comuni +* Tobias Diekershoff switched the sources to OpenWeatherMap after the original + provider turned off support for locations outside of the USA. + +To access the API of OpenWeatherMap the library +[OpenWeatherMap-PHP-Api](https://github.com/cmfcmf/OpenWeatherMap-PHP-Api) by +Christian Flach is used (MIT license). + From 4f1fb007c58df8b943ba7a337a20d7e160cc4102 Mon Sep 17 00:00:00 2001 From: Tobias Diekershoff Date: Sat, 11 Jul 2015 20:20:09 +0200 Subject: [PATCH 03/28] remove unneded files --- curweather/getweather.php | 230 -------------------------------------- curweather/test.php | 5 - 2 files changed, 235 deletions(-) delete mode 100644 curweather/getweather.php delete mode 100644 curweather/test.php diff --git a/curweather/getweather.php b/curweather/getweather.php deleted file mode 100644 index b4660b9e..00000000 --- a/curweather/getweather.php +++ /dev/null @@ -1,230 +0,0 @@ -$i){ - $a=explode(" | ",$i); - if(is_numeric(array_search($wx,$a))){ - self::$wxdata['ICON']="$imgpath/$k.jpg"; - break; - } - } - - // Replace any null elements with "Not available" - foreach(array_keys(self::$wxdata) as $key){ - self::$wxdata[$key]=self::$wxdata[$key]=="NULL"?"Not available":self::$wxdata[$key]; - } - - // If we got humidity - if(is_numeric(self::$wxdata['RELATIVE_HUMIDITY'])) - // Append a percent sign - self::$wxdata['RELATIVE_HUMIDITY'].="%"; - - // Do some formatting to make the output a little friendlier - if(self::$wxdata['VISIBILITY_MI']=="NA") - self::$wxdata['VISIBILITY']="Not available"; - if(self::$wxdata['VISIBILITY']!="Not available") - self::$wxdata['VISIBILITY']=(1*self::$wxdata['VISIBILITY_MI'])." miles"; - - // If we got wind data - if(is_numeric(self::$wxdata['WIND_MPH'])){ - // We're going to output wind data as both MPH from a cardinal direction - // and as Knots from a direction in degrees - - // Calculate the value for Knots - self::$wxdata['WIND_KNOTS']=self::$wxdata['WIND_MPH']/1.15; - - // Format the output - $wind=sprintf("From the %s at %d mph (%03.0f° at %d knots)",self::$wxdata['WIND_DIR'],self::$wxdata['WIND_MPH'],self::$wxdata['WIND_DEGREES'],self::$wxdata['WIND_KNOTS']); - - // If we got a value for wind gusts - if(is_numeric(self::$wxdata['WIND_GUST_MPH']) && self::$wxdata['WIND_GUST_MPH']>0){ - // add it into the wind string - $wind=str_replace("mph","gusting to ".self::$wxdata['WIND_GUST_MPH']." mph
", $wind); - $knots=sprintf("%d",self::$wxdata['WIND_GUST_MPH']/1.15); - $wind=str_replace("knots","gusting to $knots knots",$wind); - } - } else { - // Otherwise, if wind is zero, we'll show "Calm" - $wind=self::$wxdata['WIND_MPH']=="Not available"?"Not available":"Calm"; - } // Done with wind - self::$wxdata['WIND_STRING']=$wind; - - } // Done getting and formatting the data - return self::$wxdata; - } - - function startElement($parser, $name, $attrs) { - self::$itemname=$name; - self::$itemdata=""; - } - - function endElement($parser, $name) { - self::$wxdata[self::$itemname]=self::$itemdata; - self::$itemdata=""; - } - - function characterData($parser, $data) { - self::$itemdata.=$data; - } - - function defineIcons(){ - // See http://weather.gov/data/current_obs/weather.php for source data for this function - $retVal['bkn']="Mostly Cloudy | Mostly Cloudy with Haze | Mostly Cloudy and Breezy"; - $retVal['skc']="Fair | Clear | Fair with Haze | Clear with Haze | Fair and Breezy | Clear and Breezy"; - $retVal['few']="A Few Clouds | A Few Clouds with Haze | A Few Clouds and Breezy"; - $retVal['sct']="Partly Cloudy | Party Cloudy with Haze | Partly Cloudy and Breezy"; - $retVal['ovc']="Overcast | Overcast with Haze | Overcast and Breezy"; - $retVal['nfg']="Fog/Mist | Fog | Freezing Fog | Shallow Fog | Partial Fog | Patches of Fog | Fog in Vicinity | Freezing Fog in Vicinity | Shallow Fog in Vicinity | Partial Fog in Vicinity | Patches of Fog in Vicinity | Showers in Vicinity Fog | Light Freezing Fog | Heavy Freezing Fog"; - $retVal['smoke']="Smoke"; - $retVal['fzra']="Freezing Rain | Freezing Drizzle | Light Freezing Rain | Light Freezing Drizzle | Heavy Freezing Rain | Heavy Freezing Drizzle | Freezing Rain in Vicinity | Freezing Drizzle in Vicinity"; - $retVal['ip']="Ice Pellets | Light Ice Pellets | Heavy Ice Pellets | Ice Pellets in Vicinity | Showers Ice Pellets | Thunderstorm Ice Pellets | Ice Crystals | Hail | Small Hail/Snow Pellets | Light Small Hail/Snow Pellets | Heavy Small Hail/Snow Pellets | Showers Hail | Hail Showers"; - $retVal['mix']="Freezing Rain Snow | Light Freezing Rain Snow | Heavy Freezing Rain Snow | Freezing Drizzle Snow | Light Freezing Drizzle Snow | Heavy Freezing Drizzle Snow | Snow Freezing Rain| Light Snow Freezing Rain | Heavy Snow Freezing Rain | Snow Freezing Drizzle | Light Snow Freezing Drizzle | Heavy Snow Freezing Drizzle"; - $retVal['raip']="Rain Ice Pellets | Light Rain Ice Pellets | Heavy Rain Ice Pellets | Drizzle Ice Pellets | Light Drizzle Ice Pellets | Heavy Drizzle Ice Pellets | Ice Pellets Rain | Light Ice Pellets Rain | Heavy Ice Pellets Rain | Ice Pellets Drizzle | Light Ice Pellets Drizzle | Heavy Ice Pellets Drizzle"; - $retVal['rasn']="Rain Snow | Light Rain Snow | Heavy Rain Snow | Snow Rain | Light Snow Rain | Heavy Snow Rain | Drizzle Snow | Light Drizzle Snow | Heavy Drizzle Snow | Snow Drizzle | Light Snow Drizzle | Heavy Snow Drizzle"; - $retVal['shra']="Rain Showers | Light Rain Showers | Heavy Rain Showers | Rain Showers in Vicinity | Light Showers Rain | Heavy Showers Rain | Showers Rain | Showers Rain in Vicinity | Rain Showers Fog/Mist | Light Rain Showers Fog/Mist | Heavy Rain Showers Fog/Mist | Rain Showers in Vicinity Fog/Mist | Light Showers Rain Fog/Mist | Heavy Showers Rain Fog/Mist | Showers Rain Fog/Mist | Showers Rain in Vicinity Fog/Mist"; - $retVal['tsra']="Thunderstorm | Light Thunderstorm Rain | Heavy Thunderstorm Rain | Thunderstorm Rain Fog/Mist | Light Thunderstorm Rain Fog/Mist | Heavy Thunderstorm Rain Fog/Mist | Thunderstorm Showers in Vicinity | | Light Thunderstorm Rain Haze | Heavy Thunderstorm Rain Haze | Thunderstorm Fog | Light Thunderstorm Rain Fog | Heavy Thunderstorm Rain Fog | Thunderstorm Light Rain | Thunderstorm Heavy Rain | Thunderstorm Rain Fog/Mist | Thunderstorm Light Rain Fog/Mist | Thunderstorm Heavy Rain Fog/Mist | Thunderstorm in Vicinity Fog/Mist | Thunderstorm Showers in Vicinity | Thunderstorm in Vicinity | Thunderstorm in Vicinity Haze | Thunderstorm Haze in Vicinity | Thunderstorm Light Rain Haze | Thunderstorm Heavy Rain Haze | Thunderstorm Fog | Thunderstorm Light Rain Fog | Thunderstorm Heavy Rain Fog | Thunderstorm Hail | Light Thunderstorm Rain Hail | Heavy Thunderstorm Rain Hail | Thunderstorm Rain Hail Fog/Mist | Light Thunderstorm Rain Hail Fog/Mist | Heavy Thunderstorm Rain Hail Fog/Mist | Thunderstorm Showers in Vicinity Hail | | Light Thunderstorm Rain Hail Haze | Heavy Thunderstorm Rain Hail Haze | Thunderstorm Hail Fog | Light Thunderstorm Rain Hail Fog | Heavy Thunderstorm Rain Hail Fog | Thunderstorm Light Rain Hail | Thunderstorm Heavy Rain Hail | Thunderstorm Rain Hail Fog/Mist | Thunderstorm Light Rain Hail Fog/Mist | Thunderstorm Heavy Rain Hail Fog/Mist | Thunderstorm in Vicinity Hail Fog/Mist | Thunderstorm Showers in Vicinity Hail | Thunderstorm in Vicinity Hail | Thunderstorm in Vicinity Hail Haze | Thunderstorm Haze in Vicinity Hail | Thunderstorm Light Rain Hail Haze | Thunderstorm Heavy Rain Hail Haze | Thunderstorm Hail Fog | Thunderstorm Light Rain Hail Fog | Thunderstorm Heavy Rain Hail Fog | Thunderstorm Small Hail/Snow Pellets | Thunderstorm Rain Small Hail/Snow Pellets | Light Thunderstorm Rain Small Hail/Snow Pellets | Heavy Thunderstorm Rain Small Hail/Snow Pellets"; - $retVal['sn']="Snow | Light Snow | Heavy Snow | Snow Showers | Light Snow Showers | Heavy Snow Showers | Showers Snow | Light Showers Snow | Heavy Showers Snow | Snow Fog/Mist | Light Snow Fog/Mist | Heavy Snow Fog/Mist | Snow Showers Fog/Mist | Light Snow Showers Fog/Mist | Heavy Snow Showers Fog/Mist | Showers Snow Fog/Mist | Light Showers Snow Fog/Mist | Heavy Showers Snow Fog/Mist | Snow Fog | Light Snow Fog | Heavy Snow Fog | Snow Showers Fog | Light Snow Showers Fog | Heavy Snow Showers Fog | Showers Snow Fog | Light Showers Snow Fog | Heavy Showers Snow Fog | Showers in Vicinity Snow | Snow Showers in Vicinity | Snow Showers in Vicinity Fog/Mist | Snow Showers in Vicinity Fog | Low Drifting Snow | Blowing Snow | Snow Low Drifting Snow | Snow Blowing Snow | Light Snow Low Drifting Snow | Light Snow Blowing Snow | Heavy Snow Low Drifting Snow | Heavy Snow Blowing Snow | Thunderstorm Snow | Light Thunderstorm Snow | Heavy Thunderstorm Snow | Snow Grains | Light Snow Grains | Heavy Snow Grains | Heavy Blowing Snow | Blowing Snow in Vicinity"; - $retVal['wind']="Windy | Fair and Windy | A Few Clouds and Windy | Partly Cloudy and Windy | Mostly Cloudy and Windy | Overcast and Windy"; - $retVal['hi_shwrs']="Showers in Vicinity | Showers in Vicinity Fog/Mist | Showers in Vicinity Fog | Showers in Vicinity Haze"; - $retVal['fzrara']="Freezing Rain Rain | Light Freezing Rain Rain | Heavy Freezing Rain Rain | Rain Freezing Rain | Light Rain Freezing Rain | Heavy Rain Freezing Rain | Freezing Drizzle Rain | Light Freezing Drizzle Rain | Heavy Freezing Drizzle Rain | Rain Freezing Drizzle | Light Rain Freezing Drizzle | Heavy Rain Freezing Drizzle"; - $retVal['hi_tsra']="Thunderstorm in Vicinity | Thunderstorm in Vicinity Fog/Mist | Thunderstorm in Vicinity Fog | Thunderstorm Haze in Vicinity | Thunderstorm in Vicinity Haze"; - $retVal['ra1']="Light Rain | Drizzle | Light Drizzle | Heavy Drizzle | Light Rain Fog/Mist | Drizzle Fog/Mist | Light Drizzle Fog/Mist | Heavy Drizzle Fog/Mist | Light Rain Fog | Drizzle Fog | Light Drizzle Fog | Heavy Drizzle Fog"; - $retVal['ra']="Rain | Heavy Rain | Rain Fog/Mist | Heavy Rain Fog/Mist | Rain Fog | Heavy Rain Fog"; - $retVal['nsvrtsra']="Funnel Cloud | Funnel Cloud in Vicinity | Tornado/Water Spout"; - $retVal['dust']="Dust | Low Drifting Dust | Blowing Dust | Sand | Blowing Sand | Low Drifting Sand | Dust/Sand Whirls | Dust/Sand Whirls in Vicinity | Dust Storm | Heavy Dust Storm | Dust Storm in Vicinity | Sand Storm | Heavy Sand Storm | Sand Storm in Vicinity"; - $retVal['mist']="Haze"; - return $retVal; - } -// end CLASS -} -?> diff --git a/curweather/test.php b/curweather/test.php deleted file mode 100644 index cd51c23c..00000000 --- a/curweather/test.php +++ /dev/null @@ -1,5 +0,0 @@ - Date: Sat, 11 Jul 2015 20:21:09 +0200 Subject: [PATCH 04/28] added composer.json and needed libs --- curweather/composer.json | 5 + curweather/vendor/autoload.php | 7 + .../cmfcmf/openweathermap-php-api/.gitignore | 1 + .../cmfcmf/openweathermap-php-api/.travis.yml | 22 + .../Cmfcmf/OpenWeatherMap.php | 598 +++++++++++ .../Cmfcmf/OpenWeatherMap/AbstractCache.php | 69 ++ .../Cmfcmf/OpenWeatherMap/CurrentWeather.php | 117 +++ .../Cmfcmf/OpenWeatherMap/Exception.php | 27 + .../OpenWeatherMap/Fetcher/CurlFetcher.php | 42 + .../Fetcher/FetcherInterface.php | 37 + .../Fetcher/FileGetContentsFetcher.php | 34 + .../Cmfcmf/OpenWeatherMap/Forecast.php | 83 ++ .../Cmfcmf/OpenWeatherMap/History.php | 104 ++ .../Cmfcmf/OpenWeatherMap/Util/City.php | 76 ++ .../Cmfcmf/OpenWeatherMap/Util/Sun.php | 52 + .../OpenWeatherMap/Util/Temperature.php | 105 ++ .../Cmfcmf/OpenWeatherMap/Util/Time.php | 65 ++ .../Cmfcmf/OpenWeatherMap/Util/Unit.php | 128 +++ .../Cmfcmf/OpenWeatherMap/Util/Weather.php | 82 ++ .../Cmfcmf/OpenWeatherMap/Util/Wind.php | 48 + .../Cmfcmf/OpenWeatherMap/WeatherForecast.php | 136 +++ .../Cmfcmf/OpenWeatherMap/WeatherHistory.php | 118 +++ .../openweathermap-php-api/Examples/Cache.php | 95 ++ .../Examples/CurrentWeather.php | 236 +++++ .../Examples/WeatherForecast.php | 69 ++ .../Examples/WeatherHistory.php | 43 + .../cmfcmf/openweathermap-php-api/LICENSE | 19 + .../cmfcmf/openweathermap-php-api/README.md | 83 ++ .../openweathermap-php-api/composer.json | 30 + .../openweathermap-php-api/composer.lock | 973 ++++++++++++++++++ .../openweathermap-php-api/phpunit.xml.dist | 22 + .../tests/Fetcher/CurlFetcherTest.php | 53 + .../Fetcher/FileGetContentsFetcherTest.php | 59 ++ .../tests/Util/SunTest.php | 62 ++ .../tests/Util/UnitTest.php | 159 +++ .../tests/bootstrap.php | 12 + curweather/vendor/composer/ClassLoader.php | 413 ++++++++ .../vendor/composer/autoload_classmap.php | 9 + .../vendor/composer/autoload_namespaces.php | 10 + curweather/vendor/composer/autoload_psr4.php | 9 + curweather/vendor/composer/autoload_real.php | 50 + curweather/vendor/composer/installed.json | 51 + 42 files changed, 4413 insertions(+) create mode 100644 curweather/composer.json create mode 100644 curweather/vendor/autoload.php create mode 100644 curweather/vendor/cmfcmf/openweathermap-php-api/.gitignore create mode 100644 curweather/vendor/cmfcmf/openweathermap-php-api/.travis.yml create mode 100644 curweather/vendor/cmfcmf/openweathermap-php-api/Cmfcmf/OpenWeatherMap.php create mode 100644 curweather/vendor/cmfcmf/openweathermap-php-api/Cmfcmf/OpenWeatherMap/AbstractCache.php create mode 100644 curweather/vendor/cmfcmf/openweathermap-php-api/Cmfcmf/OpenWeatherMap/CurrentWeather.php create mode 100644 curweather/vendor/cmfcmf/openweathermap-php-api/Cmfcmf/OpenWeatherMap/Exception.php create mode 100644 curweather/vendor/cmfcmf/openweathermap-php-api/Cmfcmf/OpenWeatherMap/Fetcher/CurlFetcher.php create mode 100644 curweather/vendor/cmfcmf/openweathermap-php-api/Cmfcmf/OpenWeatherMap/Fetcher/FetcherInterface.php create mode 100644 curweather/vendor/cmfcmf/openweathermap-php-api/Cmfcmf/OpenWeatherMap/Fetcher/FileGetContentsFetcher.php create mode 100644 curweather/vendor/cmfcmf/openweathermap-php-api/Cmfcmf/OpenWeatherMap/Forecast.php create mode 100644 curweather/vendor/cmfcmf/openweathermap-php-api/Cmfcmf/OpenWeatherMap/History.php create mode 100644 curweather/vendor/cmfcmf/openweathermap-php-api/Cmfcmf/OpenWeatherMap/Util/City.php create mode 100644 curweather/vendor/cmfcmf/openweathermap-php-api/Cmfcmf/OpenWeatherMap/Util/Sun.php create mode 100644 curweather/vendor/cmfcmf/openweathermap-php-api/Cmfcmf/OpenWeatherMap/Util/Temperature.php create mode 100644 curweather/vendor/cmfcmf/openweathermap-php-api/Cmfcmf/OpenWeatherMap/Util/Time.php create mode 100644 curweather/vendor/cmfcmf/openweathermap-php-api/Cmfcmf/OpenWeatherMap/Util/Unit.php create mode 100644 curweather/vendor/cmfcmf/openweathermap-php-api/Cmfcmf/OpenWeatherMap/Util/Weather.php create mode 100644 curweather/vendor/cmfcmf/openweathermap-php-api/Cmfcmf/OpenWeatherMap/Util/Wind.php create mode 100644 curweather/vendor/cmfcmf/openweathermap-php-api/Cmfcmf/OpenWeatherMap/WeatherForecast.php create mode 100644 curweather/vendor/cmfcmf/openweathermap-php-api/Cmfcmf/OpenWeatherMap/WeatherHistory.php create mode 100644 curweather/vendor/cmfcmf/openweathermap-php-api/Examples/Cache.php create mode 100644 curweather/vendor/cmfcmf/openweathermap-php-api/Examples/CurrentWeather.php create mode 100644 curweather/vendor/cmfcmf/openweathermap-php-api/Examples/WeatherForecast.php create mode 100644 curweather/vendor/cmfcmf/openweathermap-php-api/Examples/WeatherHistory.php create mode 100644 curweather/vendor/cmfcmf/openweathermap-php-api/LICENSE create mode 100644 curweather/vendor/cmfcmf/openweathermap-php-api/README.md create mode 100644 curweather/vendor/cmfcmf/openweathermap-php-api/composer.json create mode 100644 curweather/vendor/cmfcmf/openweathermap-php-api/composer.lock create mode 100644 curweather/vendor/cmfcmf/openweathermap-php-api/phpunit.xml.dist create mode 100644 curweather/vendor/cmfcmf/openweathermap-php-api/tests/Fetcher/CurlFetcherTest.php create mode 100644 curweather/vendor/cmfcmf/openweathermap-php-api/tests/Fetcher/FileGetContentsFetcherTest.php create mode 100644 curweather/vendor/cmfcmf/openweathermap-php-api/tests/Util/SunTest.php create mode 100644 curweather/vendor/cmfcmf/openweathermap-php-api/tests/Util/UnitTest.php create mode 100644 curweather/vendor/cmfcmf/openweathermap-php-api/tests/bootstrap.php create mode 100644 curweather/vendor/composer/ClassLoader.php create mode 100644 curweather/vendor/composer/autoload_classmap.php create mode 100644 curweather/vendor/composer/autoload_namespaces.php create mode 100644 curweather/vendor/composer/autoload_psr4.php create mode 100644 curweather/vendor/composer/autoload_real.php create mode 100644 curweather/vendor/composer/installed.json diff --git a/curweather/composer.json b/curweather/composer.json new file mode 100644 index 00000000..d54ac721 --- /dev/null +++ b/curweather/composer.json @@ -0,0 +1,5 @@ +{ + "require": { + "cmfcmf/openweathermap-php-api": "~2.0" + } +} diff --git a/curweather/vendor/autoload.php b/curweather/vendor/autoload.php new file mode 100644 index 00000000..9e1325a6 --- /dev/null +++ b/curweather/vendor/autoload.php @@ -0,0 +1,7 @@ +OpenWeatherMap.org"; + + /** + * @var \Cmfcmf\OpenWeatherMap\AbstractCache|bool $cacheClass The cache class. + */ + private $cacheClass = false; + + /** + * @var int + */ + private $seconds; + + /** + * @var FetcherInterface The url fetcher. + */ + private $fetcher; + + /** + * Constructs the OpenWeatherMap object. + * + * @param null|FetcherInterface $fetcher The interface to fetch the data from OpenWeatherMap. Defaults to + * CurlFetcher() if cURL is available. Otherwise defaults to + * FileGetContentsFetcher() using 'file_get_contents()'. + * @param bool|string $cacheClass If set to false, caching is disabled. Otherwise this must be a class + * extending AbstractCache. Defaults to false. + * @param int $seconds How long weather data shall be cached. Default 10 minutes. + * + * @throws \Exception If $cache is neither false nor a valid callable extending Cmfcmf\OpenWeatherMap\Util\Cache. + * @api + */ + public function __construct($fetcher = null, $cacheClass = false, $seconds = 600) + { + if ($cacheClass !== false && !($cacheClass instanceof AbstractCache)) { + throw new \Exception("The cache class must implement the FetcherInterface!"); + } + if (!is_numeric($seconds)) { + throw new \Exception("\$seconds must be numeric."); + } + if (!isset($fetcher)) { + $fetcher = (function_exists('curl_version')) ? new CurlFetcher() : new FileGetContentsFetcher(); + } + if ($seconds == 0) { + $cacheClass = false; + } + + $this->cacheClass = $cacheClass; + $this->seconds = $seconds; + $this->fetcher = $fetcher; + } + + /** + * Returns the current weather at the place you specified as an object. + * + * @param array|int|string $query The place to get weather information for. For possible values see below. + * @param string $units Can be either 'metric' or 'imperial' (default). This affects almost all units returned. + * @param string $lang The language to use for descriptions, default is 'en'. For possible values see below. + * @param string $appid Your app id, default ''. See http://openweathermap.org/appid for more details. + * + * @throws OpenWeatherMap\Exception If OpenWeatherMap returns an error. + * @throws \InvalidArgumentException If an argument error occurs. + * + * @return CurrentWeather The weather object. + * + * There are three ways to specify the place to get weather information for: + * - Use the city name: $query must be a string containing the city name. + * - Use the city id: $query must be an integer containing the city id. + * - Use the coordinates: $query must be an associative array containing the 'lat' and 'lon' values. + * + * Available languages are (as of 17. July 2013): + * - English - en + * - Russian - ru + * - Italian - it + * - Spanish - sp + * - Ukrainian - ua + * - German - de + * - Portuguese - pt + * - Romanian - ro + * - Polish - pl + * - Finnish - fi + * - Dutch - nl + * - French - fr + * - Bulgarian - bg + * - Swedish - se + * - Chinese Traditional - zh_tw + * - Chinese Simplified - zh_cn + * - Turkish - tr + * + * @api + */ + public function getWeather($query, $units = 'imperial', $lang = 'en', $appid = '') + { + // Disable default error handling of SimpleXML (Do not throw E_WARNINGs). + libxml_use_internal_errors(true); + libxml_clear_errors(); + + $answer = $this->getRawWeatherData($query, $units, $lang, $appid, 'xml'); + + try { + $xml = new \SimpleXMLElement($answer); + } catch (\Exception $e) { + // Invalid xml format. This happens in case OpenWeatherMap returns an error. + // OpenWeatherMap always uses json for errors, even if one specifies xml as format. + $error = json_decode($answer, true); + if (isset($error['message'])) { + throw new OWMException($error['message'], $error['cod']); + } else { + throw new OWMException('Unknown fatal error: OpenWeatherMap returned the following json object: ' . $answer); + } + } + + return new CurrentWeather($xml, $units); + } + + /** + * Returns the current weather at the place you specified as an object. + * + * @param array|int|string $query The place to get weather information for. For possible values see below. + * @param string $units Can be either 'metric' or 'imperial' (default). This affects almost all units returned. + * @param string $lang The language to use for descriptions, default is 'en'. For possible values see below. + * @param string $appid Your app id, default ''. See http://openweathermap.org/appid for more details. + * @param int $days For how much days you want to get a forecast. Default 1, maximum: 16. + * + * @throws OpenWeatherMap\Exception If OpenWeatherMap returns an error. + * @throws \InvalidArgumentException If an argument error occurs. + * + * @return WeatherForecast The WeatherForecast object. + * + * There are three ways to specify the place to get weather information for: + * - Use the city name: $query must be a string containing the city name. + * - Use the city id: $query must be an integer containing the city id. + * - Use the coordinates: $query must be an associative array containing the 'lat' and 'lon' values. + * + * Available languages are (as of 17. July 2013): + * - English - en + * - Russian - ru + * - Italian - it + * - Spanish - sp + * - Ukrainian - ua + * - German - de + * - Portuguese - pt + * - Romanian - ro + * - Polish - pl + * - Finnish - fi + * - Dutch - nl + * - French - fr + * - Bulgarian - bg + * - Swedish - se + * - Chinese Traditional - zh_tw + * - Chinese Simplified - zh_cn + * - Turkish - tr + * + * @api + */ + public function getWeatherForecast($query, $units = 'imperial', $lang = 'en', $appid = '', $days = 1) + { + // Disable default error handling of SimpleXML (Do not throw E_WARNINGs). + libxml_use_internal_errors(true); + libxml_clear_errors(); + + if ($days <= 5) { + $answer = $this->getRawHourlyForecastData($query, $units, $lang, $appid, 'xml'); + } else if ($days <= 16) { + $answer = $this->getRawDailyForecastData($query, $units, $lang, $appid, 'xml', $days); + } else { + throw new \InvalidArgumentException('Error: forecasts are only available for the next 16 days. $days must be lower than 17.'); + } + + try { + $xml = new \SimpleXMLElement($answer); + } catch (\Exception $e) { + // Invalid xml format. This happens in case OpenWeatherMap returns an error. + // OpenWeatherMap always uses json for errors, even if one specifies xml as format. + $error = json_decode($answer, true); + if (isset($error['message'])) { + throw new OWMException($error['message'], $error['cod']); + } else { + throw new OWMException('Unknown fatal error: OpenWeatherMap returned the following json object: ' . $answer); + } + } + + return new WeatherForecast($xml, $units, $days); + } + + /** + * Returns the weather history for the place you specified as an object. + * + * @param array|int|string $query The place to get weather information for. For possible values see below. + * @param \DateTime $start + * @param int $endOrCount + * @param string $type + * @param string $units Can be either 'metric' or 'imperial' (default). This affects almost all units returned. + * @param string $lang The language to use for descriptions, default is 'en'. For possible values see below. + * @param string $appid Your app id, default ''. See http://openweathermap.org/appid for more details. + * + * @throws OpenWeatherMap\Exception If OpenWeatherMap returns an error. + * @throws \InvalidArgumentException If an argument error occurs. + * + * @return WeatherHistory The WeatherHistory object. + * + * There are three ways to specify the place to get weather information for: + * - Use the city name: $query must be a string containing the city name. + * - Use the city id: $query must be an integer containing the city id. + * - Use the coordinates: $query must be an associative array containing the 'lat' and 'lon' values. + * + * Available languages are (as of 17. July 2013): + * - English - en + * - Russian - ru + * - Italian - it + * - Spanish - sp + * - Ukrainian - ua + * - German - de + * - Portuguese - pt + * - Romanian - ro + * - Polish - pl + * - Finnish - fi + * - Dutch - nl + * - French - fr + * - Bulgarian - bg + * - Swedish - se + * - Chinese Traditional - zh_tw + * - Chinese Simplified - zh_cn + * - Turkish - tr + * + * @api + */ + public function getWeatherHistory($query, \DateTime $start, $endOrCount = 1, $type = 'hour', $units = 'imperial', $lang = 'en', $appid = '') + { + if (!in_array($type, array('tick', 'hour', 'day'))) { + throw new \InvalidArgumentException('$type must be either "tick", "hour" or "day"'); + } + + $xml = json_decode($this->getRawWeatherHistory($query, $start, $endOrCount, $type, $units, $lang, $appid), true); + + if ($xml['cod'] != 200) { + throw new OWMException($xml['message'], $xml['cod']); + } + + return new WeatherHistory($xml, $query); + } + + /** + * @deprecated Use {@link self::getRawWeatherData()} instead. + */ + public function getRawData($query, $units = 'imperial', $lang = 'en', $appid = '', $mode = 'xml') + { + return $this->getRawWeatherData($query, $units, $lang, $appid, $mode); + } + + /** + * Directly returns the xml/json/html string returned by OpenWeatherMap for the current weather. + * + * @param array|int|string $query The place to get weather information for. For possible values see below. + * @param string $units Can be either 'metric' or 'imperial' (default). This affects almost all units returned. + * @param string $lang The language to use for descriptions, default is 'en'. For possible values see below. + * @param string $appid Your app id, default ''. See http://openweathermap.org/appid for more details. + * @param string $mode The format of the data fetched. Possible values are 'json', 'html' and 'xml' (default). + * + * @return string Returns false on failure and the fetched data in the format you specified on success. + * + * Warning If an error occurred, OpenWeatherMap returns data in json format ALWAYS + * + * There are three ways to specify the place to get weather information for: + * - Use the city name: $query must be a string containing the city name. + * - Use the city id: $query must be an integer containing the city id. + * - Use the coordinates: $query must be an associative array containing the 'lat' and 'lon' values. + * + * Available languages are (as of 17. July 2013): + * - English - en + * - Russian - ru + * - Italian - it + * - Spanish - sp + * - Ukrainian - ua + * - German - de + * - Portuguese - pt + * - Romanian - ro + * - Polish - pl + * - Finnish - fi + * - Dutch - nl + * - French - fr + * - Bulgarian - bg + * - Swedish - se + * - Chinese Traditional - zh_tw + * - Chinese Simplified - zh_cn + * - Turkish - tr + * + * @api + */ + public function getRawWeatherData($query, $units = 'imperial', $lang = 'en', $appid = '', $mode = 'xml') + { + $url = $this->buildUrl($query, $units, $lang, $appid, $mode, $this->weatherUrl); + + return $this->cacheOrFetchResult($url); + } + + /** + * Directly returns the xml/json/html string returned by OpenWeatherMap for the hourly forecast. + * + * @param array|int|string $query The place to get weather information for. For possible values see below. + * @param string $units Can be either 'metric' or 'imperial' (default). This affects almost all units returned. + * @param string $lang The language to use for descriptions, default is 'en'. For possible values see below. + * @param string $appid Your app id, default ''. See http://openweathermap.org/appid for more details. + * @param string $mode The format of the data fetched. Possible values are 'json', 'html' and 'xml' (default). + * + * @return string Returns false on failure and the fetched data in the format you specified on success. + * + * Warning If an error occurred, OpenWeatherMap returns data in json format ALWAYS + * + * There are three ways to specify the place to get weather information for: + * - Use the city name: $query must be a string containing the city name. + * - Use the city id: $query must be an integer containing the city id. + * - Use the coordinates: $query must be an associative array containing the 'lat' and 'lon' values. + * + * Available languages are (as of 17. July 2013): + * - English - en + * - Russian - ru + * - Italian - it + * - Spanish - sp + * - Ukrainian - ua + * - German - de + * - Portuguese - pt + * - Romanian - ro + * - Polish - pl + * - Finnish - fi + * - Dutch - nl + * - French - fr + * - Bulgarian - bg + * - Swedish - se + * - Chinese Traditional - zh_tw + * - Chinese Simplified - zh_cn + * - Turkish - tr + * + * @api + */ + public function getRawHourlyForecastData($query, $units = 'imperial', $lang = 'en', $appid = '', $mode = 'xml') + { + $url = $this->buildUrl($query, $units, $lang, $appid, $mode, $this->weatherHourlyForecastUrl); + + return $this->cacheOrFetchResult($url); + } + + /** + * Directly returns the xml/json/html string returned by OpenWeatherMap for the daily forecast. + * + * @param array|int|string $query The place to get weather information for. For possible values see below. + * @param string $units Can be either 'metric' or 'imperial' (default). This affects almost all units returned. + * @param string $lang The language to use for descriptions, default is 'en'. For possible values see below. + * @param string $appid Your app id, default ''. See http://openweathermap.org/appid for more details. + * @param string $mode The format of the data fetched. Possible values are 'json', 'html' and 'xml' (default) + * @param int $cnt How many days of forecast shall be returned? Maximum (and default): 16 + * + * @throws \InvalidArgumentException If $cnt is higher than 16. + * @return string Returns false on failure and the fetched data in the format you specified on success. + * + * Warning If an error occurred, OpenWeatherMap returns data in json format ALWAYS + * + * There are three ways to specify the place to get weather information for: + * - Use the city name: $query must be a string containing the city name. + * - Use the city id: $query must be an integer containing the city id. + * - Use the coordinates: $query must be an associative array containing the 'lat' and 'lon' values. + * + * Available languages are (as of 17. July 2013): + * - English - en + * - Russian - ru + * - Italian - it + * - Spanish - sp + * - Ukrainian - ua + * - German - de + * - Portuguese - pt + * - Romanian - ro + * - Polish - pl + * - Finnish - fi + * - Dutch - nl + * - French - fr + * - Bulgarian - bg + * - Swedish - se + * - Chinese Traditional - zh_tw + * - Chinese Simplified - zh_cn + * - Turkish - tr + * + * @api + */ + public function getRawDailyForecastData($query, $units = 'imperial', $lang = 'en', $appid = '', $mode = 'xml', $cnt = 16) + { + if ($cnt > 16) { + throw new \InvalidArgumentException('$cnt must be 16 or below!'); + } + $url = $this->buildUrl($query, $units, $lang, $appid, $mode, $this->weatherDailyForecastUrl) . "&cnt=$cnt"; + + return $this->cacheOrFetchResult($url); + } + + /** + * Directly returns the xml/json/html string returned by OpenWeatherMap for the daily forecast. + * + * @param array|int|string $query The place to get weather information for. For possible values see below. + * @param \DateTime $start The \DateTime object of the date to get the first weather information from. + * @param \DateTime|int $endOrCount Can be either a \DateTime object representing the end of the period to + * receive weather history data for or an integer counting the number of + * reports requested. + * @param string $type The period of the weather history requested. Can be either be either "tick", + * "hour" or "day". + * @param string $units Can be either 'metric' or 'imperial' (default). This affects almost all units returned. + * @param string $lang The language to use for descriptions, default is 'en'. For possible values see below. + * @param string $appid Your app id, default ''. See http://openweathermap.org/appid for more details. + * + * @throws \InvalidArgumentException + * + * @return string Returns false on failure and the fetched data in the format you specified on success. + * + * Warning If an error occurred, OpenWeatherMap returns data in json format ALWAYS + * + * There are three ways to specify the place to get weather information for: + * - Use the city name: $query must be a string containing the city name. + * - Use the city id: $query must be an integer containing the city id. + * - Use the coordinates: $query must be an associative array containing the 'lat' and 'lon' values. + * + * Available languages are (as of 17. July 2013): + * - English - en + * - Russian - ru + * - Italian - it + * - Spanish - sp + * - Ukrainian - ua + * - German - de + * - Portuguese - pt + * - Romanian - ro + * - Polish - pl + * - Finnish - fi + * - Dutch - nl + * - French - fr + * - Bulgarian - bg + * - Swedish - se + * - Chinese Traditional - zh_tw + * - Chinese Simplified - zh_cn + * - Turkish - tr + * + * @api + */ + public function getRawWeatherHistory($query, \DateTime $start, $endOrCount = 1, $type = 'hour', $units = 'imperial', $lang = 'en', $appid = '') + { + if (!in_array($type, array('tick', 'hour', 'day'))) { + throw new \InvalidArgumentException('$type must be either "tick", "hour" or "day"'); + } + + $queryUrl = $this->weatherHistoryUrl . $this->buildQueryUrlParameter($query) . "&start={$start->format('U')}"; + + if ($endOrCount instanceof \DateTime) { + $queryUrl .= "&end={$endOrCount->format('U')}"; + } else if (is_numeric($endOrCount) && $endOrCount > 0) { + $queryUrl .= "&cnt=$endOrCount"; + } else { + throw new \InvalidArgumentException('$endOrCount must be either a \DateTime or a positive integer.'); + } + $queryUrl .= "&type=$type&units=$units&lang=$lang"; + + if (!empty($appid)) { + $queryUrl .= "&APPID=$appid"; + } + + return $this->cacheOrFetchResult($queryUrl); + } + + /** + * Fetches the result or delivers a cached version of the result. + * + * @param $url + * + * @return string + * + * @internal + */ + private function cacheOrFetchResult($url) + { + if ($this->cacheClass !== false) { + /** @var \Cmfcmf\OpenWeatherMap\AbstractCache $cache */ + $cache = $this->cacheClass; + $cache->setSeconds($this->seconds); + if ($cache->isCached($url)) { + return $cache->getCached($url); + } + $result = $this->fetcher->fetch($url); + $cache->setCached($url, $result); + } else { + $result = $this->fetcher->fetch($url); + } + + return $result; + } + + /** + * Build the url to fetch weather data from. + * + * @param $query + * @param $units + * @param $lang + * @param $appid + * @param $mode + * @param string $url The url to prepend. + * + * @return bool|string The fetched url, false on failure. + * + * @internal + */ + private function buildUrl($query, $units, $lang, $appid, $mode, $url) + { + $queryUrl = $this->buildQueryUrlParameter($query); + + $url = $url . "$queryUrl&units=$units&lang=$lang&mode=$mode"; + if (!empty($appid)) { + $url .= "&APPID=$appid"; + } + + return $url; + } + + /** + * Builds the query string for the url. + * + * @param $query + * + * @return string The built query string for the url. + * @throws \InvalidArgumentException If the query parameter is invalid. + * + * @internal + */ + private function buildQueryUrlParameter($query) + { + switch ($query) { + case (is_array($query) && isset($query['lat']) && isset($query['lon']) && is_numeric($query['lat']) && is_numeric($query['lon'])): + return "lat={$query['lat']}&lon={$query['lon']}"; + case (is_numeric($query)): + return "id=$query"; + case (is_string($query)): + return "q=" . urlencode($query); + default: + throw new \InvalidArgumentException('Error: $query has the wrong format. See the documentation of OpenWeatherMap::getRawData() to read about valid formats.'); + } + } +} diff --git a/curweather/vendor/cmfcmf/openweathermap-php-api/Cmfcmf/OpenWeatherMap/AbstractCache.php b/curweather/vendor/cmfcmf/openweathermap-php-api/Cmfcmf/OpenWeatherMap/AbstractCache.php new file mode 100644 index 00000000..c9b66ebe --- /dev/null +++ b/curweather/vendor/cmfcmf/openweathermap-php-api/Cmfcmf/OpenWeatherMap/AbstractCache.php @@ -0,0 +1,69 @@ +seconds = $seconds; + } +} diff --git a/curweather/vendor/cmfcmf/openweathermap-php-api/Cmfcmf/OpenWeatherMap/CurrentWeather.php b/curweather/vendor/cmfcmf/openweathermap-php-api/Cmfcmf/OpenWeatherMap/CurrentWeather.php new file mode 100644 index 00000000..7ce2e2a1 --- /dev/null +++ b/curweather/vendor/cmfcmf/openweathermap-php-api/Cmfcmf/OpenWeatherMap/CurrentWeather.php @@ -0,0 +1,117 @@ +city = new City($xml->city['id'], $xml->city['name'], $xml->city->coord['lon'], $xml->city->coord['lat'], $xml->city->country); + $this->temperature = new Temperature(new Unit($xml->temperature['value'], $xml->temperature['unit']), new Unit($xml->temperature['min'], $xml->temperature['unit']), new Unit($xml->temperature['max'], $xml->temperature['unit'])); + $this->humidity = new Unit($xml->humidity['value'], $xml->humidity['unit']); + $this->pressure = new Unit($xml->pressure['value'], $xml->pressure['unit']); + + // This is kind of a hack, because the units are missing in the xml document. + if ($units == 'metric') { + $windSpeedUnit = 'm/s'; + } else { + $windSpeedUnit = 'mph'; + } + $this->wind = new Wind(new Unit($xml->wind->speed['value'], $windSpeedUnit, $xml->wind->speed['name']), new Unit($xml->wind->direction['value'], $xml->wind->direction['code'], $xml->wind->direction['name'])); + + $this->clouds = new Unit($xml->clouds['value'], null, $xml->clouds['name']); + $this->precipitation = new Unit($xml->precipitation['value'], $xml->precipitation['unit'], $xml->precipitation['mode']); + $utctz = new \DateTimeZone('UTC'); + $this->sun = new Sun(new \DateTime($xml->city->sun['rise'], $utctz), new \DateTime($xml->city->sun['set'], $utctz)); + $this->weather = new WeatherObj($xml->weather['number'], $xml->weather['value'], $xml->weather['icon']); + $this->lastUpdate = new \DateTime($xml->lastupdate['value'], $utctz); + } +} diff --git a/curweather/vendor/cmfcmf/openweathermap-php-api/Cmfcmf/OpenWeatherMap/Exception.php b/curweather/vendor/cmfcmf/openweathermap-php-api/Cmfcmf/OpenWeatherMap/Exception.php new file mode 100644 index 00000000..20f3a871 --- /dev/null +++ b/curweather/vendor/cmfcmf/openweathermap-php-api/Cmfcmf/OpenWeatherMap/Exception.php @@ -0,0 +1,27 @@ +city = new City($xml->city['id'], $xml->city['name'], $xml->city->coord['lon'], $xml->city->coord['lat'], $xml->city->country); + + if ($units == 'metric') { + $temperatureUnit = "°C"; + } else { + $temperatureUnit = 'F'; + } + + $xml->temperature['value'] = ($xml->temperature['max'] + $xml->temperature['min']) / 2; + + $this->temperature = new Temperature(new Unit($xml->temperature['value'], $temperatureUnit), new Unit($xml->temperature['min'], $temperatureUnit), new Unit($xml->temperature['max'], $temperatureUnit)); + $this->humidity = new Unit($xml->humidity['value'], $xml->humidity['unit']); + $this->pressure = new Unit($xml->pressure['value'], $xml->pressure['unit']); + + // This is kind of a hack, because the units are missing in the xml document. + if ($units == 'metric') { + $windSpeedUnit = 'm/s'; + } else { + $windSpeedUnit = 'mps'; + } + + $this->wind = new Wind(new Unit($xml->windSpeed['mps'], $windSpeedUnit, $xml->windSpeed['name']), new Unit($xml->windDirection['value'], $xml->windDirection['code'], $xml->windDirection['name'])); + $this->clouds = new Unit($xml->clouds['all'], $xml->clouds['unit'], $xml->clouds['value']); + $this->precipitation = new Unit($xml->precipitation['value'], null, $xml->precipitation['type']); + $this->sun = new Sun(new \DateTime($xml->city->sun['rise']), new \DateTime($xml->city->sun['set'])); + $this->weather = new WeatherObj($xml->symbol['number'], $xml->symbol['name'], $xml->symbol['var']); + $this->lastUpdate = new \DateTime($xml->lastupdate['value']); + + if (isset($xml['from'])) { + $this->time = new Time($xml['from'], $xml['to']); + } else { + $this->time = new Time($xml['day']); + } + } +} diff --git a/curweather/vendor/cmfcmf/openweathermap-php-api/Cmfcmf/OpenWeatherMap/History.php b/curweather/vendor/cmfcmf/openweathermap-php-api/Cmfcmf/OpenWeatherMap/History.php new file mode 100644 index 00000000..6601a840 --- /dev/null +++ b/curweather/vendor/cmfcmf/openweathermap-php-api/Cmfcmf/OpenWeatherMap/History.php @@ -0,0 +1,104 @@ +city = $city; + $this->weather = new Weather($weather['id'], $weather['description'], $weather['icon']); + $this->temperature = new Temperature(new Unit($temperature['now'] - 273.15, "\xB0C"), new Unit($temperature['min'] - 273.15, "\xB0C"), new Unit($temperature['max'] - 273.15, "\xB0C")); + $this->pressure = new Unit($pressure, 'kPa'); + $this->humidity = new Unit($humidity, '%'); + $this->clouds = new Unit($clouds, '%'); + $this->precipitation = new Unit($rain['val'], $rain['unit']); + $this->wind = new Wind(new Unit($wind['speed']), new Unit($wind['deg'])); + $this->time = $time; + } +} diff --git a/curweather/vendor/cmfcmf/openweathermap-php-api/Cmfcmf/OpenWeatherMap/Util/City.php b/curweather/vendor/cmfcmf/openweathermap-php-api/Cmfcmf/OpenWeatherMap/Util/City.php new file mode 100644 index 00000000..b5dceb2b --- /dev/null +++ b/curweather/vendor/cmfcmf/openweathermap-php-api/Cmfcmf/OpenWeatherMap/Util/City.php @@ -0,0 +1,76 @@ +id = (int)$id; + $this->name = isset($name) ? (string)$name : null; + $this->lon = isset($lon) ? (float)$lon : null; + $this->lat = isset($lat) ? (float)$lat : null; + $this->country = isset($country) ? (string)$country : null; + $this->population = isset($population) ? (int)$population : null; + } +} diff --git a/curweather/vendor/cmfcmf/openweathermap-php-api/Cmfcmf/OpenWeatherMap/Util/Sun.php b/curweather/vendor/cmfcmf/openweathermap-php-api/Cmfcmf/OpenWeatherMap/Util/Sun.php new file mode 100644 index 00000000..dc0f0104 --- /dev/null +++ b/curweather/vendor/cmfcmf/openweathermap-php-api/Cmfcmf/OpenWeatherMap/Util/Sun.php @@ -0,0 +1,52 @@ +rise = $rise; + $this->set = $set; + } +} diff --git a/curweather/vendor/cmfcmf/openweathermap-php-api/Cmfcmf/OpenWeatherMap/Util/Temperature.php b/curweather/vendor/cmfcmf/openweathermap-php-api/Cmfcmf/OpenWeatherMap/Util/Temperature.php new file mode 100644 index 00000000..14146c06 --- /dev/null +++ b/curweather/vendor/cmfcmf/openweathermap-php-api/Cmfcmf/OpenWeatherMap/Util/Temperature.php @@ -0,0 +1,105 @@ +now->__toString(); + } + + /** + * Returns the current temperature's unit. + * + * @return string The current temperature's unit. + */ + public function getUnit() + { + return $this->now->getUnit(); + } + + /** + * Returns the current temperature. + * + * @return string The current temperature. + */ + public function getValue() + { + return $this->now->getValue(); + } + + /** + * Returns the current temperature's description. + * + * @return string The current temperature's description. + */ + public function getDescription() + { + return $this->now->getDescription(); + } + + /** + * Returns the current temperature as formatted string. + * + * @return string The current temperature as formatted string. + */ + public function getFormatted() + { + return $this->now->getFormatted(); + } + + /** + * Create a new temperature object. + * + * @param Unit $now The current temperature. + * @param Unit $min The minimal temperature. + * @param Unit $max The maximal temperature. + * + * @internal + */ + public function __construct(Unit $now, Unit $min, Unit $max) + { + $this->now = $now; + $this->min = $min; + $this->max = $max; + } +} diff --git a/curweather/vendor/cmfcmf/openweathermap-php-api/Cmfcmf/OpenWeatherMap/Util/Time.php b/curweather/vendor/cmfcmf/openweathermap-php-api/Cmfcmf/OpenWeatherMap/Util/Time.php new file mode 100644 index 00000000..517b4c30 --- /dev/null +++ b/curweather/vendor/cmfcmf/openweathermap-php-api/Cmfcmf/OpenWeatherMap/Util/Time.php @@ -0,0 +1,65 @@ +format('Y-m-d')); + } else { + $from = ($from instanceof \DateTime) ? $from : new \DateTime((string)$from); + $day = clone $from; + $to = clone $from; + $to = $to->add(new \DateInterval('PT23H59M59S')); + } + + $this->from = $from; + $this->to = $to; + $this->day = $day; + } +} diff --git a/curweather/vendor/cmfcmf/openweathermap-php-api/Cmfcmf/OpenWeatherMap/Util/Unit.php b/curweather/vendor/cmfcmf/openweathermap-php-api/Cmfcmf/OpenWeatherMap/Util/Unit.php new file mode 100644 index 00000000..017ff05e --- /dev/null +++ b/curweather/vendor/cmfcmf/openweathermap-php-api/Cmfcmf/OpenWeatherMap/Util/Unit.php @@ -0,0 +1,128 @@ +value = (float)$value; + $this->unit = (string)$unit; + $this->description = (string)$description; + } + + /** + * Get the value as formatted string with unit. + * + * @return string The value as formatted string with unit. + * + * The unit is not included if it is empty. + */ + public function __toString() + { + return $this->getFormatted(); + } + + /** + * Get the value's unit. + * + * @return string The value's unit. + * + * This also converts 'celsius' to '°C' and 'fahrenheit' to 'F'. + */ + public function getUnit() + { + // Units are inconsistent. Only celsius and fahrenheit are not abbreviated. This check fixes that. + if ($this->unit == 'celsius') { + return "°C"; + } else if ($this->unit == 'fahrenheit') { + return 'F'; + } else { + return $this->unit; + } + } + + /** + * Get the value. + * + * @return float The value. + */ + public function getValue() + { + return $this->value; + } + + /** + * Get the value's description. + * + * @return string The value's description. + */ + public function getDescription() + { + return $this->description; + } + + /** + * Get the value as formatted string with unit. + * + * @return string The value as formatted string with unit. + * + * The unit is not included if it is empty. + */ + public function getFormatted() + { + if ($this->getUnit() != "") { + return "{$this->getValue()} {$this->getUnit()}"; + } else { + return "{$this->getValue()}"; + } + } +} diff --git a/curweather/vendor/cmfcmf/openweathermap-php-api/Cmfcmf/OpenWeatherMap/Util/Weather.php b/curweather/vendor/cmfcmf/openweathermap-php-api/Cmfcmf/OpenWeatherMap/Util/Weather.php new file mode 100644 index 00000000..a9d848eb --- /dev/null +++ b/curweather/vendor/cmfcmf/openweathermap-php-api/Cmfcmf/OpenWeatherMap/Util/Weather.php @@ -0,0 +1,82 @@ +id = (int)$id; + $this->description = (string)$description; + $this->icon = (string)$icon; + } + + /** + * Get the weather description. + * + * @return string + */ + public function __toString() + { + return $this->description; + } + + /** + * Get the icon url. + * + * @return string The icon url. + */ + public function getIconUrl() + { + return str_replace("%s", $this->icon, $this->iconUrl); + } +} diff --git a/curweather/vendor/cmfcmf/openweathermap-php-api/Cmfcmf/OpenWeatherMap/Util/Wind.php b/curweather/vendor/cmfcmf/openweathermap-php-api/Cmfcmf/OpenWeatherMap/Util/Wind.php new file mode 100644 index 00000000..02209600 --- /dev/null +++ b/curweather/vendor/cmfcmf/openweathermap-php-api/Cmfcmf/OpenWeatherMap/Util/Wind.php @@ -0,0 +1,48 @@ +speed = $speed; + $this->direction = $direction; + } +} diff --git a/curweather/vendor/cmfcmf/openweathermap-php-api/Cmfcmf/OpenWeatherMap/WeatherForecast.php b/curweather/vendor/cmfcmf/openweathermap-php-api/Cmfcmf/OpenWeatherMap/WeatherForecast.php new file mode 100644 index 00000000..8230989e --- /dev/null +++ b/curweather/vendor/cmfcmf/openweathermap-php-api/Cmfcmf/OpenWeatherMap/WeatherForecast.php @@ -0,0 +1,136 @@ +getWeather(). + * + * @see Cmfcmf\OpenWeatherMap::getWeather() The function using it. + */ +class WeatherForecast implements \Iterator +{ + /** + * A city object. + * + * @var Util\City + */ + public $city; + + /** + * A sun object + * + * @var Util\Sun + */ + public $sun; + + /** + * The time of the last update of this weather data. + * + * @var \DateTime + */ + public $lastUpdate; + + /** + * An array of {@link WeatherForecast} objects. + * + * @var array + * + * @see WeatherForecast The WeatherForecast class. + */ + private $forecasts; + + /** + * @internal + */ + private $position = 0; + + /** + * Create a new Forecast object. + * + * @param $xml + * @param string $units + * @param int $days How many days of forecast to receive. + * + * @internal + */ + public function __construct($xml, $units, $days) + { + $this->city = new City(-1, $xml->location->name, $xml->location->location['longitude'], $xml->location->location['latitude'], $xml->location->country); + $this->sun = new Sun(new \DateTime($xml->sun['rise']), new \DateTime($xml->sun['set'])); + $this->lastUpdate = new \DateTime($xml->meta->lastupdate); + + $counter = 0; + foreach ($xml->forecast->time as $time) { + $forecast = new Forecast($time, $units); + $forecast->city = $this->city; + $this->forecasts[] = $forecast; + + $counter++; + // Make sure to only return the requested number of days. + if ($days <= 5 && $counter == $days * 8) { + break; + } else if ($days > 5 && $counter == $days) { + break; + } + } + } + + /** + * @internal + */ + public function rewind() + { + $this->position = 0; + } + + /** + * @internal + */ + public function current() + { + return $this->forecasts[$this->position]; + } + + /** + * @internal + */ + public function key() + { + return $this->position; + } + + /** + * @internal + */ + public function next() + { + ++$this->position; + } + + /** + * @internal + */ + public function valid() + { + return isset($this->forecasts[$this->position]); + } +} diff --git a/curweather/vendor/cmfcmf/openweathermap-php-api/Cmfcmf/OpenWeatherMap/WeatherHistory.php b/curweather/vendor/cmfcmf/openweathermap-php-api/Cmfcmf/OpenWeatherMap/WeatherHistory.php new file mode 100644 index 00000000..7ee4084a --- /dev/null +++ b/curweather/vendor/cmfcmf/openweathermap-php-api/Cmfcmf/OpenWeatherMap/WeatherHistory.php @@ -0,0 +1,118 @@ +city = new OpenWeatherMap\Util\City($weatherHistory['city_id'], (is_string($query)) ? $query : null, (isset($query['lon'])) ? $query['lon'] : null, (isset($query['lat'])) ? $query['lat'] : null, $country, $population); + $this->calctime = $weatherHistory['calctime']; + + foreach ($weatherHistory['list'] as $history) { + if (isset($history['rain'])) { + $units = array_keys($history['rain']); + } else { + $units = array(0 => null); + } + + $this->histories[] = new History($this->city, $history['weather'][0], array('now' => $history['main']['temp'], 'min' => $history['main']['temp_min'], 'max' => $history['main']['temp_max']), $history['main']['pressure'], $history['main']['humidity'], $history['clouds']['all'], isset($history['rain']) ? array('val' => $history['rain'][($units[0])], 'unit' => $units[0]) : null, $history['wind'], \DateTime::createFromFormat('U', $history['dt'])); + } + } + + /** + * @internal + */ + public function rewind() + { + $this->position = 0; + } + + /** + * @internal + */ + public function current() + { + return $this->histories[$this->position]; + } + + /** + * @internal + */ + public function key() + { + return $this->position; + } + + /** + * @internal + */ + public function next() + { + ++$this->position; + } + + /** + * @internal + */ + public function valid() + { + return isset($this->histories[$this->position]); + } +} diff --git a/curweather/vendor/cmfcmf/openweathermap-php-api/Examples/Cache.php b/curweather/vendor/cmfcmf/openweathermap-php-api/Examples/Cache.php new file mode 100644 index 00000000..61869f2e --- /dev/null +++ b/curweather/vendor/cmfcmf/openweathermap-php-api/Examples/Cache.php @@ -0,0 +1,95 @@ +urlToPath($url); + if (!file_exists($path) || filectime($path) + $this->seconds < time()) { + echo "Weather data is NOT cached!\n"; + + return false; + } + + echo "Weather data is cached!\n"; + + return true; + } + + /** + * @inheritdoc + */ + public function getCached($url) + { + return file_get_contents($this->urlToPath($url)); + } + + /** + * @inheritdoc + */ + public function setCached($url, $content) + { + file_put_contents($this->urlToPath($url), $content); + } +} + +// Language of data (try your own language here!): +$lang = 'de'; + +// Units (can be 'metric' or 'imperial' [default]): +$units = 'metric'; + +// Example 1: Use your own cache implementation. Cache for 10 seconds only in this example. +$owm = new OpenWeatherMap(null, new ExampleCache(), 10); + +$weather = $owm->getWeather('Berlin', $units, $lang); +echo "EXAMPLE 1
\n\n\n"; +echo $weather->temperature; diff --git a/curweather/vendor/cmfcmf/openweathermap-php-api/Examples/CurrentWeather.php b/curweather/vendor/cmfcmf/openweathermap-php-api/Examples/CurrentWeather.php new file mode 100644 index 00000000..46a6c517 --- /dev/null +++ b/curweather/vendor/cmfcmf/openweathermap-php-api/Examples/CurrentWeather.php @@ -0,0 +1,236 @@ +getWeather('Berlin', $units, $lang); +echo "EXAMPLE 1
\n\n\n"; + +// $weather contains all available weather information for Berlin. +// Let's get the temperature: + +// Returns it as formatted string (using __toString()): +echo $weather->temperature; +echo "
\n"; + +// Returns it as formatted string (using a method): +echo $weather->temperature->getFormatted(); +echo "
\n"; + +// Returns the value only: +echo $weather->temperature->getValue(); +echo "
\n"; + +// Returns the unit only: +echo $weather->temperature->getUnit(); +echo "
\n"; + +/** + * In the example above we're using a "shortcut". OpenWeatherMap returns the minimum temperature of a day, + * the maximum temperature and the temperature right now. If you don't specify which temperature you want, it will default + * to the current temperature. See below how to access the other values. Notice that each of them has implemented the methods + * "getFormatted()", "getValue()", "getUnit()". + */ + +// Returns the current temperature: +echo "Current: " . $weather->temperature->now; +echo "
\n"; + +// Returns the minimum temperature: +echo "Minimum: " . $weather->temperature->min; +echo "
\n"; + +// Returns the maximum temperature: +echo "Maximum: " . $weather->temperature->max; +echo "
\n"; + +/** + * When speaking about "current" and "now", this means when the weather data was last updated. You can get this + * via a DateTime object: + */ +echo "Last update: " . $weather->lastUpdate->format('r'); +echo "
\n"; + +// Example 2: Get current pressure and humidity in Hongkong. +$weather = $owm->getWeather('Hongkong', $units, $lang); +echo "

\n\n\nEXAMPLE 2
\n\n\n"; + +/** + * You can use the methods above to only get the value or the unit. + */ + +echo "Pressure: " . $weather->pressure; +echo "
\n"; +echo "Humidity: " . $weather->humidity; +echo "
\n"; + +// Example 3: Get today's sunrise and sunset times. +echo "

\n\n\nEXAMPLE 3
\n\n\n"; + +/** + * These functions return a DateTime object. + */ + +echo "Sunrise: " . $weather->sun->rise->format('r'); +echo "
\n"; +echo "Sunset: " . $weather->sun->set->format('r'); +echo "
\n"; + +// Example 4: Get current temperature from coordinates (Greenland :-) ). +$weather = $owm->getWeather(array('lat' => 77.73038, 'lon' => 41.89604), $units, $lang); +echo "

\n\n\nEXAMPLE 4
\n\n\n"; + +echo "Temperature: " . $weather->temperature; +echo "
\n"; + +// Example 5: Get current temperature from city id. The city is an internal id used by OpenWeatherMap. See example 6 too. +$weather = $owm->getWeather(2172797, $units, $lang); +echo "

\n\n\nEXAMPLE 5
\n\n\n"; + +echo "City: " . $weather->city->name; +echo "
\n"; + +echo "Temperature: " . $weather->temperature; +echo "
\n"; + +// Example 6: Get information about a city. +$weather = $owm->getWeather('Paris', $units, $lang); +echo "

\n\n\nEXAMPLE 6
\n\n\n"; + +echo "Id: " . $weather->city->id; +echo "
\n"; + +echo "Name: " . $weather->city->name; +echo "
\n"; + +echo "Lon: " . $weather->city->lon; +echo "
\n"; + +echo "Lat: " . $weather->city->lat; +echo "
\n"; + +echo "Country: " . $weather->city->country; +echo "
\n"; + +// Example 7: Get wind information. +echo "

\n\n\nEXAMPLE 7
\n\n\n"; + +echo "Speed: " . $weather->wind->speed; +echo "
\n"; + +echo "Direction: " . $weather->wind->direction; +echo "
\n"; + +/** + * For speed and direction there is a description available, which isn't always translated. + */ + +echo "Speed: " . $weather->wind->speed->getDescription(); +echo "
\n"; + +echo "Direction: " . $weather->wind->direction->getDescription(); +echo "
\n"; + +// Example 8: Get information about the clouds. +echo "

\n\n\nEXAMPLE 8
\n\n\n"; + +// The number in braces seems to be an indicator how cloudy the sky is. +echo "Clouds: " . $weather->clouds->getDescription() . " (" . $weather->clouds . ")"; +echo "
\n"; + +// Example 9: Get information about precipitation. +echo "

\n\n\nEXAMPLE 9
\n\n\n"; + +echo "Precipation: " . $weather->precipitation->getDescription() . " (" . $weather->precipitation . ")"; +echo "
\n"; + +// Example 10: Show copyright notice. WARNING: This is no offical text. This hint was created regarding to http://www.http://openweathermap.org/copyright . +echo "

\n\n\nEXAMPLE 10
\n\n\n"; + +echo $owm::COPYRIGHT; +echo "
\n"; + +// Example 11: Get raw xml data. +echo "

\n\n\nEXAMPLE 11
\n\n\n"; + +echo "
" . htmlspecialchars($owm->getRawWeatherData('Berlin', $units, $lang, null, 'xml')) . "
"; +echo "
\n"; + +// Example 12: Get raw json data. +echo "

\n\n\nEXAMPLE 12
\n\n\n"; + +echo "" . htmlspecialchars($owm->getRawWeatherData('Berlin', $units, $lang, null, 'json')) . ""; +echo "
\n"; + +// Example 13: Get raw html data. +echo "

\n\n\nEXAMPLE 13
\n\n\n"; + +echo $owm->getRawWeatherData('Berlin', $units, $lang, null, 'html'); +echo "
\n"; + +// Example 14: Error handling. +echo "

\n\n\nEXAMPLE 14
\n\n\n"; + +// Try wrong city name. +try { + $weather = $owm->getWeather("ThisCityNameIsNotValidAndDoesNotExist", $units, $lang); +} catch (OWMException $e) { + echo $e->getMessage() . ' (Code ' . $e->getCode() . ').'; + echo "
\n"; +} + +// Try invalid $query. +try { + $weather = $owm->getWeather(new \DateTime('now'), $units, $lang); +} catch (\Exception $e) { + echo $e->getMessage() . ' (Code ' . $e->getCode() . ').'; + echo "
\n"; +} + +// Full error handling would look like this: +try { + $weather = $owm->getWeather(-1, $units, $lang); +} catch (OWMException $e) { + echo 'OpenWeatherMap exception: ' . $e->getMessage() . ' (Code ' . $e->getCode() . ').'; + echo "
\n"; +} catch (\Exception $e) { + echo 'General exception: ' . $e->getMessage() . ' (Code ' . $e->getCode() . ').'; + echo "
\n"; +} + +// Example 15: Using an api key: +$owm->getWeather('Berlin', $units, $lang, 'Your-Api-Key-Here'); diff --git a/curweather/vendor/cmfcmf/openweathermap-php-api/Examples/WeatherForecast.php b/curweather/vendor/cmfcmf/openweathermap-php-api/Examples/WeatherForecast.php new file mode 100644 index 00000000..833425bb --- /dev/null +++ b/curweather/vendor/cmfcmf/openweathermap-php-api/Examples/WeatherForecast.php @@ -0,0 +1,69 @@ +getWeatherForecast('Berlin', $units, $lang, '', 10); +echo "EXAMPLE 1
\n\n\n"; + +echo "City: " . $forecast->city->name; +echo "
\n"; +echo "LastUpdate: " . $forecast->lastUpdate->format('d.m.Y H:i'); +echo "
\n"; +echo "Sunrise : " . $forecast->sun->rise->format("H:i:s") . " Sunset : " . $forecast->sun->set->format("H:i:s"); +echo "
\n"; +echo "
\n"; + +foreach ($forecast as $weather) { + // Each $weather contains a Cmfcmf\ForecastWeather object which is almost the same as the Cmfcmf\Weather object. + // Take a look into 'Examples_Current.php' to see the available options. + echo "Weather forecast at " . $weather->time->day->format('d.m.Y') . " from " . $weather->time->from->format('H:i') . " to " . $weather->time->to->format('H:i'); + echo "
\n"; + echo $weather->temperature; + echo "
\n"; + echo "---"; + echo "
\n"; +} + +// Example 2: Get forecast for the next 3 days for Berlin. +$forecast = $owm->getWeatherForecast('Berlin', $units, $lang, '', 3); +echo "EXAMPLE 2
\n\n\n"; + +foreach ($forecast as $weather) { + echo "Weather forecast at " . $weather->time->day->format('d.m.Y') . " from " . $weather->time->from->format('H:i') . " to " . $weather->time->to->format('H:i') . "
"; + echo $weather->temperature . "
\n"; + echo "---
\n"; +} diff --git a/curweather/vendor/cmfcmf/openweathermap-php-api/Examples/WeatherHistory.php b/curweather/vendor/cmfcmf/openweathermap-php-api/Examples/WeatherHistory.php new file mode 100644 index 00000000..c64ee524 --- /dev/null +++ b/curweather/vendor/cmfcmf/openweathermap-php-api/Examples/WeatherHistory.php @@ -0,0 +1,43 @@ +getWeatherHistory('Berlin', new \DateTime('2014-01-01'), new \DateTime('now'), 'hour', $units, $lang); + +foreach ($history as $weather) { + echo "Average temperature at " . $weather->time->format('d.m.Y H:i') . ": " . $weather->temperature . "\n\r
"; +} diff --git a/curweather/vendor/cmfcmf/openweathermap-php-api/LICENSE b/curweather/vendor/cmfcmf/openweathermap-php-api/LICENSE new file mode 100644 index 00000000..1d2c3966 --- /dev/null +++ b/curweather/vendor/cmfcmf/openweathermap-php-api/LICENSE @@ -0,0 +1,19 @@ +Copyright (c) 2013 Christian Flach + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. diff --git a/curweather/vendor/cmfcmf/openweathermap-php-api/README.md b/curweather/vendor/cmfcmf/openweathermap-php-api/README.md new file mode 100644 index 00000000..ea452611 --- /dev/null +++ b/curweather/vendor/cmfcmf/openweathermap-php-api/README.md @@ -0,0 +1,83 @@ +OpenWeatherMap-PHP-Api +====================== +A php api to parse weather data from [OpenWeatherMap.org](http://www.OpenWeatherMap.org). This api tries to normalise and abstract the data and remove inconsistencies. + +[![Build Status](https://travis-ci.org/cmfcmf/OpenWeatherMap-PHP-Api.png?branch=master)](https://travis-ci.org/cmfcmf/OpenWeatherMap-PHP-Api)[![Scrutinizer Quality Score](https://scrutinizer-ci.com/g/cmfcmf/OpenWeatherMap-PHP-Api/badges/quality-score.png?s=f31ca08aa8896416cf162403d34362f0a5da0966)](https://scrutinizer-ci.com/g/cmfcmf/OpenWeatherMap-PHP-Api/)[![Code Coverage](https://scrutinizer-ci.com/g/cmfcmf/OpenWeatherMap-PHP-Api/badges/coverage.png?s=65153e7cfb13e050d734c645e38f2dd7ea7a6860)](https://scrutinizer-ci.com/g/cmfcmf/OpenWeatherMap-PHP-Api/) +[![SensioLabsInsight](https://insight.sensiolabs.com/projects/0addfb24-e2b4-4feb-848e-86b2078ca104/big.png)](https://insight.sensiolabs.com/projects/0addfb24-e2b4-4feb-848e-86b2078ca104) +----------- + +For example code and how to use this api, please take a look into `Examples_*.php` files and run them in your browser. +- `Examples_Current.php` Shows how to receive the current weather. +- `Examples_Forecast.php` Shows how to receive weather forecasts. +- [*NEW*] `Examples_History.php` Shows how to receive weather history. +- `Examples_Cache.php` Shows how to implement a cache. + +**Notice:** This api is not made by OpenWeatherMap, nor their official php api. + +Contribute! +=========== +I'm very happy if you open **pull requests** or **issues** to help making this API **more awesome**. + +Installation +============ +This library can be found on [Packagist](https://packagist.org/packages/cmfcmf/openweathermap-php-api). +The recommended way to install this is through [composer](http://getcomposer.org). + +Edit your `composer.json` and add: + +```json +{ + "require": { + "cmfcmf/openweathermap-php-api": "~2.0" + } +} +``` + +And install dependencies: + +```bash +$ curl -sS https://getcomposer.org/installer | php +$ php composer.phar install +``` + + +Example call +============ +```php +getWeather('Berlin', $units, $lang); +} catch(OWMException $e) { + echo 'OpenWeatherMap exception: ' . $e->getMessage() . ' (Code ' . $e->getCode() . ').'; + echo "
\n"; +} catch(\Exception $e) { + echo 'General exception: ' . $e->getMessage() . ' (Code ' . $e->getCode() . ').'; + echo "
\n"; +} + +echo $weather->temperature; +``` + +License +======= +MIT — Please see the [LICENSE file](https://github.com/Cmfcmf/OpenWeatherMap-PHP-Api/blob/master/LICENSE) distributed with this source code for further information regarding copyright and licensing. + +**Please check out the following links to read about the usage policies and the license of OpenWeatherMap before using the service.** +- [OpenWeatherMap.org](http://www.OpenWeatherMap.org) +- [OpenWeatherMap.org/terms](http://www.OpenWeatherMap.org/terms) +- [OpenWeatherMap.org/appid](http://www.OpenWeatherMap.org/appid) diff --git a/curweather/vendor/cmfcmf/openweathermap-php-api/composer.json b/curweather/vendor/cmfcmf/openweathermap-php-api/composer.json new file mode 100644 index 00000000..687cd4f4 --- /dev/null +++ b/curweather/vendor/cmfcmf/openweathermap-php-api/composer.json @@ -0,0 +1,30 @@ +{ + "name": "cmfcmf/openweathermap-php-api", + "description": "A php api to parse weather data from OpenWeatherMap.org. This api tries to normalise and abstract the data and remove inconsistencies.", + "keywords": ["weather", "OpenWeatherMap", "weather api"], + "homepage": "https://github.com/cmfcmf/OpenWeatherMap-PHP-Api", + "license": "MIT", + "authors": [ + { + "name": "Christian Flach (cmfcmf)", + "email": "cmfcmf.flach@gmail.com", + "homepage": "http://cmfcmf.github.io", + "role": "Developer" + } + ], + "support": { + "issues": "https://github.com/cmfcmf/OpenWeatherMap-PHP-Api/issues", + "source": "https://github.com/cmfcmf/OpenWeatherMap-PHP-Api.git" + }, + "require": { + "php": ">=5.3.0" + }, + "require-dev": { + "phpunit/phpunit": "^4.7.0" + }, + "autoload": { + "psr-0": { + "Cmfcmf\\": "" + } + } +} diff --git a/curweather/vendor/cmfcmf/openweathermap-php-api/composer.lock b/curweather/vendor/cmfcmf/openweathermap-php-api/composer.lock new file mode 100644 index 00000000..5ef16474 --- /dev/null +++ b/curweather/vendor/cmfcmf/openweathermap-php-api/composer.lock @@ -0,0 +1,973 @@ +{ + "_readme": [ + "This file locks the dependencies of your project to a known state", + "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file", + "This file is @generated automatically" + ], + "hash": "23a2734069dc5af143bb0e0a09160885", + "packages": [], + "packages-dev": [ + { + "name": "doctrine/instantiator", + "version": "1.0.5", + "source": { + "type": "git", + "url": "https://github.com/doctrine/instantiator.git", + "reference": "8e884e78f9f0eb1329e445619e04456e64d8051d" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/doctrine/instantiator/zipball/8e884e78f9f0eb1329e445619e04456e64d8051d", + "reference": "8e884e78f9f0eb1329e445619e04456e64d8051d", + "shasum": "" + }, + "require": { + "php": ">=5.3,<8.0-DEV" + }, + "require-dev": { + "athletic/athletic": "~0.1.8", + "ext-pdo": "*", + "ext-phar": "*", + "phpunit/phpunit": "~4.0", + "squizlabs/php_codesniffer": "~2.0" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.0.x-dev" + } + }, + "autoload": { + "psr-4": { + "Doctrine\\Instantiator\\": "src/Doctrine/Instantiator/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Marco Pivetta", + "email": "ocramius@gmail.com", + "homepage": "http://ocramius.github.com/" + } + ], + "description": "A small, lightweight utility to instantiate objects in PHP without invoking their constructors", + "homepage": "https://github.com/doctrine/instantiator", + "keywords": [ + "constructor", + "instantiate" + ], + "time": "2015-06-14 21:17:01" + }, + { + "name": "phpdocumentor/reflection-docblock", + "version": "2.0.4", + "source": { + "type": "git", + "url": "https://github.com/phpDocumentor/ReflectionDocBlock.git", + "reference": "d68dbdc53dc358a816f00b300704702b2eaff7b8" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/phpDocumentor/ReflectionDocBlock/zipball/d68dbdc53dc358a816f00b300704702b2eaff7b8", + "reference": "d68dbdc53dc358a816f00b300704702b2eaff7b8", + "shasum": "" + }, + "require": { + "php": ">=5.3.3" + }, + "require-dev": { + "phpunit/phpunit": "~4.0" + }, + "suggest": { + "dflydev/markdown": "~1.0", + "erusev/parsedown": "~1.0" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "2.0.x-dev" + } + }, + "autoload": { + "psr-0": { + "phpDocumentor": [ + "src/" + ] + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Mike van Riel", + "email": "mike.vanriel@naenius.com" + } + ], + "time": "2015-02-03 12:10:50" + }, + { + "name": "phpspec/prophecy", + "version": "v1.4.1", + "source": { + "type": "git", + "url": "https://github.com/phpspec/prophecy.git", + "reference": "3132b1f44c7bf2ec4c7eb2d3cb78fdeca760d373" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/phpspec/prophecy/zipball/3132b1f44c7bf2ec4c7eb2d3cb78fdeca760d373", + "reference": "3132b1f44c7bf2ec4c7eb2d3cb78fdeca760d373", + "shasum": "" + }, + "require": { + "doctrine/instantiator": "^1.0.2", + "phpdocumentor/reflection-docblock": "~2.0", + "sebastian/comparator": "~1.1" + }, + "require-dev": { + "phpspec/phpspec": "~2.0" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.4.x-dev" + } + }, + "autoload": { + "psr-0": { + "Prophecy\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Konstantin Kudryashov", + "email": "ever.zet@gmail.com", + "homepage": "http://everzet.com" + }, + { + "name": "Marcello Duarte", + "email": "marcello.duarte@gmail.com" + } + ], + "description": "Highly opinionated mocking framework for PHP 5.3+", + "homepage": "https://github.com/phpspec/prophecy", + "keywords": [ + "Double", + "Dummy", + "fake", + "mock", + "spy", + "stub" + ], + "time": "2015-04-27 22:15:08" + }, + { + "name": "phpunit/php-code-coverage", + "version": "2.1.6", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/php-code-coverage.git", + "reference": "631e365cf26bb2c078683e8d9bcf8bc631ac4d44" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/php-code-coverage/zipball/631e365cf26bb2c078683e8d9bcf8bc631ac4d44", + "reference": "631e365cf26bb2c078683e8d9bcf8bc631ac4d44", + "shasum": "" + }, + "require": { + "php": ">=5.3.3", + "phpunit/php-file-iterator": "~1.3", + "phpunit/php-text-template": "~1.2", + "phpunit/php-token-stream": "~1.3", + "sebastian/environment": "~1.0", + "sebastian/version": "~1.0" + }, + "require-dev": { + "ext-xdebug": ">=2.1.4", + "phpunit/phpunit": "~4" + }, + "suggest": { + "ext-dom": "*", + "ext-xdebug": ">=2.2.1", + "ext-xmlwriter": "*" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "2.1.x-dev" + } + }, + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Sebastian Bergmann", + "email": "sb@sebastian-bergmann.de", + "role": "lead" + } + ], + "description": "Library that provides collection, processing, and rendering functionality for PHP code coverage information.", + "homepage": "https://github.com/sebastianbergmann/php-code-coverage", + "keywords": [ + "coverage", + "testing", + "xunit" + ], + "time": "2015-06-19 07:11:55" + }, + { + "name": "phpunit/php-file-iterator", + "version": "1.4.0", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/php-file-iterator.git", + "reference": "a923bb15680d0089e2316f7a4af8f437046e96bb" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/php-file-iterator/zipball/a923bb15680d0089e2316f7a4af8f437046e96bb", + "reference": "a923bb15680d0089e2316f7a4af8f437046e96bb", + "shasum": "" + }, + "require": { + "php": ">=5.3.3" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.4.x-dev" + } + }, + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Sebastian Bergmann", + "email": "sb@sebastian-bergmann.de", + "role": "lead" + } + ], + "description": "FilterIterator implementation that filters files based on a list of suffixes.", + "homepage": "https://github.com/sebastianbergmann/php-file-iterator/", + "keywords": [ + "filesystem", + "iterator" + ], + "time": "2015-04-02 05:19:05" + }, + { + "name": "phpunit/php-text-template", + "version": "1.2.0", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/php-text-template.git", + "reference": "206dfefc0ffe9cebf65c413e3d0e809c82fbf00a" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/php-text-template/zipball/206dfefc0ffe9cebf65c413e3d0e809c82fbf00a", + "reference": "206dfefc0ffe9cebf65c413e3d0e809c82fbf00a", + "shasum": "" + }, + "require": { + "php": ">=5.3.3" + }, + "type": "library", + "autoload": { + "classmap": [ + "Text/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "include-path": [ + "" + ], + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Sebastian Bergmann", + "email": "sb@sebastian-bergmann.de", + "role": "lead" + } + ], + "description": "Simple template engine.", + "homepage": "https://github.com/sebastianbergmann/php-text-template/", + "keywords": [ + "template" + ], + "time": "2014-01-30 17:20:04" + }, + { + "name": "phpunit/php-timer", + "version": "1.0.6", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/php-timer.git", + "reference": "83fe1bdc5d47658b727595c14da140da92b3d66d" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/php-timer/zipball/83fe1bdc5d47658b727595c14da140da92b3d66d", + "reference": "83fe1bdc5d47658b727595c14da140da92b3d66d", + "shasum": "" + }, + "require": { + "php": ">=5.3.3" + }, + "type": "library", + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Sebastian Bergmann", + "email": "sb@sebastian-bergmann.de", + "role": "lead" + } + ], + "description": "Utility class for timing", + "homepage": "https://github.com/sebastianbergmann/php-timer/", + "keywords": [ + "timer" + ], + "time": "2015-06-13 07:35:30" + }, + { + "name": "phpunit/php-token-stream", + "version": "1.4.3", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/php-token-stream.git", + "reference": "7a9b0969488c3c54fd62b4d504b3ec758fd005d9" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/php-token-stream/zipball/7a9b0969488c3c54fd62b4d504b3ec758fd005d9", + "reference": "7a9b0969488c3c54fd62b4d504b3ec758fd005d9", + "shasum": "" + }, + "require": { + "ext-tokenizer": "*", + "php": ">=5.3.3" + }, + "require-dev": { + "phpunit/phpunit": "~4.2" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.4-dev" + } + }, + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Sebastian Bergmann", + "email": "sebastian@phpunit.de" + } + ], + "description": "Wrapper around PHP's tokenizer extension.", + "homepage": "https://github.com/sebastianbergmann/php-token-stream/", + "keywords": [ + "tokenizer" + ], + "time": "2015-06-19 03:43:16" + }, + { + "name": "phpunit/phpunit", + "version": "4.7.4", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/phpunit.git", + "reference": "e5f851f324f7add846316f39e668e9deac97a103" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/phpunit/zipball/e5f851f324f7add846316f39e668e9deac97a103", + "reference": "e5f851f324f7add846316f39e668e9deac97a103", + "shasum": "" + }, + "require": { + "ext-dom": "*", + "ext-json": "*", + "ext-pcre": "*", + "ext-reflection": "*", + "ext-spl": "*", + "php": ">=5.3.3", + "phpspec/prophecy": "~1.3,>=1.3.1", + "phpunit/php-code-coverage": "~2.1", + "phpunit/php-file-iterator": "~1.4", + "phpunit/php-text-template": "~1.2", + "phpunit/php-timer": ">=1.0.6", + "phpunit/phpunit-mock-objects": "~2.3", + "sebastian/comparator": "~1.1", + "sebastian/diff": "~1.2", + "sebastian/environment": "~1.2", + "sebastian/exporter": "~1.2", + "sebastian/global-state": "~1.0", + "sebastian/version": "~1.0", + "symfony/yaml": "~2.1|~3.0" + }, + "suggest": { + "phpunit/php-invoker": "~1.1" + }, + "bin": [ + "phpunit" + ], + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "4.7.x-dev" + } + }, + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Sebastian Bergmann", + "email": "sebastian@phpunit.de", + "role": "lead" + } + ], + "description": "The PHP Unit Testing framework.", + "homepage": "https://phpunit.de/", + "keywords": [ + "phpunit", + "testing", + "xunit" + ], + "time": "2015-06-18 13:33:26" + }, + { + "name": "phpunit/phpunit-mock-objects", + "version": "2.3.4", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/phpunit-mock-objects.git", + "reference": "92408bb1968a81b3217a6fdf6c1a198da83caa35" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/phpunit-mock-objects/zipball/92408bb1968a81b3217a6fdf6c1a198da83caa35", + "reference": "92408bb1968a81b3217a6fdf6c1a198da83caa35", + "shasum": "" + }, + "require": { + "doctrine/instantiator": "~1.0,>=1.0.2", + "php": ">=5.3.3", + "phpunit/php-text-template": "~1.2" + }, + "require-dev": { + "phpunit/phpunit": "~4.4" + }, + "suggest": { + "ext-soap": "*" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "2.3.x-dev" + } + }, + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Sebastian Bergmann", + "email": "sb@sebastian-bergmann.de", + "role": "lead" + } + ], + "description": "Mock Object library for PHPUnit", + "homepage": "https://github.com/sebastianbergmann/phpunit-mock-objects/", + "keywords": [ + "mock", + "xunit" + ], + "time": "2015-06-11 15:55:48" + }, + { + "name": "sebastian/comparator", + "version": "1.1.1", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/comparator.git", + "reference": "1dd8869519a225f7f2b9eb663e225298fade819e" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/comparator/zipball/1dd8869519a225f7f2b9eb663e225298fade819e", + "reference": "1dd8869519a225f7f2b9eb663e225298fade819e", + "shasum": "" + }, + "require": { + "php": ">=5.3.3", + "sebastian/diff": "~1.2", + "sebastian/exporter": "~1.2" + }, + "require-dev": { + "phpunit/phpunit": "~4.4" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.1.x-dev" + } + }, + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Jeff Welch", + "email": "whatthejeff@gmail.com" + }, + { + "name": "Volker Dusch", + "email": "github@wallbash.com" + }, + { + "name": "Bernhard Schussek", + "email": "bschussek@2bepublished.at" + }, + { + "name": "Sebastian Bergmann", + "email": "sebastian@phpunit.de" + } + ], + "description": "Provides the functionality to compare PHP values for equality", + "homepage": "http://www.github.com/sebastianbergmann/comparator", + "keywords": [ + "comparator", + "compare", + "equality" + ], + "time": "2015-01-29 16:28:08" + }, + { + "name": "sebastian/diff", + "version": "1.3.0", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/diff.git", + "reference": "863df9687835c62aa423a22412d26fa2ebde3fd3" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/diff/zipball/863df9687835c62aa423a22412d26fa2ebde3fd3", + "reference": "863df9687835c62aa423a22412d26fa2ebde3fd3", + "shasum": "" + }, + "require": { + "php": ">=5.3.3" + }, + "require-dev": { + "phpunit/phpunit": "~4.2" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.3-dev" + } + }, + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Kore Nordmann", + "email": "mail@kore-nordmann.de" + }, + { + "name": "Sebastian Bergmann", + "email": "sebastian@phpunit.de" + } + ], + "description": "Diff implementation", + "homepage": "http://www.github.com/sebastianbergmann/diff", + "keywords": [ + "diff" + ], + "time": "2015-02-22 15:13:53" + }, + { + "name": "sebastian/environment", + "version": "1.2.2", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/environment.git", + "reference": "5a8c7d31914337b69923db26c4221b81ff5a196e" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/environment/zipball/5a8c7d31914337b69923db26c4221b81ff5a196e", + "reference": "5a8c7d31914337b69923db26c4221b81ff5a196e", + "shasum": "" + }, + "require": { + "php": ">=5.3.3" + }, + "require-dev": { + "phpunit/phpunit": "~4.4" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.3.x-dev" + } + }, + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Sebastian Bergmann", + "email": "sebastian@phpunit.de" + } + ], + "description": "Provides functionality to handle HHVM/PHP environments", + "homepage": "http://www.github.com/sebastianbergmann/environment", + "keywords": [ + "Xdebug", + "environment", + "hhvm" + ], + "time": "2015-01-01 10:01:08" + }, + { + "name": "sebastian/exporter", + "version": "1.2.0", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/exporter.git", + "reference": "84839970d05254c73cde183a721c7af13aede943" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/exporter/zipball/84839970d05254c73cde183a721c7af13aede943", + "reference": "84839970d05254c73cde183a721c7af13aede943", + "shasum": "" + }, + "require": { + "php": ">=5.3.3", + "sebastian/recursion-context": "~1.0" + }, + "require-dev": { + "phpunit/phpunit": "~4.4" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.2.x-dev" + } + }, + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Jeff Welch", + "email": "whatthejeff@gmail.com" + }, + { + "name": "Volker Dusch", + "email": "github@wallbash.com" + }, + { + "name": "Bernhard Schussek", + "email": "bschussek@2bepublished.at" + }, + { + "name": "Sebastian Bergmann", + "email": "sebastian@phpunit.de" + }, + { + "name": "Adam Harvey", + "email": "aharvey@php.net" + } + ], + "description": "Provides the functionality to export PHP variables for visualization", + "homepage": "http://www.github.com/sebastianbergmann/exporter", + "keywords": [ + "export", + "exporter" + ], + "time": "2015-01-27 07:23:06" + }, + { + "name": "sebastian/global-state", + "version": "1.0.0", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/global-state.git", + "reference": "c7428acdb62ece0a45e6306f1ae85e1c05b09c01" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/global-state/zipball/c7428acdb62ece0a45e6306f1ae85e1c05b09c01", + "reference": "c7428acdb62ece0a45e6306f1ae85e1c05b09c01", + "shasum": "" + }, + "require": { + "php": ">=5.3.3" + }, + "require-dev": { + "phpunit/phpunit": "~4.2" + }, + "suggest": { + "ext-uopz": "*" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.0-dev" + } + }, + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Sebastian Bergmann", + "email": "sebastian@phpunit.de" + } + ], + "description": "Snapshotting of global state", + "homepage": "http://www.github.com/sebastianbergmann/global-state", + "keywords": [ + "global state" + ], + "time": "2014-10-06 09:23:50" + }, + { + "name": "sebastian/recursion-context", + "version": "1.0.0", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/recursion-context.git", + "reference": "3989662bbb30a29d20d9faa04a846af79b276252" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/recursion-context/zipball/3989662bbb30a29d20d9faa04a846af79b276252", + "reference": "3989662bbb30a29d20d9faa04a846af79b276252", + "shasum": "" + }, + "require": { + "php": ">=5.3.3" + }, + "require-dev": { + "phpunit/phpunit": "~4.4" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.0.x-dev" + } + }, + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Jeff Welch", + "email": "whatthejeff@gmail.com" + }, + { + "name": "Sebastian Bergmann", + "email": "sebastian@phpunit.de" + }, + { + "name": "Adam Harvey", + "email": "aharvey@php.net" + } + ], + "description": "Provides functionality to recursively process PHP variables", + "homepage": "http://www.github.com/sebastianbergmann/recursion-context", + "time": "2015-01-24 09:48:32" + }, + { + "name": "sebastian/version", + "version": "1.0.5", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/version.git", + "reference": "ab931d46cd0d3204a91e1b9a40c4bc13032b58e4" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/version/zipball/ab931d46cd0d3204a91e1b9a40c4bc13032b58e4", + "reference": "ab931d46cd0d3204a91e1b9a40c4bc13032b58e4", + "shasum": "" + }, + "type": "library", + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Sebastian Bergmann", + "email": "sebastian@phpunit.de", + "role": "lead" + } + ], + "description": "Library that helps with managing the version number of Git-hosted PHP projects", + "homepage": "https://github.com/sebastianbergmann/version", + "time": "2015-02-24 06:35:25" + }, + { + "name": "symfony/yaml", + "version": "v2.7.1", + "source": { + "type": "git", + "url": "https://github.com/symfony/Yaml.git", + "reference": "9808e75c609a14f6db02f70fccf4ca4aab53c160" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/symfony/Yaml/zipball/9808e75c609a14f6db02f70fccf4ca4aab53c160", + "reference": "9808e75c609a14f6db02f70fccf4ca4aab53c160", + "shasum": "" + }, + "require": { + "php": ">=5.3.9" + }, + "require-dev": { + "symfony/phpunit-bridge": "~2.7" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "2.7-dev" + } + }, + "autoload": { + "psr-4": { + "Symfony\\Component\\Yaml\\": "" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Fabien Potencier", + "email": "fabien@symfony.com" + }, + { + "name": "Symfony Community", + "homepage": "https://symfony.com/contributors" + } + ], + "description": "Symfony Yaml Component", + "homepage": "https://symfony.com", + "time": "2015-06-10 15:30:22" + } + ], + "aliases": [], + "minimum-stability": "stable", + "stability-flags": [], + "prefer-stable": false, + "prefer-lowest": false, + "platform": { + "php": ">=5.3.0" + }, + "platform-dev": [] +} diff --git a/curweather/vendor/cmfcmf/openweathermap-php-api/phpunit.xml.dist b/curweather/vendor/cmfcmf/openweathermap-php-api/phpunit.xml.dist new file mode 100644 index 00000000..cceb148d --- /dev/null +++ b/curweather/vendor/cmfcmf/openweathermap-php-api/phpunit.xml.dist @@ -0,0 +1,22 @@ + + + + + + + + ./tests + + + + + + ./ + + ./ + ./ + ./vendor + + + + diff --git a/curweather/vendor/cmfcmf/openweathermap-php-api/tests/Fetcher/CurlFetcherTest.php b/curweather/vendor/cmfcmf/openweathermap-php-api/tests/Fetcher/CurlFetcherTest.php new file mode 100644 index 00000000..7f2cfe9a --- /dev/null +++ b/curweather/vendor/cmfcmf/openweathermap-php-api/tests/Fetcher/CurlFetcherTest.php @@ -0,0 +1,53 @@ +fetch('http://notexisting.example.com'); + + $this->assertSame(false, $content); + } + + public function testEmptyUrl() + { + $fetcher = new CurlFetcher(); + + $content = $fetcher->fetch(''); + + $this->assertSame(false, $content); + } + + public function testValidUrl() + { + $fetcher = new CurlFetcher(); + + $content = $fetcher->fetch('http://httpbin.org/html'); + + $this->assertContains('Herman Melville', $content); + } +} diff --git a/curweather/vendor/cmfcmf/openweathermap-php-api/tests/Fetcher/FileGetContentsFetcherTest.php b/curweather/vendor/cmfcmf/openweathermap-php-api/tests/Fetcher/FileGetContentsFetcherTest.php new file mode 100644 index 00000000..f556c09f --- /dev/null +++ b/curweather/vendor/cmfcmf/openweathermap-php-api/tests/Fetcher/FileGetContentsFetcherTest.php @@ -0,0 +1,59 @@ +markTestSkipped('"allow_url_fopen" is set to off.'); + } + } + + /** + * @expectedException \PHPUnit_Framework_Error_Warning + */ + public function testInvalidUrl() + { + $fetcher = new FileGetContentsFetcher(); + + $fetcher->fetch('http://notexisting.example.com'); + } + + /** + * @expectedException \PHPUnit_Framework_Error_Warning + */ + public function testEmptyUrl() + { + $fetcher = new FileGetContentsFetcher(); + + $fetcher->fetch(''); + } + + public function testValidUrl() + { + $fetcher = new FileGetContentsFetcher(); + + $content = $fetcher->fetch('http://httpbin.org/html'); + + $this->assertContains('Herman Melville', $content); + } +} diff --git a/curweather/vendor/cmfcmf/openweathermap-php-api/tests/Util/SunTest.php b/curweather/vendor/cmfcmf/openweathermap-php-api/tests/Util/SunTest.php new file mode 100644 index 00000000..516a796d --- /dev/null +++ b/curweather/vendor/cmfcmf/openweathermap-php-api/tests/Util/SunTest.php @@ -0,0 +1,62 @@ +givenThereIsASunObject($rise, $set); + + $this->assertSame($rise, $this->sun->rise); + } + + public function testSunSet() + { + $rise = new \DateTime('2014-01-01 08:00:00'); + $set = new \DateTime('2014-01-01 20:00:00'); + + $this->givenThereIsASunObject($rise, $set); + + $this->assertSame($set, $this->sun->set); + } + + + private function givenThereIsASunObject($rise, $set) + { + $this->sun = new Sun($rise, $set); + } + + /** + * @expectedException \LogicException + */ + public function testSunSetBeforeSunRiseException() + { + $rise = new \DateTime('2014-01-01 08:00:00'); + $set = new \DateTime('2014-01-01 7:00:00'); + + $this->givenThereIsASunObject($rise, $set); + } +} diff --git a/curweather/vendor/cmfcmf/openweathermap-php-api/tests/Util/UnitTest.php b/curweather/vendor/cmfcmf/openweathermap-php-api/tests/Util/UnitTest.php new file mode 100644 index 00000000..bd85e16f --- /dev/null +++ b/curweather/vendor/cmfcmf/openweathermap-php-api/tests/Util/UnitTest.php @@ -0,0 +1,159 @@ +givenThereIsAUnitWithValue(self::POSITIVE_INT_VALUE); + + $this->assertSame((float)self::POSITIVE_INT_VALUE, $this->unit->getValue()); + } + + public function testGetValueWithPositiveFloatValue() + { + $this->givenThereIsAUnitWithValue(self::POSITIVE_FLOAT_VALUE); + + $this->assertSame(self::POSITIVE_FLOAT_VALUE, $this->unit->getValue()); + } + + public function testGetValueWithNegativeIntValue() + { + $this->givenThereIsAUnitWithValue(self::NEGATIVE_INT_VALUE); + + $this->assertSame((float)self::NEGATIVE_INT_VALUE, $this->unit->getValue()); + } + + public function testGetValueWithNegativeFloatValue() + { + $this->givenThereIsAUnitWithValue(self::NEGATIVE_FLOAT_VALUE); + + $this->assertSame(self::NEGATIVE_FLOAT_VALUE, $this->unit->getValue()); + } + + public function testGetValueWithZeroIntValue() + { + $this->givenThereIsAUnitWithValue(self::ZERO_INT_VALUE); + + $this->assertSame((float)self::ZERO_INT_VALUE, $this->unit->getValue()); + } + + public function testGetValueWithZeroFloatValue() + { + $this->givenThereIsAUnitWithValue(self::ZERO_FLOAT_VALUE); + + $this->assertSame(self::ZERO_FLOAT_VALUE, $this->unit->getValue()); + } + + private function givenThereIsAUnitWithValue($value, $unit = null) + { + $this->unit = $unit === null ? new Unit($value) : new Unit($value, $unit); + } + + public function testGetUnitWithEmptyUnit() + { + $this->givenThereIsAUnitWithUnit(""); + + $this->assertSame("", $this->unit->getUnit()); + } + + public function testGetUnitWithStringAsUnit() + { + $this->givenThereIsAUnitWithUnit("Hey! I'm cmfcmf"); + + $this->assertSame("Hey! I'm cmfcmf", $this->unit->getUnit()); + } + + public function testCelsiusFixture() + { + $this->givenThereIsAUnitWithUnit("celsius"); + + $this->assertSame("°C", $this->unit->getUnit()); + } + + public function testFahrenheitFixture() + { + $this->givenThereIsAUnitWithUnit("fahrenheit"); + + $this->assertSame("F", $this->unit->getUnit()); + } + + private function givenThereIsAUnitWithUnit($unit) + { + $this->unit = new Unit(0, $unit); + } + + public function testGetDescriptionWithEmptyDescription() + { + $this->givenThereIsAUnitWithDescription(""); + + $this->assertSame("", $this->unit->getDescription()); + } + + public function testGetDescriptionWithStringAsDescription() + { + $this->givenThereIsAUnitWithDescription("Hey! I'm cmfcmf"); + + $this->assertSame("Hey! I'm cmfcmf", $this->unit->getDescription()); + } + + private function givenThereIsAUnitWithDescription($description) + { + $this->unit = new Unit(0, "", $description); + } + + public function testGetFormattedWithoutUnit() + { + $this->givenThereIsAUnitWithValue(self::POSITIVE_INT_VALUE); + + $this->assertEquals(self::POSITIVE_INT_VALUE, $this->unit->getFormatted()); + $this->assertEquals($this->unit->getValue(), $this->unit->getFormatted()); + } + + public function testGetFormattedWithUnit() + { + $this->givenThereIsAUnitWithValue(self::POSITIVE_INT_VALUE, 'K'); + + $this->assertEquals(self::POSITIVE_INT_VALUE . ' K', $this->unit->getFormatted()); + $this->assertEquals($this->unit->getValue() . ' ' . $this->unit->getUnit(), $this->unit->getFormatted()); + } + + public function testToString() + { + $this->givenThereIsAUnitWithValue(self::POSITIVE_INT_VALUE, 'K'); + + $this->assertEquals($this->unit->getFormatted(), $this->unit); + } +} diff --git a/curweather/vendor/cmfcmf/openweathermap-php-api/tests/bootstrap.php b/curweather/vendor/cmfcmf/openweathermap-php-api/tests/bootstrap.php new file mode 100644 index 00000000..a844cc5a --- /dev/null +++ b/curweather/vendor/cmfcmf/openweathermap-php-api/tests/bootstrap.php @@ -0,0 +1,12 @@ + + * Jordi Boggiano + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Composer\Autoload; + +/** + * ClassLoader implements a PSR-0 class loader + * + * See https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-0.md + * + * $loader = new \Composer\Autoload\ClassLoader(); + * + * // register classes with namespaces + * $loader->add('Symfony\Component', __DIR__.'/component'); + * $loader->add('Symfony', __DIR__.'/framework'); + * + * // activate the autoloader + * $loader->register(); + * + * // to enable searching the include path (eg. for PEAR packages) + * $loader->setUseIncludePath(true); + * + * In this example, if you try to use a class in the Symfony\Component + * namespace or one of its children (Symfony\Component\Console for instance), + * the autoloader will first look for the class under the component/ + * directory, and it will then fallback to the framework/ directory if not + * found before giving up. + * + * This class is loosely based on the Symfony UniversalClassLoader. + * + * @author Fabien Potencier + * @author Jordi Boggiano + */ +class ClassLoader +{ + // PSR-4 + private $prefixLengthsPsr4 = array(); + private $prefixDirsPsr4 = array(); + private $fallbackDirsPsr4 = array(); + + // PSR-0 + private $prefixesPsr0 = array(); + private $fallbackDirsPsr0 = array(); + + private $useIncludePath = false; + private $classMap = array(); + + private $classMapAuthoritative = false; + + public function getPrefixes() + { + if (!empty($this->prefixesPsr0)) { + return call_user_func_array('array_merge', $this->prefixesPsr0); + } + + return array(); + } + + public function getPrefixesPsr4() + { + return $this->prefixDirsPsr4; + } + + public function getFallbackDirs() + { + return $this->fallbackDirsPsr0; + } + + public function getFallbackDirsPsr4() + { + return $this->fallbackDirsPsr4; + } + + public function getClassMap() + { + return $this->classMap; + } + + /** + * @param array $classMap Class to filename map + */ + public function addClassMap(array $classMap) + { + if ($this->classMap) { + $this->classMap = array_merge($this->classMap, $classMap); + } else { + $this->classMap = $classMap; + } + } + + /** + * Registers a set of PSR-0 directories for a given prefix, either + * appending or prepending to the ones previously set for this prefix. + * + * @param string $prefix The prefix + * @param array|string $paths The PSR-0 root directories + * @param bool $prepend Whether to prepend the directories + */ + public function add($prefix, $paths, $prepend = false) + { + if (!$prefix) { + if ($prepend) { + $this->fallbackDirsPsr0 = array_merge( + (array) $paths, + $this->fallbackDirsPsr0 + ); + } else { + $this->fallbackDirsPsr0 = array_merge( + $this->fallbackDirsPsr0, + (array) $paths + ); + } + + return; + } + + $first = $prefix[0]; + if (!isset($this->prefixesPsr0[$first][$prefix])) { + $this->prefixesPsr0[$first][$prefix] = (array) $paths; + + return; + } + if ($prepend) { + $this->prefixesPsr0[$first][$prefix] = array_merge( + (array) $paths, + $this->prefixesPsr0[$first][$prefix] + ); + } else { + $this->prefixesPsr0[$first][$prefix] = array_merge( + $this->prefixesPsr0[$first][$prefix], + (array) $paths + ); + } + } + + /** + * Registers a set of PSR-4 directories for a given namespace, either + * appending or prepending to the ones previously set for this namespace. + * + * @param string $prefix The prefix/namespace, with trailing '\\' + * @param array|string $paths The PSR-0 base directories + * @param bool $prepend Whether to prepend the directories + * + * @throws \InvalidArgumentException + */ + public function addPsr4($prefix, $paths, $prepend = false) + { + if (!$prefix) { + // Register directories for the root namespace. + if ($prepend) { + $this->fallbackDirsPsr4 = array_merge( + (array) $paths, + $this->fallbackDirsPsr4 + ); + } else { + $this->fallbackDirsPsr4 = array_merge( + $this->fallbackDirsPsr4, + (array) $paths + ); + } + } elseif (!isset($this->prefixDirsPsr4[$prefix])) { + // Register directories for a new namespace. + $length = strlen($prefix); + if ('\\' !== $prefix[$length - 1]) { + throw new \InvalidArgumentException("A non-empty PSR-4 prefix must end with a namespace separator."); + } + $this->prefixLengthsPsr4[$prefix[0]][$prefix] = $length; + $this->prefixDirsPsr4[$prefix] = (array) $paths; + } elseif ($prepend) { + // Prepend directories for an already registered namespace. + $this->prefixDirsPsr4[$prefix] = array_merge( + (array) $paths, + $this->prefixDirsPsr4[$prefix] + ); + } else { + // Append directories for an already registered namespace. + $this->prefixDirsPsr4[$prefix] = array_merge( + $this->prefixDirsPsr4[$prefix], + (array) $paths + ); + } + } + + /** + * Registers a set of PSR-0 directories for a given prefix, + * replacing any others previously set for this prefix. + * + * @param string $prefix The prefix + * @param array|string $paths The PSR-0 base directories + */ + public function set($prefix, $paths) + { + if (!$prefix) { + $this->fallbackDirsPsr0 = (array) $paths; + } else { + $this->prefixesPsr0[$prefix[0]][$prefix] = (array) $paths; + } + } + + /** + * Registers a set of PSR-4 directories for a given namespace, + * replacing any others previously set for this namespace. + * + * @param string $prefix The prefix/namespace, with trailing '\\' + * @param array|string $paths The PSR-4 base directories + * + * @throws \InvalidArgumentException + */ + public function setPsr4($prefix, $paths) + { + if (!$prefix) { + $this->fallbackDirsPsr4 = (array) $paths; + } else { + $length = strlen($prefix); + if ('\\' !== $prefix[$length - 1]) { + throw new \InvalidArgumentException("A non-empty PSR-4 prefix must end with a namespace separator."); + } + $this->prefixLengthsPsr4[$prefix[0]][$prefix] = $length; + $this->prefixDirsPsr4[$prefix] = (array) $paths; + } + } + + /** + * Turns on searching the include path for class files. + * + * @param bool $useIncludePath + */ + public function setUseIncludePath($useIncludePath) + { + $this->useIncludePath = $useIncludePath; + } + + /** + * Can be used to check if the autoloader uses the include path to check + * for classes. + * + * @return bool + */ + public function getUseIncludePath() + { + return $this->useIncludePath; + } + + /** + * Turns off searching the prefix and fallback directories for classes + * that have not been registered with the class map. + * + * @param bool $classMapAuthoritative + */ + public function setClassMapAuthoritative($classMapAuthoritative) + { + $this->classMapAuthoritative = $classMapAuthoritative; + } + + /** + * Should class lookup fail if not found in the current class map? + * + * @return bool + */ + public function isClassMapAuthoritative() + { + return $this->classMapAuthoritative; + } + + /** + * Registers this instance as an autoloader. + * + * @param bool $prepend Whether to prepend the autoloader or not + */ + public function register($prepend = false) + { + spl_autoload_register(array($this, 'loadClass'), true, $prepend); + } + + /** + * Unregisters this instance as an autoloader. + */ + public function unregister() + { + spl_autoload_unregister(array($this, 'loadClass')); + } + + /** + * Loads the given class or interface. + * + * @param string $class The name of the class + * @return bool|null True if loaded, null otherwise + */ + public function loadClass($class) + { + if ($file = $this->findFile($class)) { + includeFile($file); + + return true; + } + } + + /** + * Finds the path to the file where the class is defined. + * + * @param string $class The name of the class + * + * @return string|false The path if found, false otherwise + */ + public function findFile($class) + { + // work around for PHP 5.3.0 - 5.3.2 https://bugs.php.net/50731 + if ('\\' == $class[0]) { + $class = substr($class, 1); + } + + // class map lookup + if (isset($this->classMap[$class])) { + return $this->classMap[$class]; + } + if ($this->classMapAuthoritative) { + return false; + } + + $file = $this->findFileWithExtension($class, '.php'); + + // Search for Hack files if we are running on HHVM + if ($file === null && defined('HHVM_VERSION')) { + $file = $this->findFileWithExtension($class, '.hh'); + } + + if ($file === null) { + // Remember that this class does not exist. + return $this->classMap[$class] = false; + } + + return $file; + } + + private function findFileWithExtension($class, $ext) + { + // PSR-4 lookup + $logicalPathPsr4 = strtr($class, '\\', DIRECTORY_SEPARATOR) . $ext; + + $first = $class[0]; + if (isset($this->prefixLengthsPsr4[$first])) { + foreach ($this->prefixLengthsPsr4[$first] as $prefix => $length) { + if (0 === strpos($class, $prefix)) { + foreach ($this->prefixDirsPsr4[$prefix] as $dir) { + if (is_file($file = $dir . DIRECTORY_SEPARATOR . substr($logicalPathPsr4, $length))) { + return $file; + } + } + } + } + } + + // PSR-4 fallback dirs + foreach ($this->fallbackDirsPsr4 as $dir) { + if (is_file($file = $dir . DIRECTORY_SEPARATOR . $logicalPathPsr4)) { + return $file; + } + } + + // PSR-0 lookup + if (false !== $pos = strrpos($class, '\\')) { + // namespaced class name + $logicalPathPsr0 = substr($logicalPathPsr4, 0, $pos + 1) + . strtr(substr($logicalPathPsr4, $pos + 1), '_', DIRECTORY_SEPARATOR); + } else { + // PEAR-like class name + $logicalPathPsr0 = strtr($class, '_', DIRECTORY_SEPARATOR) . $ext; + } + + if (isset($this->prefixesPsr0[$first])) { + foreach ($this->prefixesPsr0[$first] as $prefix => $dirs) { + if (0 === strpos($class, $prefix)) { + foreach ($dirs as $dir) { + if (is_file($file = $dir . DIRECTORY_SEPARATOR . $logicalPathPsr0)) { + return $file; + } + } + } + } + } + + // PSR-0 fallback dirs + foreach ($this->fallbackDirsPsr0 as $dir) { + if (is_file($file = $dir . DIRECTORY_SEPARATOR . $logicalPathPsr0)) { + return $file; + } + } + + // PSR-0 include paths. + if ($this->useIncludePath && $file = stream_resolve_include_path($logicalPathPsr0)) { + return $file; + } + } +} + +/** + * Scope isolated include. + * + * Prevents access to $this/self from included files. + */ +function includeFile($file) +{ + include $file; +} diff --git a/curweather/vendor/composer/autoload_classmap.php b/curweather/vendor/composer/autoload_classmap.php new file mode 100644 index 00000000..7a91153b --- /dev/null +++ b/curweather/vendor/composer/autoload_classmap.php @@ -0,0 +1,9 @@ + array($vendorDir . '/cmfcmf/openweathermap-php-api'), +); diff --git a/curweather/vendor/composer/autoload_psr4.php b/curweather/vendor/composer/autoload_psr4.php new file mode 100644 index 00000000..b265c64a --- /dev/null +++ b/curweather/vendor/composer/autoload_psr4.php @@ -0,0 +1,9 @@ + $path) { + $loader->set($namespace, $path); + } + + $map = require __DIR__ . '/autoload_psr4.php'; + foreach ($map as $namespace => $path) { + $loader->setPsr4($namespace, $path); + } + + $classMap = require __DIR__ . '/autoload_classmap.php'; + if ($classMap) { + $loader->addClassMap($classMap); + } + + $loader->register(true); + + return $loader; + } +} + +function composerRequire6bf0e42f34a65c53928f3dc22e5b93d3($file) +{ + require $file; +} diff --git a/curweather/vendor/composer/installed.json b/curweather/vendor/composer/installed.json new file mode 100644 index 00000000..cdba81cc --- /dev/null +++ b/curweather/vendor/composer/installed.json @@ -0,0 +1,51 @@ +[ + { + "name": "cmfcmf/openweathermap-php-api", + "version": "v2.0.7", + "version_normalized": "2.0.7.0", + "source": { + "type": "git", + "url": "https://github.com/cmfcmf/OpenWeatherMap-PHP-Api.git", + "reference": "ab387ebcad332b1e58be443f760e1235e7976443" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/cmfcmf/OpenWeatherMap-PHP-Api/zipball/ab387ebcad332b1e58be443f760e1235e7976443", + "reference": "ab387ebcad332b1e58be443f760e1235e7976443", + "shasum": "" + }, + "require": { + "php": ">=5.3.0" + }, + "require-dev": { + "phpunit/phpunit": "^4.7.0" + }, + "time": "2015-06-23 21:07:37", + "type": "library", + "installation-source": "dist", + "autoload": { + "psr-0": { + "Cmfcmf\\": "" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Christian Flach (cmfcmf)", + "email": "cmfcmf.flach@gmail.com", + "homepage": "http://cmfcmf.github.io", + "role": "Developer" + } + ], + "description": "A php api to parse weather data from OpenWeatherMap.org. This api tries to normalise and abstract the data and remove inconsistencies.", + "homepage": "https://github.com/cmfcmf/OpenWeatherMap-PHP-Api", + "keywords": [ + "OpenWeatherMap", + "weather", + "weather api" + ] + } +] From 4d6cfe14d0c93c93567ca7e73f7740a5a77a4c24 Mon Sep 17 00:00:00 2001 From: Tobias Diekershoff Date: Sat, 11 Jul 2015 20:54:40 +0200 Subject: [PATCH 05/28] curweather update message.po --- curweather/lang/C/messages.po | 76 ++++++++++++++++++++++++++++++----- 1 file changed, 65 insertions(+), 11 deletions(-) diff --git a/curweather/lang/C/messages.po b/curweather/lang/C/messages.po index b462719c..cea93891 100644 --- a/curweather/lang/C/messages.po +++ b/curweather/lang/C/messages.po @@ -8,7 +8,7 @@ msgid "" msgstr "" "Project-Id-Version: \n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2013-02-27 05:01-0500\n" +"POT-Creation-Date: 2015-07-11 20:54+0200\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "Last-Translator: FULL NAME \n" "Language-Team: LANGUAGE \n" @@ -17,26 +17,80 @@ msgstr "" "Content-Type: text/plain; charset=UTF-8\n" "Content-Transfer-Encoding: 8bit\n" -#: curweather.php:46 +#: curweather.php:75 msgid "Current Weather" msgstr "" -#: curweather.php:67 +#: curweather.php:78 +msgid "Relative Humidity" +msgstr "" + +#: curweather.php:79 +msgid "Pressure" +msgstr "" + +#: curweather.php:80 +msgid "Wind" +msgstr "" + +#: curweather.php:81 +msgid "Data by" +msgstr "" + +#: curweather.php:81 +msgid "Show on map" +msgstr "" + +#: curweather.php:97 msgid "Current Weather settings updated." msgstr "" -#: curweather.php:90 -msgid "Current Weather Settings" +#: curweather.php:112 curweather.php:124 +msgid "No APPID found, please contact your admin to optain one." msgstr "" -#: curweather.php:93 -msgid "Weather Location: " +#: curweather.php:122 curweather.php:147 +msgid "Save Settings" msgstr "" -#: curweather.php:96 -msgid "Enable Current Weather" +#: curweather.php:123 +msgid "curweather Settings" msgstr "" -#: curweather.php:104 -msgid "Submit" +#: curweather.php:125 +msgid "Enter either the name of your location or the zip code." +msgstr "" + +#: curweather.php:126 +msgid "Your Location" +msgstr "" + +#: curweather.php:126 +msgid "" +"Identifier of your location (name or zip code), e.g. Berlin,DE or " +"14476,DE." +msgstr "" + +#: curweather.php:127 +msgid "Units" +msgstr "" + +#: curweather.php:127 +msgid "select if the temperatur should be displayed in °C or °F" +msgstr "" + +#: curweather.php:128 +msgid "Show weather data" +msgstr "" + +#: curweather.php:140 +msgid "Curweather settings saved." +msgstr "" + +#: curweather.php:148 +msgid "Your APPID" +msgstr "" + +#: curweather.php:148 +msgid "Your API key provided by OpenWeatherMap" msgstr "" From c1f26a22c361cd20a2b8b2367c9b5005457433e7 Mon Sep 17 00:00:00 2001 From: Tobias Diekershoff Date: Sat, 11 Jul 2015 20:59:00 +0200 Subject: [PATCH 06/28] typo --- curweather/curweather.php | 130 +++++++++++++++++++++++++------------- 1 file changed, 87 insertions(+), 43 deletions(-) diff --git a/curweather/curweather.php b/curweather/curweather.php index 67d5939e..9ad74b48 100644 --- a/curweather/curweather.php +++ b/curweather/curweather.php @@ -1,13 +1,18 @@ - Find the location code for the station or airport nearest you here. - * Version: 1.0 + * Description: Shows current weather conditions for user's location on their network page. + * Version: 1.1 * Author: Tony Baldwin * Author: Fabio Comuni + * Author: Tobias Diekershoff * */ -require_once('addon/curweather/getweather.php'); +use Cmfcmf\OpenWeatherMap; +use Cmfcmf\OpenWeatherMap\Exception as OWMException; + +// Must point to composer's autoload file. +require('vendor/autoload.php'); function curweather_install() { register_hook('network_mod_init', 'addon/curweather/curweather.php', 'curweather_network_mod_init'); @@ -35,21 +40,45 @@ function curweather_network_mod_init(&$fk_app,&$b) { // the $rpt value is needed for location // which getweather uses to fetch the weather data for weather and temp $rpt = get_pconfig(local_user(), 'curweather', 'curweather_loc'); - $wxdata = GetWeather::get($rpt); - $temp = $wxdata['TEMPERATURE_STRING']; - $weather = $wxdata['WEATHER']; - $rhumid = $wxdata['RELATIVE_HUMIDITY']; - $pressure = $wxdata['PRESSURE_STRING']; - $wind = $wxdata['WIND_STRING']; - $curweather = '
-
-

'.t("Current Weather").'

'; - $curweather .= "Weather: $weather
- Temperature: $temp
- Relative Humidity: $rhumid
- Pressure: $pressure
- Wind: $wind"; + + // set the language to the browsers language and use metric units + $lang = $_SESSION['language']; + $units = get_pconfig( local_user(), 'curweather', 'curweather_units'); + $appid = get_config('curweather','appid'); + if ($units==="") + $units = 'metric'; + // Get OpenWeatherMap object. Don't use caching (take a look into + // Example_Cache.php to see how it works). + $owm = new OpenWeatherMap(); + + try { + $weather = $owm->getWeather($rpt, $units, $lang, $appid); + $temp = $weather->temperature->getValue(); + if ( $units === 'metric') { + $temp .= '°C'; + } else { + $temp .= '°F'; + }; + $rhumid = $weather->humidity; + $pressure = $weather->pressure; + $wind = $weather->wind->speed . " " . $weather->wind->direction; + $description = $weather->clouds->getDescription(); + } catch(OWMException $e) { + alert ( 'OpenWeatherMap exception: ' . $e->getMessage() . ' (Code ' . $e->getCode() . ').'); + } catch(\Exception $e) { + alert ('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 .= '
'; @@ -63,6 +92,7 @@ function curweather_plugin_settings_post($a,$post) { return; set_pconfig(local_user(),'curweather','curweather_loc',trim($_POST['curweather_loc'])); set_pconfig(local_user(),'curweather','curweather_enable',intval($_POST['curweather_enable'])); + set_pconfig(local_user(),'curweather','curweather_units',trim($_POST['curweather_units'])); info( t('Current Weather settings updated.') . EOL); } @@ -73,36 +103,50 @@ function curweather_plugin_settings(&$a,&$s) { if(! local_user()) return; - /* Add our stylesheet to the curweather so we can make our settings look nice */ - - $a->page['htmlhead'] .= '' . "\r\n"; - /* Get the current state of our config variable */ $curweather_loc = get_pconfig(local_user(), 'curweather', 'curweather_loc'); + $curweather_units = get_pconfig(local_user(), 'curweather', 'curweather_units'); + $appid = get_config('curweather','appid'); + if (x($appid)) { + $noappidtext = t('No APPID found, please contact your admin to optain one.'); + } else { + $noappidtext = ''; + } $enable = intval(get_pconfig(local_user(),'curweather','curweather_enable')); $enable_checked = (($enable) ? ' checked="checked" ' : ''); - - /* Add some HTML to the existing form */ - - $s .= '
'; - $s .= '

' . t('Current Weather') . '

'; - $s .= '
'; - $s .= '

Find the location code for the airport/weather station nearest you here.

'; - $s .= ''; - $s .= ''; - $s .= '
'; - $s .= ''; - $s .= ''; - $s .= '
'; - - $s .= '
'; - - /* provide a submit button */ - - $s .= '
'; + // load template and replace the macros + $t = get_markup_template("settings.tpl", "addon/curweather/" ); + $s = replace_macros ($t, array( + '$submit' => t('Save Settings'), + '$header' => t('curweather Settings'), + '$noappidtext' => t('No APPID found, please contact your admin to optain one.'), + '$info' => t('Enter either the name of your location or the zip code.'), + '$curweather_loc' => array( 'curweather_loc', t('Your Location'), $curweather_loc, t('Identifier of your location (name or zip code), e.g. Berlin,DE or 14476,DE.') ), + '$curweather_units' => array( 'curweather_units', t('Units'), $curweather_units, t('select if the temperatur should be displayed in °C or °F'), array('metric'=>'°C', 'imperial'=>'°F')), + '$enabled' => array( 'curweather_enable', t('Show weather data'), $enable, '') + )); + return; } - - +// Config stuff for the admin panel to let the admin of the node set a APPID +// for accessing the API of openweathermap +function curweather_plugin_admin_post (&$a) { + if(! is_site_admin()) + return; + if ($_POST['curweather-submit']) { + set_config('curweather','appid',trim($_POST['appid'])); + info( t('Curweather settings saved.'.EOL)); + } +} +function curweather_plugin_admin (&$a, &$o) { + if(! is_site_admin()) + return; + $appid = get_config('curweather','appid'); + $t = get_markup_template("admin.tpl", "addon/curweather/" ); + $o = replace_macros ($t, array( + '$submit' => t('Save Settings'), + '$appid' => array('appid', t('Your APPID'), $appid, t('Your API key provided by OpenWeatherMap')) + )); +} From 1c720a682444bc26cf5c15a37223878afc40f6bf Mon Sep 17 00:00:00 2001 From: Tobias Diekershoff Date: Sun, 12 Jul 2015 08:18:24 +0200 Subject: [PATCH 07/28] cache OWM data --- curweather/curweather.php | 63 +++++++++++++++++++++++++++++++--- curweather/templates/admin.tpl | 1 + 2 files changed, 60 insertions(+), 4 deletions(-) diff --git a/curweather/curweather.php b/curweather/curweather.php index 9ad74b48..33b1df67 100644 --- a/curweather/curweather.php +++ b/curweather/curweather.php @@ -9,6 +9,7 @@ * */ use Cmfcmf\OpenWeatherMap; +use Cmfcmf\OpenWeatherMap\AbstractCache; use Cmfcmf\OpenWeatherMap\Exception as OWMException; // Must point to composer's autoload file. @@ -28,6 +29,51 @@ function curweather_uninstall() { } +// The caching mechanism is taken from the cache example of the +// OpenWeatherMap-PHP-API library and a bit customized to allow admins to set +// the caching time depending on the plans they got from openweathermap.org + +class ExampleCache extends AbstractCache +{ + private function urlToPath($url) + { + $tmp = sys_get_temp_dir(); + $dir = $tmp . DIRECTORY_SEPARATOR . "OpenWeatherMapPHPAPI"; + if (!is_dir($dir)) { + mkdir($dir); + } + + $path = $dir . DIRECTORY_SEPARATOR . md5($url); + return $path; + } + + /** + * @inheritdoc + */ + public function isCached($url) + { + $path = $this->urlToPath($url); + if (!file_exists($path) || filectime($path) + $this->seconds < time()) { + return false; + } + return true; + } + /** + * @inheritdoc + */ + public function getCached($url) + { + return file_get_contents($this->urlToPath($url)); + } + /** + * @inheritdoc + */ + public function setCached($url, $content) + { + file_put_contents($this->urlToPath($url), $content); + } +} + function curweather_network_mod_init(&$fk_app,&$b) { @@ -36,9 +82,14 @@ function curweather_network_mod_init(&$fk_app,&$b) { $fk_app->page['htmlhead'] .= '' . "\r\n"; - // the getweather file does all the work here + // the OpenWeatherMap-PHP-APIlib does all the work here // the $rpt value is needed for location - // which getweather uses to fetch the weather data for weather and temp + // $lang will be taken from the browser session to honour user settings + // $units can be set in the settings by the user + // $appid is configured by the admin in the admin panel + // those parameters will be used to get: cloud status, temperature, preassure + // and relative humidity for display, also the relevent area of the map is + // linked from lat/log of the reply of OWMp $rpt = get_pconfig(local_user(), 'curweather', 'curweather_loc'); @@ -46,11 +97,13 @@ function curweather_network_mod_init(&$fk_app,&$b) { $lang = $_SESSION['language']; $units = get_pconfig( local_user(), 'curweather', 'curweather_units'); $appid = get_config('curweather','appid'); + $cachetime = intval(get_config('curweather','cachetime')); if ($units==="") $units = 'metric'; // 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(); + $owm = new OpenWeatherMap(null, new ExampleCache(), $cachetime); try { $weather = $owm->getWeather($rpt, $units, $lang, $appid); @@ -62,7 +115,7 @@ function curweather_network_mod_init(&$fk_app,&$b) { }; $rhumid = $weather->humidity; $pressure = $weather->pressure; - $wind = $weather->wind->speed . " " . $weather->wind->direction; + $wind = $weather->wind->speed->getDescription().', '.$weather->wind->speed . " " . $weather->wind->direction; $description = $weather->clouds->getDescription(); } catch(OWMException $e) { alert ( 'OpenWeatherMap exception: ' . $e->getMessage() . ' (Code ' . $e->getCode() . ').'); @@ -137,6 +190,7 @@ function curweather_plugin_admin_post (&$a) { return; if ($_POST['curweather-submit']) { set_config('curweather','appid',trim($_POST['appid'])); + set_config('curweather','cachetime',trim($_POST['cachetime'])); info( t('Curweather settings saved.'.EOL)); } } @@ -147,6 +201,7 @@ function curweather_plugin_admin (&$a, &$o) { $t = get_markup_template("admin.tpl", "addon/curweather/" ); $o = replace_macros ($t, array( '$submit' => t('Save Settings'), + '$cachetime' => array('cachetime', t('Caching Interval'), $cachetime, t('For how long should the weather data be cached? Choose according your OpenWeatherMap account type.'), array('0'=>t('no cache'), '300'=>'5 '.t('minutes'), '900'=>'15 '.t('minutes'), '1800'=>'30 '.t('minutes'), '3600'=>'60 '.t('minutes'))), '$appid' => array('appid', t('Your APPID'), $appid, t('Your API key provided by OpenWeatherMap')) )); } diff --git a/curweather/templates/admin.tpl b/curweather/templates/admin.tpl index 5f0c11bf..0d43ae57 100644 --- a/curweather/templates/admin.tpl +++ b/curweather/templates/admin.tpl @@ -1,2 +1,3 @@ {{include file="field_input.tpl" field=$appid}} +{{include file="field_select.tpl" field=$cachetime}}
From cf06804bc82cbf78198bfa0bfa1304391248417c Mon Sep 17 00:00:00 2001 From: Tobias Diekershoff Date: Sun, 12 Jul 2015 08:33:49 +0200 Subject: [PATCH 08/28] include the last time updates as title of the header of the widget --- curweather/curweather.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/curweather/curweather.php b/curweather/curweather.php index 33b1df67..48457fe0 100644 --- a/curweather/curweather.php +++ b/curweather/curweather.php @@ -125,7 +125,7 @@ function curweather_network_mod_init(&$fk_app,&$b) { $curweather = '
-

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

'; +

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

'; $curweather .= "$description; $temp
"; $curweather .= t('Relative Humidity').": $rhumid
"; From 7b1c6557f327383d3a57b9811abdbf9f45d71c58 Mon Sep 17 00:00:00 2001 From: Tobias Diekershoff Date: Sun, 12 Jul 2015 08:52:29 +0200 Subject: [PATCH 09/28] show selected cachetime in admin panel --- curweather/curweather.php | 1 + 1 file changed, 1 insertion(+) diff --git a/curweather/curweather.php b/curweather/curweather.php index 48457fe0..557a10aa 100644 --- a/curweather/curweather.php +++ b/curweather/curweather.php @@ -198,6 +198,7 @@ function curweather_plugin_admin (&$a, &$o) { if(! is_site_admin()) return; $appid = get_config('curweather','appid'); + $cachetime = get_config('curweather','cachetime'); $t = get_markup_template("admin.tpl", "addon/curweather/" ); $o = replace_macros ($t, array( '$submit' => t('Save Settings'), From 040a6be3658e4fe86403697e2396d0a1f82129ce Mon Sep 17 00:00:00 2001 From: Tobias Diekershoff Date: Sun, 12 Jul 2015 08:57:22 +0200 Subject: [PATCH 10/28] updating the message.po for the caching times --- curweather/lang/C/messages.po | 58 +++++++++++++++++++++++------------ 1 file changed, 38 insertions(+), 20 deletions(-) diff --git a/curweather/lang/C/messages.po b/curweather/lang/C/messages.po index cea93891..0a34eb2b 100644 --- a/curweather/lang/C/messages.po +++ b/curweather/lang/C/messages.po @@ -8,7 +8,7 @@ msgid "" msgstr "" "Project-Id-Version: \n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2015-07-11 20:54+0200\n" +"POT-Creation-Date: 2015-07-12 08:56+0200\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "Last-Translator: FULL NAME \n" "Language-Team: LANGUAGE \n" @@ -17,80 +17,98 @@ msgstr "" "Content-Type: text/plain; charset=UTF-8\n" "Content-Transfer-Encoding: 8bit\n" -#: curweather.php:75 +#: curweather.php:128 msgid "Current Weather" msgstr "" -#: curweather.php:78 +#: curweather.php:131 msgid "Relative Humidity" msgstr "" -#: curweather.php:79 +#: curweather.php:132 msgid "Pressure" msgstr "" -#: curweather.php:80 +#: curweather.php:133 msgid "Wind" msgstr "" -#: curweather.php:81 +#: curweather.php:134 msgid "Data by" msgstr "" -#: curweather.php:81 +#: curweather.php:134 msgid "Show on map" msgstr "" -#: curweather.php:97 +#: curweather.php:150 msgid "Current Weather settings updated." msgstr "" -#: curweather.php:112 curweather.php:124 +#: curweather.php:165 curweather.php:177 msgid "No APPID found, please contact your admin to optain one." msgstr "" -#: curweather.php:122 curweather.php:147 +#: curweather.php:175 curweather.php:204 msgid "Save Settings" msgstr "" -#: curweather.php:123 +#: curweather.php:176 msgid "curweather Settings" msgstr "" -#: curweather.php:125 +#: curweather.php:178 msgid "Enter either the name of your location or the zip code." msgstr "" -#: curweather.php:126 +#: curweather.php:179 msgid "Your Location" msgstr "" -#: curweather.php:126 +#: curweather.php:179 msgid "" "Identifier of your location (name or zip code), e.g. Berlin,DE or " "14476,DE." msgstr "" -#: curweather.php:127 +#: curweather.php:180 msgid "Units" msgstr "" -#: curweather.php:127 +#: curweather.php:180 msgid "select if the temperatur should be displayed in °C or °F" msgstr "" -#: curweather.php:128 +#: curweather.php:181 msgid "Show weather data" msgstr "" -#: curweather.php:140 +#: curweather.php:194 msgid "Curweather settings saved." msgstr "" -#: curweather.php:148 +#: curweather.php:205 +msgid "Caching Interval" +msgstr "" + +#: curweather.php:205 +msgid "" +"For how long should the weather data be cached? Choose according your " +"OpenWeatherMap account type." +msgstr "" + +#: curweather.php:205 +msgid "no cache" +msgstr "" + +#: curweather.php:205 +msgid "minutes" +msgstr "" + +#: curweather.php:206 msgid "Your APPID" msgstr "" -#: curweather.php:148 +#: curweather.php:206 msgid "Your API key provided by OpenWeatherMap" msgstr "" From 22cc81cbc5b422d2d4a6d5660c15dcc4574f1484 Mon Sep 17 00:00:00 2001 From: Tobias Diekershoff Date: Sun, 12 Jul 2015 14:30:09 +0200 Subject: [PATCH 11/28] had to remove the time for the last update again --- curweather/curweather.php | 8 ++++---- curweather/lang/C/messages.po | 6 +++--- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/curweather/curweather.php b/curweather/curweather.php index 557a10aa..120545fd 100644 --- a/curweather/curweather.php +++ b/curweather/curweather.php @@ -118,14 +118,14 @@ function curweather_network_mod_init(&$fk_app,&$b) { $wind = $weather->wind->speed->getDescription().', '.$weather->wind->speed . " " . $weather->wind->direction; $description = $weather->clouds->getDescription(); } catch(OWMException $e) { - alert ( 'OpenWeatherMap exception: ' . $e->getMessage() . ' (Code ' . $e->getCode() . ').'); + info ( 'OpenWeatherMap exception: ' . $e->getMessage() . ' (Code ' . $e->getCode() . ').'); } catch(\Exception $e) { - alert ('General exception: ' . $e->getMessage() . ' (Code ' . $e->getCode() . ').'); + info ('General exception: ' . $e->getMessage() . ' (Code ' . $e->getCode() . ').'); } $curweather = '
-

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

'; +

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

'; $curweather .= "$description; $temp
"; $curweather .= t('Relative Humidity').": $rhumid
"; @@ -173,7 +173,7 @@ function curweather_plugin_settings(&$a,&$s) { $t = get_markup_template("settings.tpl", "addon/curweather/" ); $s = replace_macros ($t, array( '$submit' => t('Save Settings'), - '$header' => t('curweather Settings'), + '$header' => t('Current Weather').' '.t('Settings'), '$noappidtext' => t('No APPID found, please contact your admin to optain one.'), '$info' => t('Enter either the name of your location or the zip code.'), '$curweather_loc' => array( 'curweather_loc', t('Your Location'), $curweather_loc, t('Identifier of your location (name or zip code), e.g. Berlin,DE or 14476,DE.') ), diff --git a/curweather/lang/C/messages.po b/curweather/lang/C/messages.po index 0a34eb2b..1b57a529 100644 --- a/curweather/lang/C/messages.po +++ b/curweather/lang/C/messages.po @@ -8,7 +8,7 @@ msgid "" msgstr "" "Project-Id-Version: \n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2015-07-12 08:56+0200\n" +"POT-Creation-Date: 2015-07-12 14:29+0200\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "Last-Translator: FULL NAME \n" "Language-Team: LANGUAGE \n" @@ -17,7 +17,7 @@ msgstr "" "Content-Type: text/plain; charset=UTF-8\n" "Content-Transfer-Encoding: 8bit\n" -#: curweather.php:128 +#: curweather.php:128 curweather.php:176 msgid "Current Weather" msgstr "" @@ -54,7 +54,7 @@ msgid "Save Settings" msgstr "" #: curweather.php:176 -msgid "curweather Settings" +msgid "Settings" msgstr "" #: curweather.php:178 From 867f48aebe52423107dc904c8713621290498df4 Mon Sep 17 00:00:00 2001 From: Tobias Diekershoff Date: Sun, 12 Jul 2015 15:09:04 +0200 Subject: [PATCH 12/28] no appid logic not followed --- curweather/curweather.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/curweather/curweather.php b/curweather/curweather.php index 120545fd..056a5aa3 100644 --- a/curweather/curweather.php +++ b/curweather/curweather.php @@ -161,7 +161,7 @@ function curweather_plugin_settings(&$a,&$s) { $curweather_loc = get_pconfig(local_user(), 'curweather', 'curweather_loc'); $curweather_units = get_pconfig(local_user(), 'curweather', 'curweather_units'); $appid = get_config('curweather','appid'); - if (x($appid)) { + if ($appid=="") { $noappidtext = t('No APPID found, please contact your admin to optain one.'); } else { $noappidtext = ''; @@ -174,7 +174,7 @@ function curweather_plugin_settings(&$a,&$s) { $s = replace_macros ($t, array( '$submit' => t('Save Settings'), '$header' => t('Current Weather').' '.t('Settings'), - '$noappidtext' => t('No APPID found, please contact your admin to optain one.'), + '$noappidtext' => $noappidtext, '$info' => t('Enter either the name of your location or the zip code.'), '$curweather_loc' => array( 'curweather_loc', t('Your Location'), $curweather_loc, t('Identifier of your location (name or zip code), e.g. Berlin,DE or 14476,DE.') ), '$curweather_units' => array( 'curweather_units', t('Units'), $curweather_units, t('select if the temperatur should be displayed in °C or °F'), array('metric'=>'°C', 'imperial'=>'°F')), From 02b29b2a6a5e9c8c10999feec9b270967c4050ba Mon Sep 17 00:00:00 2001 From: Tobias Diekershoff Date: Sun, 12 Jul 2015 15:39:49 +0200 Subject: [PATCH 13/28] use friendica temppath settings for cache data --- curweather/curweather.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/curweather/curweather.php b/curweather/curweather.php index 056a5aa3..6db89428 100644 --- a/curweather/curweather.php +++ b/curweather/curweather.php @@ -32,12 +32,13 @@ function curweather_uninstall() { // The caching mechanism is taken from the cache example of the // OpenWeatherMap-PHP-API library and a bit customized to allow admins to set // the caching time depending on the plans they got from openweathermap.org +// and the usage of the friendica temppath class ExampleCache extends AbstractCache { private function urlToPath($url) { - $tmp = sys_get_temp_dir(); + $tmp = get_config('system','temppath'); $dir = $tmp . DIRECTORY_SEPARATOR . "OpenWeatherMapPHPAPI"; if (!is_dir($dir)) { mkdir($dir); From f9c887e24df56d3ef46beae065f55a9ec3caaaf5 Mon Sep 17 00:00:00 2001 From: Tobias Diekershoff Date: Mon, 13 Jul 2015 07:05:55 +0200 Subject: [PATCH 14/28] 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}} +

    +
  • {{$relhumidity['caption']}}: {{$relhumidity['val']}}
  • +
  • {{$pressure['caption']}}: {{$pressure['val']}}
  • +
  • {{$wind['caption']}}: {{$wind['val']}}
  • +

+ +
+
From c02fef3e1f0eafe4935cc4c8950e6263d1b51e36 Mon Sep 17 00:00:00 2001 From: Tobias Diekershoff Date: Mon, 13 Jul 2015 08:16:41 +0200 Subject: [PATCH 15/28] minor additions to the README --- curweather/README.md | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/curweather/README.md b/curweather/README.md index 720f92cf..140e171e 100644 --- a/curweather/README.md +++ b/curweather/README.md @@ -2,13 +2,13 @@ Current Weather =============== If activated by your user this addon adds a widget to the users network tab -sidebar showing current weather informations from -[OpenWeatherMap](http://openweathermap.org). The user can configure the -location as e.g. *Berlin,DE* or the zip code "14476,DE". +sidebar showing current weather informations (temperature, relative humidity, +wind conditions and preassure) from [OpenWeatherMap](http://openweathermap.org). +The user can configure the location as e.g. *Berlin,DE* or the zip code "14476,DE". The language for the request at OpenWeatherMap is set to the UI language of friendica. If the string for the description of the current weather conditions -is available in this language depends on OpenWeatherMap. +is available in this language depends on OpenWeatherMap, fallback is english. **You should get an APPID from OpenWeatherMap if you want to use this widget.** You can register [here](http://openweathermap.org/register). @@ -16,12 +16,12 @@ You can register [here](http://openweathermap.org/register). Credits ------- -* Tony Baldvin wrote the original addon for Friendica +* Tony Baldwin wrote the original addon for Friendica * Fabio Comuni * Tobias Diekershoff switched the sources to OpenWeatherMap after the original provider turned off support for locations outside of the USA. To access the API of OpenWeatherMap the library -[OpenWeatherMap-PHP-Api](https://github.com/cmfcmf/OpenWeatherMap-PHP-Api) by +[OpenWeatherMap-PHP-API](https://github.com/cmfcmf/OpenWeatherMap-PHP-Api) by Christian Flach is used (MIT license). From 0d31af52ea0b85f0aaf84227c61dee8b8d48656e Mon Sep 17 00:00:00 2001 From: Tobias Diekershoff Date: Mon, 13 Jul 2015 09:13:54 +0200 Subject: [PATCH 16/28] Revert "added composer.json and needed libs" This reverts commit 1f74d409a2ff1dc64afb5ff075684356275fc3aa. --- curweather/composer.json | 5 - curweather/vendor/autoload.php | 7 - .../cmfcmf/openweathermap-php-api/.gitignore | 1 - .../cmfcmf/openweathermap-php-api/.travis.yml | 22 - .../Cmfcmf/OpenWeatherMap.php | 598 ----------- .../Cmfcmf/OpenWeatherMap/AbstractCache.php | 69 -- .../Cmfcmf/OpenWeatherMap/CurrentWeather.php | 117 --- .../Cmfcmf/OpenWeatherMap/Exception.php | 27 - .../OpenWeatherMap/Fetcher/CurlFetcher.php | 42 - .../Fetcher/FetcherInterface.php | 37 - .../Fetcher/FileGetContentsFetcher.php | 34 - .../Cmfcmf/OpenWeatherMap/Forecast.php | 83 -- .../Cmfcmf/OpenWeatherMap/History.php | 104 -- .../Cmfcmf/OpenWeatherMap/Util/City.php | 76 -- .../Cmfcmf/OpenWeatherMap/Util/Sun.php | 52 - .../OpenWeatherMap/Util/Temperature.php | 105 -- .../Cmfcmf/OpenWeatherMap/Util/Time.php | 65 -- .../Cmfcmf/OpenWeatherMap/Util/Unit.php | 128 --- .../Cmfcmf/OpenWeatherMap/Util/Weather.php | 82 -- .../Cmfcmf/OpenWeatherMap/Util/Wind.php | 48 - .../Cmfcmf/OpenWeatherMap/WeatherForecast.php | 136 --- .../Cmfcmf/OpenWeatherMap/WeatherHistory.php | 118 --- .../openweathermap-php-api/Examples/Cache.php | 95 -- .../Examples/CurrentWeather.php | 236 ----- .../Examples/WeatherForecast.php | 69 -- .../Examples/WeatherHistory.php | 43 - .../cmfcmf/openweathermap-php-api/LICENSE | 19 - .../cmfcmf/openweathermap-php-api/README.md | 83 -- .../openweathermap-php-api/composer.json | 30 - .../openweathermap-php-api/composer.lock | 973 ------------------ .../openweathermap-php-api/phpunit.xml.dist | 22 - .../tests/Fetcher/CurlFetcherTest.php | 53 - .../Fetcher/FileGetContentsFetcherTest.php | 59 -- .../tests/Util/SunTest.php | 62 -- .../tests/Util/UnitTest.php | 159 --- .../tests/bootstrap.php | 12 - curweather/vendor/composer/ClassLoader.php | 413 -------- .../vendor/composer/autoload_classmap.php | 9 - .../vendor/composer/autoload_namespaces.php | 10 - curweather/vendor/composer/autoload_psr4.php | 9 - curweather/vendor/composer/autoload_real.php | 50 - curweather/vendor/composer/installed.json | 51 - 42 files changed, 4413 deletions(-) delete mode 100644 curweather/composer.json delete mode 100644 curweather/vendor/autoload.php delete mode 100644 curweather/vendor/cmfcmf/openweathermap-php-api/.gitignore delete mode 100644 curweather/vendor/cmfcmf/openweathermap-php-api/.travis.yml delete mode 100644 curweather/vendor/cmfcmf/openweathermap-php-api/Cmfcmf/OpenWeatherMap.php delete mode 100644 curweather/vendor/cmfcmf/openweathermap-php-api/Cmfcmf/OpenWeatherMap/AbstractCache.php delete mode 100644 curweather/vendor/cmfcmf/openweathermap-php-api/Cmfcmf/OpenWeatherMap/CurrentWeather.php delete mode 100644 curweather/vendor/cmfcmf/openweathermap-php-api/Cmfcmf/OpenWeatherMap/Exception.php delete mode 100644 curweather/vendor/cmfcmf/openweathermap-php-api/Cmfcmf/OpenWeatherMap/Fetcher/CurlFetcher.php delete mode 100644 curweather/vendor/cmfcmf/openweathermap-php-api/Cmfcmf/OpenWeatherMap/Fetcher/FetcherInterface.php delete mode 100644 curweather/vendor/cmfcmf/openweathermap-php-api/Cmfcmf/OpenWeatherMap/Fetcher/FileGetContentsFetcher.php delete mode 100644 curweather/vendor/cmfcmf/openweathermap-php-api/Cmfcmf/OpenWeatherMap/Forecast.php delete mode 100644 curweather/vendor/cmfcmf/openweathermap-php-api/Cmfcmf/OpenWeatherMap/History.php delete mode 100644 curweather/vendor/cmfcmf/openweathermap-php-api/Cmfcmf/OpenWeatherMap/Util/City.php delete mode 100644 curweather/vendor/cmfcmf/openweathermap-php-api/Cmfcmf/OpenWeatherMap/Util/Sun.php delete mode 100644 curweather/vendor/cmfcmf/openweathermap-php-api/Cmfcmf/OpenWeatherMap/Util/Temperature.php delete mode 100644 curweather/vendor/cmfcmf/openweathermap-php-api/Cmfcmf/OpenWeatherMap/Util/Time.php delete mode 100644 curweather/vendor/cmfcmf/openweathermap-php-api/Cmfcmf/OpenWeatherMap/Util/Unit.php delete mode 100644 curweather/vendor/cmfcmf/openweathermap-php-api/Cmfcmf/OpenWeatherMap/Util/Weather.php delete mode 100644 curweather/vendor/cmfcmf/openweathermap-php-api/Cmfcmf/OpenWeatherMap/Util/Wind.php delete mode 100644 curweather/vendor/cmfcmf/openweathermap-php-api/Cmfcmf/OpenWeatherMap/WeatherForecast.php delete mode 100644 curweather/vendor/cmfcmf/openweathermap-php-api/Cmfcmf/OpenWeatherMap/WeatherHistory.php delete mode 100644 curweather/vendor/cmfcmf/openweathermap-php-api/Examples/Cache.php delete mode 100644 curweather/vendor/cmfcmf/openweathermap-php-api/Examples/CurrentWeather.php delete mode 100644 curweather/vendor/cmfcmf/openweathermap-php-api/Examples/WeatherForecast.php delete mode 100644 curweather/vendor/cmfcmf/openweathermap-php-api/Examples/WeatherHistory.php delete mode 100644 curweather/vendor/cmfcmf/openweathermap-php-api/LICENSE delete mode 100644 curweather/vendor/cmfcmf/openweathermap-php-api/README.md delete mode 100644 curweather/vendor/cmfcmf/openweathermap-php-api/composer.json delete mode 100644 curweather/vendor/cmfcmf/openweathermap-php-api/composer.lock delete mode 100644 curweather/vendor/cmfcmf/openweathermap-php-api/phpunit.xml.dist delete mode 100644 curweather/vendor/cmfcmf/openweathermap-php-api/tests/Fetcher/CurlFetcherTest.php delete mode 100644 curweather/vendor/cmfcmf/openweathermap-php-api/tests/Fetcher/FileGetContentsFetcherTest.php delete mode 100644 curweather/vendor/cmfcmf/openweathermap-php-api/tests/Util/SunTest.php delete mode 100644 curweather/vendor/cmfcmf/openweathermap-php-api/tests/Util/UnitTest.php delete mode 100644 curweather/vendor/cmfcmf/openweathermap-php-api/tests/bootstrap.php delete mode 100644 curweather/vendor/composer/ClassLoader.php delete mode 100644 curweather/vendor/composer/autoload_classmap.php delete mode 100644 curweather/vendor/composer/autoload_namespaces.php delete mode 100644 curweather/vendor/composer/autoload_psr4.php delete mode 100644 curweather/vendor/composer/autoload_real.php delete mode 100644 curweather/vendor/composer/installed.json diff --git a/curweather/composer.json b/curweather/composer.json deleted file mode 100644 index d54ac721..00000000 --- a/curweather/composer.json +++ /dev/null @@ -1,5 +0,0 @@ -{ - "require": { - "cmfcmf/openweathermap-php-api": "~2.0" - } -} diff --git a/curweather/vendor/autoload.php b/curweather/vendor/autoload.php deleted file mode 100644 index 9e1325a6..00000000 --- a/curweather/vendor/autoload.php +++ /dev/null @@ -1,7 +0,0 @@ -OpenWeatherMap.org"; - - /** - * @var \Cmfcmf\OpenWeatherMap\AbstractCache|bool $cacheClass The cache class. - */ - private $cacheClass = false; - - /** - * @var int - */ - private $seconds; - - /** - * @var FetcherInterface The url fetcher. - */ - private $fetcher; - - /** - * Constructs the OpenWeatherMap object. - * - * @param null|FetcherInterface $fetcher The interface to fetch the data from OpenWeatherMap. Defaults to - * CurlFetcher() if cURL is available. Otherwise defaults to - * FileGetContentsFetcher() using 'file_get_contents()'. - * @param bool|string $cacheClass If set to false, caching is disabled. Otherwise this must be a class - * extending AbstractCache. Defaults to false. - * @param int $seconds How long weather data shall be cached. Default 10 minutes. - * - * @throws \Exception If $cache is neither false nor a valid callable extending Cmfcmf\OpenWeatherMap\Util\Cache. - * @api - */ - public function __construct($fetcher = null, $cacheClass = false, $seconds = 600) - { - if ($cacheClass !== false && !($cacheClass instanceof AbstractCache)) { - throw new \Exception("The cache class must implement the FetcherInterface!"); - } - if (!is_numeric($seconds)) { - throw new \Exception("\$seconds must be numeric."); - } - if (!isset($fetcher)) { - $fetcher = (function_exists('curl_version')) ? new CurlFetcher() : new FileGetContentsFetcher(); - } - if ($seconds == 0) { - $cacheClass = false; - } - - $this->cacheClass = $cacheClass; - $this->seconds = $seconds; - $this->fetcher = $fetcher; - } - - /** - * Returns the current weather at the place you specified as an object. - * - * @param array|int|string $query The place to get weather information for. For possible values see below. - * @param string $units Can be either 'metric' or 'imperial' (default). This affects almost all units returned. - * @param string $lang The language to use for descriptions, default is 'en'. For possible values see below. - * @param string $appid Your app id, default ''. See http://openweathermap.org/appid for more details. - * - * @throws OpenWeatherMap\Exception If OpenWeatherMap returns an error. - * @throws \InvalidArgumentException If an argument error occurs. - * - * @return CurrentWeather The weather object. - * - * There are three ways to specify the place to get weather information for: - * - Use the city name: $query must be a string containing the city name. - * - Use the city id: $query must be an integer containing the city id. - * - Use the coordinates: $query must be an associative array containing the 'lat' and 'lon' values. - * - * Available languages are (as of 17. July 2013): - * - English - en - * - Russian - ru - * - Italian - it - * - Spanish - sp - * - Ukrainian - ua - * - German - de - * - Portuguese - pt - * - Romanian - ro - * - Polish - pl - * - Finnish - fi - * - Dutch - nl - * - French - fr - * - Bulgarian - bg - * - Swedish - se - * - Chinese Traditional - zh_tw - * - Chinese Simplified - zh_cn - * - Turkish - tr - * - * @api - */ - public function getWeather($query, $units = 'imperial', $lang = 'en', $appid = '') - { - // Disable default error handling of SimpleXML (Do not throw E_WARNINGs). - libxml_use_internal_errors(true); - libxml_clear_errors(); - - $answer = $this->getRawWeatherData($query, $units, $lang, $appid, 'xml'); - - try { - $xml = new \SimpleXMLElement($answer); - } catch (\Exception $e) { - // Invalid xml format. This happens in case OpenWeatherMap returns an error. - // OpenWeatherMap always uses json for errors, even if one specifies xml as format. - $error = json_decode($answer, true); - if (isset($error['message'])) { - throw new OWMException($error['message'], $error['cod']); - } else { - throw new OWMException('Unknown fatal error: OpenWeatherMap returned the following json object: ' . $answer); - } - } - - return new CurrentWeather($xml, $units); - } - - /** - * Returns the current weather at the place you specified as an object. - * - * @param array|int|string $query The place to get weather information for. For possible values see below. - * @param string $units Can be either 'metric' or 'imperial' (default). This affects almost all units returned. - * @param string $lang The language to use for descriptions, default is 'en'. For possible values see below. - * @param string $appid Your app id, default ''. See http://openweathermap.org/appid for more details. - * @param int $days For how much days you want to get a forecast. Default 1, maximum: 16. - * - * @throws OpenWeatherMap\Exception If OpenWeatherMap returns an error. - * @throws \InvalidArgumentException If an argument error occurs. - * - * @return WeatherForecast The WeatherForecast object. - * - * There are three ways to specify the place to get weather information for: - * - Use the city name: $query must be a string containing the city name. - * - Use the city id: $query must be an integer containing the city id. - * - Use the coordinates: $query must be an associative array containing the 'lat' and 'lon' values. - * - * Available languages are (as of 17. July 2013): - * - English - en - * - Russian - ru - * - Italian - it - * - Spanish - sp - * - Ukrainian - ua - * - German - de - * - Portuguese - pt - * - Romanian - ro - * - Polish - pl - * - Finnish - fi - * - Dutch - nl - * - French - fr - * - Bulgarian - bg - * - Swedish - se - * - Chinese Traditional - zh_tw - * - Chinese Simplified - zh_cn - * - Turkish - tr - * - * @api - */ - public function getWeatherForecast($query, $units = 'imperial', $lang = 'en', $appid = '', $days = 1) - { - // Disable default error handling of SimpleXML (Do not throw E_WARNINGs). - libxml_use_internal_errors(true); - libxml_clear_errors(); - - if ($days <= 5) { - $answer = $this->getRawHourlyForecastData($query, $units, $lang, $appid, 'xml'); - } else if ($days <= 16) { - $answer = $this->getRawDailyForecastData($query, $units, $lang, $appid, 'xml', $days); - } else { - throw new \InvalidArgumentException('Error: forecasts are only available for the next 16 days. $days must be lower than 17.'); - } - - try { - $xml = new \SimpleXMLElement($answer); - } catch (\Exception $e) { - // Invalid xml format. This happens in case OpenWeatherMap returns an error. - // OpenWeatherMap always uses json for errors, even if one specifies xml as format. - $error = json_decode($answer, true); - if (isset($error['message'])) { - throw new OWMException($error['message'], $error['cod']); - } else { - throw new OWMException('Unknown fatal error: OpenWeatherMap returned the following json object: ' . $answer); - } - } - - return new WeatherForecast($xml, $units, $days); - } - - /** - * Returns the weather history for the place you specified as an object. - * - * @param array|int|string $query The place to get weather information for. For possible values see below. - * @param \DateTime $start - * @param int $endOrCount - * @param string $type - * @param string $units Can be either 'metric' or 'imperial' (default). This affects almost all units returned. - * @param string $lang The language to use for descriptions, default is 'en'. For possible values see below. - * @param string $appid Your app id, default ''. See http://openweathermap.org/appid for more details. - * - * @throws OpenWeatherMap\Exception If OpenWeatherMap returns an error. - * @throws \InvalidArgumentException If an argument error occurs. - * - * @return WeatherHistory The WeatherHistory object. - * - * There are three ways to specify the place to get weather information for: - * - Use the city name: $query must be a string containing the city name. - * - Use the city id: $query must be an integer containing the city id. - * - Use the coordinates: $query must be an associative array containing the 'lat' and 'lon' values. - * - * Available languages are (as of 17. July 2013): - * - English - en - * - Russian - ru - * - Italian - it - * - Spanish - sp - * - Ukrainian - ua - * - German - de - * - Portuguese - pt - * - Romanian - ro - * - Polish - pl - * - Finnish - fi - * - Dutch - nl - * - French - fr - * - Bulgarian - bg - * - Swedish - se - * - Chinese Traditional - zh_tw - * - Chinese Simplified - zh_cn - * - Turkish - tr - * - * @api - */ - public function getWeatherHistory($query, \DateTime $start, $endOrCount = 1, $type = 'hour', $units = 'imperial', $lang = 'en', $appid = '') - { - if (!in_array($type, array('tick', 'hour', 'day'))) { - throw new \InvalidArgumentException('$type must be either "tick", "hour" or "day"'); - } - - $xml = json_decode($this->getRawWeatherHistory($query, $start, $endOrCount, $type, $units, $lang, $appid), true); - - if ($xml['cod'] != 200) { - throw new OWMException($xml['message'], $xml['cod']); - } - - return new WeatherHistory($xml, $query); - } - - /** - * @deprecated Use {@link self::getRawWeatherData()} instead. - */ - public function getRawData($query, $units = 'imperial', $lang = 'en', $appid = '', $mode = 'xml') - { - return $this->getRawWeatherData($query, $units, $lang, $appid, $mode); - } - - /** - * Directly returns the xml/json/html string returned by OpenWeatherMap for the current weather. - * - * @param array|int|string $query The place to get weather information for. For possible values see below. - * @param string $units Can be either 'metric' or 'imperial' (default). This affects almost all units returned. - * @param string $lang The language to use for descriptions, default is 'en'. For possible values see below. - * @param string $appid Your app id, default ''. See http://openweathermap.org/appid for more details. - * @param string $mode The format of the data fetched. Possible values are 'json', 'html' and 'xml' (default). - * - * @return string Returns false on failure and the fetched data in the format you specified on success. - * - * Warning If an error occurred, OpenWeatherMap returns data in json format ALWAYS - * - * There are three ways to specify the place to get weather information for: - * - Use the city name: $query must be a string containing the city name. - * - Use the city id: $query must be an integer containing the city id. - * - Use the coordinates: $query must be an associative array containing the 'lat' and 'lon' values. - * - * Available languages are (as of 17. July 2013): - * - English - en - * - Russian - ru - * - Italian - it - * - Spanish - sp - * - Ukrainian - ua - * - German - de - * - Portuguese - pt - * - Romanian - ro - * - Polish - pl - * - Finnish - fi - * - Dutch - nl - * - French - fr - * - Bulgarian - bg - * - Swedish - se - * - Chinese Traditional - zh_tw - * - Chinese Simplified - zh_cn - * - Turkish - tr - * - * @api - */ - public function getRawWeatherData($query, $units = 'imperial', $lang = 'en', $appid = '', $mode = 'xml') - { - $url = $this->buildUrl($query, $units, $lang, $appid, $mode, $this->weatherUrl); - - return $this->cacheOrFetchResult($url); - } - - /** - * Directly returns the xml/json/html string returned by OpenWeatherMap for the hourly forecast. - * - * @param array|int|string $query The place to get weather information for. For possible values see below. - * @param string $units Can be either 'metric' or 'imperial' (default). This affects almost all units returned. - * @param string $lang The language to use for descriptions, default is 'en'. For possible values see below. - * @param string $appid Your app id, default ''. See http://openweathermap.org/appid for more details. - * @param string $mode The format of the data fetched. Possible values are 'json', 'html' and 'xml' (default). - * - * @return string Returns false on failure and the fetched data in the format you specified on success. - * - * Warning If an error occurred, OpenWeatherMap returns data in json format ALWAYS - * - * There are three ways to specify the place to get weather information for: - * - Use the city name: $query must be a string containing the city name. - * - Use the city id: $query must be an integer containing the city id. - * - Use the coordinates: $query must be an associative array containing the 'lat' and 'lon' values. - * - * Available languages are (as of 17. July 2013): - * - English - en - * - Russian - ru - * - Italian - it - * - Spanish - sp - * - Ukrainian - ua - * - German - de - * - Portuguese - pt - * - Romanian - ro - * - Polish - pl - * - Finnish - fi - * - Dutch - nl - * - French - fr - * - Bulgarian - bg - * - Swedish - se - * - Chinese Traditional - zh_tw - * - Chinese Simplified - zh_cn - * - Turkish - tr - * - * @api - */ - public function getRawHourlyForecastData($query, $units = 'imperial', $lang = 'en', $appid = '', $mode = 'xml') - { - $url = $this->buildUrl($query, $units, $lang, $appid, $mode, $this->weatherHourlyForecastUrl); - - return $this->cacheOrFetchResult($url); - } - - /** - * Directly returns the xml/json/html string returned by OpenWeatherMap for the daily forecast. - * - * @param array|int|string $query The place to get weather information for. For possible values see below. - * @param string $units Can be either 'metric' or 'imperial' (default). This affects almost all units returned. - * @param string $lang The language to use for descriptions, default is 'en'. For possible values see below. - * @param string $appid Your app id, default ''. See http://openweathermap.org/appid for more details. - * @param string $mode The format of the data fetched. Possible values are 'json', 'html' and 'xml' (default) - * @param int $cnt How many days of forecast shall be returned? Maximum (and default): 16 - * - * @throws \InvalidArgumentException If $cnt is higher than 16. - * @return string Returns false on failure and the fetched data in the format you specified on success. - * - * Warning If an error occurred, OpenWeatherMap returns data in json format ALWAYS - * - * There are three ways to specify the place to get weather information for: - * - Use the city name: $query must be a string containing the city name. - * - Use the city id: $query must be an integer containing the city id. - * - Use the coordinates: $query must be an associative array containing the 'lat' and 'lon' values. - * - * Available languages are (as of 17. July 2013): - * - English - en - * - Russian - ru - * - Italian - it - * - Spanish - sp - * - Ukrainian - ua - * - German - de - * - Portuguese - pt - * - Romanian - ro - * - Polish - pl - * - Finnish - fi - * - Dutch - nl - * - French - fr - * - Bulgarian - bg - * - Swedish - se - * - Chinese Traditional - zh_tw - * - Chinese Simplified - zh_cn - * - Turkish - tr - * - * @api - */ - public function getRawDailyForecastData($query, $units = 'imperial', $lang = 'en', $appid = '', $mode = 'xml', $cnt = 16) - { - if ($cnt > 16) { - throw new \InvalidArgumentException('$cnt must be 16 or below!'); - } - $url = $this->buildUrl($query, $units, $lang, $appid, $mode, $this->weatherDailyForecastUrl) . "&cnt=$cnt"; - - return $this->cacheOrFetchResult($url); - } - - /** - * Directly returns the xml/json/html string returned by OpenWeatherMap for the daily forecast. - * - * @param array|int|string $query The place to get weather information for. For possible values see below. - * @param \DateTime $start The \DateTime object of the date to get the first weather information from. - * @param \DateTime|int $endOrCount Can be either a \DateTime object representing the end of the period to - * receive weather history data for or an integer counting the number of - * reports requested. - * @param string $type The period of the weather history requested. Can be either be either "tick", - * "hour" or "day". - * @param string $units Can be either 'metric' or 'imperial' (default). This affects almost all units returned. - * @param string $lang The language to use for descriptions, default is 'en'. For possible values see below. - * @param string $appid Your app id, default ''. See http://openweathermap.org/appid for more details. - * - * @throws \InvalidArgumentException - * - * @return string Returns false on failure and the fetched data in the format you specified on success. - * - * Warning If an error occurred, OpenWeatherMap returns data in json format ALWAYS - * - * There are three ways to specify the place to get weather information for: - * - Use the city name: $query must be a string containing the city name. - * - Use the city id: $query must be an integer containing the city id. - * - Use the coordinates: $query must be an associative array containing the 'lat' and 'lon' values. - * - * Available languages are (as of 17. July 2013): - * - English - en - * - Russian - ru - * - Italian - it - * - Spanish - sp - * - Ukrainian - ua - * - German - de - * - Portuguese - pt - * - Romanian - ro - * - Polish - pl - * - Finnish - fi - * - Dutch - nl - * - French - fr - * - Bulgarian - bg - * - Swedish - se - * - Chinese Traditional - zh_tw - * - Chinese Simplified - zh_cn - * - Turkish - tr - * - * @api - */ - public function getRawWeatherHistory($query, \DateTime $start, $endOrCount = 1, $type = 'hour', $units = 'imperial', $lang = 'en', $appid = '') - { - if (!in_array($type, array('tick', 'hour', 'day'))) { - throw new \InvalidArgumentException('$type must be either "tick", "hour" or "day"'); - } - - $queryUrl = $this->weatherHistoryUrl . $this->buildQueryUrlParameter($query) . "&start={$start->format('U')}"; - - if ($endOrCount instanceof \DateTime) { - $queryUrl .= "&end={$endOrCount->format('U')}"; - } else if (is_numeric($endOrCount) && $endOrCount > 0) { - $queryUrl .= "&cnt=$endOrCount"; - } else { - throw new \InvalidArgumentException('$endOrCount must be either a \DateTime or a positive integer.'); - } - $queryUrl .= "&type=$type&units=$units&lang=$lang"; - - if (!empty($appid)) { - $queryUrl .= "&APPID=$appid"; - } - - return $this->cacheOrFetchResult($queryUrl); - } - - /** - * Fetches the result or delivers a cached version of the result. - * - * @param $url - * - * @return string - * - * @internal - */ - private function cacheOrFetchResult($url) - { - if ($this->cacheClass !== false) { - /** @var \Cmfcmf\OpenWeatherMap\AbstractCache $cache */ - $cache = $this->cacheClass; - $cache->setSeconds($this->seconds); - if ($cache->isCached($url)) { - return $cache->getCached($url); - } - $result = $this->fetcher->fetch($url); - $cache->setCached($url, $result); - } else { - $result = $this->fetcher->fetch($url); - } - - return $result; - } - - /** - * Build the url to fetch weather data from. - * - * @param $query - * @param $units - * @param $lang - * @param $appid - * @param $mode - * @param string $url The url to prepend. - * - * @return bool|string The fetched url, false on failure. - * - * @internal - */ - private function buildUrl($query, $units, $lang, $appid, $mode, $url) - { - $queryUrl = $this->buildQueryUrlParameter($query); - - $url = $url . "$queryUrl&units=$units&lang=$lang&mode=$mode"; - if (!empty($appid)) { - $url .= "&APPID=$appid"; - } - - return $url; - } - - /** - * Builds the query string for the url. - * - * @param $query - * - * @return string The built query string for the url. - * @throws \InvalidArgumentException If the query parameter is invalid. - * - * @internal - */ - private function buildQueryUrlParameter($query) - { - switch ($query) { - case (is_array($query) && isset($query['lat']) && isset($query['lon']) && is_numeric($query['lat']) && is_numeric($query['lon'])): - return "lat={$query['lat']}&lon={$query['lon']}"; - case (is_numeric($query)): - return "id=$query"; - case (is_string($query)): - return "q=" . urlencode($query); - default: - throw new \InvalidArgumentException('Error: $query has the wrong format. See the documentation of OpenWeatherMap::getRawData() to read about valid formats.'); - } - } -} diff --git a/curweather/vendor/cmfcmf/openweathermap-php-api/Cmfcmf/OpenWeatherMap/AbstractCache.php b/curweather/vendor/cmfcmf/openweathermap-php-api/Cmfcmf/OpenWeatherMap/AbstractCache.php deleted file mode 100644 index c9b66ebe..00000000 --- a/curweather/vendor/cmfcmf/openweathermap-php-api/Cmfcmf/OpenWeatherMap/AbstractCache.php +++ /dev/null @@ -1,69 +0,0 @@ -seconds = $seconds; - } -} diff --git a/curweather/vendor/cmfcmf/openweathermap-php-api/Cmfcmf/OpenWeatherMap/CurrentWeather.php b/curweather/vendor/cmfcmf/openweathermap-php-api/Cmfcmf/OpenWeatherMap/CurrentWeather.php deleted file mode 100644 index 7ce2e2a1..00000000 --- a/curweather/vendor/cmfcmf/openweathermap-php-api/Cmfcmf/OpenWeatherMap/CurrentWeather.php +++ /dev/null @@ -1,117 +0,0 @@ -city = new City($xml->city['id'], $xml->city['name'], $xml->city->coord['lon'], $xml->city->coord['lat'], $xml->city->country); - $this->temperature = new Temperature(new Unit($xml->temperature['value'], $xml->temperature['unit']), new Unit($xml->temperature['min'], $xml->temperature['unit']), new Unit($xml->temperature['max'], $xml->temperature['unit'])); - $this->humidity = new Unit($xml->humidity['value'], $xml->humidity['unit']); - $this->pressure = new Unit($xml->pressure['value'], $xml->pressure['unit']); - - // This is kind of a hack, because the units are missing in the xml document. - if ($units == 'metric') { - $windSpeedUnit = 'm/s'; - } else { - $windSpeedUnit = 'mph'; - } - $this->wind = new Wind(new Unit($xml->wind->speed['value'], $windSpeedUnit, $xml->wind->speed['name']), new Unit($xml->wind->direction['value'], $xml->wind->direction['code'], $xml->wind->direction['name'])); - - $this->clouds = new Unit($xml->clouds['value'], null, $xml->clouds['name']); - $this->precipitation = new Unit($xml->precipitation['value'], $xml->precipitation['unit'], $xml->precipitation['mode']); - $utctz = new \DateTimeZone('UTC'); - $this->sun = new Sun(new \DateTime($xml->city->sun['rise'], $utctz), new \DateTime($xml->city->sun['set'], $utctz)); - $this->weather = new WeatherObj($xml->weather['number'], $xml->weather['value'], $xml->weather['icon']); - $this->lastUpdate = new \DateTime($xml->lastupdate['value'], $utctz); - } -} diff --git a/curweather/vendor/cmfcmf/openweathermap-php-api/Cmfcmf/OpenWeatherMap/Exception.php b/curweather/vendor/cmfcmf/openweathermap-php-api/Cmfcmf/OpenWeatherMap/Exception.php deleted file mode 100644 index 20f3a871..00000000 --- a/curweather/vendor/cmfcmf/openweathermap-php-api/Cmfcmf/OpenWeatherMap/Exception.php +++ /dev/null @@ -1,27 +0,0 @@ -city = new City($xml->city['id'], $xml->city['name'], $xml->city->coord['lon'], $xml->city->coord['lat'], $xml->city->country); - - if ($units == 'metric') { - $temperatureUnit = "°C"; - } else { - $temperatureUnit = 'F'; - } - - $xml->temperature['value'] = ($xml->temperature['max'] + $xml->temperature['min']) / 2; - - $this->temperature = new Temperature(new Unit($xml->temperature['value'], $temperatureUnit), new Unit($xml->temperature['min'], $temperatureUnit), new Unit($xml->temperature['max'], $temperatureUnit)); - $this->humidity = new Unit($xml->humidity['value'], $xml->humidity['unit']); - $this->pressure = new Unit($xml->pressure['value'], $xml->pressure['unit']); - - // This is kind of a hack, because the units are missing in the xml document. - if ($units == 'metric') { - $windSpeedUnit = 'm/s'; - } else { - $windSpeedUnit = 'mps'; - } - - $this->wind = new Wind(new Unit($xml->windSpeed['mps'], $windSpeedUnit, $xml->windSpeed['name']), new Unit($xml->windDirection['value'], $xml->windDirection['code'], $xml->windDirection['name'])); - $this->clouds = new Unit($xml->clouds['all'], $xml->clouds['unit'], $xml->clouds['value']); - $this->precipitation = new Unit($xml->precipitation['value'], null, $xml->precipitation['type']); - $this->sun = new Sun(new \DateTime($xml->city->sun['rise']), new \DateTime($xml->city->sun['set'])); - $this->weather = new WeatherObj($xml->symbol['number'], $xml->symbol['name'], $xml->symbol['var']); - $this->lastUpdate = new \DateTime($xml->lastupdate['value']); - - if (isset($xml['from'])) { - $this->time = new Time($xml['from'], $xml['to']); - } else { - $this->time = new Time($xml['day']); - } - } -} diff --git a/curweather/vendor/cmfcmf/openweathermap-php-api/Cmfcmf/OpenWeatherMap/History.php b/curweather/vendor/cmfcmf/openweathermap-php-api/Cmfcmf/OpenWeatherMap/History.php deleted file mode 100644 index 6601a840..00000000 --- a/curweather/vendor/cmfcmf/openweathermap-php-api/Cmfcmf/OpenWeatherMap/History.php +++ /dev/null @@ -1,104 +0,0 @@ -city = $city; - $this->weather = new Weather($weather['id'], $weather['description'], $weather['icon']); - $this->temperature = new Temperature(new Unit($temperature['now'] - 273.15, "\xB0C"), new Unit($temperature['min'] - 273.15, "\xB0C"), new Unit($temperature['max'] - 273.15, "\xB0C")); - $this->pressure = new Unit($pressure, 'kPa'); - $this->humidity = new Unit($humidity, '%'); - $this->clouds = new Unit($clouds, '%'); - $this->precipitation = new Unit($rain['val'], $rain['unit']); - $this->wind = new Wind(new Unit($wind['speed']), new Unit($wind['deg'])); - $this->time = $time; - } -} diff --git a/curweather/vendor/cmfcmf/openweathermap-php-api/Cmfcmf/OpenWeatherMap/Util/City.php b/curweather/vendor/cmfcmf/openweathermap-php-api/Cmfcmf/OpenWeatherMap/Util/City.php deleted file mode 100644 index b5dceb2b..00000000 --- a/curweather/vendor/cmfcmf/openweathermap-php-api/Cmfcmf/OpenWeatherMap/Util/City.php +++ /dev/null @@ -1,76 +0,0 @@ -id = (int)$id; - $this->name = isset($name) ? (string)$name : null; - $this->lon = isset($lon) ? (float)$lon : null; - $this->lat = isset($lat) ? (float)$lat : null; - $this->country = isset($country) ? (string)$country : null; - $this->population = isset($population) ? (int)$population : null; - } -} diff --git a/curweather/vendor/cmfcmf/openweathermap-php-api/Cmfcmf/OpenWeatherMap/Util/Sun.php b/curweather/vendor/cmfcmf/openweathermap-php-api/Cmfcmf/OpenWeatherMap/Util/Sun.php deleted file mode 100644 index dc0f0104..00000000 --- a/curweather/vendor/cmfcmf/openweathermap-php-api/Cmfcmf/OpenWeatherMap/Util/Sun.php +++ /dev/null @@ -1,52 +0,0 @@ -rise = $rise; - $this->set = $set; - } -} diff --git a/curweather/vendor/cmfcmf/openweathermap-php-api/Cmfcmf/OpenWeatherMap/Util/Temperature.php b/curweather/vendor/cmfcmf/openweathermap-php-api/Cmfcmf/OpenWeatherMap/Util/Temperature.php deleted file mode 100644 index 14146c06..00000000 --- a/curweather/vendor/cmfcmf/openweathermap-php-api/Cmfcmf/OpenWeatherMap/Util/Temperature.php +++ /dev/null @@ -1,105 +0,0 @@ -now->__toString(); - } - - /** - * Returns the current temperature's unit. - * - * @return string The current temperature's unit. - */ - public function getUnit() - { - return $this->now->getUnit(); - } - - /** - * Returns the current temperature. - * - * @return string The current temperature. - */ - public function getValue() - { - return $this->now->getValue(); - } - - /** - * Returns the current temperature's description. - * - * @return string The current temperature's description. - */ - public function getDescription() - { - return $this->now->getDescription(); - } - - /** - * Returns the current temperature as formatted string. - * - * @return string The current temperature as formatted string. - */ - public function getFormatted() - { - return $this->now->getFormatted(); - } - - /** - * Create a new temperature object. - * - * @param Unit $now The current temperature. - * @param Unit $min The minimal temperature. - * @param Unit $max The maximal temperature. - * - * @internal - */ - public function __construct(Unit $now, Unit $min, Unit $max) - { - $this->now = $now; - $this->min = $min; - $this->max = $max; - } -} diff --git a/curweather/vendor/cmfcmf/openweathermap-php-api/Cmfcmf/OpenWeatherMap/Util/Time.php b/curweather/vendor/cmfcmf/openweathermap-php-api/Cmfcmf/OpenWeatherMap/Util/Time.php deleted file mode 100644 index 517b4c30..00000000 --- a/curweather/vendor/cmfcmf/openweathermap-php-api/Cmfcmf/OpenWeatherMap/Util/Time.php +++ /dev/null @@ -1,65 +0,0 @@ -format('Y-m-d')); - } else { - $from = ($from instanceof \DateTime) ? $from : new \DateTime((string)$from); - $day = clone $from; - $to = clone $from; - $to = $to->add(new \DateInterval('PT23H59M59S')); - } - - $this->from = $from; - $this->to = $to; - $this->day = $day; - } -} diff --git a/curweather/vendor/cmfcmf/openweathermap-php-api/Cmfcmf/OpenWeatherMap/Util/Unit.php b/curweather/vendor/cmfcmf/openweathermap-php-api/Cmfcmf/OpenWeatherMap/Util/Unit.php deleted file mode 100644 index 017ff05e..00000000 --- a/curweather/vendor/cmfcmf/openweathermap-php-api/Cmfcmf/OpenWeatherMap/Util/Unit.php +++ /dev/null @@ -1,128 +0,0 @@ -value = (float)$value; - $this->unit = (string)$unit; - $this->description = (string)$description; - } - - /** - * Get the value as formatted string with unit. - * - * @return string The value as formatted string with unit. - * - * The unit is not included if it is empty. - */ - public function __toString() - { - return $this->getFormatted(); - } - - /** - * Get the value's unit. - * - * @return string The value's unit. - * - * This also converts 'celsius' to '°C' and 'fahrenheit' to 'F'. - */ - public function getUnit() - { - // Units are inconsistent. Only celsius and fahrenheit are not abbreviated. This check fixes that. - if ($this->unit == 'celsius') { - return "°C"; - } else if ($this->unit == 'fahrenheit') { - return 'F'; - } else { - return $this->unit; - } - } - - /** - * Get the value. - * - * @return float The value. - */ - public function getValue() - { - return $this->value; - } - - /** - * Get the value's description. - * - * @return string The value's description. - */ - public function getDescription() - { - return $this->description; - } - - /** - * Get the value as formatted string with unit. - * - * @return string The value as formatted string with unit. - * - * The unit is not included if it is empty. - */ - public function getFormatted() - { - if ($this->getUnit() != "") { - return "{$this->getValue()} {$this->getUnit()}"; - } else { - return "{$this->getValue()}"; - } - } -} diff --git a/curweather/vendor/cmfcmf/openweathermap-php-api/Cmfcmf/OpenWeatherMap/Util/Weather.php b/curweather/vendor/cmfcmf/openweathermap-php-api/Cmfcmf/OpenWeatherMap/Util/Weather.php deleted file mode 100644 index a9d848eb..00000000 --- a/curweather/vendor/cmfcmf/openweathermap-php-api/Cmfcmf/OpenWeatherMap/Util/Weather.php +++ /dev/null @@ -1,82 +0,0 @@ -id = (int)$id; - $this->description = (string)$description; - $this->icon = (string)$icon; - } - - /** - * Get the weather description. - * - * @return string - */ - public function __toString() - { - return $this->description; - } - - /** - * Get the icon url. - * - * @return string The icon url. - */ - public function getIconUrl() - { - return str_replace("%s", $this->icon, $this->iconUrl); - } -} diff --git a/curweather/vendor/cmfcmf/openweathermap-php-api/Cmfcmf/OpenWeatherMap/Util/Wind.php b/curweather/vendor/cmfcmf/openweathermap-php-api/Cmfcmf/OpenWeatherMap/Util/Wind.php deleted file mode 100644 index 02209600..00000000 --- a/curweather/vendor/cmfcmf/openweathermap-php-api/Cmfcmf/OpenWeatherMap/Util/Wind.php +++ /dev/null @@ -1,48 +0,0 @@ -speed = $speed; - $this->direction = $direction; - } -} diff --git a/curweather/vendor/cmfcmf/openweathermap-php-api/Cmfcmf/OpenWeatherMap/WeatherForecast.php b/curweather/vendor/cmfcmf/openweathermap-php-api/Cmfcmf/OpenWeatherMap/WeatherForecast.php deleted file mode 100644 index 8230989e..00000000 --- a/curweather/vendor/cmfcmf/openweathermap-php-api/Cmfcmf/OpenWeatherMap/WeatherForecast.php +++ /dev/null @@ -1,136 +0,0 @@ -getWeather(). - * - * @see Cmfcmf\OpenWeatherMap::getWeather() The function using it. - */ -class WeatherForecast implements \Iterator -{ - /** - * A city object. - * - * @var Util\City - */ - public $city; - - /** - * A sun object - * - * @var Util\Sun - */ - public $sun; - - /** - * The time of the last update of this weather data. - * - * @var \DateTime - */ - public $lastUpdate; - - /** - * An array of {@link WeatherForecast} objects. - * - * @var array - * - * @see WeatherForecast The WeatherForecast class. - */ - private $forecasts; - - /** - * @internal - */ - private $position = 0; - - /** - * Create a new Forecast object. - * - * @param $xml - * @param string $units - * @param int $days How many days of forecast to receive. - * - * @internal - */ - public function __construct($xml, $units, $days) - { - $this->city = new City(-1, $xml->location->name, $xml->location->location['longitude'], $xml->location->location['latitude'], $xml->location->country); - $this->sun = new Sun(new \DateTime($xml->sun['rise']), new \DateTime($xml->sun['set'])); - $this->lastUpdate = new \DateTime($xml->meta->lastupdate); - - $counter = 0; - foreach ($xml->forecast->time as $time) { - $forecast = new Forecast($time, $units); - $forecast->city = $this->city; - $this->forecasts[] = $forecast; - - $counter++; - // Make sure to only return the requested number of days. - if ($days <= 5 && $counter == $days * 8) { - break; - } else if ($days > 5 && $counter == $days) { - break; - } - } - } - - /** - * @internal - */ - public function rewind() - { - $this->position = 0; - } - - /** - * @internal - */ - public function current() - { - return $this->forecasts[$this->position]; - } - - /** - * @internal - */ - public function key() - { - return $this->position; - } - - /** - * @internal - */ - public function next() - { - ++$this->position; - } - - /** - * @internal - */ - public function valid() - { - return isset($this->forecasts[$this->position]); - } -} diff --git a/curweather/vendor/cmfcmf/openweathermap-php-api/Cmfcmf/OpenWeatherMap/WeatherHistory.php b/curweather/vendor/cmfcmf/openweathermap-php-api/Cmfcmf/OpenWeatherMap/WeatherHistory.php deleted file mode 100644 index 7ee4084a..00000000 --- a/curweather/vendor/cmfcmf/openweathermap-php-api/Cmfcmf/OpenWeatherMap/WeatherHistory.php +++ /dev/null @@ -1,118 +0,0 @@ -city = new OpenWeatherMap\Util\City($weatherHistory['city_id'], (is_string($query)) ? $query : null, (isset($query['lon'])) ? $query['lon'] : null, (isset($query['lat'])) ? $query['lat'] : null, $country, $population); - $this->calctime = $weatherHistory['calctime']; - - foreach ($weatherHistory['list'] as $history) { - if (isset($history['rain'])) { - $units = array_keys($history['rain']); - } else { - $units = array(0 => null); - } - - $this->histories[] = new History($this->city, $history['weather'][0], array('now' => $history['main']['temp'], 'min' => $history['main']['temp_min'], 'max' => $history['main']['temp_max']), $history['main']['pressure'], $history['main']['humidity'], $history['clouds']['all'], isset($history['rain']) ? array('val' => $history['rain'][($units[0])], 'unit' => $units[0]) : null, $history['wind'], \DateTime::createFromFormat('U', $history['dt'])); - } - } - - /** - * @internal - */ - public function rewind() - { - $this->position = 0; - } - - /** - * @internal - */ - public function current() - { - return $this->histories[$this->position]; - } - - /** - * @internal - */ - public function key() - { - return $this->position; - } - - /** - * @internal - */ - public function next() - { - ++$this->position; - } - - /** - * @internal - */ - public function valid() - { - return isset($this->histories[$this->position]); - } -} diff --git a/curweather/vendor/cmfcmf/openweathermap-php-api/Examples/Cache.php b/curweather/vendor/cmfcmf/openweathermap-php-api/Examples/Cache.php deleted file mode 100644 index 61869f2e..00000000 --- a/curweather/vendor/cmfcmf/openweathermap-php-api/Examples/Cache.php +++ /dev/null @@ -1,95 +0,0 @@ -urlToPath($url); - if (!file_exists($path) || filectime($path) + $this->seconds < time()) { - echo "Weather data is NOT cached!\n"; - - return false; - } - - echo "Weather data is cached!\n"; - - return true; - } - - /** - * @inheritdoc - */ - public function getCached($url) - { - return file_get_contents($this->urlToPath($url)); - } - - /** - * @inheritdoc - */ - public function setCached($url, $content) - { - file_put_contents($this->urlToPath($url), $content); - } -} - -// Language of data (try your own language here!): -$lang = 'de'; - -// Units (can be 'metric' or 'imperial' [default]): -$units = 'metric'; - -// Example 1: Use your own cache implementation. Cache for 10 seconds only in this example. -$owm = new OpenWeatherMap(null, new ExampleCache(), 10); - -$weather = $owm->getWeather('Berlin', $units, $lang); -echo "EXAMPLE 1
\n\n\n"; -echo $weather->temperature; diff --git a/curweather/vendor/cmfcmf/openweathermap-php-api/Examples/CurrentWeather.php b/curweather/vendor/cmfcmf/openweathermap-php-api/Examples/CurrentWeather.php deleted file mode 100644 index 46a6c517..00000000 --- a/curweather/vendor/cmfcmf/openweathermap-php-api/Examples/CurrentWeather.php +++ /dev/null @@ -1,236 +0,0 @@ -getWeather('Berlin', $units, $lang); -echo "EXAMPLE 1
\n\n\n"; - -// $weather contains all available weather information for Berlin. -// Let's get the temperature: - -// Returns it as formatted string (using __toString()): -echo $weather->temperature; -echo "
\n"; - -// Returns it as formatted string (using a method): -echo $weather->temperature->getFormatted(); -echo "
\n"; - -// Returns the value only: -echo $weather->temperature->getValue(); -echo "
\n"; - -// Returns the unit only: -echo $weather->temperature->getUnit(); -echo "
\n"; - -/** - * In the example above we're using a "shortcut". OpenWeatherMap returns the minimum temperature of a day, - * the maximum temperature and the temperature right now. If you don't specify which temperature you want, it will default - * to the current temperature. See below how to access the other values. Notice that each of them has implemented the methods - * "getFormatted()", "getValue()", "getUnit()". - */ - -// Returns the current temperature: -echo "Current: " . $weather->temperature->now; -echo "
\n"; - -// Returns the minimum temperature: -echo "Minimum: " . $weather->temperature->min; -echo "
\n"; - -// Returns the maximum temperature: -echo "Maximum: " . $weather->temperature->max; -echo "
\n"; - -/** - * When speaking about "current" and "now", this means when the weather data was last updated. You can get this - * via a DateTime object: - */ -echo "Last update: " . $weather->lastUpdate->format('r'); -echo "
\n"; - -// Example 2: Get current pressure and humidity in Hongkong. -$weather = $owm->getWeather('Hongkong', $units, $lang); -echo "

\n\n\nEXAMPLE 2
\n\n\n"; - -/** - * You can use the methods above to only get the value or the unit. - */ - -echo "Pressure: " . $weather->pressure; -echo "
\n"; -echo "Humidity: " . $weather->humidity; -echo "
\n"; - -// Example 3: Get today's sunrise and sunset times. -echo "

\n\n\nEXAMPLE 3
\n\n\n"; - -/** - * These functions return a DateTime object. - */ - -echo "Sunrise: " . $weather->sun->rise->format('r'); -echo "
\n"; -echo "Sunset: " . $weather->sun->set->format('r'); -echo "
\n"; - -// Example 4: Get current temperature from coordinates (Greenland :-) ). -$weather = $owm->getWeather(array('lat' => 77.73038, 'lon' => 41.89604), $units, $lang); -echo "

\n\n\nEXAMPLE 4
\n\n\n"; - -echo "Temperature: " . $weather->temperature; -echo "
\n"; - -// Example 5: Get current temperature from city id. The city is an internal id used by OpenWeatherMap. See example 6 too. -$weather = $owm->getWeather(2172797, $units, $lang); -echo "

\n\n\nEXAMPLE 5
\n\n\n"; - -echo "City: " . $weather->city->name; -echo "
\n"; - -echo "Temperature: " . $weather->temperature; -echo "
\n"; - -// Example 6: Get information about a city. -$weather = $owm->getWeather('Paris', $units, $lang); -echo "

\n\n\nEXAMPLE 6
\n\n\n"; - -echo "Id: " . $weather->city->id; -echo "
\n"; - -echo "Name: " . $weather->city->name; -echo "
\n"; - -echo "Lon: " . $weather->city->lon; -echo "
\n"; - -echo "Lat: " . $weather->city->lat; -echo "
\n"; - -echo "Country: " . $weather->city->country; -echo "
\n"; - -// Example 7: Get wind information. -echo "

\n\n\nEXAMPLE 7
\n\n\n"; - -echo "Speed: " . $weather->wind->speed; -echo "
\n"; - -echo "Direction: " . $weather->wind->direction; -echo "
\n"; - -/** - * For speed and direction there is a description available, which isn't always translated. - */ - -echo "Speed: " . $weather->wind->speed->getDescription(); -echo "
\n"; - -echo "Direction: " . $weather->wind->direction->getDescription(); -echo "
\n"; - -// Example 8: Get information about the clouds. -echo "

\n\n\nEXAMPLE 8
\n\n\n"; - -// The number in braces seems to be an indicator how cloudy the sky is. -echo "Clouds: " . $weather->clouds->getDescription() . " (" . $weather->clouds . ")"; -echo "
\n"; - -// Example 9: Get information about precipitation. -echo "

\n\n\nEXAMPLE 9
\n\n\n"; - -echo "Precipation: " . $weather->precipitation->getDescription() . " (" . $weather->precipitation . ")"; -echo "
\n"; - -// Example 10: Show copyright notice. WARNING: This is no offical text. This hint was created regarding to http://www.http://openweathermap.org/copyright . -echo "

\n\n\nEXAMPLE 10
\n\n\n"; - -echo $owm::COPYRIGHT; -echo "
\n"; - -// Example 11: Get raw xml data. -echo "

\n\n\nEXAMPLE 11
\n\n\n"; - -echo "
" . htmlspecialchars($owm->getRawWeatherData('Berlin', $units, $lang, null, 'xml')) . "
"; -echo "
\n"; - -// Example 12: Get raw json data. -echo "

\n\n\nEXAMPLE 12
\n\n\n"; - -echo "" . htmlspecialchars($owm->getRawWeatherData('Berlin', $units, $lang, null, 'json')) . ""; -echo "
\n"; - -// Example 13: Get raw html data. -echo "

\n\n\nEXAMPLE 13
\n\n\n"; - -echo $owm->getRawWeatherData('Berlin', $units, $lang, null, 'html'); -echo "
\n"; - -// Example 14: Error handling. -echo "

\n\n\nEXAMPLE 14
\n\n\n"; - -// Try wrong city name. -try { - $weather = $owm->getWeather("ThisCityNameIsNotValidAndDoesNotExist", $units, $lang); -} catch (OWMException $e) { - echo $e->getMessage() . ' (Code ' . $e->getCode() . ').'; - echo "
\n"; -} - -// Try invalid $query. -try { - $weather = $owm->getWeather(new \DateTime('now'), $units, $lang); -} catch (\Exception $e) { - echo $e->getMessage() . ' (Code ' . $e->getCode() . ').'; - echo "
\n"; -} - -// Full error handling would look like this: -try { - $weather = $owm->getWeather(-1, $units, $lang); -} catch (OWMException $e) { - echo 'OpenWeatherMap exception: ' . $e->getMessage() . ' (Code ' . $e->getCode() . ').'; - echo "
\n"; -} catch (\Exception $e) { - echo 'General exception: ' . $e->getMessage() . ' (Code ' . $e->getCode() . ').'; - echo "
\n"; -} - -// Example 15: Using an api key: -$owm->getWeather('Berlin', $units, $lang, 'Your-Api-Key-Here'); diff --git a/curweather/vendor/cmfcmf/openweathermap-php-api/Examples/WeatherForecast.php b/curweather/vendor/cmfcmf/openweathermap-php-api/Examples/WeatherForecast.php deleted file mode 100644 index 833425bb..00000000 --- a/curweather/vendor/cmfcmf/openweathermap-php-api/Examples/WeatherForecast.php +++ /dev/null @@ -1,69 +0,0 @@ -getWeatherForecast('Berlin', $units, $lang, '', 10); -echo "EXAMPLE 1
\n\n\n"; - -echo "City: " . $forecast->city->name; -echo "
\n"; -echo "LastUpdate: " . $forecast->lastUpdate->format('d.m.Y H:i'); -echo "
\n"; -echo "Sunrise : " . $forecast->sun->rise->format("H:i:s") . " Sunset : " . $forecast->sun->set->format("H:i:s"); -echo "
\n"; -echo "
\n"; - -foreach ($forecast as $weather) { - // Each $weather contains a Cmfcmf\ForecastWeather object which is almost the same as the Cmfcmf\Weather object. - // Take a look into 'Examples_Current.php' to see the available options. - echo "Weather forecast at " . $weather->time->day->format('d.m.Y') . " from " . $weather->time->from->format('H:i') . " to " . $weather->time->to->format('H:i'); - echo "
\n"; - echo $weather->temperature; - echo "
\n"; - echo "---"; - echo "
\n"; -} - -// Example 2: Get forecast for the next 3 days for Berlin. -$forecast = $owm->getWeatherForecast('Berlin', $units, $lang, '', 3); -echo "EXAMPLE 2
\n\n\n"; - -foreach ($forecast as $weather) { - echo "Weather forecast at " . $weather->time->day->format('d.m.Y') . " from " . $weather->time->from->format('H:i') . " to " . $weather->time->to->format('H:i') . "
"; - echo $weather->temperature . "
\n"; - echo "---
\n"; -} diff --git a/curweather/vendor/cmfcmf/openweathermap-php-api/Examples/WeatherHistory.php b/curweather/vendor/cmfcmf/openweathermap-php-api/Examples/WeatherHistory.php deleted file mode 100644 index c64ee524..00000000 --- a/curweather/vendor/cmfcmf/openweathermap-php-api/Examples/WeatherHistory.php +++ /dev/null @@ -1,43 +0,0 @@ -getWeatherHistory('Berlin', new \DateTime('2014-01-01'), new \DateTime('now'), 'hour', $units, $lang); - -foreach ($history as $weather) { - echo "Average temperature at " . $weather->time->format('d.m.Y H:i') . ": " . $weather->temperature . "\n\r
"; -} diff --git a/curweather/vendor/cmfcmf/openweathermap-php-api/LICENSE b/curweather/vendor/cmfcmf/openweathermap-php-api/LICENSE deleted file mode 100644 index 1d2c3966..00000000 --- a/curweather/vendor/cmfcmf/openweathermap-php-api/LICENSE +++ /dev/null @@ -1,19 +0,0 @@ -Copyright (c) 2013 Christian Flach - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in -all copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -THE SOFTWARE. diff --git a/curweather/vendor/cmfcmf/openweathermap-php-api/README.md b/curweather/vendor/cmfcmf/openweathermap-php-api/README.md deleted file mode 100644 index ea452611..00000000 --- a/curweather/vendor/cmfcmf/openweathermap-php-api/README.md +++ /dev/null @@ -1,83 +0,0 @@ -OpenWeatherMap-PHP-Api -====================== -A php api to parse weather data from [OpenWeatherMap.org](http://www.OpenWeatherMap.org). This api tries to normalise and abstract the data and remove inconsistencies. - -[![Build Status](https://travis-ci.org/cmfcmf/OpenWeatherMap-PHP-Api.png?branch=master)](https://travis-ci.org/cmfcmf/OpenWeatherMap-PHP-Api)[![Scrutinizer Quality Score](https://scrutinizer-ci.com/g/cmfcmf/OpenWeatherMap-PHP-Api/badges/quality-score.png?s=f31ca08aa8896416cf162403d34362f0a5da0966)](https://scrutinizer-ci.com/g/cmfcmf/OpenWeatherMap-PHP-Api/)[![Code Coverage](https://scrutinizer-ci.com/g/cmfcmf/OpenWeatherMap-PHP-Api/badges/coverage.png?s=65153e7cfb13e050d734c645e38f2dd7ea7a6860)](https://scrutinizer-ci.com/g/cmfcmf/OpenWeatherMap-PHP-Api/) -[![SensioLabsInsight](https://insight.sensiolabs.com/projects/0addfb24-e2b4-4feb-848e-86b2078ca104/big.png)](https://insight.sensiolabs.com/projects/0addfb24-e2b4-4feb-848e-86b2078ca104) ------------ - -For example code and how to use this api, please take a look into `Examples_*.php` files and run them in your browser. -- `Examples_Current.php` Shows how to receive the current weather. -- `Examples_Forecast.php` Shows how to receive weather forecasts. -- [*NEW*] `Examples_History.php` Shows how to receive weather history. -- `Examples_Cache.php` Shows how to implement a cache. - -**Notice:** This api is not made by OpenWeatherMap, nor their official php api. - -Contribute! -=========== -I'm very happy if you open **pull requests** or **issues** to help making this API **more awesome**. - -Installation -============ -This library can be found on [Packagist](https://packagist.org/packages/cmfcmf/openweathermap-php-api). -The recommended way to install this is through [composer](http://getcomposer.org). - -Edit your `composer.json` and add: - -```json -{ - "require": { - "cmfcmf/openweathermap-php-api": "~2.0" - } -} -``` - -And install dependencies: - -```bash -$ curl -sS https://getcomposer.org/installer | php -$ php composer.phar install -``` - - -Example call -============ -```php -getWeather('Berlin', $units, $lang); -} catch(OWMException $e) { - echo 'OpenWeatherMap exception: ' . $e->getMessage() . ' (Code ' . $e->getCode() . ').'; - echo "
\n"; -} catch(\Exception $e) { - echo 'General exception: ' . $e->getMessage() . ' (Code ' . $e->getCode() . ').'; - echo "
\n"; -} - -echo $weather->temperature; -``` - -License -======= -MIT — Please see the [LICENSE file](https://github.com/Cmfcmf/OpenWeatherMap-PHP-Api/blob/master/LICENSE) distributed with this source code for further information regarding copyright and licensing. - -**Please check out the following links to read about the usage policies and the license of OpenWeatherMap before using the service.** -- [OpenWeatherMap.org](http://www.OpenWeatherMap.org) -- [OpenWeatherMap.org/terms](http://www.OpenWeatherMap.org/terms) -- [OpenWeatherMap.org/appid](http://www.OpenWeatherMap.org/appid) diff --git a/curweather/vendor/cmfcmf/openweathermap-php-api/composer.json b/curweather/vendor/cmfcmf/openweathermap-php-api/composer.json deleted file mode 100644 index 687cd4f4..00000000 --- a/curweather/vendor/cmfcmf/openweathermap-php-api/composer.json +++ /dev/null @@ -1,30 +0,0 @@ -{ - "name": "cmfcmf/openweathermap-php-api", - "description": "A php api to parse weather data from OpenWeatherMap.org. This api tries to normalise and abstract the data and remove inconsistencies.", - "keywords": ["weather", "OpenWeatherMap", "weather api"], - "homepage": "https://github.com/cmfcmf/OpenWeatherMap-PHP-Api", - "license": "MIT", - "authors": [ - { - "name": "Christian Flach (cmfcmf)", - "email": "cmfcmf.flach@gmail.com", - "homepage": "http://cmfcmf.github.io", - "role": "Developer" - } - ], - "support": { - "issues": "https://github.com/cmfcmf/OpenWeatherMap-PHP-Api/issues", - "source": "https://github.com/cmfcmf/OpenWeatherMap-PHP-Api.git" - }, - "require": { - "php": ">=5.3.0" - }, - "require-dev": { - "phpunit/phpunit": "^4.7.0" - }, - "autoload": { - "psr-0": { - "Cmfcmf\\": "" - } - } -} diff --git a/curweather/vendor/cmfcmf/openweathermap-php-api/composer.lock b/curweather/vendor/cmfcmf/openweathermap-php-api/composer.lock deleted file mode 100644 index 5ef16474..00000000 --- a/curweather/vendor/cmfcmf/openweathermap-php-api/composer.lock +++ /dev/null @@ -1,973 +0,0 @@ -{ - "_readme": [ - "This file locks the dependencies of your project to a known state", - "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file", - "This file is @generated automatically" - ], - "hash": "23a2734069dc5af143bb0e0a09160885", - "packages": [], - "packages-dev": [ - { - "name": "doctrine/instantiator", - "version": "1.0.5", - "source": { - "type": "git", - "url": "https://github.com/doctrine/instantiator.git", - "reference": "8e884e78f9f0eb1329e445619e04456e64d8051d" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/doctrine/instantiator/zipball/8e884e78f9f0eb1329e445619e04456e64d8051d", - "reference": "8e884e78f9f0eb1329e445619e04456e64d8051d", - "shasum": "" - }, - "require": { - "php": ">=5.3,<8.0-DEV" - }, - "require-dev": { - "athletic/athletic": "~0.1.8", - "ext-pdo": "*", - "ext-phar": "*", - "phpunit/phpunit": "~4.0", - "squizlabs/php_codesniffer": "~2.0" - }, - "type": "library", - "extra": { - "branch-alias": { - "dev-master": "1.0.x-dev" - } - }, - "autoload": { - "psr-4": { - "Doctrine\\Instantiator\\": "src/Doctrine/Instantiator/" - } - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "MIT" - ], - "authors": [ - { - "name": "Marco Pivetta", - "email": "ocramius@gmail.com", - "homepage": "http://ocramius.github.com/" - } - ], - "description": "A small, lightweight utility to instantiate objects in PHP without invoking their constructors", - "homepage": "https://github.com/doctrine/instantiator", - "keywords": [ - "constructor", - "instantiate" - ], - "time": "2015-06-14 21:17:01" - }, - { - "name": "phpdocumentor/reflection-docblock", - "version": "2.0.4", - "source": { - "type": "git", - "url": "https://github.com/phpDocumentor/ReflectionDocBlock.git", - "reference": "d68dbdc53dc358a816f00b300704702b2eaff7b8" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/phpDocumentor/ReflectionDocBlock/zipball/d68dbdc53dc358a816f00b300704702b2eaff7b8", - "reference": "d68dbdc53dc358a816f00b300704702b2eaff7b8", - "shasum": "" - }, - "require": { - "php": ">=5.3.3" - }, - "require-dev": { - "phpunit/phpunit": "~4.0" - }, - "suggest": { - "dflydev/markdown": "~1.0", - "erusev/parsedown": "~1.0" - }, - "type": "library", - "extra": { - "branch-alias": { - "dev-master": "2.0.x-dev" - } - }, - "autoload": { - "psr-0": { - "phpDocumentor": [ - "src/" - ] - } - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "MIT" - ], - "authors": [ - { - "name": "Mike van Riel", - "email": "mike.vanriel@naenius.com" - } - ], - "time": "2015-02-03 12:10:50" - }, - { - "name": "phpspec/prophecy", - "version": "v1.4.1", - "source": { - "type": "git", - "url": "https://github.com/phpspec/prophecy.git", - "reference": "3132b1f44c7bf2ec4c7eb2d3cb78fdeca760d373" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/phpspec/prophecy/zipball/3132b1f44c7bf2ec4c7eb2d3cb78fdeca760d373", - "reference": "3132b1f44c7bf2ec4c7eb2d3cb78fdeca760d373", - "shasum": "" - }, - "require": { - "doctrine/instantiator": "^1.0.2", - "phpdocumentor/reflection-docblock": "~2.0", - "sebastian/comparator": "~1.1" - }, - "require-dev": { - "phpspec/phpspec": "~2.0" - }, - "type": "library", - "extra": { - "branch-alias": { - "dev-master": "1.4.x-dev" - } - }, - "autoload": { - "psr-0": { - "Prophecy\\": "src/" - } - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "MIT" - ], - "authors": [ - { - "name": "Konstantin Kudryashov", - "email": "ever.zet@gmail.com", - "homepage": "http://everzet.com" - }, - { - "name": "Marcello Duarte", - "email": "marcello.duarte@gmail.com" - } - ], - "description": "Highly opinionated mocking framework for PHP 5.3+", - "homepage": "https://github.com/phpspec/prophecy", - "keywords": [ - "Double", - "Dummy", - "fake", - "mock", - "spy", - "stub" - ], - "time": "2015-04-27 22:15:08" - }, - { - "name": "phpunit/php-code-coverage", - "version": "2.1.6", - "source": { - "type": "git", - "url": "https://github.com/sebastianbergmann/php-code-coverage.git", - "reference": "631e365cf26bb2c078683e8d9bcf8bc631ac4d44" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/php-code-coverage/zipball/631e365cf26bb2c078683e8d9bcf8bc631ac4d44", - "reference": "631e365cf26bb2c078683e8d9bcf8bc631ac4d44", - "shasum": "" - }, - "require": { - "php": ">=5.3.3", - "phpunit/php-file-iterator": "~1.3", - "phpunit/php-text-template": "~1.2", - "phpunit/php-token-stream": "~1.3", - "sebastian/environment": "~1.0", - "sebastian/version": "~1.0" - }, - "require-dev": { - "ext-xdebug": ">=2.1.4", - "phpunit/phpunit": "~4" - }, - "suggest": { - "ext-dom": "*", - "ext-xdebug": ">=2.2.1", - "ext-xmlwriter": "*" - }, - "type": "library", - "extra": { - "branch-alias": { - "dev-master": "2.1.x-dev" - } - }, - "autoload": { - "classmap": [ - "src/" - ] - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "BSD-3-Clause" - ], - "authors": [ - { - "name": "Sebastian Bergmann", - "email": "sb@sebastian-bergmann.de", - "role": "lead" - } - ], - "description": "Library that provides collection, processing, and rendering functionality for PHP code coverage information.", - "homepage": "https://github.com/sebastianbergmann/php-code-coverage", - "keywords": [ - "coverage", - "testing", - "xunit" - ], - "time": "2015-06-19 07:11:55" - }, - { - "name": "phpunit/php-file-iterator", - "version": "1.4.0", - "source": { - "type": "git", - "url": "https://github.com/sebastianbergmann/php-file-iterator.git", - "reference": "a923bb15680d0089e2316f7a4af8f437046e96bb" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/php-file-iterator/zipball/a923bb15680d0089e2316f7a4af8f437046e96bb", - "reference": "a923bb15680d0089e2316f7a4af8f437046e96bb", - "shasum": "" - }, - "require": { - "php": ">=5.3.3" - }, - "type": "library", - "extra": { - "branch-alias": { - "dev-master": "1.4.x-dev" - } - }, - "autoload": { - "classmap": [ - "src/" - ] - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "BSD-3-Clause" - ], - "authors": [ - { - "name": "Sebastian Bergmann", - "email": "sb@sebastian-bergmann.de", - "role": "lead" - } - ], - "description": "FilterIterator implementation that filters files based on a list of suffixes.", - "homepage": "https://github.com/sebastianbergmann/php-file-iterator/", - "keywords": [ - "filesystem", - "iterator" - ], - "time": "2015-04-02 05:19:05" - }, - { - "name": "phpunit/php-text-template", - "version": "1.2.0", - "source": { - "type": "git", - "url": "https://github.com/sebastianbergmann/php-text-template.git", - "reference": "206dfefc0ffe9cebf65c413e3d0e809c82fbf00a" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/php-text-template/zipball/206dfefc0ffe9cebf65c413e3d0e809c82fbf00a", - "reference": "206dfefc0ffe9cebf65c413e3d0e809c82fbf00a", - "shasum": "" - }, - "require": { - "php": ">=5.3.3" - }, - "type": "library", - "autoload": { - "classmap": [ - "Text/" - ] - }, - "notification-url": "https://packagist.org/downloads/", - "include-path": [ - "" - ], - "license": [ - "BSD-3-Clause" - ], - "authors": [ - { - "name": "Sebastian Bergmann", - "email": "sb@sebastian-bergmann.de", - "role": "lead" - } - ], - "description": "Simple template engine.", - "homepage": "https://github.com/sebastianbergmann/php-text-template/", - "keywords": [ - "template" - ], - "time": "2014-01-30 17:20:04" - }, - { - "name": "phpunit/php-timer", - "version": "1.0.6", - "source": { - "type": "git", - "url": "https://github.com/sebastianbergmann/php-timer.git", - "reference": "83fe1bdc5d47658b727595c14da140da92b3d66d" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/php-timer/zipball/83fe1bdc5d47658b727595c14da140da92b3d66d", - "reference": "83fe1bdc5d47658b727595c14da140da92b3d66d", - "shasum": "" - }, - "require": { - "php": ">=5.3.3" - }, - "type": "library", - "autoload": { - "classmap": [ - "src/" - ] - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "BSD-3-Clause" - ], - "authors": [ - { - "name": "Sebastian Bergmann", - "email": "sb@sebastian-bergmann.de", - "role": "lead" - } - ], - "description": "Utility class for timing", - "homepage": "https://github.com/sebastianbergmann/php-timer/", - "keywords": [ - "timer" - ], - "time": "2015-06-13 07:35:30" - }, - { - "name": "phpunit/php-token-stream", - "version": "1.4.3", - "source": { - "type": "git", - "url": "https://github.com/sebastianbergmann/php-token-stream.git", - "reference": "7a9b0969488c3c54fd62b4d504b3ec758fd005d9" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/php-token-stream/zipball/7a9b0969488c3c54fd62b4d504b3ec758fd005d9", - "reference": "7a9b0969488c3c54fd62b4d504b3ec758fd005d9", - "shasum": "" - }, - "require": { - "ext-tokenizer": "*", - "php": ">=5.3.3" - }, - "require-dev": { - "phpunit/phpunit": "~4.2" - }, - "type": "library", - "extra": { - "branch-alias": { - "dev-master": "1.4-dev" - } - }, - "autoload": { - "classmap": [ - "src/" - ] - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "BSD-3-Clause" - ], - "authors": [ - { - "name": "Sebastian Bergmann", - "email": "sebastian@phpunit.de" - } - ], - "description": "Wrapper around PHP's tokenizer extension.", - "homepage": "https://github.com/sebastianbergmann/php-token-stream/", - "keywords": [ - "tokenizer" - ], - "time": "2015-06-19 03:43:16" - }, - { - "name": "phpunit/phpunit", - "version": "4.7.4", - "source": { - "type": "git", - "url": "https://github.com/sebastianbergmann/phpunit.git", - "reference": "e5f851f324f7add846316f39e668e9deac97a103" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/phpunit/zipball/e5f851f324f7add846316f39e668e9deac97a103", - "reference": "e5f851f324f7add846316f39e668e9deac97a103", - "shasum": "" - }, - "require": { - "ext-dom": "*", - "ext-json": "*", - "ext-pcre": "*", - "ext-reflection": "*", - "ext-spl": "*", - "php": ">=5.3.3", - "phpspec/prophecy": "~1.3,>=1.3.1", - "phpunit/php-code-coverage": "~2.1", - "phpunit/php-file-iterator": "~1.4", - "phpunit/php-text-template": "~1.2", - "phpunit/php-timer": ">=1.0.6", - "phpunit/phpunit-mock-objects": "~2.3", - "sebastian/comparator": "~1.1", - "sebastian/diff": "~1.2", - "sebastian/environment": "~1.2", - "sebastian/exporter": "~1.2", - "sebastian/global-state": "~1.0", - "sebastian/version": "~1.0", - "symfony/yaml": "~2.1|~3.0" - }, - "suggest": { - "phpunit/php-invoker": "~1.1" - }, - "bin": [ - "phpunit" - ], - "type": "library", - "extra": { - "branch-alias": { - "dev-master": "4.7.x-dev" - } - }, - "autoload": { - "classmap": [ - "src/" - ] - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "BSD-3-Clause" - ], - "authors": [ - { - "name": "Sebastian Bergmann", - "email": "sebastian@phpunit.de", - "role": "lead" - } - ], - "description": "The PHP Unit Testing framework.", - "homepage": "https://phpunit.de/", - "keywords": [ - "phpunit", - "testing", - "xunit" - ], - "time": "2015-06-18 13:33:26" - }, - { - "name": "phpunit/phpunit-mock-objects", - "version": "2.3.4", - "source": { - "type": "git", - "url": "https://github.com/sebastianbergmann/phpunit-mock-objects.git", - "reference": "92408bb1968a81b3217a6fdf6c1a198da83caa35" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/phpunit-mock-objects/zipball/92408bb1968a81b3217a6fdf6c1a198da83caa35", - "reference": "92408bb1968a81b3217a6fdf6c1a198da83caa35", - "shasum": "" - }, - "require": { - "doctrine/instantiator": "~1.0,>=1.0.2", - "php": ">=5.3.3", - "phpunit/php-text-template": "~1.2" - }, - "require-dev": { - "phpunit/phpunit": "~4.4" - }, - "suggest": { - "ext-soap": "*" - }, - "type": "library", - "extra": { - "branch-alias": { - "dev-master": "2.3.x-dev" - } - }, - "autoload": { - "classmap": [ - "src/" - ] - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "BSD-3-Clause" - ], - "authors": [ - { - "name": "Sebastian Bergmann", - "email": "sb@sebastian-bergmann.de", - "role": "lead" - } - ], - "description": "Mock Object library for PHPUnit", - "homepage": "https://github.com/sebastianbergmann/phpunit-mock-objects/", - "keywords": [ - "mock", - "xunit" - ], - "time": "2015-06-11 15:55:48" - }, - { - "name": "sebastian/comparator", - "version": "1.1.1", - "source": { - "type": "git", - "url": "https://github.com/sebastianbergmann/comparator.git", - "reference": "1dd8869519a225f7f2b9eb663e225298fade819e" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/comparator/zipball/1dd8869519a225f7f2b9eb663e225298fade819e", - "reference": "1dd8869519a225f7f2b9eb663e225298fade819e", - "shasum": "" - }, - "require": { - "php": ">=5.3.3", - "sebastian/diff": "~1.2", - "sebastian/exporter": "~1.2" - }, - "require-dev": { - "phpunit/phpunit": "~4.4" - }, - "type": "library", - "extra": { - "branch-alias": { - "dev-master": "1.1.x-dev" - } - }, - "autoload": { - "classmap": [ - "src/" - ] - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "BSD-3-Clause" - ], - "authors": [ - { - "name": "Jeff Welch", - "email": "whatthejeff@gmail.com" - }, - { - "name": "Volker Dusch", - "email": "github@wallbash.com" - }, - { - "name": "Bernhard Schussek", - "email": "bschussek@2bepublished.at" - }, - { - "name": "Sebastian Bergmann", - "email": "sebastian@phpunit.de" - } - ], - "description": "Provides the functionality to compare PHP values for equality", - "homepage": "http://www.github.com/sebastianbergmann/comparator", - "keywords": [ - "comparator", - "compare", - "equality" - ], - "time": "2015-01-29 16:28:08" - }, - { - "name": "sebastian/diff", - "version": "1.3.0", - "source": { - "type": "git", - "url": "https://github.com/sebastianbergmann/diff.git", - "reference": "863df9687835c62aa423a22412d26fa2ebde3fd3" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/diff/zipball/863df9687835c62aa423a22412d26fa2ebde3fd3", - "reference": "863df9687835c62aa423a22412d26fa2ebde3fd3", - "shasum": "" - }, - "require": { - "php": ">=5.3.3" - }, - "require-dev": { - "phpunit/phpunit": "~4.2" - }, - "type": "library", - "extra": { - "branch-alias": { - "dev-master": "1.3-dev" - } - }, - "autoload": { - "classmap": [ - "src/" - ] - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "BSD-3-Clause" - ], - "authors": [ - { - "name": "Kore Nordmann", - "email": "mail@kore-nordmann.de" - }, - { - "name": "Sebastian Bergmann", - "email": "sebastian@phpunit.de" - } - ], - "description": "Diff implementation", - "homepage": "http://www.github.com/sebastianbergmann/diff", - "keywords": [ - "diff" - ], - "time": "2015-02-22 15:13:53" - }, - { - "name": "sebastian/environment", - "version": "1.2.2", - "source": { - "type": "git", - "url": "https://github.com/sebastianbergmann/environment.git", - "reference": "5a8c7d31914337b69923db26c4221b81ff5a196e" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/environment/zipball/5a8c7d31914337b69923db26c4221b81ff5a196e", - "reference": "5a8c7d31914337b69923db26c4221b81ff5a196e", - "shasum": "" - }, - "require": { - "php": ">=5.3.3" - }, - "require-dev": { - "phpunit/phpunit": "~4.4" - }, - "type": "library", - "extra": { - "branch-alias": { - "dev-master": "1.3.x-dev" - } - }, - "autoload": { - "classmap": [ - "src/" - ] - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "BSD-3-Clause" - ], - "authors": [ - { - "name": "Sebastian Bergmann", - "email": "sebastian@phpunit.de" - } - ], - "description": "Provides functionality to handle HHVM/PHP environments", - "homepage": "http://www.github.com/sebastianbergmann/environment", - "keywords": [ - "Xdebug", - "environment", - "hhvm" - ], - "time": "2015-01-01 10:01:08" - }, - { - "name": "sebastian/exporter", - "version": "1.2.0", - "source": { - "type": "git", - "url": "https://github.com/sebastianbergmann/exporter.git", - "reference": "84839970d05254c73cde183a721c7af13aede943" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/exporter/zipball/84839970d05254c73cde183a721c7af13aede943", - "reference": "84839970d05254c73cde183a721c7af13aede943", - "shasum": "" - }, - "require": { - "php": ">=5.3.3", - "sebastian/recursion-context": "~1.0" - }, - "require-dev": { - "phpunit/phpunit": "~4.4" - }, - "type": "library", - "extra": { - "branch-alias": { - "dev-master": "1.2.x-dev" - } - }, - "autoload": { - "classmap": [ - "src/" - ] - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "BSD-3-Clause" - ], - "authors": [ - { - "name": "Jeff Welch", - "email": "whatthejeff@gmail.com" - }, - { - "name": "Volker Dusch", - "email": "github@wallbash.com" - }, - { - "name": "Bernhard Schussek", - "email": "bschussek@2bepublished.at" - }, - { - "name": "Sebastian Bergmann", - "email": "sebastian@phpunit.de" - }, - { - "name": "Adam Harvey", - "email": "aharvey@php.net" - } - ], - "description": "Provides the functionality to export PHP variables for visualization", - "homepage": "http://www.github.com/sebastianbergmann/exporter", - "keywords": [ - "export", - "exporter" - ], - "time": "2015-01-27 07:23:06" - }, - { - "name": "sebastian/global-state", - "version": "1.0.0", - "source": { - "type": "git", - "url": "https://github.com/sebastianbergmann/global-state.git", - "reference": "c7428acdb62ece0a45e6306f1ae85e1c05b09c01" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/global-state/zipball/c7428acdb62ece0a45e6306f1ae85e1c05b09c01", - "reference": "c7428acdb62ece0a45e6306f1ae85e1c05b09c01", - "shasum": "" - }, - "require": { - "php": ">=5.3.3" - }, - "require-dev": { - "phpunit/phpunit": "~4.2" - }, - "suggest": { - "ext-uopz": "*" - }, - "type": "library", - "extra": { - "branch-alias": { - "dev-master": "1.0-dev" - } - }, - "autoload": { - "classmap": [ - "src/" - ] - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "BSD-3-Clause" - ], - "authors": [ - { - "name": "Sebastian Bergmann", - "email": "sebastian@phpunit.de" - } - ], - "description": "Snapshotting of global state", - "homepage": "http://www.github.com/sebastianbergmann/global-state", - "keywords": [ - "global state" - ], - "time": "2014-10-06 09:23:50" - }, - { - "name": "sebastian/recursion-context", - "version": "1.0.0", - "source": { - "type": "git", - "url": "https://github.com/sebastianbergmann/recursion-context.git", - "reference": "3989662bbb30a29d20d9faa04a846af79b276252" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/recursion-context/zipball/3989662bbb30a29d20d9faa04a846af79b276252", - "reference": "3989662bbb30a29d20d9faa04a846af79b276252", - "shasum": "" - }, - "require": { - "php": ">=5.3.3" - }, - "require-dev": { - "phpunit/phpunit": "~4.4" - }, - "type": "library", - "extra": { - "branch-alias": { - "dev-master": "1.0.x-dev" - } - }, - "autoload": { - "classmap": [ - "src/" - ] - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "BSD-3-Clause" - ], - "authors": [ - { - "name": "Jeff Welch", - "email": "whatthejeff@gmail.com" - }, - { - "name": "Sebastian Bergmann", - "email": "sebastian@phpunit.de" - }, - { - "name": "Adam Harvey", - "email": "aharvey@php.net" - } - ], - "description": "Provides functionality to recursively process PHP variables", - "homepage": "http://www.github.com/sebastianbergmann/recursion-context", - "time": "2015-01-24 09:48:32" - }, - { - "name": "sebastian/version", - "version": "1.0.5", - "source": { - "type": "git", - "url": "https://github.com/sebastianbergmann/version.git", - "reference": "ab931d46cd0d3204a91e1b9a40c4bc13032b58e4" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/version/zipball/ab931d46cd0d3204a91e1b9a40c4bc13032b58e4", - "reference": "ab931d46cd0d3204a91e1b9a40c4bc13032b58e4", - "shasum": "" - }, - "type": "library", - "autoload": { - "classmap": [ - "src/" - ] - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "BSD-3-Clause" - ], - "authors": [ - { - "name": "Sebastian Bergmann", - "email": "sebastian@phpunit.de", - "role": "lead" - } - ], - "description": "Library that helps with managing the version number of Git-hosted PHP projects", - "homepage": "https://github.com/sebastianbergmann/version", - "time": "2015-02-24 06:35:25" - }, - { - "name": "symfony/yaml", - "version": "v2.7.1", - "source": { - "type": "git", - "url": "https://github.com/symfony/Yaml.git", - "reference": "9808e75c609a14f6db02f70fccf4ca4aab53c160" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/symfony/Yaml/zipball/9808e75c609a14f6db02f70fccf4ca4aab53c160", - "reference": "9808e75c609a14f6db02f70fccf4ca4aab53c160", - "shasum": "" - }, - "require": { - "php": ">=5.3.9" - }, - "require-dev": { - "symfony/phpunit-bridge": "~2.7" - }, - "type": "library", - "extra": { - "branch-alias": { - "dev-master": "2.7-dev" - } - }, - "autoload": { - "psr-4": { - "Symfony\\Component\\Yaml\\": "" - } - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "MIT" - ], - "authors": [ - { - "name": "Fabien Potencier", - "email": "fabien@symfony.com" - }, - { - "name": "Symfony Community", - "homepage": "https://symfony.com/contributors" - } - ], - "description": "Symfony Yaml Component", - "homepage": "https://symfony.com", - "time": "2015-06-10 15:30:22" - } - ], - "aliases": [], - "minimum-stability": "stable", - "stability-flags": [], - "prefer-stable": false, - "prefer-lowest": false, - "platform": { - "php": ">=5.3.0" - }, - "platform-dev": [] -} diff --git a/curweather/vendor/cmfcmf/openweathermap-php-api/phpunit.xml.dist b/curweather/vendor/cmfcmf/openweathermap-php-api/phpunit.xml.dist deleted file mode 100644 index cceb148d..00000000 --- a/curweather/vendor/cmfcmf/openweathermap-php-api/phpunit.xml.dist +++ /dev/null @@ -1,22 +0,0 @@ - - - - - - - - ./tests - - - - - - ./ - - ./ - ./ - ./vendor - - - - diff --git a/curweather/vendor/cmfcmf/openweathermap-php-api/tests/Fetcher/CurlFetcherTest.php b/curweather/vendor/cmfcmf/openweathermap-php-api/tests/Fetcher/CurlFetcherTest.php deleted file mode 100644 index 7f2cfe9a..00000000 --- a/curweather/vendor/cmfcmf/openweathermap-php-api/tests/Fetcher/CurlFetcherTest.php +++ /dev/null @@ -1,53 +0,0 @@ -fetch('http://notexisting.example.com'); - - $this->assertSame(false, $content); - } - - public function testEmptyUrl() - { - $fetcher = new CurlFetcher(); - - $content = $fetcher->fetch(''); - - $this->assertSame(false, $content); - } - - public function testValidUrl() - { - $fetcher = new CurlFetcher(); - - $content = $fetcher->fetch('http://httpbin.org/html'); - - $this->assertContains('Herman Melville', $content); - } -} diff --git a/curweather/vendor/cmfcmf/openweathermap-php-api/tests/Fetcher/FileGetContentsFetcherTest.php b/curweather/vendor/cmfcmf/openweathermap-php-api/tests/Fetcher/FileGetContentsFetcherTest.php deleted file mode 100644 index f556c09f..00000000 --- a/curweather/vendor/cmfcmf/openweathermap-php-api/tests/Fetcher/FileGetContentsFetcherTest.php +++ /dev/null @@ -1,59 +0,0 @@ -markTestSkipped('"allow_url_fopen" is set to off.'); - } - } - - /** - * @expectedException \PHPUnit_Framework_Error_Warning - */ - public function testInvalidUrl() - { - $fetcher = new FileGetContentsFetcher(); - - $fetcher->fetch('http://notexisting.example.com'); - } - - /** - * @expectedException \PHPUnit_Framework_Error_Warning - */ - public function testEmptyUrl() - { - $fetcher = new FileGetContentsFetcher(); - - $fetcher->fetch(''); - } - - public function testValidUrl() - { - $fetcher = new FileGetContentsFetcher(); - - $content = $fetcher->fetch('http://httpbin.org/html'); - - $this->assertContains('Herman Melville', $content); - } -} diff --git a/curweather/vendor/cmfcmf/openweathermap-php-api/tests/Util/SunTest.php b/curweather/vendor/cmfcmf/openweathermap-php-api/tests/Util/SunTest.php deleted file mode 100644 index 516a796d..00000000 --- a/curweather/vendor/cmfcmf/openweathermap-php-api/tests/Util/SunTest.php +++ /dev/null @@ -1,62 +0,0 @@ -givenThereIsASunObject($rise, $set); - - $this->assertSame($rise, $this->sun->rise); - } - - public function testSunSet() - { - $rise = new \DateTime('2014-01-01 08:00:00'); - $set = new \DateTime('2014-01-01 20:00:00'); - - $this->givenThereIsASunObject($rise, $set); - - $this->assertSame($set, $this->sun->set); - } - - - private function givenThereIsASunObject($rise, $set) - { - $this->sun = new Sun($rise, $set); - } - - /** - * @expectedException \LogicException - */ - public function testSunSetBeforeSunRiseException() - { - $rise = new \DateTime('2014-01-01 08:00:00'); - $set = new \DateTime('2014-01-01 7:00:00'); - - $this->givenThereIsASunObject($rise, $set); - } -} diff --git a/curweather/vendor/cmfcmf/openweathermap-php-api/tests/Util/UnitTest.php b/curweather/vendor/cmfcmf/openweathermap-php-api/tests/Util/UnitTest.php deleted file mode 100644 index bd85e16f..00000000 --- a/curweather/vendor/cmfcmf/openweathermap-php-api/tests/Util/UnitTest.php +++ /dev/null @@ -1,159 +0,0 @@ -givenThereIsAUnitWithValue(self::POSITIVE_INT_VALUE); - - $this->assertSame((float)self::POSITIVE_INT_VALUE, $this->unit->getValue()); - } - - public function testGetValueWithPositiveFloatValue() - { - $this->givenThereIsAUnitWithValue(self::POSITIVE_FLOAT_VALUE); - - $this->assertSame(self::POSITIVE_FLOAT_VALUE, $this->unit->getValue()); - } - - public function testGetValueWithNegativeIntValue() - { - $this->givenThereIsAUnitWithValue(self::NEGATIVE_INT_VALUE); - - $this->assertSame((float)self::NEGATIVE_INT_VALUE, $this->unit->getValue()); - } - - public function testGetValueWithNegativeFloatValue() - { - $this->givenThereIsAUnitWithValue(self::NEGATIVE_FLOAT_VALUE); - - $this->assertSame(self::NEGATIVE_FLOAT_VALUE, $this->unit->getValue()); - } - - public function testGetValueWithZeroIntValue() - { - $this->givenThereIsAUnitWithValue(self::ZERO_INT_VALUE); - - $this->assertSame((float)self::ZERO_INT_VALUE, $this->unit->getValue()); - } - - public function testGetValueWithZeroFloatValue() - { - $this->givenThereIsAUnitWithValue(self::ZERO_FLOAT_VALUE); - - $this->assertSame(self::ZERO_FLOAT_VALUE, $this->unit->getValue()); - } - - private function givenThereIsAUnitWithValue($value, $unit = null) - { - $this->unit = $unit === null ? new Unit($value) : new Unit($value, $unit); - } - - public function testGetUnitWithEmptyUnit() - { - $this->givenThereIsAUnitWithUnit(""); - - $this->assertSame("", $this->unit->getUnit()); - } - - public function testGetUnitWithStringAsUnit() - { - $this->givenThereIsAUnitWithUnit("Hey! I'm cmfcmf"); - - $this->assertSame("Hey! I'm cmfcmf", $this->unit->getUnit()); - } - - public function testCelsiusFixture() - { - $this->givenThereIsAUnitWithUnit("celsius"); - - $this->assertSame("°C", $this->unit->getUnit()); - } - - public function testFahrenheitFixture() - { - $this->givenThereIsAUnitWithUnit("fahrenheit"); - - $this->assertSame("F", $this->unit->getUnit()); - } - - private function givenThereIsAUnitWithUnit($unit) - { - $this->unit = new Unit(0, $unit); - } - - public function testGetDescriptionWithEmptyDescription() - { - $this->givenThereIsAUnitWithDescription(""); - - $this->assertSame("", $this->unit->getDescription()); - } - - public function testGetDescriptionWithStringAsDescription() - { - $this->givenThereIsAUnitWithDescription("Hey! I'm cmfcmf"); - - $this->assertSame("Hey! I'm cmfcmf", $this->unit->getDescription()); - } - - private function givenThereIsAUnitWithDescription($description) - { - $this->unit = new Unit(0, "", $description); - } - - public function testGetFormattedWithoutUnit() - { - $this->givenThereIsAUnitWithValue(self::POSITIVE_INT_VALUE); - - $this->assertEquals(self::POSITIVE_INT_VALUE, $this->unit->getFormatted()); - $this->assertEquals($this->unit->getValue(), $this->unit->getFormatted()); - } - - public function testGetFormattedWithUnit() - { - $this->givenThereIsAUnitWithValue(self::POSITIVE_INT_VALUE, 'K'); - - $this->assertEquals(self::POSITIVE_INT_VALUE . ' K', $this->unit->getFormatted()); - $this->assertEquals($this->unit->getValue() . ' ' . $this->unit->getUnit(), $this->unit->getFormatted()); - } - - public function testToString() - { - $this->givenThereIsAUnitWithValue(self::POSITIVE_INT_VALUE, 'K'); - - $this->assertEquals($this->unit->getFormatted(), $this->unit); - } -} diff --git a/curweather/vendor/cmfcmf/openweathermap-php-api/tests/bootstrap.php b/curweather/vendor/cmfcmf/openweathermap-php-api/tests/bootstrap.php deleted file mode 100644 index a844cc5a..00000000 --- a/curweather/vendor/cmfcmf/openweathermap-php-api/tests/bootstrap.php +++ /dev/null @@ -1,12 +0,0 @@ - - * Jordi Boggiano - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -namespace Composer\Autoload; - -/** - * ClassLoader implements a PSR-0 class loader - * - * See https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-0.md - * - * $loader = new \Composer\Autoload\ClassLoader(); - * - * // register classes with namespaces - * $loader->add('Symfony\Component', __DIR__.'/component'); - * $loader->add('Symfony', __DIR__.'/framework'); - * - * // activate the autoloader - * $loader->register(); - * - * // to enable searching the include path (eg. for PEAR packages) - * $loader->setUseIncludePath(true); - * - * In this example, if you try to use a class in the Symfony\Component - * namespace or one of its children (Symfony\Component\Console for instance), - * the autoloader will first look for the class under the component/ - * directory, and it will then fallback to the framework/ directory if not - * found before giving up. - * - * This class is loosely based on the Symfony UniversalClassLoader. - * - * @author Fabien Potencier - * @author Jordi Boggiano - */ -class ClassLoader -{ - // PSR-4 - private $prefixLengthsPsr4 = array(); - private $prefixDirsPsr4 = array(); - private $fallbackDirsPsr4 = array(); - - // PSR-0 - private $prefixesPsr0 = array(); - private $fallbackDirsPsr0 = array(); - - private $useIncludePath = false; - private $classMap = array(); - - private $classMapAuthoritative = false; - - public function getPrefixes() - { - if (!empty($this->prefixesPsr0)) { - return call_user_func_array('array_merge', $this->prefixesPsr0); - } - - return array(); - } - - public function getPrefixesPsr4() - { - return $this->prefixDirsPsr4; - } - - public function getFallbackDirs() - { - return $this->fallbackDirsPsr0; - } - - public function getFallbackDirsPsr4() - { - return $this->fallbackDirsPsr4; - } - - public function getClassMap() - { - return $this->classMap; - } - - /** - * @param array $classMap Class to filename map - */ - public function addClassMap(array $classMap) - { - if ($this->classMap) { - $this->classMap = array_merge($this->classMap, $classMap); - } else { - $this->classMap = $classMap; - } - } - - /** - * Registers a set of PSR-0 directories for a given prefix, either - * appending or prepending to the ones previously set for this prefix. - * - * @param string $prefix The prefix - * @param array|string $paths The PSR-0 root directories - * @param bool $prepend Whether to prepend the directories - */ - public function add($prefix, $paths, $prepend = false) - { - if (!$prefix) { - if ($prepend) { - $this->fallbackDirsPsr0 = array_merge( - (array) $paths, - $this->fallbackDirsPsr0 - ); - } else { - $this->fallbackDirsPsr0 = array_merge( - $this->fallbackDirsPsr0, - (array) $paths - ); - } - - return; - } - - $first = $prefix[0]; - if (!isset($this->prefixesPsr0[$first][$prefix])) { - $this->prefixesPsr0[$first][$prefix] = (array) $paths; - - return; - } - if ($prepend) { - $this->prefixesPsr0[$first][$prefix] = array_merge( - (array) $paths, - $this->prefixesPsr0[$first][$prefix] - ); - } else { - $this->prefixesPsr0[$first][$prefix] = array_merge( - $this->prefixesPsr0[$first][$prefix], - (array) $paths - ); - } - } - - /** - * Registers a set of PSR-4 directories for a given namespace, either - * appending or prepending to the ones previously set for this namespace. - * - * @param string $prefix The prefix/namespace, with trailing '\\' - * @param array|string $paths The PSR-0 base directories - * @param bool $prepend Whether to prepend the directories - * - * @throws \InvalidArgumentException - */ - public function addPsr4($prefix, $paths, $prepend = false) - { - if (!$prefix) { - // Register directories for the root namespace. - if ($prepend) { - $this->fallbackDirsPsr4 = array_merge( - (array) $paths, - $this->fallbackDirsPsr4 - ); - } else { - $this->fallbackDirsPsr4 = array_merge( - $this->fallbackDirsPsr4, - (array) $paths - ); - } - } elseif (!isset($this->prefixDirsPsr4[$prefix])) { - // Register directories for a new namespace. - $length = strlen($prefix); - if ('\\' !== $prefix[$length - 1]) { - throw new \InvalidArgumentException("A non-empty PSR-4 prefix must end with a namespace separator."); - } - $this->prefixLengthsPsr4[$prefix[0]][$prefix] = $length; - $this->prefixDirsPsr4[$prefix] = (array) $paths; - } elseif ($prepend) { - // Prepend directories for an already registered namespace. - $this->prefixDirsPsr4[$prefix] = array_merge( - (array) $paths, - $this->prefixDirsPsr4[$prefix] - ); - } else { - // Append directories for an already registered namespace. - $this->prefixDirsPsr4[$prefix] = array_merge( - $this->prefixDirsPsr4[$prefix], - (array) $paths - ); - } - } - - /** - * Registers a set of PSR-0 directories for a given prefix, - * replacing any others previously set for this prefix. - * - * @param string $prefix The prefix - * @param array|string $paths The PSR-0 base directories - */ - public function set($prefix, $paths) - { - if (!$prefix) { - $this->fallbackDirsPsr0 = (array) $paths; - } else { - $this->prefixesPsr0[$prefix[0]][$prefix] = (array) $paths; - } - } - - /** - * Registers a set of PSR-4 directories for a given namespace, - * replacing any others previously set for this namespace. - * - * @param string $prefix The prefix/namespace, with trailing '\\' - * @param array|string $paths The PSR-4 base directories - * - * @throws \InvalidArgumentException - */ - public function setPsr4($prefix, $paths) - { - if (!$prefix) { - $this->fallbackDirsPsr4 = (array) $paths; - } else { - $length = strlen($prefix); - if ('\\' !== $prefix[$length - 1]) { - throw new \InvalidArgumentException("A non-empty PSR-4 prefix must end with a namespace separator."); - } - $this->prefixLengthsPsr4[$prefix[0]][$prefix] = $length; - $this->prefixDirsPsr4[$prefix] = (array) $paths; - } - } - - /** - * Turns on searching the include path for class files. - * - * @param bool $useIncludePath - */ - public function setUseIncludePath($useIncludePath) - { - $this->useIncludePath = $useIncludePath; - } - - /** - * Can be used to check if the autoloader uses the include path to check - * for classes. - * - * @return bool - */ - public function getUseIncludePath() - { - return $this->useIncludePath; - } - - /** - * Turns off searching the prefix and fallback directories for classes - * that have not been registered with the class map. - * - * @param bool $classMapAuthoritative - */ - public function setClassMapAuthoritative($classMapAuthoritative) - { - $this->classMapAuthoritative = $classMapAuthoritative; - } - - /** - * Should class lookup fail if not found in the current class map? - * - * @return bool - */ - public function isClassMapAuthoritative() - { - return $this->classMapAuthoritative; - } - - /** - * Registers this instance as an autoloader. - * - * @param bool $prepend Whether to prepend the autoloader or not - */ - public function register($prepend = false) - { - spl_autoload_register(array($this, 'loadClass'), true, $prepend); - } - - /** - * Unregisters this instance as an autoloader. - */ - public function unregister() - { - spl_autoload_unregister(array($this, 'loadClass')); - } - - /** - * Loads the given class or interface. - * - * @param string $class The name of the class - * @return bool|null True if loaded, null otherwise - */ - public function loadClass($class) - { - if ($file = $this->findFile($class)) { - includeFile($file); - - return true; - } - } - - /** - * Finds the path to the file where the class is defined. - * - * @param string $class The name of the class - * - * @return string|false The path if found, false otherwise - */ - public function findFile($class) - { - // work around for PHP 5.3.0 - 5.3.2 https://bugs.php.net/50731 - if ('\\' == $class[0]) { - $class = substr($class, 1); - } - - // class map lookup - if (isset($this->classMap[$class])) { - return $this->classMap[$class]; - } - if ($this->classMapAuthoritative) { - return false; - } - - $file = $this->findFileWithExtension($class, '.php'); - - // Search for Hack files if we are running on HHVM - if ($file === null && defined('HHVM_VERSION')) { - $file = $this->findFileWithExtension($class, '.hh'); - } - - if ($file === null) { - // Remember that this class does not exist. - return $this->classMap[$class] = false; - } - - return $file; - } - - private function findFileWithExtension($class, $ext) - { - // PSR-4 lookup - $logicalPathPsr4 = strtr($class, '\\', DIRECTORY_SEPARATOR) . $ext; - - $first = $class[0]; - if (isset($this->prefixLengthsPsr4[$first])) { - foreach ($this->prefixLengthsPsr4[$first] as $prefix => $length) { - if (0 === strpos($class, $prefix)) { - foreach ($this->prefixDirsPsr4[$prefix] as $dir) { - if (is_file($file = $dir . DIRECTORY_SEPARATOR . substr($logicalPathPsr4, $length))) { - return $file; - } - } - } - } - } - - // PSR-4 fallback dirs - foreach ($this->fallbackDirsPsr4 as $dir) { - if (is_file($file = $dir . DIRECTORY_SEPARATOR . $logicalPathPsr4)) { - return $file; - } - } - - // PSR-0 lookup - if (false !== $pos = strrpos($class, '\\')) { - // namespaced class name - $logicalPathPsr0 = substr($logicalPathPsr4, 0, $pos + 1) - . strtr(substr($logicalPathPsr4, $pos + 1), '_', DIRECTORY_SEPARATOR); - } else { - // PEAR-like class name - $logicalPathPsr0 = strtr($class, '_', DIRECTORY_SEPARATOR) . $ext; - } - - if (isset($this->prefixesPsr0[$first])) { - foreach ($this->prefixesPsr0[$first] as $prefix => $dirs) { - if (0 === strpos($class, $prefix)) { - foreach ($dirs as $dir) { - if (is_file($file = $dir . DIRECTORY_SEPARATOR . $logicalPathPsr0)) { - return $file; - } - } - } - } - } - - // PSR-0 fallback dirs - foreach ($this->fallbackDirsPsr0 as $dir) { - if (is_file($file = $dir . DIRECTORY_SEPARATOR . $logicalPathPsr0)) { - return $file; - } - } - - // PSR-0 include paths. - if ($this->useIncludePath && $file = stream_resolve_include_path($logicalPathPsr0)) { - return $file; - } - } -} - -/** - * Scope isolated include. - * - * Prevents access to $this/self from included files. - */ -function includeFile($file) -{ - include $file; -} diff --git a/curweather/vendor/composer/autoload_classmap.php b/curweather/vendor/composer/autoload_classmap.php deleted file mode 100644 index 7a91153b..00000000 --- a/curweather/vendor/composer/autoload_classmap.php +++ /dev/null @@ -1,9 +0,0 @@ - array($vendorDir . '/cmfcmf/openweathermap-php-api'), -); diff --git a/curweather/vendor/composer/autoload_psr4.php b/curweather/vendor/composer/autoload_psr4.php deleted file mode 100644 index b265c64a..00000000 --- a/curweather/vendor/composer/autoload_psr4.php +++ /dev/null @@ -1,9 +0,0 @@ - $path) { - $loader->set($namespace, $path); - } - - $map = require __DIR__ . '/autoload_psr4.php'; - foreach ($map as $namespace => $path) { - $loader->setPsr4($namespace, $path); - } - - $classMap = require __DIR__ . '/autoload_classmap.php'; - if ($classMap) { - $loader->addClassMap($classMap); - } - - $loader->register(true); - - return $loader; - } -} - -function composerRequire6bf0e42f34a65c53928f3dc22e5b93d3($file) -{ - require $file; -} diff --git a/curweather/vendor/composer/installed.json b/curweather/vendor/composer/installed.json deleted file mode 100644 index cdba81cc..00000000 --- a/curweather/vendor/composer/installed.json +++ /dev/null @@ -1,51 +0,0 @@ -[ - { - "name": "cmfcmf/openweathermap-php-api", - "version": "v2.0.7", - "version_normalized": "2.0.7.0", - "source": { - "type": "git", - "url": "https://github.com/cmfcmf/OpenWeatherMap-PHP-Api.git", - "reference": "ab387ebcad332b1e58be443f760e1235e7976443" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/cmfcmf/OpenWeatherMap-PHP-Api/zipball/ab387ebcad332b1e58be443f760e1235e7976443", - "reference": "ab387ebcad332b1e58be443f760e1235e7976443", - "shasum": "" - }, - "require": { - "php": ">=5.3.0" - }, - "require-dev": { - "phpunit/phpunit": "^4.7.0" - }, - "time": "2015-06-23 21:07:37", - "type": "library", - "installation-source": "dist", - "autoload": { - "psr-0": { - "Cmfcmf\\": "" - } - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "MIT" - ], - "authors": [ - { - "name": "Christian Flach (cmfcmf)", - "email": "cmfcmf.flach@gmail.com", - "homepage": "http://cmfcmf.github.io", - "role": "Developer" - } - ], - "description": "A php api to parse weather data from OpenWeatherMap.org. This api tries to normalise and abstract the data and remove inconsistencies.", - "homepage": "https://github.com/cmfcmf/OpenWeatherMap-PHP-Api", - "keywords": [ - "OpenWeatherMap", - "weather", - "weather api" - ] - } -] From c0e27bbe80df29a5b07b80b72db2fd3334998f87 Mon Sep 17 00:00:00 2001 From: Tobias Diekershoff Date: Mon, 13 Jul 2015 09:17:35 +0200 Subject: [PATCH 17/28] but keep the composer.json for reverence --- curweather/composer.json | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 curweather/composer.json diff --git a/curweather/composer.json b/curweather/composer.json new file mode 100644 index 00000000..d54ac721 --- /dev/null +++ b/curweather/composer.json @@ -0,0 +1,5 @@ +{ + "require": { + "cmfcmf/openweathermap-php-api": "~2.0" + } +} From 317e8724c58d151d659a1443b55953c5747bfd47 Mon Sep 17 00:00:00 2001 From: Tobias Diekershoff Date: Mon, 13 Jul 2015 11:22:51 +0200 Subject: [PATCH 18/28] template for the widget should an error occur --- curweather/curweather.php | 42 ++++++++++++++++++--------- curweather/templates/widget-error.tpl | 1 + 2 files changed, 29 insertions(+), 14 deletions(-) create mode 100644 curweather/templates/widget-error.tpl diff --git a/curweather/curweather.php b/curweather/curweather.php index 29b16512..34590a7e 100644 --- a/curweather/curweather.php +++ b/curweather/curweather.php @@ -14,6 +14,8 @@ use Cmfcmf\OpenWeatherMap\Exception as OWMException; // Must point to composer's autoload file. require('vendor/autoload.php'); +//require('addon/curweather/openweathermap-php-api/Cmfcmf/OpenWeatherMap.php'); +//require('addon/curweather/vendor/cmfcmf/openweathermap-php-api/Cmfcmf/OpenWeatherMap.php'); function curweather_install() { register_hook('network_mod_init', 'addon/curweather/curweather.php', 'curweather_network_mod_init'); @@ -106,6 +108,7 @@ function curweather_network_mod_init(&$fk_app,&$b) { // Example_Cache.php to see how it works). //$owm = new OpenWeatherMap(); $owm = new OpenWeatherMap(null, new CWCache(), $cachetime); + $ok = true; try { $weather = $owm->getWeather($rpt, $units, $lang, $appid); @@ -125,23 +128,34 @@ function curweather_network_mod_init(&$fk_app,&$b) { 'lat' =>$weather->city->lat ); } catch(OWMException $e) { - info ( 'OpenWeatherMap exception: ' . $e->getMessage() . ' (Code ' . $e->getCode() . ').'); + info ( 'OpenWeatherMap exception: ' . $e->getMessage() . ' (Code ' . $e->getCode() . ').'); + $ok = false; } catch(\Exception $e) { - info ('General exception: ' . $e->getMessage() . ' (Code ' . $e->getCode() . ').'); + info ('General exception: ' . $e->getMessage() . ' (Code ' . $e->getCode() . ').'); + $ok = false; } - $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') - )); + if ($ok) { + $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') + )); + } else { + $t = get_markup_template('widget-error.tpl', 'addon/curweather/'); + $curweather = replace_macros( $t, array( + '$problem' => t('There was a problem accessing the weather data. But have a look'), + '$rpt' => $rpt, + '$atOWM' => t('at OpenWeatherMap') + )); + } $fk_app->page['aside'] = $curweather.$fk_app->page['aside']; diff --git a/curweather/templates/widget-error.tpl b/curweather/templates/widget-error.tpl new file mode 100644 index 00000000..c5762404 --- /dev/null +++ b/curweather/templates/widget-error.tpl @@ -0,0 +1 @@ +
{{$problem}} {{$atOWM}}.
From 24975c93cbe7ac96c6592998ddc5555024195c10 Mon Sep 17 00:00:00 2001 From: Tobias Diekershoff Date: Mon, 13 Jul 2015 13:24:58 +0200 Subject: [PATCH 19/28] avaid the hazzle, do it manually" This reverts commit c0e27bbe80df29a5b07b80b72db2fd3334998f87. --- curweather/composer.json | 5 ----- 1 file changed, 5 deletions(-) delete mode 100644 curweather/composer.json diff --git a/curweather/composer.json b/curweather/composer.json deleted file mode 100644 index d54ac721..00000000 --- a/curweather/composer.json +++ /dev/null @@ -1,5 +0,0 @@ -{ - "require": { - "cmfcmf/openweathermap-php-api": "~2.0" - } -} From 710780392c59c68f25981d224c2ac84ec91a70fc Mon Sep 17 00:00:00 2001 From: Tobias Diekershoff Date: Mon, 13 Jul 2015 13:28:47 +0200 Subject: [PATCH 20/28] README cleanup --- curweather/README.md | 4 ---- 1 file changed, 4 deletions(-) diff --git a/curweather/README.md b/curweather/README.md index 140e171e..9c901278 100644 --- a/curweather/README.md +++ b/curweather/README.md @@ -21,7 +21,3 @@ Credits * Tobias Diekershoff switched the sources to OpenWeatherMap after the original provider turned off support for locations outside of the USA. -To access the API of OpenWeatherMap the library -[OpenWeatherMap-PHP-API](https://github.com/cmfcmf/OpenWeatherMap-PHP-Api) by -Christian Flach is used (MIT license). - From c3459bd66c4082d60d2fa37b606476eed43c1e2b Mon Sep 17 00:00:00 2001 From: Tobias Diekershoff Date: Mon, 13 Jul 2015 16:21:43 +0200 Subject: [PATCH 21/28] manually fetch data from openweathermap and parse it --- curweather/curweather.php | 134 +++++++++++--------------------- curweather/templates/widget.tpl | 2 +- 2 files changed, 45 insertions(+), 91 deletions(-) diff --git a/curweather/curweather.php b/curweather/curweather.php index 34590a7e..cfe66b7e 100644 --- a/curweather/curweather.php +++ b/curweather/curweather.php @@ -8,77 +8,52 @@ * Author: Tobias Diekershoff * */ -use Cmfcmf\OpenWeatherMap; -use Cmfcmf\OpenWeatherMap\AbstractCache; -use Cmfcmf\OpenWeatherMap\Exception as OWMException; -// Must point to composer's autoload file. -require('vendor/autoload.php'); -//require('addon/curweather/openweathermap-php-api/Cmfcmf/OpenWeatherMap.php'); -//require('addon/curweather/vendor/cmfcmf/openweathermap-php-api/Cmfcmf/OpenWeatherMap.php'); +require_once('include/network.php'); +include_once('include/text.php'); + +// get the weather data from OpenWeatherMap +function getWeather( $loc, $units='metric', $lang='en', $appid='') { + $url = "http://api.openweathermap.org/data/2.5/weather?q=".$loc."&appid=".$appid."&lang=".$lang."&units=".$units."&mode=xml"; + try { + $res = new SimpleXMLElement(fetch_url($url)); + } catch (Exception $e) { + info(t('Error fetching weather data.\nError was: '.$e->getMessage())); + return false; + } + if ((string)$res->temperature['unit']==='metric') { + $tunit = '°C'; + $wunit = 'm/s'; + } else { + $tunit = '°F'; + $wunit = 'mph'; + } + return array( + 'city'=> (string) $res->city['name'][0], + 'country' => (string) $res->city->country[0], + 'lat' => (string) $res->city->coord['lat'], + 'lon' => (string) $res->city->coord['lon'], + 'temperature' => (string) $res->temperature['value'][0].$tunit, + 'pressure' => (string) $res->pressure['value'].(string)$res->pressure['unit'], + 'humidity' => (string) $res->humidity['value'].(string)$res->humidity['unit'], + 'descripion' => (string)$res->weather['value'].', '.(string)$res->clouds['name'], + 'wind' => (string)$res->wind->speed['name'].' ('.(string)$res->wind->speed['value'].$wunit.')', + 'update' => (string)$res->lastupdate['value'] + ); +} function curweather_install() { register_hook('network_mod_init', 'addon/curweather/curweather.php', 'curweather_network_mod_init'); register_hook('plugin_settings', 'addon/curweather/curweather.php', 'curweather_plugin_settings'); register_hook('plugin_settings_post', 'addon/curweather/curweather.php', 'curweather_plugin_settings_post'); - } function curweather_uninstall() { unregister_hook('network_mod_init', 'addon/curweather/curweather.php', 'curweather_network_mod_init'); unregister_hook('plugin_settings', 'addon/curweather/curweather.php', 'curweather_plugin_settings'); unregister_hook('plugin_settings_post', 'addon/curweather/curweather.php', 'curweather_plugin_settings_post'); - } -// The caching mechanism is taken from the cache example of the -// OpenWeatherMap-PHP-API library and a bit customized to allow admins to set -// the caching time depending on the plans they got from openweathermap.org -// and the usage of the friendica temppath - -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)) { - mkdir($dir); - } - - $path = $dir . DIRECTORY_SEPARATOR . md5($url); - return $path; - } - - /** - * @inheritdoc - */ - public function isCached($url) - { - $path = $this->urlToPath($url); - if (!file_exists($path) || filectime($path) + $this->seconds < time()) { - return false; - } - return true; - } - /** - * @inheritdoc - */ - public function getCached($url) - { - return file_get_contents($this->urlToPath($url)); - } - /** - * @inheritdoc - */ - public function setCached($url, $content) - { - file_put_contents($this->urlToPath($url), $content); - } -} - - function curweather_network_mod_init(&$fk_app,&$b) { if(! intval(get_pconfig(local_user(),'curweather','curweather_enable'))) @@ -104,47 +79,26 @@ function curweather_network_mod_init(&$fk_app,&$b) { $cachetime = intval(get_config('curweather','cachetime')); if ($units==="") $units = 'metric'; - // 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 CWCache(), $cachetime); $ok = true; - try { - $weather = $owm->getWeather($rpt, $units, $lang, $appid); - $temp = $weather->temperature->getValue(); - if ( $units === 'metric') { - $temp .= '°C'; - } else { - $temp .= '°F'; - }; - $rhumid = $weather->humidity; - $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() . ').'); + $res = getWeather($rpt, $units, $lang, $appid); + if ($res===false) $ok = false; - } catch(\Exception $e) { - info ('General exception: ' . $e->getMessage() . ' (Code ' . $e->getCode() . ').'); - $ok = false; - } + // TODO Caching if ($ok) { $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), + '$city' => $res['city'], + '$lon' => $res['lon'], + '$lat' => $res['lat'], + '$description' => $res['descripion'], + '$temp' => $res['temperature'], + '$relhumidity' => array('caption'=>t('Relative Humidity'), 'val'=>$res['humidity']), + '$pressure' => array('caption'=>t('Pressure'), 'val'=>$res['pressure']), + '$wind' => array('caption'=>t('Wind'), 'val'=> $res['wind']), + '$lastupdate' => t('Last Updated').': '.$res['update'], '$databy' => t('Data by'), '$showonmap' => t('Show on map') )); diff --git a/curweather/templates/widget.tpl b/curweather/templates/widget.tpl index e90a348f..910c0258 100644 --- a/curweather/templates/widget.tpl +++ b/curweather/templates/widget.tpl @@ -1,6 +1,6 @@
-

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

+

{{$title}}: {{$city}}

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

    From 2b1d28f05a61ef4862d9ac16c450c98a6b74ce49 Mon Sep 17 00:00:00 2001 From: Tobias Diekershoff Date: Mon, 13 Jul 2015 18:45:12 +0200 Subject: [PATCH 22/28] curweather caching of weather data --- curweather/curweather.php | 23 +++++++++++++++++------ 1 file changed, 17 insertions(+), 6 deletions(-) diff --git a/curweather/curweather.php b/curweather/curweather.php index cfe66b7e..93e9af9e 100644 --- a/curweather/curweather.php +++ b/curweather/curweather.php @@ -13,8 +13,17 @@ require_once('include/network.php'); include_once('include/text.php'); // get the weather data from OpenWeatherMap -function getWeather( $loc, $units='metric', $lang='en', $appid='') { +function getWeather( $loc, $units='metric', $lang='en', $appid='', $cachetime=0) { $url = "http://api.openweathermap.org/data/2.5/weather?q=".$loc."&appid=".$appid."&lang=".$lang."&units=".$units."&mode=xml"; + $cached = Cache::get('curweather'.md5($url)); + $now = new DateTime(); + if (!is_null($cached)) { + $cdate = get_pconfig(local_user(), 'curweather', 'last'); + $cached = unserialize($cached); + if ($cdate + $cachetime > $now->getTimestamp()) { + return $cached; + } + } try { $res = new SimpleXMLElement(fetch_url($url)); } catch (Exception $e) { @@ -28,7 +37,7 @@ function getWeather( $loc, $units='metric', $lang='en', $appid='') { $tunit = '°F'; $wunit = 'mph'; } - return array( + $r = array( 'city'=> (string) $res->city['name'][0], 'country' => (string) $res->city->country[0], 'lat' => (string) $res->city->coord['lat'], @@ -40,6 +49,9 @@ function getWeather( $loc, $units='metric', $lang='en', $appid='') { 'wind' => (string)$res->wind->speed['name'].' ('.(string)$res->wind->speed['value'].$wunit.')', 'update' => (string)$res->lastupdate['value'] ); + set_pconfig(local_user(), 'curweather', 'last', $now->getTimestamp()); + Cache::set('curweather'.md5($url), serialize($r)); + return $r; } function curweather_install() { @@ -80,11 +92,10 @@ function curweather_network_mod_init(&$fk_app,&$b) { if ($units==="") $units = 'metric'; $ok = true; - - $res = getWeather($rpt, $units, $lang, $appid); + + $res = getWeather($rpt, $units, $lang, $appid, $cachetime); if ($res===false) $ok = false; - // TODO Caching if ($ok) { $t = get_markup_template("widget.tpl", "addon/curweather/" ); @@ -98,7 +109,7 @@ function curweather_network_mod_init(&$fk_app,&$b) { '$relhumidity' => array('caption'=>t('Relative Humidity'), 'val'=>$res['humidity']), '$pressure' => array('caption'=>t('Pressure'), 'val'=>$res['pressure']), '$wind' => array('caption'=>t('Wind'), 'val'=> $res['wind']), - '$lastupdate' => t('Last Updated').': '.$res['update'], + '$lastupdate' => t('Last Updated').': '.$res['update'].'UTC', '$databy' => t('Data by'), '$showonmap' => t('Show on map') )); From cd48daa0b3a362fdf772350a69e7b5d7a2a4bd30 Mon Sep 17 00:00:00 2001 From: Tobias Diekershoff Date: Mon, 13 Jul 2015 18:46:55 +0200 Subject: [PATCH 23/28] updating the strings --- curweather/lang/C/messages.po | 64 ++++++++++++++++++++++------------- 1 file changed, 40 insertions(+), 24 deletions(-) diff --git a/curweather/lang/C/messages.po b/curweather/lang/C/messages.po index 1b57a529..b2ed6e5e 100644 --- a/curweather/lang/C/messages.po +++ b/curweather/lang/C/messages.po @@ -8,7 +8,7 @@ msgid "" msgstr "" "Project-Id-Version: \n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2015-07-12 14:29+0200\n" +"POT-Creation-Date: 2015-07-13 18:46+0200\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "Last-Translator: FULL NAME \n" "Language-Team: LANGUAGE \n" @@ -17,98 +17,114 @@ msgstr "" "Content-Type: text/plain; charset=UTF-8\n" "Content-Transfer-Encoding: 8bit\n" -#: curweather.php:128 curweather.php:176 +#: curweather.php:30 +msgid "Error fetching weather data.\\nError was: " +msgstr "" + +#: curweather.php:103 curweather.php:163 msgid "Current Weather" msgstr "" -#: curweather.php:131 +#: curweather.php:109 msgid "Relative Humidity" msgstr "" -#: curweather.php:132 +#: curweather.php:110 msgid "Pressure" msgstr "" -#: curweather.php:133 +#: curweather.php:111 msgid "Wind" msgstr "" -#: curweather.php:134 +#: curweather.php:112 +msgid "Last Updated" +msgstr "" + +#: curweather.php:113 msgid "Data by" msgstr "" -#: curweather.php:134 +#: curweather.php:114 msgid "Show on map" msgstr "" -#: curweather.php:150 +#: curweather.php:119 +msgid "There was a problem accessing the weather data. But have a look" +msgstr "" + +#: curweather.php:121 +msgid "at OpenWeatherMap" +msgstr "" + +#: curweather.php:137 msgid "Current Weather settings updated." msgstr "" -#: curweather.php:165 curweather.php:177 +#: curweather.php:152 msgid "No APPID found, please contact your admin to optain one." msgstr "" -#: curweather.php:175 curweather.php:204 +#: curweather.php:162 curweather.php:191 msgid "Save Settings" msgstr "" -#: curweather.php:176 +#: curweather.php:163 msgid "Settings" msgstr "" -#: curweather.php:178 +#: curweather.php:165 msgid "Enter either the name of your location or the zip code." msgstr "" -#: curweather.php:179 +#: curweather.php:166 msgid "Your Location" msgstr "" -#: curweather.php:179 +#: curweather.php:166 msgid "" "Identifier of your location (name or zip code), e.g. Berlin,DE or " "14476,DE." msgstr "" -#: curweather.php:180 +#: curweather.php:167 msgid "Units" msgstr "" -#: curweather.php:180 +#: curweather.php:167 msgid "select if the temperatur should be displayed in °C or °F" msgstr "" -#: curweather.php:181 +#: curweather.php:168 msgid "Show weather data" msgstr "" -#: curweather.php:194 +#: curweather.php:181 msgid "Curweather settings saved." msgstr "" -#: curweather.php:205 +#: curweather.php:192 msgid "Caching Interval" msgstr "" -#: curweather.php:205 +#: curweather.php:192 msgid "" "For how long should the weather data be cached? Choose according your " "OpenWeatherMap account type." msgstr "" -#: curweather.php:205 +#: curweather.php:192 msgid "no cache" msgstr "" -#: curweather.php:205 +#: curweather.php:192 msgid "minutes" msgstr "" -#: curweather.php:206 +#: curweather.php:193 msgid "Your APPID" msgstr "" -#: curweather.php:206 +#: curweather.php:193 msgid "Your API key provided by OpenWeatherMap" msgstr "" From e750412d8782a565b51e8c3b97e175fcea37d1b2 Mon Sep 17 00:00:00 2001 From: Tobias Diekershoff Date: Mon, 13 Jul 2015 18:59:54 +0200 Subject: [PATCH 24/28] added a note about XML/JSON to the README --- curweather/README.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/curweather/README.md b/curweather/README.md index 9c901278..ff43f248 100644 --- a/curweather/README.md +++ b/curweather/README.md @@ -21,3 +21,9 @@ Credits * Tobias Diekershoff switched the sources to OpenWeatherMap after the original provider turned off support for locations outside of the USA. +Known Issues +------------ + +* Localization does not work (Jul 15) data requested via XML are EN only but + have moew information available compared to data requested via JSON which is + available in other languages as well. Right now we use the XML dataset From ce637c58454e13704c4f8ea8dee4645cb463b8f2 Mon Sep 17 00:00:00 2001 From: Tobias Diekershoff Date: Wed, 15 Jul 2015 13:15:02 +0200 Subject: [PATCH 25/28] cleanup --- curweather/curweather.php | 12 +++++++++--- curweather/templates/settings.tpl | 4 +--- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/curweather/curweather.php b/curweather/curweather.php index 93e9af9e..58daab0b 100644 --- a/curweather/curweather.php +++ b/curweather/curweather.php @@ -37,6 +37,11 @@ function getWeather( $loc, $units='metric', $lang='en', $appid='', $cachetime=0) $tunit = '°F'; $wunit = 'mph'; } + if ( trim((string)$res->weather['value']) == trim((string)$res->clouds['name']) ) { + $desc = (string)$res->clouds['name']; + } else { + $desc = (string)$res->weather['value'].', '.(string)$res->clouds['name']; + } $r = array( 'city'=> (string) $res->city['name'][0], 'country' => (string) $res->city->country[0], @@ -45,7 +50,7 @@ function getWeather( $loc, $units='metric', $lang='en', $appid='', $cachetime=0) 'temperature' => (string) $res->temperature['value'][0].$tunit, 'pressure' => (string) $res->pressure['value'].(string)$res->pressure['unit'], 'humidity' => (string) $res->humidity['value'].(string)$res->humidity['unit'], - 'descripion' => (string)$res->weather['value'].', '.(string)$res->clouds['name'], + 'descripion' => $desc, 'wind' => (string)$res->wind->speed['name'].' ('.(string)$res->wind->speed['value'].$wunit.')', 'update' => (string)$res->lastupdate['value'] ); @@ -73,9 +78,10 @@ function curweather_network_mod_init(&$fk_app,&$b) { $fk_app->page['htmlhead'] .= '' . "\r\n"; - // the OpenWeatherMap-PHP-APIlib does all the work here - // the $rpt value is needed for location + // $rpt value is needed for location // $lang will be taken from the browser session to honour user settings + // TODO $lang does not work if the default settings are used + // and not all response strings are translated // $units can be set in the settings by the user // $appid is configured by the admin in the admin panel // those parameters will be used to get: cloud status, temperature, preassure diff --git a/curweather/templates/settings.tpl b/curweather/templates/settings.tpl index 1453b210..09f6f506 100644 --- a/curweather/templates/settings.tpl +++ b/curweather/templates/settings.tpl @@ -1,6 +1,4 @@ - +

    {{$header}}

    - +

    • {{$temp}}
    • {{$relhumidity['caption']}}: {{$relhumidity['val']}}
    • From a70280de1dfb7a7708ede437826b83eb30427c45 Mon Sep 17 00:00:00 2001 From: Tobias Diekershoff Date: Fri, 17 Jul 2015 17:43:41 +0200 Subject: [PATCH 28/28] the icon needs more space to breathe --- curweather/curweather.css | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/curweather/curweather.css b/curweather/curweather.css index adf948f0..69574ff0 100644 --- a/curweather/curweather.css +++ b/curweather/curweather.css @@ -1,6 +1,6 @@ #curweather-network img { float: left; - margin: 20px 10px; + margin: 30px 10px; } ul.curweather-details li { list-type: none;