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, 57 insertions, 4 deletions
diff --git a/inc/poche/Poche.class.php b/inc/poche/Poche.class.php
index 5eba3564..753bd7f0 100644
--- a/inc/poche/Poche.class.php
+++ b/inc/poche/Poche.class.php
@@ -374,6 +374,11 @@ class Poche
374 $title = ($content['rss']['channel']['item']['title'] != '') ? $content['rss']['channel']['item']['title'] : _('Untitled'); 374 $title = ($content['rss']['channel']['item']['title'] != '') ? $content['rss']['channel']['item']['title'] : _('Untitled');
375 $body = $content['rss']['channel']['item']['description']; 375 $body = $content['rss']['channel']['item']['description'];
376 376
377 //search for possible duplicate if not in import mode
378 if (!$import) {
379 $duplicate = $this->store->retrieveOneByURL($url->getUrl(), $this->user->getId());
380 }
381
377 if ($this->store->add($url->getUrl(), $title, $body, $this->user->getId())) { 382 if ($this->store->add($url->getUrl(), $title, $body, $this->user->getId())) {
378 Tools::logm('add link ' . $url->getUrl()); 383 Tools::logm('add link ' . $url->getUrl());
379 $sequence = ''; 384 $sequence = '';
@@ -386,6 +391,20 @@ class Poche
386 Tools::logm('updating content article'); 391 Tools::logm('updating content article');
387 $this->store->updateContent($last_id, $content, $this->user->getId()); 392 $this->store->updateContent($last_id, $content, $this->user->getId());
388 } 393 }
394
395 if ($duplicate != NULL) {
396 // 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
397 Tools::logm('link ' . $url->getUrl() . ' is a duplicate');
398 // 1) - preserve tags and favorite, then drop old entry
399 $this->store->reassignTags($duplicate['id'], $last_id);
400 if ($duplicate['is_fav']) {
401 $this->store->favoriteById($last_id, $this->user->getId());
402 }
403 if ($this->store->deleteById($duplicate['id'], $this->user->getId())) {
404 Tools::logm('previous link ' . $url->getUrl() .' entry deleted');
405 }
406 }
407
389 if (!$import) { 408 if (!$import) {
390 $this->messages->add('s', _('the link has been added successfully')); 409 $this->messages->add('s', _('the link has been added successfully'));
391 } 410 }
@@ -444,6 +463,12 @@ class Poche
444 case 'add_tag' : 463 case 'add_tag' :
445 $tags = explode(',', $_POST['value']); 464 $tags = explode(',', $_POST['value']);
446 $entry_id = $_POST['entry_id']; 465 $entry_id = $_POST['entry_id'];
466 $entry = $this->store->retrieveOneById($entry_id, $this->user->getId());
467 if (!$entry) {
468 $this->messages->add('e', _('Article not found!'));
469 Tools::logm('error : article not found');
470 Tools::redirect();
471 }
447 foreach($tags as $key => $tag_value) { 472 foreach($tags as $key => $tag_value) {
448 $value = trim($tag_value); 473 $value = trim($tag_value);
449 $tag = $this->store->retrieveTagByValue($value); 474 $tag = $this->store->retrieveTagByValue($value);
@@ -468,6 +493,12 @@ class Poche
468 break; 493 break;
469 case 'remove_tag' : 494 case 'remove_tag' :
470 $tag_id = $_GET['tag_id']; 495 $tag_id = $_GET['tag_id'];
496 $entry = $this->store->retrieveOneById($id, $this->user->getId());
497 if (!$entry) {
498 $this->messages->add('e', _('Article not found!'));
499 Tools::logm('error : article not found');
500 Tools::redirect();
501 }
471 $this->store->removeTagForEntry($id, $tag_id); 502 $this->store->removeTagForEntry($id, $tag_id);
472 Tools::redirect(); 503 Tools::redirect();
473 break; 504 break;
@@ -506,6 +537,12 @@ class Poche
506 break; 537 break;
507 case 'edit-tags': 538 case 'edit-tags':
508 # tags 539 # tags
540 $entry = $this->store->retrieveOneById($id, $this->user->getId());
541 if (!$entry) {
542 $this->messages->add('e', _('Article not found!'));
543 Tools::logm('error : article not found');
544 Tools::redirect();
545 }
509 $tags = $this->store->retrieveTagsByEntry($id); 546 $tags = $this->store->retrieveTagsByEntry($id);
510 $tpl_vars = array( 547 $tpl_vars = array(
511 'entry_id' => $id, 548 'entry_id' => $id,
@@ -513,8 +550,8 @@ class Poche
513 ); 550 );
514 break; 551 break;
515 case 'tag': 552 case 'tag':
516 $entries = $this->store->retrieveEntriesByTag($id); 553 $entries = $this->store->retrieveEntriesByTag($id, $this->user->getId());
517 $tag = $this->store->retrieveTag($id); 554 $tag = $this->store->retrieveTag($id, $this->user->getId());
518 $tpl_vars = array( 555 $tpl_vars = array(
519 'tag' => $tag, 556 'tag' => $tag,
520 'entries' => $entries, 557 'entries' => $entries,
@@ -522,7 +559,7 @@ class Poche
522 break; 559 break;
523 case 'tags': 560 case 'tags':
524 $token = $this->user->getConfigValue('token'); 561 $token = $this->user->getConfigValue('token');
525 $tags = $this->store->retrieveAllTags(); 562 $tags = $this->store->retrieveAllTags($this->user->getId());
526 $tpl_vars = array( 563 $tpl_vars = array(
527 'token' => $token, 564 'token' => $token,
528 'user_id' => $this->user->getId(), 565 'user_id' => $this->user->getId(),
@@ -1037,7 +1074,7 @@ class Poche
1037 $feed->setChannelElement('author', 'wallabag'); 1074 $feed->setChannelElement('author', 'wallabag');
1038 1075
1039 if ($type == 'tag') { 1076 if ($type == 'tag') {
1040 $entries = $this->store->retrieveEntriesByTag($tag_id); 1077 $entries = $this->store->retrieveEntriesByTag($tag_id, $user_id);
1041 } 1078 }
1042 else { 1079 else {
1043 $entries = $this->store->getEntriesByView($type, $user_id); 1080 $entries = $this->store->getEntriesByView($type, $user_id);
@@ -1057,4 +1094,20 @@ class Poche
1057 $feed->genarateFeed(); 1094 $feed->genarateFeed();
1058 exit; 1095 exit;
1059 } 1096 }
1097
1098 public function emptyCache() {
1099 $files = new RecursiveIteratorIterator(
1100 new RecursiveDirectoryIterator(CACHE, RecursiveDirectoryIterator::SKIP_DOTS),
1101 RecursiveIteratorIterator::CHILD_FIRST
1102 );
1103
1104 foreach ($files as $fileinfo) {
1105 $todo = ($fileinfo->isDir() ? 'rmdir' : 'unlink');
1106 $todo($fileinfo->getRealPath());
1107 }
1108
1109 Tools::logm('empty cache');
1110 $this->messages->add('s', _('Cache deleted.'));
1111 Tools::redirect();
1112 }
1060} 1113}