]>
git.immae.eu Git - github/wallabag/wallabag.git/blob - inc/3rdparty/FlattrItem.class.php
3 * Class for Flattr querying
12 public function checkItem($urltoflattr,$id) {
13 $this->cacheflattrfile($urltoflattr, $id);
14 $flattrResponse = file_get_contents(CACHE
. "/flattr/".$id.".cache");
15 print_r($flattrResponse);
16 if($flattrResponse != FALSE) {
17 $result = json_decode($flattrResponse);
18 if (isset($result->message
)){
19 if ($result->message
== "flattrable") {
20 $this->status
= FLATTRABLE
;
23 elseif ($result->link
) {
24 $this->status
= FLATTRED
;
25 $this->flattrItemURL
= $result->link
;
26 $this->numflattrs
= $result->flattrs
;
29 $this->status
= NOT_FLATTRABLE
;
33 $this->status
= "FLATTR_ERR_CONNECTION";
37 private function cacheflattrfile($urltoflattr, $id) {
38 if (!is_dir(CACHE
. '/flattr')) {
39 mkdir(CACHE
. '/flattr', 0777);
42 // 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
43 if ((!file_exists(CACHE
. "/flattr/".$id.".cache")) || (time() - filemtime(CACHE
. "/flattr/".$id.".cache") > 86400)) {
44 $askForFlattr = Tools
::getFile(FLATTR_API
. $urltoflattr);
45 $flattrCacheFile = fopen(CACHE
. "/flattr/".$id.".cache", 'w+');
46 fwrite($flattrCacheFile, $askForFlattr);
47 fclose($flattrCacheFile);