aboutsummaryrefslogtreecommitdiffhomepage
path: root/inc/poche/Poche.class.php
diff options
context:
space:
mode:
Diffstat (limited to 'inc/poche/Poche.class.php')
-rw-r--r--inc/poche/Poche.class.php61
1 files changed, 7 insertions, 54 deletions
diff --git a/inc/poche/Poche.class.php b/inc/poche/Poche.class.php
index b0efe69a..9db4a034 100644
--- a/inc/poche/Poche.class.php
+++ b/inc/poche/Poche.class.php
@@ -182,7 +182,7 @@ class Poche
182 } 182 }
183 183
184 if (!$import) { 184 if (!$import) {
185 Tools::redirect(); 185 Tools::redirect('?view=home');
186 } 186 }
187 break; 187 break;
188 case 'delete': 188 case 'delete':
@@ -248,9 +248,9 @@ class Poche
248 $tidy->cleanRepair(); 248 $tidy->cleanRepair();
249 $content = $tidy->value; 249 $content = $tidy->value;
250 250
251 // flattr checking 251 # flattr checking
252 $flattr = new FlattrItem(); 252 $flattr = new FlattrItem();
253 $flattr->checkitem($entry['url']); 253 $flattr->checkItem($entry['url']);
254 254
255 $tpl_vars = array( 255 $tpl_vars = array(
256 'entry' => $entry, 256 'entry' => $entry,
@@ -263,11 +263,12 @@ class Poche
263 Tools::logm('error in view call : entry is null'); 263 Tools::logm('error in view call : entry is null');
264 } 264 }
265 break; 265 break;
266 default : // home, favorites and archive views 266 default: # home, favorites and archive views
267 $entries = $this->store->getEntriesByView($view, $this->user->getId()); 267 $entries = $this->store->getEntriesByView($view, $this->user->getId());
268 $tpl_vars = array( 268 $tpl_vars = array(
269 'entries' => '', 269 'entries' => '',
270 'page_links' => '', 270 'page_links' => '',
271 'nb_results' => '',
271 ); 272 );
272 if (count($entries) > 0) { 273 if (count($entries) > 0) {
273 $this->pagination->set_total(count($entries)); 274 $this->pagination->set_total(count($entries));
@@ -275,6 +276,7 @@ class Poche
275 $datas = $this->store->getEntriesByView($view, $this->user->getId(), $this->pagination->get_limit()); 276 $datas = $this->store->getEntriesByView($view, $this->user->getId(), $this->pagination->get_limit());
276 $tpl_vars['entries'] = $datas; 277 $tpl_vars['entries'] = $datas;
277 $tpl_vars['page_links'] = $page_links; 278 $tpl_vars['page_links'] = $page_links;
279 $tpl_vars['nb_results'] = count($entries);
278 } 280 }
279 Tools::logm('display ' . $view . ' view'); 281 Tools::logm('display ' . $view . ' view');
280 break; 282 break;
@@ -564,53 +566,4 @@ class Poche
564 } 566 }
565 return $version; 567 return $version;
566 } 568 }
567} 569} \ No newline at end of file
568
569/* class for Flattr querying. Should be put in a separate file
570* Or maybe just create an array instead of a complete class... My mistake. :-°
571*/
572class FlattrItem{
573 public $status;
574 public $urltoflattr;
575 public $flattrItemURL;
576 public $numflattrs;
577
578 public function checkitem($urltoflattr){
579 $this->cacheflattrfile($urltoflattr);
580 $flattrResponse = file_get_contents("cache/flattr/".base64_encode($urltoflattr).".cache");
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;
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', 0777);
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}