diff options
author | Thomas Citharel <thomas.citharet@gmail.com> | 2013-09-27 11:11:45 +0200 |
---|---|---|
committer | Thomas Citharel <thomas.citharet@gmail.com> | 2013-09-27 11:11:45 +0200 |
commit | 4e5b04113d923b54206436c74ce1fa8649854046 (patch) | |
tree | 531ad424baafb102baa4c4fa0bdf639dddf669a5 | |
parent | be2b9055b9019fccc9d2e4678494d0ffcd5f5f12 (diff) | |
download | wallabag-4e5b04113d923b54206436c74ce1fa8649854046.tar.gz wallabag-4e5b04113d923b54206436c74ce1fa8649854046.tar.zst wallabag-4e5b04113d923b54206436c74ce1fa8649854046.zip |
Changed Flattr Caching System
From md5(url) to the ID of an article. Easier and faster.
-rw-r--r-- | inc/3rdparty/FlattrItem.class.php | 13 | ||||
-rw-r--r-- | inc/poche/Poche.class.php | 2 |
2 files changed, 8 insertions, 7 deletions
diff --git a/inc/3rdparty/FlattrItem.class.php b/inc/3rdparty/FlattrItem.class.php index ab5ed81d..2b7ea3fa 100644 --- a/inc/3rdparty/FlattrItem.class.php +++ b/inc/3rdparty/FlattrItem.class.php | |||
@@ -9,9 +9,10 @@ class FlattrItem { | |||
9 | public $flattrItemURL; | 9 | public $flattrItemURL; |
10 | public $numflattrs; | 10 | public $numflattrs; |
11 | 11 | ||
12 | public function checkItem($urltoflattr) { | 12 | public function checkItem($urltoflattr,$id) { |
13 | $this->cacheflattrfile($urltoflattr); | 13 | $this->cacheflattrfile($urltoflattr, $id); |
14 | $flattrResponse = file_get_contents(CACHE . "/flattr/".md5($urltoflattr).".cache"); | 14 | $flattrResponse = file_get_contents(CACHE . "/flattr/".$id.".cache"); |
15 | print_r($flattrResponse); | ||
15 | if($flattrResponse != FALSE) { | 16 | if($flattrResponse != FALSE) { |
16 | $result = json_decode($flattrResponse); | 17 | $result = json_decode($flattrResponse); |
17 | if (isset($result->message)){ | 18 | if (isset($result->message)){ |
@@ -33,15 +34,15 @@ class FlattrItem { | |||
33 | } | 34 | } |
34 | } | 35 | } |
35 | 36 | ||
36 | private function cacheflattrfile($urltoflattr) { | 37 | private function cacheflattrfile($urltoflattr, $id) { |
37 | if (!is_dir(CACHE . '/flattr')) { | 38 | if (!is_dir(CACHE . '/flattr')) { |
38 | mkdir(CACHE . '/flattr', 0777); | 39 | mkdir(CACHE . '/flattr', 0777); |
39 | } | 40 | } |
40 | 41 | ||
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 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/".md5($urltoflattr).".cache")) || (time() - filemtime(CACHE . "/flattr/".md5($urltoflattr).".cache") > 86400)) { | 43 | if ((!file_exists(CACHE . "/flattr/".$id.".cache")) || (time() - filemtime(CACHE . "/flattr/".$id.".cache") > 86400)) { |
43 | $askForFlattr = Tools::getFile(FLATTR_API . $urltoflattr); | 44 | $askForFlattr = Tools::getFile(FLATTR_API . $urltoflattr); |
44 | $flattrCacheFile = fopen(CACHE . "/flattr/".md5($urltoflattr).".cache", 'w+'); | 45 | $flattrCacheFile = fopen(CACHE . "/flattr/".$id.".cache", 'w+'); |
45 | fwrite($flattrCacheFile, $askForFlattr); | 46 | fwrite($flattrCacheFile, $askForFlattr); |
46 | fclose($flattrCacheFile); | 47 | fclose($flattrCacheFile); |
47 | } | 48 | } |
diff --git a/inc/poche/Poche.class.php b/inc/poche/Poche.class.php index 561de808..6907e649 100644 --- a/inc/poche/Poche.class.php +++ b/inc/poche/Poche.class.php | |||
@@ -385,7 +385,7 @@ class Poche | |||
385 | 385 | ||
386 | # flattr checking | 386 | # flattr checking |
387 | $flattr = new FlattrItem(); | 387 | $flattr = new FlattrItem(); |
388 | $flattr->checkItem($entry['url']); | 388 | $flattr->checkItem($entry['url'],$entry['id']); |
389 | 389 | ||
390 | $tpl_vars = array( | 390 | $tpl_vars = array( |
391 | 'entry' => $entry, | 391 | 'entry' => $entry, |