Example #1
0
 /**
  * {@inheritdoc}
  */
 public function parseEntry(array $importedEntry)
 {
     $existingEntry = $this->em->getRepository('WallabagCoreBundle:Entry')->findByUrlAndUserId($importedEntry['url'], $this->user->getId());
     if (false !== $existingEntry) {
         ++$this->skippedEntries;
         return;
     }
     $data = $this->prepareEntry($importedEntry);
     $entry = new Entry($this->user);
     $entry->setUrl($data['url']);
     $entry->setTitle($data['title']);
     // update entry with content (in case fetching failed, the given entry will be return)
     $entry = $this->fetchContent($entry, $data['url'], $data);
     if (array_key_exists('tags', $data)) {
         $this->contentProxy->assignTagsToEntry($entry, $data['tags'], $this->em->getUnitOfWork()->getScheduledEntityInsertions());
     }
     if (isset($importedEntry['preview_picture'])) {
         $entry->setPreviewPicture($importedEntry['preview_picture']);
     }
     $entry->setArchived($data['is_archived']);
     $entry->setStarred($data['is_starred']);
     if (!empty($data['created_at'])) {
         $entry->setCreatedAt(new \DateTime($data['created_at']));
     }
     $this->em->persist($entry);
     ++$this->importedEntries;
     return $entry;
 }
 /**
  * Retrieve annotations for an entry.
  *
  * @ApiDoc(
  *      requirements={
  *          {"name"="entry", "dataType"="integer", "requirement"="\w+", "description"="The entry ID"}
  *      }
  * )
  *
  * @return Response
  */
 public function getAnnotationsAction(Entry $entry)
 {
     $annotationRows = $this->getDoctrine()->getRepository('WallabagAnnotationBundle:Annotation')->findAnnotationsByPageId($entry->getId(), $this->getUser()->getId());
     $total = count($annotationRows);
     $annotations = ['total' => $total, 'rows' => $annotationRows];
     $json = $this->get('serializer')->serialize($annotations, 'json');
     return $this->renderJsonResponse($json);
 }
Example #3
0
 /**
  * Removes tag from entry.
  *
  * @Route("/remove-tag/{entry}/{tag}", requirements={"entry" = "\d+", "tag" = "\d+"}, name="remove_tag")
  *
  * @return \Symfony\Component\HttpFoundation\Response
  */
 public function removeTagFromEntry(Request $request, Entry $entry, Tag $tag)
 {
     $entry->removeTag($tag);
     $em = $this->getDoctrine()->getManager();
     $em->flush();
     if (count($tag->getEntries()) == 0) {
         $em->remove($tag);
     }
     $em->flush();
     $redirectUrl = $this->get('wallabag_core.helper.redirect')->to($request->headers->get('referer'));
     return $this->redirect($redirectUrl);
 }
Example #4
0
 /**
  * Add tags from rules defined by the user.
  *
  * @param Entry $entry Entry to tag
  */
 public function tag(Entry $entry)
 {
     $rules = $this->getRulesForUser($entry->getUser());
     foreach ($rules as $rule) {
         if (!$this->rulerz->satisfies($entry, $rule->getRule())) {
             continue;
         }
         foreach ($rule->getTags() as $label) {
             $tag = $this->getTag($label);
             $entry->addTag($tag);
         }
     }
 }
Example #5
0
 /**
  * {@inheritdoc}
  */
 public function parseEntry(array $importedEntry)
 {
     $existingEntry = $this->em->getRepository('WallabagCoreBundle:Entry')->findByUrlAndUserId($importedEntry['url'], $this->user->getId());
     if (false !== $existingEntry) {
         ++$this->skippedEntries;
         return;
     }
     $entry = new Entry($this->user);
     $entry->setUrl($importedEntry['url']);
     $entry->setTitle($importedEntry['title']);
     // update entry with content (in case fetching failed, the given entry will be return)
     $entry = $this->fetchContent($entry, $importedEntry['url'], $importedEntry);
     $entry->setArchived($importedEntry['is_archived']);
     $entry->setStarred($importedEntry['is_starred']);
     $this->em->persist($entry);
     ++$this->importedEntries;
     return $entry;
 }
Example #6
0
 /**
  * {@inheritdoc}
  */
 public function parseEntry(array $importedEntry)
 {
     $existingEntry = $this->em->getRepository('WallabagCoreBundle:Entry')->findByUrlAndUserId($importedEntry['article__url'], $this->user->getId());
     if (false !== $existingEntry) {
         ++$this->skippedEntries;
         return;
     }
     $data = ['title' => $importedEntry['article__title'], 'url' => $importedEntry['article__url'], 'content_type' => '', 'language' => '', 'is_archived' => $importedEntry['archive'] || $this->markAsRead, 'is_starred' => $importedEntry['favorite'], 'created_at' => $importedEntry['date_added']];
     $entry = new Entry($this->user);
     $entry->setUrl($data['url']);
     $entry->setTitle($data['title']);
     // update entry with content (in case fetching failed, the given entry will be return)
     $entry = $this->fetchContent($entry, $data['url'], $data);
     $entry->setArchived($data['is_archived']);
     $entry->setStarred($data['is_starred']);
     $entry->setCreatedAt(new \DateTime($data['created_at']));
     $this->em->persist($entry);
     ++$this->importedEntries;
     return $entry;
 }
Example #7
0
 /**
  * Assign some tags to an entry.
  *
  * @param Entry        $entry
  * @param array|string $tags  An array of tag or a string coma separated of tag
  */
 public function assignTagsToEntry(Entry $entry, $tags)
 {
     if (!is_array($tags)) {
         $tags = explode(',', $tags);
     }
     foreach ($tags as $label) {
         $label = trim($label);
         // avoid empty tag
         if (0 === strlen($label)) {
             continue;
         }
         $tagEntity = $this->tagRepository->findOneByLabel($label);
         if (is_null($tagEntity)) {
             $tagEntity = new Tag();
             $tagEntity->setLabel($label);
         }
         // only add the tag on the entry if the relation doesn't exist
         if (false === $entry->getTags()->contains($tagEntity)) {
             $entry->addTag($tagEntity);
         }
     }
 }
Example #8
0
 /**
  * Assign some tags to an entry.
  *
  * @param Entry        $entry
  * @param array|string $tags          An array of tag or a string coma separated of tag
  * @param array        $entitiesReady Entities from the EntityManager which are persisted but not yet flushed
  *                                    It is mostly to fix duplicate tag on import @see http://stackoverflow.com/a/7879164/569101
  */
 public function assignTagsToEntry(Entry $entry, $tags, array $entitiesReady = [])
 {
     if (!is_array($tags)) {
         $tags = explode(',', $tags);
     }
     // keeps only Tag entity from the "not yet flushed entities"
     $tagsNotYetFlushed = [];
     foreach ($entitiesReady as $entity) {
         if ($entity instanceof Tag) {
             $tagsNotYetFlushed[$entity->getLabel()] = $entity;
         }
     }
     foreach ($tags as $label) {
         $label = trim($label);
         // avoid empty tag
         if (0 === strlen($label)) {
             continue;
         }
         if (isset($tagsNotYetFlushed[$label])) {
             $tagEntity = $tagsNotYetFlushed[$label];
         } else {
             $tagEntity = $this->tagRepository->findOneByLabel($label);
             if (is_null($tagEntity)) {
                 $tagEntity = new Tag();
                 $tagEntity->setLabel($label);
             }
         }
         // only add the tag on the entry if the relation doesn't exist
         if (false === $entry->getTags()->contains($tagEntity)) {
             $entry->addTag($tagEntity);
         }
     }
 }
 /**
  * Permanently remove one tag for an entry.
  *
  * @ApiDoc(
  *      requirements={
  *          {"name"="tag", "dataType"="integer", "requirement"="\w+", "description"="The tag ID"},
  *          {"name"="entry", "dataType"="integer", "requirement"="\w+", "description"="The entry ID"}
  *      }
  * )
  *
  * @return JsonResponse
  */
 public function deleteEntriesTagsAction(Entry $entry, Tag $tag)
 {
     $this->validateAuthentication();
     $this->validateUserAccess($entry->getUser()->getId());
     $entry->removeTag($tag);
     $em = $this->getDoctrine()->getManager();
     $em->persist($entry);
     $em->flush();
     $json = $this->get('serializer')->serialize($entry, 'json');
     return (new JsonResponse())->setJson($json);
 }
Example #10
0
 public function testAssignTagsAlreadyAssigned()
 {
     $graby = $this->getMockBuilder('Graby\\Graby')->disableOriginalConstructor()->getMock();
     $tagRepo = $this->getTagRepositoryMock();
     $proxy = new ContentProxy($graby, $this->getTaggerMock(), $tagRepo, $this->getLogger());
     $tagEntity = new Tag();
     $tagEntity->setLabel('tag1');
     $entry = new Entry(new User());
     $entry->addTag($tagEntity);
     $proxy->assignTagsToEntry($entry, 'tag1, tag2');
     $this->assertCount(2, $entry->getTags());
     $this->assertEquals('tag1', $entry->getTags()[0]->getLabel());
     $this->assertEquals('tag2', $entry->getTags()[1]->getLabel());
 }
Example #11
0
 /**
  * Check for existing entry, if it exists, redirect to it with a message.
  *
  * @param Entry $entry
  *
  * @return Entry|bool
  */
 private function checkIfEntryAlreadyExists(Entry $entry)
 {
     return $this->get('wallabag_core.entry_repository')->findByUrlAndUserId($entry->getUrl(), $this->getUser()->getId());
 }
Example #12
0
 /**
  * {@inheritdoc}
  */
 public function load(ObjectManager $manager)
 {
     $entry1 = new Entry($this->getReference('admin-user'));
     $entry1->setUrl('http://0.0.0.0/entry1');
     $entry1->setReadingTime(11);
     $entry1->setDomainName('domain.io');
     $entry1->setMimetype('text/html');
     $entry1->setTitle('test title entry1');
     $entry1->setContent('This is my content /o/');
     $entry1->setLanguage('en');
     $manager->persist($entry1);
     $this->addReference('entry1', $entry1);
     $entry2 = new Entry($this->getReference('admin-user'));
     $entry2->setUrl('http://0.0.0.0/entry2');
     $entry2->setReadingTime(1);
     $entry2->setDomainName('domain.io');
     $entry2->setMimetype('text/html');
     $entry2->setTitle('test title entry2');
     $entry2->setContent('This is my content /o/');
     $entry2->setLanguage('fr');
     $manager->persist($entry2);
     $this->addReference('entry2', $entry2);
     $entry3 = new Entry($this->getReference('bob-user'));
     $entry3->setUrl('http://0.0.0.0/entry3');
     $entry3->setReadingTime(1);
     $entry3->setDomainName('domain.io');
     $entry3->setMimetype('text/html');
     $entry3->setTitle('test title entry3');
     $entry3->setContent('This is my content /o/');
     $entry3->setLanguage('en');
     $entry3->addTag($this->getReference('foo-tag'));
     $entry3->addTag($this->getReference('bar-tag'));
     $manager->persist($entry3);
     $this->addReference('entry3', $entry3);
     $entry4 = new Entry($this->getReference('admin-user'));
     $entry4->setUrl('http://0.0.0.0/entry4');
     $entry4->setReadingTime(12);
     $entry4->setDomainName('domain.io');
     $entry4->setMimetype('text/html');
     $entry4->setTitle('test title entry4');
     $entry4->setContent('This is my content /o/');
     $entry4->setLanguage('en');
     $entry4->addTag($this->getReference('foo-tag'));
     $entry4->addTag($this->getReference('bar-tag'));
     $manager->persist($entry4);
     $this->addReference('entry4', $entry4);
     $entry5 = new Entry($this->getReference('admin-user'));
     $entry5->setUrl('http://0.0.0.0/entry5');
     $entry5->setReadingTime(12);
     $entry5->setDomainName('domain.io');
     $entry5->setMimetype('text/html');
     $entry5->setTitle('test title entry5');
     $entry5->setContent('This is my content /o/');
     $entry5->setStarred(true);
     $entry5->setLanguage('fr');
     $entry5->setPreviewPicture('http://0.0.0.0/image.jpg');
     $manager->persist($entry5);
     $this->addReference('entry5', $entry5);
     $entry6 = new Entry($this->getReference('admin-user'));
     $entry6->setUrl('http://0.0.0.0/entry6');
     $entry6->setReadingTime(12);
     $entry6->setDomainName('domain.io');
     $entry6->setMimetype('text/html');
     $entry6->setTitle('test title entry6');
     $entry6->setContent('This is my content /o/');
     $entry6->setArchived(true);
     $entry6->setLanguage('de');
     $manager->persist($entry6);
     $this->addReference('entry6', $entry6);
     $manager->flush();
 }
Example #13
0
 /**
  * It will create a new entry.
  * Browse to it.
  * Then remove it.
  *
  * And it'll check that user won't be redirected to the view page of the content when it had been removed
  */
 public function testViewAndDelete()
 {
     $this->logInAs('admin');
     $client = $this->getClient();
     $em = $client->getContainer()->get('doctrine.orm.entity_manager');
     // add a new content to be removed later
     $user = $em->getRepository('WallabagUserBundle:User')->findOneByUserName('admin');
     $content = new Entry($user);
     $content->setUrl('http://1.1.1.1/entry');
     $content->setReadingTime(12);
     $content->setDomainName('domain.io');
     $content->setMimetype('text/html');
     $content->setTitle('test title entry');
     $content->setContent('This is my content /o/');
     $content->setArchived(true);
     $content->setLanguage('fr');
     $em->persist($content);
     $em->flush();
     $client->request('GET', '/view/' . $content->getId());
     $this->assertEquals(200, $client->getResponse()->getStatusCode());
     $client->request('GET', '/delete/' . $content->getId());
     $this->assertEquals(302, $client->getResponse()->getStatusCode());
     $client->followRedirect();
     $this->assertEquals(200, $client->getResponse()->getStatusCode());
 }
Example #14
0
 /**
  * {@inheritdoc}
  *
  * @see https://getpocket.com/developer/docs/v3/retrieve
  */
 public function parseEntry(array $importedEntry)
 {
     $url = isset($importedEntry['resolved_url']) && $importedEntry['resolved_url'] != '' ? $importedEntry['resolved_url'] : $importedEntry['given_url'];
     $existingEntry = $this->em->getRepository('WallabagCoreBundle:Entry')->findByUrlAndUserId($url, $this->user->getId());
     if (false !== $existingEntry) {
         ++$this->skippedEntries;
         return;
     }
     $entry = new Entry($this->user);
     $entry->setUrl($url);
     // update entry with content (in case fetching failed, the given entry will be return)
     $entry = $this->fetchContent($entry, $url);
     // 0, 1, 2 - 1 if the item is archived - 2 if the item should be deleted
     $entry->setArchived($importedEntry['status'] == 1 || $this->markAsRead);
     // 0 or 1 - 1 If the item is starred
     $entry->setStarred($importedEntry['favorite'] == 1);
     $title = 'Untitled';
     if (isset($importedEntry['resolved_title']) && $importedEntry['resolved_title'] != '') {
         $title = $importedEntry['resolved_title'];
     } elseif (isset($importedEntry['given_title']) && $importedEntry['given_title'] != '') {
         $title = $importedEntry['given_title'];
     }
     $entry->setTitle($title);
     // 0, 1, or 2 - 1 if the item has images in it - 2 if the item is an image
     if (isset($importedEntry['has_image']) && $importedEntry['has_image'] > 0 && isset($importedEntry['images'][1])) {
         $entry->setPreviewPicture($importedEntry['images'][1]['src']);
     }
     if (isset($importedEntry['tags']) && !empty($importedEntry['tags'])) {
         $this->contentProxy->assignTagsToEntry($entry, array_keys($importedEntry['tags']), $this->em->getUnitOfWork()->getScheduledEntityInsertions());
     }
     if (!empty($importedEntry['time_added'])) {
         $entry->setCreatedAt((new \DateTime())->setTimestamp($importedEntry['time_added']));
     }
     $this->em->persist($entry);
     ++$this->importedEntries;
     return $entry;
 }
Example #15
0
 /**
  * Set entry.
  *
  * @param Entry $entry
  *
  * @return Annotation
  */
 public function setEntry($entry)
 {
     $this->entry = $entry;
     $entry->setAnnotation($this);
     return $this;
 }
Example #16
0
 /**
  * {@inheritdoc}
  */
 public function parseEntry(array $importedEntry)
 {
     if ((!array_key_exists('guid', $importedEntry) || !array_key_exists('id', $importedEntry)) && is_array(reset($importedEntry))) {
         $this->parseEntries($importedEntry);
         return;
     }
     if (array_key_exists('children', $importedEntry)) {
         $this->parseEntries($importedEntry['children']);
         return;
     }
     if (!array_key_exists('uri', $importedEntry) && !array_key_exists('url', $importedEntry)) {
         return;
     }
     $url = array_key_exists('uri', $importedEntry) ? $importedEntry['uri'] : $importedEntry['url'];
     $existingEntry = $this->em->getRepository('WallabagCoreBundle:Entry')->findByUrlAndUserId($url, $this->user->getId());
     if (false !== $existingEntry) {
         ++$this->skippedEntries;
         return;
     }
     $data = $this->prepareEntry($importedEntry);
     $entry = new Entry($this->user);
     $entry->setUrl($data['url']);
     $entry->setTitle($data['title']);
     // update entry with content (in case fetching failed, the given entry will be return)
     $entry = $this->fetchContent($entry, $data['url'], $data);
     if (array_key_exists('tags', $data)) {
         $this->contentProxy->assignTagsToEntry($entry, $data['tags']);
     }
     $entry->setArchived($data['is_archived']);
     if (!empty($data['created_at'])) {
         $dt = new \DateTime();
         $entry->setCreatedAt($dt->setTimestamp($data['created_at']));
     }
     $this->em->persist($entry);
     ++$this->importedEntries;
     return $entry;
 }