X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=src%2FWallabag%2FCoreBundle%2FHelper%2FEntriesExport.php;h=d3b7ee3e7265dcf3d2ac59ba6658ffe7b93c72b4;hb=3b07d019379106d6786121b3208d0e396e1ae40a;hp=c14f9d72fa46d0a524e5e932d0417ee147b5aee5;hpb=268e9e7277d470dbd65b4eaa70c247ef35a95a3d;p=github%2Fwallabag%2Fwallabag.git diff --git a/src/Wallabag/CoreBundle/Helper/EntriesExport.php b/src/Wallabag/CoreBundle/Helper/EntriesExport.php index c14f9d72..d3b7ee3e 100644 --- a/src/Wallabag/CoreBundle/Helper/EntriesExport.php +++ b/src/Wallabag/CoreBundle/Helper/EntriesExport.php @@ -2,13 +2,17 @@ namespace Wallabag\CoreBundle\Helper; +use JMS\Serializer; +use JMS\Serializer\SerializationContext; +use JMS\Serializer\SerializerBuilder; use PHPePub\Core\EPub; use PHPePub\Core\Structure\OPF\DublinCore; use Symfony\Component\HttpFoundation\Response; -use JMS\Serializer; -use JMS\Serializer\SerializerBuilder; -use JMS\Serializer\SerializationContext; +use Craue\ConfigBundle\Util\Config; +/** + * This class doesn't have unit test BUT it's fully covered by a functional test with ExportControllerTest. + */ class EntriesExport { private $wallabagUrl; @@ -24,12 +28,12 @@ class EntriesExport wallabagUrl = $wallabagUrl; + $this->wallabagUrl = $craueConfig->get('wallabag_url'); $this->logoPath = $logoPath; } @@ -95,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)); @@ -303,7 +309,8 @@ class EntriesExport array( $entry->getTitle(), $entry->getURL(), - $entry->getContent(), + // remove new line to avoid crazy results + str_replace(array("\r\n", "\r", "\n"), '', $entry->getContent()), implode(', ', $entry->getTags()->toArray()), $entry->getMimetype(), $entry->getLanguage(), @@ -354,6 +361,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). * @@ -363,7 +389,11 @@ class EntriesExport { $serializer = SerializerBuilder::create()->build(); - return $serializer->serialize($this->entries, $format, SerializationContext::create()->setGroups(array('entries_for_user'))); + return $serializer->serialize( + $this->entries, + $format, + SerializationContext::create()->setGroups(array('entries_for_user')) + ); } /**