diff --git a/app/config/parameters.yml.dist b/app/config/parameters.yml.dist index 52f9bccbc..b475d6370 100644 --- a/app/config/parameters.yml.dist +++ b/app/config/parameters.yml.dist @@ -51,6 +51,7 @@ parameters: export_epub: true export_mobi: true export_pdf: true + wallabag_url: http://v2.wallabag.org # default user config items_on_page: 12 diff --git a/app/config/tests/parameters.yml.dist.mysql b/app/config/tests/parameters.yml.dist.mysql index 03fdf5a60..5b29690c4 100644 --- a/app/config/tests/parameters.yml.dist.mysql +++ b/app/config/tests/parameters.yml.dist.mysql @@ -51,6 +51,7 @@ parameters: export_epub: true export_mobi: true export_pdf: true + wallabag_url: http://v2.wallabag.org # default user config items_on_page: 12 diff --git a/app/config/tests/parameters.yml.dist.pgsql b/app/config/tests/parameters.yml.dist.pgsql index 675ba6c91..efdac9617 100644 --- a/app/config/tests/parameters.yml.dist.pgsql +++ b/app/config/tests/parameters.yml.dist.pgsql @@ -51,6 +51,7 @@ parameters: export_epub: true export_mobi: true export_pdf: true + wallabag_url: http://v2.wallabag.org # default user config items_on_page: 12 diff --git a/app/config/tests/parameters.yml.dist.sqlite b/app/config/tests/parameters.yml.dist.sqlite index 258627af9..276d11471 100644 --- a/app/config/tests/parameters.yml.dist.sqlite +++ b/app/config/tests/parameters.yml.dist.sqlite @@ -51,6 +51,7 @@ parameters: export_epub: true export_mobi: true export_pdf: true + wallabag_url: http://v2.wallabag.org # default user config items_on_page: 12 diff --git a/composer.json b/composer.json index a46e990ad..b6a9c8541 100644 --- a/composer.json +++ b/composer.json @@ -55,7 +55,9 @@ "j0k3r/graby": "~1.0", "friendsofsymfony/user-bundle": "dev-master", "friendsofsymfony/oauth-server-bundle": "^1.4@dev", - "scheb/two-factor-bundle": "~1.4" + "scheb/two-factor-bundle": "~1.4", + "grandt/phpepub": "~4.0", + "wallabag/php-mobi": "~1.0.0" }, "require-dev": { "doctrine/doctrine-fixtures-bundle": "~2.2.0", @@ -63,6 +65,12 @@ "phpunit/phpunit": "~4.4", "symfony/phpunit-bridge": "~2.7.0" }, + "repositories": [ + { + "type": "vcs", + "url": "https://github.com/wallabag/phpMobi" + } + ], "scripts": { "post-install-cmd": [ "Incenteev\\ParameterHandler\\ScriptHandler::buildParameters", diff --git a/composer.lock b/composer.lock index ec11324f5..b7b5d142b 100644 --- a/composer.lock +++ b/composer.lock @@ -4,8 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file", "This file is @generated automatically" ], - "hash": "6bd09434f83c7e6b5e1c75fddbd7608b", - "content-hash": "d07d54c4cc6f4f4947c652bd659af02e", + "hash": "a9ec461e17166dcda1563dd55f6ff861", "packages": [ { "name": "doctrine/annotations", @@ -1088,6 +1087,244 @@ ], "time": "2015-11-03 10:24:23" }, + { + "name": "grandt/binstring", + "version": "1.0.0", + "source": { + "type": "git", + "url": "https://github.com/Grandt/PHPBinString.git", + "reference": "825fe2ac8a68190f651fc2dbc07b6edde18bc431" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/Grandt/PHPBinString/zipball/825fe2ac8a68190f651fc2dbc07b6edde18bc431", + "reference": "825fe2ac8a68190f651fc2dbc07b6edde18bc431", + "shasum": "" + }, + "require": { + "php": ">=5.0" + }, + "type": "library", + "autoload": { + "classmap": [ + "BinString.php", + "BinStringStatic.php" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "LGPL-2.1" + ], + "authors": [ + { + "name": "A. Grandt", + "email": "php@grandt.com", + "role": "Developer" + } + ], + "description": "A class for working around the use of mbstring.func_override", + "homepage": "https://github.com/Grandt/PHPBinString", + "keywords": [ + "binary strings", + "mbstring" + ], + "time": "2015-08-13 06:14:41" + }, + { + "name": "grandt/phpepub", + "version": "4.0.3", + "source": { + "type": "git", + "url": "https://github.com/Grandt/PHPePub.git", + "reference": "dee0c5549a8d2c6bf6a1ad5b4ee21d245b711fca" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/Grandt/PHPePub/zipball/dee0c5549a8d2c6bf6a1ad5b4ee21d245b711fca", + "reference": "dee0c5549a8d2c6bf6a1ad5b4ee21d245b711fca", + "shasum": "" + }, + "require": { + "grandt/phpresizegif": ">=1.0.3", + "grandt/relativepath": ">=1.0.1", + "php": ">=5.3.0", + "phpzip/phpzip": ">=2.0.7" + }, + "type": "library", + "autoload": { + "psr-4": { + "PHPePub\\": "src/PHPePub" + }, + "classmap": [ + "src/lib.uuid.php" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "LGPL-2.1" + ], + "authors": [ + { + "name": "A. Grandt", + "email": "php@grandt.com", + "homepage": "http://grandt.com", + "role": "Developer" + } + ], + "description": "Package to create and stream e-books in the ePub 2.0 and 3.0 formats.", + "homepage": "https://github.com/Grandt/PHPZip", + "keywords": [ + "e-book", + "epub" + ], + "time": "2015-09-15 08:47:09" + }, + { + "name": "grandt/phpresizegif", + "version": "1.0.3", + "source": { + "type": "git", + "url": "https://github.com/Grandt/PHPResizeGif.git", + "reference": "775f6810fcda2fd1d8ca881d44a80c8d310ae7fe" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/Grandt/PHPResizeGif/zipball/775f6810fcda2fd1d8ca881d44a80c8d310ae7fe", + "reference": "775f6810fcda2fd1d8ca881d44a80c8d310ae7fe", + "shasum": "" + }, + "require": { + "grandt/binstring": ">=0.2.0", + "php": ">=5.3.0" + }, + "type": "library", + "autoload": { + "psr-4": { + "grandt\\ResizeGif\\": "src/ResizeGif", + "grandt\\ResizeGif\\Files\\": "src/ResizeGif/Files", + "grandt\\ResizeGif\\Structure\\": "src/ResizeGif/Structure", + "grandt\\ResizeGif\\Debug\\": "src/ResizeGif/Debug" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "LGPL-2.1" + ], + "authors": [ + { + "name": "A. Grandt", + "email": "php@grandt.com", + "homepage": "http://grandt.com", + "role": "Developer" + } + ], + "description": "GIF89a compliant Gif resizer, including transparency and optimized gifs with sub sized elements.", + "homepage": "https://github.com/Grandt/PHPResizeGif", + "keywords": [ + "GIF89a", + "animated gif", + "gif", + "resize" + ], + "time": "2015-05-10 10:52:24" + }, + { + "name": "grandt/phpzipmerge", + "version": "1.0.4", + "source": { + "type": "git", + "url": "https://github.com/Grandt/PHPZipMerge.git", + "reference": "0b1273d3c2dbfe244904158b1dbd65a663264fb9" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/Grandt/PHPZipMerge/zipball/0b1273d3c2dbfe244904158b1dbd65a663264fb9", + "reference": "0b1273d3c2dbfe244904158b1dbd65a663264fb9", + "shasum": "" + }, + "require": { + "grandt/binstring": ">=1.0.0", + "grandt/relativepath": ">=1.0.1", + "php": ">=5.3.0" + }, + "type": "library", + "autoload": { + "psr-4": { + "ZipMerge\\": "src/ZipMerge" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "LGPL-2.1" + ], + "authors": [ + { + "name": "A. Grandt", + "email": "php@grandt.com", + "homepage": "http://grandt.com", + "role": "Developer" + }, + { + "name": "Greg Kappatos", + "homepage": "http://websiteconnect.com.au", + "role": "Developer" + } + ], + "description": "Merge and stream multiple Zip files on the fly.", + "homepage": "https://github.com/Grandt/PHPZipMerge", + "keywords": [ + "archive", + "compressed", + "compression", + "merge", + "phpzip", + "pkzip", + "stream", + "zip" + ], + "time": "2015-08-18 13:49:33" + }, + { + "name": "grandt/relativepath", + "version": "1.0.2", + "source": { + "type": "git", + "url": "https://github.com/Grandt/PHPRelativePath.git", + "reference": "19541133c24143b6295688472c54dd6ed15a5462" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/Grandt/PHPRelativePath/zipball/19541133c24143b6295688472c54dd6ed15a5462", + "reference": "19541133c24143b6295688472c54dd6ed15a5462", + "shasum": "" + }, + "require": { + "php": ">=5.0" + }, + "type": "library", + "autoload": { + "classmap": [ + "RelativePath.php" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "LGPL-2.1" + ], + "authors": [ + { + "name": "A. Grandt", + "email": "php@grandt.com", + "role": "Developer" + } + ], + "description": "A class for cleaning up/collapsing relative paths. Like real_path, but without the need for the path to exist on the filesystem.", + "homepage": "https://github.com/Grandt/PHPRelativePath", + "keywords": [ + "file path" + ], + "time": "2015-05-14 08:18:23" + }, { "name": "guzzlehttp/guzzle", "version": "5.3.0", @@ -2523,6 +2760,67 @@ ], "time": "2015-07-25 16:39:46" }, + { + "name": "phpzip/phpzip", + "version": "2.0.7", + "source": { + "type": "git", + "url": "https://github.com/Grandt/PHPZip.git", + "reference": "a43a7ce8b2f21050f8b143876c5c1661b0d65306" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/Grandt/PHPZip/zipball/a43a7ce8b2f21050f8b143876c5c1661b0d65306", + "reference": "a43a7ce8b2f21050f8b143876c5c1661b0d65306", + "shasum": "" + }, + "require": { + "grandt/binstring": ">=0.2.0", + "grandt/phpzipmerge": ">=1.0.3", + "grandt/relativepath": ">=1.0.1", + "php": ">=5.3.0" + }, + "type": "library", + "autoload": { + "psr-4": { + "PHPZip\\Zip\\": "src/Zip" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "LGPL-2.1" + ], + "authors": [ + { + "name": "Adam Schmalhofer", + "email": "Adam.Schmalhofer@gmx.de", + "role": "Developer" + }, + { + "name": "A. Grandt", + "email": "php@grandt.com", + "homepage": "http://grandt.com", + "role": "Developer" + }, + { + "name": "Greg Kappatos", + "homepage": "http://websiteconnect.com.au", + "role": "Developer" + } + ], + "description": "Package to create and stream archives of compressed files in ZIP format with PHP 5.3+", + "homepage": "https://github.com/Grandt/PHPZip", + "keywords": [ + "archive", + "compressed", + "compression", + "phpzip", + "pkzip", + "stream", + "zip" + ], + "time": "2015-04-30 06:45:53" + }, { "name": "psr/log", "version": "1.0.0", @@ -3496,6 +3794,55 @@ ], "time": "2015-11-05 12:49:06" }, + { + "name": "wallabag/php-mobi", + "version": "1.0.1", + "source": { + "type": "git", + "url": "https://github.com/wallabag/php-mobi.git", + "reference": "1cd7d022fe6be838535d6bba917d19cc48dcf487" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/wallabag/php-mobi/zipball/1cd7d022fe6be838535d6bba917d19cc48dcf487", + "reference": "1cd7d022fe6be838535d6bba917d19cc48dcf487", + "shasum": "" + }, + "require": { + "php": ">=5.3.0" + }, + "replace": { + "wallabag/phpmobi": "*" + }, + "type": "library", + "autoload": { + "files": [ + "MOBIClass/MOBI.php" + ] + }, + "license": [ + "Apache-2.0" + ], + "authors": [ + { + "name": "Sander Kromwijk", + "email": "s.kromwijk@gmail.co", + "role": "Original developer" + }, + { + "name": "Nicolas LÅ“uillet", + "email": "nicolas@loeuillet.org", + "homepage": "http://www.cdetc.fr" + } + ], + "description": "A Mobipocket file (.mobi) creator in PHP.", + "homepage": "https://github.com/wallabag/phpMobi", + "support": { + "source": "https://github.com/wallabag/php-mobi/tree/1.0.1", + "issues": "https://github.com/wallabag/php-mobi/issues" + }, + "time": "2015-10-16 08:42:42" + }, { "name": "willdurand/hateoas", "version": "v2.6.0", @@ -3602,7 +3949,7 @@ ], "authors": [ { - "name": "William Durand", + "name": "William DURAND", "email": "william.durand1@gmail.com" } ], diff --git a/src/Wallabag/CoreBundle/Controller/ExportController.php b/src/Wallabag/CoreBundle/Controller/ExportController.php new file mode 100644 index 000000000..c8ef49a2f --- /dev/null +++ b/src/Wallabag/CoreBundle/Controller/ExportController.php @@ -0,0 +1,65 @@ +get('wallabag_core.helper.entries_export') + ->setEntries($entry) + ->updateTitle('entry') + ->exportAs($format); + } catch (\InvalidArgumentException $e) { + throw new NotFoundHttpException($e->getMessage()); + } + } + + /** + * Export all entries for current user. + * + * @Route("/export/{category}.{format}", name="export_entries", requirements={ + * "format": "epub|mobi|pdf|json|xml|txt|csv", + * "category": "all|unread|starred|archive" + * }) + */ + public function downloadEntriesAction($format, $category) + { + $method = ucfirst($category); + $methodBuilder = 'getBuilderFor'.$method.'ByUser'; + $entries = $this->getDoctrine() + ->getRepository('WallabagCoreBundle:Entry') + ->$methodBuilder($this->getUser()->getId()) + ->getQuery() + ->getResult(); + + try { + return $this->get('wallabag_core.helper.entries_export') + ->setEntries($entries) + ->updateTitle($method) + ->exportAs($format); + } catch (\InvalidArgumentException $e) { + throw new NotFoundHttpException($e->getMessage()); + } + } +} diff --git a/src/Wallabag/CoreBundle/DataFixtures/ORM/LoadEntryData.php b/src/Wallabag/CoreBundle/DataFixtures/ORM/LoadEntryData.php index 7e64c5e1c..176c529e1 100644 --- a/src/Wallabag/CoreBundle/DataFixtures/ORM/LoadEntryData.php +++ b/src/Wallabag/CoreBundle/DataFixtures/ORM/LoadEntryData.php @@ -19,6 +19,7 @@ class LoadEntryData extends AbstractFixture implements OrderedFixtureInterface $entry1->setUrl('http://0.0.0.0'); $entry1->setReadingTime(11); $entry1->setDomainName('domain.io'); + $entry1->setMimetype('text/html'); $entry1->setTitle('test title entry1'); $entry1->setContent('This is my content /o/'); $entry1->setLanguage('en'); @@ -31,6 +32,7 @@ class LoadEntryData extends AbstractFixture implements OrderedFixtureInterface $entry2->setUrl('http://0.0.0.0'); $entry2->setReadingTime(1); $entry2->setDomainName('domain.io'); + $entry2->setMimetype('text/html'); $entry2->setTitle('test title entry2'); $entry2->setContent('This is my content /o/'); $entry2->setLanguage('fr'); @@ -43,6 +45,7 @@ class LoadEntryData extends AbstractFixture implements OrderedFixtureInterface $entry3->setUrl('http://0.0.0.0'); $entry3->setReadingTime(1); $entry3->setDomainName('domain.io'); + $entry3->setMimetype('text/html'); $entry3->setTitle('test title entry3'); $entry3->setContent('This is my content /o/'); $entry3->setLanguage('en'); @@ -63,6 +66,7 @@ class LoadEntryData extends AbstractFixture implements OrderedFixtureInterface $entry4->setUrl('http://0.0.0.0'); $entry4->setReadingTime(12); $entry4->setDomainName('domain.io'); + $entry4->setMimetype('text/html'); $entry4->setTitle('test title entry4'); $entry4->setContent('This is my content /o/'); $entry4->setLanguage('en'); @@ -83,6 +87,7 @@ class LoadEntryData extends AbstractFixture implements OrderedFixtureInterface $entry5->setUrl('http://0.0.0.0'); $entry5->setReadingTime(12); $entry5->setDomainName('domain.io'); + $entry5->setMimetype('text/html'); $entry5->setTitle('test title entry5'); $entry5->setContent('This is my content /o/'); $entry5->setStarred(true); @@ -97,6 +102,7 @@ class LoadEntryData extends AbstractFixture implements OrderedFixtureInterface $entry6->setUrl('http://0.0.0.0'); $entry6->setReadingTime(12); $entry6->setDomainName('domain.io'); + $entry6->setMimetype('text/html'); $entry6->setTitle('test title entry6'); $entry6->setContent('This is my content /o/'); $entry6->setArchived(true); diff --git a/src/Wallabag/CoreBundle/Entity/Entry.php b/src/Wallabag/CoreBundle/Entity/Entry.php index 9e5446a64..5aa582f8d 100644 --- a/src/Wallabag/CoreBundle/Entity/Entry.php +++ b/src/Wallabag/CoreBundle/Entity/Entry.php @@ -6,6 +6,7 @@ use Doctrine\Common\Collections\ArrayCollection; use Doctrine\ORM\Mapping as ORM; use Symfony\Component\Validator\Constraints as Assert; use Hateoas\Configuration\Annotation as Hateoas; +use JMS\Serializer\Annotation\Groups; use JMS\Serializer\Annotation\XmlRoot; use Wallabag\UserBundle\Entity\User; @@ -27,6 +28,8 @@ class Entry * @ORM\Column(name="id", type="integer") * @ORM\Id * @ORM\GeneratedValue(strategy="AUTO") + * + * @Groups({"entries_for_user", "export_all"}) */ private $id; @@ -34,6 +37,8 @@ class Entry * @var string * * @ORM\Column(name="title", type="text", nullable=true) + * + * @Groups({"entries_for_user", "export_all"}) */ private $title; @@ -42,6 +47,8 @@ class Entry * * @Assert\NotBlank() * @ORM\Column(name="url", type="text", nullable=true) + * + * @Groups({"entries_for_user", "export_all"}) */ private $url; @@ -49,6 +56,8 @@ class Entry * @var bool * * @ORM\Column(name="is_archived", type="boolean") + * + * @Groups({"entries_for_user", "export_all"}) */ private $isArchived = false; @@ -56,6 +65,8 @@ class Entry * @var bool * * @ORM\Column(name="is_starred", type="boolean") + * + * @Groups({"entries_for_user", "export_all"}) */ private $isStarred = false; @@ -63,6 +74,8 @@ class Entry * @var string * * @ORM\Column(name="content", type="text", nullable=true) + * + * @Groups({"entries_for_user", "export_all"}) */ private $content; @@ -70,6 +83,8 @@ class Entry * @var date * * @ORM\Column(name="created_at", type="datetime") + * + * @Groups({"export_all"}) */ private $createdAt; @@ -77,6 +92,8 @@ class Entry * @var date * * @ORM\Column(name="updated_at", type="datetime") + * + * @Groups({"export_all"}) */ private $updatedAt; @@ -84,6 +101,8 @@ class Entry * @var string * * @ORM\Column(name="comments", type="text", nullable=true) + * + * @Groups({"export_all"}) */ private $comments; @@ -91,6 +110,8 @@ class Entry * @var string * * @ORM\Column(name="mimetype", type="text", nullable=true) + * + * @Groups({"entries_for_user", "export_all"}) */ private $mimetype; @@ -98,6 +119,8 @@ class Entry * @var string * * @ORM\Column(name="language", type="text", nullable=true) + * + * @Groups({"entries_for_user", "export_all"}) */ private $language; @@ -105,6 +128,8 @@ class Entry * @var int * * @ORM\Column(name="reading_time", type="integer", nullable=true) + * + * @Groups({"entries_for_user", "export_all"}) */ private $readingTime; @@ -112,6 +137,8 @@ class Entry * @var string * * @ORM\Column(name="domain_name", type="text", nullable=true) + * + * @Groups({"entries_for_user", "export_all"}) */ private $domainName; @@ -119,6 +146,8 @@ class Entry * @var string * * @ORM\Column(name="preview_picture", type="text", nullable=true) + * + * @Groups({"entries_for_user", "export_all"}) */ private $previewPicture; @@ -126,17 +155,23 @@ class Entry * @var bool * * @ORM\Column(name="is_public", type="boolean", nullable=true, options={"default" = false}) + * + * @Groups({"export_all"}) */ private $isPublic; /** * @ORM\ManyToOne(targetEntity="Wallabag\UserBundle\Entity\User", inversedBy="entries") + * + * @Groups({"export_all"}) */ private $user; /** * @ORM\ManyToMany(targetEntity="Tag", inversedBy="entries", cascade={"persist"}) * @ORM\JoinTable + * + * @Groups({"entries_for_user", "export_all"}) */ private $tags; diff --git a/src/Wallabag/CoreBundle/Helper/EntriesExport.php b/src/Wallabag/CoreBundle/Helper/EntriesExport.php new file mode 100644 index 000000000..d6a4d094a --- /dev/null +++ b/src/Wallabag/CoreBundle/Helper/EntriesExport.php @@ -0,0 +1,394 @@ + +
Produced by wallabag with %EXPORT_METHOD%
+Please open an issue if you have trouble with the display of this E-Book on your device.
+ wallabagUrl = $wallabagUrl; + $this->logoPath = $logoPath; + } + + /** + * Define entries. + * + * @param array|Entry $entries An array of entries or one entry + */ + public function setEntries($entries) + { + if (!is_array($entries)) { + $this->language = $entries->getLanguage(); + $entries = array($entries); + } + + $this->entries = $entries; + + foreach ($entries as $entry) { + $this->tags[] = $entry->getTags(); + } + + return $this; + } + + /** + * Sets the category of which we want to get articles, or just one entry. + * + * @param string $method Method to get articles + */ + public function updateTitle($method) + { + $this->title = $method.' articles'; + + if ('entry' === $method) { + $this->title = $this->entries[0]->getTitle(); + } + + return $this; + } + + /** + * Sets the output format. + * + * @param string $format + */ + public function exportAs($format) + { + switch ($format) { + case 'epub': + return $this->produceEpub(); + + case 'mobi': + return $this->produceMobi(); + + case 'pdf': + return $this->producePDF(); + + case 'csv': + return $this->produceCSV(); + + case 'json': + return $this->produceJSON(); + + case 'xml': + return $this->produceXML(); + } + + throw new \InvalidArgumentException(sprintf('The format "%s" is not yet supported.', $format)); + } + + /** + * Use PHPePub to dump a .epub file. + */ + private function produceEpub() + { + /* + * Start and End of the book + */ + $content_start = + "\n" + ."\n" + .'' + ."\n" + ."