From 4e5b04113d923b54206436c74ce1fa8649854046 Mon Sep 17 00:00:00 2001 From: Thomas Citharel Date: Fri, 27 Sep 2013 11:11:45 +0200 Subject: [PATCH] Changed Flattr Caching System From md5(url) to the ID of an article. Easier and faster. --- inc/3rdparty/FlattrItem.class.php | 13 +++++++------ 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 ab5ed81..2b7ea3f 100644 --- a/inc/3rdparty/FlattrItem.class.php +++ b/inc/3rdparty/FlattrItem.class.php @@ -9,9 +9,10 @@ class FlattrItem { public $flattrItemURL; public $numflattrs; - public function checkItem($urltoflattr) { - $this->cacheflattrfile($urltoflattr); - $flattrResponse = file_get_contents(CACHE . "/flattr/".md5($urltoflattr).".cache"); + public function checkItem($urltoflattr,$id) { + $this->cacheflattrfile($urltoflattr, $id); + $flattrResponse = file_get_contents(CACHE . "/flattr/".$id.".cache"); + print_r($flattrResponse); if($flattrResponse != FALSE) { $result = json_decode($flattrResponse); if (isset($result->message)){ @@ -33,15 +34,15 @@ class FlattrItem { } } - private function cacheflattrfile($urltoflattr) { + private function cacheflattrfile($urltoflattr, $id) { if (!is_dir(CACHE . '/flattr')) { mkdir(CACHE . '/flattr', 0777); } // 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 - if ((!file_exists(CACHE . "/flattr/".md5($urltoflattr).".cache")) || (time() - filemtime(CACHE . "/flattr/".md5($urltoflattr).".cache") > 86400)) { + if ((!file_exists(CACHE . "/flattr/".$id.".cache")) || (time() - filemtime(CACHE . "/flattr/".$id.".cache") > 86400)) { $askForFlattr = Tools::getFile(FLATTR_API . $urltoflattr); - $flattrCacheFile = fopen(CACHE . "/flattr/".md5($urltoflattr).".cache", 'w+'); + $flattrCacheFile = fopen(CACHE . "/flattr/".$id.".cache", 'w+'); fwrite($flattrCacheFile, $askForFlattr); fclose($flattrCacheFile); } diff --git a/inc/poche/Poche.class.php b/inc/poche/Poche.class.php index 561de80..6907e64 100644 --- a/inc/poche/Poche.class.php +++ b/inc/poche/Poche.class.php @@ -385,7 +385,7 @@ class Poche # flattr checking $flattr = new FlattrItem(); - $flattr->checkItem($entry['url']); + $flattr->checkItem($entry['url'],$entry['id']); $tpl_vars = array( 'entry' => $entry,