]> git.immae.eu Git - github/wallabag/wallabag.git/blobdiff - src/Wallabag/CoreBundle/Helper/EntriesExport.php
put the equals bar outside the loop
[github/wallabag/wallabag.git] / src / Wallabag / CoreBundle / Helper / EntriesExport.php
index 965a40b6a1ec190bb06c4f0bb0956fcd0f709ada..3f1fc43cc22e5b1dc8b4496ac430bdebf8d6a57c 100644 (file)
@@ -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).
      *