aboutsummaryrefslogtreecommitdiffhomepage
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/Wallabag/CoreBundle/Helper/EntriesExport.php22
-rw-r--r--src/Wallabag/CoreBundle/Resources/views/themes/material/Entry/entries.html.twig14
-rw-r--r--src/Wallabag/CoreBundle/Resources/views/themes/material/Entry/entry.html.twig2
-rw-r--r--src/Wallabag/CoreBundle/Tests/Controller/ExportControllerTest.php21
4 files changed, 49 insertions, 10 deletions
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
99 99
100 case 'xml': 100 case 'xml':
101 return $this->produceXML(); 101 return $this->produceXML();
102 case 'txt':
103 return $this->produceTXT();
102 } 104 }
103 105
104 throw new \InvalidArgumentException(sprintf('The format "%s" is not yet supported.', $format)); 106 throw new \InvalidArgumentException(sprintf('The format "%s" is not yet supported.', $format));
@@ -359,6 +361,26 @@ class EntriesExport
359 )->send(); 361 )->send();
360 } 362 }
361 363
364 private function produceTXT()
365 {
366 $content = '';
367 $bar = str_repeat('=', 100);
368 foreach ($this->entries as $entry) {
369 $content .= "\n\n".$bar."\n\n".$entry->getTitle()."\n\n".$bar."\n\n";
370 $content .= trim(preg_replace('/\s+/S', ' ', strip_tags($entry->getContent())))."\n\n";
371 }
372
373 return Response::create(
374 $content,
375 200,
376 array(
377 'Content-type' => 'text/plain',
378 'Content-Disposition' => 'attachment; filename="'.$this->title.'.txt"',
379 'Content-Transfer-Encoding' => 'UTF-8',
380 )
381 )->send();
382 }
383
362 /** 384 /**
363 * Return a Serializer object for producing processes that need it (JSON & XML). 385 * Return a Serializer object for producing processes that need it (JSON & XML).
364 * 386 *
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 @@
101 {% endif %} 101 {% endif %}
102 <h4 class="center">{% trans %}Export{% endtrans %}</h4> 102 <h4 class="center">{% trans %}Export{% endtrans %}</h4>
103 <ul> 103 <ul>
104 {% if craue_setting('export_epub') %}<li class="bold"><a class="waves-effect" href="{{ path('export_entries', { 'category': currentRoute, 'format': 'epub' }) }}">{% trans %}EPUB{% endtrans %}</a></li>{% endif %} 104 {% if craue_setting('export_epub') %}<li class="bold"><a class="waves-effect" href="{{ path('export_entries', { 'category': currentRoute, 'format': 'epub' }) }}">EPUB</a></li>{% endif %}
105 {% if craue_setting('export_mobi') %}<li class="bold"><a class="waves-effect" href="{{ path('export_entries', { 'category': currentRoute, 'format': 'mobi' }) }}">{% trans %}MOBI{% endtrans %}</a></li>{% endif %} 105 {% if craue_setting('export_mobi') %}<li class="bold"><a class="waves-effect" href="{{ path('export_entries', { 'category': currentRoute, 'format': 'mobi' }) }}">MOBI</a></li>{% endif %}
106 {% if craue_setting('export_pdf') %}<li class="bold"><a class="waves-effect" href="{{ path('export_entries', { 'category': currentRoute, 'format': 'pdf' }) }}">{% trans %}PDF{% endtrans %}</a></li>{% endif %} 106 {% if craue_setting('export_pdf') %}<li class="bold"><a class="waves-effect" href="{{ path('export_entries', { 'category': currentRoute, 'format': 'pdf' }) }}">PDF</a></li>{% endif %}
107 {% if craue_setting('export_xml') %}<li class="bold"><a class="waves-effect" href="{{ path('export_entries', { 'category': currentRoute, 'format': 'xml' }) }}">{% trans %}XML{% endtrans %}</a></li>{% endif %} 107 {% if craue_setting('export_csv') %}<li class="bold"><a class="waves-effect" href="{{ path('export_entries', { 'category': currentRoute, 'format': 'json' }) }}">JSON</a></li>{% endif %}
108 {% if craue_setting('export_csv') %}<li class="bold"><a class="waves-effect" href="{{ path('export_entries', { 'category': currentRoute, 'format': 'json' }) }}">{% trans %}JSON{% endtrans %}</a></li>{% endif %} 108 {% if craue_setting('export_json') %}<li class="bold"><a class="waves-effect" href="{{ path('export_entries', { 'category': currentRoute, 'format': 'csv' }) }}">CSV</a></li>{% endif %}
109 {% if craue_setting('export_json') %}<li class="bold"><a class="waves-effect" href="{{ path('export_entries', { 'category': currentRoute, 'format': 'csv' }) }}">{% trans %}CSV{% endtrans %}</a></li>{% endif %} 109 {% if craue_setting('export_txt') %}<li class="bold"><a class="waves-effect" href="{{ path('export_entries', { 'category': currentRoute, 'format': 'txt' }) }}">TXT</a></li>{% endif %}
110 {% if craue_setting('export_txt') %}<li class="bold"><del><a class="waves-effect" href="{{ path('export_entries', { 'category': currentRoute, 'format': 'txt' }) }}">{% trans %}TXT{% endtrans %}</a></del></li>{% endif %} 110 {% if craue_setting('export_xml') %}<li class="bold"><a class="waves-effect" href="{{ path('export_entries', { 'category': currentRoute, 'format': 'xml' }) }}">XML</a></li>{% endif %}
111 </ul> 111 </ul>
112 </div> 112 </div>
113 113
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 @@
118 {% if craue_setting('export_pdf') %}<li><a href="{{ path('export_entry', { 'id': entry.id, 'format': 'pdf' }) }}" title="Generate PDF file">PDF</a></li>{% endif %} 118 {% if craue_setting('export_pdf') %}<li><a href="{{ path('export_entry', { 'id': entry.id, 'format': 'pdf' }) }}" title="Generate PDF file">PDF</a></li>{% endif %}
119 {% if craue_setting('export_csv') %}<li><a href="{{ path('export_entry', { 'id': entry.id, 'format': 'csv' }) }}" title="Generate CSV file">CSV</a></li>{% endif %} 119 {% if craue_setting('export_csv') %}<li><a href="{{ path('export_entry', { 'id': entry.id, 'format': 'csv' }) }}" title="Generate CSV file">CSV</a></li>{% endif %}
120 {% if craue_setting('export_json') %}<li><a href="{{ path('export_entry', { 'id': entry.id, 'format': 'json' }) }}" title="Generate JSON file">JSON</a></li>{% endif %} 120 {% if craue_setting('export_json') %}<li><a href="{{ path('export_entry', { 'id': entry.id, 'format': 'json' }) }}" title="Generate JSON file">JSON</a></li>{% endif %}
121 {% if craue_setting('export_txt') %}<li><del><a href="{{ path('export_entry', { 'id': entry.id, 'format': 'txt' }) }}" title="Generate TXT file">TXT</a></del></li>{% endif %} 121 {% if craue_setting('export_txt') %}<li><a href="{{ path('export_entry', { 'id': entry.id, 'format': 'txt' }) }}" title="Generate TXT file">TXT</a></li>{% endif %}
122 {% if craue_setting('export_xml') %}<li><a href="{{ path('export_entry', { 'id': entry.id, 'format': 'xml' }) }}" title="Generate XML file">XML</a></li>{% endif %} 122 {% if craue_setting('export_xml') %}<li><a href="{{ path('export_entry', { 'id': entry.id, 'format': 'xml' }) }}" title="Generate XML file">XML</a></li>{% endif %}
123 </ul> 123 </ul>
124 </div> 124 </div>
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
41 $this->logInAs('admin'); 41 $this->logInAs('admin');
42 $client = $this->getClient(); 42 $client = $this->getClient();
43 43
44 $client->request('GET', '/export/unread.txt'); 44 $client->request('GET', '/export/unread.doc');
45 $this->assertEquals(404, $client->getResponse()->getStatusCode()); 45 $this->assertEquals(404, $client->getResponse()->getStatusCode());
46 46
47 $content = $client->getContainer() 47 $content = $client->getContainer()
@@ -49,7 +49,7 @@ class ExportControllerTest extends WallabagCoreTestCase
49 ->getRepository('WallabagCoreBundle:Entry') 49 ->getRepository('WallabagCoreBundle:Entry')
50 ->findOneByUsernameAndNotArchived('admin'); 50 ->findOneByUsernameAndNotArchived('admin');
51 51
52 $client->request('GET', '/export/'.$content->getId().'.txt'); 52 $client->request('GET', '/export/'.$content->getId().'.doc');
53 $this->assertEquals(404, $client->getResponse()->getStatusCode()); 53 $this->assertEquals(404, $client->getResponse()->getStatusCode());
54 } 54 }
55 55
@@ -119,6 +119,23 @@ class ExportControllerTest extends WallabagCoreTestCase
119 $this->assertEquals('binary', $headers->get('content-transfer-encoding')); 119 $this->assertEquals('binary', $headers->get('content-transfer-encoding'));
120 } 120 }
121 121
122 public function testTxtExport()
123 {
124 $this->logInAs('admin');
125 $client = $this->getClient();
126
127 ob_start();
128 $crawler = $client->request('GET', '/export/all.txt');
129 ob_end_clean();
130
131 $this->assertEquals(200, $client->getResponse()->getStatusCode());
132
133 $headers = $client->getResponse()->headers;
134 $this->assertEquals('text/plain; charset=UTF-8', $headers->get('content-type'));
135 $this->assertEquals('attachment; filename="All articles.txt"', $headers->get('content-disposition'));
136 $this->assertEquals('UTF-8', $headers->get('content-transfer-encoding'));
137 }
138
122 public function testCsvExport() 139 public function testCsvExport()
123 { 140 {
124 $this->logInAs('admin'); 141 $this->logInAs('admin');