mirror of
https://git.friendi.ca/friendica/friendica-addons.git
synced 2025-10-10 00:43:00 +00:00
added composer.json and needed libs
This commit is contained in:
parent
4f1fb007c5
commit
1f74d409a2
42 changed files with 4413 additions and 0 deletions
95
curweather/vendor/cmfcmf/openweathermap-php-api/Examples/Cache.php
vendored
Normal file
95
curweather/vendor/cmfcmf/openweathermap-php-api/Examples/Cache.php
vendored
Normal file
|
@ -0,0 +1,95 @@
|
|||
<?php
|
||||
/**
|
||||
* OpenWeatherMap-PHP-API — A php api to parse weather data from http://www.OpenWeatherMap.org .
|
||||
*
|
||||
* @license MIT
|
||||
*
|
||||
* Please see the LICENSE file distributed with this source code for further
|
||||
* information regarding copyright and licensing.
|
||||
*
|
||||
* Please visit the following links to read about the usage policies and the license of
|
||||
* OpenWeatherMap before using this class:
|
||||
*
|
||||
* @see http://www.OpenWeatherMap.org
|
||||
* @see http://www.OpenWeatherMap.org/terms
|
||||
* @see http://openweathermap.org/appid
|
||||
*/
|
||||
|
||||
use Cmfcmf\OpenWeatherMap;
|
||||
use Cmfcmf\OpenWeatherMap\AbstractCache;
|
||||
|
||||
if (file_exists('../vendor/autoload.php')) {
|
||||
// Library is not part of a project. "composer install" was executed directly on this library's composer file.
|
||||
require('../vendor/autoload.php');
|
||||
} else {
|
||||
// Library is part of a project.
|
||||
/** @noinspection PhpIncludeInspection */
|
||||
require('../../../autoload.php');
|
||||
}
|
||||
|
||||
/**
|
||||
* Example cache implementation.
|
||||
*
|
||||
* @ignore
|
||||
*/
|
||||
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()) {
|
||||
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<hr />\n\n\n";
|
||||
echo $weather->temperature;
|
Loading…
Add table
Add a link
Reference in a new issue