diff options
Diffstat (limited to 'inc/3rdparty/FlattrItem.class.php')
-rw-r--r-- | inc/3rdparty/FlattrItem.class.php | 36 |
1 files changed, 22 insertions, 14 deletions
diff --git a/inc/3rdparty/FlattrItem.class.php b/inc/3rdparty/FlattrItem.class.php index 711b4ee0..ef8c62f7 100644 --- a/inc/3rdparty/FlattrItem.class.php +++ b/inc/3rdparty/FlattrItem.class.php | |||
@@ -1,28 +1,35 @@ | |||
1 | <?php | 1 | <?php |
2 | /* | 2 | /** |
3 | * Class for Flattr querying | 3 | * wallabag, self hostable application allowing you to not miss any content anymore |
4 | */ | 4 | * |
5 | class FlattrItem { | 5 | * @category wallabag |
6 | * @author Nicolas LÅ“uillet <nicolas@loeuillet.org> | ||
7 | * @copyright 2013 | ||
8 | * @license http://opensource.org/licenses/MIT see COPYING file | ||
9 | */ | ||
6 | 10 | ||
11 | class FlattrItem | ||
12 | { | ||
7 | public $status; | 13 | public $status; |
8 | public $urltoflattr; | 14 | public $urlToFlattr; |
9 | public $flattrItemURL; | 15 | public $flattrItemURL; |
10 | public $numflattrs; | 16 | public $numFlattrs; |
11 | 17 | ||
12 | public function checkItem($urltoflattr,$id) { | 18 | public function checkItem($urlToFlattr, $id) |
13 | $this->cacheflattrfile($urltoflattr, $id); | 19 | { |
20 | $this->_cacheFlattrFile($urlToFlattr, $id); | ||
14 | $flattrResponse = file_get_contents(CACHE . "/flattr/".$id.".cache"); | 21 | $flattrResponse = file_get_contents(CACHE . "/flattr/".$id.".cache"); |
15 | if($flattrResponse != FALSE) { | 22 | if($flattrResponse != FALSE) { |
16 | $result = json_decode($flattrResponse); | 23 | $result = json_decode($flattrResponse); |
17 | if (isset($result->message)){ | 24 | if (isset($result->message)) { |
18 | if ($result->message == "flattrable") { | 25 | if ($result->message == "flattrable") { |
19 | $this->status = FLATTRABLE; | 26 | $this->status = FLATTRABLE; |
20 | } | 27 | } |
21 | } | 28 | } |
22 | elseif (is_object($result) && $result->link) { | 29 | elseif (is_object($result) && $result->link) { |
23 | $this->status = FLATTRED; | 30 | $this->status = FLATTRED; |
24 | $this->flattrItemURL = $result->link; | 31 | $this->flattrItemURL = $result->link; |
25 | $this->numflattrs = $result->flattrs; | 32 | $this->numFlattrs = $result->flattrs; |
26 | } | 33 | } |
27 | else { | 34 | else { |
28 | $this->status = NOT_FLATTRABLE; | 35 | $this->status = NOT_FLATTRABLE; |
@@ -33,17 +40,18 @@ class FlattrItem { | |||
33 | } | 40 | } |
34 | } | 41 | } |
35 | 42 | ||
36 | private function cacheflattrfile($urltoflattr, $id) { | 43 | private function _cacheFlattrFile($urlToFlattr, $id) |
44 | { | ||
37 | if (!is_dir(CACHE . '/flattr')) { | 45 | if (!is_dir(CACHE . '/flattr')) { |
38 | mkdir(CACHE . '/flattr', 0777); | 46 | mkdir(CACHE . '/flattr', 0777); |
39 | } | 47 | } |
40 | 48 | ||
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 | 49 | // 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/".$id.".cache")) || (time() - filemtime(CACHE . "/flattr/".$id.".cache") > 86400)) { | 50 | if ((!file_exists(CACHE . "/flattr/".$id.".cache")) || (time() - filemtime(CACHE . "/flattr/".$id.".cache") > 86400)) { |
43 | $askForFlattr = Tools::getFile(FLATTR_API . $urltoflattr); | 51 | $askForFlattr = Tools::getFile(FLATTR_API . $urlToFlattr); |
44 | $flattrCacheFile = fopen(CACHE . "/flattr/".$id.".cache", 'w+'); | 52 | $flattrCacheFile = fopen(CACHE . "/flattr/".$id.".cache", 'w+'); |
45 | fwrite($flattrCacheFile, $askForFlattr); | 53 | fwrite($flattrCacheFile, $askForFlattr); |
46 | fclose($flattrCacheFile); | 54 | fclose($flattrCacheFile); |
47 | } | 55 | } |
48 | } | 56 | } |
49 | } \ No newline at end of file | 57 | } |