]> _ Git - fluidbook-toolbox.git/commitdiff
wait #5429 @0.5
authorVincent Vanwaelscappel <vincent@cubedesigners.com>
Fri, 2 Sep 2022 14:09:58 +0000 (16:09 +0200)
committerVincent Vanwaelscappel <vincent@cubedesigners.com>
Fri, 2 Sep 2022 14:09:58 +0000 (16:09 +0200)
app/Http/Controllers/Admin/Operations/FluidbookPublication/PreviewOperation.php
app/Jobs/FluidbookCompiler.php
app/Models/FluidbookPublication.php

index 25dd8b202e0539cdaeb6d5969d3641fd604b3833..eed7572c194418523e7adc59930f877ef4a376d9 100644 (file)
@@ -16,15 +16,30 @@ trait PreviewOperation
 {
     protected function setupPreviewRoutes($segment, $routeName, $controller)
     {
+        Route::match(['get'], $segment . '/preview/{version}/{id}_{hash}', function ($version, $id, $hash) use ($segment) {
+            return $this->_preview($segment, $version, $id, $hash, null, 'index.html');
+        })->where('id', '([0-9]+)(-[0-9]+)?')
+            ->whereAlpha('version')
+            ->where('hash', '[0-9a-f]{32}')
+            ->withoutMiddleware([CheckIfAdmin::class]);
+
+        Route::match(['get'], $segment . '/preview/{version}/{id}_{hash}_{time}/{path?}', function ($version, $id, $hash, $time, $path = 'index.html') use ($segment, $controller) {
+            return $this->_preview($segment, $version, $id, $hash, $time, $path);
+        })->where('id', '([0-9]+)(-[0-9]+)?')
+            ->where('hash', '[0-9a-f]{32}')
+            ->where('path', '.*')
+            ->whereAlpha('version')
+            ->withoutMiddleware([CheckIfAdmin::class]);
+
         // Redirect to the url with a timestamp to prevent cache
         Route::match(['get'], $segment . '/preview/{id}_{hash}', function ($id, $hash) use ($segment) {
-            return $this->_preview($segment, $id, $hash, null, 'index.html');
+            return $this->_preview($segment, 'online', $id, $hash, null, 'index.html');
         })->where('id', '([0-9]+)(-[0-9]+)?')
             ->where('hash', '[0-9a-f]{32}')
             ->withoutMiddleware([CheckIfAdmin::class]);
 
         Route::match(['get'], $segment . '/preview/{id}_{hash}_{time}/{path?}', function ($id, $hash, $time, $path = 'index.html') use ($segment, $controller) {
-            return $this->_preview($segment, $id, $hash, $time, $path);
+            return $this->_preview($segment, 'online', $id, $hash, $time, $path);
         })->where('id', '([0-9]+)(-[0-9]+)?')
             ->where('hash', '[0-9a-f]{32}')
             ->where('path', '.*')
@@ -36,7 +51,7 @@ trait PreviewOperation
         $this->crud->addButtonFromView('line', 'preview', 'fluidbook_publication.preview', 'end');
     }
 
-    protected function _preview($segment, $id, $hash, $time = null, $path = null)
+    protected function _preview($segment, $version, $id, $hash, $time = null, $path = null)
     {
         $q = request()->getQueryString();
         if ($q) {
@@ -46,17 +61,17 @@ trait PreviewOperation
         $shortLoading = !!request('shortLoading', false);
 
         if (null === $time || ((null === $path || $path === 'index.html') && $time < (time() - 60) && !$nointerface && !$shortLoading)) {
-            $url = backpack_url($segment . '/preview/' . $id . '_' . $hash . '_' . time()) . '/' . $q;
+            $v = ($version === 'online') ? '' : $version . '/';
+            $url = backpack_url($segment . '/preview/' . $v . $id . '_' . $hash . '_' . time()) . '/' . $q;
             return $this->loadingCompile($url, $id, $hash);
         }
 
-
         self::_getFluidbookAndTheme($id, $hash, $fluidbook, $theme);
         $check = $this->_checkDemoLinkAuth($fluidbook);
         if ($check !== true) {
             return $check;
         }
-        return $this->preview($fluidbook, $theme, $path);
+        return $this->preview($version, $fluidbook, $theme, $path);
     }
 
     /**
@@ -151,14 +166,14 @@ html,body{height:100%;cursor: wait;font-family: "Open Sans", Arial;background-co
     /**
      * @throws \Exception
      */
-    public function preview($fluidbook, $theme, $path = 'index.html')
+    public function preview($version, $fluidbook, $theme, $path = 'index.html')
     {
         $nointerface = !!request('nointerface', false);
         $shortLoading = !!request('shortLoading', false);
 
-        $dest = $fluidbook->getFinalPath($theme);
+        $dest = $fluidbook->getFinalPath($theme, $version);
         if ($path === 'index.html') {
-            $compiler = new FluidbookCompiler($fluidbook, theme: $theme);
+            $compiler = new FluidbookCompiler($fluidbook, version: $version, theme: $theme);
             $compiler->handle();
         }
         return XSendFileController::sendfile($dest . '/' . $path);
index 1663c7a1edbfba67520cfbfb6400b502dc22fe1a..8280deaa9845540f7b079b7e0cf706644c277e8d 100644 (file)
@@ -200,7 +200,7 @@ class FluidbookCompiler extends Base implements CompilerInterface
     public $book;
     public $pages;
     public $theme;
-    public $version;
+    public $devversion;
     public $book_id;
     public $themeRoot;
     public $needToRecompileContents = true;
@@ -282,7 +282,7 @@ class FluidbookCompiler extends Base implements CompilerInterface
      * @throws \Exception
      */
 
-    function __construct(FluidbookPublication $book, $version = null, $phonegap = false, $phonegapVersion = 'latest', $dir = null, $standalone = false, $appcache = false, $home = false, FluidbookTheme $theme = null, $hybrid = false, Command $command = null)
+    function __construct(FluidbookPublication $book, $version = 'online', $phonegap = false, $phonegapVersion = 'latest', $dir = null, $standalone = false, $appcache = false, $home = false, FluidbookTheme $theme = null, $hybrid = false, Command $command = null)
     {
         parent::__construct();
 
@@ -292,12 +292,13 @@ class FluidbookCompiler extends Base implements CompilerInterface
         $this->phonegapVersion = self::getPhonegapVersion($phonegapVersion);
         $this->appcache = $appcache;
         $this->multiApp = $this->home = $home;
-        $this->version = $this->version ?? $this->getFluidbook()->mobileLVersion;
+        $this->devversion = $this->getFluidbook()->mobileLVersion;
+        $this->version = $version;
 
         $this->hybrid = $hybrid;
 
-        $this->assets = self::getSourcesPath($this->version);
-        $this->compiledAssets = self::getCompiledSourcesPath($this->version);
+        $this->assets = self::getSourcesPath($this->devversion);
+        $this->compiledAssets = self::getCompiledSourcesPath($this->devversion);
 
         $this->phonegap = $phonegap;
         $this->standalone = $standalone || $this->phonegap;
@@ -311,7 +312,7 @@ class FluidbookCompiler extends Base implements CompilerInterface
         $this->book_id = $this->getFluidbook()->id;
         $this->log('Start compilation');
 
-        $this->dir = $this->getFluidbook()->getFinalPath($theme);
+        $this->dir = $this->getFluidbook()->getFinalPath($theme, $version);
         $this->vdir = new VirtualDirectory($this->dir);
 
         $this->wdir = $this->getFluidbook()->getAssetDir();
@@ -468,6 +469,10 @@ class FluidbookCompiler extends Base implements CompilerInterface
 
     public function initConfig()
     {
+        if ($this->version !== 'scorm') {
+            $this->fluidbookSettings->scorm_enable = false;
+        }
+
         $this->config = new Data(array_merge($this->fluidbookSettings->getRawData()['settings'], $this->themeSettings->getRawData()));
         $this->config->pages = count($this->getFluidbook()->composition);
         $this->config->bookmarkDisablePages = ArrayUtil::parseRange($this->config->bookmarkDisablePages);
@@ -1261,7 +1266,6 @@ class FluidbookCompiler extends Base implements CompilerInterface
 
     protected function writeStats()
     {
-
         if ($this->fluidbookSettings->stats) {
             $this->config->statsMatomo = $this->book_id;
             $this->config->statsMatomoServer = 3;
@@ -1273,7 +1277,6 @@ class FluidbookCompiler extends Base implements CompilerInterface
         }
 
         if ($this->fluidbookSettings->tagcommander_id) {
-
             $id = $this->fluidbookSettings->tagcommander_id;
             if (!$this->fluidbookSettings->tagcommander_prod) {
                 $id .= '/uat';
index 6ee9e0e2fabc62d85dba7f34464ec4f7c2b62f5e..b6015af20faae0d8403bc218f6dbafcffab16022 100644 (file)
@@ -279,7 +279,7 @@ class FluidbookPublication extends ToolboxSettingsModel
         return $this->getDocumentSize($page)[1];
     }
 
-    public function getFinalPath($theme = null)
+    public function getFinalPath($theme = null, $version = 'online')
     {
         $dir = $this->id;
         if (null === $theme || ($theme instanceof FluidbookTheme && $theme->id != $this->theme)) {
@@ -290,7 +290,7 @@ class FluidbookPublication extends ToolboxSettingsModel
                 $dir .= $theme->id;
             }
         }
-        return protected_path('fluidbookpublication/final/' . $dir);
+        return protected_path('fluidbookpublication/final/' . $dir . '/' . $version);
     }
 
     public function getAssetDir()