diff options
-rw-r--r-- | inc/poche/Poche.class.php | 59 | ||||
-rw-r--r-- | tpl/view.twig | 1 |
2 files changed, 58 insertions, 2 deletions
diff --git a/inc/poche/Poche.class.php b/inc/poche/Poche.class.php index a8f64151..5dab10df 100644 --- a/inc/poche/Poche.class.php +++ b/inc/poche/Poche.class.php | |||
@@ -247,10 +247,15 @@ class Poche | |||
247 | $tidy = tidy_parse_string($content, array('indent'=>true, 'show-body-only' => true), 'UTF8'); | 247 | $tidy = tidy_parse_string($content, array('indent'=>true, 'show-body-only' => true), 'UTF8'); |
248 | $tidy->cleanRepair(); | 248 | $tidy->cleanRepair(); |
249 | $content = $tidy->value; | 249 | $content = $tidy->value; |
250 | } | 250 | |
251 | // flattr checking | ||
252 | $flattr = new FlattrItem(); | ||
253 | $flattr->checkitem($entry['url']); | ||
254 | |||
251 | $tpl_vars = array( | 255 | $tpl_vars = array( |
252 | 'entry' => $entry, | 256 | 'entry' => $entry, |
253 | 'content' => $content, | 257 | 'content' => $content, |
258 | 'flattr' => $flattr, | ||
254 | ); | 259 | ); |
255 | } | 260 | } |
256 | else { | 261 | else { |
@@ -558,4 +563,54 @@ class Poche | |||
558 | } | 563 | } |
559 | return $version; | 564 | return $version; |
560 | } | 565 | } |
561 | } \ No newline at end of file | 566 | } |
567 | |||
568 | /* class for Flattr querying. Should be put in a separate file | ||
569 | * Or maybe just create an array instead of a complete class... My mistake. :-° | ||
570 | */ | ||
571 | class FlattrItem{ | ||
572 | public $status; | ||
573 | public $urltoflattr; | ||
574 | public $flattrItemURL; | ||
575 | public $numflattrs; | ||
576 | |||
577 | public function checkitem($urltoflattr){ | ||
578 | $this->cacheflattrfile($urltoflattr); | ||
579 | $flattrResponse = file_get_contents("cache/flattr/".base64_encode($urltoflattr).".cache"); | ||
580 | var_dump($flattrResponse); | ||
581 | if($flattrResponse != FALSE){ | ||
582 | $result = json_decode($flattrResponse); | ||
583 | if (isset($result->message)){ | ||
584 | if ($result->message == "flattrable"){ | ||
585 | $this->status = "flattrable"; | ||
586 | } | ||
587 | } | ||
588 | elseif ($result->link) { | ||
589 | $this->status = "flattred"; | ||
590 | $this->flattrItemURL = $result->link; | ||
591 | $this->numflattrs = $result->flattrs_user_count; | ||
592 | } | ||
593 | else{ | ||
594 | $this->status = "not flattrable"; | ||
595 | } | ||
596 | } | ||
597 | else | ||
598 | { | ||
599 | $this->status = "FLATTR_ERR_CONNECTION"; | ||
600 | } | ||
601 | } | ||
602 | |||
603 | private function cacheflattrfile($urltoflattr){ | ||
604 | if (!is_dir('cache/flattr')){ | ||
605 | mkdir('./cache/flattr', 0700); | ||
606 | } | ||
607 | // 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 | ||
608 | if ((!file_exists("cache/flattr/".base64_encode($urltoflattr).".cache")) || (time() - filemtime("cache/flattr/".base64_encode($urltoflattr).".cache") > 86400)) | ||
609 | { | ||
610 | $askForFlattr = Tools::getFile("https://api.flattr.com/rest/v2/things/lookup/?url=".$urltoflattr); | ||
611 | $flattrCacheFile = fopen("cache/flattr/".base64_encode($urltoflattr).".cache", 'w+'); | ||
612 | fwrite($flattrCacheFile, $askForFlattr); | ||
613 | fclose($flattrCacheFile); | ||
614 | } | ||
615 | } | ||
616 | } | ||
diff --git a/tpl/view.twig b/tpl/view.twig index 28508772..7b15c7c7 100644 --- a/tpl/view.twig +++ b/tpl/view.twig | |||
@@ -31,6 +31,7 @@ | |||
31 | {% if constant('SHARE_TWITTER') == 1 %}<li><a href="https://twitter.com/home?status={{entry.title|url_encode}}%20{{ entry.url|url_encode }}%20via%20@getpoche" target="_blank" class="tool twitter" title="{% trans "tweet" %}"><span>{% trans "tweet" %}</span></a></li>{% endif %} | 31 | {% if constant('SHARE_TWITTER') == 1 %}<li><a href="https://twitter.com/home?status={{entry.title|url_encode}}%20{{ entry.url|url_encode }}%20via%20@getpoche" target="_blank" class="tool twitter" title="{% trans "tweet" %}"><span>{% trans "tweet" %}</span></a></li>{% endif %} |
32 | {% if constant('SHARE_MAIL') == 1 %}<li><a href="mailto:?subject={{ entry.title|url_encode }}&body={{ entry.url|url_encode }}%20via%20@getpoche" class="tool email" title="{% trans "email" %}"><span>{% trans "email" %}</span></a></li>{% endif %} | 32 | {% if constant('SHARE_MAIL') == 1 %}<li><a href="mailto:?subject={{ entry.title|url_encode }}&body={{ entry.url|url_encode }}%20via%20@getpoche" class="tool email" title="{% trans "email" %}"><span>{% trans "email" %}</span></a></li>{% endif %} |
33 | {% if constant('SHARE_SHAARLI') == 1 %}<li><a href="{{ constant('SHAARLI_URL') }}/index.php?post={{ entry.url|url_encode }}&title={{ entry.title|url_encode }}" target="_blank" class="tool shaarli" title="{% trans "shaarli" %}"><span>{% trans "shaarli" %}</span></a></li>{% endif %} | 33 | {% if constant('SHARE_SHAARLI') == 1 %}<li><a href="{{ constant('SHAARLI_URL') }}/index.php?post={{ entry.url|url_encode }}&title={{ entry.title|url_encode }}" target="_blank" class="tool shaarli" title="{% trans "shaarli" %}"><span>{% trans "shaarli" %}</span></a></li>{% endif %} |
34 | <li>{% if flattr.status == "flattrable" %} This thing is flattrable !{% elseif flattr.status == "flattred" %} <a href="{{ flattr.flattrItemURL }}" >This thing has already been flattred by {{ flattr.numflattrs }} users and can be flattred !</a>{% else %}This article cannot be flattred{% endif %}</li> | ||
34 | </ul> | 35 | </ul> |
35 | <p>{% trans "this article appears wrong?" %} <a href="https://github.com/inthepoche/poche/issues/new">{% trans "create an issue" %}</a> {% trans "or" %} <a href="mailto:support@inthepoche.com?subject=Wrong%20display%20in%20poche&body={{ entry.url|url_encode }}">{% trans "contact us by mail" %}</a></p> | 36 | <p>{% trans "this article appears wrong?" %} <a href="https://github.com/inthepoche/poche/issues/new">{% trans "create an issue" %}</a> {% trans "or" %} <a href="mailto:support@inthepoche.com?subject=Wrong%20display%20in%20poche&body={{ entry.url|url_encode }}">{% trans "contact us by mail" %}</a></p> |
36 | </div> | 37 | </div> |