setUrl() public method

Set url.
public setUrl ( string $url ) : Entry
$url string
return Entry
コード例 #1
0
ファイル: WallabagImport.php プロジェクト: wallabag/wallabag
 /**
  * {@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;
 }
コード例 #2
0
ファイル: EntryController.php プロジェクト: jjanvier/wallabag
 /**
  * @param Request $request
  *
  * @Route("/bookmarklet", name="bookmarklet")
  *
  * @return \Symfony\Component\HttpFoundation\Response
  */
 public function addEntryViaBookmarkletAction(Request $request)
 {
     $entry = new Entry($this->getUser());
     $entry->setUrl($request->get('url'));
     if (false === $this->checkIfEntryAlreadyExists($entry)) {
         $this->updateEntry($entry);
     }
     return $this->redirect($this->generateUrl('homepage'));
 }
コード例 #3
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;
 }
コード例 #4
0
ファイル: ContentProxy.php プロジェクト: wallabag/wallabag
 /**
  * Fetch content using graby and hydrate given entry with results information.
  * In case we couldn't find content, we'll try to use Open Graph data.
  *
  * We can also force the content, in case of an import from the v1 for example, so the function won't
  * fetch the content from the website but rather use information given with the $content parameter.
  *
  * @param Entry  $entry   Entry to update
  * @param string $url     Url to grab content for
  * @param array  $content An array with AT LEAST keys title, html, url, language & content_type to skip the fetchContent from the url
  *
  * @return Entry
  */
 public function updateEntry(Entry $entry, $url, array $content = [])
 {
     // do we have to fetch the content or the provided one is ok?
     if (empty($content) || false === $this->validateContent($content)) {
         $content = $this->graby->fetchContent($url);
     }
     $title = $content['title'];
     if (!$title && isset($content['open_graph']['og_title'])) {
         $title = $content['open_graph']['og_title'];
     }
     $html = $content['html'];
     if (false === $html) {
         $html = '<p>Unable to retrieve readable content.</p>';
         if (isset($content['open_graph']['og_description'])) {
             $html .= '<p><i>But we found a short description: </i></p>';
             $html .= $content['open_graph']['og_description'];
         }
     }
     $entry->setUrl($content['url'] ?: $url);
     $entry->setTitle($title);
     $entry->setContent($html);
     $entry->setLanguage($content['language']);
     $entry->setMimetype($content['content_type']);
     $entry->setReadingTime(Utils::getReadingTime($html));
     $domainName = parse_url($entry->getUrl(), PHP_URL_HOST);
     if (false !== $domainName) {
         $entry->setDomainName($domainName);
     }
     if (isset($content['open_graph']['og_image'])) {
         $entry->setPreviewPicture($content['open_graph']['og_image']);
     }
     // if content is an image define as a preview too
     if (in_array($this->mimeGuesser->guess($content['content_type']), ['jpeg', 'jpg', 'gif', 'png'], true)) {
         $entry->setPreviewPicture($content['url']);
     }
     try {
         $this->tagger->tag($entry);
     } catch (\Exception $e) {
         $this->logger->error('Error while trying to automatically tag an entry.', ['entry_url' => $url, 'error_msg' => $e->getMessage()]);
     }
     return $entry;
 }
コード例 #5
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;
 }
コード例 #6
0
ファイル: LoadEntryData.php プロジェクト: jjanvier/wallabag
 /**
  * {@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();
 }
コード例 #7
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());
 }
コード例 #8
0
ファイル: PocketImport.php プロジェクト: wallabag/wallabag
 /**
  * {@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;
 }
コード例 #9
0
ファイル: BrowserImport.php プロジェクト: nicofrand/wallabag
 /**
  * {@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;
 }