From 6c08fb68b8e7883df7f6c1a2ba7c56ced4c1153b Mon Sep 17 00:00:00 2001 From: Thomas Citharel Date: Mon, 25 Jan 2016 17:31:45 +0100 Subject: add txt export --- src/Wallabag/CoreBundle/Helper/EntriesExport.php | 22 ++++++++++++++++++++++ .../views/themes/material/Entry/entry.html.twig | 2 +- 2 files changed, 23 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/Wallabag/CoreBundle/Helper/EntriesExport.php b/src/Wallabag/CoreBundle/Helper/EntriesExport.php index 965a40b6..79fe6eaa 100644 --- a/src/Wallabag/CoreBundle/Helper/EntriesExport.php +++ b/src/Wallabag/CoreBundle/Helper/EntriesExport.php @@ -6,6 +6,7 @@ use JMS\Serializer; use JMS\Serializer\SerializationContext; use JMS\Serializer\SerializerBuilder; use PHPePub\Core\EPub; +use Html2Text\Html2Text; use PHPePub\Core\Structure\OPF\DublinCore; use Symfony\Component\HttpFoundation\Response; use Craue\ConfigBundle\Util\Config; @@ -99,6 +100,8 @@ class EntriesExport case 'xml': return $this->produceXML(); + case 'txt': + return $this->produceTXT(); } throw new \InvalidArgumentException(sprintf('The format "%s" is not yet supported.', $format)); @@ -359,6 +362,25 @@ class EntriesExport )->send(); } + private function produceTXT() + { + $content = ''; + foreach ($this->entries as $entry) { + $content .= $entry->getTitle(); + $content .= strip_tags($entry->getContent()); + } + return Response::create( + $content, + 200, + array( + 'Content-type' => 'text/plain', + 'Content-Disposition' => 'attachment; filename="'.$this->title.'.txt"', + 'Content-Transfer-Encoding' => 'UTF-8', + ) + )->send(); + } + + /** * Return a Serializer object for producing processes that need it (JSON & XML). * 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 dad96187..2d3fd516 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 @@ -118,7 +118,7 @@ {% if craue_setting('export_pdf') %}
  • PDF
  • {% endif %} {% if craue_setting('export_csv') %}
  • CSV
  • {% endif %} {% if craue_setting('export_json') %}
  • JSON
  • {% endif %} - {% if craue_setting('export_txt') %}
  • TXT
  • {% endif %} + {% if craue_setting('export_txt') %}
  • TXT
  • {% endif %} {% if craue_setting('export_xml') %}
  • XML
  • {% endif %} -- cgit v1.2.3 From 365a38984e32d152ec0170991a61bf704756cf1e Mon Sep 17 00:00:00 2001 From: Thomas Citharel Date: Mon, 25 Jan 2016 22:02:44 +0100 Subject: better display for txt --- src/Wallabag/CoreBundle/Helper/EntriesExport.php | 4 ++-- .../Resources/views/themes/material/Entry/entries.html.twig | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) (limited to 'src') diff --git a/src/Wallabag/CoreBundle/Helper/EntriesExport.php b/src/Wallabag/CoreBundle/Helper/EntriesExport.php index 79fe6eaa..6e06086f 100644 --- a/src/Wallabag/CoreBundle/Helper/EntriesExport.php +++ b/src/Wallabag/CoreBundle/Helper/EntriesExport.php @@ -366,8 +366,8 @@ class EntriesExport { $content = ''; foreach ($this->entries as $entry) { - $content .= $entry->getTitle(); - $content .= strip_tags($entry->getContent()); + $content .= "\n\n" . str_repeat("=",100) . "\n\n" . $entry->getTitle() . "\n\n" . str_repeat("=",100) . "\n\n"; + $content .= trim(preg_replace('/\s+/S', ' ', strip_tags($entry->getContent()))) . "\n\n"; } return Response::create( $content, diff --git a/src/Wallabag/CoreBundle/Resources/views/themes/material/Entry/entries.html.twig b/src/Wallabag/CoreBundle/Resources/views/themes/material/Entry/entries.html.twig index 8ad24fbf..e9925e3d 100644 --- a/src/Wallabag/CoreBundle/Resources/views/themes/material/Entry/entries.html.twig +++ b/src/Wallabag/CoreBundle/Resources/views/themes/material/Entry/entries.html.twig @@ -107,7 +107,7 @@ {% if craue_setting('export_xml') %}
  • {% trans %}XML{% endtrans %}
  • {% endif %} {% if craue_setting('export_csv') %}
  • {% trans %}JSON{% endtrans %}
  • {% endif %} {% if craue_setting('export_json') %}
  • {% trans %}CSV{% endtrans %}
  • {% endif %} - {% if craue_setting('export_txt') %}
  • {% trans %}TXT{% endtrans %}
  • {% endif %} + {% if craue_setting('export_txt') %}
  • {% trans %}TXT{% endtrans %}
  • {% endif %} -- cgit v1.2.3 From 3a2ada0be070acf2642d9ab06ce59e612538edee Mon Sep 17 00:00:00 2001 From: Thomas Citharel Date: Mon, 25 Jan 2016 22:25:55 +0100 Subject: fix tests --- .../Tests/Controller/ExportControllerTest.php | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/Wallabag/CoreBundle/Tests/Controller/ExportControllerTest.php b/src/Wallabag/CoreBundle/Tests/Controller/ExportControllerTest.php index aaa26499..76c98055 100644 --- a/src/Wallabag/CoreBundle/Tests/Controller/ExportControllerTest.php +++ b/src/Wallabag/CoreBundle/Tests/Controller/ExportControllerTest.php @@ -41,7 +41,7 @@ class ExportControllerTest extends WallabagCoreTestCase $this->logInAs('admin'); $client = $this->getClient(); - $client->request('GET', '/export/unread.txt'); + $client->request('GET', '/export/unread.doc'); $this->assertEquals(404, $client->getResponse()->getStatusCode()); $content = $client->getContainer() @@ -49,7 +49,7 @@ class ExportControllerTest extends WallabagCoreTestCase ->getRepository('WallabagCoreBundle:Entry') ->findOneByUsernameAndNotArchived('admin'); - $client->request('GET', '/export/'.$content->getId().'.txt'); + $client->request('GET', '/export/'.$content->getId().'.doc'); $this->assertEquals(404, $client->getResponse()->getStatusCode()); } @@ -119,6 +119,23 @@ class ExportControllerTest extends WallabagCoreTestCase $this->assertEquals('binary', $headers->get('content-transfer-encoding')); } + public function testTxtExport() + { + $this->logInAs('admin'); + $client = $this->getClient(); + + ob_start(); + $crawler = $client->request('GET', '/export/all.txt'); + ob_end_clean(); + + $this->assertEquals(200, $client->getResponse()->getStatusCode()); + + $headers = $client->getResponse()->headers; + $this->assertEquals('text/plain; charset=UTF-8', $headers->get('content-type')); + $this->assertEquals('attachment; filename="All articles.txt"', $headers->get('content-disposition')); + $this->assertEquals('UTF-8', $headers->get('content-transfer-encoding')); + } + public function testCsvExport() { $this->logInAs('admin'); -- cgit v1.2.3 From 3b07d019379106d6786121b3208d0e396e1ae40a Mon Sep 17 00:00:00 2001 From: Thomas Citharel Date: Sun, 31 Jan 2016 14:13:42 +0100 Subject: remove old dependancy --- src/Wallabag/CoreBundle/Helper/EntriesExport.php | 1 - 1 file changed, 1 deletion(-) (limited to 'src') diff --git a/src/Wallabag/CoreBundle/Helper/EntriesExport.php b/src/Wallabag/CoreBundle/Helper/EntriesExport.php index 6e06086f..d3b7ee3e 100644 --- a/src/Wallabag/CoreBundle/Helper/EntriesExport.php +++ b/src/Wallabag/CoreBundle/Helper/EntriesExport.php @@ -6,7 +6,6 @@ use JMS\Serializer; use JMS\Serializer\SerializationContext; use JMS\Serializer\SerializerBuilder; use PHPePub\Core\EPub; -use Html2Text\Html2Text; use PHPePub\Core\Structure\OPF\DublinCore; use Symfony\Component\HttpFoundation\Response; use Craue\ConfigBundle\Util\Config; -- cgit v1.2.3 From f161122412ea73f8939d581bfbd383b3655cd4c1 Mon Sep 17 00:00:00 2001 From: Thomas Citharel Date: Mon, 1 Feb 2016 14:43:02 +0100 Subject: put the equals bar outside the loop --- src/Wallabag/CoreBundle/Helper/EntriesExport.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/Wallabag/CoreBundle/Helper/EntriesExport.php b/src/Wallabag/CoreBundle/Helper/EntriesExport.php index d3b7ee3e..3f1fc43c 100644 --- a/src/Wallabag/CoreBundle/Helper/EntriesExport.php +++ b/src/Wallabag/CoreBundle/Helper/EntriesExport.php @@ -364,8 +364,9 @@ class EntriesExport private function produceTXT() { $content = ''; + $bar = str_repeat("=",100); foreach ($this->entries as $entry) { - $content .= "\n\n" . str_repeat("=",100) . "\n\n" . $entry->getTitle() . "\n\n" . str_repeat("=",100) . "\n\n"; + $content .= "\n\n" . $bar . "\n\n" . $entry->getTitle() . "\n\n" . $bar . "\n\n"; $content .= trim(preg_replace('/\s+/S', ' ', strip_tags($entry->getContent()))) . "\n\n"; } return Response::create( -- cgit v1.2.3 From d3f31ec485c2d8d0fcf9361d137aa482d6a939ea Mon Sep 17 00:00:00 2001 From: Jeremy Benoist Date: Mon, 1 Feb 2016 15:35:30 +0100 Subject: CS --- src/Wallabag/CoreBundle/Helper/EntriesExport.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'src') diff --git a/src/Wallabag/CoreBundle/Helper/EntriesExport.php b/src/Wallabag/CoreBundle/Helper/EntriesExport.php index 3f1fc43c..c9aac6e5 100644 --- a/src/Wallabag/CoreBundle/Helper/EntriesExport.php +++ b/src/Wallabag/CoreBundle/Helper/EntriesExport.php @@ -364,11 +364,12 @@ class EntriesExport private function produceTXT() { $content = ''; - $bar = str_repeat("=",100); + $bar = str_repeat('=', 100); foreach ($this->entries as $entry) { - $content .= "\n\n" . $bar . "\n\n" . $entry->getTitle() . "\n\n" . $bar . "\n\n"; - $content .= trim(preg_replace('/\s+/S', ' ', strip_tags($entry->getContent()))) . "\n\n"; + $content .= "\n\n".$bar."\n\n".$entry->getTitle()."\n\n".$bar."\n\n"; + $content .= trim(preg_replace('/\s+/S', ' ', strip_tags($entry->getContent())))."\n\n"; } + return Response::create( $content, 200, @@ -380,7 +381,6 @@ class EntriesExport )->send(); } - /** * Return a Serializer object for producing processes that need it (JSON & XML). * -- cgit v1.2.3 From eb15061d0b98491d581f9ad0b76671bfcbdd40f1 Mon Sep 17 00:00:00 2001 From: Jeremy Benoist Date: Thu, 4 Feb 2016 20:41:30 +0100 Subject: Adjust export order To be the same as on the entry page. Also, export name doesn't need to be translated. --- .../views/themes/material/Entry/entries.html.twig | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) (limited to 'src') diff --git a/src/Wallabag/CoreBundle/Resources/views/themes/material/Entry/entries.html.twig b/src/Wallabag/CoreBundle/Resources/views/themes/material/Entry/entries.html.twig index e9925e3d..3b7698f3 100644 --- a/src/Wallabag/CoreBundle/Resources/views/themes/material/Entry/entries.html.twig +++ b/src/Wallabag/CoreBundle/Resources/views/themes/material/Entry/entries.html.twig @@ -101,13 +101,13 @@ {% endif %}

    {% trans %}Export{% endtrans %}

    -- cgit v1.2.3