diff --git a/composer.json b/composer.json index afef9e30b..cbd57676d 100755 --- a/composer.json +++ b/composer.json @@ -38,7 +38,8 @@ "imagine/imagine": "dev-master", "symfony/icu": "1.0", "swiftmailer/swiftmailer": "5.0.*", - "symfony/serializer": "2.3.*" + "symfony/serializer": "2.3.*", + "dompdf/dompdf": "dev-master" }, "require-dev" : { "phpunit/phpunit": "3.7.*", diff --git a/composer.lock b/composer.lock index a89768ef1..3539bd208 100755 --- a/composer.lock +++ b/composer.lock @@ -3,8 +3,49 @@ "This file locks the dependencies of your project to a known state", "Read more about it at http://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file" ], - "hash": "097481390dc87b3482d895b3b6a65479", + "hash": "39e5fa13bfa3de21f03854c90a076713", "packages": [ + { + "name": "dompdf/dompdf", + "version": "dev-master", + "source": { + "type": "git", + "url": "https://github.com/dompdf/dompdf.git", + "reference": "3a8a09240159ac084f0c4b607eb12ca83ddbe318" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/dompdf/dompdf/zipball/3a8a09240159ac084f0c4b607eb12ca83ddbe318", + "reference": "3a8a09240159ac084f0c4b607eb12ca83ddbe318", + "shasum": "" + }, + "require": { + "phenx/php-font-lib": "0.2.*" + }, + "type": "library", + "autoload": { + "classmap": [ + "include/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "LGPL" + ], + "authors": [ + { + "name": "Fabien Ménager", + "email": "fabien.menager@gmail.com" + }, + { + "name": "Brian Sweeney", + "email": "eclecticgeek@gmail.com" + } + ], + "description": "DOMPDF is a CSS 2.1 compliant HTML to PDF converter", + "homepage": "https://github.com/dompdf/dompdf", + "time": "2013-09-04 20:59:58" + }, { "name": "imagine/imagine", "version": "dev-master", @@ -208,6 +249,40 @@ "homepage": "http://leafo.net/lessphp/", "time": "2013-08-09 17:09:19" }, + { + "name": "phenx/php-font-lib", + "version": "0.2.1", + "source": { + "type": "git", + "url": "https://github.com/PhenX/php-font-lib.git", + "reference": "42a1ca6d19f14076911a118705b771c3a5a8b179" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/PhenX/php-font-lib/zipball/42a1ca6d19f14076911a118705b771c3a5a8b179", + "reference": "42a1ca6d19f14076911a118705b771c3a5a8b179", + "shasum": "" + }, + "type": "library", + "autoload": { + "classmap": [ + "classes/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "LGPL" + ], + "authors": [ + { + "name": "Fabien Ménager", + "email": "fabien.menager@gmail.com" + } + ], + "description": "A library to read, parse, export and make subsets of different types of font files.", + "homepage": "https://github.com/PhenX/php-font-lib", + "time": "2013-02-22 23:30:49" + }, { "name": "propel/propel", "version": "dev-master", @@ -2143,6 +2218,7 @@ "ptachoire/cssembed": 20, "simplepie/simplepie": 20, "imagine/imagine": 20, + "dompdf/dompdf": 20, "fzaninotto/faker": 20, "maximebf/debugbar": 20 }, diff --git a/core/bootstrap.php b/core/bootstrap.php index a75190704..f722b355f 100755 --- a/core/bootstrap.php +++ b/core/bootstrap.php @@ -12,6 +12,7 @@ define('THELIA_MODULE_DIR' , THELIA_LOCAL_DIR . 'modules/'); define('THELIA_WEB_DIR' , THELIA_ROOT . 'web/'); define('THELIA_TEMPLATE_DIR' , THELIA_ROOT . 'templates/'); define('DS', DIRECTORY_SEPARATOR); +define('DOMPDF_ENABLE_AUTOLOAD', false); $loader = require __DIR__ . "/vendor/autoload.php"; diff --git a/core/lib/Thelia/Action/Pdf.php b/core/lib/Thelia/Action/Pdf.php new file mode 100644 index 000000000..82a6a86f4 --- /dev/null +++ b/core/lib/Thelia/Action/Pdf.php @@ -0,0 +1,74 @@ +. */ +/* */ +/*************************************************************************************/ + +namespace Thelia\Action; +use Symfony\Component\EventDispatcher\EventSubscriberInterface; +use Thelia\Core\Event\PdfEvent; +use Thelia\Core\Event\TheliaEvents; + + +/** + * Class Pdf + * @package Thelia\Action + * @author Manuel Raynaud + */ +class Pdf extends BaseAction implements EventSubscriberInterface +{ + + public function generatePdf(PdfEvent $event) + { + require_once THELIA_ROOT . '/core/vendor/dompdf/dompdf/dompdf_config.inc.php'; + + $domPdf = new \DOMPDF(); + $domPdf->load_html($event->getContent()); + + $event->setPdf($domPdf->output()); + } + + /** + * Returns an array of event names this subscriber wants to listen to. + * + * The array keys are event names and the value can be: + * + * * The method name to call (priority defaults to 0) + * * An array composed of the method name to call and the priority + * * An array of arrays composed of the method names to call and respective + * priorities, or 0 if unset + * + * For instance: + * + * * array('eventName' => 'methodName') + * * array('eventName' => array('methodName', $priority)) + * * array('eventName' => array(array('methodName1', $priority), array('methodName2')) + * + * @return array The event names to listen to + * + * @api + */ + public static function getSubscribedEvents() + { + array( + TheliaEvents::GENERATE_PDF => array("generatePdf", 128) + ); + } +} \ No newline at end of file diff --git a/core/lib/Thelia/Core/Event/PdfEvent.php b/core/lib/Thelia/Core/Event/PdfEvent.php new file mode 100644 index 000000000..ef8e68503 --- /dev/null +++ b/core/lib/Thelia/Core/Event/PdfEvent.php @@ -0,0 +1,68 @@ +. */ +/* */ +/*************************************************************************************/ + +namespace Thelia\Core\Event; + + +/** + * Class PdfEvent + * @package Thelia\Core\Event + * @author Manuel Raynaud + */ +class PdfEvent extends ActionEvent +{ + protected $content; + + protected $pdf; + + public function __construct($content) + { + $this->content = $content; + } + + /** + * @param mixed $content + */ + public function setContent($content) + { + $this->content = $content; + } + + /** + * @return mixed + */ + public function getContent() + { + return $this->content; + } + + public function setPdf($pdf) + { + $this->pdf = $pdf; + } + + public function getPdf() + { + return $this->pdf; + } +} \ No newline at end of file diff --git a/core/lib/Thelia/Core/Event/TheliaEvents.php b/core/lib/Thelia/Core/Event/TheliaEvents.php index 29f45dd6d..9ffe08bcb 100755 --- a/core/lib/Thelia/Core/Event/TheliaEvents.php +++ b/core/lib/Thelia/Core/Event/TheliaEvents.php @@ -597,4 +597,6 @@ final class TheliaEvents */ const GENERATE_REWRITTENURL = 'action.generate_rewritenurl'; + const GENERATE_PDF = 'thelia.generatePdf'; + }