use Cubist\Util\Files\Files;
use Cubist\Util\PHP;
use Cubist\Util\Text;
+use Exception;
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;
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/' '{}' \;`;
+ }
+ }
}
$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 = [
}
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);
<?php
+
namespace App\Fluidbook\Packager;
+
+use Cubist\Util\CommandLine;
+use Cubist\Util\Files\Files;
+
class WindowsInstaller extends WindowsZIP
{
protected $nsi;
protected $nsifile = 'html';
- public $type='win_ins_html';
+ public $type = 'win_ins_html';
protected function preparePackage()
protected function makeNSI()
{
- global $core;
$winvdir = $this->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`;
}
$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)
use Cubist\Net\SSH2;
use Cubist\Util\CommandLine;
+use Cubist\Util\Files\Files;
use Cubist\Util\Text;
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`;
$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);
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()
{
// 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()