]>
git.immae.eu Git - github/wallabag/wallabag.git/blob - src/Wallabag/Wallabag/FlattrItem.php
3 * wallabag, self hostable application allowing you to not miss any content anymore
6 * @author Nicolas LÅ“uillet <nicolas@loeuillet.org>
8 * @license http://opensource.org/licenses/MIT see COPYING file
11 namespace Wallabag\Wallabag
;
17 public $flattrItemURL;
20 public function checkItem($urlToFlattr, $id)
22 $this->_cacheFlattrFile($urlToFlattr, $id);
23 $flattrResponse = file_get_contents(CACHE
. "/flattr/".$id.".cache");
24 if($flattrResponse != FALSE) {
25 $result = json_decode($flattrResponse);
26 if (isset($result->message
)) {
27 if ($result->message
== "flattrable") {
28 $this->status
= FLATTRABLE
;
31 elseif (is_object($result) && $result->link
) {
32 $this->status
= FLATTRED
;
33 $this->flattrItemURL
= $result->link
;
34 $this->numFlattrs
= $result->flattrs
;
37 $this->status
= NOT_FLATTRABLE
;
41 $this->status
= "FLATTR_ERR_CONNECTION";
45 private function _cacheFlattrFile($urlToFlattr, $id)
47 if (!is_dir(CACHE
. '/flattr')) {
48 mkdir(CACHE
. '/flattr', 0777);
51 // 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
52 if ((!file_exists(CACHE
. "/flattr/".$id.".cache")) || (time() - filemtime(CACHE
. "/flattr/".$id.".cache") > 86400)) {
53 $askForFlattr = Tools
::getFile(FLATTR_API
. $urlToFlattr);
54 $flattrCacheFile = fopen(CACHE
. "/flattr/".$id.".cache", 'w+');
55 fwrite($flattrCacheFile, $askForFlattr);
56 fclose($flattrCacheFile);