From 429230b9901b5509c66546a1db2fbb6f62f9caf3 Mon Sep 17 00:00:00 2001 From: Vincent Vanwaelscappel Date: Fri, 18 Oct 2024 12:57:42 +0200 Subject: [PATCH] wait #7131 @7 --- app/Fluidbook/Compiler/Compiler.php | 26 ++- app/Fluidbook/Compiler/PDF.php | 7 + .../Services/FormOperation.php | 158 ++++++++++++++++++ app/Models/FluidbookHealthIssues.php | 14 ++ app/Models/FluidbookPublication.php | 2 + app/Models/Traits/PublicationSettings.php | 3 + 6 files changed, 202 insertions(+), 8 deletions(-) create mode 100644 app/Http/Controllers/Admin/Operations/FluidbookPublication/Services/FormOperation.php diff --git a/app/Fluidbook/Compiler/Compiler.php b/app/Fluidbook/Compiler/Compiler.php index 5ff82878d..b2a063441 100644 --- a/app/Fluidbook/Compiler/Compiler.php +++ b/app/Fluidbook/Compiler/Compiler.php @@ -110,8 +110,10 @@ class Compiler extends Base implements CompilerInterface, IVirtualDirectoryError ['js/libs/gal/gal.js', 'js/libs/gal/gal.filesystem.js',], 'raphael' => - ['js/libs/raphael/raphael.min.js', - 'js/libs/gsap/plugins/RaphaelPlugin.min.js'], + [ + 'js/libs/raphael/raphael.min.js', + //'js/libs/gsap/plugins/RaphaelPlugin.min.js' + ], 'countup' => ['js/libs/countup/countup.min.js'], 'clipboard' => ['js/libs/clipboard.min.js'], @@ -577,10 +579,10 @@ class Compiler extends Base implements CompilerInterface, IVirtualDirectoryError if ($this->config->form == 'bulle') { $this->addJsLib('bulle', 'js/libs/fluidbook/forms/fluidbook.form.bulle.js'); } else if ($this->config->form == 'bourbon') { - $this->addJsLib('parsley', 'js/libs/parsley.min.js'); + $this->addParsley(); $this->addJsLib('bourbon', 'js/libs/fluidbook/forms/fluidbook.form.bourbon.js'); } else if ($this->config->form == 'avery') { - $this->addJsLib('parsley', 'js/libs/parsley.min.js'); + $this->addParsley(); $this->addJsLib('avery', 'js/libs/fluidbook/forms/fluidbook.form.avery.js'); $this->addLess('form/avery'); $this->writeCountries(); @@ -588,6 +590,12 @@ class Compiler extends Base implements CompilerInterface, IVirtualDirectoryError $this->config->seoArticles = $this->seoArticles; } + protected function addParsley() + { + $this->addJsLib('parsley', ['js/libs/parsley/parsley.min.js', 'js/libs/parsley/i18n/' . mb_strtolower($this->config->defaultLang) . '.js']); + + } + protected function checkPageLabels() { @@ -756,6 +764,8 @@ class Compiler extends Base implements CompilerInterface, IVirtualDirectoryError $this->log('PWA written'); $this->writeExtras(); $this->log('Extras written'); + $this->writePDF(); + // Adding js libraries or CSS must be done before this. $this->populateConfig(); $this->log('Config populated'); $this->writeCSS($linksCSS); @@ -1050,7 +1060,6 @@ class Compiler extends Base implements CompilerInterface, IVirtualDirectoryError $favicon .= ''; } - $print = $this->writePDF(); $message = 'An error occured when trying to show the publication. Please check if JavaScript is enabled or try to update your browser.'; $this->log('Got index vars 4'); @@ -1140,7 +1149,7 @@ class Compiler extends Base implements CompilerInterface, IVirtualDirectoryError $pwa = $this->getPWAMarkup(); $this->log('Got index vars 5'); - $vars = array('lang', 'titre', 'credits', 'style', 'script', 'pagesContents', 'print', 'splash', 'splashstyles', 'cache', 'bgcolor', 'message', 'favicon', 'svg', 'beginbody', 'csp', 'opengraph', 'twittercard', 'description', 'console', 'pwa'); + $vars = array('lang', 'titre', 'credits', 'style', 'script', 'pagesContents', 'splash', 'splashstyles', 'cache', 'bgcolor', 'message', 'favicon', 'svg', 'beginbody', 'csp', 'opengraph', 'twittercard', 'description', 'console', 'pwa'); $res = []; foreach ($vars as $v) { @@ -1574,7 +1583,7 @@ class Compiler extends Base implements CompilerInterface, IVirtualDirectoryError $dirminimized = Files::mkdir($this->compiledAssets . '/js/min'); foreach ($finals as $jsfinal => $files) { - $mintime = 0; + $hash = hash('sha256', json_encode($files)); $minimized = $dirminimized . $jsfinal . '-' . $hash . '-min.js'; if (file_exists($minimized) && filesize($minimized) > 0) { @@ -1607,6 +1616,7 @@ class Compiler extends Base implements CompilerInterface, IVirtualDirectoryError foreach ($files as $file) { $f = $this->assets . '/' . $file; if (!file_exists($f)) { + FluidbookHealthIssues::addIssue($this->book_id, FluidbookHealthIssues::TYPE_MISSING_JS, ['file' => $f]); continue; } if (strpos($f, '.min.') === false) { @@ -2035,7 +2045,7 @@ class Compiler extends Base implements CompilerInterface, IVirtualDirectoryError $destination_css = $tmp . '/' . $f . '.css'; if (!file_exists($source_less)) { - die($source_less); + FluidbookHealthIssues::addIssue($this->book_id, FluidbookHealthIssues::TYPE_MISSING_CSS, ['file' => $source_less]); continue; } diff --git a/app/Fluidbook/Compiler/PDF.php b/app/Fluidbook/Compiler/PDF.php index e3df5134a..943a1566a 100644 --- a/app/Fluidbook/Compiler/PDF.php +++ b/app/Fluidbook/Compiler/PDF.php @@ -13,6 +13,13 @@ trait PDF return; } + if ($this->fluidbookSettings->pdfBeforeForm) { + $n = mb_strtolower($this->fluidbookSettings->pdfBeforeForm); + $this->addJsLib('pdfform', ['js/libs/fluidbook/forms/fluidbook.form.' . $n . '.js']); + $this->addParsley(); + $this->addLess('form/' . $n); + } + $res = \App\Fluidbook\PDF::compilePDF($this->getFluidbook()); $this->config->pdfName = str_replace('.pdf', '', $this->config->pdfName); if (!$this->config->pdfName) { diff --git a/app/Http/Controllers/Admin/Operations/FluidbookPublication/Services/FormOperation.php b/app/Http/Controllers/Admin/Operations/FluidbookPublication/Services/FormOperation.php new file mode 100644 index 000000000..951f0c382 --- /dev/null +++ b/app/Http/Controllers/Admin/Operations/FluidbookPublication/Services/FormOperation.php @@ -0,0 +1,158 @@ +withoutMiddleware([CheckIfAdmin::class, VerifyCsrfToken::class]); + } + } + + public function form() + { + $f = Str::ucfirst(Str::camel(request('form'))); + if (method_exists($this, 'handleForm' . $f)) { + $res = $this->{"handleForm{$f}"}(); + } else { + return ['ok' => false]; + } + return response()->json($res); + } + + public function handleFormChristaud() + { + $dep = ["01" => "lyon@christaud.com", + "02" => "reims@christaud.com", + "03" => "clermont@christaud.com", + "04" => "gap@christaud.com", + "05" => "gap@christaud.com", + "06" => "grenoble@christaud.com", + "07" => "valence@christaud.com", + "08" => "reims@christaud.com", + "09" => "grenoble@christaud.com", + "10" => "reims@christaud.com", + "11" => "grenoble@christaud.com", + "12" => "clermont@christaud.com", + "13" => "grenoble@christaud.com", + "14" => "caen@billmat.fr", + "15" => "clermont@christaud.com", + "16" => "aquitaine@christaud.com", + "17" => "aquitaine@christaud.com", + "18" => "tours@billmat.fr", + "19" => "clermont@christaud.com", + "2A" => "grenoble@christaud.com", + "2B" => "grenoble@christaud.com", + "21" => "lyon@christaud.com", + "22" => "guingamp@billmat.fr", + "23" => "clermont@christaud.com", + "24" => "aquitaine@christaud.com", + "25" => "etupes@christaud.com", + "26" => "valence@christaud.com", + "27" => "rouen@billmat.fr", + "28" => "tours@billmat.fr", + "29" => "guingamp@billmat.fr", + "30" => "valence@christaud.com", + "31" => "aquitaine@christaud.com", + "32" => "aquitaine@christaud.com", + "33" => "aquitaine@christaud.com", + "34" => "grenoble@christaud.com", + "35" => "rennes@billmat.fr", + "36" => "tours@billmat.fr", + "37" => "tours@billmat.fr", + "38" => "grenoble@christaud.com", + "39" => "etupes@christaud.com", + "40" => "aquitaine@christaud.com", + "41" => "tours@billmat.fr", + "42" => "talaudiere@christaud.com", + "43" => "le-puy@christaud.com", + "44" => "rennes@billmat.fr", + "45" => "lagny@christaud.com", + "46" => "castelculier@christaud.com", + "47" => "castelculier@christaud.com", + "48" => "le-puy@christaud.com", + "49" => "rennes@billmat.fr", + "50" => "coutances@billmat.fr", + "51" => "reims@christaud.com", + "52" => "reims@christaud.com", + "53" => "rennes@billmat.fr", + "54" => "haguenau@christaud.com", + "55" => "reims@christaud.com", + "56" => "lorientàbillmat.fr", + "57" => "woustviller@christaud.com", + "58" => "clermont@christaud.com", + "59" => "lens@christaud.com", + "60" => "rouen@billmat.fr", + "61" => "caen@billmat.fr", + "62" => "lens@christaud.com", + "63" => "clermont@christaud.com", + "64" => "aquitaine@christaud.com", + "65" => "aquitaine@christaud.com", + "66" => "grenoble@christaud.com", + "67" => "haguenau@christaud.com", + "68" => "richwiller@christaud.com", + "69" => "lyon@christaud.com", + "70" => "richwiller@christaud.com", + "71" => "lyon@christaud.com", + "72" => "rennes@billmat.fr", + "73" => "savoies@christaud.com", + "74" => "savoies@christaud.com", + "75" => "lagny@christaud.com", + "76" => "rouen@billmat.fr", + "77" => "lagny@christaud.com", + "78" => "lagny@christaud.com", + "79" => "tours@billmat.fr", + "80" => "lens@christaud.com", + "81" => "castelculier@christaud.com", + "82" => "castelculier@christaud.com", + "83" => "grenoble@christaud.com", + "84" => "valence@christaud.com", + "85" => "rennes@billmat.fr", + "86" => "tours@billmat.fr", + "87" => "clermont@christaud.com", + "88" => "richwiller@christaud.com", + "89" => "reims@christaud.com", + "90" => "richwiller@christaud.com", + "91" => "lagny@christaud.com", + "92" => "lagny@christaud.com", + "93" => "lagny@christaud.com", + "94" => "lagny@christaud.com", + "95" => "lagny@christaud.com", + "971" => "grenoble@christaud.com", + "972" => "grenoble@christaud.com", + "973" => "grenoble@christaud.com", + "974" => "grenoble@christaud.com", + "976" => "grenoble@christaud.com"]; + $labels = ['fluidbook_id' => 'Fluidbook', 'firstname' => 'Prénom', 'name' => 'Nom', 'company' => 'Société', 'email' => 'E-mail', 'phone' => 'Téléphone', 'departement' => 'Département']; + + $body = ''; + foreach ($labels as $name => $label) { + $body .= $label . ' : ' . request($name) . "\r\n"; + if ($name === 'departement' && isset($dep[request($name)])) { + $cc = $dep[request($name)]; + } + } + $fluidbook_id = request('fluidbook_id'); + + dispatch(function () use ($body, $cc, $fluidbook_id) { + Mail::raw($body, function (Message $message) use ($body, $cc, $fluidbook_id) { + $message->subject('[Fluidbook #' . $fluidbook_id . '] Téléchargement du PDF'); + $message->to('contact@christaud.com'); + if (isset($cc)) { + $message->cc($cc); + } + }); + }); + + return ['ok' => true]; + } +} diff --git a/app/Models/FluidbookHealthIssues.php b/app/Models/FluidbookHealthIssues.php index 9bab3e746..a10fda2ca 100644 --- a/app/Models/FluidbookHealthIssues.php +++ b/app/Models/FluidbookHealthIssues.php @@ -22,6 +22,8 @@ class FluidbookHealthIssues extends ToolboxModel const TYPE_TIMEOUT_MAKE_SVG = 9; const TYPE_NOT_VALID_IMAGE_IN_LINK = 10; const TYPE_TABS_INVALID_SVG = 11; + const TYPE_MISSING_JS=12; + const TYPE_MISSING_CSS=13; const CRIT_ERROR = 5; const CRIT_WARNING = 3; @@ -165,6 +167,18 @@ class FluidbookHealthIssues extends ToolboxModel 'text' => 'Le format du SVG des onglets est invalide. L\'erreur suivante est retournée : :error', 'fixText' => __('Corriger le SVG'), ], + static::TYPE_MISSING_JS => + [ + 'summary' => __('Bibliothèque JS introuvable'), + 'criticality' => self::CRIT_WARNING, + 'text' => 'Fichier JS indisponible : :file. Certaines fonctionnalités peuvent ne pas fonctionner.', + ], + static::TYPE_MISSING_CSS=> + [ + 'summary' => __('Feuille de style introuvable'), + 'criticality' => self::CRIT_WARNING, + 'text' => 'Feuille de style introuvable : :file. Certaines fonctionnalités peuvent ne pas fonctionner.', + ], ]; } diff --git a/app/Models/FluidbookPublication.php b/app/Models/FluidbookPublication.php index a918e2d22..8857d276e 100644 --- a/app/Models/FluidbookPublication.php +++ b/app/Models/FluidbookPublication.php @@ -29,6 +29,7 @@ use App\Http\Controllers\Admin\Operations\FluidbookPublication\LinksOperation; use App\Http\Controllers\Admin\Operations\FluidbookPublication\PreviewOperation; use App\Http\Controllers\Admin\Operations\FluidbookPublication\Services\BastideOperation; use App\Http\Controllers\Admin\Operations\FluidbookPublication\Services\ExportPdfOperation; +use App\Http\Controllers\Admin\Operations\FluidbookPublication\Services\FormOperation; use App\Http\Controllers\Admin\Operations\FluidbookPublication\Services\GetPageFromWebsiteOperation; use App\Http\Controllers\Admin\Operations\FluidbookPublication\Services\SocialImageOperation; use App\Http\Controllers\Admin\Operations\FluidbookPublication\StatsOperation; @@ -110,6 +111,7 @@ class FluidbookPublication extends ToolboxStatusModel SocialImageOperation::class, ExportPdfOperation::class, GetPageFromWebsiteOperation::class, + FormOperation::class, // Carts BastideOperation::class, ]; diff --git a/app/Models/Traits/PublicationSettings.php b/app/Models/Traits/PublicationSettings.php index 0c0de8422..c1a6e904f 100644 --- a/app/Models/Traits/PublicationSettings.php +++ b/app/Models/Traits/PublicationSettings.php @@ -988,6 +988,9 @@ trait PublicationSettings 'v2' => '{"type":"boolean","default":true,"editable":true,"label":"\\u00a7!\\u00a7Afficher les pages courrantes!\\u00a7!","grade":3}', 'default' => true, ]); + $this->addSettingField('', FormSeparator::class); + $forms = ['Christaud']; + $this->addSettingField('pdfBeforeForm', SelectFromArray::class, $this->__('Remplir un formulaire avant le téléchargement ou l\'impression'), ['default' => '', 'allows_null' => true, 'options' => array_merge(['' => __('Aucun')], array_combine($forms, $forms))]); } -- 2.39.5