namespace Wallabag\CoreBundle\Helper;
+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 Symfony\Component\Serializer\Serializer;
-use Symfony\Component\Serializer\Encoder\XmlEncoder;
-use Symfony\Component\Serializer\Encoder\JsonEncoder;
-use Symfony\Component\Serializer\Normalizer\ObjectNormalizer;
+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;
</div';
/**
- * @param string $wallabagUrl Wallabag instance url
+ * @param Config $craueConfig CraueConfig instance to get wallabag instance url from database
* @param string $logoPath Path to the logo FROM THE BUNDLE SCOPE
*/
- public function __construct($wallabagUrl, $logoPath)
+ public function __construct(Config $craueConfig, $logoPath)
{
- $this->wallabagUrl = $wallabagUrl;
+ $this->wallabagUrl = $craueConfig->get('wallabag_url');
$this->logoPath = $logoPath;
}
case 'xml':
return $this->produceXML();
+ case 'txt':
+ return $this->produceTXT();
}
throw new \InvalidArgumentException(sprintf('The format "%s" is not yet supported.', $format));
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(),
)->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).
*
*/
private function prepareSerializingContent($format)
{
- $encoders = array(new XmlEncoder(), new JsonEncoder());
- $normalizers = array(new ObjectNormalizer());
- $normalizers[0]->setIgnoredAttributes(array('user', 'createdAt', 'updatedAt'));
- $serializer = new Serializer($normalizers, $encoders);
+ $serializer = SerializerBuilder::create()->build();
- return $serializer->serialize($this->entries, $format);
+ return $serializer->serialize(
+ $this->entries,
+ $format,
+ SerializationContext::create()->setGroups(array('entries_for_user'))
+ );
}
/**