]> git.immae.eu Git - github/wallabag/wallabag.git/commitdiff
Merge pull request #3425 from wallabag/add-setting-for-headers
authorNicolas Lœuillet <nicolas@loeuillet.org>
Tue, 21 Nov 2017 12:26:24 +0000 (13:26 +0100)
committerGitHub <noreply@github.com>
Tue, 21 Nov 2017 12:26:24 +0000 (13:26 +0100)
Added internal setting to enable/disable headers storage

27 files changed:
app/DoctrineMigrations/Version20171008195606.php
app/DoctrineMigrations/Version20171105202000.php [new file with mode: 0644]
composer.json
src/Wallabag/ApiBundle/Controller/EntryRestController.php
src/Wallabag/CoreBundle/DataFixtures/ORM/LoadEntryData.php
src/Wallabag/CoreBundle/Entity/Entry.php
src/Wallabag/CoreBundle/Form/Type/EditEntryType.php
src/Wallabag/CoreBundle/Resources/translations/messages.da.yml
src/Wallabag/CoreBundle/Resources/translations/messages.de.yml
src/Wallabag/CoreBundle/Resources/translations/messages.en.yml
src/Wallabag/CoreBundle/Resources/translations/messages.es.yml
src/Wallabag/CoreBundle/Resources/translations/messages.fa.yml
src/Wallabag/CoreBundle/Resources/translations/messages.fr.yml
src/Wallabag/CoreBundle/Resources/translations/messages.it.yml
src/Wallabag/CoreBundle/Resources/translations/messages.oc.yml
src/Wallabag/CoreBundle/Resources/translations/messages.pl.yml
src/Wallabag/CoreBundle/Resources/translations/messages.pt.yml
src/Wallabag/CoreBundle/Resources/translations/messages.ro.yml
src/Wallabag/CoreBundle/Resources/translations/messages.ru.yml
src/Wallabag/CoreBundle/Resources/translations/messages.tr.yml
src/Wallabag/CoreBundle/Resources/views/themes/baggy/Entry/entry.html.twig
src/Wallabag/CoreBundle/Resources/views/themes/material/Entry/edit.html.twig
src/Wallabag/CoreBundle/Resources/views/themes/material/Entry/entry.html.twig
src/Wallabag/CoreBundle/Twig/WallabagExtension.php
tests/Wallabag/ApiBundle/Controller/EntryRestControllerTest.php
tests/Wallabag/CoreBundle/Controller/EntryControllerTest.php
tests/Wallabag/CoreBundle/Twig/WallabagExtensionTest.php

index c190f4ed38324a6ee07ca759de1953b25dd90a3d..f09726c8532dbf72e0eea8e22ba164273861399c 100644 (file)
@@ -31,6 +31,7 @@ class Version20171008195606 extends AbstractMigration implements ContainerAwareI
 
         switch ($this->connection->getDatabasePlatform()->getName()) {
             case 'mysql':
+                $this->addSql('UPDATE ' . $this->getTable('entry') . ' SET reading_time = 0 WHERE reading_time IS NULL;');
                 $this->addSql('ALTER TABLE ' . $this->getTable('entry') . ' CHANGE reading_time reading_time INT(11) NOT NULL;');
                 break;
             case 'postgresql':
diff --git a/app/DoctrineMigrations/Version20171105202000.php b/app/DoctrineMigrations/Version20171105202000.php
new file mode 100644 (file)
index 0000000..3769045
--- /dev/null
@@ -0,0 +1,55 @@
+<?php
+
+namespace Application\Migrations;
+
+use Doctrine\DBAL\Migrations\AbstractMigration;
+use Doctrine\DBAL\Schema\Schema;
+use Symfony\Component\DependencyInjection\ContainerAwareInterface;
+use Symfony\Component\DependencyInjection\ContainerInterface;
+
+/**
+ * Add origin_url column.
+ */
+class Version20171105202000 extends AbstractMigration implements ContainerAwareInterface
+{
+    /**
+     * @var ContainerInterface
+     */
+    private $container;
+
+    public function setContainer(ContainerInterface $container = null)
+    {
+        $this->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;
+    }
+}
index ae7108f06321597c66ce64e3669399e4c87fa54f..23c7cdc2b16fba8035577d5475f8b38839113d43 100644 (file)
         "ext-iconv": "*",
         "ext-tokenizer": "*",
         "ext-pdo": "*",
-        "symfony/symfony": "3.3.*",
-        "doctrine/orm": "^2.5",
-        "doctrine/doctrine-bundle": "^1.6",
-        "doctrine/doctrine-cache-bundle": "^1.2",
-        "twig/extensions": "~1.0",
-        "symfony/swiftmailer-bundle": "^2.3",
-        "symfony/monolog-bundle": "^3.0",
-        "sensio/distribution-bundle": "^5.0",
-        "sensio/framework-extra-bundle": "^3.0",
-        "incenteev/composer-parameter-handler": "^2.0",
-        "nelmio/cors-bundle": "~1.4",
+        "symfony/symfony": "~3.3.13",
+        "doctrine/orm": "^2.5.12",
+        "doctrine/doctrine-bundle": "^1.8.0",
+        "doctrine/doctrine-cache-bundle": "^1.3.2",
+        "twig/extensions": "^1.5.1",
+        "symfony/swiftmailer-bundle": "^2.6.7",
+        "symfony/monolog-bundle": "^3.1.2",
+        "sensio/distribution-bundle": "^5.0.21",
+        "sensio/framework-extra-bundle": "^3.0.28",
+        "incenteev/composer-parameter-handler": "^2.1.2",
+        "nelmio/cors-bundle": "~1.5",
         "friendsofsymfony/rest-bundle": "~2.1",
         "jms/serializer-bundle": "~2.2",
-        "nelmio/api-doc-bundle": "~2.7",
+        "nelmio/api-doc-bundle": "^2.13.2",
         "mgargano/simplehtmldom": "~1.5",
-        "wallabag/tcpdf": "^6.2",
+        "wallabag/tcpdf": "^6.2.15",
         "simplepie/simplepie": "~1.5",
-        "willdurand/hateoas-bundle": "~1.0",
-        "liip/theme-bundle": "~1.1",
-        "lexik/form-filter-bundle": "~5.0",
+        "willdurand/hateoas-bundle": "~1.3",
+        "liip/theme-bundle": "^1.4.6",
+        "lexik/form-filter-bundle": "^5.0.4",
         "j0k3r/graby": "^1.0",
-        "friendsofsymfony/user-bundle": "^2.0",
-        "friendsofsymfony/oauth-server-bundle": "^1.5",
+        "friendsofsymfony/user-bundle": "^2.0.1",
+        "friendsofsymfony/oauth-server-bundle": "^1.5.2",
         "stof/doctrine-extensions-bundle": "^1.2",
-        "scheb/two-factor-bundle": "~2.0",
-        "grandt/phpepub": "~4.0",
+        "scheb/two-factor-bundle": "^2.14.0",
+        "grandt/phpepub": "^4.0.7",
         "wallabag/php-mobi": "~1.0.0",
         "kphoen/rulerz-bundle": "~0.13",
         "guzzlehttp/guzzle": "^5.3.1",
-        "doctrine/doctrine-migrations-bundle": "^1.0",
-        "paragonie/random_compat": "~2.0",
+        "doctrine/doctrine-migrations-bundle": "^1.3",
+        "paragonie/random_compat": "^2.0.11",
         "craue/config-bundle": "~2.0",
         "mnapoli/piwik-twig-extension": "^1.0",
-        "ocramius/proxy-manager": "1.*",
-        "white-october/pagerfanta-bundle": "^1.0",
-        "php-amqplib/rabbitmq-bundle": "^1.8",
-        "predis/predis": "^1.0",
+        "ocramius/proxy-manager": "^1.0.2",
+        "white-october/pagerfanta-bundle": "^1.1.0",
+        "php-amqplib/rabbitmq-bundle": "^1.14",
+        "predis/predis": "^1.1.1",
         "javibravo/simpleue": "^2.0",
-        "symfony/dom-crawler": "^3.1",
-        "friendsofsymfony/jsrouting-bundle": "^1.6",
+        "symfony/dom-crawler": "^3.3.13",
+        "friendsofsymfony/jsrouting-bundle": "^1.6.3",
         "bdunogier/guzzle-site-authenticator": "^1.0.0@dev",
         "defuse/php-encryption": "^2.1",
         "html2text/html2text": "^4.1"
index 6f161a081eb436431a26d7854988e1c6d3b7cb6c..7d820c7e606195e15697cd652442308e56643e8d 100644 (file)
@@ -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 (from where you found it)."},
      *       }
      * )
      *
@@ -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 (from where you found it)."},
      *      }
      * )
      *
@@ -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', ''),
         ];
     }
 
index fedad00993f6b3b5ff354f72c74bcea76e3e9c46..0e1510a29bf450f7c8e9e6067fb7c6ee2af84012 100644 (file)
@@ -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);
index cfb8db75275c2e42d1b994e5f037a58220bd31d5..2b1f2e050799c24495611d2ba75212e37944f4d5 100644 (file)
@@ -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;
+    }
 }
index 1627cc445e60035047fa9d1926a1e0866750e3e2..083559286477d5bf53fe8d91cb0f716f37adec8a 100644 (file)
@@ -5,6 +5,7 @@ namespace Wallabag\CoreBundle\Form\Type;
 use Symfony\Component\Form\AbstractType;
 use Symfony\Component\Form\Extension\Core\Type\SubmitType;
 use Symfony\Component\Form\Extension\Core\Type\TextType;
+use Symfony\Component\Form\Extension\Core\Type\UrlType;
 use Symfony\Component\Form\FormBuilderInterface;
 use Symfony\Component\OptionsResolver\OptionsResolver;
 
@@ -17,11 +18,16 @@ class EditEntryType extends AbstractType
                 'required' => true,
                 'label' => 'entry.edit.title_label',
             ])
-            ->add('url', TextType::class, [
+            ->add('url', UrlType::class, [
                 'disabled' => true,
                 'required' => false,
                 'label' => 'entry.edit.url_label',
             ])
+            ->add('origin_url', UrlType::class, [
+                'required' => false,
+                'property_path' => 'originUrl',
+                'label' => 'entry.edit.origin_url_label',
+            ])
             ->add('save', SubmitType::class, [
                 'label' => 'entry.edit.save_label',
             ])
index d0a38f7e3b25b6321f59f72fa1b39d2b5d697fbe..27dbb3885468db74c42f1864d673f8a80d819d20 100644 (file)
@@ -233,6 +233,7 @@ entry:
         created_at: 'Oprettelsesdato'
         # published_at: 'Publication date'
         # published_by: 'Published by'
+        # provided_by: 'Provided by'
     new:
         page_title: 'Gem ny artikel'
         placeholder: 'http://website.com'
@@ -244,6 +245,7 @@ entry:
         # page_title: 'Edit an entry'
         # title_label: 'Title'
         url_label: 'Url'
+        # origin_url_label: 'Origin url (from where you found that entry)'
         save_label: 'Gem'
     public:
         # shared_by_wallabag: "This article has been shared by %username% with <a href='%wallabag_instance%'>wallabag</a>"
index 158762a97b6a2d7a57b6f5f7e2beb1d84792d2f9..d47986e5bac8ccf6490c220f0a3b2b0b01c43f8d 100644 (file)
@@ -233,6 +233,7 @@ entry:
         created_at: 'Erstellungsdatum'
         published_at: 'Erscheinungsdatum'
         published_by: 'Veröffentlicht von'
+        # provided_by: 'Provided by'
     new:
         page_title: 'Neuen Artikel speichern'
         placeholder: 'https://website.de'
@@ -244,6 +245,7 @@ entry:
         page_title: 'Eintrag bearbeiten'
         title_label: 'Titel'
         url_label: 'URL'
+        # origin_url_label: 'Origin url (from where you found that entry)'
         save_label: 'Speichern'
     public:
         shared_by_wallabag: 'Dieser Artikel wurde von %username% mittels <a href="%wallabag_instance%">wallabag</a> geteilt'
index de3e11fe27bd1b1994f0141a6dabd6091f0a5344..bbaecb24a01204117f425b167e5a98c48c15a083 100644 (file)
@@ -233,6 +233,7 @@ entry:
         created_at: 'Creation date'
         published_at: 'Publication date'
         published_by: 'Published by'
+        provided_by: 'Provided by'
     new:
         page_title: 'Save new entry'
         placeholder: 'http://website.com'
@@ -244,6 +245,7 @@ entry:
         page_title: 'Edit an entry'
         title_label: 'Title'
         url_label: 'Url'
+        origin_url_label: 'Origin url (from where you found that entry)'
         save_label: 'Save'
     public:
         shared_by_wallabag: "This article has been shared by %username% with <a href='%wallabag_instance%'>wallabag</a>"
index 6dfc1525e2892130bb47f020910b7cf160ba824a..e3b625f7a61f566ea8ad727829811d916dce4ebf 100644 (file)
@@ -233,6 +233,7 @@ entry:
         created_at: 'Fecha de creación'
         # published_at: 'Publication date'
         # published_by: 'Published by'
+        # provided_by: 'Provided by'
     new:
         page_title: 'Guardar un nuevo artículo'
         placeholder: 'http://sitioweb.com'
@@ -244,6 +245,7 @@ entry:
         page_title: 'Editar un artículo'
         title_label: 'Título'
         url_label: 'URL'
+        # origin_url_label: 'Origin url (from where you found that entry)'
         save_label: 'Guardar'
     public:
         shared_by_wallabag: "Este artículo se ha compartido con <a href='%wallabag_instance%'>wallabag</a>"
index ffc48933a09378d6146b848471d2f4764cb97e1e..c03cca464720a2d379e4e6679967c024bef28a72 100644 (file)
@@ -233,6 +233,7 @@ entry:
         created_at: 'زمان ساخت'
         # published_at: 'Publication date'
         # published_by: 'Published by'
+        # provided_by: 'Provided by'
     new:
         page_title: 'ذخیرهٔ مقالهٔ تازه'
         placeholder: 'http://website.com'
@@ -244,6 +245,7 @@ entry:
         page_title: 'ویرایش مقاله'
         title_label: 'عنوان'
         url_label: 'نشانی'
+        # origin_url_label: 'Origin url (from where you found that entry)'
         save_label: 'ذخیره'
     public:
         # shared_by_wallabag: "This article has been shared by %username% with <a href='%wallabag_instance%'>wallabag</a>"
index c9d95e2bcdc6708e0f95b5762e946bb8f5eccc9b..b0037ad277db75e32a20912f7d15905bd0db3ba4 100644 (file)
@@ -233,6 +233,7 @@ entry:
         created_at: "Date de création"
         published_at: "Date de publication"
         published_by: "Publié par"
+        provided_by: "Fourni par"
     new:
         page_title: "Sauvegarder un nouvel article"
         placeholder: "http://website.com"
@@ -244,6 +245,7 @@ entry:
         page_title: "Éditer un article"
         title_label: "Titre"
         url_label: "Adresse"
+        origin_url_label: "Adresse d'origine (d'où vous avez trouvé cet article)"
         save_label: "Enregistrer"
     public:
         shared_by_wallabag: "Cet article a été partagé par %username% avec <a href=\"%wallabag_instance%\">wallabag</a>"
index c53266ca360fc548d9ac873d4b991a75b0b68218..56cf341bdf10c2f4a38607efb087ae2cbb48dfc0 100644 (file)
@@ -233,6 +233,7 @@ entry:
         created_at: 'Data di creazione'
         published_at: 'Data di pubblicazione'
         published_by: 'Pubblicato da'
+        # provided_by: 'Provided by'
     new:
         page_title: 'Salva un nuovo contenuto'
         placeholder: 'http://website.com'
@@ -244,6 +245,7 @@ entry:
         page_title: 'Modifica voce'
         title_label: 'Titolo'
         url_label: 'Url'
+        # origin_url_label: 'Origin url (from where you found that entry)'
         save_label: 'Salva'
     public:
         shared_by_wallabag: "Questo articolo è stato condiviso da %username% con <a href='%wallabag_instance%'>wallabag</a>"
index 3ae64c49f73e7f8c69fd0e1660f7ea16a417f3e3..1b5b221fade65ee20a64141cd82c87e95f268f4d 100644 (file)
@@ -233,6 +233,7 @@ entry:
         created_at: 'Data de creacion'
         published_at: 'Data de publicacion'
         published_by: 'Publicat per'
+        # provided_by: 'Provided by'
     new:
         page_title: 'Enregistrar un novèl article'
         placeholder: 'http://website.com'
@@ -244,6 +245,7 @@ entry:
         page_title: 'Modificar un article'
         title_label: 'Títol'
         url_label: 'Url'
+        # origin_url_label: 'Origin url (from where you found that entry)'
         save_label: 'Enregistrar'
     public:
         shared_by_wallabag: "Aqueste article es estat partejat per <a href='%wallabag_instance%'>wallabag</a>"
index e642c5307a35a5fe863fd448e803d876b9530a10..88f35738d89e31d54224207b905b0f1b2a0cdfeb 100644 (file)
@@ -233,6 +233,7 @@ entry:
         created_at: 'Czas stworzenia'
         published_at: 'Data publikacji'
         published_by: 'Opublikowane przez'
+        # provided_by: 'Provided by'
     new:
         page_title: 'Zapisz nowy wpis'
         placeholder: 'http://website.com'
@@ -244,6 +245,7 @@ entry:
         page_title: 'Edytuj wpis'
         title_label: 'Tytuł'
         url_label: 'Adres URL'
+        # origin_url_label: 'Origin url (from where you found that entry)'
         save_label: 'Zapisz'
     public:
         shared_by_wallabag: "Ten artykuł został udostępniony przez <a href='%wallabag_instance%'>wallabag</a>"
index 9b3fea6b0e1dae9957f138cff2dda6858138f8a7..3987cec3dc51df6a312c402886bb05662aa2e24e 100644 (file)
@@ -233,6 +233,7 @@ entry:
         created_at: 'Data de criação'
         # published_at: 'Publication date'
         # published_by: 'Published by'
+        # provided_by: 'Provided by'
     new:
         page_title: 'Salvar nova entrada'
         placeholder: 'http://website.com'
@@ -244,6 +245,7 @@ entry:
         page_title: 'Editar uma entrada'
         title_label: 'Título'
         url_label: 'Url'
+        # origin_url_label: 'Origin url (from where you found that entry)'
         save_label: 'Salvar'
     public:
         shared_by_wallabag: "Este artigo foi compartilhado pelo <a href='%wallabag_instance%'>wallabag</a>"
index 673ca183a87273c80bfc95e93201f8938bf3a58a..4d2fd5693d9d85ef91774d6a1933577a385e0810 100644 (file)
@@ -233,6 +233,7 @@ entry:
         created_at: 'Data creării'
         # published_at: 'Publication date'
         # published_by: 'Published by'
+        # provided_by: 'Provided by'
     new:
         page_title: 'Salvează un nou articol'
         placeholder: 'http://website.com'
@@ -244,6 +245,7 @@ entry:
         # page_title: 'Edit an entry'
         # title_label: 'Title'
         url_label: 'Url'
+        # origin_url_label: 'Origin url (from where you found that entry)'
         save_label: 'Salvează'
     public:
         # shared_by_wallabag: "This article has been shared by %username% with <a href='%wallabag_instance%'>wallabag</a>"
index eceecabfbf6f16e8fbc553e6b27f1bed24254caf..a560e58df106e8bc633ae4278d4b6baae02b102c 100644 (file)
@@ -223,6 +223,7 @@ entry:
         original_article: 'оригинал'
         annotations_on_the_entry: '{0} Нет аннотации|{1} Одна аннотация|]1,Inf[ %count% аннотаций'
         created_at: 'Дата создания'
+        # provided_by: 'Provided by'
     new:
         page_title: 'Сохранить новую запись'
         placeholder: 'http://website.com'
@@ -234,6 +235,7 @@ entry:
         page_title: 'Изменить запись'
         title_label: 'Название'
         url_label: 'Ссылка'
+        # origin_url_label: 'Origin url (from where you found that entry)'
         is_public_label: 'Публичная'
         save_label: 'Сохранить'
     public:
index 563bc50b05a6d4bc0ffe56fb70c1d1fd87cb34d9..0fd6e989096a7e77b064164baf19736153c28d11 100644 (file)
@@ -231,6 +231,7 @@ entry:
         created_at: 'Oluşturulma tarihi'
         # published_at: 'Publication date'
         # published_by: 'Published by'
+        # provided_by: 'Provided by'
     new:
         page_title: 'Yeni makaleyi kaydet'
         placeholder: 'http://website.com'
@@ -242,6 +243,7 @@ entry:
         page_title: 'Makaleyi düzenle'
         title_label: 'Başlık'
         url_label: 'Url'
+        # origin_url_label: 'Origin url (from where you found that entry)'
         save_label: 'Kaydet'
     public:
         # shared_by_wallabag: "This article has been shared by %username% with <a href='%wallabag_instance%'>wallabag</a>"
index f8723189b725592fd6a9721e363dc7fbaab7d125..0c7cbaa6e4183a46d2d08e7876a503d5215490c4 100644 (file)
             </i>
 
             <span class="tool link"><i class="material-icons link">comment</i> {{ 'entry.view.annotations_on_the_entry'|transchoice(entry.annotations | length) }}</span>
+
+            {% if entry.originUrl is not empty %}
+                <i class="material-icons" title="{{ 'entry.view.provided_by'|trans }}">launch</i>
+                <a href="{{ entry.originUrl|e }}" target="_blank" class="tool">
+                    {{ entry.originUrl|striptags|removeSchemeAndWww|truncate(32) }}
+                </a>
+            {% endif %}
+
             <aside class="tags">
                 <div class="card-entry-tags">
                 {% for tag in entry.tags %}
index b95379758dc5de2cb15bf7e0d4ebd66cd9e7db10..ed225957ce6af81e007c2c8ea334b2a7061daa0d 100644 (file)
                             {{ form_label(form.url) }}
                             {{ form_widget(form.url) }}
                         </div>
+
+                        <div class="input-field s12">
+                            {{ form_label(form.origin_url) }}
+                            {{ form_widget(form.origin_url) }}
+                        </div>
                         <br>
 
                         {{ form_widget(form.save, {'attr': {'class': 'btn waves-effect waves-light'}}) }}
index 4cff7bf2db489491618b6a61eb35c31086366ec4..019569f793978acc94e644704760ab7b3d80c42e 100644 (file)
                     {% endif %}
                     {% if craue_setting('share_shaarli') %}
                         <li>
-                        <a href="{{ craue_setting('shaarli_url') }}/index.php?post={{ entry.url|url_encode }}&amp;title={{ entry.title|striptags|url_encode }}&amp;tags={{ entry.tags|join(',')|striptags|url_encode }}" target="_blank" title="shaarli" class="tool icon-image shaarli">
+                        <a href="{{ craue_setting('shaarli_url') }}/index.php?post={{ entry.url|url_encode }}&amp;title={{ entry.title|striptags|url_encode }}&amp;tags={{ entry.tags|join(',')|striptags|url_encode }}&amp;lf_original_url={{ entry.originUrl|url_encode }}" target="_blank" title="shaarli" class="tool icon-image shaarli">
                                 <span>shaarli</span>
                             </a>
                         </li>
                         <i class="material-icons link">comment</i>
                         {{ 'entry.view.annotations_on_the_entry'|transchoice(entry.annotations | length) }}
                     </li>
+                    {% if entry.originUrl is not empty %}
+                        <li>
+                            <i class="material-icons" title="{{ 'entry.view.provided_by'|trans }}">launch</i>
+                            <a href="{{ entry.originUrl|e }}" target="_blank" class="tool">
+                                {{ entry.originUrl|striptags|removeSchemeAndWww|truncate(32) }}
+                            </a>
+                        </li>
+                    {% endif %}
                 </ul>
                 <ul class="tags">
                     {% for tag in entry.tags %}
index 351172c460f2fc24ba76c37e85e76b14ac958c57..8992117e62baef07228a517238ca44aa06ddf2e6 100644 (file)
@@ -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).
      *
index 8a65f512033bd41be3d9b7380b56d0796f434088..b0d4c4e1a609bfb8778fc1da9b310fe6cb64b082 100644 (file)
@@ -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()
@@ -421,6 +440,7 @@ class EntryRestControllerTest extends WallabagApiTestCase
         $this->assertSame('New title for my article', $content['title']);
         $this->assertSame(1, $content['user_id']);
         $this->assertCount(2, $content['tags']);
+        $this->assertNull($content['origin_url']);
         $this->assertSame('my content', $content['content']);
         $this->assertSame('de', $content['language']);
         $this->assertSame('2016-09-08T11:55:58+0200', $content['published_at']);
@@ -531,6 +551,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 +650,91 @@ 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 testPatchEntryRemoveOriginUrl()
+    {
+        $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();
+        $previousTitle = $entry->getTitle();
+
+        $this->client->request('PATCH', '/api/entries/' . $entry->getId() . '.json', [
+            'origin_url' => '',
+        ]);
+
+        $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->assertEmpty($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');
+        $this->assertSame($previousTitle, $content['title'], 'Ensure title has not moved');
+    }
+
+    public function testPatchEntryNullOriginUrl()
+    {
+        $entry = $this->client->getContainer()
+            ->get('doctrine.orm.entity_manager')
+            ->getRepository('WallabagCoreBundle:Entry')
+            ->findOneByUser(1);
+
+        if (!$entry) {
+            $this->markTestSkipped('No content found in db.');
+        }
+
+        $this->client->request('PATCH', '/api/entries/' . $entry->getId() . '.json', [
+                'origin_url' => null,
+            ]);
+
+        $this->assertSame(200, $this->client->getResponse()->getStatusCode());
+
+        $content = json_decode($this->client->getResponse()->getContent(), true);
+
+        $this->assertNull($content['origin_url']);
+    }
+
     public function testGetTagsEntry()
     {
         $entry = $this->client->getContainer()
index 2a2fd1a4c80086037f1659fc3dc16816cbe92bf0..4ac4548b2624b2f75035e525a4f4e0fb5ec577f9 100644 (file)
@@ -478,6 +478,7 @@ class EntryControllerTest extends WallabagCoreTestCase
 
         $data = [
             'entry[title]' => 'My updated title hehe :)',
+            'entry[origin_url]' => 'https://example.io',
         ];
 
         $client->submit($form, $data);
@@ -486,8 +487,43 @@ class EntryControllerTest extends WallabagCoreTestCase
 
         $crawler = $client->followRedirect();
 
-        $this->assertGreaterThan(1, $alert = $crawler->filter('div[id=article] h1')->extract(['_text']));
-        $this->assertContains('My updated title hehe :)', $alert[0]);
+        $this->assertGreaterThan(1, $title = $crawler->filter('div[id=article] h1')->extract(['_text']));
+        $this->assertContains('My updated title hehe :)', $title[0]);
+        $this->assertGreaterThan(1, $stats = $crawler->filter('div[class=tools] ul[class=stats] li a[class=tool]')->extract(['_text']));
+        $this->assertContains('example.io', trim($stats[1]));
+    }
+
+    public function testEditRemoveOriginUrl()
+    {
+        $this->logInAs('admin');
+        $client = $this->getClient();
+
+        $entry = new Entry($this->getLoggedInUser());
+        $entry->setUrl($this->url);
+        $this->getEntityManager()->persist($entry);
+        $this->getEntityManager()->flush();
+
+        $crawler = $client->request('GET', '/edit/' . $entry->getId());
+
+        $this->assertSame(200, $client->getResponse()->getStatusCode());
+
+        $form = $crawler->filter('button[type=submit]')->form();
+
+        $data = [
+            'entry[title]' => 'My updated title hehe :)',
+            'entry[origin_url]' => '',
+        ];
+
+        $client->submit($form, $data);
+
+        $this->assertSame(302, $client->getResponse()->getStatusCode());
+
+        $crawler = $client->followRedirect();
+
+        $this->assertGreaterThan(1, $title = $crawler->filter('div[id=article] h1')->extract(['_text']));
+        $this->assertContains('My updated title hehe :)', $title[0]);
+        $this->assertSame(1, count($stats = $crawler->filter('div[class=tools] ul[class=stats] li a[class=tool]')->extract(['_text'])));
+        $this->assertNotContains('example.io', trim($stats[0]));
     }
 
     public function testToggleArchive()
index ceec4b37b7a91316dcb8884cb074481d82e38606..82336060fb79356447b868a342e2de40d5791631 100644 (file)
@@ -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'));
+    }
 }