diff options
author | Nicolas LÅ“uillet <nicolas.loeuillet@gmail.com> | 2013-09-20 04:36:35 -0700 |
---|---|---|
committer | Nicolas LÅ“uillet <nicolas.loeuillet@gmail.com> | 2013-09-20 04:36:35 -0700 |
commit | 79026b73a804d1fe3715c3edf5bc2cfb1e56732c (patch) | |
tree | 225136afe844ad0b1c3fef443fcea86fe54384e5 /inc/3rdparty/FlattrItem.class.php | |
parent | c51be6b697da573cdcf0788eb8617130ce5517a4 (diff) | |
parent | 6a6c1c1172f3c6167d360a2322335ea91e94a3ff (diff) | |
download | wallabag-79026b73a804d1fe3715c3edf5bc2cfb1e56732c.tar.gz wallabag-79026b73a804d1fe3715c3edf5bc2cfb1e56732c.tar.zst wallabag-79026b73a804d1fe3715c3edf5bc2cfb1e56732c.zip |
Merge pull request #226 from inthepoche/dev1.0-beta5
beta5
Diffstat (limited to 'inc/3rdparty/FlattrItem.class.php')
-rw-r--r-- | inc/3rdparty/FlattrItem.class.php | 49 |
1 files changed, 49 insertions, 0 deletions
diff --git a/inc/3rdparty/FlattrItem.class.php b/inc/3rdparty/FlattrItem.class.php new file mode 100644 index 00000000..c940fcd6 --- /dev/null +++ b/inc/3rdparty/FlattrItem.class.php | |||
@@ -0,0 +1,49 @@ | |||
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 | |||
12 | public function checkItem($urltoflattr) { | ||
13 | $this->cacheflattrfile($urltoflattr); | ||
14 | $flattrResponse = file_get_contents(CACHE . "/flattr/".base64_encode($urltoflattr).".cache"); | ||
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 | |||
36 | private function cacheflattrfile($urltoflattr) { | ||
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 | ||
42 | if ((!file_exists(CACHE . "/flattr/".base64_encode($urltoflattr).".cache")) || (time() - filemtime(CACHE . "/flattr/".base64_encode($urltoflattr).".cache") > 86400)) { | ||
43 | $askForFlattr = Tools::getFile(FLATTR_API . $urltoflattr); | ||
44 | $flattrCacheFile = fopen(CACHE . "/flattr/".base64_encode($urltoflattr).".cache", 'w+'); | ||
45 | fwrite($flattrCacheFile, $askForFlattr); | ||
46 | fclose($flattrCacheFile); | ||
47 | } | ||
48 | } | ||
49 | } \ No newline at end of file | ||