From a32231274060ec2de453124117518458c4fa00df Mon Sep 17 00:00:00 2001 From: Thomas Citharel Date: Sun, 8 Sep 2013 20:54:11 +0200 Subject: Implemented Flattr changes Added a button to say if the article is flattrable or not and how many people have flattred this object. --- inc/poche/Poche.class.php | 59 +++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 57 insertions(+), 2 deletions(-) (limited to 'inc/poche') 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 $tidy = tidy_parse_string($content, array('indent'=>true, 'show-body-only' => true), 'UTF8'); $tidy->cleanRepair(); $content = $tidy->value; - } + + // flattr checking + $flattr = new FlattrItem(); + $flattr->checkitem($entry['url']); + $tpl_vars = array( 'entry' => $entry, 'content' => $content, + 'flattr' => $flattr, ); } else { @@ -558,4 +563,54 @@ class Poche } return $version; } -} \ No newline at end of file +} + +/* class for Flattr querying. Should be put in a separate file +* Or maybe just create an array instead of a complete class... My mistake. :-° +*/ +class FlattrItem{ + public $status; + public $urltoflattr; + public $flattrItemURL; + public $numflattrs; + + public function checkitem($urltoflattr){ + $this->cacheflattrfile($urltoflattr); + $flattrResponse = file_get_contents("cache/flattr/".base64_encode($urltoflattr).".cache"); + var_dump($flattrResponse); + 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_user_count; + } + else{ + $this->status = "not flattrable"; + } + } + else + { + $this->status = "FLATTR_ERR_CONNECTION"; + } + } + + private function cacheflattrfile($urltoflattr){ + if (!is_dir('cache/flattr')){ + mkdir('./cache/flattr', 0700); + } + // 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("https://api.flattr.com/rest/v2/things/lookup/?url=".$urltoflattr); + $flattrCacheFile = fopen("cache/flattr/".base64_encode($urltoflattr).".cache", 'w+'); + fwrite($flattrCacheFile, $askForFlattr); + fclose($flattrCacheFile); + } + } +} -- cgit v1.2.3 From af1d2792263d45c5ffea2e5485dd81bf59b7bded Mon Sep 17 00:00:00 2001 From: Thomas Citharel Date: Sun, 8 Sep 2013 21:52:01 +0200 Subject: Fixed errors and changed source of flattrs Fixed errors, and the number displayed is no longer the number of peope who has flattred an article, but the number of flattrs he has got. --- inc/poche/Poche.class.php | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) (limited to 'inc/poche') diff --git a/inc/poche/Poche.class.php b/inc/poche/Poche.class.php index 5dab10df..8b24e5cd 100644 --- a/inc/poche/Poche.class.php +++ b/inc/poche/Poche.class.php @@ -249,20 +249,21 @@ class Poche $content = $tidy->value; // flattr checking - $flattr = new FlattrItem(); - $flattr->checkitem($entry['url']); + $flattr = new FlattrItem(); + $flattr->checkitem($entry['url']); - $tpl_vars = array( + $tpl_vars = array( 'entry' => $entry, 'content' => $content, - 'flattr' => $flattr, - ); + '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' => '', @@ -577,7 +578,6 @@ class FlattrItem{ public function checkitem($urltoflattr){ $this->cacheflattrfile($urltoflattr); $flattrResponse = file_get_contents("cache/flattr/".base64_encode($urltoflattr).".cache"); - var_dump($flattrResponse); if($flattrResponse != FALSE){ $result = json_decode($flattrResponse); if (isset($result->message)){ @@ -588,7 +588,7 @@ class FlattrItem{ elseif ($result->link) { $this->status = "flattred"; $this->flattrItemURL = $result->link; - $this->numflattrs = $result->flattrs_user_count; + $this->numflattrs = $result->flattrs; } else{ $this->status = "not flattrable"; -- cgit v1.2.3 From 964481d023676bee964141a1d14f638995ac8d30 Mon Sep 17 00:00:00 2001 From: Thomas Citharel Date: Tue, 10 Sep 2013 18:23:56 +0200 Subject: Fixed bugs, added a flattr button and an option There's a button and an option in define.inc.php to show the button or not. --- inc/poche/Poche.class.php | 2 +- inc/poche/define.inc.php | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) (limited to 'inc/poche') diff --git a/inc/poche/Poche.class.php b/inc/poche/Poche.class.php index 8b24e5cd..b0efe69a 100644 --- a/inc/poche/Poche.class.php +++ b/inc/poche/Poche.class.php @@ -602,7 +602,7 @@ class FlattrItem{ private function cacheflattrfile($urltoflattr){ if (!is_dir('cache/flattr')){ - mkdir('./cache/flattr', 0700); + 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)) diff --git a/inc/poche/define.inc.php b/inc/poche/define.inc.php index 3f667430..62777282 100644 --- a/inc/poche/define.inc.php +++ b/inc/poche/define.inc.php @@ -20,8 +20,9 @@ define ('DEBUG_POCHE', FALSE); define ('DOWNLOAD_PICTURES', FALSE); define ('SHARE_TWITTER', TRUE); define ('SHARE_MAIL', TRUE); -define ('SHARE_SHAARLI', FALSE); +define ('SHARE_SHAARLI', TRUE); define ('SHAARLI_URL', 'http://myshaarliurl.com'); +define ('FLATTR', TRUE); define ('ABS_PATH', 'assets/'); define ('TPL', __DIR__ . '/../../tpl'); define ('LOCALE', __DIR__ . '/../../locale'); -- cgit v1.2.3