aboutsummaryrefslogtreecommitdiffhomepage
path: root/inc/poche
diff options
context:
space:
mode:
authorThomas Citharel <thomas.citharet@gmail.com>2013-09-08 20:54:11 +0200
committerThomas Citharel <thomas.citharet@gmail.com>2013-09-08 20:54:11 +0200
commita32231274060ec2de453124117518458c4fa00df (patch)
treeccb326938a0df6c5b2cb58de2ebb5adc61206360 /inc/poche
parent3eb049036e601c1978cf5f7f0d5be8c577933b72 (diff)
downloadwallabag-a32231274060ec2de453124117518458c4fa00df.tar.gz
wallabag-a32231274060ec2de453124117518458c4fa00df.tar.zst
wallabag-a32231274060ec2de453124117518458c4fa00df.zip
Implemented Flattr changes
Added a button to say if the article is flattrable or not and how many people have flattred this object.
Diffstat (limited to 'inc/poche')
-rw-r--r--inc/poche/Poche.class.php59
1 files changed, 57 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*/
571class 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}