From: Nicolas LÅ“uillet Date: Thu, 4 Feb 2016 19:53:42 +0000 (+0100) Subject: Merge pull request #1633 from wallabag/exporttxt X-Git-Tag: 2.0.0-beta.1~54 X-Git-Url: https://git.immae.eu/?a=commitdiff_plain;h=22a267aeffa9e5b7d63e6a149501f9a1448e925f;hp=27c837dcd1640a7f5f0ed197e882eefd53ba8273;p=github%2Fwallabag%2Fwallabag.git Merge pull request #1633 from wallabag/exporttxt Exporttxt --- diff --git a/src/Wallabag/CoreBundle/Helper/EntriesExport.php b/src/Wallabag/CoreBundle/Helper/EntriesExport.php index 965a40b6..c9aac6e5 100644 --- a/src/Wallabag/CoreBundle/Helper/EntriesExport.php +++ b/src/Wallabag/CoreBundle/Helper/EntriesExport.php @@ -99,6 +99,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 +361,26 @@ class EntriesExport )->send(); } + private function produceTXT() + { + $content = ''; + $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"; + } + + 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/entries.html.twig b/src/Wallabag/CoreBundle/Resources/views/themes/material/Entry/entries.html.twig index 8ad24fbf..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 %}

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 %} 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');