]>
git.immae.eu Git - github/wallabag/wallabag.git/blob - inc/3rdparty/FlattrItem.class.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
15 public $flattrItemURL;
18 public function checkItem($urlToFlattr, $id)
20 $this->_cacheFlattrFile($urlToFlattr, $id);
21 $flattrResponse = file_get_contents(CACHE
. "/flattr/".$id.".cache");
22 if($flattrResponse != FALSE) {
23 $result = json_decode($flattrResponse);
24 if (isset($result->message
)) {
25 if ($result->message
== "flattrable") {
26 $this->status
= FLATTRABLE
;
29 elseif (is_object($result) && $result->link
) {
30 $this->status
= FLATTRED
;
31 $this->flattrItemURL
= $result->link
;
32 $this->numFlattrs
= $result->flattrs
;
35 $this->status
= NOT_FLATTRABLE
;
39 $this->status
= "FLATTR_ERR_CONNECTION";
43 private function _cacheFlattrFile($urlToFlattr, $id)
45 if (!is_dir(CACHE
. '/flattr')) {
46 mkdir(CACHE
. '/flattr', 0777);
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
50 if ((!file_exists(CACHE
. "/flattr/".$id.".cache")) || (time() - filemtime(CACHE
. "/flattr/".$id.".cache") > 86400)) {
51 $askForFlattr = Tools
::getFile(FLATTR_API
. $urlToFlattr);
52 $flattrCacheFile = fopen(CACHE
. "/flattr/".$id.".cache", 'w+');
53 fwrite($flattrCacheFile, $askForFlattr);
54 fclose($flattrCacheFile);