]>
Commit | Line | Data |
---|---|---|
12d9cfbc NL |
1 | <?php |
2 | /* | |
3 | * Class for Flattr querying | |
4 | */ | |
5 | class FlattrItem { | |
6 | ||
7 | public $status; | |
8 | public $urltoflattr; | |
9 | public $flattrItemURL; | |
10 | public $numflattrs; | |
11 | ||
4e5b0411 TC |
12 | public function checkItem($urltoflattr,$id) { |
13 | $this->cacheflattrfile($urltoflattr, $id); | |
14 | $flattrResponse = file_get_contents(CACHE . "/flattr/".$id.".cache"); | |
12d9cfbc NL |
15 | if($flattrResponse != FALSE) { |
16 | $result = json_decode($flattrResponse); | |
17 | if (isset($result->message)){ | |
18 | if ($result->message == "flattrable") { | |
19 | $this->status = FLATTRABLE; | |
20 | } | |
21 | } | |
22 | elseif ($result->link) { | |
23 | $this->status = FLATTRED; | |
24 | $this->flattrItemURL = $result->link; | |
25 | $this->numflattrs = $result->flattrs; | |
26 | } | |
27 | else { | |
28 | $this->status = NOT_FLATTRABLE; | |
29 | } | |
30 | } | |
31 | else { | |
32 | $this->status = "FLATTR_ERR_CONNECTION"; | |
33 | } | |
34 | } | |
35 | ||
4e5b0411 | 36 | private function cacheflattrfile($urltoflattr, $id) { |
12d9cfbc NL |
37 | if (!is_dir(CACHE . '/flattr')) { |
38 | mkdir(CACHE . '/flattr', 0777); | |
39 | } | |
40 | ||
41 | // if a cache flattr file for this url already exists and it's been less than one day than it have been updated, see in /cache | |
4e5b0411 | 42 | if ((!file_exists(CACHE . "/flattr/".$id.".cache")) || (time() - filemtime(CACHE . "/flattr/".$id.".cache") > 86400)) { |
12d9cfbc | 43 | $askForFlattr = Tools::getFile(FLATTR_API . $urltoflattr); |
4e5b0411 | 44 | $flattrCacheFile = fopen(CACHE . "/flattr/".$id.".cache", 'w+'); |
12d9cfbc NL |
45 | fwrite($flattrCacheFile, $askForFlattr); |
46 | fclose($flattrCacheFile); | |
47 | } | |
48 | } | |
49 | } |