From: Vincent Vanwaelscappel Date: Wed, 11 Jan 2023 09:31:49 +0000 (+0100) Subject: wip #5661 @2 X-Git-Url: http://git.cubedesigners.com/?a=commitdiff_plain;h=3175947e7487ed3e54bcbfb18f97407fe461795b;p=fluidbook-toolbox.git wip #5661 @2 --- diff --git a/app/Http/Controllers/Admin/Operations/FluidbookPublication/PreviewOperation.php b/app/Http/Controllers/Admin/Operations/FluidbookPublication/PreviewOperation.php index eed7572c1..dd1af655f 100644 --- a/app/Http/Controllers/Admin/Operations/FluidbookPublication/PreviewOperation.php +++ b/app/Http/Controllers/Admin/Operations/FluidbookPublication/PreviewOperation.php @@ -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); } /** diff --git a/app/Jobs/FluidbookCompiler.php b/app/Jobs/FluidbookCompiler.php index 3edc38821..80b80b20a 100644 --- a/app/Jobs/FluidbookCompiler.php +++ b/app/Jobs/FluidbookCompiler.php @@ -1550,33 +1550,26 @@ height="0" width="0" style="display:none;visibility:hidden"> $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"> $this->accessibleTexts[$page] = $text; } - if (count($this->accessibleTexts) > 0) { $this->config->accessibleTexts = $this->accessibleTexts; } diff --git a/app/Models/FluidbookCollection.php b/app/Models/FluidbookCollection.php index 8e098584f..1160f2deb 100644 --- a/app/Models/FluidbookCollection.php +++ b/app/Models/FluidbookCollection.php @@ -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]); diff --git a/app/Models/FluidbookPublication.php b/app/Models/FluidbookPublication.php index 406a623ee..f377b1c73 100644 --- a/app/Models/FluidbookPublication.php +++ b/app/Models/FluidbookPublication.php @@ -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')); }