}
$last_id = $this->store->getLastId($sequence);
if (DOWNLOAD_PICTURES) {
- $content = filtre_picture($parametres_url['body'], $url->getUrl(), $last_id);
+ $content = filtre_picture($content['body'], $url->getUrl(), $last_id);
Tools::logm('updating content article');
$this->store->updateContent($last_id, $content, $this->user->getId());
}
$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 view
+ default : // home, favorites and archive views
$entries = $this->store->getEntriesByView($view, $this->user->getId());
- $this->pagination->set_total(count($entries));
- $page_links = $this->pagination->page_links('?view=' . $view . '&sort=' . $_SESSION['sort'] . '&');
- $datas = $this->store->getEntriesByView($view, $this->user->getId(), $this->pagination->get_limit());
$tpl_vars = array(
- 'entries' => $datas,
- 'page_links' => $page_links,
+ 'entries' => '',
+ 'page_links' => '',
);
+ if (count($entries) > 0) {
+ $this->pagination->set_total(count($entries));
+ $page_links = $this->pagination->page_links('?view=' . $view . '&sort=' . $_SESSION['sort'] . '&');
+ $datas = $this->store->getEntriesByView($view, $this->user->getId(), $this->pagination->get_limit());
+ $tpl_vars['entries'] = $datas;
+ $tpl_vars['page_links'] = $page_links;
+ }
Tools::logm('display ' . $view . ' view');
break;
}
}
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");
+ 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("https://api.flattr.com/rest/v2/things/lookup/?url=".$urltoflattr);
+ $flattrCacheFile = fopen("cache/flattr/".base64_encode($urltoflattr).".cache", 'w+');
+ fwrite($flattrCacheFile, $askForFlattr);
+ fclose($flattrCacheFile);
+ }
+ }
+}