]> git.immae.eu Git - github/wallabag/wallabag.git/blobdiff - src/Wallabag/CoreBundle/Helper/EntriesExport.php
better display for txt
[github/wallabag/wallabag.git] / src / Wallabag / CoreBundle / Helper / EntriesExport.php
index 965a40b6a1ec190bb06c4f0bb0956fcd0f709ada..6e06086fcf93f56fc80fa08db8dc5f149f5894f6 100644 (file)
@@ -6,6 +6,7 @@ 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;
@@ -99,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));
@@ -359,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).
      *