From dda7884ace3a3906b65668669fb67b37f596fd62 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicolas=20L=C5=93uillet?= Date: Mon, 19 Jan 2015 11:29:25 +0100 Subject: pagination with composer and move FlattrItem --- inc/poche/FlattrItem.class.php | 57 ++++++++++++++++++++++++++++++++++++++++++ inc/poche/global.inc.php | 2 +- 2 files changed, 58 insertions(+), 1 deletion(-) create mode 100644 inc/poche/FlattrItem.class.php (limited to 'inc/poche') diff --git a/inc/poche/FlattrItem.class.php b/inc/poche/FlattrItem.class.php new file mode 100644 index 00000000..ef8c62f7 --- /dev/null +++ b/inc/poche/FlattrItem.class.php @@ -0,0 +1,57 @@ + + * @copyright 2013 + * @license http://opensource.org/licenses/MIT see COPYING file + */ + +class FlattrItem +{ + public $status; + public $urlToFlattr; + public $flattrItemURL; + public $numFlattrs; + + public function checkItem($urlToFlattr, $id) + { + $this->_cacheFlattrFile($urlToFlattr, $id); + $flattrResponse = file_get_contents(CACHE . "/flattr/".$id.".cache"); + if($flattrResponse != FALSE) { + $result = json_decode($flattrResponse); + if (isset($result->message)) { + if ($result->message == "flattrable") { + $this->status = FLATTRABLE; + } + } + elseif (is_object($result) && $result->link) { + $this->status = FLATTRED; + $this->flattrItemURL = $result->link; + $this->numFlattrs = $result->flattrs; + } + else { + $this->status = NOT_FLATTRABLE; + } + } + else { + $this->status = "FLATTR_ERR_CONNECTION"; + } + } + + 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/".$id.".cache")) || (time() - filemtime(CACHE . "/flattr/".$id.".cache") > 86400)) { + $askForFlattr = Tools::getFile(FLATTR_API . $urlToFlattr); + $flattrCacheFile = fopen(CACHE . "/flattr/".$id.".cache", 'w+'); + fwrite($flattrCacheFile, $askForFlattr); + fclose($flattrCacheFile); + } + } +} diff --git a/inc/poche/global.inc.php b/inc/poche/global.inc.php index 4d119456..c17d54e6 100755 --- a/inc/poche/global.inc.php +++ b/inc/poche/global.inc.php @@ -29,7 +29,7 @@ require_once INCLUDES . '/3rdparty/paginator.php'; require_once INCLUDES . '/3rdparty/libraries/feedwriter/FeedItem.php'; require_once INCLUDES . '/3rdparty/libraries/feedwriter/FeedWriter.php'; -require_once INCLUDES . '/3rdparty/FlattrItem.class.php'; +require_once INCLUDES . '/poche/FlattrItem.class.php'; # epub library require_once INCLUDES . '/3rdparty/libraries/PHPePub/Logger.php'; -- cgit v1.2.3