diff --git a/inc/3rdparty/FlattrItem.class.php b/inc/3rdparty/FlattrItem.class.php new file mode 100644 index 0000000..c940fcd --- /dev/null +++ b/inc/3rdparty/FlattrItem.class.php @@ -0,0 +1,49 @@ +cacheflattrfile($urltoflattr); + $flattrResponse = file_get_contents(CACHE . "/flattr/".base64_encode($urltoflattr).".cache"); + if($flattrResponse != FALSE) { + $result = json_decode($flattrResponse); + if (isset($result->message)){ + if ($result->message == "flattrable") { + $this->status = FLATTRABLE; + } + } + elseif ($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) { + 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/".base64_encode($urltoflattr).".cache")) || (time() - filemtime(CACHE . "/flattr/".base64_encode($urltoflattr).".cache") > 86400)) { + $askForFlattr = Tools::getFile(FLATTR_API . $urltoflattr); + $flattrCacheFile = fopen(CACHE . "/flattr/".base64_encode($urltoflattr).".cache", 'w+'); + fwrite($flattrCacheFile, $askForFlattr); + fclose($flattrCacheFile); + } + } +} \ No newline at end of file diff --git a/inc/poche/Poche.class.php b/inc/poche/Poche.class.php index 534e660..9db4a03 100644 --- a/inc/poche/Poche.class.php +++ b/inc/poche/Poche.class.php @@ -247,17 +247,23 @@ class Poche $tidy = tidy_parse_string($content, array('indent'=>true, 'show-body-only' => true), 'UTF8'); $tidy->cleanRepair(); $content = $tidy->value; - } - $tpl_vars = array( + + # flattr checking + $flattr = new FlattrItem(); + $flattr->checkItem($entry['url']); + + $tpl_vars = array( 'entry' => $entry, 'content' => $content, - ); + 'flattr' => $flattr + ); + } } else { Tools::logm('error in view call : entry is null'); } break; - default: # home, favorites and archive views + default: # home, favorites and archive views $entries = $this->store->getEntriesByView($view, $this->user->getId()); $tpl_vars = array( 'entries' => '', diff --git a/inc/poche/config.inc.php b/inc/poche/config.inc.php index 7f1b8c9..4552669 100755 --- a/inc/poche/config.inc.php +++ b/inc/poche/config.inc.php @@ -37,6 +37,7 @@ require_once __DIR__ . '/../../inc/3rdparty/humble-http-agent/CookieJar.php'; require_once __DIR__ . '/../../inc/3rdparty/feedwriter/FeedItem.php'; require_once __DIR__ . '/../../inc/3rdparty/feedwriter/FeedWriter.php'; require_once __DIR__ . '/../../inc/3rdparty/feedwriter/DummySingleItemFeed.php'; +require_once __DIR__ . '/../../inc/3rdparty/FlattrItem.class.php'; if (DOWNLOAD_PICTURES) { require_once __DIR__ . '/../../inc/poche/pochePictures.php'; diff --git a/inc/poche/define.inc.php b/inc/poche/define.inc.php index 53c275d..40f77b5 100644 --- a/inc/poche/define.inc.php +++ b/inc/poche/define.inc.php @@ -22,6 +22,11 @@ define ('SHARE_TWITTER', TRUE); define ('SHARE_MAIL', TRUE); define ('SHARE_SHAARLI', FALSE); define ('SHAARLI_URL', 'http://myshaarliurl.com'); +define ('FLATTR', TRUE); +define ('FLATTR_API', 'https://api.flattr.com/rest/v2/things/lookup/?url='); +define ('NOT_FLATTRABLE', '0'); +define ('FLATTRABLE', '1'); +define ('FLATTRED', '2'); define ('ABS_PATH', 'assets/'); define ('TPL', __DIR__ . '/../../tpl'); define ('LOCALE', __DIR__ . '/../../locale'); diff --git a/tpl/css/style-light.css b/tpl/css/style-light.css index e2788a1..224ef18 100644 --- a/tpl/css/style-light.css +++ b/tpl/css/style-light.css @@ -48,6 +48,10 @@ a.shaarli span { background: url('../img/light/shaarli.png') no-repeat; } +a.flattr span { + background: url('../img/light/flattr.png'); +} + a.email span { background: url('../img/light/envelop.png') no-repeat; } diff --git a/tpl/img/light/flattr.png b/tpl/img/light/flattr.png new file mode 100644 index 0000000..d9007c0 Binary files /dev/null and b/tpl/img/light/flattr.png differ diff --git a/tpl/view.twig b/tpl/view.twig index 2850877..ee16afa 100644 --- a/tpl/view.twig +++ b/tpl/view.twig @@ -11,6 +11,7 @@ {% if constant('SHARE_TWITTER') == 1 %}
  • {% trans "tweet" %}
  • {% endif %} {% if constant('SHARE_MAIL') == 1 %}
  • {% trans "email" %}
  • {% endif %} {% if constant('SHARE_SHAARLI') == 1 %}
  • {% trans "shaarli" %}
  • {% endif %} + {% if constant('FLATTR') == 1 %}{% if flattr.status == constant('FLATTRABLE') %}
  • flattr
  • {% elseif flattr.status == constant('FLATTRED') %}
  • flattr{{ flattr.numflattrs }}
  • {% endif %}{% endif %}
    @@ -31,6 +32,7 @@ {% if constant('SHARE_TWITTER') == 1 %}
  • {% endif %} {% if constant('SHARE_MAIL') == 1 %}
  • {% endif %} {% if constant('SHARE_SHAARLI') == 1 %}
  • {% trans "shaarli" %}
  • {% endif %} + {% if constant('FLATTR') == 1 %}{% if flattr.status == constant('FLATTRABLE') %}
  • flattr
  • {% elseif flattr.status == constant('FLATTRED') %}
  • flattr{{ flattr.numflattrs }}
  • {% endif %}{% endif %}

    {% trans "this article appears wrong?" %} {% trans "create an issue" %} {% trans "or" %} {% trans "contact us by mail" %}