From: Vincent Vanwaelscappel Date: Mon, 19 Dec 2022 20:46:03 +0000 (+0100) Subject: wip #5661 @0.5 X-Git-Url: http://git.cubedesigners.com/?a=commitdiff_plain;h=f0c17dcb2f39c595c531c142f28649c106e8bcb5;p=fluidbook-toolbox.git wip #5661 @0.5 --- diff --git a/app/Fluidbook/Packager/Base.php b/app/Fluidbook/Packager/Base.php index b6cd67f48..8d0f0f29b 100644 --- a/app/Fluidbook/Packager/Base.php +++ b/app/Fluidbook/Packager/Base.php @@ -9,6 +9,7 @@ use Cubist\Util\CommandLine; use Cubist\Util\Files\Files; use Cubist\Util\PHP; use Cubist\Util\Text; +use Exception; class Base extends \App\Jobs\Base { @@ -38,28 +39,50 @@ class Base extends \App\Jobs\Base public static function package($book_id, $type, $zipPackage = true, $cleanOnDestruct = true, $options = []) { - if ($type === 'html') { - $packager = new Online($book_id, null, $options); - } else if ($type === 'scorm') { - $packager = new SCORM($book_id, null, $options); - } else if ($type === 'sharepoint') { - $packager = new Sharepoint($book_id, null, $options); - } elseif ($type === 'win_html') { - $packager = new OfflineHTML($book_id, null, $options); - } else if ($type === 'win_exe_html') { - $packager = new WindowsZIP($book_id, null, $options); - } else if ($type === 'mac_exe_html') { - $packager = new MacOS($book_id, null, $options); - } else if ($type === 'win_ins_html') { - $packager = new WindowsInstaller($book_id, null, $options); - } else if ($type === 'win_inss_html') { - $packager = new WindowsEXE($book_id, null, $options); - } else if ($type === 'win_cd_html') { - $packager = new USBKey($book_id, null, $options); - } else if ($type === 'precompiled') { - $packager = new Precompiled($book_id, null, $options); - } else if ($type === 'chromeos') { - $packager = new ChromeOS($book_id, null, $options); + $type = str_replace('-', '_', $type); + switch ($type) { + case 'html': + case 'online': + $packager = new Online($book_id, null, $options); + break; + case 'scorm': + $packager = new SCORM($book_id, null, $options); + break; + case 'sharepoint': + $packager = new Sharepoint($book_id, null, $options); + break; + case 'win_html': + $packager = new OfflineHTML($book_id, null, $options); + break; + case 'win_exe_html': + case 'win_zip': + $packager = new WindowsZIP($book_id, null, $options); + break; + case 'mac_exe_html': + case 'mac_exe': + $packager = new MacOS($book_id, null, $options); + break; + case 'win_ins_html': + case 'win_ins': + $packager = new WindowsInstaller($book_id, null, $options); + break; + case 'win_inss_html': + case 'win_inss': + case 'win_exe': + $packager = new WindowsEXE($book_id, null, $options); + break; + case 'win_cd_html': + case 'usbkey': + $packager = new USBKey($book_id, null, $options); + break; + case 'precompiled': + $packager = new Precompiled($book_id, null, $options); + break; + case 'chromeos': + $packager = new ChromeOS($book_id, null, $options); + break; + default: + throw new Exception('Package type ' . $type . ' not exists'); } $packager->cleanOnDestruct = $packager->cleanOnDestruct && $cleanOnDestruct; $packager->zipPackage = $zipPackage; @@ -224,4 +247,38 @@ class Base extends \App\Jobs\Base copy($source, $dest); touch($dest, filemtime($source)); } + + /** + * @throws Exception + */ + protected function _compileFluidbook( $book, $dest, $hybrid = false) + { + $compiler = new FluidbookCompiler($book, $this->scormVariant, false, "latest", null, false, false, false, null, $hybrid); + $compiler->handle(); + + $rsync = new CommandLine\Rsync(rtrim($compiler->getFinalPath(),'/'), $dest, true); + $rsync->execute(); + + $htmlFiles = array('index'); + $filesToDelete = []; + + foreach ($htmlFiles as $name) { + $html = $book->getSettings()->get('htmlPrepend') . file_get_contents($dest . $name . '.html'); + file_put_contents($dest . '/' . $name . '.' . $this->_ext, $html); + if ($this->_ext != 'html') { + $filesToDelete[] = $name . '.html'; + } + } + + $rm = new CommandLine('rm'); + foreach ($filesToDelete as $f) { + $rm->setArg(null, $dest . '/' . $f); + } + $rm->execute(); + + if ($this->_ext !== 'html') { + $e = $this->_ext; + `find $dest -type f -name "*.html" -exec rename 's/\.html$/.$e/' '{}' \;`; + } + } } diff --git a/app/Fluidbook/Packager/Online.php b/app/Fluidbook/Packager/Online.php index 45ffc8442..cde42b4d1 100644 --- a/app/Fluidbook/Packager/Online.php +++ b/app/Fluidbook/Packager/Online.php @@ -26,20 +26,20 @@ class Online extends Base $this->_ext = $this->book->getSettings()->get('htmlExtension'); $this->book->getSettings()->set('actualHtmlExtension', $this->_ext); - $this->prepareHTML5(); + $this->prepareFluidbook(); } - public function prepareHTML5() + public function prepareFluidbook() { $dest = $this->vdir; $mfid = $this->book->getSettings()->get('mobilefirstFluidbookId', ''); if ($mfid != '' && (int)$mfid > 0) { $mfbook = FluidbookPublication::find($mfid); - $this->_compileHTML5($this->book_id, $this->book, $dest . '/d', true); + $this->_compileFluidbook($this->book, $dest . '/d', true); $vars = wsDAOBook::$lastHTML5Compiler->getIndexVars(); - $this->_compileHTML5($mfid, $mfbook, $dest . '/mf', true); + $this->_compileFluidbook($mfbook, $dest . '/mf', true); $hybrid = file_get_contents($this->resource_path('hybrid.html')); $replace = [ @@ -56,42 +56,11 @@ class Online extends Base } file_put_contents($dest . '/index.html', $hybrid); } else { - $this->_compileHTML5($this->book_id, $this->book, $dest); + $this->_compileFluidbook($this->book, $dest); } } - protected function _compileHTML5($bookId, $book, $dest, $hybrid = false) - { - $compiler = new FluidbookCompiler($book, $this->scormVariant, false, "latest", null, false, false, false, null, $hybrid); - $compiler->handle(); - - $rsync = new CommandLine\Rsync(rtrim($compiler->getFinalPath(),'/'), $dest, true); - $rsync->execute(); - - $htmlFiles = array('index'); - $filesToDelete = []; - - foreach ($htmlFiles as $name) { - $html = $book->getSettings()->get('htmlPrepend') . file_get_contents($dest . $name . '.html'); - file_put_contents($dest . '/' . $name . '.' . $this->_ext, $html); - if ($this->_ext != 'html') { - $filesToDelete[] = $name . '.html'; - } - } - - $rm = new CommandLine('rm'); - foreach ($filesToDelete as $f) { - $rm->setArg(null, $dest . '/' . $f); - } - $rm->execute(); - - if ($this->_ext !== 'html') { - $e = $this->_ext; - `find $dest -type f -name "*.html" -exec rename 's/\.html$/.$e/' '{}' \;`; - } - } - public function makePackage($zip) { parent::makePackage($zip); diff --git a/app/Fluidbook/Packager/WindowsInstaller.php b/app/Fluidbook/Packager/WindowsInstaller.php index 8d7ab471c..273d42122 100644 --- a/app/Fluidbook/Packager/WindowsInstaller.php +++ b/app/Fluidbook/Packager/WindowsInstaller.php @@ -1,12 +1,17 @@ getFinalPackageDir(); - $daoLang = new wsDAOLang($core->con); - $lang = $daoLang->selectById($this->book->lang); - - if ($lang->nsis == 'Arabic') { - $lang->nsis = 'English'; - } - - if (!file_exists(WS_FILES . '/packager/download')) { - mkdir(WS_FILES . '/packager/download', 0777, true); + $locale = $this->book->translations['nsis']; + if ($locale === 'Arabic') { + $locale = 'English'; } $fname = $this->exeName; $title = $this->appName; - $nsi = file_get_contents(WS_COMPILE_ASSETS . '/' . $this->nsifile . '.nsi'); + $nsi = file_get_contents($this->resource_path($this->nsifile . '.nsi')); $nsi = str_replace('$name', $title, $nsi); - $nsi = str_replace('$htmldir', WS_COMPILE_ASSETS, $nsi); $nsi = str_replace('$fname', $fname, $nsi); $nsi = str_replace('$fdir', $winvdir, $nsi); $nsi = str_replace('$titre', $title, $nsi); - $nsi = str_replace('$lang', $lang->nsis, $nsi); + $nsi = str_replace('$lang', $locale, $nsi); $nsi = str_replace('$nwplatform', $this->nwplatform, $nsi); $nsi = str_replace('$nsisdir', '/usr/local/share/nsis', $nsi); $nsi = str_replace('$output', $this->getPathBase('exe'), $nsi); + $nsi = str_replace('$favicon', $this->_favicon(), $nsi); + + $this->nsi = $nsi; + } + + protected function _favicon() + { $favicon = $this->vdir . 'data/favicon.ico'; if ($this->theme->parametres->favicon == '') { - $this->copy(WS_COMPILE_ASSETS . '/fluidbook.ico', $favicon); + $this->copy($this->resource_path('/fluidbook.ico'), $favicon); } else if (!file_exists($favicon)) { - $pngFile = WS_THEMES . '/' . $this->theme->theme_id . '/' . $this->theme->parametres->favicon; + $pngFile = $this->co->themeAsset('favicon', $this->theme->parametres->favicon); $icoFile = WS_THEMES . '/' . $this->theme->theme_id . '/favicon.ico'; if (!file_exists($icoFile) || filemtime($icoFile) < filemtime($pngFile) || filemtime(__FILE__) > filemtime($icoFile)) { - $tmp = CubeIT_Files::tempnam() . '.png'; + $tmp = Files::tempnam() . '.png'; $convert = "convert $pngFile -resize 64x64^ -gravity center $tmp"; `$convert`; @@ -67,12 +71,10 @@ class WindowsInstaller extends WindowsZIP } $this->copy($icoFile, $favicon); if (!file_exists($favicon)) { - $this->copy(WS_COMPILE_ASSETS . '/fluidbook.ico', $favicon); + $this->copy($this->resource_path('fluidbook.ico'), $favicon); } } - $nsi = str_replace('$favicon', $favicon, $nsi); - - $this->nsi = $nsi; + return $favicon; } public function makePackage($zip) diff --git a/app/Fluidbook/Packager/WindowsZIP.php b/app/Fluidbook/Packager/WindowsZIP.php index b1643bc79..e617ce897 100644 --- a/app/Fluidbook/Packager/WindowsZIP.php +++ b/app/Fluidbook/Packager/WindowsZIP.php @@ -4,6 +4,7 @@ namespace App\Fluidbook\Packager; use Cubist\Net\SSH2; use Cubist\Util\CommandLine; +use Cubist\Util\Files\Files; use Cubist\Util\Text; class WindowsZIP extends Base @@ -48,7 +49,7 @@ class WindowsZIP extends Base $this->copyFluidbookFiles(); $this->makeJSON(); - $this->buildPath = WS_PACKAGER . '/nwbuild/' . $this->version . '/' . $this->book_id; + $this->buildPath = Files::mkdir($this->packager_path('/nwbuild/' . $this->version . '/' . $this->book_id)); `umask 0000;rm -rf $this->buildPath;mkdir -p 0777 $this->buildPath;chmod -R 777 $this->vdir;mkdir -p 0777 /application/tmp;chmod -R 777 /application/tmp`; @@ -77,7 +78,7 @@ class WindowsZIP extends Base $cl->execute(); $cl->debug(); - `sudo chown -R extranet:www-data $this->buildPath`; + `sudo chown -R toolbox:www-data $this->buildPath`; if (!file_exists($this->buildPath)) { die('Error while making exe : ' . $cl->commande . ' // ' . $cl->output); @@ -109,7 +110,7 @@ class WindowsZIP extends Base function replaceFFMpeg() { - copy(WS_COMPILE_ASSETS . '/_exehtml/_ffmpeg/' . $this->nwplatform . '-ffmpeg.dll', $this->getFinalPackageDir() . '/ffmpeg.dll'); + copy($this->resource_path('_ffmpeg/' . $this->nwplatform . '-ffmpeg.dll'), $this->getFinalPackageDir() . '/ffmpeg.dll'); } function makeJSON() @@ -169,12 +170,11 @@ class WindowsZIP extends Base { // For exe version, force to export only the html5 version // No need to export pages with texts for this version, we are certain that svg is supported if enabled - if ($this->book->parametres->mobileVersion == 'html5-desktop') { - $this->book->parametres->mobileVersion = 'html5'; + if ($this->book->getSettings()->get('mobileVersion') == 'html5-desktop') { + $this->book->getSettings()->set('mobileVersion','html5'); } - $this->book->parametres->seoVersion = false; - - $this->daoBook->compile($this->book_id, 'html5', false, $this->book->parametres->forceCompileOnDownload, false, $this->book); + $this->book->getSettings()->set('seoVersion',false); + $this->_compileFluidbook($this->book,null,false); } protected function copyFluidbookFiles()