X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=src%2FWallabag%2FCoreBundle%2FHelper%2FEntriesExport.php;h=6e06086fcf93f56fc80fa08db8dc5f149f5894f6;hb=365a38984e32d152ec0170991a61bf704756cf1e;hp=31a80d6e3283b12365f7fe2e228a20ffcde372b4;hpb=1930c19d8214c05ceefac5ac011a6b6e7e4a983d;p=github%2Fwallabag%2Fwallabag.git diff --git a/src/Wallabag/CoreBundle/Helper/EntriesExport.php b/src/Wallabag/CoreBundle/Helper/EntriesExport.php index 31a80d6e..6e06086f 100644 --- a/src/Wallabag/CoreBundle/Helper/EntriesExport.php +++ b/src/Wallabag/CoreBundle/Helper/EntriesExport.php @@ -6,8 +6,10 @@ 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; /** * This class doesn't have unit test BUT it's fully covered by a functional test with ExportControllerTest. @@ -27,12 +29,12 @@ class EntriesExport wallabagUrl = $wallabagUrl; + $this->wallabagUrl = $craueConfig->get('wallabag_url'); $this->logoPath = $logoPath; } @@ -98,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)); @@ -358,6 +362,25 @@ class EntriesExport )->send(); } + private function produceTXT() + { + $content = ''; + foreach ($this->entries as $entry) { + $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, + 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). *