From: Vincent Vanwaelscappel Date: Mon, 19 Dec 2022 20:11:29 +0000 (+0100) Subject: wip #5661 @3 X-Git-Url: http://git.cubedesigners.com/?a=commitdiff_plain;h=6a7c22aeecad4d5eafe2d82076fa4c72cf64dff8;p=fluidbook-toolbox.git wip #5661 @3 --- diff --git a/app/Console/Commands/FluidbookPackage.php b/app/Console/Commands/FluidbookPackage.php new file mode 100644 index 000000000..135a5f637 --- /dev/null +++ b/app/Console/Commands/FluidbookPackage.php @@ -0,0 +1,21 @@ +argument('id'), $this->argument('type'), $this->option('zip', false)); + $packager->handle(); + } +} diff --git a/app/Fluidbook/Links.php b/app/Fluidbook/Links.php index 77d41167a..e63e59307 100644 --- a/app/Fluidbook/Links.php +++ b/app/Fluidbook/Links.php @@ -5,6 +5,7 @@ namespace App\Fluidbook; use App\Models\User; use App\Util\wsDAOBook; use App\Util\wsDocument; +use Cubist\Util\ArrayUtil; use Cubist\Util\Files\Files; use Cubist\Util\Str; use Fluidbook\Tools\Links\Link; @@ -157,14 +158,17 @@ class Links } $r = json_decode(gzdecode(file_get_contents($file)), true); + $links = self::_UID($r['links']); $rulers = self::_UID($r['rulers']); + if (can('fluidbook-publication:links:edit-animations')) { $links = Link::decryptLinks($links); - }else{ + } else { $links = Link::encryptLinks($links); } + self::_correctImageSpecialLinks($links); } diff --git a/app/Fluidbook/Packager/Base.php b/app/Fluidbook/Packager/Base.php index 847950955..b6cd67f48 100644 --- a/app/Fluidbook/Packager/Base.php +++ b/app/Fluidbook/Packager/Base.php @@ -2,7 +2,11 @@ namespace App\Fluidbook\Packager; +use App\Jobs\FluidbookCompiler; +use App\Models\FluidbookPublication; +use App\Models\FluidbookTheme; use Cubist\Util\CommandLine; +use Cubist\Util\Files\Files; use Cubist\Util\PHP; use Cubist\Util\Text; @@ -11,57 +15,60 @@ class Base extends \App\Jobs\Base protected $dir; protected $vdir; + + /** + * @var FluidbookPublication + */ public $book; - protected $pages; + /** @var FluidbookTheme */ protected $theme; - protected $version; + protected $scormVariant = false; protected $book_id; protected $themeRoot; - protected $daoBook; protected $zip; protected $workingDir; - protected $whole = true; protected $_clean = true; protected $_compileOnConstruct = false; public $cleanOnDestruct = true; - const COMPILE_ASSETS = '/application/resources/fluidbookpublication/packager/'; - - public static function package($book_id, $version, $zip = true, $cleanOnDestruct = true, $options = []) - { - global $packager; - - PHP::neverStop(); - - if ($version === 'html') { - $packager = new Online($book_id, null, true, $options); - } else if ($version === 'scorm') { - $packager = new SCORM($book_id, null, true, $options); - } else if ($version === 'sharepoint') { - $packager = new Sharepoint($book_id, null, true, $options); - } elseif ($version === 'win_html') { - $packager = new OfflineHTML($book_id, null, true, $options); - } else if ($version === 'win_exe_html') { - $packager = new WindowsZIP($book_id, $options); - } else if ($version === 'mac_exe_html') { - $packager = new MacOS($book_id, $options); - } else if ($version === 'win_ins_html') { - $packager = new WindowsInstaller($book_id, $options); - } else if ($version === 'win_inss_html') { - $packager = new WindowsEXE($book_id, $options); - } else if ($version === 'win_cd_html') { - $packager = new USBKey($book_id, $options); - } else if ($version === 'precompiled') { - $packager = new Precompiled($book_id, null, true, $options); - } else if ($version === 'chromeos') { - $packager = new ChromeOS($book_id, null, true, $options); + public $zipPackage = true; + + public $type = '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); } $packager->cleanOnDestruct = $packager->cleanOnDestruct && $cleanOnDestruct; + $packager->zipPackage = $zipPackage; - return $packager->makePackage($zip); + return $packager; } - public function __construct($book_id, $vdir = null, $whole = true, $options = []) + + public function __construct($book_id, $vdir = null, $options = []) { $this->_clean = (null === $vdir); @@ -69,27 +76,18 @@ class Base extends \App\Jobs\Base $this->book_id = $book_id; $this->vdir = $vdir; - $this->dir = ROOT . '/fluidbook/packager/' . $book_id . '/'; - $this->whole = $whole; + $this->dir = Files::mkdir($this->packager_path('/' . $book_id)); - if (!file_exists($this->dir)) { - mkdir($this->dir, 0777, true); - } - - $this->book = $this->daoBook->selectById($book_id); + $this->book = FluidbookPublication::find($book_id); $forceCompile = false; if (count($options)) { $options['forceCompileOnDownload'] = true; } foreach ($options as $k => $v) { - $this->book->parametres->$k = $v; + $this->book->getSettings()->set($k, $v); } - $this->pages = $this->daoBook->getPagesOfBook($book_id, false); - - $daoTheme = new wsDAOTheme($core->con); - $this->theme = $daoTheme->getThemeOfBook($book_id, true); - $this->themeRoot = WS_THEMES . '/' . $this->theme->theme_id . '/'; + $this->theme = $this->book->getTheme(); $this->workingDir = $this->book->getAssetDir(); @@ -98,10 +96,27 @@ class Base extends \App\Jobs\Base } } + public function handle() + { + PHP::neverStop(); + $this->makePackage($this->zipPackage); + } + + protected function packager_path($path = '') + { + return protected_path('/fluidbookpublication/packager/' . ltrim($path, '/')); + } + + + protected function resource_path($path) + { + return resource_path('/fluidbookpublication/packager/' . ltrim($path, '/')); + } protected function compile($forceCompile = false) { - $this->daoBook->compile($this->book_id, '2', false, $this->book->parametres->forceCompileOnDownload || $forceCompile, false, $this->book); + $compiler = new FluidbookCompiler($this->book, $this->scormVariant); + $compiler->handle(); } protected function preparePackage() @@ -126,87 +141,35 @@ class Base extends \App\Jobs\Base return $res; } - protected function copyFluidbookFiles() - { - // Copie du FB vers un répertoire temporaire - $cp = new CommandLine('cp'); - $cp->setArg('R'); - $cp->setArg('p'); - $cp->setArg(null, WS_BOOKS . '/final/' . $this->book->book_id . '/*'); - $cp->setArg(null, $this->vdir); - $cp->execute(); - } - - protected function copyOtherFiles($files) - { - foreach ($files as $source => $dest) { - if (is_int($source)) { - $source = $dest; - } - - $s = WS_COMPILE_ASSETS . '/' . $source; - if (is_file($s) && !file_exists($this->vdir . $dest)) { - $this->copy($s, $this->vdir . $dest); - } else if (is_dir($s)) { - $cp = new CommandLine('cp'); - $cp->setArg('R'); - $cp->setArg('p'); - $cp->setArg(null, $s); - $cp->setArg(null, $this->vdir); - $cp->execute(); - - $mv = new CommandLine('mv'); - $mv->setArg($this->vdir . '/' . $source); - $mv->setArg($this->vdir . '/' . $dest); - $mv->execute(); - } - } - } protected function getBaseFile() { - return $this->version . '-' . date('Ymdhis') . '-' . $this->escapeTitle(); + return $this->type . '-' . date('Ymdhis') . '-' . $this->escapeTitle(); } protected function escapeTitle() { - $res = Text::str2URL($this->book->parametres->title); + $res = Text::str2URL($this->book->title); if ($res == '') { $res = 'fluidbook'; } return $res; } - protected function getRelativeBase() - { - return '/packager/download/' . $this->getBaseFile(); - } - - protected function getURLBase($ext = '') - { - $res = '/fluidbook' . $this->getRelativeBase(); - if ($ext != '') { - $res .= '.' . $ext; - } - return $res; - } protected function getPathBase($ext = '') { - $res = WS_FILES . $this->getRelativeBase(); + $res = '/download/' . $this->getBaseFile(); if ($ext != '') { $res .= '.' . $ext; } - return $res; + return $this->packager_path($res); } protected function zip($zipfile = null) { - if (!$this->whole) { - return; - } - $url = $this->getURLBase('zip'); + Files::mkdir($this->packager_path('download')); $final = $this->getPathBase('zip'); $rename = false; if (is_null($zipfile)) { @@ -227,64 +190,32 @@ class Base extends \App\Jobs\Base $zip->setArg(null, '.'); $zip->setManualArg('-x "*/\.*"'); $zip->execute(); - $zip->debug(); - } - - if (!file_exists(WS_FILES . '/packager/download')) { - mkdir(WS_FILES . '/packager/download', 0777, true); } if ($rename) { rename($zipfile, $final); } - return $url; + return $final; } public function getFinalPackageDir() { - $dir = $this->vdir; - $dir .= '/m/'; - return $dir; + return $this->vdir; } protected function initTempDir() { if (is_null($this->vdir)) { - $this->vdir = $this->dir . $this->version . '/'; - } - $this->cleanVdir(); - if (!file_exists($this->vdir . '/data')) { - mkdir($this->vdir . '/data', 0777, true); + $this->vdir = $this->dir . $this->type . '/'; } } - protected function cleanVdir() - { - if (!$this->_clean) { - return; - } - if (file_exists($this->vdir)) { - // Suppression du répertoire si il existe - $rm = new CommandLine('rm'); - $rm->setArg('r'); - $rm->setArg('f'); - $rm->setArg(null, $this->vdir); - $rm->execute(); - } - } protected function postPackage() { } - public function __destruct() - { - if ($this->whole && $this->cleanOnDestruct) { - $this->cleanVdir(); - } - } - public function copy($source, $dest) { if (!file_exists($source)) { diff --git a/app/Fluidbook/Packager/ChromeOS.php b/app/Fluidbook/Packager/ChromeOS.php index 7347dbb73..cafdabbcf 100644 --- a/app/Fluidbook/Packager/ChromeOS.php +++ b/app/Fluidbook/Packager/ChromeOS.php @@ -6,12 +6,9 @@ use Cubist\Util\CommandLine; class ChromeOS extends Online { - public function __construct($book_id, $vdir = null, $whole = true, $options = []) - { - parent::__construct($book_id, $vdir, $whole, $options); - $this->version = 'chromeos'; - $this->cleanOnDestruct = true; - } + + public $type='chormeos'; + public $cleanOnDestruct=true; protected function preparePackage() { diff --git a/app/Fluidbook/Packager/MacOS.php b/app/Fluidbook/Packager/MacOS.php index afff8cc28..1dcab8f2f 100644 --- a/app/Fluidbook/Packager/MacOS.php +++ b/app/Fluidbook/Packager/MacOS.php @@ -1,5 +1,7 @@ version = 'mac_exe_html'; - } + public $type = 'mac_exe_html'; public function makePackage($zip) { @@ -65,8 +62,8 @@ class MacOS extends OfflineHTML $cl->debug(); $this->replaceFFMpeg(); - if(!file_exists($this->getAppPath())){ - die('Error while building mac app : '.$cl->commande.' // '.$cl->output); + if (!file_exists($this->getAppPath())) { + die('Error while building mac app : ' . $cl->commande . ' // ' . $cl->output); } $this->signApp(); diff --git a/app/Fluidbook/Packager/OfflineHTML.php b/app/Fluidbook/Packager/OfflineHTML.php index 22ff130cf..8744fe99a 100644 --- a/app/Fluidbook/Packager/OfflineHTML.php +++ b/app/Fluidbook/Packager/OfflineHTML.php @@ -2,13 +2,16 @@ namespace App\Fluidbook\Packager; -class OfflineHTML extends Online { - protected $_allowNetworking = 'internal'; +class OfflineHTML extends Online +{ + protected $_allowNetworking = 'internal'; + public $type = 'win_html'; - protected function copyFluidbookFiles() { - parent::copyFluidbookFiles(); - unlink($this->vdir . '/index.swf'); - unlink($this->vdir . '/player.swf'); - copy(WS_COMPILE_ASSETS . '/offline.swf', $this->vdir . '/index.swf'); - } + protected function copyFluidbookFiles() + { + parent::copyFluidbookFiles(); + unlink($this->vdir . '/index.swf'); + unlink($this->vdir . '/player.swf'); + copy(WS_COMPILE_ASSETS . '/offline.swf', $this->vdir . '/index.swf'); + } } diff --git a/app/Fluidbook/Packager/Online.php b/app/Fluidbook/Packager/Online.php index b81c37439..45ffc8442 100644 --- a/app/Fluidbook/Packager/Online.php +++ b/app/Fluidbook/Packager/Online.php @@ -2,225 +2,46 @@ namespace App\Fluidbook\Packager; +use App\Jobs\FluidbookCompiler; +use App\Models\FluidbookPublication; use Cubist\Util\CommandLine; class Online extends Base -{ protected $origHTML; +{ + protected $origHTML; protected $_labels = array(); protected $_allowNeworking = 'all'; protected $_ext = 'html'; - protected $_disableScorm = true; + public $type = 'html'; + protected $_compileOnConstruct = false; - public function __construct($book_id, $vdir = null, $whole = true, $options = []) - { - parent::__construct($book_id, $vdir, $whole, $options); - $this->version = 'html'; - } protected function preparePackage() { parent::preparePackage(); - if ($this->_disableScorm) { - $this->book->parametres->scorm_enable = false; - } - - $this->_ext = $this->book->parametres->htmlExtension; - $this->book->parametres->actualHtmlExtension = $this->_ext; - - $this->copyFluidbookFiles(); - $this->mergeJavascript(); + $this->book->getSettings()->set('scorm_enable', $this->scormVariant); -// $others = array('fluidbook.js', 'getflash.gif', 'index.html', 'style.css'); -// $others = array_merge($others, $this->getSWFFiles()); -// -// $this->copyOtherFiles($others); - - if (!file_exists($this->vdir . '/pages')) { - mkdir($this->vdir . '/pages/', 0777, true); - } + $this->_ext = $this->book->getSettings()->get('htmlExtension'); + $this->book->getSettings()->set('actualHtmlExtension', $this->_ext); - $ga = ''; - if ($this->book->parametres->googleAnalyticsCustom) { - $ga = $this->book->parametres->googleAnalyticsCustom; - } elseif ($this->book->parametres->googleAnalytics != '') { - $variables = array('Language' => array('value' => 'getLang()', 'valueAsJS' => true, 'scope' => 2)); - $ga = cubePage::googleAnalytics(explode(',', $this->book->parametres->googleAnalytics), true, $variables); - } - - $statsfooter = ''; - if ($this->book->parametres->statsCustom != '') { - $statsfooter = $this->book->parametres->statsCustom; - } - - $facebook = ''; - if ($this->book->parametres->facebook) { - if ($this->book->parametres->facebook_title != '') { - $facebook .= ''; - } else { - $facebook .= ''; - } - if ($this->book->parametres->facebook_description != '') { - $facebook .= ''; - } - $t = 'https://workshop.fluidbook.com/services/facebook_thumbnail?cid=' . $this->book->cid . '&j=' . time(); - $dim = getimagesize($t); - $facebook .= ''; - $facebook .= ''; - $facebook .= ''; - } - - $favicon = ''; - - if ($this->theme->parametres->favicon != '') { - $favicon = ''; - } - - $redirectPDF = 'redirectPDF();'; - if ($this->book->parametres->mobileVersion == 'pdf') { - $redirectMobile = $redirectPDF; - } else { - $redirectMobile = 'redirectMobile();'; - $this->prepareHTML5(); - } - - $seoVersion = true; - if (isset($this->book->parametres->seoVersion)) { - $seoVersion = $this->book->parametres->seoVersion; - } - - $seoRobot = true; - if (isset($this->book->parametres->seoRobots)) { - $seoRobot = $this->book->parametres->seoRobots; - } - - $robots = ''; - if (!$seoRobot) { - $robots = ''; - } - - $keywords = ''; - if ($this->book->parametres->seoKeywords) { - $keywords = ''; - } - - $alwaysHTML5 = true; - $html5priority = true; - - - // Stuffs to replace in html - $toReplace = array('lang' => strtolower($this->book->lang), - 'ga' => $ga, - 'statsfooter' => $statsfooter, - 'facebook' => $facebook, - 'bgcolor' => $this->theme->parametres->loadingBackColor, - 'junk' => TIME, - 'robots' => $robots, - 'favicon' => $favicon, - 'alwaysHTML5' => $alwaysHTML5, - 'keywords' => $keywords, - ); - - $this->origHTML = $this->book->parametres->htmlPrepend; - $h = $this->vdir . '/index.html'; - if (file_exists($h)) { - $this->origHTML .= file_get_contents($h); - unlink($h); - } - $this->origHTML = $this->replaceHTML($toReplace); - - $nav1 = $this->makeHTMLNav(true); - $nav = $this->makeHTMLNav(false); - $footer = $this->makeHTMLFooter(); - - - foreach ($this->pages as $page => $infos) { - $pathToIndex = 'index.swf'; - $pathToGetflash = 'getflash.gif'; - $redirectScript = ''; - if ($page == 1) { - $dest = 'index.' . $this->_ext; - $title = $this->book->parametres->title; - $sp = ''; - } else { - $label = $this->_getLabelOfPage($page); - $title = $label . ' - ' . $this->book->parametres->title; - $dest = 'pages/' . $page . '-' . mb_strtolower(cubeText::str2URL($label)) . '.' . $this->_ext; - $pathToIndex = '../index.swf'; - $pathToGetflash = '../getflash.gif'; - $sp = '../'; - $redirectScript = ''; - } - $alt = ''; - -// if ($seoVersion && CubeIT_Util_Gzip::file_exists($htmlfile)) { -// $html = CubeIT_Util_Gzip::file_get_contents($htmlfile); -// $alt .= "\n" . $html . "\n"; -// -// if ($page == 1) { -// $alt .= $nav1; -// } else { -// $alt .= $nav; -// } -// } - - $alt .= $footer; - - $base = ''; - if ($this->book->parametres->baseUrl) { - $base = ''; - } - - if ($page == 1 && $this->book->parametres->seoDescription) { - $description = $this->book->parametres->seoDescription; - } else { - $textfile = wsDocument::getDir($infos['document_id']) . 'ph' . $infos['document_page'] . '.txt'; - if (file_exists($textfile)) { - $description = mb_substr(file_get_contents($textfile), 0, 150); - } else { - $description = ''; - } - } - - $data = str_replace('$alt', $alt, $this->origHTML); - $data = str_replace('$base', $base, $data); - $data = str_replace('$pathToIndex', $pathToIndex, $data); - $data = str_replace('$title', $this->escape($title), $data); - $data = str_replace('$pathToGetflash', $pathToGetflash, $data); - $data = str_replace('$redirectScript', $redirectScript, $data); - $data = str_replace('$sp', $sp, $data); - $data = str_replace('$index_ext', $this->_ext, $data); - $data = str_replace('$description', '', $data); - - file_put_contents($this->vdir . $dest, $data); - - if (!$seoVersion) { - break; - } - } + $this->prepareHTML5(); } - protected function getFlashvars() - { - return array(); - } public function prepareHTML5() { - if (!$this->whole) { - return; - } - $dest = $this->vdir . 'm'; + $dest = $this->vdir; - $mfid = $this->book->parametres->mobilefirstFluidbookId; + $mfid = $this->book->getSettings()->get('mobilefirstFluidbookId', ''); if ($mfid != '' && (int)$mfid > 0) { - $mfbook = $this->daoBook->selectById($mfid); + $mfbook = FluidbookPublication::find($mfid); $this->_compileHTML5($this->book_id, $this->book, $dest . '/d', true); $vars = wsDAOBook::$lastHTML5Compiler->getIndexVars(); $this->_compileHTML5($mfid, $mfbook, $dest . '/mf', true); - $hybrid = file_get_contents(WS_COMPILE_ASSETS . '/hybrid/index.html'); + $hybrid = file_get_contents($this->resource_path('hybrid.html')); $replace = [ 'titre' => $vars[''], 'breakpoint' => $this->book->parametres->mobilefirstBreakpoint . 'px', @@ -242,32 +63,17 @@ class Online extends Base protected function _compileHTML5($bookId, $book, $dest, $hybrid = false) { + $compiler = new FluidbookCompiler($book, $this->scormVariant, false, "latest", null, false, false, false, null, $hybrid); + $compiler->handle(); - $this->daoBook->compile($bookId, 'html5', false, $book->parametres->forceCompileOnDownload, false, $book, true, false, $hybrid); - - if (!file_exists($dest)) { - mkdir($dest, 0777, true); - } - - $cp = new CommandLine('cp'); - $cp->setPath(CONVERTER_PATH); - $cp->setArg('r'); - $cp->setArg('p'); - $cp->setArg(null, WS_BOOKS . '/html5/' . $bookId . '/*'); - $cp->setArg(null, $dest); - $cp->execute(); - - $filesToAdd = array(); - foreach ($filesToAdd as $f) { - $this->copy(WS_COMPILE_ASSETS . '/_html5/' . $f, $dest . '/' . $f); - } - - $filesToDelete = array('indext.html', 'indexu.html'); + $rsync = new CommandLine\Rsync(rtrim($compiler->getFinalPath(),'/'), $dest, true); + $rsync->execute(); $htmlFiles = array('index'); + $filesToDelete = []; foreach ($htmlFiles as $name) { - $html = $book->parametres->htmlPrepend . file_get_contents($dest . '/' . $name . '.html'); + $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'; @@ -275,7 +81,6 @@ class Online extends Base } $rm = new CommandLine('rm'); - $rm->setPath(CONVERTER_PATH); foreach ($filesToDelete as $f) { $rm->setArg(null, $dest . '/' . $f); } @@ -284,7 +89,6 @@ class Online extends Base if ($this->_ext !== 'html') { $e = $this->_ext; `find $dest -type f -name "*.html" -exec rename 's/\.html$/.$e/' '{}' \;`; - } } @@ -297,145 +101,5 @@ class Online extends Base return $this->getFinalPackageDir(); } - protected function makeHTMLNav($root) - { - $res = ''; - return $res; - } - - protected function _getLabelOfPage($page) - { - if (!isset($this->_chapters)) { - $this->_chapters = $this->book->chapters; - } - - - if (isset($this->_labels[$page])) { - return $this->_labels[$page]; - } - - - if ($page == 1) { - $this->_labels[1] = $this->book->parametres->title; - - return $this->_labels[1]; - } - - - $virtual = $this->_getVirtualPage($page); - - $candidates = array(); - foreach ($this->_chapters as $c) { - if ($c->page == $virtual) { - $candidates[] = $c; - } - } - if (!count($candidates)) { - $this->_labels[$page] = $this->_getLabelOfPage($page - 1); - return $this->_labels[$page]; - } - - usort($candidates, array($this, '_sortCandidates')); - $c = array_shift($candidates); - - $this->_labels[$page] = $c->label; - return $this->_labels[$page]; - } - - protected function _sortCandidates($a, $b) - { - if ($a->level > $b->level) { - return 1; - } else if ($a->level < $b->level) { - return -1; - } else { - return 0; - } - } - - protected function _getVirtualPage($page) - { - $num = explode(',', $this->book->numerotation); - if (isset($num[$page - 1])) { - return $num[$page - 1]; - } - return 1; - } - - protected function escape($txt, $replaceNewLines = false) - { - $res = htmlentities($txt, ENT_COMPAT, 'UTF-8'); - if ($replaceNewLines) { - $res = str_replace("\n", ' ', $res); - $res = str_replace("\r", '', $res); - } - return $res; - } - - protected function makeHTMLFooter() - { - $res = ''; - return $res; - } - - protected function replaceHTML($toReplace) - { - return $this->replaceContents($this->origHTML, $toReplace); - } - - protected function mergeJavascript() - { - $dest = WS_COMPILE_ASSETS . '/fluidbook.js'; - $orig = WS_COMPILE_ASSETS . '/_js/'; - $files = array('log4js.js' => false, 'esapi.js' => false, 'resources/i18n/ESAPI_Standard_en_US.properties.js' => false, 'resources/Base.esapi.properties.js' => false, 'swfobject.js' => false, 'swfaddress.js' => true, 'fluidbook.js' => true); - - $refresh = false; - if (file_exists($dest)) { - $mtime = filemtime($dest); - foreach ($files as $file => $min) { - if (filemtime($orig . $file) > $mtime) { - $refresh = true; - break; - } - } - } else { - $refresh = true; - } - if (!$refresh) { - return; - } - - $minjs = "\n\n"; - foreach ($files as $file => $min) { - $c = file_get_contents($orig . $file); - if ($min) { - $c = JSMin::minify($c); - } - - $minjs .= $c . "\n\n"; - } - file_put_contents($dest, $minjs); - } - } diff --git a/app/Fluidbook/Packager/Precompiled.php b/app/Fluidbook/Packager/Precompiled.php index 45b87e926..6f2ce8364 100644 --- a/app/Fluidbook/Packager/Precompiled.php +++ b/app/Fluidbook/Packager/Precompiled.php @@ -4,10 +4,11 @@ namespace App\Fluidbook\Packager; class Precompiled extends Online { - public function __construct($book_id, $vdir = null, $whole = true,$options=[]) + public $type = 'precompiled'; + + public function __construct($book_id, $vdir = null, $options = []) { - parent::__construct($book_id, $vdir, $whole,$options); - $this->version = 'precompiled'; + parent::__construct($book_id, $vdir, $options); $this->book->parametres->embedAllLibraries = true; } diff --git a/app/Fluidbook/Packager/Scorm.php b/app/Fluidbook/Packager/Scorm.php index dcba067fb..c7f4c0d14 100644 --- a/app/Fluidbook/Packager/Scorm.php +++ b/app/Fluidbook/Packager/Scorm.php @@ -1,13 +1,11 @@ version = 'scorm'; - $this->_disableScorm = false; - } + protected $scormVariant = true; + + public $type = 'scorm'; protected function preparePackage() { diff --git a/app/Fluidbook/Packager/Sharepoint.php b/app/Fluidbook/Packager/Sharepoint.php index 341849ac0..c569b6023 100644 --- a/app/Fluidbook/Packager/Sharepoint.php +++ b/app/Fluidbook/Packager/Sharepoint.php @@ -4,12 +4,13 @@ namespace App\Fluidbook\Packager; class Sharepoint extends Online { - public function __construct($book_id, $vdir = null, $whole = true, $options = []) + public $type = 'sharepoint'; + + public function __construct($book_id, $vdir = null, $options = []) { - parent::__construct($book_id, $vdir, $whole, $options); - $this->version = 'sharepoint'; - $this->book->parametres->seoVersion = false; - $this->book->parametres->maxResolution = 150; - $this->book->parametres->htmlExtension = 'aspx'; + parent::__construct($book_id, $vdir, $options); + $this->book->getSettings()->set('seoVersion', false); + $this->book->getSettings()->set('maxResolution', 150); + $this->book->getSettings()->set('htmlExtension', 'aspx'); } } diff --git a/app/Fluidbook/Packager/USBKey.php b/app/Fluidbook/Packager/USBKey.php index e3a65c38b..91082f949 100644 --- a/app/Fluidbook/Packager/USBKey.php +++ b/app/Fluidbook/Packager/USBKey.php @@ -2,12 +2,7 @@ namespace App\Fluidbook\Packager; class USBKey extends MacOS { - - public function __construct($book_id,$options=[]) - { - parent::__construct($book_id,$options); - $this->version = 'win_cd_html'; - } + public $type='win_cd_html'; protected function preparePackage() { diff --git a/app/Fluidbook/Packager/WindowsEXE.php b/app/Fluidbook/Packager/WindowsEXE.php index 937497dd0..5e26ed213 100644 --- a/app/Fluidbook/Packager/WindowsEXE.php +++ b/app/Fluidbook/Packager/WindowsEXE.php @@ -1,13 +1,10 @@ version = 'win_inss_html'; - } } diff --git a/app/Fluidbook/Packager/WindowsInstaller.php b/app/Fluidbook/Packager/WindowsInstaller.php index e3c61f3e4..8d7ab471c 100644 --- a/app/Fluidbook/Packager/WindowsInstaller.php +++ b/app/Fluidbook/Packager/WindowsInstaller.php @@ -6,11 +6,8 @@ class WindowsInstaller extends WindowsZIP protected $nsi; protected $nsifile = 'html'; - public function __construct($book_id, $options = []) - { - parent::__construct($book_id, $options); - $this->version = 'win_ins_html'; - } + public $type='win_ins_html'; + protected function preparePackage() { diff --git a/app/Fluidbook/Packager/WindowsZIP.php b/app/Fluidbook/Packager/WindowsZIP.php index 7526a8ca9..b1643bc79 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\Text; class WindowsZIP extends Base { @@ -17,10 +18,11 @@ class WindowsZIP extends Base protected $exenameMaxlength = 30; protected $_compileOnConstruct = true; - public function __construct($book_id, $options = []) + public $type = 'win_exe_html'; + + public function __construct($book_id, $vdir = null, $options = []) { - parent::__construct($book_id, null, true, $options); - $this->version = 'win_exe_html'; + parent::__construct($book_id, $vdir, $options); $this->appName = ''; $this->appversion = '1.0.' . time(); $this->_clean = false; @@ -29,7 +31,7 @@ class WindowsZIP extends Base $this->exeName = $this->book->book_id . '-' . trim(cubeText::str2URL(mb_substr($this->book->parametres->title, 0, $this->exenameMaxlength - 6)), '-'); $this->appName = $this->book->parametres->title; } else { - $this->exeName = trim(cubeText::str2URL(mb_substr($this->book->parametres->offlineTitle, 0, $this->exenameMaxlength)), '-'); + $this->exeName = trim(Text::str2URL(mb_substr($this->book->parametres->offlineTitle, 0, $this->exenameMaxlength)), '-'); $this->appName = $this->book->parametres->offlineTitle; } diff --git a/app/Jobs/FluidbookCompiler.php b/app/Jobs/FluidbookCompiler.php index f2f97568f..e7a14b8c5 100644 --- a/app/Jobs/FluidbookCompiler.php +++ b/app/Jobs/FluidbookCompiler.php @@ -197,6 +197,10 @@ class FluidbookCompiler extends Base implements CompilerInterface public $dir; public $z = 3; protected $_lottieIDByHash = []; + + /** + * @var FluidbookPublication + */ public $book; public $pages; public $theme; @@ -269,7 +273,7 @@ class FluidbookCompiler extends Base implements CompilerInterface /** * @param FluidbookPublication $book - * @param $version null|string + * @param bool $scormVariant * @param $phonegap * @param $phonegapVersion * @param $dir @@ -282,7 +286,7 @@ class FluidbookCompiler extends Base implements CompilerInterface * @throws \Exception */ - 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) + function __construct(FluidbookPublication $book, $scormVariant = false, $phonegap = false, $phonegapVersion = 'latest', $dir = null, $standalone = false, $appcache = false, $home = false, FluidbookTheme $theme = null, $hybrid = false, Command $command = null) { parent::__construct(); @@ -293,7 +297,7 @@ class FluidbookCompiler extends Base implements CompilerInterface $this->appcache = $appcache; $this->multiApp = $this->home = $home; $this->devversion = $this->getFluidbook()->mobileLVersion; - $this->version = $version; + $this->scormVariant = $scormVariant; $this->hybrid = $hybrid; @@ -312,7 +316,7 @@ class FluidbookCompiler extends Base implements CompilerInterface $this->book_id = $this->getFluidbook()->id; $this->log('Start compilation'); - $this->dir = $this->getFluidbook()->getFinalPath($theme, $version); + $this->dir = $this->getFluidbook()->getFinalPath($theme, $scormVariant); $this->vdir = new VirtualDirectory($this->dir); $this->wdir = $this->getFluidbook()->getAssetDir(); @@ -332,7 +336,6 @@ class FluidbookCompiler extends Base implements CompilerInterface $this->imageFormat = $this->fluidbookSettings->imageFormat; - $p1 = $this->getFluidbook()->getFile(1, $this->imageFormat, 150); $imagesize = Image::getimagesize($p1); $this->pdf2htmlRatio = round(($imagesize[0] * 0.48) / $this->width, 12); @@ -375,6 +378,11 @@ class FluidbookCompiler extends Base implements CompilerInterface $this->log('Defined dimensions'); } + public function getFinalPath() + { + return $this->dir; + } + public function getSetting($key, $default = null) { @@ -470,7 +478,7 @@ class FluidbookCompiler extends Base implements CompilerInterface public function initConfig() { - if ($this->version !== 'scorm') { + if (!$this->scormVariant) { $this->fluidbookSettings->scorm_enable = false; } diff --git a/app/Models/FluidbookPublication.php b/app/Models/FluidbookPublication.php index 41c57325d..e978a6274 100644 --- a/app/Models/FluidbookPublication.php +++ b/app/Models/FluidbookPublication.php @@ -62,15 +62,6 @@ class FluidbookPublication extends ToolboxSettingsModel { parent::setFields(); -// $this->addField([ -// 'name' => 'name', -// 'type' => FluidbookTitle::class, -// 'label' => __('Titre de la publication'), -// 'default' => '', -// 'column' => true, -// 'translatable' => false, -// 'non_default_tracking' => false, -// ]); $this->addOwnerField(); @@ -330,10 +321,10 @@ class FluidbookPublication extends ToolboxSettingsModel return (float)$this->getDocumentSize($page)[1]; } - public function getFinalPath($theme = null, $version = 'online') + public function getFinalPath($theme = null, $scormVariant = false) { $dir = $this->id; - if (null === $theme || ($theme instanceof FluidbookTheme && $theme->id != $this->theme)) { + if (null !== $theme || ($theme instanceof FluidbookTheme && $theme->id != $this->theme)) { $dir .= '-'; if (is_string($theme) || is_numeric($theme)) { $dir .= $theme; @@ -341,7 +332,7 @@ class FluidbookPublication extends ToolboxSettingsModel $dir .= $theme->id; } } - return protected_path('fluidbookpublication/final/' . $dir . '/' . $version); + return protected_path('fluidbookpublication/final/' . $dir . '/' . ($scormVariant ? 'scorm' : 'online')); } public function getAssetDir() diff --git a/resources/fluidbookpublication/packager/_ffmpeg/libffmpeg.dylib b/resources/fluidbookpublication/packager/_ffmpeg/libffmpeg.dylib new file mode 100644 index 000000000..03951a7b5 Binary files /dev/null and b/resources/fluidbookpublication/packager/_ffmpeg/libffmpeg.dylib differ diff --git a/resources/fluidbookpublication/packager/_ffmpeg/windows-x32-ffmpeg.dll b/resources/fluidbookpublication/packager/_ffmpeg/windows-x32-ffmpeg.dll new file mode 100644 index 000000000..4d335bea9 Binary files /dev/null and b/resources/fluidbookpublication/packager/_ffmpeg/windows-x32-ffmpeg.dll differ diff --git a/resources/fluidbookpublication/packager/_ffmpeg/windows-x64-ffmpeg.dll b/resources/fluidbookpublication/packager/_ffmpeg/windows-x64-ffmpeg.dll new file mode 100644 index 000000000..faa1b7db3 Binary files /dev/null and b/resources/fluidbookpublication/packager/_ffmpeg/windows-x64-ffmpeg.dll differ diff --git a/resources/fluidbookpublication/packager/autorun-html.inf b/resources/fluidbookpublication/packager/autorun-html.inf new file mode 100644 index 000000000..8625bb10b --- /dev/null +++ b/resources/fluidbookpublication/packager/autorun-html.inf @@ -0,0 +1,5 @@ +[autorun] +label=$title +icon=$exe +open=$exe +action=$title \ No newline at end of file diff --git a/resources/fluidbookpublication/packager/autorun.inf b/resources/fluidbookpublication/packager/autorun.inf new file mode 100644 index 000000000..ee85c2a03 --- /dev/null +++ b/resources/fluidbookpublication/packager/autorun.inf @@ -0,0 +1,5 @@ +[autorun] +label=$title +icon=data\fluidbook.ico +open=$exe +action=$title \ No newline at end of file diff --git a/resources/fluidbookpublication/packager/fluidbook.ico b/resources/fluidbookpublication/packager/fluidbook.ico new file mode 100644 index 000000000..fdaa6af8d Binary files /dev/null and b/resources/fluidbookpublication/packager/fluidbook.ico differ diff --git a/resources/fluidbookpublication/packager/html-silent.nsi b/resources/fluidbookpublication/packager/html-silent.nsi new file mode 100644 index 000000000..89ff111a4 --- /dev/null +++ b/resources/fluidbookpublication/packager/html-silent.nsi @@ -0,0 +1,80 @@ +; Fluidbook +;-------------------------------- + +!define FLUIDBOOKNAME "$name" +!define REG_UNINSTALL "Software\Microsoft\Windows\CurrentVersion\Uninstall\$fname" + +Unicode true + +; The name of the installer +Name "${FLUIDBOOKNAME}" + +; The file to write +OutFile "$output" + +; The default installation directory +InstallDir $LOCALAPPDATA\$fname + +; Request application privileges for Windows Vista +RequestExecutionLevel user + +; Style +XPStyle on + +Icon "$favicon" + +; not released +;TargetMinimalOS 5.0 + +; Langues +LoadLanguageFile "$nsisdir/Contrib/Language files/$lang.nlf" + +; Pages + +Page directory +Page instfiles + +; Compression +SetCompress off + +;-------------------------------- + +Function .onInit + SetSilent silent +FunctionEnd + +; The stuff to install +Section "" ;No components page, name is not important + ; Set output path to the installation directory. + SetOutPath $INSTDIR + + ; Put file there + SetOverwrite ifnewer + File /r "$fdir\*" + + ; Create shortcut + CreateShortCut "$SMPROGRAMS\${FLUIDBOOKNAME}.lnk" "$INSTDIR\$fname.exe" "--disable-crash-handler=true" "$INSTDIR\package.nw\icon.ico" + CreateShortCut "$DESKTOP\${FLUIDBOOKNAME}.lnk" "$INSTDIR\$fname.exe" "--disable-crash-handler=true" "$INSTDIR\package.nw\icon.ico" + + WriteRegStr HKCU "${REG_UNINSTALL}" "DisplayName" "${FLUIDBOOKNAME}" + WriteRegStr HKCU "${REG_UNINSTALL}" "DisplayIcon" "$\"$INSTDIR\package.nw\icon.ico$\"" + WriteRegStr HKCU "${REG_UNINSTALL}" "InstallLocation" "$\"$INSTDIR$\"" + WriteRegDWord HKCU "${REG_UNINSTALL}" "NoModify" 1 + WriteRegDWord HKCU "${REG_UNINSTALL}" "NoRepair" 1 + WriteRegStr HKCU "${REG_UNINSTALL}" "UninstallString" "$\"$INSTDIR\Uninstall.exe$\"" + + WriteUninstaller "$INSTDIR\Uninstall.exe" + + ExecShell "" "$INSTDIR\$fname.exe" "--disable-crash-handler=true" +SectionEnd + +Section "Uninstall" + DeleteRegKey HKCU "${REG_UNINSTALL}" + Delete "$SMPROGRAMS\${FLUIDBOOKNAME}.lnk" + Delete "$DESKTOP\${FLUIDBOOKNAME}.lnk" + Delete "$INSTDIR\Uninstall.exe" + RMDIR /r /REBOOTOK $INSTDIR + SetRebootFlag false +SectionEnd + + diff --git a/resources/fluidbookpublication/packager/html.inf b/resources/fluidbookpublication/packager/html.inf new file mode 100644 index 000000000..8b6ece3c1 --- /dev/null +++ b/resources/fluidbookpublication/packager/html.inf @@ -0,0 +1,5 @@ +[autorun] +label=$title +icon=$nwplatform\package.nw\icon.ico +open=$exe +action=$title \ No newline at end of file diff --git a/resources/fluidbookpublication/packager/html.nsi b/resources/fluidbookpublication/packager/html.nsi new file mode 100644 index 000000000..2b80e9f1b --- /dev/null +++ b/resources/fluidbookpublication/packager/html.nsi @@ -0,0 +1,74 @@ +; Fluidbook +;-------------------------------- + +!define FLUIDBOOKNAME "$name" +!define REG_UNINSTALL "Software\Microsoft\Windows\CurrentVersion\Uninstall\$fname" + +Unicode true + +; The name of the installer +Name "${FLUIDBOOKNAME}" + +; The file to write +OutFile "$output" + +; The default installation directory +InstallDir $LOCALAPPDATA\$fname + +; Request application privileges for Windows Vista +RequestExecutionLevel user + +; Style +XPStyle on + +Icon "$favicon" + +; not released +;TargetMinimalOS 5.0 + +; Langues +LoadLanguageFile "$nsisdir/Contrib/Language files/$lang.nlf" + +; Pages + +Page directory +Page instfiles + +; Compression +SetCompress off + +; The stuff to install +Section "" ;No components page, name is not important + ; Set output path to the installation directory. + SetOutPath $INSTDIR + + ; Put file there + SetOverwrite ifnewer + File /r "$fdir\*" + + ; Create shortcut + CreateShortCut "$SMPROGRAMS\${FLUIDBOOKNAME}.lnk" "$INSTDIR\$fname.exe" "--disable-crash-handler=true" "$INSTDIR\package.nw\icon.ico" + CreateShortCut "$DESKTOP\${FLUIDBOOKNAME}.lnk" "$INSTDIR\$fname.exe" "--disable-crash-handler=true" "$INSTDIR\package.nw\icon.ico" + + WriteRegStr HKCU "${REG_UNINSTALL}" "DisplayName" "${FLUIDBOOKNAME}" + WriteRegStr HKCU "${REG_UNINSTALL}" "DisplayIcon" "$\"$INSTDIR\package.nw\icon.ico$\"" + WriteRegStr HKCU "${REG_UNINSTALL}" "InstallLocation" "$\"$INSTDIR$\"" + WriteRegDWord HKCU "${REG_UNINSTALL}" "NoModify" 1 + WriteRegDWord HKCU "${REG_UNINSTALL}" "NoRepair" 1 + WriteRegStr HKCU "${REG_UNINSTALL}" "UninstallString" "$\"$INSTDIR\Uninstall.exe$\"" + + WriteUninstaller "$INSTDIR\Uninstall.exe" + + ExecShell "" "$INSTDIR\$fname.exe" "--disable-crash-handler=true" +SectionEnd + +Section "Uninstall" + DeleteRegKey HKCU "${REG_UNINSTALL}" + Delete "$SMPROGRAMS\${FLUIDBOOKNAME}.lnk" + Delete "$DESKTOP\${FLUIDBOOKNAME}.lnk" + Delete "$INSTDIR\Uninstall.exe" + RMDIR /r /REBOOTOK $INSTDIR + SetRebootFlag false +SectionEnd + + diff --git a/resources/fluidbookpublication/packager/hybrid.html b/resources/fluidbookpublication/packager/hybrid.html new file mode 100644 index 000000000..b504f9acf --- /dev/null +++ b/resources/fluidbookpublication/packager/hybrid.html @@ -0,0 +1,46 @@ + + + + $titre + + + $description + $opengraph + $twittercard + + + + + + + \ No newline at end of file diff --git a/resources/fluidbookpublication/packager/script.nsi b/resources/fluidbookpublication/packager/script.nsi new file mode 100644 index 000000000..7499cb6e6 --- /dev/null +++ b/resources/fluidbookpublication/packager/script.nsi @@ -0,0 +1,74 @@ +; Fluidbook +;-------------------------------- + +!define FLUIDBOOKNAME "$name" +!define REG_UNINSTALL "Software\Microsoft\Windows\CurrentVersion\Uninstall\$fname" + +; The name of the installer +Name "${FLUIDBOOKNAME}" + +; The file to write +OutFile "$output" + +; The default installation directory +InstallDir $LOCALAPPDATA\$fname + +; Request application privileges for Windows Vista +RequestExecutionLevel user + +; Style +XPStyle on + +Icon "$favicon" + +; not released +;TargetMinimalOS 5.0 + +; Langues +LoadLanguageFile "$nsisdir/Contrib/Language files/$lang.nlf" + +; Pages + +Page directory +Page instfiles + +; Compression +SetCompress off + +;-------------------------------- + +; The stuff to install +Section "" ;No components page, name is not important + + ; Set output path to the installation directory. + SetOutPath $INSTDIR + + ; Put file there + File /r "$fdir\*" + + ; Create shortcut + CreateShortCut "$SMPROGRAMS\${FLUIDBOOKNAME}.lnk" "$INSTDIR\$fname.exe" "" "$INSTDIR\data\fluidbook.ico" + CreateShortCut "$DESKTOP\${FLUIDBOOKNAME}.lnk" "$INSTDIR\$fname.exe" "" "$INSTDIR\data\fluidbook.ico" + + WriteRegStr HKCU "${REG_UNINSTALL}" "DisplayName" "${FLUIDBOOKNAME}" + WriteRegStr HKCU "${REG_UNINSTALL}" "DisplayIcon" "$\"$INSTDIR\data\fluidbook.ico$\"" + WriteRegStr HKCU "${REG_UNINSTALL}" "InstallLocation" "$\"$INSTDIR$\"" + WriteRegDWord HKCU "${REG_UNINSTALL}" "NoModify" 1 + WriteRegDWord HKCU "${REG_UNINSTALL}" "NoRepair" 1 + WriteRegStr HKCU "${REG_UNINSTALL}" "UninstallString" "$\"$INSTDIR\Uninstall.exe$\"" + + WriteUninstaller "$INSTDIR\Uninstall.exe" + + ExecShell "" "$INSTDIR\$fname.exe" +SectionEnd + +Section "Uninstall" +DeleteRegKey HKCU "${REG_UNINSTALL}" +Delete "$SMPROGRAMS\${FLUIDBOOKNAME}.lnk" +Delete "$DESKTOP\${FLUIDBOOKNAME}.lnk" +Delete "$INSTDIR\Uninstall.exe" +RMDIR /r /REBOOTOK $INSTDIR +SetRebootFlag false +SectionEnd + +