diff options
Diffstat (limited to 'inc/poche/Poche.class.php')
-rwxr-xr-x | inc/poche/Poche.class.php | 168 |
1 files changed, 129 insertions, 39 deletions
diff --git a/inc/poche/Poche.class.php b/inc/poche/Poche.class.php index fd2600f3..15d83bfe 100755 --- a/inc/poche/Poche.class.php +++ b/inc/poche/Poche.class.php | |||
@@ -200,27 +200,34 @@ class Poche | |||
200 | 200 | ||
201 | //search for possible duplicate | 201 | //search for possible duplicate |
202 | $duplicate = NULL; | 202 | $duplicate = NULL; |
203 | $duplicate = $this->store->retrieveOneByURL($url->getUrl(), $this->user->getId()); | 203 | $clean_url = $url->getUrl(); |
204 | 204 | ||
205 | $last_id = $this->store->add($url->getUrl(), $title, $body, $this->user->getId()); | 205 | // Clean URL to remove parameters from feedburner and all this stuff. Taken from Shaarli. |
206 | $i=strpos($clean_url,'&utm_source='); if ($i!==false) $clean_url=substr($clean_url,0,$i); | ||
207 | $i=strpos($clean_url,'?utm_source='); if ($i!==false) $clean_url=substr($clean_url,0,$i); | ||
208 | $i=strpos($clean_url,'#xtor=RSS-'); if ($i!==false) $clean_url=substr($clean_url,0,$i); | ||
209 | |||
210 | $duplicate = $this->store->retrieveOneByURL($clean_url, $this->user->getId()); | ||
211 | |||
212 | $last_id = $this->store->add($clean_url, $title, $body, $this->user->getId()); | ||
206 | if ( $last_id ) { | 213 | if ( $last_id ) { |
207 | Tools::logm('add link ' . $url->getUrl()); | 214 | Tools::logm('add link ' . $clean_url); |
208 | if (DOWNLOAD_PICTURES) { | 215 | if (DOWNLOAD_PICTURES) { |
209 | $content = Picture::filterPicture($body, $url->getUrl(), $last_id); | 216 | $content = Picture::filterPicture($body, $clean_url, $last_id); |
210 | Tools::logm('updating content article'); | 217 | Tools::logm('updating content article'); |
211 | $this->store->updateContent($last_id, $content, $this->user->getId()); | 218 | $this->store->updateContent($last_id, $content, $this->user->getId()); |
212 | } | 219 | } |
213 | 220 | ||
214 | if ($duplicate != NULL) { | 221 | if ($duplicate != NULL) { |
215 | // duplicate exists, so, older entry needs to be deleted (as new entry should go to the top of list), BUT favorite mark and tags should be preserved | 222 | // duplicate exists, so, older entry needs to be deleted (as new entry should go to the top of list), BUT favorite mark and tags should be preserved |
216 | Tools::logm('link ' . $url->getUrl() . ' is a duplicate'); | 223 | Tools::logm('link ' . $clean_url . ' is a duplicate'); |
217 | // 1) - preserve tags and favorite, then drop old entry | 224 | // 1) - preserve tags and favorite, then drop old entry |
218 | $this->store->reassignTags($duplicate['id'], $last_id); | 225 | $this->store->reassignTags($duplicate['id'], $last_id); |
219 | if ($duplicate['is_fav']) { | 226 | if ($duplicate['is_fav']) { |
220 | $this->store->favoriteById($last_id, $this->user->getId()); | 227 | $this->store->favoriteById($last_id, $this->user->getId()); |
221 | } | 228 | } |
222 | if ($this->store->deleteById($duplicate['id'], $this->user->getId())) { | 229 | if ($this->store->deleteById($duplicate['id'], $this->user->getId())) { |
223 | Tools::logm('previous link ' . $url->getUrl() .' entry deleted'); | 230 | Tools::logm('previous link ' . $clean_url .' entry deleted'); |
224 | } | 231 | } |
225 | } | 232 | } |
226 | 233 | ||
@@ -235,7 +242,7 @@ class Poche | |||
235 | } | 242 | } |
236 | else { | 243 | else { |
237 | $this->messages->add('e', _('error during insertion : the link wasn\'t added')); | 244 | $this->messages->add('e', _('error during insertion : the link wasn\'t added')); |
238 | Tools::logm('error during insertion : the link wasn\'t added ' . $url->getUrl()); | 245 | Tools::logm('error during insertion : the link wasn\'t added ' . $clean_url); |
239 | } | 246 | } |
240 | 247 | ||
241 | if ($autoclose == TRUE) { | 248 | if ($autoclose == TRUE) { |
@@ -259,6 +266,15 @@ class Poche | |||
259 | } | 266 | } |
260 | foreach($entry_ids as $id) { | 267 | foreach($entry_ids as $id) { |
261 | $msg = 'delete link #' . $id; | 268 | $msg = 'delete link #' . $id; |
269 | |||
270 | // deleting tags and tags_entries | ||
271 | $tags = $this->store->retrieveTagsByEntry($id); | ||
272 | foreach ($tags as $tag) { | ||
273 | $this->store->removeTagForEntry($id, $tag['id']); | ||
274 | $this->store->cleanUnusedTag($tag['id']); | ||
275 | } | ||
276 | |||
277 | // deleting pictures | ||
262 | if ($this->store->deleteById($id, $this->user->getId())) { | 278 | if ($this->store->deleteById($id, $this->user->getId())) { |
263 | if (DOWNLOAD_PICTURES) { | 279 | if (DOWNLOAD_PICTURES) { |
264 | Picture::removeDirectory(ABS_PATH . $id); | 280 | Picture::removeDirectory(ABS_PATH . $id); |
@@ -303,11 +319,16 @@ class Poche | |||
303 | if ( Tools::isAjaxRequest() ) { | 319 | if ( Tools::isAjaxRequest() ) { |
304 | echo 1; | 320 | echo 1; |
305 | exit; | 321 | exit; |
306 | } | 322 | } else { |
307 | else { | ||
308 | Tools::redirect(); | 323 | Tools::redirect(); |
309 | } | 324 | } |
310 | break; | 325 | break; |
326 | case 'archive_and_next' : | ||
327 | $nextid = $this->store->getPreviousArticle($id, $this->user->getId()); | ||
328 | $this->store->archiveById($id, $this->user->getId()); | ||
329 | Tools::logm('archive link #' . $id); | ||
330 | Tools::redirect('?view=view&id=' . $nextid); | ||
331 | break; | ||
311 | case 'archive_all' : | 332 | case 'archive_all' : |
312 | $this->store->archiveAll($this->user->getId()); | 333 | $this->store->archiveAll($this->user->getId()); |
313 | Tools::logm('archive all links'); | 334 | Tools::logm('archive all links'); |
@@ -394,8 +415,9 @@ class Poche | |||
394 | /* For some unknown reason I can't get displayView() to work here (it redirects to home view afterwards). So here's a dirty fix which redirects directly to URL */ | 415 | /* For some unknown reason I can't get displayView() to work here (it redirects to home view afterwards). So here's a dirty fix which redirects directly to URL */ |
395 | case 'random': | 416 | case 'random': |
396 | Tools::logm('get a random article'); | 417 | Tools::logm('get a random article'); |
397 | if ($this->store->getRandomId($this->user->getId())) { | 418 | $view = $_GET['view']; |
398 | $id_array = $this->store->getRandomId($this->user->getId()); | 419 | if ($this->store->getRandomId($this->user->getId(),$view)) { |
420 | $id_array = $this->store->getRandomId($this->user->getId(),$view); | ||
399 | $id = $id_array[0]; | 421 | $id = $id_array[0]; |
400 | Tools::redirect('?view=view&id=' . $id[0]); | 422 | Tools::redirect('?view=view&id=' . $id[0]); |
401 | Tools::logm('got the article with id ' . $id[0]); | 423 | Tools::logm('got the article with id ' . $id[0]); |
@@ -453,9 +475,31 @@ class Poche | |||
453 | Tools::redirect(); | 475 | Tools::redirect(); |
454 | } | 476 | } |
455 | $tags = $this->store->retrieveTagsByEntry($id); | 477 | $tags = $this->store->retrieveTagsByEntry($id); |
478 | $all_tags = $this->store->retrieveAllTags($this->user->getId()); | ||
479 | $maximus = 0; | ||
480 | foreach ($all_tags as $eachtag) { // search for the most times a tag is present | ||
481 | if ($eachtag["entriescount"] > $maximus) $maximus = $eachtag["entriescount"]; | ||
482 | } | ||
483 | foreach ($all_tags as $key => $eachtag) { // get the percentage of presence of each tag | ||
484 | $percent = floor(($eachtag["entriescount"] / $maximus) * 100); | ||
485 | |||
486 | if ($percent < 20): // assign a css class, depending on the number of entries count | ||
487 | $cssclass = 'smallesttag'; | ||
488 | elseif ($percent >= 20 and $percent < 40): | ||
489 | $cssclass = 'smalltag'; | ||
490 | elseif ($percent >= 40 and $percent < 60): | ||
491 | $cssclass = 'mediumtag'; | ||
492 | elseif ($percent >= 60 and $percent < 80): | ||
493 | $cssclass = 'largetag'; | ||
494 | else: | ||
495 | $cssclass = 'largesttag'; | ||
496 | endif; | ||
497 | $all_tags[$key]['cssclass'] = $cssclass; | ||
498 | } | ||
456 | $tpl_vars = array( | 499 | $tpl_vars = array( |
457 | 'entry_id' => $id, | 500 | 'entry_id' => $id, |
458 | 'tags' => $tags, | 501 | 'tags' => $tags, |
502 | 'alltags' => $all_tags, | ||
459 | 'entry' => $entry, | 503 | 'entry' => $entry, |
460 | ); | 504 | ); |
461 | break; | 505 | break; |
@@ -509,6 +553,20 @@ class Poche | |||
509 | $flattr->checkItem($entry['url'], $entry['id']); | 553 | $flattr->checkItem($entry['url'], $entry['id']); |
510 | } | 554 | } |
511 | 555 | ||
556 | # previous and next | ||
557 | $previous = FALSE; | ||
558 | $previous_id = $this->store->getPreviousArticle($id, $this->user->getId()); | ||
559 | $next = FALSE; | ||
560 | $next_id = $this->store->getNextArticle($id, $this->user->getId()); | ||
561 | |||
562 | if ($this->store->retrieveOneById($previous_id, $this->user->getId())) { | ||
563 | $previous = TRUE; | ||
564 | } | ||
565 | if ($this->store->retrieveOneById($next_id, $this->user->getId())) { | ||
566 | $next = TRUE; | ||
567 | } | ||
568 | $navigate = array('previous' => $previous, 'previousid' => $previous_id, 'next' => $next, 'nextid' => $next_id); | ||
569 | |||
512 | # tags | 570 | # tags |
513 | $tags = $this->store->retrieveTagsByEntry($entry['id']); | 571 | $tags = $this->store->retrieveTagsByEntry($entry['id']); |
514 | 572 | ||
@@ -516,7 +574,8 @@ class Poche | |||
516 | 'entry' => $entry, | 574 | 'entry' => $entry, |
517 | 'content' => $content, | 575 | 'content' => $content, |
518 | 'flattr' => $flattr, | 576 | 'flattr' => $flattr, |
519 | 'tags' => $tags | 577 | 'tags' => $tags, |
578 | 'navigate' => $navigate | ||
520 | ); | 579 | ); |
521 | } | 580 | } |
522 | else { | 581 | else { |
@@ -529,6 +588,7 @@ class Poche | |||
529 | 'page_links' => '', | 588 | 'page_links' => '', |
530 | 'nb_results' => '', | 589 | 'nb_results' => '', |
531 | 'listmode' => (isset($_COOKIE['listmode']) ? true : false), | 590 | 'listmode' => (isset($_COOKIE['listmode']) ? true : false), |
591 | 'view' => $view, | ||
532 | ); | 592 | ); |
533 | 593 | ||
534 | //if id is given - we retrieve entries by tag: id is tag id | 594 | //if id is given - we retrieve entries by tag: id is tag id |
@@ -539,7 +599,7 @@ class Poche | |||
539 | 599 | ||
540 | $count = $this->store->getEntriesByViewCount($view, $this->user->getId(), $id); | 600 | $count = $this->store->getEntriesByViewCount($view, $this->user->getId(), $id); |
541 | 601 | ||
542 | if ($count > 0) { | 602 | if ($count && $count > 0) { |
543 | $this->pagination->set_total($count); | 603 | $this->pagination->set_total($count); |
544 | $page_links = str_replace(array('previous', 'next'), array(_('previous'), _('next')), | 604 | $page_links = str_replace(array('previous', 'next'), array(_('previous'), _('next')), |
545 | $this->pagination->page_links('?view=' . $view . '&sort=' . $_SESSION['sort'] . (($id)?'&id='.$id:'') . '&' )); | 605 | $this->pagination->page_links('?view=' . $view . '&sort=' . $_SESSION['sort'] . (($id)?'&id='.$id:'') . '&' )); |
@@ -635,6 +695,7 @@ class Poche | |||
635 | setlocale(LC_ALL, $language); | 695 | setlocale(LC_ALL, $language); |
636 | bindtextdomain($language, LOCALE); | 696 | bindtextdomain($language, LOCALE); |
637 | textdomain($language); | 697 | textdomain($language); |
698 | bind_textdomain_codeset($language, 'UTF-8'); | ||
638 | 699 | ||
639 | $this->messages->add('s', _('welcome to your wallabag')); | 700 | $this->messages->add('s', _('welcome to your wallabag')); |
640 | Tools::logm('login successful'); | 701 | Tools::logm('login successful'); |
@@ -681,23 +742,45 @@ class Poche | |||
681 | $html->load_file($_FILES['file']['tmp_name']); | 742 | $html->load_file($_FILES['file']['tmp_name']); |
682 | $data = array(); | 743 | $data = array(); |
683 | $read = 0; | 744 | $read = 0; |
684 | foreach (array('ol','ul') as $list) { | 745 | |
685 | foreach ($html->find($list) as $ul) { | 746 | if (Tools::get_doctype($html)->innertext == "<!DOCTYPE NETSCAPE-Bookmark-file-1>") { |
686 | foreach ($ul->find('li') as $li) { | 747 | // Firefox-bookmarks HTML |
687 | $tmpEntry = array(); | 748 | foreach (array('DL','ul') as $list) { |
688 | $a = $li->find('a'); | 749 | foreach ($html->find($list) as $ul) { |
689 | $tmpEntry['url'] = $a[0]->href; | 750 | foreach ($ul->find('DT') as $li) { |
690 | $tmpEntry['tags'] = $a[0]->tags; | 751 | $tmpEntry = array(); |
691 | $tmpEntry['is_read'] = $read; | 752 | $a = $li->find('A'); |
692 | if ($tmpEntry['url']) { | 753 | $tmpEntry['url'] = $a[0]->href; |
693 | $data[] = $tmpEntry; | 754 | $tmpEntry['tags'] = $a[0]->tags; |
755 | $tmpEntry['is_read'] = $read; | ||
756 | if ($tmpEntry['url']) { | ||
757 | $data[] = $tmpEntry; | ||
758 | } | ||
694 | } | 759 | } |
695 | } | 760 | # the second <ol/ul> is for read links |
696 | # the second <ol/ul> is for read links | 761 | $read = ((sizeof($data) && $read)?0:1); |
697 | $read = ((sizeof($data) && $read)?0:1); | 762 | } |
698 | } | 763 | } |
699 | } | 764 | } else { |
700 | } | 765 | // regular HTML |
766 | foreach (array('ol','ul') as $list) { | ||
767 | foreach ($html->find($list) as $ul) { | ||
768 | foreach ($ul->find('li') as $li) { | ||
769 | $tmpEntry = array(); | ||
770 | $a = $li->find('a'); | ||
771 | $tmpEntry['url'] = $a[0]->href; | ||
772 | $tmpEntry['tags'] = $a[0]->tags; | ||
773 | $tmpEntry['is_read'] = $read; | ||
774 | if ($tmpEntry['url']) { | ||
775 | $data[] = $tmpEntry; | ||
776 | } | ||
777 | } | ||
778 | # the second <ol/ul> is for read links | ||
779 | $read = ((sizeof($data) && $read)?0:1); | ||
780 | } | ||
781 | } | ||
782 | } | ||
783 | } | ||
701 | 784 | ||
702 | // for readability structure | 785 | // for readability structure |
703 | 786 | ||
@@ -715,7 +798,7 @@ class Poche | |||
715 | $urlsInserted = array(); //urls of articles inserted | 798 | $urlsInserted = array(); //urls of articles inserted |
716 | foreach($data as $record) { | 799 | foreach($data as $record) { |
717 | $url = trim(isset($record['article__url']) ? $record['article__url'] : (isset($record['url']) ? $record['url'] : '')); | 800 | $url = trim(isset($record['article__url']) ? $record['article__url'] : (isset($record['url']) ? $record['url'] : '')); |
718 | if ($url and !in_array($url, $urlsInserted)) { | 801 | if (filter_var($url, FILTER_VALIDATE_URL) and !in_array($url, $urlsInserted)) { |
719 | $title = (isset($record['title']) ? $record['title'] : _('Untitled - Import - ') . '</a> <a href="./?import">' . _('click to finish import') . '</a><a>'); | 802 | $title = (isset($record['title']) ? $record['title'] : _('Untitled - Import - ') . '</a> <a href="./?import">' . _('click to finish import') . '</a><a>'); |
720 | $body = (isset($record['content']) ? $record['content'] : ''); | 803 | $body = (isset($record['content']) ? $record['content'] : ''); |
721 | $isRead = (isset($record['is_read']) ? intval($record['is_read']) : (isset($record['archive']) ? intval($record['archive']) : 0)); | 804 | $isRead = (isset($record['is_read']) ? intval($record['is_read']) : (isset($record['archive']) ? intval($record['archive']) : 0)); |
@@ -820,14 +903,18 @@ class Poche | |||
820 | */ | 903 | */ |
821 | public function export() | 904 | public function export() |
822 | { | 905 | { |
823 | $filename = "wallabag-export-".$this->user->getId()."-".date("Y-m-d").".json"; | 906 | $filename = "wallabag-export-".$this->user->getId()."-".date("Y-m-d").".json"; |
824 | header('Content-Disposition: attachment; filename='.$filename); | 907 | header('Content-Disposition: attachment; filename='.$filename); |
825 | 908 | ||
826 | $entries = $this->store->retrieveAll($this->user->getId()); | 909 | $entries = $this->store->retrieveAllWithTags($this->user->getId()); |
827 | echo $this->tpl->render('export.twig', array( | 910 | if ($entries) { |
828 | 'export' => Tools::renderJson($entries), | 911 | echo $this->tpl->render('export.twig', array( |
829 | )); | 912 | 'export' => Tools::renderJson($entries), |
830 | Tools::logm('export view'); | 913 | )); |
914 | Tools::logm('export view'); | ||
915 | } else { | ||
916 | Tools::logm('error accessing database while exporting'); | ||
917 | } | ||
831 | } | 918 | } |
832 | 919 | ||
833 | /** | 920 | /** |
@@ -903,7 +990,7 @@ class Poche | |||
903 | if (0 == $limit) { | 990 | if (0 == $limit) { |
904 | $limit = count($entries); | 991 | $limit = count($entries); |
905 | } | 992 | } |
906 | if (count($entries) > 0) { | 993 | if ($entries && count($entries) > 0) { |
907 | for ($i = 0; $i < min(count($entries), $limit); $i++) { | 994 | for ($i = 0; $i < min(count($entries), $limit); $i++) { |
908 | $entry = $entries[$i]; | 995 | $entry = $entries[$i]; |
909 | $newItem = $feed->createNewItem(); | 996 | $newItem = $feed->createNewItem(); |
@@ -915,7 +1002,10 @@ class Poche | |||
915 | $feed->addItem($newItem); | 1002 | $feed->addItem($newItem); |
916 | } | 1003 | } |
917 | } | 1004 | } |
918 | 1005 | else | |
1006 | { | ||
1007 | Tools::logm("database error while generating feeds"); | ||
1008 | } | ||
919 | $feed->genarateFeed(); | 1009 | $feed->genarateFeed(); |
920 | exit; | 1010 | exit; |
921 | } | 1011 | } |