+
+ rewind($handle);
+ $output = stream_get_contents($handle);
+ fclose($handle);
+
+ return Response::create(
+ $output,
+ 200,
+ [
+ 'Content-type' => 'application/csv',
+ 'Content-Disposition' => 'attachment; filename="' . $this->title . '.csv"',
+ 'Content-Transfer-Encoding' => 'UTF-8',
+ ]
+ );
+ }
+
+ /**
+ * Dump a JSON file.
+ *
+ * @return Response
+ */
+ private function produceJson()
+ {
+ return Response::create(
+ $this->prepareSerializingContent('json'),
+ 200,
+ [
+ 'Content-type' => 'application/json',
+ 'Content-Disposition' => 'attachment; filename="' . $this->title . '.json"',
+ 'Content-Transfer-Encoding' => 'UTF-8',
+ ]
+ );
+ }
+
+ /**
+ * Dump a XML file.
+ *
+ * @return Response
+ */
+ private function produceXml()
+ {
+ return Response::create(
+ $this->prepareSerializingContent('xml'),
+ 200,
+ [
+ 'Content-type' => 'application/xml',
+ 'Content-Disposition' => 'attachment; filename="' . $this->title . '.xml"',
+ 'Content-Transfer-Encoding' => 'UTF-8',
+ ]
+ );
+ }
+
+ /**
+ * Dump a TXT file.
+ *
+ * @return Response
+ */
+ 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,
+ [
+ 'Content-type' => 'text/plain',
+ 'Content-Disposition' => 'attachment; filename="' . $this->title . '.txt"',
+ 'Content-Transfer-Encoding' => 'UTF-8',
+ ]
+ );
+ }
+
+ /**
+ * Return a Serializer object for producing processes that need it (JSON & XML).
+ *
+ * @param string $format
+ *
+ * @return Serializer
+ */
+ private function prepareSerializingContent($format)
+ {
+ $serializer = SerializerBuilder::create()->build();
+
+ return $serializer->serialize(
+ $this->entries,
+ $format,
+ SerializationContext::create()->setGroups(['entries_for_user'])
+ );
+ }
+
+ /**
+ * Return a kind of footer / information for the epub.
+ *
+ * @param string $type Generator of the export, can be: tdpdf, PHPePub, PHPMobi
+ *
+ * @return string
+ */
+ private function getExportInformation($type)
+ {
+ $info = str_replace('%EXPORT_METHOD%', $type, $this->footerTemplate);
+
+ if ('tcpdf' === $type) {
+ return str_replace('%IMAGE%', '<img src="' . $this->logoPath . '" />', $info);
+ }
+
+ return str_replace('%IMAGE%', '', $info);