]> _ Git - fluidbook-toolbox.git/commitdiff
wip #5661 @2
authorVincent Vanwaelscappel <vincent@cubedesigners.com>
Wed, 11 Jan 2023 09:31:49 +0000 (10:31 +0100)
committerVincent Vanwaelscappel <vincent@cubedesigners.com>
Wed, 11 Jan 2023 09:31:49 +0000 (10:31 +0100)
app/Http/Controllers/Admin/Operations/FluidbookPublication/PreviewOperation.php
app/Jobs/FluidbookCompiler.php
app/Models/FluidbookCollection.php
app/Models/FluidbookPublication.php

index eed7572c194418523e7adc59930f877ef4a376d9..dd1af655fa69e1d265478e99dd083a4c927ab851 100644 (file)
@@ -164,6 +164,11 @@ html,body{height:100%;cursor: wait;font-family: "Open Sans", Arial;background-co
     }
 
     /**
+     * @param $version string
+     * @param $fluidbook FluidbookPublication
+     * @param $theme FluidbookTheme
+     * @param $path string
+     * @return \Illuminate\Contracts\Foundation\Application|\Illuminate\Contracts\Routing\ResponseFactory|\Illuminate\Http\Response|object
      * @throws \Exception
      */
     public function preview($version, $fluidbook, $theme, $path = 'index.html')
@@ -171,12 +176,19 @@ html,body{height:100%;cursor: wait;font-family: "Open Sans", Arial;background-co
         $nointerface = !!request('nointerface', false);
         $shortLoading = !!request('shortLoading', false);
 
-        $dest = $fluidbook->getFinalPath($theme, $version);
+        $isScorm = $version === 'scorm';
+
+        $dest = $fluidbook->getFinalPath($theme, $isScorm);
         if ($path === 'index.html') {
-            $compiler = new FluidbookCompiler($fluidbook, version: $version, theme: $theme);
+            $compiler = new FluidbookCompiler($fluidbook, $isScorm, theme: $theme);
             $compiler->handle();
         }
-        return XSendFileController::sendfile($dest . '/' . $path);
+
+        $relayPath = $dest . '/' . $path;
+        if (!file_exists($relayPath)) {
+            throw new \Exception($relayPath . ' not found');
+        }
+        return XSendFileController::sendfile($relayPath);
     }
 
     /**
index 3edc388215dc31a536ff595b72863a72b6e3fb9b..80b80b20a2906cc070c86b56d53dd6ebc4046f16 100644 (file)
@@ -1550,33 +1550,26 @@ height="0" width="0" style="display:none;visibility:hidden"></iframe></noscript>
             $text = str_replace(array_keys($replace), array_values($replace), $text);
             $text = Text::cleanUTF8($text, '');
 
-            $voiceInfos = $data['voice'] ? !$this->fluidbookSettings->audiodescriptionVoice;
+            $voiceInfos = $data['voice'] ?$this->fluidbookSettings->audiodescriptionVoice;
 
             if ($voiceInfos) {
-                $hash = hash('sha256', $voiceInfos . '_^_' . $text);
-                $fname = $hash . '.mp3';
-                $dir = WS_BOOKS . '/audiodescription/';
-                if (!file_exists($dir)) {
-                    mkdir($dir, 0777, true);
-                }
-
-                $file = $dir . $fname;
+                $e = explode(':', $voiceInfos);
 
-                if ($this->book_id === '18860' && file_exists($file)) {
-                    unlink($file);
+                if (count($e) === 1) {
+                    $engine = 'azuretts';
+                    $voice = $voiceInfos;
+                } else {
+                    $engine = $e[0];
+                    $voice = $e[1];
                 }
 
-                if (!file_exists($file) || filesize($file) === 0) {
-                    $e = explode(':', $voiceInfos);s
+                $hash = hash('sha256', $engine . ':' . $voice . '_^_' . $text);
+                $fname = $hash . '.mp3';
+                $dir = Files::mkdir(protected_path('audiodescription'));
 
-                    if (count($e) === 1) {
-                        $engine = 'azuretts';
-                        $voice = $voiceInfos;
-                    } else {
-                        $engine = $e[0];
-                        $voice = $e[1];
-                    }
+                $file = $dir . $fname;
 
+                if (!file_exists($file) || filesize($file) === 0) {
                     if ($engine == 'festival') {
                         $tmp = Files::tempnam() . '.wav';
                         $tmptext = Files::tempnam() . '.txt';
@@ -1603,7 +1596,6 @@ height="0" width="0" style="display:none;visibility:hidden"></iframe></noscript>
             $this->accessibleTexts[$page] = $text;
         }
 
-
         if (count($this->accessibleTexts) > 0) {
             $this->config->accessibleTexts = $this->accessibleTexts;
         }
index 8e098584fcba039427854cbd32b01d8cbe99532c..1160f2deb541f628c77e132d6af81d0d4ea460c3 100644 (file)
@@ -31,8 +31,8 @@ class FluidbookCollection extends ToolboxModel
 
         $this->addOwnerField();
 
-        $this->addField('type', SelectFromArray::class, __('Type'), ['column' => true, 'options' => ['export' => __('Export'), 'scorm_multilang' => __('SCORM multilingue')]]);
-        $this->addField('locale_switch', Checkbox::class, __('Permettre le changement de langue'), ['when' => ['type' => 'scorm_multilang'], 'default' => true]);
+        $this->addField('type', SelectFromArray::class, __('Type'), ['column' => true, 'options' => ['export' => __('Export'), 'export_multilang' => __('Export multilingue'), 'scorm_multilang' => __('SCORM multilingue')]]);
+        $this->addField('locale_switch', Checkbox::class, __('Permettre le changement de langue'), ['when' => ['type' => ['scorm_multilang', 'export_multilang']], 'default' => true]);
         $this->addField('version', FluidbookExportVersion::class, __('Version'), ['when' => ['type' => 'export']]);
         $this->addField('publications', BunchOfFieldsMultiple::class, __('Publications'), ['bunch' => CollectionPublication::class, 'edit_label' => '%fluidbook > %dir']);
         $this->addField('override_settings', BunchOfFieldsMultiple::class, __('Redéfinir les paramètres lors de l\'export'), ['bunch' => Fluidbook_Setting::class]);
index 406a623eed0cedbc55641e42a90027097fe2c172..f377b1c734f941ac4fff1f1fdd70faaa49d27a46 100644 (file)
@@ -324,13 +324,15 @@ class FluidbookPublication extends ToolboxSettingsModel
     public function getFinalPath($theme = null, $scormVariant = false)
     {
         $dir = $this->id;
-        if (null !== $theme || ($theme instanceof FluidbookTheme && $theme->id != $this->theme)) {
-            $dir .= '-';
-            if (is_string($theme) || is_numeric($theme)) {
-                $dir .= $theme;
-            } else if ($theme instanceof FluidbookTheme) {
-                $dir .= $theme->id;
-            }
+
+        if (null !== $theme) {
+            $themeId = $theme instanceof FluidbookTheme ? $theme->id : $theme;
+        } else {
+            $themeId = null;
+        }
+
+        if (null !== $theme && ($themeId != $this->theme)) {
+            $dir .= '-' . $themeId;
         }
         return protected_path('fluidbookpublication/final/' . $dir . '/' . ($scormVariant ? 'scorm' : 'online'));
     }