From e0ef1a1c8b6badd2f52acbdcf928469ef1a15b3e Mon Sep 17 00:00:00 2001 From: Kevin Decherf Date: Mon, 4 Sep 2017 23:39:08 +0200 Subject: [PATCH 01/13] Add originUrl property to Entry, handle that in EntryRestController, handle migration Signed-off-by: Kevin Decherf --- .../Version20171105202000.php | 55 +++++++++++++++++++ .../Controller/EntryRestController.php | 11 ++++ src/Wallabag/CoreBundle/Entity/Entry.php | 33 +++++++++++ 3 files changed, 99 insertions(+) create mode 100644 app/DoctrineMigrations/Version20171105202000.php diff --git a/app/DoctrineMigrations/Version20171105202000.php b/app/DoctrineMigrations/Version20171105202000.php new file mode 100644 index 000000000..b1cff9cea --- /dev/null +++ b/app/DoctrineMigrations/Version20171105202000.php @@ -0,0 +1,55 @@ +container = $container; + } + + /** + * @param Schema $schema + */ + public function up(Schema $schema) + { + $entryTable = $schema->getTable($this->getTable('entry')); + + $this->skipIf($entryTable->hasColumn('origin_url'), 'It seems that you already played this migration.'); + + $entryTable->addColumn('origin_url', 'text', [ + 'notnull' => false, + ]); + } + + /** + * @param Schema $schema + */ + public function down(Schema $schema) + { + $entryTable = $schema->getTable($this->getTable('entry')); + + $this->skipIf(!$entryTable->hasColumn('origin_url'), 'It seems that you already played this migration.'); + + $entryTable->dropColumn('origin_url'); + } + + private function getTable($tableName) + { + return $this->container->getParameter('database_table_prefix') . $tableName; + } +} diff --git a/src/Wallabag/ApiBundle/Controller/EntryRestController.php b/src/Wallabag/ApiBundle/Controller/EntryRestController.php index 6f161a081..5a9afc698 100644 --- a/src/Wallabag/ApiBundle/Controller/EntryRestController.php +++ b/src/Wallabag/ApiBundle/Controller/EntryRestController.php @@ -309,6 +309,7 @@ class EntryRestController extends WallabagRestController * {"name"="published_at", "dataType"="datetime|integer", "format"="YYYY-MM-DDTHH:II:SS+TZ or a timestamp", "required"=false, "description"="Published date of the entry"}, * {"name"="authors", "dataType"="string", "format"="Name Firstname,author2,author3", "required"=false, "description"="Authors of the entry"}, * {"name"="public", "dataType"="integer", "required"=false, "format"="1 or 0", "description"="will generate a public link for the entry"}, + * {"name"="origin_url", "dataType"="string", "required"=false, "format"="http://www.test.com/article.html", "description"="Origin url for the entry."}, * } * ) * @@ -368,6 +369,10 @@ class EntryRestController extends WallabagRestController $this->get('wallabag_core.tags_assigner')->assignTagsToEntry($entry, $data['tags']); } + if (!empty($data['origin_url'])) { + $entry->setOriginUrl($data['origin_url']); + } + if (null !== $data['isPublic']) { if (true === (bool) $data['isPublic'] && null === $entry->getUid()) { $entry->generateUid(); @@ -404,6 +409,7 @@ class EntryRestController extends WallabagRestController * {"name"="published_at", "dataType"="datetime|integer", "format"="YYYY-MM-DDTHH:II:SS+TZ or a timestamp", "required"=false, "description"="Published date of the entry"}, * {"name"="authors", "dataType"="string", "format"="Name Firstname,author2,author3", "required"=false, "description"="Authors of the entry"}, * {"name"="public", "dataType"="integer", "required"=false, "format"="1 or 0", "description"="will generate a public link for the entry"}, + * {"name"="origin_url", "dataType"="string", "required"=false, "format"="http://www.test.com/article.html", "description"="Origin url for the entry."}, * } * ) * @@ -480,6 +486,10 @@ class EntryRestController extends WallabagRestController } } + if (!empty($data['origin_url'])) { + $entry->setOriginUrl($data['origin_url']); + } + $em = $this->getDoctrine()->getManager(); $em->persist($entry); $em->flush(); @@ -778,6 +788,7 @@ class EntryRestController extends WallabagRestController 'picture' => $request->request->get('preview_picture'), 'publishedAt' => $request->request->get('published_at'), 'authors' => $request->request->get('authors', ''), + 'origin_url' => $request->request->get('origin_url', ''), ]; } diff --git a/src/Wallabag/CoreBundle/Entity/Entry.php b/src/Wallabag/CoreBundle/Entity/Entry.php index cfb8db752..445cc45e5 100644 --- a/src/Wallabag/CoreBundle/Entity/Entry.php +++ b/src/Wallabag/CoreBundle/Entity/Entry.php @@ -245,6 +245,15 @@ class Entry */ private $tags; + /** + * @var string + * + * @ORM\Column(name="origin_url", type="text", nullable=true) + * + * @Groups({"entries_for_user", "export_all"}) + */ + private $originUrl; + /* * @param User $user */ @@ -831,4 +840,28 @@ class Entry return $this; } + + /** + * Set origin url. + * + * @param string $originUrl + * + * @return Entry + */ + public function setOriginUrl($originUrl) + { + $this->originUrl = $originUrl; + + return $this; + } + + /** + * Get origin url. + * + * @return string + */ + public function getOriginUrl() + { + return $this->originUrl; + } } From 03b020eb205a052b3a09f94e316c3b6b48607103 Mon Sep 17 00:00:00 2001 From: Kevin Decherf Date: Sat, 9 Sep 2017 19:32:42 +0200 Subject: [PATCH 02/13] Entry: handle originUrl in edit form, update translations Signed-off-by: Kevin Decherf --- src/Wallabag/CoreBundle/Form/Type/EditEntryType.php | 5 +++++ .../CoreBundle/Resources/translations/messages.da.yml | 1 + .../CoreBundle/Resources/translations/messages.de.yml | 1 + .../CoreBundle/Resources/translations/messages.en.yml | 1 + .../CoreBundle/Resources/translations/messages.es.yml | 1 + .../CoreBundle/Resources/translations/messages.fa.yml | 1 + .../CoreBundle/Resources/translations/messages.fr.yml | 1 + .../CoreBundle/Resources/translations/messages.it.yml | 1 + .../CoreBundle/Resources/translations/messages.oc.yml | 1 + .../CoreBundle/Resources/translations/messages.pl.yml | 1 + .../CoreBundle/Resources/translations/messages.pt.yml | 1 + .../CoreBundle/Resources/translations/messages.ro.yml | 1 + .../CoreBundle/Resources/translations/messages.tr.yml | 1 + .../Resources/views/themes/material/Entry/edit.html.twig | 5 +++++ 14 files changed, 22 insertions(+) diff --git a/src/Wallabag/CoreBundle/Form/Type/EditEntryType.php b/src/Wallabag/CoreBundle/Form/Type/EditEntryType.php index 1627cc445..4bceaf5f9 100644 --- a/src/Wallabag/CoreBundle/Form/Type/EditEntryType.php +++ b/src/Wallabag/CoreBundle/Form/Type/EditEntryType.php @@ -22,6 +22,11 @@ class EditEntryType extends AbstractType 'required' => false, 'label' => 'entry.edit.url_label', ]) + ->add('origin_url', TextType::class, [ + 'required' => false, + 'property_path' => 'originUrl', + 'label' => 'entry.edit.origin_url_label', + ]) ->add('save', SubmitType::class, [ 'label' => 'entry.edit.save_label', ]) diff --git a/src/Wallabag/CoreBundle/Resources/translations/messages.da.yml b/src/Wallabag/CoreBundle/Resources/translations/messages.da.yml index d0a38f7e3..8fa5965eb 100644 --- a/src/Wallabag/CoreBundle/Resources/translations/messages.da.yml +++ b/src/Wallabag/CoreBundle/Resources/translations/messages.da.yml @@ -244,6 +244,7 @@ entry: # page_title: 'Edit an entry' # title_label: 'Title' url_label: 'Url' + # origin_url_label: 'Origin url' save_label: 'Gem' public: # shared_by_wallabag: "This article has been shared by %username% with wallabag" diff --git a/src/Wallabag/CoreBundle/Resources/translations/messages.de.yml b/src/Wallabag/CoreBundle/Resources/translations/messages.de.yml index 158762a97..3bb10d516 100644 --- a/src/Wallabag/CoreBundle/Resources/translations/messages.de.yml +++ b/src/Wallabag/CoreBundle/Resources/translations/messages.de.yml @@ -244,6 +244,7 @@ entry: page_title: 'Eintrag bearbeiten' title_label: 'Titel' url_label: 'URL' + # origin_url_label: 'Origin url' save_label: 'Speichern' public: shared_by_wallabag: 'Dieser Artikel wurde von %username% mittels wallabag geteilt' diff --git a/src/Wallabag/CoreBundle/Resources/translations/messages.en.yml b/src/Wallabag/CoreBundle/Resources/translations/messages.en.yml index de3e11fe2..9da36e242 100644 --- a/src/Wallabag/CoreBundle/Resources/translations/messages.en.yml +++ b/src/Wallabag/CoreBundle/Resources/translations/messages.en.yml @@ -244,6 +244,7 @@ entry: page_title: 'Edit an entry' title_label: 'Title' url_label: 'Url' + origin_url_label: 'Origin url' save_label: 'Save' public: shared_by_wallabag: "This article has been shared by %username% with wallabag" diff --git a/src/Wallabag/CoreBundle/Resources/translations/messages.es.yml b/src/Wallabag/CoreBundle/Resources/translations/messages.es.yml index 6dfc1525e..37fee3c11 100644 --- a/src/Wallabag/CoreBundle/Resources/translations/messages.es.yml +++ b/src/Wallabag/CoreBundle/Resources/translations/messages.es.yml @@ -244,6 +244,7 @@ entry: page_title: 'Editar un artículo' title_label: 'Título' url_label: 'URL' + # origin_url_label: 'Origin url' save_label: 'Guardar' public: shared_by_wallabag: "Este artículo se ha compartido con wallabag" diff --git a/src/Wallabag/CoreBundle/Resources/translations/messages.fa.yml b/src/Wallabag/CoreBundle/Resources/translations/messages.fa.yml index ffc48933a..ac39aa62e 100644 --- a/src/Wallabag/CoreBundle/Resources/translations/messages.fa.yml +++ b/src/Wallabag/CoreBundle/Resources/translations/messages.fa.yml @@ -244,6 +244,7 @@ entry: page_title: 'ویرایش مقاله' title_label: 'عنوان' url_label: 'نشانی' + # origin_url_label: 'Origin url' save_label: 'ذخیره' public: # shared_by_wallabag: "This article has been shared by %username% with wallabag" diff --git a/src/Wallabag/CoreBundle/Resources/translations/messages.fr.yml b/src/Wallabag/CoreBundle/Resources/translations/messages.fr.yml index c9d95e2bc..e640f2ba0 100644 --- a/src/Wallabag/CoreBundle/Resources/translations/messages.fr.yml +++ b/src/Wallabag/CoreBundle/Resources/translations/messages.fr.yml @@ -244,6 +244,7 @@ entry: page_title: "Éditer un article" title_label: "Titre" url_label: "Adresse" + origin_url_label: "Adresse d'origine" save_label: "Enregistrer" public: shared_by_wallabag: "Cet article a été partagé par %username% avec wallabag" diff --git a/src/Wallabag/CoreBundle/Resources/translations/messages.it.yml b/src/Wallabag/CoreBundle/Resources/translations/messages.it.yml index c53266ca3..c2dad0dfd 100644 --- a/src/Wallabag/CoreBundle/Resources/translations/messages.it.yml +++ b/src/Wallabag/CoreBundle/Resources/translations/messages.it.yml @@ -244,6 +244,7 @@ entry: page_title: 'Modifica voce' title_label: 'Titolo' url_label: 'Url' + # origin_url_label: 'Origin url' save_label: 'Salva' public: shared_by_wallabag: "Questo articolo è stato condiviso da %username% con wallabag" diff --git a/src/Wallabag/CoreBundle/Resources/translations/messages.oc.yml b/src/Wallabag/CoreBundle/Resources/translations/messages.oc.yml index 3ae64c49f..72442c561 100644 --- a/src/Wallabag/CoreBundle/Resources/translations/messages.oc.yml +++ b/src/Wallabag/CoreBundle/Resources/translations/messages.oc.yml @@ -244,6 +244,7 @@ entry: page_title: 'Modificar un article' title_label: 'Títol' url_label: 'Url' + # origin_url_label: 'Origin url' save_label: 'Enregistrar' public: shared_by_wallabag: "Aqueste article es estat partejat per wallabag" diff --git a/src/Wallabag/CoreBundle/Resources/translations/messages.pl.yml b/src/Wallabag/CoreBundle/Resources/translations/messages.pl.yml index e642c5307..2e1039bd5 100644 --- a/src/Wallabag/CoreBundle/Resources/translations/messages.pl.yml +++ b/src/Wallabag/CoreBundle/Resources/translations/messages.pl.yml @@ -244,6 +244,7 @@ entry: page_title: 'Edytuj wpis' title_label: 'Tytuł' url_label: 'Adres URL' + # origin_url_label: 'Origin url' save_label: 'Zapisz' public: shared_by_wallabag: "Ten artykuł został udostępniony przez wallabag" diff --git a/src/Wallabag/CoreBundle/Resources/translations/messages.pt.yml b/src/Wallabag/CoreBundle/Resources/translations/messages.pt.yml index 9b3fea6b0..72fe2c9a9 100644 --- a/src/Wallabag/CoreBundle/Resources/translations/messages.pt.yml +++ b/src/Wallabag/CoreBundle/Resources/translations/messages.pt.yml @@ -244,6 +244,7 @@ entry: page_title: 'Editar uma entrada' title_label: 'Título' url_label: 'Url' + # origin_url_label: 'Origin url' save_label: 'Salvar' public: shared_by_wallabag: "Este artigo foi compartilhado pelo wallabag" diff --git a/src/Wallabag/CoreBundle/Resources/translations/messages.ro.yml b/src/Wallabag/CoreBundle/Resources/translations/messages.ro.yml index 673ca183a..7a3f0526a 100644 --- a/src/Wallabag/CoreBundle/Resources/translations/messages.ro.yml +++ b/src/Wallabag/CoreBundle/Resources/translations/messages.ro.yml @@ -244,6 +244,7 @@ entry: # page_title: 'Edit an entry' # title_label: 'Title' url_label: 'Url' + # origin_url_label: 'Origin url' save_label: 'Salvează' public: # shared_by_wallabag: "This article has been shared by %username% with wallabag" diff --git a/src/Wallabag/CoreBundle/Resources/translations/messages.tr.yml b/src/Wallabag/CoreBundle/Resources/translations/messages.tr.yml index 563bc50b0..44619ea5a 100644 --- a/src/Wallabag/CoreBundle/Resources/translations/messages.tr.yml +++ b/src/Wallabag/CoreBundle/Resources/translations/messages.tr.yml @@ -242,6 +242,7 @@ entry: page_title: 'Makaleyi düzenle' title_label: 'Başlık' url_label: 'Url' + # origin_url_label: 'Origin url' save_label: 'Kaydet' public: # shared_by_wallabag: "This article has been shared by %username% with wallabag" diff --git a/src/Wallabag/CoreBundle/Resources/views/themes/material/Entry/edit.html.twig b/src/Wallabag/CoreBundle/Resources/views/themes/material/Entry/edit.html.twig index b95379758..ed225957c 100644 --- a/src/Wallabag/CoreBundle/Resources/views/themes/material/Entry/edit.html.twig +++ b/src/Wallabag/CoreBundle/Resources/views/themes/material/Entry/edit.html.twig @@ -27,6 +27,11 @@ {{ form_label(form.url) }} {{ form_widget(form.url) }} + +
+ {{ form_label(form.origin_url) }} + {{ form_widget(form.origin_url) }} +

{{ form_widget(form.save, {'attr': {'class': 'btn waves-effect waves-light'}}) }} From e50e45d6fa64aea8b6b96f60073fb36960322aa8 Mon Sep 17 00:00:00 2001 From: Kevin Decherf Date: Sat, 9 Sep 2017 19:34:41 +0200 Subject: [PATCH 03/13] Twig: add removeSchemeAndWww filter This twig filter removes scheme (only http and https are supported) and pass the result to removeWww filter to also remove 'www.' at the beginning of an url. Signed-off-by: Kevin Decherf --- .../CoreBundle/Twig/WallabagExtension.php | 8 ++++++ .../CoreBundle/Twig/WallabagExtensionTest.php | 27 +++++++++++++++++++ 2 files changed, 35 insertions(+) diff --git a/src/Wallabag/CoreBundle/Twig/WallabagExtension.php b/src/Wallabag/CoreBundle/Twig/WallabagExtension.php index 351172c46..8992117e6 100644 --- a/src/Wallabag/CoreBundle/Twig/WallabagExtension.php +++ b/src/Wallabag/CoreBundle/Twig/WallabagExtension.php @@ -28,6 +28,7 @@ class WallabagExtension extends \Twig_Extension implements \Twig_Extension_Globa { return [ new \Twig_SimpleFilter('removeWww', [$this, 'removeWww']), + new \Twig_SimpleFilter('removeSchemeAndWww', [$this, 'removeSchemeAndWww']), ]; } @@ -45,6 +46,13 @@ class WallabagExtension extends \Twig_Extension implements \Twig_Extension_Globa return preg_replace('/^www\./i', '', $url); } + public function removeSchemeAndWww($url) + { + return $this->removeWww( + preg_replace('@^https?://@i', '', $url) + ); + } + /** * Return number of entries depending of the type (unread, archive, starred or all). * diff --git a/tests/Wallabag/CoreBundle/Twig/WallabagExtensionTest.php b/tests/Wallabag/CoreBundle/Twig/WallabagExtensionTest.php index ceec4b37b..279893461 100644 --- a/tests/Wallabag/CoreBundle/Twig/WallabagExtensionTest.php +++ b/tests/Wallabag/CoreBundle/Twig/WallabagExtensionTest.php @@ -30,4 +30,31 @@ class WallabagExtensionTest extends \PHPUnit_Framework_TestCase $this->assertSame('lemonde.fr', $extension->removeWww('lemonde.fr')); $this->assertSame('gist.github.com', $extension->removeWww('gist.github.com')); } + + public function testRemoveSchemeAndWww() + { + $entryRepository = $this->getMockBuilder('Wallabag\CoreBundle\Repository\EntryRepository') + ->disableOriginalConstructor() + ->getMock(); + + $tagRepository = $this->getMockBuilder('Wallabag\CoreBundle\Repository\TagRepository') + ->disableOriginalConstructor() + ->getMock(); + + $tokenStorage = $this->getMockBuilder('Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface') + ->disableOriginalConstructor() + ->getMock(); + + $translator = $this->getMockBuilder('Symfony\Component\Translation\TranslatorInterface') + ->disableOriginalConstructor() + ->getMock(); + + $extension = new WallabagExtension($entryRepository, $tagRepository, $tokenStorage, 0, $translator); + + $this->assertSame('lemonde.fr', $extension->removeSchemeAndWww('www.lemonde.fr')); + $this->assertSame('lemonde.fr', $extension->removeSchemeAndWww('http://lemonde.fr')); + $this->assertSame('lemonde.fr', $extension->removeSchemeAndWww('https://www.lemonde.fr')); + $this->assertSame('gist.github.com', $extension->removeSchemeAndWww('https://gist.github.com')); + $this->assertSame('ftp://gist.github.com', $extension->removeSchemeAndWww('ftp://gist.github.com')); + } } From f0f162b8d289f33a7bdff1c6f9ff9ecb1657ff67 Mon Sep 17 00:00:00 2001 From: Kevin Decherf Date: Sat, 9 Sep 2017 21:00:32 +0200 Subject: [PATCH 04/13] Add support of originUrl field in material entry view Signed-off-by: Kevin Decherf --- .../Resources/views/themes/material/Entry/entry.html.twig | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/Wallabag/CoreBundle/Resources/views/themes/material/Entry/entry.html.twig b/src/Wallabag/CoreBundle/Resources/views/themes/material/Entry/entry.html.twig index 4cff7bf2d..0d242d2bf 100644 --- a/src/Wallabag/CoreBundle/Resources/views/themes/material/Entry/entry.html.twig +++ b/src/Wallabag/CoreBundle/Resources/views/themes/material/Entry/entry.html.twig @@ -249,6 +249,14 @@ comment {{ 'entry.view.annotations_on_the_entry'|transchoice(entry.annotations | length) }} + {% if entry.originUrl is not empty %} +
  • + launch + + {{ entry.originUrl|striptags|removeSchemeAndWww|truncate(32) }} + +
  • + {% endif %}
      {% for tag in entry.tags %} From 3198ea9682e87f10c2b0fd6e75bcde40ad801245 Mon Sep 17 00:00:00 2001 From: Kevin Decherf Date: Sat, 9 Sep 2017 21:20:16 +0200 Subject: [PATCH 05/13] Handle original_url querystring in Shaarli sharing link This feature needs at least shaarli-plugin-via 0.2 from https://github.com/Kdecherf/shaarli-plugin-via to work. Shaarli will silently ignore this parameter if this plugin is missing. Signed-off-by: Kevin Decherf --- .../Resources/views/themes/material/Entry/entry.html.twig | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Wallabag/CoreBundle/Resources/views/themes/material/Entry/entry.html.twig b/src/Wallabag/CoreBundle/Resources/views/themes/material/Entry/entry.html.twig index 0d242d2bf..d585a7dcf 100644 --- a/src/Wallabag/CoreBundle/Resources/views/themes/material/Entry/entry.html.twig +++ b/src/Wallabag/CoreBundle/Resources/views/themes/material/Entry/entry.html.twig @@ -125,7 +125,7 @@ {% endif %} {% if craue_setting('share_shaarli') %}
    • - + shaarli
    • From 00f2368f7a99679aba7cd16e3d5cdbb072def562 Mon Sep 17 00:00:00 2001 From: Kevin Decherf Date: Sun, 15 Oct 2017 18:41:58 +0200 Subject: [PATCH 06/13] Add some tests for OriginUrl in EntryRestController Signed-off-by: Kevin Decherf --- .../DataFixtures/ORM/LoadEntryData.php | 1 + .../Controller/EntryRestControllerTest.php | 73 +++++++++++++++++++ 2 files changed, 74 insertions(+) diff --git a/src/Wallabag/CoreBundle/DataFixtures/ORM/LoadEntryData.php b/src/Wallabag/CoreBundle/DataFixtures/ORM/LoadEntryData.php index fedad0099..0e1510a29 100644 --- a/src/Wallabag/CoreBundle/DataFixtures/ORM/LoadEntryData.php +++ b/src/Wallabag/CoreBundle/DataFixtures/ORM/LoadEntryData.php @@ -37,6 +37,7 @@ class LoadEntryData extends AbstractFixture implements OrderedFixtureInterface $entry2->setMimetype('text/html'); $entry2->setTitle('test title entry2'); $entry2->setContent('This is my content /o/'); + $entry2->setOriginUrl('ftp://oneftp.tld'); $entry2->setLanguage('fr'); $manager->persist($entry2); diff --git a/tests/Wallabag/ApiBundle/Controller/EntryRestControllerTest.php b/tests/Wallabag/ApiBundle/Controller/EntryRestControllerTest.php index 95c64501c..ed104df3a 100644 --- a/tests/Wallabag/ApiBundle/Controller/EntryRestControllerTest.php +++ b/tests/Wallabag/ApiBundle/Controller/EntryRestControllerTest.php @@ -36,6 +36,25 @@ class EntryRestControllerTest extends WallabagApiTestCase $this->assertSame('application/json', $this->client->getResponse()->headers->get('Content-Type')); } + public function testGetOneEntryWithOriginUrl() + { + $entry = $this->client->getContainer() + ->get('doctrine.orm.entity_manager') + ->getRepository('WallabagCoreBundle:Entry') + ->findOneBy(['user' => 1, 'url' => 'http://0.0.0.0/entry2']); + + if (!$entry) { + $this->markTestSkipped('No content found in db.'); + } + + $this->client->request('GET', '/api/entries/' . $entry->getId() . '.json'); + $this->assertSame(200, $this->client->getResponse()->getStatusCode()); + + $content = json_decode($this->client->getResponse()->getContent(), true); + + $this->assertSame($entry->getOriginUrl(), $content['origin_url']); + } + public function testExportEntry() { $entry = $this->client->getContainer() @@ -531,6 +550,29 @@ class EntryRestControllerTest extends WallabagApiTestCase $this->assertSame(1, $content['is_starred']); } + public function testPostEntryWithOriginUrl() + { + $this->client->request('POST', '/api/entries.json', [ + 'url' => 'http://www.lemonde.fr/pixels/article/2015/03/28/plongee-dans-l-univers-d-ingress-le-jeu-de-google-aux-frontieres-du-reel_4601155_4408996.html', + 'tags' => 'google', + 'title' => 'New title for my article', + 'content' => 'my content', + 'language' => 'de', + 'published_at' => '2016-09-08T11:55:58+0200', + 'authors' => 'bob,helen', + 'public' => 1, + 'origin_url' => 'http://mysource.tld', + ]); + + $this->assertSame(200, $this->client->getResponse()->getStatusCode()); + + $content = json_decode($this->client->getResponse()->getContent(), true); + + $this->assertGreaterThan(0, $content['id']); + $this->assertSame('http://www.lemonde.fr/pixels/article/2015/03/28/plongee-dans-l-univers-d-ingress-le-jeu-de-google-aux-frontieres-du-reel_4601155_4408996.html', $content['url']); + $this->assertSame('http://mysource.tld', $content['origin_url']); + } + public function testPatchEntry() { $entry = $this->client->getContainer() @@ -607,6 +649,37 @@ class EntryRestControllerTest extends WallabagApiTestCase $this->assertSame($previousLanguage, $content['language'], 'Ensure language has not moved'); } + public function testPatchEntryWithOriginUrl() + { + $entry = $this->client->getContainer() + ->get('doctrine.orm.entity_manager') + ->getRepository('WallabagCoreBundle:Entry') + ->findOneByUser(1); + + if (!$entry) { + $this->markTestSkipped('No content found in db.'); + } + + $previousContent = $entry->getContent(); + $previousLanguage = $entry->getLanguage(); + + $this->client->request('PATCH', '/api/entries/' . $entry->getId() . '.json', [ + 'title' => 'Another awesome title just for profit', + 'origin_url' => 'https://myawesomesource.example.com', + ]); + + $this->assertSame(200, $this->client->getResponse()->getStatusCode()); + + $content = json_decode($this->client->getResponse()->getContent(), true); + + $this->assertSame($entry->getId(), $content['id']); + $this->assertSame($entry->getUrl(), $content['url']); + $this->assertSame('https://myawesomesource.example.com', $content['origin_url']); + $this->assertEmpty($content['published_by'], 'Authors were not saved because of an array instead of a string'); + $this->assertSame($previousContent, $content['content'], 'Ensure content has not moved'); + $this->assertSame($previousLanguage, $content['language'], 'Ensure language has not moved'); + } + public function testGetTagsEntry() { $entry = $this->client->getContainer() From 6de4cd35b5b979c37cf1bca5e5b3dae6a5b0170e Mon Sep 17 00:00:00 2001 From: Kevin Decherf Date: Sun, 5 Nov 2017 15:32:32 +0100 Subject: [PATCH 07/13] Add support of originUrl field in baggy entry view --- .../Resources/views/themes/baggy/Entry/entry.html.twig | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/Wallabag/CoreBundle/Resources/views/themes/baggy/Entry/entry.html.twig b/src/Wallabag/CoreBundle/Resources/views/themes/baggy/Entry/entry.html.twig index f8723189b..f7c89abf9 100644 --- a/src/Wallabag/CoreBundle/Resources/views/themes/baggy/Entry/entry.html.twig +++ b/src/Wallabag/CoreBundle/Resources/views/themes/baggy/Entry/entry.html.twig @@ -71,6 +71,14 @@ comment {{ 'entry.view.annotations_on_the_entry'|transchoice(entry.annotations | length) }} + + {% if entry.originUrl is not empty %} + launch + + {{ entry.originUrl|striptags|removeSchemeAndWww|truncate(32) }} + + {% endif %} +