mirror of
https://github.com/wallabag/wallabag.git
synced 2025-01-31 07:47:28 +01:00
commit
22a267aeff
@ -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).
|
||||
*
|
||||
|
@ -101,13 +101,13 @@
|
||||
{% endif %}
|
||||
<h4 class="center">{% trans %}Export{% endtrans %}</h4>
|
||||
<ul>
|
||||
{% 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 %}
|
||||
{% 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 %}
|
||||
{% 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 %}
|
||||
{% 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 %}
|
||||
{% 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 %}
|
||||
{% 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 %}
|
||||
{% 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 %}
|
||||
{% if craue_setting('export_epub') %}<li class="bold"><a class="waves-effect" href="{{ path('export_entries', { 'category': currentRoute, 'format': 'epub' }) }}">EPUB</a></li>{% endif %}
|
||||
{% if craue_setting('export_mobi') %}<li class="bold"><a class="waves-effect" href="{{ path('export_entries', { 'category': currentRoute, 'format': 'mobi' }) }}">MOBI</a></li>{% endif %}
|
||||
{% if craue_setting('export_pdf') %}<li class="bold"><a class="waves-effect" href="{{ path('export_entries', { 'category': currentRoute, 'format': 'pdf' }) }}">PDF</a></li>{% endif %}
|
||||
{% if craue_setting('export_csv') %}<li class="bold"><a class="waves-effect" href="{{ path('export_entries', { 'category': currentRoute, 'format': 'json' }) }}">JSON</a></li>{% endif %}
|
||||
{% if craue_setting('export_json') %}<li class="bold"><a class="waves-effect" href="{{ path('export_entries', { 'category': currentRoute, 'format': 'csv' }) }}">CSV</a></li>{% endif %}
|
||||
{% if craue_setting('export_txt') %}<li class="bold"><a class="waves-effect" href="{{ path('export_entries', { 'category': currentRoute, 'format': 'txt' }) }}">TXT</a></li>{% endif %}
|
||||
{% if craue_setting('export_xml') %}<li class="bold"><a class="waves-effect" href="{{ path('export_entries', { 'category': currentRoute, 'format': 'xml' }) }}">XML</a></li>{% endif %}
|
||||
</ul>
|
||||
</div>
|
||||
|
||||
|
@ -118,7 +118,7 @@
|
||||
{% if craue_setting('export_pdf') %}<li><a href="{{ path('export_entry', { 'id': entry.id, 'format': 'pdf' }) }}" title="Generate PDF file">PDF</a></li>{% endif %}
|
||||
{% if craue_setting('export_csv') %}<li><a href="{{ path('export_entry', { 'id': entry.id, 'format': 'csv' }) }}" title="Generate CSV file">CSV</a></li>{% endif %}
|
||||
{% if craue_setting('export_json') %}<li><a href="{{ path('export_entry', { 'id': entry.id, 'format': 'json' }) }}" title="Generate JSON file">JSON</a></li>{% endif %}
|
||||
{% 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 %}
|
||||
{% if craue_setting('export_txt') %}<li><a href="{{ path('export_entry', { 'id': entry.id, 'format': 'txt' }) }}" title="Generate TXT file">TXT</a></li>{% endif %}
|
||||
{% if craue_setting('export_xml') %}<li><a href="{{ path('export_entry', { 'id': entry.id, 'format': 'xml' }) }}" title="Generate XML file">XML</a></li>{% endif %}
|
||||
</ul>
|
||||
</div>
|
||||
|
@ -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');
|
||||
|
Loading…
x
Reference in New Issue
Block a user