]> _ Git - fluidbook-toolbox.git/commitdiff
.
authorVincent Vanwaelscappel <vincent@cubedesigners.com>
Mon, 15 Apr 2024 13:43:29 +0000 (15:43 +0200)
committerVincent Vanwaelscappel <vincent@cubedesigners.com>
Mon, 15 Apr 2024 13:43:29 +0000 (15:43 +0200)
app/Fluidbook/Compiler/Compiler.php
app/Http/Controllers/Admin/Operations/Tools/DockerWebContainer.php
resources/tools/dockerwebcontainer/laravel/AppServiceProvider.php

index ce22cc82fa06dec418901f5118c3180b8528ce89..fb9a953c9a9da72049f8d616b6a5ef633a6b8b43 100644 (file)
@@ -3,6 +3,7 @@
 namespace App\Fluidbook\Compiler;
 
 use App\Fields\FluidbookFont;
+use App\Fluidbook\PDF;
 use App\Fluidbook\SEO\Page;
 use App\Fluidbook\SocialImage;
 use App\Http\Controllers\Admin\Operations\Tools\Favicon;
@@ -50,8 +51,6 @@ class Compiler extends Base implements CompilerInterface, IVirtualDirectoryError
     use Cache;
     use Search;
     use Accessibility;
-    use Tabs;
-    use PDF;
 
     /** @var Lock */
     protected $lock;
@@ -85,7 +84,7 @@ class Compiler extends Base implements CompilerInterface, IVirtualDirectoryError
             'js/libs/jquery/jquery.scrollto.min.js',
         ],
         'aria' => ['js/libs/aria/radio.js',],
-        //'bluebird' => ['js/libs/bluebird.min.js'],
+        'bluebird' => ['js/libs/bluebird.min.js'],
         'noaccents' => ['js/libs/noaccents.js'],
         'screenfull' => ['js/libs/screenfull.min.js'],
         'storage' => ['js/libs/storage.js',],
@@ -184,7 +183,6 @@ class Compiler extends Base implements CompilerInterface, IVirtualDirectoryError
         'android' => array('webintent'));
     public $pluginCSS = [];
     public $pluginJs = [];
-    protected $customJs = [];
     public $htmlmultimedia = [];
     public $cssX = [];
     public $cssY = [];
@@ -325,7 +323,6 @@ class Compiler extends Base implements CompilerInterface, IVirtualDirectoryError
 
         $this->dir = $this->getFluidbook()->getFinalPath($theme, $scormVariant);
         $this->vdir = new VirtualDirectory($this->dir);
-        $this->vdir->setLogger($this);
         $this->vdir->setErrorListener($this);
 
         $this->wdir = $this->getFluidbook()->getAssetDir();
@@ -509,8 +506,17 @@ class Compiler extends Base implements CompilerInterface, IVirtualDirectoryError
         $this->config->vectorPages = array_diff(ArrayUtil::parseRange($this->config->vectorPages), $this->config->rasterizePages);
         $this->numerotation = $this->config->numerotation = explode(',', $this->getFluidbook()->page_numbers);
 
-        $this->initTabsConfig();
+        $hideOnPages = ArrayUtil::parseRange($this->config->tabsHideOnPages);
+        $this->config->tabsDisabledOnPages = ArrayUtil::parseRange($this->config->tabsDisabledOnPages);
 
+        if ($this->config->tabsHideOnCover) {
+            $hideOnPages[] = 0;
+            $hideOnPages[] = 1;
+        }
+        if ($this->config->tabsHideOnLastPage) {
+            $hideOnPages[] = count($this->pages);
+        }
+        $this->config->tabsHideOnPages = $hideOnPages;
         $this->config->triggersLinks = [];
         $this->config->hasContentLock = false;
     }
@@ -555,8 +561,8 @@ class Compiler extends Base implements CompilerInterface, IVirtualDirectoryError
 
         // We need to be able to reference both navOrder and navOrderH so convert both to arrays
         // We also make sure there are no empty items in the arrays (see: http://php.net/manual/en/function.array-filter.php#111091)
-        $this->config->navOrder = array_values(array_filter(array_map('trim', explode(',', $this->config->navOrder)), 'strlen'));
-        $this->config->navOrderH = array_values(array_filter(array_map('trim', explode(',', $this->config->navOrderH)), 'strlen'));
+        $this->config->navOrder = array_filter(array_map('trim', explode(',', $this->config->navOrder)), 'strlen');
+        $this->config->navOrderH = array_filter(array_map('trim', explode(',', $this->config->navOrderH)), 'strlen');
 
         $this->config->standalone = $this->standalone;
         if ($this->config->phonegap) {
@@ -598,6 +604,7 @@ class Compiler extends Base implements CompilerInterface, IVirtualDirectoryError
             if ($error) {
                 FluidbookHealthIssues::addIssue($this->book_id, FluidbookHealthIssues::TYPE_CHAPTER_PAGE_NOT_EXIST, ['chapter' => $chapter['label'], 'page' => $chapter['page']]);
             }
+
         }
     }
 
@@ -757,10 +764,8 @@ class Compiler extends Base implements CompilerInterface, IVirtualDirectoryError
                 }
                 $this->writeJs();
                 $this->log('Js written');
-                //$this->vdir->setUpdateMode($this->getFluidbook()->region !== 'UE');
                 $this->vdir->sync(true, $this);
-
-                \Cubist\Backpack\Jobs\CommandLine::dispatch("chmod -R 775 $this->dir");
+                `chmod -R 775 $this->dir`;
                 $this->log('Files Synced');
 //        $f=rtrim(str_replace('/html5/', '/compiletime/', $this->dir));
 //        touch($f);
@@ -975,9 +980,6 @@ class Compiler extends Base implements CompilerInterface, IVirtualDirectoryError
             }
 
             $script = '<script type="text/javascript" charset="utf-8" src="' . $assetsPrefix . 'data/datas.js' . $jstime . '"></script>' . "\n";
-            foreach ($this->customJs as $c) {
-                $script .= "\t" . '<script type="text/javascript" charset="utf-8" src="' . $c . $jstime . '"></script>' . "\n";
-            }
             foreach ($this->jsLibs as $jsLib => $files) {
                 $script .= "\t" . '<script type="text/javascript" charset="utf-8" src="' . $assetsPrefix . 'data/' . $jsLib . '.js' . $jstime . '"></script>' . "\n";
             }
@@ -1249,11 +1251,26 @@ class Compiler extends Base implements CompilerInterface, IVirtualDirectoryError
         return $variables;
     }
 
-
-    protected function replaceVariables($str)
+    protected function writePDF()
     {
-        $replace = ['%title%' => $this->config->title];
-        return strtr($str, $replace);
+        if (!$this->fluidbookSettings->print && !$this->fluidbookSettings->pdf) {
+            return;
+        }
+
+        $res = PDF::compilePDF($this->getFluidbook());
+        if (!$this->config->pdfName) {
+            $this->config->pdfName = 'document.pdf';
+        }
+        $this->config->pdfName = Text::removeAccents($this->config->pdfName);
+        if (mb_strtolower(substr($this->config->pdfName, -4)) !== '.pdf') {
+            $this->config->pdfName .= '.pdf';
+        }
+
+        if ($res !== false) {
+            $this->vdir->copy($res, 'data/' . $this->config->pdfName);
+        }
+        $this->log('PDF written');
+        return '';
     }
 
     protected function addFilesInfos($key, $file)
@@ -1476,12 +1493,6 @@ class Compiler extends Base implements CompilerInterface, IVirtualDirectoryError
         $this->config->content_lock = $this->content_lock;
     }
 
-    public function addPDFJSPageRenderer()
-    {
-        $this->vdir->copyDirectory(resource_path('pdfjs/dist-min'), 'pdfjs');
-        $this->customJs[] = 'pdfjs/build/pdf.js';
-    }
-
     public function addPDFJS($force = false)
     {
         if ($this->_addedPDFJS) {
@@ -1498,6 +1509,7 @@ class Compiler extends Base implements CompilerInterface, IVirtualDirectoryError
 
         $this->_addedPDFJS = true;
 
+
         if ($renderer === 'pdfjs') {
             $resource = resource_path('pdfjs/dist-min');
         } else if ($renderer === 'pdfjs-legacy') {
@@ -1775,9 +1787,11 @@ class Compiler extends Base implements CompilerInterface, IVirtualDirectoryError
         $this->lessVariables['z'] = $this->z;
         $this->lessVariables['book-page-width'] = $w;
 
+
         $this->lessVariables['book-page-correct-width'] = $w;
         $this->lessVariables['book-page-correct-height'] = $h;
 
+
         $this->log('CSS 2');
         $this->lessVariables['book-page-height'] = $h;
         $this->lessVariables['book-page-ratio'] = floatval($w) / floatval($h);
@@ -2259,7 +2273,7 @@ class Compiler extends Base implements CompilerInterface, IVirtualDirectoryError
             if (isset($fontCapHeight) && isset($fontHeight) && is_numeric($fontCapHeight) && is_numeric($fontHeight)) {
                 $capHeight = $fontCapHeight / $fontHeight;
             }
-            $font = ['family' => $hash, 'capHeight' => $capHeight, 'ascender' => $ascender / $fontHeight, 'descender' => $descender / $fontHeight];
+            $font = ['family' => $hash, 'capHeight' => $capHeight, 'ascender' => $fontHeight > 0 ? $ascender / $fontHeight : 1, 'descender' => $fontHeight > 0 ? $descender / $fontHeight : 1];
             $this->cssfont[$hash] = $font;
         }
         return $this->cssfont[$hash];
index 4077b8857fce9edbe4981d65aa11d4eb244f7f76..27041febd403168493bf26fae17254c034f70dd3 100644 (file)
@@ -34,22 +34,20 @@ trait DockerWebContainer
         $form->addField('containername', Text::class, __('Nom du container'), ['prefix' => '/docker/']);
         $form->addField('domain', Text::class, __('Nom du domaine ou sous-domaine'), ['placeholder' => 'containername.dev.cubedesigners.com']);
         $form->addField('env', SelectFromArrayMultiple::class, __('Environnements'), ['default' => json_encode(['production', 'dev']), 'options' => ['production' => 'production', 'dev' => 'dev', 'staging' => 'staging', 'preprod' => 'preprod']]);
-
-        $form->addField('laravel', Checkbox::class, __('Installer Laravel'), ['default' => true]);
-        $form->addField('public', Checkbox::class, __('Racine dans le dossier "public"'), ['default' => true]);
+        $form->addField('laravel', SelectFromArray::class, __('Installer Laravel'), ['options' => ['0' => __('Non'), '5' => 'Laraval Backpack 5', '6' => 'Laravel Backpack 6'], 'default' => '5']);
+        $form->addField('public', Checkbox::class, __('Racine dans le dossier "public"'), ['default' => true, 'when' => ['laravel' => '0']]);
         $form->addField('phpversion', SelectFromArray::class, __('Version de PHP'), ["options" =>
             ['none' => '-',
                 '5.6' => '5.6',
                 '7.4' => '7.4',
                 '8.2' => '8.2',
                 '8.3' => '8.3',
-            ], 'value' => '8.3']);
-        $form->addField('mysql', Checkbox::class, __('Serveur Mariadb') . ' (MySQL)', ['default' => true]);
-        $form->addField('redis', Checkbox::class, __('Serveur Redis'), ['default' => true]);
+            ], 'value' => '8.3', 'when' => ['laravel' => 0]]);
+        $form->addField('mysql', Checkbox::class, __('Serveur Mariadb') . ' (MySQL)', ['default' => true, 'when' => ['laravel' => '0']]);
+        $form->addField('redis', Checkbox::class, __('Serveur Redis'), ['default' => true, 'when' => ['laravel' => '0']]);
         $form->addField('matomo', Checkbox::class, __('Serveur Matomo'), ['default' => false]);
         $form->addField('elasticsearch', Checkbox::class, __('Serveur ElasticSearch'), ['default' => false]);
 
-
         return view('tools.form', ['form' => $form]);
     }
 
@@ -108,7 +106,14 @@ trait DockerWebContainer
             $subDomain = '';
         }
 
-        $laravel = $request->get('laravel', true);
+        $laravel = $request->get('laravel', 5);
+        $phpversion = $request->get('phpversion', '8.3');
+        $mysql = $request->get('mysql', true);
+        $redis = $request->get('redis', true);
+        if ($laravel > 0) {
+            $phpversion = '8.3';
+            $redis = $mysql = true;
+        }
 
         $variables = [
             '$user' => $name,
@@ -139,7 +144,7 @@ trait DockerWebContainer
         $additionalEnv = [];
 
         $compose = ['base'];
-        $variables['$phpversion'] = $request->get('phpversion', '8.3');
+        $variables['$phpversion'] = $phpversion;
         if ($variables['$phpversion'] !== 'none') {
             $compose[] = 'php';
             if (version_compare($variables['$phpversion'], '5.6', '<=')) {
@@ -147,7 +152,7 @@ trait DockerWebContainer
             }
             $fixRights[] = 'chown 0:0 ./config/cron/crontab';
         }
-        if ($laravel || $request->get('mysql', true)) {
+        if ($mysql) {
             $compose[] = 'mysql';
             $fixRights[] = 'chown -R 999:999 ./database/data';
 
@@ -158,7 +163,7 @@ trait DockerWebContainer
             $additionalEnv['DB_USERNAME'] = 'root';
             $additionalEnv['DB_PASSWORD'] = '$dbpassword';
         }
-        if ($laravel || $request->get('redis', true)) {
+        if ($redis) {
             $compose[] = 'redis';
             $fixRights[] = 'chown -R 999:999 ./redis';
             $additionalEnv['CACHE_DRIVER'] = 'redis';
@@ -173,19 +178,27 @@ trait DockerWebContainer
             $fixRights[] = 'chmod -R 777 ./esdata';
         }
 
-        if ($request->get('laravel', true)) {
+        if ($laravel) {
             $laravelSource = resource_path('tools/dockerwebcontainer/laravel');
 
+            $cmsbackVersion = 'dev-backpack' . $laravel;
+            if ($laravel == 5) {
+                $cmsbackVersion = 'dev-master';
+                $frameworkVersion = '10.0';
+            } else if ($laravel == 6) {
+                $frameworkVersion = '11.0';
+            }
+
             $envPath = $www . '/.env';
             $projectEnv = Dotenv::parse(file_get_contents($envPath));
-            `rm -rf $www;composer create-project laravel/laravel $www`;
+            `rm -rf $www;composer create-project laravel/laravel:^$frameworkVersion.0 $www`;
             $composerFile = $www . '/composer.json';
             $composer = json_decode(file_get_contents($composerFile));
             $composer->name = str_replace('-', '/', $name);
             $composer->license = 'Proprietary';
             $composer->keywords = [$name];
             $composer->description = $name . ' project';
-            $composer->require->{"cubist/cms-back"} = 'dev-backpack6';
+            $composer->require->{"cubist/cms-back"} = $cmsbackVersion;
             $composer->repositories = [
                 ['type' => 'composer', 'url' => "https://composer.cubedesigners.com/"],
                 ['type' => 'composer', 'url' => "https://repo.backpackforlaravel.com/"]
@@ -202,7 +215,7 @@ trait DockerWebContainer
             Env::arrayToEnvFile($envPath . '.' . $env, $laravelEnv);
             unlink($envPath);
             unlink($envPath . '.example');
-            copy($laravelSource . '/AppServiceProvider.php', $www . '/Providers/AppServiceProvider.php');
+            copy($laravelSource . '/AppServiceProvider.php', $www . '/app/Providers/AppServiceProvider.php');
         }
 
         $variables['$fixrights'] = implode("\n", $fixRights);
index 51590d1836f25063a1cb8e3f5dbb8ed4ccfec7d9..1a3dbc4f8320c80a82397f634f4f1ee7acf0d816 100644 (file)
@@ -1,5 +1,6 @@
 <?php
 
+namespace App\Providers;
 
 use Illuminate\Support\Facades\URL;
 use Illuminate\Support\ServiceProvider;