diff --git a/src/Wallabag/CoreBundle/Helper/EntriesExport.php b/src/Wallabag/CoreBundle/Helper/EntriesExport.php
index 965a40b6a..c9aac6e54 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 8ad24fbf8..3b7698f35 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 dad96187c..2d3fd5169 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 aaa264994..76c980557 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');