-
Notifications
You must be signed in to change notification settings - Fork 0
/
openweathermap.php
42 lines (34 loc) · 981 Bytes
/
openweathermap.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
<?php
use Cmfcmf\OpenWeatherMap\AbstractCache;
function color($c) {
$r = round(($c * (255 / 20)));
$b = round(255 - ($c * (255 / 50))) ;
$g = $c < 15 ? round($b * 0.5) : round($r * 0.5);
return array($r, $g, $b);
}
function gradient($c) {
return array(
color(($c - 5)),
color(($c + 5))
);
}
class FileSystemCache extends AbstractCache {
private function urlToPath($url) {
if(!is_dir(__DIR__ . "/data/cache/")) mkdir(__DIR__ . "/data/cache/");
return __DIR__ . "/data/cache/" . md5($url);
}
public function isCached($url) {
$path = $this->urlToPath($url);
if (!file_exists($path) || filectime($path) + $this->seconds < time()) {
return false;
}
return true;
}
public function getCached($url) {
return file_get_contents($this->urlToPath($url));
}
public function setCached($url, $content) {
file_put_contents($this->urlToPath($url), $content);
}
}
?>