}
}
+ if (empty($entry->getDomainName())) {
+ $this->get('wallabag_core.content_proxy')->setEntryDomainName($entry);
+ }
+
+ if (empty($entry->getTitle())) {
+ $this->get('wallabag_core.content_proxy')->setDefaultEntryTitle($entry);
+ }
+
$em = $this->getDoctrine()->getManager();
$em->persist($entry);
$em->flush();
$entry->setOriginUrl($data['origin_url']);
}
+ if (empty($entry->getDomainName())) {
+ $this->get('wallabag_core.content_proxy')->setEntryDomainName($entry);
+ }
+
+ if (empty($entry->getTitle())) {
+ $this->get('wallabag_core.content_proxy')->setDefaultEntryTitle($entry);
+ }
+
$em = $this->getDoctrine()->getManager();
$em->persist($entry);
$em->flush();
$message = 'flashes.entry.notice.' . $prefixMessage . '_failed';
}
+ if (empty($entry->getDomainName())) {
+ $this->get('wallabag_core.content_proxy')->setEntryDomainName($entry);
+ }
+
+ if (empty($entry->getTitle())) {
+ $this->get('wallabag_core.content_proxy')->setDefaultEntryTitle($entry);
+ }
+
$this->get('session')->getFlashBag()->add('notice', $message);
}
}
}
+ /**
+ * Helper to extract and save host from entry url.
+ *
+ * @param Entry $entry
+ */
+ public function setEntryDomainName(Entry $entry)
+ {
+ $domainName = parse_url($entry->getUrl(), PHP_URL_HOST);
+ if (false !== $domainName) {
+ $entry->setDomainName($domainName);
+ }
+ }
+
+ /**
+ * Helper to set a default title using:
+ * - url basename, if applicable
+ * - hostname.
+ *
+ * @param Entry $entry
+ */
+ public function setDefaultEntryTitle(Entry $entry)
+ {
+ $url = parse_url($entry->getUrl());
+ $path = pathinfo($url['path'], PATHINFO_BASENAME);
+
+ if (empty($path)) {
+ $path = $url['host'];
+ }
+
+ $entry->setTitle($path);
+ }
+
/**
* Stock entry with fetched or imported content.
* Will fall back to OpenGraph data if available.
{
$entry->setUrl($content['url']);
- $domainName = parse_url($entry->getUrl(), PHP_URL_HOST);
- if (false !== $domainName) {
- $entry->setDomainName($domainName);
- }
+ $this->setEntryDomainName($entry);
if (!empty($content['title'])) {
$entry->setTitle($content['title']);
$content = json_decode($this->client->getResponse()->getContent(), true);
$this->assertGreaterThan(0, $content['id']);
$this->assertSame('http://www.example.com/', $content['url']);
+ $this->assertSame('www.example.com', $content['domain_name']);
+ $this->assertSame('www.example.com', $content['title']);
} finally {
// Remove the created entry to avoid side effects on other tests
if (isset($content['id'])) {