From a5e31e6a810982e83d62a2a551c3c8b87d65dbe7 Mon Sep 17 00:00:00 2001 From: Vincent Vanwaelscappel Date: Mon, 26 Jun 2023 18:07:11 +0200 Subject: [PATCH] wait #5399 --- app/Fluidbook/Compiler/Compiler.php | 91 +-------------- app/Fluidbook/Compiler/Images.php | 104 ++++++++++++++++++ .../FluidbookPublication/PreviewOperation.php | 7 ++ 3 files changed, 112 insertions(+), 90 deletions(-) create mode 100644 app/Fluidbook/Compiler/Images.php diff --git a/app/Fluidbook/Compiler/Compiler.php b/app/Fluidbook/Compiler/Compiler.php index 20b63e288..3fb738bd4 100644 --- a/app/Fluidbook/Compiler/Compiler.php +++ b/app/Fluidbook/Compiler/Compiler.php @@ -48,6 +48,7 @@ class Compiler extends Base implements CompilerInterface use \Fluidbook\Tools\Compiler\FluidbookCompiler; use Favicon; use Secure; + use Images; protected static $uaPrefixes = array('-moz-', '-webkit-', '-o-', '-ms-', ''); @@ -1820,68 +1821,6 @@ class Compiler extends Base implements CompilerInterface return $res; } - protected function writeImages() - { - set_time_limit(0); - switch ($this->fluidbookSettings->mobileVersion) { - case 'html5-desktop': - $this->backgroundsPrefix = array(true, false); - $this->svg = true; - break; - case 'html5-images': - $this->backgroundsPrefix = array(true); - $this->svg = false; - break; - default: - $this->backgroundsPrefix = array(false); - $this->svg = true; - break; - } - - $rasterizePages = $this->config->rasterizePages; - $this->config->pagesDimensions = []; - - if ($this->fluidbookSettings->mobileNavigationType === 'mobilefirst') { - $imdir = 'mf'; - } else { - $imdir = 'html'; - } - - $thumbs = array(); - foreach ($this->pages as $page => $infos) { - $thisrasterize = in_array($page, $rasterizePages); - $thisimagesvg = !$thisrasterize && $this->svg; - $thisbackgroundPrefix = $thisrasterize ? [true] : $this->backgroundsPrefix; - - foreach ($this->getResolutions() as $r) { - foreach ($thisbackgroundPrefix as $backgroundsPrefix) { - $source = $this->getFluidbook()->getFile($page, $this->imageFormat, $r, $backgroundsPrefix, true, $imdir); - if ($r === $this->maxRes) { - $this->getPageDimension($page); - } - $this->vdir->copy($source, 'data/background/' . $r . '/' . ($backgroundsPrefix ? 't' : 'p') . $page . '.' . $this->imageFormat); - } - } - - if ($thisimagesvg) { - $this->vdir->copy( - $this->getFluidbook()->getFile($page, 'svg', 150, true, - in_array($page, $this->config->vectorPages), 'html') - , 'data/contents/p' . $page . '.svg'); - } - - $t = $this->getFluidbook()->getThumbFile($page, $this->imageFormat); - $this->vdir->copy($t, 'data/thumbnails/p' . $page . '.' . $this->imageFormat); - $this->log('Made image page ' . $page); - } - - - $this->_makeCover($this->getFluidbook()->getFile(1, 'jpg', 150, true, true)); - $this->log('Made cover for apps'); - - $this->log('Made images'); - } - /** * @param $page @@ -1910,35 +1849,7 @@ class Compiler extends Base implements CompilerInterface } - protected function _makeCover($orig) - { - $cached = $this->wdir . '/_cover.jpg'; - - if (!file_exists($cached) || filemtime($cached) < filemtime($orig)) { - $size = Image::getimagesize($orig); - $w = $size[0]; - $h = $size[1]; - - $tmp = Files::tempnam() . '.png'; - - $c = new CommandLine('convert'); - $c->setArg(null, resource_path('fluidbookpublication/cover/shade-cover-app.png')); - $c->setManualArg('-resize ' . round($w / 3) . 'x' . $h); - $c->setArg(null, $tmp); - $c->execute(); - $convert = new CommandLine('composite'); - $cmd = '-compose Multiply '; - $cmd .= $tmp . ' ' . $orig . ' '; - $cmd .= $cached; - $convert->setManualArg($cmd); - $convert->execute(); - - unlink($tmp); - } - $this->vdir->copy($cached, 'cover.jpg', true); - - } protected function _lessBoolean($val) { diff --git a/app/Fluidbook/Compiler/Images.php b/app/Fluidbook/Compiler/Images.php new file mode 100644 index 000000000..9340d7e5c --- /dev/null +++ b/app/Fluidbook/Compiler/Images.php @@ -0,0 +1,104 @@ +fluidbookSettings->mobileVersion) { + case 'html5-desktop': + $this->backgroundsPrefix = array(true, false); + $this->svg = true; + break; + case 'html5-images': + $this->backgroundsPrefix = array(true); + $this->svg = false; + break; + default: + $this->backgroundsPrefix = array(false); + $this->svg = true; + break; + } + + $rasterizePages = $this->config->rasterizePages; + $this->config->pagesDimensions = []; + + if ($this->fluidbookSettings->mobileNavigationType === 'mobilefirst') { + $imdir = 'mf'; + } else { + $imdir = 'html'; + } + + $thumbs = array(); + foreach ($this->pages as $page => $infos) { + $thisrasterize = in_array($page, $rasterizePages); + $thisimagesvg = !$thisrasterize && $this->svg; + $thisbackgroundPrefix = $thisrasterize ? [true] : $this->backgroundsPrefix; + + foreach ($this->getResolutions() as $r) { + foreach ($thisbackgroundPrefix as $backgroundsPrefix) { + $source = $this->getFluidbook()->getFile($page, $this->imageFormat, $r, $backgroundsPrefix, true, $imdir); + if ($r === $this->maxRes) { + $this->getPageDimension($page); + } + $this->vdir->copy($source, 'data/background/' . $r . '/' . ($backgroundsPrefix ? 't' : 'p') . $page . '.' . $this->imageFormat); + } + } + + if ($thisimagesvg) { + $this->vdir->copy( + $this->getFluidbook()->getFile($page, 'svg', 150, true, + in_array($page, $this->config->vectorPages), 'html') + , 'data/contents/p' . $page . '.svg'); + } + + $t = $this->getFluidbook()->getThumbFile($page, $this->imageFormat); + $this->vdir->copy($t, 'data/thumbnails/p' . $page . '.' . $this->imageFormat); + $this->log('Made image page ' . $page); + } + + + $this->_makeCover($this->getFluidbook()->getFile(1, 'jpg', 150, true, true)); + $this->log('Made cover for apps'); + + $this->log('Made images'); + } + + protected function _makeCover($orig) + { + $cached = $this->wdir . '/_cover.jpg'; + + if (!file_exists($cached) || filemtime($cached) < filemtime($orig)) { + $size = Image::getimagesize($orig); + $w = $size[0]; + $h = $size[1]; + + $tmp = Files::tempnam() . '.png'; + + $c = new CommandLine('convert'); + $c->setArg(null, resource_path('fluidbookpublication/cover/shade-cover-app.png')); + $c->setManualArg('-resize ' . round($w / 3) . 'x' . $h); + $c->setArg(null, $tmp); + $c->execute(); + + $convert = new CommandLine('composite'); + $cmd = '-compose Multiply '; + $cmd .= $tmp . ' ' . $orig . ' '; + $cmd .= $cached; + $convert->setManualArg($cmd); + $convert->execute(); + + unlink($tmp); + } + $this->vdir->copy($cached, 'cover.jpg', true); + + } + +} diff --git a/app/Http/Controllers/Admin/Operations/FluidbookPublication/PreviewOperation.php b/app/Http/Controllers/Admin/Operations/FluidbookPublication/PreviewOperation.php index fa284fec5..c604d5d08 100644 --- a/app/Http/Controllers/Admin/Operations/FluidbookPublication/PreviewOperation.php +++ b/app/Http/Controllers/Admin/Operations/FluidbookPublication/PreviewOperation.php @@ -8,6 +8,7 @@ use App\Http\Middleware\CheckIfAdmin; use App\Models\FluidbookPublication; use App\Models\FluidbookTheme; use Cubist\Backpack\Http\Controllers\Base\XSendFileController; +use Cubist\Util\PHP; use Illuminate\Support\Facades\Auth; use Illuminate\Support\Facades\Route; @@ -15,6 +16,7 @@ use Illuminate\Support\Facades\Route; trait PreviewOperation { use FluidbookPreviewOperation; + protected function setupPreviewRoutes($segment, $routeName, $controller) { Route::match(['get'], $segment . '/preview/{version}/{id}_{hash}', function ($version, $id, $hash) use ($segment) { @@ -44,6 +46,7 @@ trait PreviewOperation protected function _preview($segment, $version, $id, $hash, $time = null, $path = null) { + PHP::neverStop(false); $q = request()->getQueryString(); if ($q) { $q = '?' . $q; @@ -94,6 +97,8 @@ trait PreviewOperation */ public function loadingCompile($url, $id, $hash) { + PHP::neverStop(false); + self::_getFluidbookAndTheme($id, $hash, $fluidbook, $theme); $res = $this->_loadingCompile($theme, $fluidbook->title, $url); return response($res); @@ -109,6 +114,8 @@ trait PreviewOperation */ public function preview($version, $fluidbook, $theme, $path = 'index.html') { + PHP::neverStop(false); + $isScorm = $version === 'scorm'; $dest = $fluidbook->getFinalPath($theme, $isScorm); -- 2.39.5