From: vincent@cubedesigners.com Date: Wed, 11 Apr 2018 17:16:46 +0000 (+0000) Subject: #1926 X-Git-Url: http://git.cubedesigners.com/?a=commitdiff_plain;h=27ecc8fdc230f617d049eacc938303d567b34589;p=cubeextranet.git #1926 --- diff --git a/inc/ws/Util/html5/master/class.ws.html5.compiler.php b/inc/ws/Util/html5/master/class.ws.html5.compiler.php index e971ff095..96f4a76fd 100644 --- a/inc/ws/Util/html5/master/class.ws.html5.compiler.php +++ b/inc/ws/Util/html5/master/class.ws.html5.compiler.php @@ -2,290 +2,290 @@ class wsHTML5Compiler { - protected static $resolutions = array(150, 300); - public $maxRes = 300; - - public $jsFiles = array( - 'js/libs/modernizr/modernizr.min.js', - 'js/libs/modernizr/tests.js', - 'js/libs/cube/fb.js', - 'js/libs/cube/util.js', - 'js/libs/screenfull.min.js', - 'js/libs/storage.js', - 'js/libs/keymaster.js', - 'js/libs/jquery/jquery.min.js', - 'js/libs/jquery/jquery.transform.js', - 'js/libs/jquery/jquery.form.min.js', - 'js/libs/jquery/jquery.mousewheel.min.js', - 'js/libs/jquery/jquery.hashchange.min.js', - 'js/libs/jquery/perfect-scrollbar.jquery.min.js', - 'js/libs/mmenu/jquery.mmenu.min.js', - 'js/libs/mmenu/jquery.mmenu.rtl.min.js', - 'js/libs/mmenu/jquery.mmenu.offcanvas.min.js', - 'js/libs/gsap/TweenMax.min.js', - 'js/libs/gsap/jquery.gsap.min.js', - 'js/libs/gal/gal.js', - 'js/libs/gal/gal.filesystem.js', - 'js/libs/hammer.min.js', - 'js/libs/fluidbook/forms/fluidbook.form.bulle.js', - 'js/libs/fluidbook/fluidbook.utils.js', - 'js/libs/fluidbook/fluidbook.links.js', - 'js/libs/fluidbook/fluidbook.support.js', - 'js/libs/fluidbook/fluidbook.video.js', - 'js/libs/fluidbook/fluidbook.viewport.js', - 'js/libs/fluidbook/fluidbook.desktop.js', - 'js/libs/fluidbook/fluidbook.service.js', - 'js/libs/fluidbook/fluidbook.share.js', - 'js/libs/fluidbook/fluidbook.l10n.js', - 'js/libs/fluidbook/fluidbook.slider.js', - 'js/libs/fluidbook/fluidbook.nav.js', - 'js/libs/fluidbook/fluidbook.interface.js', - 'js/libs/fluidbook/fluidbook.touch.js', - 'js/libs/fluidbook/fluidbook.loader.js', - 'js/libs/fluidbook/fluidbook.search.js', - 'js/libs/fluidbook/fluidbook.help.js', - 'js/libs/fluidbook/fluidbook.resize.js', - 'js/libs/fluidbook/fluidbook.stats.js', - 'js/libs/fluidbook/fluidbook.cache.js', - 'js/libs/fluidbook/fluidbook.tooltip.js', - 'js/libs/fluidbook/fluidbook.bookmarks.js', - 'js/libs/fluidbook/fluidbook.background.js', - 'js/libs/fluidbook/fluidbook.pad.js', - 'js/libs/fluidbook/fluidbook.audiodescription.js', - 'js/libs/fluidbook/fluidbook.privacy.js', - 'js/libs/fluidbook/fluidbook.zoom.js', - 'js/libs/fluidbook/fluidbook.menu.js', - 'js/libs/fluidbook/fluidbook.sound.js', - 'js/libs/fluidbook/fluidbook.scorm.js', - 'js/libs/fluidbook/menu/fluidbook.chapters.js', - 'js/libs/fluidbook/menu/fluidbook.index.js', - 'js/libs/fluidbook/fluidbook.landingpage.js', - 'js/libs/fluidbook/fluidbook.js', - 'js/main.js'); - - public $specialJsFiles = array(); - - public $debugJsFiles = array( - 'js/libs/Three.js', - 'data/search.index.js', - ); - public $testJsFiles = array( - 'js/libs/cube/fb.js', - 'js/libs/modernizr/modernizr.min.js', - 'js/libs/modernizr/tests.js', - 'js/libs/jquery/jquery.min.js', - 'js/libs/jquery/jquery.transform.min.js', - 'js/libs/jquery/jquery.mousewheel.min.js', - 'js/libs/jquery/jquery.hashchange.min.js', - 'js/tester.js' - ); - public $widgetJsFiles = array( - 'js/libs/cube/fb.js', - 'js/libs/modernizr/modernizr.min.js', - 'js/libs/modernizr/tests.js', - 'js/libs/jquery/jquery.min.js', - 'js/libs/jquery/jquery.transit.js', - 'js/widget.js' - ); - - // Collection of LESS files to be compiled - // Filename with no extension, relative to the /style directory in the player build folder - public $lessFiles = ['fluidbook']; - - public $specialCSS = array(); - public $phonegapStandardPlugins = array('ios' => array('ExternalFileUtil'), - 'android' => array('webintent')); - public $pluginCSS = array(); - public $pluginJs = array(); - public $htmlmultimedia = array(); - protected $cssX = array(); - protected $cssY = array(); - protected $cssWidths = array(); - protected $pdf2htmlRatio; - protected $scale; - protected $multiply; - protected $div = array(); - protected $numerotation; - protected $fontDocs = array(); - protected $dir; - protected $z = 3; - public $vdir; - public $wdir; - - /** - * - * @var wsBook - */ - public $book; - protected $pages; - protected $theme; - public $version; - public $book_id; - protected $themeRoot; - - /** - * - * @var wsDAOBook - */ - protected $daoBook; - protected $needToRecompileContents = true; - protected $needToRecompileSettings = true; - public $width; - public $height; - protected $cssWidth; - protected $cssHeight; - protected $cssOneWidth; - protected $cssOneHeight; - protected $cssScale; - protected $cssSVGScale; - protected $optimalWidth = 567; - protected $optimalHeight = 709; - protected $additionalConfig = array(); - protected $fontScale = 1; - protected $cache = array(); - protected $backgroundsPrefix = array(); - protected $svg = true; - protected $config = array(); - protected $assets = ''; - protected $phonegap = false; - protected $phonegapVersion; - protected $standalone = false; - protected $hiddenContents = array(); - protected $appcache; - protected $home; - protected $widget = true; - protected $multiApp = false; - protected $pageLabels = array(); - protected $stylesheets = array(); - protected $logfp = null; - protected $logtime = null; - protected $beginBody = array(); - protected $seoArticles = []; - protected $securityPolicyWhitelist = ['*.google-analytics.com', '*.youtube.com', '*.ytimg.com']; - - - function __construct($book_id, $version = 'stable', $phonegap = false, $phonegapVersion = 'latest', $dir = null, $standalone = false, $appcache = false, $home = false) - { - global $core; - - $this->phonegapVersion = wsHTML5::getPhonegapVersion($phonegapVersion); - $this->appcache = $appcache; - $this->multiApp = $this->home = $home; - $this->version = $version; - - if ($version == 'stable') { - $this->assets = WS_COMPILE_ASSETS . '/player/branches/master'; - } else if ($version == 'dev') { - $this->assets = WS_COMPILE_ASSETS . '/player/local/master'; - } else { - list($branch, $location) = explode('|', $version); - $this->assets = WS_COMPILE_ASSETS . '/player/' . ($location == 'git' ? 'branches' : $location) . '/' . $branch; - } - - $this->phonegap = $phonegap; - $this->standalone = $standalone || $this->phonegap; - $this->appcache = $appcache; - $this->widget = !$this->phonegap; - - cubePHP::set_memory('4G'); - - if (trim($book_id) == '') { - return; - } - $this->book_id = $book_id; - $this->log('Start compilation'); - - if (is_null($dir)) { - $this->dir = WS_BOOKS . '/html5/' . $book_id . '/'; - } else { - $this->dir = $dir; - } - $this->vdir = new CubeIT_Files_VirtualDirectory($this->dir); - $this->wdir = WS_BOOKS . '/working/' . $this->book_id . '/'; - - $this->daoBook = new wsDAOBook($core->con); - $this->book = $this->daoBook->selectById($book_id); - $this->pages = $this->daoBook->getPagesOfBook($book_id); - - - $daoTheme = new wsDAOTheme($core->con); - $this->theme = $daoTheme->getThemeOfBook($book_id, true); - $this->themeRoot = WS_THEMES . '/' . $this->theme->theme_id . '/'; - - $daoDoc = new wsDAODocument($core->con); - $firstDoc = $daoDoc->selectById($this->pages[1]['document_id']); - $size = $firstDoc->generalInfos['size']; - - $this->log('Got data from database'); - - $this->width = round($size[0], 3); - $this->height = round($size[1], 3); - - $imagesize = CubeIT_Image::getimagesize(wsDocument::getDir($this->pages[1]['document_id']) . 'html/h150-' . $this->pages[1]['document_page'] . '.jpg'); - $this->pdf2htmlRatio = round(($imagesize[0] * 0.48) / $this->width, 3); - - $this->cssScale = $this->z * min($this->optimalWidth / $this->width, $this->optimalHeight / $this->height); - $this->cssOneScale = $this->z * min(($this->optimalWidth * 2) / $this->width, $this->optimalHeight / $this->height); - - $this->cssWidth = $this->width * $this->cssScale; - $this->cssHeight = $this->height * $this->cssScale; - - $this->cssOneWidth = $this->width * $this->cssOneScale; - $this->cssOneHeight = $this->height * $this->cssOneScale; - - $this->cssSVGScale = 1; - - $this->scale = 1; - if ($this->book->parametres->zoomMode == 1) { - $this->multiply = $this->pdf2htmlRatio * $this->scale * $this->cssOneScale; - } else { - $this->multiply = $this->pdf2htmlRatio * $this->scale * $this->cssScale; - } - $this->numerotation = explode(',', $this->book->numerotation); - - $this->initConfig(); - $this->log('Defined dimensions'); - } - - public function initConfig() - { - $this->config = cubeObject::merge($this->book->parametres->toStandardObject(), $this->theme->parametres->toStandardObject()); - $this->config->rasterizePages = cubeArray::parseRange($this->config->rasterizePages); - $this->config->vectorPages = array_diff(cubeArray::parseRange($this->config->vectorPages), $this->config->rasterizePages); - } - - public function log($step) - { - $currenttime = microtime(true); - if (null === $this->logfp) { - $this->logfp = fopen('/var/log/extranet/htmlconversions/' . $this->book_id . '.log', 'w+'); - } - if (null === $this->logtime) { - $this->logtime = $currenttime; - } - $time = $currenttime - $this->logtime; - $log = $step . ' | ' . round($time, 3) . 's' . "\n"; - fwrite($this->logfp, $log); - fflush($this->logfp); - $this->logtime = $currenttime; - } - - public function addFacebookSDK() - { - $lang = str_replace('-', '_', $this->book->lang); - $e = explode('_', $lang); - if (count($e) > 1) { - $e[1] = mb_strtoupper($lang); - } - $lang = implode('_', $e); - - $langsMap = ['fr' => 'fr_FR', 'en' => 'en_US']; - - if (isset($langsMap[$lang])) { - $lang = $langsMap[$lang]; - } - - $this->beginBody[] = "
+ protected static $resolutions = array(150, 300); + public $maxRes = 300; + + public $jsFiles = array( + 'js/libs/modernizr/modernizr.min.js', + 'js/libs/modernizr/tests.js', + 'js/libs/cube/fb.js', + 'js/libs/cube/util.js', + 'js/libs/screenfull.min.js', + 'js/libs/storage.js', + 'js/libs/keymaster.js', + 'js/libs/jquery/jquery.min.js', + 'js/libs/jquery/jquery.transform.js', + 'js/libs/jquery/jquery.form.min.js', + 'js/libs/jquery/jquery.mousewheel.min.js', + 'js/libs/jquery/jquery.hashchange.min.js', + 'js/libs/jquery/perfect-scrollbar.jquery.min.js', + 'js/libs/mmenu/jquery.mmenu.min.js', + 'js/libs/mmenu/jquery.mmenu.rtl.min.js', + 'js/libs/mmenu/jquery.mmenu.offcanvas.min.js', + 'js/libs/gsap/TweenMax.min.js', + 'js/libs/gsap/jquery.gsap.min.js', + 'js/libs/gal/gal.js', + 'js/libs/gal/gal.filesystem.js', + 'js/libs/hammer.min.js', + 'js/libs/fluidbook/forms/fluidbook.form.bulle.js', + 'js/libs/fluidbook/fluidbook.utils.js', + 'js/libs/fluidbook/fluidbook.links.js', + 'js/libs/fluidbook/fluidbook.support.js', + 'js/libs/fluidbook/fluidbook.video.js', + 'js/libs/fluidbook/fluidbook.viewport.js', + 'js/libs/fluidbook/fluidbook.desktop.js', + 'js/libs/fluidbook/fluidbook.service.js', + 'js/libs/fluidbook/fluidbook.share.js', + 'js/libs/fluidbook/fluidbook.l10n.js', + 'js/libs/fluidbook/fluidbook.slider.js', + 'js/libs/fluidbook/fluidbook.nav.js', + 'js/libs/fluidbook/fluidbook.interface.js', + 'js/libs/fluidbook/fluidbook.touch.js', + 'js/libs/fluidbook/fluidbook.loader.js', + 'js/libs/fluidbook/fluidbook.search.js', + 'js/libs/fluidbook/fluidbook.help.js', + 'js/libs/fluidbook/fluidbook.resize.js', + 'js/libs/fluidbook/fluidbook.stats.js', + 'js/libs/fluidbook/fluidbook.cache.js', + 'js/libs/fluidbook/fluidbook.tooltip.js', + 'js/libs/fluidbook/fluidbook.bookmarks.js', + 'js/libs/fluidbook/fluidbook.background.js', + 'js/libs/fluidbook/fluidbook.pad.js', + 'js/libs/fluidbook/fluidbook.audiodescription.js', + 'js/libs/fluidbook/fluidbook.privacy.js', + 'js/libs/fluidbook/fluidbook.zoom.js', + 'js/libs/fluidbook/fluidbook.menu.js', + 'js/libs/fluidbook/fluidbook.sound.js', + 'js/libs/fluidbook/fluidbook.scorm.js', + 'js/libs/fluidbook/menu/fluidbook.chapters.js', + 'js/libs/fluidbook/menu/fluidbook.index.js', + 'js/libs/fluidbook/fluidbook.landingpage.js', + 'js/libs/fluidbook/fluidbook.js', + 'js/main.js'); + + public $specialJsFiles = array(); + + public $debugJsFiles = array( + 'js/libs/Three.js', + 'data/search.index.js', + ); + public $testJsFiles = array( + 'js/libs/cube/fb.js', + 'js/libs/modernizr/modernizr.min.js', + 'js/libs/modernizr/tests.js', + 'js/libs/jquery/jquery.min.js', + 'js/libs/jquery/jquery.transform.min.js', + 'js/libs/jquery/jquery.mousewheel.min.js', + 'js/libs/jquery/jquery.hashchange.min.js', + 'js/tester.js' + ); + public $widgetJsFiles = array( + 'js/libs/cube/fb.js', + 'js/libs/modernizr/modernizr.min.js', + 'js/libs/modernizr/tests.js', + 'js/libs/jquery/jquery.min.js', + 'js/libs/jquery/jquery.transit.js', + 'js/widget.js' + ); + + // Collection of LESS files to be compiled + // Filename with no extension, relative to the /style directory in the player build folder + public $lessFiles = ['fluidbook']; + + public $specialCSS = array(); + public $phonegapStandardPlugins = array('ios' => array('ExternalFileUtil'), + 'android' => array('webintent')); + public $pluginCSS = array(); + public $pluginJs = array(); + public $htmlmultimedia = array(); + protected $cssX = array(); + protected $cssY = array(); + protected $cssWidths = array(); + protected $pdf2htmlRatio; + protected $scale; + protected $multiply; + protected $div = array(); + protected $numerotation; + protected $fontDocs = array(); + protected $dir; + protected $z = 3; + public $vdir; + public $wdir; + + /** + * + * @var wsBook + */ + public $book; + protected $pages; + protected $theme; + public $version; + public $book_id; + protected $themeRoot; + + /** + * + * @var wsDAOBook + */ + protected $daoBook; + protected $needToRecompileContents = true; + protected $needToRecompileSettings = true; + public $width; + public $height; + protected $cssWidth; + protected $cssHeight; + protected $cssOneWidth; + protected $cssOneHeight; + protected $cssScale; + protected $cssSVGScale; + protected $optimalWidth = 567; + protected $optimalHeight = 709; + protected $additionalConfig = array(); + protected $fontScale = 1; + protected $cache = array(); + protected $backgroundsPrefix = array(); + protected $svg = true; + protected $config = array(); + protected $assets = ''; + protected $phonegap = false; + protected $phonegapVersion; + protected $standalone = false; + protected $hiddenContents = array(); + protected $appcache; + protected $home; + protected $widget = true; + protected $multiApp = false; + protected $pageLabels = array(); + protected $stylesheets = array(); + protected $logfp = null; + protected $logtime = null; + protected $beginBody = array(); + protected $seoArticles = []; + protected $securityPolicyWhitelist = ['*.google-analytics.com', '*.youtube.com', '*.ytimg.com']; + + + function __construct($book_id, $version = 'stable', $phonegap = false, $phonegapVersion = 'latest', $dir = null, $standalone = false, $appcache = false, $home = false) + { + global $core; + + $this->phonegapVersion = wsHTML5::getPhonegapVersion($phonegapVersion); + $this->appcache = $appcache; + $this->multiApp = $this->home = $home; + $this->version = $version; + + if ($version == 'stable') { + $this->assets = WS_COMPILE_ASSETS . '/player/branches/master'; + } else if ($version == 'dev') { + $this->assets = WS_COMPILE_ASSETS . '/player/local/master'; + } else { + list($branch, $location) = explode('|', $version); + $this->assets = WS_COMPILE_ASSETS . '/player/' . ($location == 'git' ? 'branches' : $location) . '/' . $branch; + } + + $this->phonegap = $phonegap; + $this->standalone = $standalone || $this->phonegap; + $this->appcache = $appcache; + $this->widget = !$this->phonegap; + + cubePHP::set_memory('4G'); + + if (trim($book_id) == '') { + return; + } + $this->book_id = $book_id; + $this->log('Start compilation'); + + if (is_null($dir)) { + $this->dir = WS_BOOKS . '/html5/' . $book_id . '/'; + } else { + $this->dir = $dir; + } + $this->vdir = new CubeIT_Files_VirtualDirectory($this->dir); + $this->wdir = WS_BOOKS . '/working/' . $this->book_id . '/'; + + $this->daoBook = new wsDAOBook($core->con); + $this->book = $this->daoBook->selectById($book_id); + $this->pages = $this->daoBook->getPagesOfBook($book_id); + + + $daoTheme = new wsDAOTheme($core->con); + $this->theme = $daoTheme->getThemeOfBook($book_id, true); + $this->themeRoot = WS_THEMES . '/' . $this->theme->theme_id . '/'; + + $daoDoc = new wsDAODocument($core->con); + $firstDoc = $daoDoc->selectById($this->pages[1]['document_id']); + $size = $firstDoc->generalInfos['size']; + + $this->log('Got data from database'); + + $this->width = round($size[0], 3); + $this->height = round($size[1], 3); + + $imagesize = CubeIT_Image::getimagesize(wsDocument::getDir($this->pages[1]['document_id']) . 'html/h150-' . $this->pages[1]['document_page'] . '.jpg'); + $this->pdf2htmlRatio = round(($imagesize[0] * 0.48) / $this->width, 3); + + $this->cssScale = $this->z * min($this->optimalWidth / $this->width, $this->optimalHeight / $this->height); + $this->cssOneScale = $this->z * min(($this->optimalWidth * 2) / $this->width, $this->optimalHeight / $this->height); + + $this->cssWidth = $this->width * $this->cssScale; + $this->cssHeight = $this->height * $this->cssScale; + + $this->cssOneWidth = $this->width * $this->cssOneScale; + $this->cssOneHeight = $this->height * $this->cssOneScale; + + $this->cssSVGScale = 1; + + $this->scale = 1; + if ($this->book->parametres->zoomMode == 1) { + $this->multiply = $this->pdf2htmlRatio * $this->scale * $this->cssOneScale; + } else { + $this->multiply = $this->pdf2htmlRatio * $this->scale * $this->cssScale; + } + $this->numerotation = explode(',', $this->book->numerotation); + + $this->initConfig(); + $this->log('Defined dimensions'); + } + + public function initConfig() + { + $this->config = cubeObject::merge($this->book->parametres->toStandardObject(), $this->theme->parametres->toStandardObject()); + $this->config->rasterizePages = cubeArray::parseRange($this->config->rasterizePages); + $this->config->vectorPages = array_diff(cubeArray::parseRange($this->config->vectorPages), $this->config->rasterizePages); + } + + public function log($step) + { + $currenttime = microtime(true); + if (null === $this->logfp) { + $this->logfp = fopen('/var/log/extranet/htmlconversions/' . $this->book_id . '.log', 'w+'); + } + if (null === $this->logtime) { + $this->logtime = $currenttime; + } + $time = $currenttime - $this->logtime; + $log = $step . ' | ' . round($time, 3) . 's' . "\n"; + fwrite($this->logfp, $log); + fflush($this->logfp); + $this->logtime = $currenttime; + } + + public function addFacebookSDK() + { + $lang = str_replace('-', '_', $this->book->lang); + $e = explode('_', $lang); + if (count($e) > 1) { + $e[1] = mb_strtoupper($lang); + } + $lang = implode('_', $e); + + $langsMap = ['fr' => 'fr_FR', 'en' => 'en_US']; + + if (isset($langsMap[$lang])) { + $lang = $langsMap[$lang]; + } + + $this->beginBody[] = "
"; - $this->securityPolicyWhitelist[] = '*.facebook.net'; - $this->securityPolicyWhitelist[] = 'data:'; - } - - public function addPageLabel($page, $label) - { - $this->pageLabels[$label] = $page; - } - - public function getResolutions() - { - $res = []; - foreach (self::$resolutions as $r) { - if ($r > $this->maxRes) { - continue; - } - $res[] = $r; - } - if ($this->widget) { - $res = array_merge(array(36), $res); - } - return $res; - } - - public function getCssScale() - { - return $this->cssScale; - } - - public function virtualToPhysical($virtual) - { - if (isset($this->pageLabels[$virtual])) { - return $virtual; - } - if (!in_array($virtual, $this->numerotation)) { - return 1; - } - $p = array_search($virtual, $this->numerotation); - return $p + 1; - } - - public function compile($delete = true) - { - - $this->log('Start compile process'); - - // Raw copy of some directories - $directories = array('style/fonts', 'images', 'sound', 'video'); - foreach ($directories as $directory) { - $from = $this->assets . '/' . $directory; - $this->vdir->copyDirectory($from, $directory); - } - - $this->log('Copied assets'); - $this->loadPlugins(); - $this->log('Plugins loaded'); - $this->writeImages(); - $this->log('Images written'); - $linksCSS = $this->writeLinks(); - $this->log('Links written'); - $this->writeCSS('data/style/style_%d.css', $linksCSS); - $this->log('CSS written'); - $this->writeLangs(); - $this->log('Langs written'); - $this->writeIndex(); - $this->log('Index written'); - $this->writeSounds(); - $this->log('Sound written'); - $this->writeTexts(); - $this->log('Texts written'); - $this->writeExtras(); - $this->log('Extras written'); - $this->writeJs(); - $this->log('Js written'); - $this->writeSEO(); - $this->vdir->sync($delete); - $this->log('Files Synced'); - } - - protected function loadPlugins() - { - $e = explode("\n", $this->book->parametres->mobilePlugins); - - $main = array_pop($this->jsFiles); - - $plugins = array(); - - foreach ($e as $plugin) { - $plugin = trim($plugin); - if ($plugin == '') { - continue; - } - - $d = 'plugins/' . str_replace('.', '/', $plugin); - $dir = $this->assets . '/' . $d; - if (!file_exists($dir)) { - continue; - } - - $plugins[] = $plugin; - - if (file_exists($dir . '/plugin.js')) { - $f = $d . '/plugin.js'; - $this->pluginJs[] = $f; - $this->vdir->copy($dir . '/plugin.js', $f); - } - if (file_exists($dir . '/plugin.css')) { - $f = $d . '/plugin.css'; - $this->pluginCSS[] = $f; - $this->vdir->copy($dir . '/plugin.css', $f); - } - } - - $this->config->plugins = $plugins; - - array_push($this->jsFiles, $main); - } - - public function getVideosFormats($poster = true) - { - $res = []; - // - // if (!$this->phonegap) { - // $res = array('ogv', 'webm', 'mp4', 'flv'); - // } elseif ($this->phonegap == 'ios') { - // $res = array('mp4'); - // } else if ($this->phonegap == 'android') { - // $res = array('webm', 'mp4'); - // } - - $res[] = 'mp4'; - - if ($poster) { - $res[] = 'jpg'; - } - return $res; - } - - /** - * Helper function to add a unique script entry to the JS stack. - * Normally this is a relative path but it can be an external URL. - * External URLs are added to the pluginJs collection instead of jsFiles. - * Duplicate paths are ignored. - * @param $path - */ - public function addJs($path, $collection = null) - { - - if (null === $collection) { - // If JS is external, it will be included via the pluginJs collection - // Otherwise, it will be compiled into the main JS file - $collection = (preg_match('#^https?://#i', $path) === 1) ? 'pluginJs' : 'jsFiles'; - } - - if (!in_array($path, $this->$collection)) { - $this->{$collection}[] = $path; - } - } - - /** - * Helper function to add a unique stylesheet entry to the LESS stack for compilation - * Duplicate paths are ignored. - * @param $path The path of the file relative to the /style folder, without any extension - * @param $extra_files Optional array of extra files that should be copied across for use during LESS compilation - */ - public function addLess($path) - { - if (!in_array($path, $this->lessFiles)) { - $this->lessFiles[] = $path; - } - } - - protected function writeSounds() - { - if ($this->book->parametres->soundTheme == '') { - return; - } - $this->vdir->copyDirectory(WS_SOUNDS . '/' . $this->book->parametres->soundTheme, 'data/sounds'); - } - - protected function writeIndex() - { - global $core; - - $html = file_get_contents($this->assets . '/_index.html'); - $uhtml = $html; - - $titre = $this->book->parametres->title; - - - $daoSignature = new wsDAOSignature($core->con); - $signature = $daoSignature->selectById($this->book->parametres->signature); - - $exportSignature = array('main' => $signature->main, - 'mainLink' => $signature->mainLink, - 'partner' => $signature->partner, - 'partnerLink' => $signature->partnerLink); - - $credits = ''; - if ($signature->partner != '') { - $credits = '' . $signature->partner . ' '; - } - $credits .= '' . $signature->main . ''; - - $hiddenContents = implode("\n", $this->hiddenContents); - - $bgcolor = $this->theme->parametres->loadingBackColor; - - // Google analytics - $ga = ''; - if ($this->book->parametres->googleAnalytics != '') { - $ga = cubePage::googleAnalytics($this->book->parametres->googleAnalytics); - } - if ($this->book->parametres->googleAnalyticsCustom != '') { - $ga .= $this->book->parametres->googleAnalyticsCustom; - } - - $statsfooter = ''; - if ($this->book->parametres->statsCustom != '') { - $statsfooter = $this->book->parametres->statsCustom; - } - // Feuilles de style - $sheets = array_merge($this->stylesheets, $this->specialCSS); - - $style = array(); - foreach ($sheets as $sheet) { - $style[] = ''; - } - $style = implode("\n\t\t", $style); - - $pagesContents = ''; - - $cache = ''; - - $beginbody = implode("\n", array_unique($this->beginBody)); - - $iscript = ''; - if (count($this->htmlmultimedia)) { - $iscript .= '' . "\n"; - } - - $script = ''; - $script .= '' . "\n"; - $script .= '' . "\n"; - if ($this->book->parametres->scorm_enable) { - $script .= '' . "\n"; - $this->writeScorm(); - } - if (count($this->specialJsFiles)) { - $script .= '' . "\n"; - } - foreach ($this->pluginJs as $p) { - $script .= '' . "\n"; - } - $script .= $iscript; - $description = ''; - - $socialTitle = $this->book->parametres->facebook_title ? $this->book->parametres->facebook_title : $titre; - $socialDescription = $this->book->parametres->seoDescription ? $this->book->parametres->seoDescription : $this->book->parametres->seoDescription; - $socialImage = 'https://workshop.fluidbook.com/services/facebook_thumbnail?id=' . $this->book_id . '&j=' . time(); - $dim = CubeIT_Image::getimagesize($socialImage); - $socialImageWidth = $dim[0]; - $socialImageHeight = $dim[1]; - - $twittercard = ' + $this->securityPolicyWhitelist[] = '*.facebook.net'; + $this->securityPolicyWhitelist[] = 'data:'; + } + + public function addPageLabel($page, $label) + { + $this->pageLabels[$label] = $page; + } + + public function getResolutions() + { + $res = []; + foreach (self::$resolutions as $r) { + if ($r > $this->maxRes) { + continue; + } + $res[] = $r; + } + if ($this->widget) { + $res = array_merge(array(36), $res); + } + return $res; + } + + public function getCssScale() + { + return $this->cssScale; + } + + public function virtualToPhysical($virtual) + { + if (isset($this->pageLabels[$virtual])) { + return $virtual; + } + if (!in_array($virtual, $this->numerotation)) { + return 1; + } + $p = array_search($virtual, $this->numerotation); + return $p + 1; + } + + public function compile($delete = true) + { + + $this->log('Start compile process'); + + // Raw copy of some directories + $directories = array('style/fonts', 'images', 'sound', 'video'); + foreach ($directories as $directory) { + $from = $this->assets . '/' . $directory; + $this->vdir->copyDirectory($from, $directory); + } + + $this->log('Copied assets'); + $this->loadPlugins(); + $this->log('Plugins loaded'); + $this->writeImages(); + $this->log('Images written'); + $linksCSS = $this->writeLinks(); + $this->log('Links written'); + $this->writeCSS('data/style/style_%d.css', $linksCSS); + $this->log('CSS written'); + $this->writeLangs(); + $this->log('Langs written'); + $this->writeIndex(); + $this->log('Index written'); + $this->writeSounds(); + $this->log('Sound written'); + $this->writeTexts(); + $this->log('Texts written'); + $this->writeExtras(); + $this->log('Extras written'); + $this->writeJs(); + $this->log('Js written'); + $this->writeSEO(); + $this->vdir->sync($delete); + $this->log('Files Synced'); + } + + protected function loadPlugins() + { + $e = explode("\n", $this->book->parametres->mobilePlugins); + + $main = array_pop($this->jsFiles); + + $plugins = array(); + + foreach ($e as $plugin) { + $plugin = trim($plugin); + if ($plugin == '') { + continue; + } + + $d = 'plugins/' . str_replace('.', '/', $plugin); + $dir = $this->assets . '/' . $d; + if (!file_exists($dir)) { + continue; + } + + $plugins[] = $plugin; + + if (file_exists($dir . '/plugin.js')) { + $f = $d . '/plugin.js'; + $this->pluginJs[] = $f; + $this->vdir->copy($dir . '/plugin.js', $f); + } + if (file_exists($dir . '/plugin.css')) { + $f = $d . '/plugin.css'; + $this->pluginCSS[] = $f; + $this->vdir->copy($dir . '/plugin.css', $f); + } + } + + $this->config->plugins = $plugins; + + array_push($this->jsFiles, $main); + } + + public function getVideosFormats($poster = true) + { + $res = []; + // + // if (!$this->phonegap) { + // $res = array('ogv', 'webm', 'mp4', 'flv'); + // } elseif ($this->phonegap == 'ios') { + // $res = array('mp4'); + // } else if ($this->phonegap == 'android') { + // $res = array('webm', 'mp4'); + // } + + $res[] = 'mp4'; + + if ($poster) { + $res[] = 'jpg'; + } + return $res; + } + + /** + * Helper function to add a unique script entry to the JS stack. + * Normally this is a relative path but it can be an external URL. + * External URLs are added to the pluginJs collection instead of jsFiles. + * Duplicate paths are ignored. + * @param $path + */ + public function addJs($path, $collection = null) + { + + if (null === $collection) { + // If JS is external, it will be included via the pluginJs collection + // Otherwise, it will be compiled into the main JS file + $collection = (preg_match('#^https?://#i', $path) === 1) ? 'pluginJs' : 'jsFiles'; + } + + if (!in_array($path, $this->$collection)) { + $this->{$collection}[] = $path; + } + } + + /** + * Helper function to add a unique stylesheet entry to the LESS stack for compilation + * Duplicate paths are ignored. + * @param $path The path of the file relative to the /style folder, without any extension + * @param $extra_files Optional array of extra files that should be copied across for use during LESS compilation + */ + public function addLess($path) + { + if (!in_array($path, $this->lessFiles)) { + $this->lessFiles[] = $path; + } + } + + protected function writeSounds() + { + if ($this->book->parametres->soundTheme == '') { + return; + } + $this->vdir->copyDirectory(WS_SOUNDS . '/' . $this->book->parametres->soundTheme, 'data/sounds'); + } + + protected function writeIndex() + { + global $core; + + $html = file_get_contents($this->assets . '/_index.html'); + $uhtml = $html; + + $titre = $this->book->parametres->title; + + + $daoSignature = new wsDAOSignature($core->con); + $signature = $daoSignature->selectById($this->book->parametres->signature); + + $exportSignature = array('main' => $signature->main, + 'mainLink' => $signature->mainLink, + 'partner' => $signature->partner, + 'partnerLink' => $signature->partnerLink); + + $credits = ''; + if ($signature->partner != '') { + $credits = '' . $signature->partner . ' '; + } + $credits .= '' . $signature->main . ''; + + $hiddenContents = implode("\n", $this->hiddenContents); + + $bgcolor = $this->theme->parametres->loadingBackColor; + + // Google analytics + $ga = ''; + if ($this->book->parametres->googleAnalytics != '') { + $ga = cubePage::googleAnalytics($this->book->parametres->googleAnalytics); + } + if ($this->book->parametres->googleAnalyticsCustom != '') { + $ga .= $this->book->parametres->googleAnalyticsCustom; + } + + $statsfooter = ''; + if ($this->book->parametres->statsCustom != '') { + $statsfooter = $this->book->parametres->statsCustom; + } + // Feuilles de style + $sheets = array_merge($this->stylesheets, $this->specialCSS); + + $style = array(); + foreach ($sheets as $sheet) { + $style[] = ''; + } + $style = implode("\n\t\t", $style); + + $pagesContents = ''; + + $cache = ''; + + $beginbody = implode("\n", array_unique($this->beginBody)); + + $iscript = ''; + if (count($this->htmlmultimedia)) { + $iscript .= '' . "\n"; + } + + $script = ''; + $script .= '' . "\n"; + $script .= '' . "\n"; + if ($this->book->parametres->scorm_enable) { + $script .= '' . "\n"; + $this->writeScorm(); + } + if (count($this->specialJsFiles)) { + $script .= '' . "\n"; + } + foreach ($this->pluginJs as $p) { + $script .= '' . "\n"; + } + $script .= $iscript; + $description = ''; + + $socialTitle = $this->book->parametres->facebook_title ? $this->book->parametres->facebook_title : $titre; + $socialDescription = $this->book->parametres->seoDescription ? $this->book->parametres->seoDescription : $this->book->parametres->seoDescription; + $socialImage = 'https://workshop.fluidbook.com/services/facebook_thumbnail?id=' . $this->book_id . '&j=' . time(); + $dim = CubeIT_Image::getimagesize($socialImage); + $socialImageWidth = $dim[0]; + $socialImageHeight = $dim[1]; + + $twittercard = ' '; - $opengraph = ' + $opengraph = ' '; - $favicon = ''; - $hasIos = false; - if ($this->theme->parametres->iosicon != '') { - $hasIos = true; - $this->vdir->copy($this->themeRoot . '/' . $this->theme->parametres->iosicon, 'data/apple-touch-icon.png'); - $favicon .= ''; - } - if ($this->theme->parametres->favicon != '') { - - $pngFile = $this->themeRoot . '/' . $this->theme->parametres->favicon; - $icoFile = $this->themeRoot . '/favicon.ico'; - if (!file_exists($icoFile) || filemtime($icoFile) < filemtime($pngFile) || filemtime(__FILE__) > filemtime($icoFile)) { - $tmp = CubeIT_Files::tempnam() . '.png'; - $convert = "convert $pngFile -resize 64x64^ -gravity center $tmp"; - `$convert`; - - $icotool = new cubeCommandLine('icotool'); - $icotool->setArg('c'); - $icotool->setArg('o', $icoFile); - $icotool->setArg(null, $tmp); - $icotool->execute(); - - unlink($tmp); - } - $this->vdir->copy($pngFile, 'data/favicon.png'); - $this->vdir->copy($icoFile, 'data/favicon.ico'); - $favicon .= ''; - $favicon .= ''; - $favicon .= ''; - if (!$hasIos) { - $favicon .= ''; - } - } - - $print = $this->writePrint(); - $message = sprintf($this->__('Your browser is not up to date and is not able to run this publication. %sLearn more%s'), '
', ''); - - $splash = ''; - if ($this->theme->parametres->logoLoader && file_exists($this->themeRoot . $this->theme->parametres->logoLoader)) { - $dim = CubeIT_Image::getimagesize($this->themeRoot . $this->theme->parametres->logoLoader); - if ($dim !== false) { - $this->vdir->copy($this->themeRoot . '/' . $this->theme->parametres->logoLoader, 'data/images/' . $this->theme->parametres->logoLoader); - $splash .= ''; - } - } - - $svgfiles = array($this->assets . '/images/interface.svg', WS_ICONS . '/' . $this->theme->parametres->iconSet . '/interface.svg'); - $svg = ''; - foreach ($svgfiles as $svgfile) { - if (file_exists($svgfile)) { - $svg .= file_get_contents($svgfile); - } else { - die($svgfile . ' does not exist'); - } - } - - if ($this->phonegap) { - $csp = "securityPolicyWhitelist)) . "; img-src * data:\">"; - } - $vars = array('titre', 'credits', 'statsfooter', 'ga', 'style', 'script', 'pagesContents', 'description', 'print', 'hiddenContents', 'splash', 'cache', 'bgcolor', 'message', 'favicon', 'svg', 'beginbody', 'csp', 'opengraph', 'twittercard'); - foreach ($vars as $v) { - if (isset($$v)) { - $html = str_replace('', $$v, $html); - } else { - $html = str_replace('', '', $html); - } - } - - $scripts = array(); - foreach ($this->debugJsFiles as $js) { - $scripts[] = ''; - } - foreach ($this->jsFiles as $js) { - $scripts[] = ''; - } - foreach ($this->pluginJs as $js) { - $scripts[] = ''; - } - - $scripts[] = ''; - $scripts[] = $iscript; - $script = implode("\n\t\t", $scripts); - - $scripts = array(); - foreach ($this->testJsFiles as $js) { - $scripts[] = ''; - } - $scripts[] = ''; - $script_test = implode("\n\t\t", $scripts); - - $thtml = $uhtml; - - $vars = array('titre', 'credits', 'statsfooter', 'ga', 'style', 'script', 'pagesContents', 'print', 'hiddenContents', 'splash', 'cache', 'bgcolor', 'message', 'favicon'); - foreach ($vars as $v) { - $uhtml = str_replace('', $$v, $uhtml); - } - - $script .= "\n\t\t" . ''; - $vars = array('titre', 'credits', 'statsfooter', 'ga', 'style', 'script', 'print', 'hiddenContents', 'splash', 'message'); - foreach ($vars as $v) { - $thtml = str_replace('', $$v, $thtml); - } - - $this->vdir->file_put_contents('index.html', $html); - $this->vdir->file_put_contents('indexu.html', $uhtml); - $this->vdir->file_put_contents('indext.html', $thtml); - - // Write widget html - if ($this->widget) { - $whtml = file_get_contents($this->assets . '/widget.html'); - $script = ''; - $script .= ''; - - $style = ''; - $vars = array('titre', 'style', 'script'); - foreach ($vars as $v) { - $whtml = str_replace('', $$v, $whtml); - } - $this->vdir->file_put_contents('widget.html', $whtml); - } - } - - function writeSEO() - { - foreach ($this->seoArticles as $seoArticle) { - $html = file_get_contents($this->assets . '/_seo.html'); - $a = $seoArticle; - unset($a['image']); - $a['imageurl'] = 'https://workshop.fluidbook.com/services/facebook_thumbnail?id=15793&j=' . time(); - if ($seoArticle['image']) { - $a['imageurl'] .= '&image=' . $seoArticle['image']; - } - $dim = CubeIT_Image::getimagesize($a['imageurl']); - $a['imagewidth'] = $dim[0]; - $a['imageheight'] = $dim[1]; - foreach ($a as $k => $v) { - $html = str_replace('$' . $k, $v, $html); - } - $this->vdir->file_put_contents('p/' . $seoArticle['url'], $html); - } - } - - protected function writeScorm() - { - $manifest = file_get_contents($this->assets . '/_imsmanifest.xml'); - if (!$this->book->parametres->scorm_title) { - $this->book->parametres->scorm_title = $this->book->parametres->title; - } - if (!$this->book->parametres->scorm_id) { - $this->book->parametres->scorm_id = 'fb_' . $this->book->parametres->id; - } - if (!$this->book->parametres->scorm_org) { - $this->book->parametres->scorm_org = 'Fluidbook'; - } - $vars = array('scorm_id', 'scorm_org', 'scorm_title'); - foreach ($vars as $v) { - $manifest = str_replace('$' . $v, $this->book->parametres->$v, $manifest); - } - $this->vdir->file_put_contents('imsmanifest.xml', $manifest); - - $variables = []; - $e = CubeIT_Text::explodeNewLines($this->book->parametres->scorm_variables); - foreach ($e as $item) { - $item = trim($item); - if ($item == '') { - continue; - } - $f = explode('=', $item, 2); - $variables[$f[0]] = $f[1]; - } - $this->config->scorm_variables = $this->book->parametres->scorm_variables = $variables; - } - - protected function writePrint() - { - - if (!$this->book->parametres->print && !$this->book->parametres->pdf) { - return; - } - - $this->vdir->copy(WS_BOOKS . '/final/' . $this->book->book_id . '/data/' . $this->book->parametres->pdfName, 'data/' . $this->book->parametres->pdfName); - return ''; - } - - protected function addFilesInfos($key, $file) - { - if (!file_exists($file)) { - return; - } - if (!isset($this->config->filesInfos)) { - $this->config->filesInfos = array(); - } - $infos = array('filesize' => filesize($file)); - $dim = CubeIT_Image::getimagesize($file); - if ($dim !== false) { - $infos['width'] = $dim[0]; - $infos['height'] = $dim[1]; - } - $this->config->filesInfos[$key] = $infos; - } - - protected function __($str) - { - if (!isset($this->config->l10n)) { - $this->writeLangs(); - } - - if (isset($this->config->l10n['default']->$str)) { - return $this->config->l10n['default']->$str; - } else { - return $str; - } - } - - protected function writeLangs() - { - global $core; - $daoLang = new wsDAOLang($core->con); - $lang = $daoLang->selectById($this->book->lang); - $langs = $daoLang->selectAll(); - - $traductions = (!count($this->book->traductions)) ? $lang->traductions : $this->book->traductions; - - $this->config->l10n = array(); - $this->config->l10n['default'] = $traductions; - $this->config->defaultLang = $this->book->lang; - - foreach ($langs as $lang) { - $this->config->l10n[$lang->lang_id] = $lang->traductions; - } - $iso = l10n::getISOcodes(); - if ($this->book->parametres->multilang != '') { - $flagsDir = 'images/flags'; - if (!file_exists($flagsDir)) { - mkdir($flagsDir); - } - $ml = str_replace("\r", "\n", $this->book->parametres->multilang); - $ml = str_replace("\n\n", "\n", $ml); - $e = explode("\n", $ml); - $m = array(); - foreach ($e as $l1) { - $l = explode(',', $l1); - $flag = $l[1]; - - $ll = explode('-', $l[0]); - - $this->vdir->copy(cubeMedia::getFlagFile($flag), $flagsDir . '/' . $flag . '.png'); - $l[3] = cubeText::ucfirst($iso[$l[0]]); - $l[4] = cubeCountry::getCountryName($flag, $ll[0]); - $m[] = implode(',', $l); - } - - $this->config->multilang = implode("\n", $m); - } - } - - protected function writeExtras() - { - if ($this->theme->parametres->afterSearch != '') { - $this->vdir->copy($this->themeRoot . '/' . $this->theme->parametres->afterSearch, 'data/images/' . $this->theme->parametres->afterSearch); - } - if ($this->book->parametres->externalArchives != '') { - $this->addFilesInfos('archives', $this->wdir . '/' . $this->book->parametres->externalArchives); - $this->vdir->copy($this->wdir . '/' . $this->book->parametres->externalArchives, 'data/images/' . $this->book->parametres->externalArchives); - } - - if ($this->book->parametres->navExtraImage != '') { - $this->vdir->copy($this->wdir . '/' . $this->book->parametres->navExtraImage, 'data/images/' . $this->book->parametres->navExtraImage); - } - - if ($this->book->parametres->navExtraImageMobile != '') { - $this->vdir->copy($this->wdir . '/' . $this->book->parametres->navExtraImageMobile, 'data/images/' . $this->book->parametres->navExtraImageMobile); - } - - for ($i = 1; $i <= 5; $i++) { - $ic = $this->book->parametres->{'navExtraIcon' . $i}; - if ($ic != '') { - $this->vdir->copy($this->wdir . '/' . $ic, 'data/images/' . $ic); - } - } - - } - - protected function writeLinks() - { - global $core; - - if ($this->book->parametres->customLinkClass == 'WescoSalesLink') { - $this->specialJsFiles[] = 'js/libs/interact.min.js'; - $this->specialJsFiles[] = 'js/libs/fluidbook/special/wescosales.js'; - $this->specialCSS[] = 'wescosales'; - } - - if ($this->book->parametres->customLinkClass == 'AtlanticDownloadLink') { - $this->specialJsFiles[] = 'js/libs/fluidbook/special/atlanticdownload.js'; - $this->specialCSS[] = 'atlanticdownload'; - } - - $this->config->links = array(); - $this->config->clinks = array(); - $this->config->bookmarkGroups = array(); - - $ignore = $this->book->parametres->ignoreLinksTypes; - if (!$ignore) { - $ignore = array(); - } else { - $ignore = split(',', $ignore); - } - - if ($this->book->parametres->externalChaptersHTML != '') { - $d = $this->unzipFile($this->book->parametres->externalChaptersHTML, false, 'data/chapters/'); - $meta = $this->getConfigZIP($d['dir']); - $this->config->externalChaptersSize = new stdClass(); - $this->config->externalChaptersSize->width = $meta['width']; - $this->config->externalChaptersSize->height = $meta['height']; - $this->vdir->copyDirectory($d['dir'], $d['fdir']); - } - - $daoDoc = new wsDAODocument($core->con); - $daoDoc->getLinksAndRulers($this->book_id, $links, $rulers); - - // Custom landing page content - if ($this->book->parametres->landingPage != '') { - $d = $this->unzipFile($this->book->parametres->landingPage, false, 'data/landing-page/'); - $this->vdir->copyDirectory($d['dir'], $d['fdir']); - } - - if ($this->book->parametres->tabsHTML5 != '') { - $links[] = [ - 'page' => 'background', - 'top' => 0, - 'left' => 0, - 'width' => 100, - 'height' => 100, - 'type' => 6, - 'to' => $this->book->parametres->tabsHTML5, - 'alternative' => $this->book->parametres->tabsHTML5, - 'image' => '', - 'inline' => 1, - 'interactive' => 1, - 'class' => 'tabslink', - ]; - } - - - foreach ($links as $linkData) { - if (isset($linkData['image']) && $linkData['image'] && $linkData['type'] != 28) { - $dupData = $linkData; - $dupData['image'] = ''; - $dupData['to'] = $linkData['image']; - $dupData['type'] = 15; - array_push($links, $dupData); - } - } - - $i = 0; - $pages = array(); - $cpages = array(); - $css = array(); - - usort($links, array($this, '_sortLinks')); - - foreach ($links as $linkData) { - if (in_array($linkData['type'], $ignore)) { - continue; - } - if ($linkData['type'] == 28) { - $this->addSEOArticle($linkData['page'], $linkData['to'], $linkData['extra'], $linkData['image']); - continue; - } - $link = wsHTML5Link::getInstance($this->base62($i), $linkData, $this); - if (is_null($link)) { - continue; - } - - // Make old "aftersearch" link compatible with new "extra" menu option by extracting link URL - if ($link->page == 'aftersearch') { - $this->config->afterSearchLink = $link->to; - $this->config->afterSearchTooltip = $link->infobulle; - } - - - $c = $link->getHTMLContainer(); - $css[] = $link->getCSSContainer(); - if (!isset($pages[$link->page])) { - $pages[$link->page] = ''; - $cpages[$link->page] = ''; - } - if ($link instanceof contentLink) { - $cpages[$link->page] .= $c; - } else { - $pages[$link->page] .= $c; - } - - if ($link->keep()) { - $this->hiddenContents[] = $c; - } - $i++; - } - - $allpages = range(0, $this->book->parametres->pages + 1); - if ($this->book->parametres->themeEnableAfterSearch) { - $allpages[] = 'aftersearch'; - } - $allpages[] = 'background'; - $allpages[] = 'archives'; - - foreach ($allpages as $i) { - - $c = ''; - $cc = ''; - if (isset($pages[$i])) { - $c = $pages[$i]; - } - if (isset($cpages[$i])) { - $cc = $cpages[$i]; - } - $this->config->links[$i] = $c; - $this->config->clinks[$i] = $cc; - } - return $css; - } - - public function addSEOArticle($page, $title, $intro, $image) - { - $this->seoArticles[$title] = ['title' => $title, 'description' => $intro, 'image' => $image, 'content' => '', 'page' => $page, 'url' => CubeIT_Text::str2URL($title) . '.html']; - } - - public function _sortLinks($a, $b) - { - $priorities = array(26 => 1); - - $pa = isset($priorities[$a['type']]) ? $priorities[$a['type']] : 0; - $pb = isset($priorities[$b['type']]) ? $priorities[$b['type']] : 0; - return $pb - $pa; - } - - public function addBookmarkGroup($link) - { - if ($link['left'] > $this->book->parametres->width) { - //$link['page']++; - } - if ($link['page'] <= 0 || $link['page'] > $this->book->parametres->pages) { - return; - } - - $this->config->bookmarkGroups[] = array('page' => ($link['page']), 'nb' => $link['to'], 'name' => $link['extra']); - } - - public function addAudiodescription($link) - { - $this->config->audiodescription[$link['page']] = $link['to']; - $this->copyLinkFile($link['to'], 'data/audiodescription/'); - } - - protected function writeJs() - { - $config = $this->writeConfig(); - $this->vdir->file_put_contents('data/datas.js', $config); - $finals = array('fluidbook' => $this->jsFiles); - if ($this->book->parametres->scorm_enable) { - $finals['scorm'] = array(); - $finals['scorm'][] = 'js/libs/scorm/apiwrapper.js'; - $finals['scorm'][] = 'js/libs/scorm/scorm.js'; - } - if (count($this->specialJsFiles)) { - $finals['special'] = $this->specialJsFiles; - } - if ($this->widget) { - $finals['widget'] = $this->widgetJsFiles; - } - - foreach ($finals as $jsfinal => $files) { - $mintime = 0; - $hash = hash('sha256', json_encode($files)); - $minimized = $this->assets . '/js/min/' . $jsfinal . '-' . $hash . '-min.js'; - if (!file_exists(dirname($minimized))) { - mkdir(dirname($minimized)); - } - if (file_exists($minimized)) { - $mintime = filemtime($minimized); - $reminimize = false; - } else { - $mintime = 0; - $reminimize = true; - } - - if (!$reminimize) { - foreach ($files as $file) { - if (filemtime($this->assets . '/' . $file) > $mintime) { - $reminimize = true; - break; - } - } - } - - if (!$reminimize) { - if (filemtime(__FILE__) > $mintime || (file_exists(__DIR__ . '/class.ws.html5.links.php') && filemtime(__DIR__ . '/class.ws.html5.links.php') > $mintime)) { - $reminimize = true; - } - } - - if ($reminimize) { - $js = ''; - foreach ($files as $file) { - $js .= file_get_contents($this->assets . '/' . $file); - $js .= ";\n\n"; - } - $tmp = cubeFiles::tempnam(); - file_put_contents($tmp, $js); - - unlink($minimized); - - $uglify = new CubeIT_CommandLine('/usr/local/bin/uglifyjs'); - $uglify->setArg('o', $minimized); - $uglify->setArg(null, $tmp); - $uglify->execute(); - $uglify->debug(); - - if (!file_exists($minimized)) { - die('An error occured while uglifying : ' . $uglify->output); - } - } - $dest = 'data/' . $jsfinal . '.js'; - $this->vdir->copy($minimized, $dest); - } - - - if ($this->phonegap) { - $this->vdir->copy(WS_COMPILE_ASSETS . '/_html5/js/libs/phonegap/' . $this->phonegapVersion . '/cordova-' . $this->phonegap . '.js', 'data/cordova.js'); - } - - } - - public function writeTexts() - { - $this->daoBook->makeTextsIndexes($this->book, $this->pages, $index, $textes, true); - $this->vdir->file_put_contents('data/search.index.js', 'var INDEX=' . $index . ';' . "\r"); - if ($this->book->parametres->highlightResults) { - $this->vdir->file_put_contents('data/search.highlight.js', 'var HIGHLIGHTS=' . json_encode($this->daoBook->makeHighlightIndex($this->book, $this->pages)) . ";\r"); - } - if ($this->book->parametres->searchWordSelectionAlgorithm == 'expression') { - $this->vdir->file_put_contents('data/search.texts.js', 'var TEXTS=' . $textes . ";\r"); - } - } - - public function supportSVG() - { - if (!$this->phonegap) { - return false; - } else if ($this->phonegap == 'ios') { - return true; - } else { - return false; - } - } - - protected function writeConfig() - { - $this->config->numerotation = explode(',', $this->book->numerotation); - $this->config->id = $this->book->book_id; - $this->config->cid = $this->book->cid; - $this->config->cacheDate = TIME; - $this->config->width = $this->cssWidth; - $this->config->height = $this->cssHeight; - $this->config->optimalWidth = $this->optimalWidth; - $this->config->optimalHeight = $this->optimalHeight; - $this->config->chapters = $this->book->chapters; - $this->config->videoFormats = $this->getVideosFormats(false); - $this->config->htmlmultimedia = $this->htmlmultimedia; - $this->config->phonegap = $this->phonegap; - $this->config->retinaResolution = min($this->book->parametres->maxResolution, $this->maxRes); - $this->config->pageLabels = $this->pageLabels; - $this->config->pageZoomFactor = $this->z; - $this->config->multiply = $this->multiply; - $this->config->cssScale = $this->cssScale; - $this->config->pdfZoomFactor = $this->pdf2htmlRatio; - if ($this->home) { - $this->config->home = 'http://home'; - } - $this->config->multiApp = $this->multiApp; - foreach ($this->additionalConfig as $k => $v) { - $this->config->$k = $v; - } - if ($this->phonegap && ($this->book->parametres->offlineLink == '' || $this->book->parametres->offlineLink == 'http://')) { - $this->config->share = false; - } - - // We need to be able to reference both navOrder and navOrderH so convert both to arrays - // We also make sure there are no empty items in the arrays (see: http://php.net/manual/en/function.array-filter.php#111091) - $this->config->navOrder = array_filter(array_map('trim', explode(',', $this->config->navOrder)), 'strlen'); - $this->config->navOrderH = array_filter(array_map('trim', explode(',', $this->config->navOrderH)), 'strlen'); - - $this->config->standalone = $this->standalone; - if ($this->config->phonegap) { - $this->config->manifest = $this->writeManifest(); - } - - if ($this->config->basket) { - if (file_exists($this->config->basketReferences) || CubeIT_Util_Url::isDistant($this->config->basketReferences)) { - $referencesFile = $this->config->basketReferences; - } else { - $referencesFile = $this->wdir . '/commerce/' . $this->config->basketReferences; - } - - if (file_exists($referencesFile) || CubeIT_Util_Url::isDistant($referencesFile)) { - $ext = CubeIT_Files::getExtension($referencesFile); - if ($ext == 'xlsx') { - $this->config->basketReferences = wsUtil::excelToArray($referencesFile); - if ($this->book->parametres->customLinkClass == 'AtlanticDownloadLink') { - $this->config->basketReferences = wsUtil::atlanticReferences($this->config->basketReferences, 'local/', array($this, 'log'), array($this->vdir, "copy")); - } - } - $this->log("Done cart references"); - } - } - $this->config->seoArticles = $this->seoArticles; - - return 'var DATAS=' . json_encode($this->config) . ';' . "\n"; - } - - protected function writeManifest() - { - $res = array(); - } - - protected function writeIcons() - { - $res = array(); - // Get the colors used to colorize graphics - if ($this->theme->parametres->colorizeIcons) { - $couleurI = $this->theme->parametres->couleurI; - } else { - $couleurI = 'FFFFFF'; - } - - $couleurM = $this->theme->parametres->subTextColor; - - $bookmarksDisabledColors = array('star' => $this->theme->parametres->bookmarkStarDisabledColor, 'bookmark' => $this->theme->parametres->bookmarkBackgroundColor); - $bookmarksEnabledColors = array('star' => $this->theme->parametres->bookmarkStarEnabledColor, 'bookmark' => $this->theme->parametres->bookmarkBackgroundColor); - $subTextColor = $this->theme->parametres->subTextColor; - - $arrowsColor = $this->theme->parametres->arrowsColor; - // Set the icon list with the color - $icons = array('interface-down' => $arrowsColor, 'interface-close' => $arrowsColor, - 'interface-audio-description-on' => $arrowsColor, 'interface-audio-description-off' => $arrowsColor, - 'help-fingers' => $couleurI, 'help-mouse' => $couleurI, - 'bookmark-left-off' => $bookmarksDisabledColors, 'bookmark-left-on' => $bookmarksEnabledColors, - 'bookmark-right-off' => $bookmarksDisabledColors, 'bookmark-right-on' => $bookmarksEnabledColors - ); - - $this->config->iconsDimensions = array(); - $makepng = !$this->supportSVG(); - $tmpdir = CubeIT_Files::tmpdir(); - foreach ($icons as $icon => $color) { - wsTools::colorizeAndRasterizeIcon($this->theme->parametres->iconSet, $icon, $color, $tmpdir, 4, $w, $h); - $this->config->iconsDimensions[$icon] = array($w, $h); - } - $this->vdir->copyDirectory($tmpdir, 'data/images'); - $this->vdir->addTemp($tmpdir); - return $res; - } - - protected function writeImages() - { - global $core; - - switch ($this->book->parametres->mobileVersion) { - case 'html5-desktop': - $this->backgroundsPrefix = array('t', 'p'); - $this->svg = true; - break; - case 'html5-images': - $this->backgroundsPrefix = array('t'); - $this->svg = false; - break; - default: - $this->backgroundsPrefix = array('p'); - $this->svg = true; - break; - } - - $thumbs = array(); - foreach ($this->pages as $page => $infos) { - $docdir = wsDocument::getDir($infos['document_id']); - if ($this->svg) { - $full = $docdir . 'html/fp' . $infos['document_page'] . '.svg'; - $fullopt = $docdir . 'html/fo' . $infos['document_page'] . '%s.svg'; - $orig = $docdir . 'html/tp' . $infos['document_page'] . '.svg'; - $opt = $docdir . 'html/to' . $infos['document_page'] . '.svg'; - - if (!file_exists($full) || filemtime($full) < 1503671520) { - if (!isset($doc) || $doc->document_id != $infos['document_id']) { - $dao = new wsDAODocument($core->con); - $doc = $dao->selectById($infos['document_id']); - } - $doc->makeSVGFile($infos['document_page']); - } - wsDocument::extractTexts($full, $orig); - wsTools::optimizeSVG($orig, $opt); - wsTools::optimizeSVG($full, $fullopt, [150, 300]); - - if (in_array($page, $this->config->vectorPages)) { - $this->vdir->copy(str_replace('%s', '-150', $fullopt), 'data/contents/p' . $page . '.svg'); - } else { - $this->vdir->copy($opt, 'data/contents/p' . $page . '.svg'); - } - } - - - foreach ($this->getResolutions() as $r) { - foreach ($this->backgroundsPrefix as $backgroundsPrefix) { - $srcPrefix = $backgroundsPrefix; - if ($backgroundsPrefix == 'p') { - $srcPrefix = 'h'; - } - $ok = $this->vdir->copy($docdir . 'html/' . $srcPrefix . $r . '-' . $infos['document_page'] . '.jpg', 'data/background/' . $r . '/' . $backgroundsPrefix . $page . '.jpg'); - if (!$ok && $r = 300) { - $this->maxRes = 150; - } - } - } - - $thumb = false; - if ($this->book->parametres->pdfThumbnails) { - $thumb = wsPDFConvert::getThumbFromPDF(WS_BOOKS . '/working/' . $this->book->book_id . '/' . $this->book->parametres->pdfThumbnails, $page); - } - if (!$thumb) { - $thumb = $docdir . 'p' . $infos['document_page'] . '.jpg'; - } - - $thumbs[$page] = $thumb; - $this->vdir->copy($thumb, 'data/thumbnails/p' . $page . '.jpg'); - - if ($page == 1) { - $this->_makeCover($docdir . 'html/t36-' . $infos['document_page'] . '.jpg'); - } - - $this->log('Copied image ' . $page); - } - - - $this->makeThumbSprites($thumbs); - $this->log('Made thumbnails'); - } - - public function makeThumbSprites(array $thumbs) - { - $cols = 10; - $rows = 10; - $perSprite = $cols * $rows; - $k = 0; - $res = ''; - $pages = count($thumbs); - - $hash = ''; - for ($i = 1; $i <= $pages; $i += $perSprite) { - $num = min(1 + $pages - $i, $perSprite); - $srows = ceil($num / $cols); - $files = array(); - $mtime = 0; - for ($j = 0; $j < $perSprite; $j++) { - $p = $i + $j; - if ($p > $pages) { - break; - } - $files[] = $thumbs[$p]; - $hash .= $thumbs[$p] . '--' . filemtime($thumbs[$p]); - } - - $cache = WS_CACHE . '/thumbsprites/' . hash('sha256', $hash) . '.jpg'; - $dest = 'data/thumbnails/s' . $k . '.jpg'; - if (!file_exists($cache)) { - $ratio = $this->width / $this->height; - $thumbh = round(100 / $ratio); - $cmd = 'montage ' . implode(' ', $files) . ' -geometry 100x' . $thumbh . '!+0+0 -background transparent -tile ' . $cols . 'x' . $srows . ' ' . $cache; - $res .= `$cmd`; - } - $this->vdir->copy($cache, $dest); - $k++; - } - return $res; - } - - protected function _makeCover($orig) - { - $size = CubeIT_Image::getimagesize($orig); - $w = $size[0]; - $h = $size[1]; - - $tmp = cubeFiles::tempnam() . '.png'; - - $c = new cubeCommandLine('convert'); - $c->setArg(null, ROOT . '/images/ws/shade-cover-app.png'); - $c->setManualArg('-resize ' . round($w / 3) . 'x' . $h); - $c->setArg(null, $tmp); - $c->execute(); - - $res = cubeFiles::tempnam() . '.jpg'; - - $convert = new cubeCommandLine('composite'); - $cmd = '-compose Multiply '; - $cmd .= $tmp . ' ' . $orig . ' '; - $cmd .= $res; - $convert->setManualArg($cmd); - $convert->execute(); - - $this->vdir->copy($res, 'cover.jpg', true); - - unlink($tmp); - } - - protected function _lessBoolean($val) - { - return $val ? 'true' : 'false'; - } - - protected function writeCSS($file, $links) - { - $res = array(); - - $lessContents = ''; - - $lessVariables = array(); - $lessVariables['slider-display'] = $this->_lessBoolean($this->theme->parametres->pagesBar); - $lessVariables['slider-thumb-background'] = wsHTML5::colorToCSS($this->theme->parametres->pageBarThumbBack); - - // General theme - $cssWidth = $this->cssWidth; - $cssHeight = $this->cssHeight; - $cssScale = $this->cssScale; - $w2 = ($cssWidth * 2) . 'px'; - - - $h = $cssHeight . 'px'; - - $wm = ($this->width * $this->multiply) . 'px'; - $hm = ($this->height * $this->multiply) . 'px'; - $w = $cssWidth . 'px'; - $offsetLeft = round(($this->optimalWidth - $cssWidth) / 2, 3); - $offsetLeft2 = $offsetLeft * 2; - $offsetTop = round(($this->optimalHeight - $cssHeight) / 2, 3); - $navTop = ($cssHeight - 40 - 100) / 2; - $leftOfRightPage = (floor($cssWidth) - 1) . 'px'; - - $lessVariables['z'] = $this->z; - $lessVariables['book-page-width'] = $w; - $lessVariables['book-page-height'] = $h; - $lessVariables['book-page-ratio'] = floatval($w) / floatval($h); - - $lessVariables['shadow-opacity'] = wsHTML5::colorToArray($this->theme->parametres->bookShadeColor)['opacity'] * 1.2; - $lessVariables['edges-display'] = $this->_lessBoolean($this->theme->parametres->usePageEdges); - - $res[] = '.portrait #pages,.portrait .doublePage.page,.page,.doublePage._3d{width:' . $w . ';max-width:' . $w . ';height:' . $h . ';max-height:' . $h . '}'; - $res[] = '.doublePage,#pages,#links,#searchHighlights{width:' . $w2 . ';max-width:' . $w2 . ';height:' . $h . ';max-height:' . $h . '}'; - $res[] = '.landscape .doublePage._2d.axis_x.next{' . wsHTML5::writeCSSUA('transform', 'translate3d(' . $w2 . ',0,0)') . '}'; - $res[] = '.landscape .doublePage._2d.axis_x.prev{' . wsHTML5::writeCSSUA('transform', 'translate3d(-' . $w2 . ',0,0)') . '}'; - $res[] = '.portrait .doublePage._2d.axis_x.next{' . wsHTML5::writeCSSUA('transform', 'translate3d(' . $w . ',0,0)') . '}'; - $res[] = '.portrait .doublePage._2d.axis_x.prev{' . wsHTML5::writeCSSUA('transform', 'translate3d(-' . $w . ',0,0)') . '}'; - $res[] = '.doublePage._2d.axis_y.next{' . wsHTML5::writeCSSUA('transform', 'translate3d(0,' . $h . ',0)') . '}'; - $res[] = '.doublePage._2d.axis_y.prev{' . wsHTML5::writeCSSUA('transform', 'translate3d(0,-' . $h . ',0)') . '}'; - - $res[] = '.doublePage._3d{left:' . $w . ';}'; - $res[] = '#links.right{left:-' . $w . ';}'; - $res[] = '.landscape .page.right{left:' . $w . '}'; - - $lessVariables['page-number-color'] = wsHTML5::colorToCSS($this->theme->parametres->colorPageNumber); - $lessVariables['display-page-number'] = $this->_lessBoolean($this->theme->parametres->displayPageNumber); - $lessVariables['page-transition-duration'] = $this->book->parametres->mobileTransitionDuration . 's'; - - - $res[] = '.background{width:100%;height:100%}'; - - if ($this->cssSVGScale != 1) { - $texts = '.texts{' . wsHTML5::writeCSSUA('transform-origin', 'top left') . ';'; - $texts .= wsHTML5::writeCSSUA('transform', 'scale(' . round((1 / $this->multiply) * $cssScale * $this->cssSVGScale, 3) . ')') . ';'; - $texts .= 'width:' . ($wm / $this->cssSVGScale) . 'px; max-width:' . ($wm / $this->cssSVGScale) . 'px;'; - $texts .= 'height:' . ($hm / $this->cssSVGScale) . 'px; max-height:' . ($hm / $this->cssSVGScale) . 'px;'; - $texts .= '}'; - } else { - $texts = '.texts{width:' . floor(floatval($w) + 4) . 'px;height:' . floor(floatval($h) + 4) . 'px;}'; - } - $res[] = $texts; - - // Theme - $shade = '.page .shade{'; - $shade .= 'opacity:' . min(($this->theme->parametres->shadeAlpha * 2) / 100, 1) . ';'; - $shade .= '}'; - $res[] = $shade; - - // SVG - $res[] = 'svg .fill-c-menu-back{fill:' . wsHTML5::colorToCSS($this->theme->parametres->couleurB) . ';}'; - $res[] = 'svg .fill-c-menu-text{fill:' . wsHTML5::colorToCSS($this->theme->parametres->subTextColor) . ';}'; - - // Background - $res[] = $this->_cssBackground(); - - // Archives - // Header - $header = 'header{'; - $header .= 'height:' . $this->theme->parametres->menuHeight . 'px;'; - if ($this->theme->parametres->menuImage != '') { - $this->vdir->copy($this->themeRoot . '/' . $this->theme->parametres->menuImage, 'data/images/' . $this->theme->parametres->menuImage); - $header .= 'background-image:url(../images/' . $this->theme->parametres->menuImage . ');'; - $header .= 'background-repeat:no-repeat;'; - $header .= 'background-size:100% ' . $this->theme->parametres->menuHeight . 'px;'; - } else { - $header .= 'background-color:' . wsHTML5::colorToCSS($this->theme->parametres->menuColor) . ';'; - } - $header .= '}'; - $res[] = $header; - - //Icons - $res = array_merge($res, $this->writeIcons()); - $res[] = '#nav #locales{background-color:' . wsHTML5::colorToCSS($this->theme->parametres->couleurI) . ';}'; - - // Logo - $logo = '#logo{'; - if ($this->theme->parametres->logo) { - $this->vdir->copy($this->themeRoot . '/' . $this->theme->parametres->logo, 'data/images/' . $this->theme->parametres->logo); - $dim = CubeIT_Image::getimagesize($this->themeRoot . '/' . $this->theme->parametres->logo); - $logo .= 'background-image:url(../images/' . $this->theme->parametres->logo . ');width:' . $dim[0] . 'px;height:' . $dim[1] . 'px;'; - } - $logo .= '}'; - $res[] = $logo; - - // Credits - $res[] = 'footer,footer a{color:' . wsHTML5::colorToCSS($this->theme->parametres->creditsColor) . ';}'; - - // Arrows - $lessVariables['arrows-background'] = wsHTML5::colorToCSS($this->theme->parametres->couleurA); - $lessVariables['arrows-color'] = wsHTML5::colorToCSS($this->theme->parametres->arrowsColor); - - // Loader - $lessVariables['loader-background-color'] = wsHTML5::colorToCSS($this->theme->parametres->couleurA); - $lessVariables['loader-foreground-color'] = wsHTML5::colorToCSS($this->theme->parametres->arrowsColor); - - // Audio description buttons - $lessVariables['audiodescription-background'] = wsHTML5::colorToCSS($this->theme->parametres->couleurA); - $lessVariables['audiodescription-color'] = wsHTML5::colorToCSS($this->theme->parametres->couleurA); - - // Links Styles - $lessVariables['links-color'] = wsHTML5::colorToCSS($this->theme->parametres->linksColor); - $res = array_merge($res, $links); - - // Bookmarks - if (!isset($this->book->parametres->bookmarkCornerSize)) { - $this->book->parametres->bookmarkCornerSize = 10; - } - $lessVariables['bookmark-corner-size'] = round($this->width * $this->book->parametres->bookmarkCornerSize * 0.0075 * $this->z) . 'px'; - $lessVariables['bookmark-corner-offset'] = $this->book->parametres->bookmarkOffset . 'px'; - - // Menus - $menuColor = new CubeIT_Graphics_Color($this->theme->parametres->couleurB); - $menuColor->setAlpha(1); - $menuTextColor = wsHTML5::colorToCSS($this->theme->parametres->subTextColor); - $menuBreakpoint = empty($this->book->parametres->menuBreakpoint) ? '1023px' : $this->book->parametres->menuBreakpoint; - - $lessVariables['menu-breakpoint'] = $menuBreakpoint; - $lessVariables['menu-background'] = $menuColor->toCSS(); - if ($this->theme->parametres->subSecondaryColor) { - $lessVariables['menu-button-background'] = wsHTML5::colorToCSS($this->theme->parametres->subSecondaryColor); - } else { - $lessVariables['menu-background-green'] = 'max(45, min(255-45, green(@menu-background)))'; - $lessVariables['menu-background-red'] = 'max(45, min(255-45, red(@menu-background)))'; - $lessVariables['menu-background-blue'] = 'max(45, min(255-45, blue(@menu-background)))'; - $lessVariables['menu-button-background'] = 'overlay(rgb(@menu-background-red, @menu-background-green, @menu-background-blue), #c0c0c0)'; - } - - $lessVariables['menu-text'] = $menuTextColor; - $lessVariables['menu-field-background'] = wsHTML5::colorToCSS($this->theme->parametres->subFieldColor); - $lessVariables['menu-field-text'] = wsHTML5::colorToCSS($this->theme->parametres->subTextFieldColor); - $lessVariables['menu-select-background'] = wsHTML5::colorToCSS($this->theme->parametres->subSelectColor); - $lessVariables['menu-select-text'] = wsHTML5::colorToCSS($this->theme->parametres->subTextSelectColor); - $lessVariables['icon-color'] = wsHTML5::colorToCSS($this->theme->parametres->couleurI); - $lessVariables['menu-overlay'] = wsHTML5::colorToCSS($this->theme->parametres->popupVideoOverlay); - - // Chapters - - - foreach ($this->book->chapters as $chapter) { - if (substr($chapter->page, 0, 1) != '#') { - continue; - } - if ($chapter->color == '') { - continue; - } - $color = trim($chapter->color, '#'); - $lessContents .= '.mview.c_' . $color . '{.menu-color(#' . $color . ');}'; - } - - // Archives - if ($this->book->parametres->externalArchivesBack) { - $this->vdir->copy($this->wdir . '/' . $this->book->parametres->externalArchivesBack, 'data/images/' . $this->book->parametres->externalArchivesBack); - $res[] = '.mview.archives{background-image:url("../images/' . $this->book->parametres->externalArchivesBack . '");}'; - } - - # Index - $ratio = $this->width / $this->height; - $thumbh = round(100 / $ratio); - $this->config->thumbHeight = $thumbh; - $lessVariables['thumb-height'] = $thumbh . 'px'; - - #tooltip - $lessVariables['tooltip-background'] = wsHTML5::colorToCSS($this->theme->parametres->tooltipBackColor); - $lessVariables['tooltip-color'] = wsHTML5::colorToCSS($this->theme->parametres->tooltipTextColor); - - # ZoomPopup close button background - $res[] = '.zoomPopupClose {background-color:' . wsHTML5::colorToCSS($this->theme->parametres->couleurB) . ';}'; - - - $this->_writeLess($lessVariables, $lessContents); - - $res = array_chunk($res, 3500); - foreach ($res as $k => $css) { - $this->stylesheets[] = 'data/style/style_' . $k . '.css'; - $this->vdir->file_put_contents(sprintf($file, $k), implode("\n", $css)); - $this->log('Write CSS ' . sprintf($file, $k)); - } - return count($res); - } - - protected function _writeLess($variables, $lessContents = '') - { - if ($this->widget) { - $this->lessFiles[] = 'widget'; - } - foreach ($this->specialCSS as $s) { - $this->lessFiles[] = 'special/' . $s; - } - - $tmp = CubeIT_Files::tmpdir(); - - $from = $this->assets . '/style/*'; - `cp -r $from $tmp`; - - $bookVariables = array(); - foreach ($variables as $k => $v) { - $bookVariables[] = '@' . trim($k) . ':' . $v . ';'; - } - file_put_contents($tmp . '/book-variables.less', implode("\n", $bookVariables)); - file_put_contents($tmp . '/additional.less', $lessContents); - - foreach ($this->lessFiles as $f) { - $source_less = $this->assets . '/style/' . $f . '.less'; - $destination_less = $tmp . '/' . $f . '.less'; - $destination_css = $tmp . '/' . $f . '.css'; - - if (!file_exists($source_less)) { - continue; - } - - // LESS file might be in a subfolder, so create if it doesn't exist - if (!is_dir(dirname($destination_less))) { - mkdir(dirname($destination_less), 0777, true); - } - - // Less files must be copied to temporary directory so they'll - // have access to the variables generated in book-variables.less - copy($source_less, $destination_less); - $less = new CubeIT_CommandLine('/usr/local/bin/lessc'); - $less->setArg(null, $destination_less); - $less->setArg(null, $destination_css); - $less->execute(); - $less->debug(); - if (!file_exists($destination_css)) { - die($less->output); - } - $this->vdir->copy($destination_css, 'style/' . $f . '.css'); - if ($f != 'widget') { - $this->stylesheets[] = 'style/' . $f . '.css'; - } - } - } - - protected function _cssBackground() - { - $body = '#background,#splash{'; - $body .= 'background-color:#' . $this->theme->parametres->backgroundColor . ' !important;'; - switch ($this->theme->parametres->repeat) { - case wsTheme::REPEAT: - $body .= 'background-repeat:repeat;'; - break; - case wsTheme::NONE: - $body .= 'background-repeat:no-repeat;'; - break; - case wsTheme::RATIO: - $body .= 'background-repeat:no-repeat;'; - $body .= 'background-size:cover;'; - break; - case wsTheme::STRETCH: - $body .= 'background-repeat:no-repeat;'; - $body .= 'background-size:100% 100%;'; - break; - } - if ($this->theme->parametres->backgroundImage != '') { - $bi = $this->themeRoot . '/' . $this->theme->parametres->backgroundImage; - if (file_exists($bi)) { - $dbi = CubeIT_Image::getimagesize($bi); - $this->config->backgroundImageDimensions = array('width' => $dbi[0], 'height' => $dbi[1]); - } - - $this->vdir->copy($this->themeRoot . '/' . $this->theme->parametres->backgroundImage, 'data/images/' . $this->theme->parametres->backgroundImage); - $body .= 'background-image:url(../images/' . $this->theme->parametres->backgroundImage . ');'; - $body .= 'background-position:'; - - switch ($this->theme->parametres->backgroundVAlign) { - case wsTheme::TOP: - $body .= 'top'; - break; - case wsTheme::MIDDLE: - $body .= 'center'; - break; - case wsTheme::BOTTOM: - $body .= 'bottom'; - break; - } - $body .= ' '; - switch ($this->theme->parametres->backgroundHAlign) { - case wsTheme::LEFT: - $body .= 'left'; - break; - case wsTheme::CENTER: - $body .= 'center'; - break; - case wsTheme::RIGHT: - $body .= 'right'; - break; - } - $body .= ';'; - } - - $body .= '}'; - - return $body; - } - - public static function writeCSSUA($property, $value) - { - $res = array(); - foreach (self::$uaPrefixes as $prefix) { - $res[] = $prefix . $property . ':' . $value; - } - return implode(';', $res); - } - - protected function base62($val) - { - $chars = '0123456789abcdefghijklmnopqrstuvwxyz'; - $base = strlen($chars); - $str = ''; - do { - $i = $val % $base; - $str = $chars[$i] . $str; - $val = ($val - $i) / $base; - } while ($val > 0); - return $str; - } - - public function copyLinkDir($source, $dest) - { - $this->vdir->copyDirectory($source, $dest); - } - - public function simpleCopyLinkFile($source, $dest, $addVdir = true) - { - if ($addVdir) { - $dest = $dest; - } - - $this->vdir->copy($source, $dest); - } - - public function copyLinkFile($source, $dest, $video = false) - { - if ($video && $this->book->parametres->mobileVideosPath != '') { - - } - - $origDir = $this->wdir; - $types = $this->getVideosFormats(); - if ($video) { - wsTools::encodeWebVideos($origDir . $source, null, true); - $e = explode('.', $source); - array_pop($e); - $base = implode('.', $e); - $source = array(); - foreach ($types as $type) { - $source[] = $base . '.' . $type; - } - } - - if (!is_array($source)) { - $source = array($source); - } - - foreach ($source as $so) { - $s = $origDir . $so; - if (file_exists($s)) { - $d = $dest . '/' . $so; - $this->simpleCopyLinkFile($s, $d, false); - } - } - } - - public function __destruct() - { - - } - - - public function unzipFile($file, $moveAssets = false, $baseDir = null) - { - $fdir = is_null($baseDir) ? 'data/links/' . str_replace('.', '_', $file) : $baseDir; - - $tmp = CubeIT_Files::tmpdir(); - $dir = $tmp . '/' . $fdir; - if (file_exists($dir) && is_file($dir)) { - unlink($dir); - } - if (!file_exists($dir)) { - mkdir($dir, 0777, true); - } - $unzip = new cubeCommandLine('unzip'); - $unzip->setArg(null, $this->wdir . '/' . $file); - $unzip->setArg('d', $dir); - $unzip->execute(); - - if ($moveAssets) { - `mv $dir/Assets/* $dir`; - rmdir($dir . '/Assets'); - } - - return array('dir' => $dir, 'fdir' => $fdir); - } - - public function getConfigZIP($d) - { - $res = array('width' => 0, 'height' => 0); - if (file_exists($d . '/index.html')) { - $doc = new DOMDocument(); - $doc->loadHTMLFile($d . '/index.html'); - $xpath = new DOMXPath($doc); - $c = $xpath->query("//canvas"); - foreach ($c as $canvas) { - /* @var $canvas DOMElement */ - $res['width'] = intval((string)$canvas->getAttribute('width')); - $res['height'] = intval((string)$canvas->getAttribute('height')); - } - - $r = array('html' => 'index.html', 'inject' => array(), 'injectcss' => array(), 'injectjs' => array()); - } else { - $r = array('html' => false, 'inject' => array(file_get_contents($d . '/init.js')), 'injectcss' => array('multimedia.css'), 'injectjs' => array('multimedia.js')); - } - $res = array_merge($res, $r); - return $res; - } + $favicon = ''; + $hasIos = false; + if ($this->theme->parametres->iosicon != '') { + $hasIos = true; + $this->vdir->copy($this->themeRoot . '/' . $this->theme->parametres->iosicon, 'data/apple-touch-icon.png'); + $favicon .= ''; + } + if ($this->theme->parametres->favicon != '') { + + $pngFile = $this->themeRoot . '/' . $this->theme->parametres->favicon; + $icoFile = $this->themeRoot . '/favicon.ico'; + if (!file_exists($icoFile) || filemtime($icoFile) < filemtime($pngFile) || filemtime(__FILE__) > filemtime($icoFile)) { + $tmp = CubeIT_Files::tempnam() . '.png'; + $convert = "convert $pngFile -resize 64x64^ -gravity center $tmp"; + `$convert`; + + $icotool = new cubeCommandLine('icotool'); + $icotool->setArg('c'); + $icotool->setArg('o', $icoFile); + $icotool->setArg(null, $tmp); + $icotool->execute(); + + unlink($tmp); + } + $this->vdir->copy($pngFile, 'data/favicon.png'); + $this->vdir->copy($icoFile, 'data/favicon.ico'); + $favicon .= ''; + $favicon .= ''; + $favicon .= ''; + if (!$hasIos) { + $favicon .= ''; + } + } + + $print = $this->writePrint(); + $message = sprintf($this->__('Your browser is not up to date and is not able to run this publication. %sLearn more%s'), '
', ''); + + $splash = ''; + if ($this->theme->parametres->logoLoader && file_exists($this->themeRoot . $this->theme->parametres->logoLoader)) { + $dim = CubeIT_Image::getimagesize($this->themeRoot . $this->theme->parametres->logoLoader); + if ($dim !== false) { + $this->vdir->copy($this->themeRoot . '/' . $this->theme->parametres->logoLoader, 'data/images/' . $this->theme->parametres->logoLoader); + $splash .= ''; + } + } + + $svgfiles = array($this->assets . '/images/interface.svg', WS_ICONS . '/' . $this->theme->parametres->iconSet . '/interface.svg'); + $svg = ''; + foreach ($svgfiles as $svgfile) { + if (file_exists($svgfile)) { + $svg .= file_get_contents($svgfile); + } else { + die($svgfile . ' does not exist'); + } + } + + if ($this->phonegap) { + $csp = "securityPolicyWhitelist)) . "; img-src * data:\">"; + } + $vars = array('titre', 'credits', 'statsfooter', 'ga', 'style', 'script', 'pagesContents', 'description', 'print', 'hiddenContents', 'splash', 'cache', 'bgcolor', 'message', 'favicon', 'svg', 'beginbody', 'csp', 'opengraph', 'twittercard'); + foreach ($vars as $v) { + if (isset($$v)) { + $html = str_replace('', $$v, $html); + } else { + $html = str_replace('', '', $html); + } + } + + $scripts = array(); + foreach ($this->debugJsFiles as $js) { + $scripts[] = ''; + } + foreach ($this->jsFiles as $js) { + $scripts[] = ''; + } + foreach ($this->pluginJs as $js) { + $scripts[] = ''; + } + + $scripts[] = ''; + $scripts[] = $iscript; + $script = implode("\n\t\t", $scripts); + + $scripts = array(); + foreach ($this->testJsFiles as $js) { + $scripts[] = ''; + } + $scripts[] = ''; + $script_test = implode("\n\t\t", $scripts); + + $thtml = $uhtml; + + $vars = array('titre', 'credits', 'statsfooter', 'ga', 'style', 'script', 'pagesContents', 'print', 'hiddenContents', 'splash', 'cache', 'bgcolor', 'message', 'favicon'); + foreach ($vars as $v) { + $uhtml = str_replace('', $$v, $uhtml); + } + + $script .= "\n\t\t" . ''; + $vars = array('titre', 'credits', 'statsfooter', 'ga', 'style', 'script', 'print', 'hiddenContents', 'splash', 'message'); + foreach ($vars as $v) { + $thtml = str_replace('', $$v, $thtml); + } + + $this->vdir->file_put_contents('index.html', $html); + $this->vdir->file_put_contents('indexu.html', $uhtml); + $this->vdir->file_put_contents('indext.html', $thtml); + + // Write widget html + if ($this->widget) { + $whtml = file_get_contents($this->assets . '/widget.html'); + $script = ''; + $script .= ''; + + $style = ''; + $vars = array('titre', 'style', 'script'); + foreach ($vars as $v) { + $whtml = str_replace('', $$v, $whtml); + } + $this->vdir->file_put_contents('widget.html', $whtml); + } + } + + function writeSEO() + { + foreach ($this->seoArticles as $seoArticle) { + $html = file_get_contents($this->assets . '/_seo.html'); + $a = $seoArticle; + unset($a['image']); + $a['imageurl'] = 'https://workshop.fluidbook.com/services/facebook_thumbnail?id=15793&j=' . time(); + if ($seoArticle['image']) { + $a['imageurl'] .= '&image=' . $seoArticle['image']; + } + $dim = CubeIT_Image::getimagesize($a['imageurl']); + $a['imagewidth'] = $dim[0]; + $a['imageheight'] = $dim[1]; + foreach ($a as $k => $v) { + $html = str_replace('$' . $k, $v, $html); + } + $this->vdir->file_put_contents('p/' . $seoArticle['url'], $html); + } + } + + protected function writeScorm() + { + $manifest = file_get_contents($this->assets . '/_imsmanifest.xml'); + if (!$this->book->parametres->scorm_title) { + $this->book->parametres->scorm_title = $this->book->parametres->title; + } + if (!$this->book->parametres->scorm_id) { + $this->book->parametres->scorm_id = 'fb_' . $this->book->parametres->id; + } + if (!$this->book->parametres->scorm_org) { + $this->book->parametres->scorm_org = 'Fluidbook'; + } + $vars = array('scorm_id', 'scorm_org', 'scorm_title'); + foreach ($vars as $v) { + $manifest = str_replace('$' . $v, $this->book->parametres->$v, $manifest); + } + $this->vdir->file_put_contents('imsmanifest.xml', $manifest); + + $variables = []; + $e = CubeIT_Text::explodeNewLines($this->book->parametres->scorm_variables); + foreach ($e as $item) { + $item = trim($item); + if ($item == '') { + continue; + } + $f = explode('=', $item, 2); + $variables[$f[0]] = $f[1]; + } + $this->config->scorm_variables = $this->book->parametres->scorm_variables = $variables; + } + + protected function writePrint() + { + + if (!$this->book->parametres->print && !$this->book->parametres->pdf) { + return; + } + + $this->vdir->copy(WS_BOOKS . '/final/' . $this->book->book_id . '/data/' . $this->book->parametres->pdfName, 'data/' . $this->book->parametres->pdfName); + return ''; + } + + protected function addFilesInfos($key, $file) + { + if (!file_exists($file)) { + return; + } + if (!isset($this->config->filesInfos)) { + $this->config->filesInfos = array(); + } + $infos = array('filesize' => filesize($file)); + $dim = CubeIT_Image::getimagesize($file); + if ($dim !== false) { + $infos['width'] = $dim[0]; + $infos['height'] = $dim[1]; + } + $this->config->filesInfos[$key] = $infos; + } + + protected function __($str) + { + if (!isset($this->config->l10n)) { + $this->writeLangs(); + } + + if (isset($this->config->l10n['default']->$str)) { + return $this->config->l10n['default']->$str; + } else { + return $str; + } + } + + protected function writeLangs() + { + global $core; + $daoLang = new wsDAOLang($core->con); + $lang = $daoLang->selectById($this->book->lang); + $langs = $daoLang->selectAll(); + + $traductions = (!count($this->book->traductions)) ? $lang->traductions : $this->book->traductions; + + $this->config->l10n = array(); + $this->config->l10n['default'] = $traductions; + $this->config->defaultLang = $this->book->lang; + + foreach ($langs as $lang) { + $this->config->l10n[$lang->lang_id] = $lang->traductions; + } + $iso = l10n::getISOcodes(); + if ($this->book->parametres->multilang != '') { + $flagsDir = 'images/flags'; + if (!file_exists($flagsDir)) { + mkdir($flagsDir); + } + $ml = str_replace("\r", "\n", $this->book->parametres->multilang); + $ml = str_replace("\n\n", "\n", $ml); + $e = explode("\n", $ml); + $m = array(); + foreach ($e as $l1) { + $l = explode(',', $l1); + $flag = $l[1]; + + $ll = explode('-', $l[0]); + + $this->vdir->copy(cubeMedia::getFlagFile($flag), $flagsDir . '/' . $flag . '.png'); + $l[3] = cubeText::ucfirst($iso[$l[0]]); + $l[4] = cubeCountry::getCountryName($flag, $ll[0]); + $m[] = implode(',', $l); + } + + $this->config->multilang = implode("\n", $m); + } + } + + protected function writeExtras() + { + if ($this->theme->parametres->afterSearch != '') { + $this->vdir->copy($this->themeRoot . '/' . $this->theme->parametres->afterSearch, 'data/images/' . $this->theme->parametres->afterSearch); + } + if ($this->book->parametres->externalArchives != '') { + $this->addFilesInfos('archives', $this->wdir . '/' . $this->book->parametres->externalArchives); + $this->vdir->copy($this->wdir . '/' . $this->book->parametres->externalArchives, 'data/images/' . $this->book->parametres->externalArchives); + } + + if ($this->book->parametres->navExtraImage != '') { + $this->vdir->copy($this->wdir . '/' . $this->book->parametres->navExtraImage, 'data/images/' . $this->book->parametres->navExtraImage); + } + + if ($this->book->parametres->navExtraImageMobile != '') { + $this->vdir->copy($this->wdir . '/' . $this->book->parametres->navExtraImageMobile, 'data/images/' . $this->book->parametres->navExtraImageMobile); + } + + for ($i = 1; $i <= 5; $i++) { + $ic = $this->book->parametres->{'navExtraIcon' . $i}; + if ($ic != '') { + $this->vdir->copy($this->wdir . '/' . $ic, 'data/images/' . $ic); + } + } + + } + + protected function writeLinks() + { + global $core; + + if ($this->book->parametres->customLinkClass == 'WescoSalesLink') { + $this->specialJsFiles[] = 'js/libs/interact.min.js'; + $this->specialJsFiles[] = 'js/libs/fluidbook/special/wescosales.js'; + $this->specialCSS[] = 'wescosales'; + } + + if ($this->book->parametres->customLinkClass == 'AtlanticDownloadLink') { + $this->specialJsFiles[] = 'js/libs/fluidbook/special/atlanticdownload.js'; + $this->specialCSS[] = 'atlanticdownload'; + } + + $this->config->links = array(); + $this->config->clinks = array(); + $this->config->bookmarkGroups = array(); + + $ignore = $this->book->parametres->ignoreLinksTypes; + if (!$ignore) { + $ignore = array(); + } else { + $ignore = split(',', $ignore); + } + + if ($this->book->parametres->externalChaptersHTML != '') { + $d = $this->unzipFile($this->book->parametres->externalChaptersHTML, false, 'data/chapters/'); + $meta = $this->getConfigZIP($d['dir']); + $this->config->externalChaptersSize = new stdClass(); + $this->config->externalChaptersSize->width = $meta['width']; + $this->config->externalChaptersSize->height = $meta['height']; + $this->vdir->copyDirectory($d['dir'], $d['fdir']); + } + + $daoDoc = new wsDAODocument($core->con); + $daoDoc->getLinksAndRulers($this->book_id, $links, $rulers); + + // Custom landing page content + if ($this->book->parametres->landingPage != '') { + $d = $this->unzipFile($this->book->parametres->landingPage, false, 'data/landing-page/'); + $this->vdir->copyDirectory($d['dir'], $d['fdir']); + } + + if ($this->book->parametres->tabsHTML5 != '') { + $links[] = [ + 'page' => 'background', + 'top' => 0, + 'left' => 0, + 'width' => 100, + 'height' => 100, + 'type' => 6, + 'to' => $this->book->parametres->tabsHTML5, + 'alternative' => $this->book->parametres->tabsHTML5, + 'image' => '', + 'inline' => 1, + 'interactive' => 1, + 'class' => 'tabslink', + ]; + } + + + foreach ($links as $linkData) { + if (isset($linkData['image']) && $linkData['image'] && $linkData['type'] != 28) { + $dupData = $linkData; + $dupData['image'] = ''; + $dupData['to'] = $linkData['image']; + $dupData['type'] = 15; + array_push($links, $dupData); + } + } + + $i = 0; + $pages = array(); + $cpages = array(); + $css = array(); + + usort($links, array($this, '_sortLinks')); + + foreach ($links as $linkData) { + if (in_array($linkData['type'], $ignore)) { + continue; + } + if ($linkData['type'] == 28) { + $this->addSEOArticle($linkData['page'], $linkData['to'], $linkData['extra'], $linkData['image']); + continue; + } + $link = wsHTML5Link::getInstance($this->base62($i), $linkData, $this); + if (is_null($link)) { + continue; + } + + // Make old "aftersearch" link compatible with new "extra" menu option by extracting link URL + if ($link->page == 'aftersearch') { + $this->config->afterSearchLink = $link->to; + $this->config->afterSearchTooltip = $link->infobulle; + } + + + $c = $link->getHTMLContainer(); + $css[] = $link->getCSSContainer(); + if (!isset($pages[$link->page])) { + $pages[$link->page] = ''; + $cpages[$link->page] = ''; + } + if ($link instanceof contentLink) { + $cpages[$link->page] .= $c; + } else { + $pages[$link->page] .= $c; + } + + if ($link->keep()) { + $this->hiddenContents[] = $c; + } + $i++; + } + + $allpages = range(0, $this->book->parametres->pages + 1); + if ($this->book->parametres->themeEnableAfterSearch) { + $allpages[] = 'aftersearch'; + } + $allpages[] = 'background'; + $allpages[] = 'archives'; + + foreach ($allpages as $i) { + + $c = ''; + $cc = ''; + if (isset($pages[$i])) { + $c = $pages[$i]; + } + if (isset($cpages[$i])) { + $cc = $cpages[$i]; + } + $this->config->links[$i] = $c; + $this->config->clinks[$i] = $cc; + } + return $css; + } + + public function addSEOArticle($page, $title, $intro, $image) + { + $this->seoArticles[$title] = ['title' => $title, 'description' => $intro, 'image' => $image, 'content' => '', 'page' => $page, 'url' => CubeIT_Text::str2URL($title) . '.html']; + } + + public function _sortLinks($a, $b) + { + $priorities = array(26 => 1); + + $pa = isset($priorities[$a['type']]) ? $priorities[$a['type']] : 0; + $pb = isset($priorities[$b['type']]) ? $priorities[$b['type']] : 0; + return $pb - $pa; + } + + public function addBookmarkGroup($link) + { + if ($link['left'] > $this->book->parametres->width) { + //$link['page']++; + } + if ($link['page'] <= 0 || $link['page'] > $this->book->parametres->pages) { + return; + } + + $this->config->bookmarkGroups[] = array('page' => ($link['page']), 'nb' => $link['to'], 'name' => $link['extra']); + } + + public function addAudiodescription($link) + { + $this->config->audiodescription[$link['page']] = $link['to']; + $this->copyLinkFile($link['to'], 'data/audiodescription/'); + } + + protected function writeJs() + { + $config = $this->writeConfig(); + $this->vdir->file_put_contents('data/datas.js', $config); + $finals = array('fluidbook' => $this->jsFiles); + if ($this->book->parametres->scorm_enable) { + $finals['scorm'] = array(); + $finals['scorm'][] = 'js/libs/scorm/apiwrapper.js'; + $finals['scorm'][] = 'js/libs/scorm/scorm.js'; + } + if (count($this->specialJsFiles)) { + $finals['special'] = $this->specialJsFiles; + } + if ($this->widget) { + $finals['widget'] = $this->widgetJsFiles; + } + + foreach ($finals as $jsfinal => $files) { + $mintime = 0; + $hash = hash('sha256', json_encode($files)); + $minimized = $this->assets . '/js/min/' . $jsfinal . '-' . $hash . '-min.js'; + if (!file_exists(dirname($minimized))) { + mkdir(dirname($minimized)); + } + if (file_exists($minimized)) { + $mintime = filemtime($minimized); + $reminimize = false; + } else { + $mintime = 0; + $reminimize = true; + } + + if (!$reminimize) { + foreach ($files as $file) { + if (filemtime($this->assets . '/' . $file) > $mintime) { + $reminimize = true; + break; + } + } + } + + if (!$reminimize) { + if (filemtime(__FILE__) > $mintime || (file_exists(__DIR__ . '/class.ws.html5.links.php') && filemtime(__DIR__ . '/class.ws.html5.links.php') > $mintime)) { + $reminimize = true; + } + } + + if ($reminimize) { + $js = ''; + foreach ($files as $file) { + $js .= file_get_contents($this->assets . '/' . $file); + $js .= ";\n\n"; + } + $tmp = cubeFiles::tempnam(); + file_put_contents($tmp, $js); + + unlink($minimized); + + $uglify = new CubeIT_CommandLine('/usr/local/bin/uglifyjs'); + $uglify->setArg('o', $minimized); + $uglify->setArg(null, $tmp); + $uglify->execute(); + $uglify->debug(); + + if (!file_exists($minimized)) { + die('An error occured while uglifying : ' . $uglify->output); + } + } + $dest = 'data/' . $jsfinal . '.js'; + $this->vdir->copy($minimized, $dest); + } + + + if ($this->phonegap) { + $this->vdir->copy(WS_COMPILE_ASSETS . '/_html5/js/libs/phonegap/' . $this->phonegapVersion . '/cordova-' . $this->phonegap . '.js', 'data/cordova.js'); + } + + } + + public function writeTexts() + { + $this->daoBook->makeTextsIndexes($this->book, $this->pages, $index, $textes, true); + $this->vdir->file_put_contents('data/search.index.js', 'var INDEX=' . $index . ';' . "\r"); + if ($this->book->parametres->highlightResults) { + $this->vdir->file_put_contents('data/search.highlight.js', 'var HIGHLIGHTS=' . json_encode($this->daoBook->makeHighlightIndex($this->book, $this->pages)) . ";\r"); + } + if ($this->book->parametres->searchWordSelectionAlgorithm == 'expression') { + $this->vdir->file_put_contents('data/search.texts.js', 'var TEXTS=' . $textes . ";\r"); + } + } + + public function supportSVG() + { + if (!$this->phonegap) { + return false; + } else if ($this->phonegap == 'ios') { + return true; + } else { + return false; + } + } + + protected function writeConfig() + { + $this->config->numerotation = explode(',', $this->book->numerotation); + $this->config->id = $this->book->book_id; + $this->config->cid = $this->book->cid; + $this->config->cacheDate = TIME; + $this->config->width = $this->cssWidth; + $this->config->height = $this->cssHeight; + $this->config->optimalWidth = $this->optimalWidth; + $this->config->optimalHeight = $this->optimalHeight; + $this->config->chapters = $this->book->chapters; + $this->config->videoFormats = $this->getVideosFormats(false); + $this->config->htmlmultimedia = $this->htmlmultimedia; + $this->config->phonegap = $this->phonegap; + $this->config->retinaResolution = min($this->book->parametres->maxResolution, $this->maxRes); + $this->config->pageLabels = $this->pageLabels; + $this->config->pageZoomFactor = $this->z; + $this->config->multiply = $this->multiply; + $this->config->cssScale = $this->cssScale; + $this->config->pdfZoomFactor = $this->pdf2htmlRatio; + if ($this->home) { + $this->config->home = 'http://home'; + } + $this->config->multiApp = $this->multiApp; + foreach ($this->additionalConfig as $k => $v) { + $this->config->$k = $v; + } + if ($this->phonegap && ($this->book->parametres->offlineLink == '' || $this->book->parametres->offlineLink == 'http://')) { + $this->config->share = false; + } + + // We need to be able to reference both navOrder and navOrderH so convert both to arrays + // We also make sure there are no empty items in the arrays (see: http://php.net/manual/en/function.array-filter.php#111091) + $this->config->navOrder = array_filter(array_map('trim', explode(',', $this->config->navOrder)), 'strlen'); + $this->config->navOrderH = array_filter(array_map('trim', explode(',', $this->config->navOrderH)), 'strlen'); + + $this->config->standalone = $this->standalone; + if ($this->config->phonegap) { + $this->config->manifest = $this->writeManifest(); + } + + if ($this->config->basket) { + $this->addJs('js/libs/fluidbook/fluidbook.cart.js'); + switch ($this->config->basketManager) { + case 'Remarkable': + $this->addJs('js/libs/fluidbook/cart/fluidbook.cart.remarkable.js'); + break; + default: + break; + } + + + if (file_exists($this->config->basketReferences) || CubeIT_Util_Url::isDistant($this->config->basketReferences)) { + $referencesFile = $this->config->basketReferences; + } else { + $referencesFile = $this->wdir . '/commerce/' . $this->config->basketReferences; + } + + if (file_exists($referencesFile) || CubeIT_Util_Url::isDistant($referencesFile)) { + $ext = CubeIT_Files::getExtension($referencesFile); + if ($ext == 'xlsx') { + $this->config->basketReferences = wsUtil::excelToArray($referencesFile); + if ($this->book->parametres->customLinkClass == 'AtlanticDownloadLink') { + $this->config->basketReferences = wsUtil::atlanticReferences($this->config->basketReferences, 'local/', array($this, 'log'), array($this->vdir, "copy")); + } + } + $this->log("Done cart references"); + } + } + $this->config->seoArticles = $this->seoArticles; + + return 'var DATAS=' . json_encode($this->config) . ';' . "\n"; + } + + protected function writeManifest() + { + $res = array(); + } + + protected function writeIcons() + { + $res = array(); + // Get the colors used to colorize graphics + if ($this->theme->parametres->colorizeIcons) { + $couleurI = $this->theme->parametres->couleurI; + } else { + $couleurI = 'FFFFFF'; + } + + $couleurM = $this->theme->parametres->subTextColor; + + $bookmarksDisabledColors = array('star' => $this->theme->parametres->bookmarkStarDisabledColor, 'bookmark' => $this->theme->parametres->bookmarkBackgroundColor); + $bookmarksEnabledColors = array('star' => $this->theme->parametres->bookmarkStarEnabledColor, 'bookmark' => $this->theme->parametres->bookmarkBackgroundColor); + $subTextColor = $this->theme->parametres->subTextColor; + + $arrowsColor = $this->theme->parametres->arrowsColor; + // Set the icon list with the color + $icons = array('interface-down' => $arrowsColor, 'interface-close' => $arrowsColor, + 'interface-audio-description-on' => $arrowsColor, 'interface-audio-description-off' => $arrowsColor, + 'help-fingers' => $couleurI, 'help-mouse' => $couleurI, + 'bookmark-left-off' => $bookmarksDisabledColors, 'bookmark-left-on' => $bookmarksEnabledColors, + 'bookmark-right-off' => $bookmarksDisabledColors, 'bookmark-right-on' => $bookmarksEnabledColors + ); + + $this->config->iconsDimensions = array(); + $makepng = !$this->supportSVG(); + $tmpdir = CubeIT_Files::tmpdir(); + foreach ($icons as $icon => $color) { + wsTools::colorizeAndRasterizeIcon($this->theme->parametres->iconSet, $icon, $color, $tmpdir, 4, $w, $h); + $this->config->iconsDimensions[$icon] = array($w, $h); + } + $this->vdir->copyDirectory($tmpdir, 'data/images'); + $this->vdir->addTemp($tmpdir); + return $res; + } + + protected function writeImages() + { + global $core; + + switch ($this->book->parametres->mobileVersion) { + case 'html5-desktop': + $this->backgroundsPrefix = array('t', 'p'); + $this->svg = true; + break; + case 'html5-images': + $this->backgroundsPrefix = array('t'); + $this->svg = false; + break; + default: + $this->backgroundsPrefix = array('p'); + $this->svg = true; + break; + } + + $thumbs = array(); + foreach ($this->pages as $page => $infos) { + $docdir = wsDocument::getDir($infos['document_id']); + if ($this->svg) { + $full = $docdir . 'html/fp' . $infos['document_page'] . '.svg'; + $fullopt = $docdir . 'html/fo' . $infos['document_page'] . '%s.svg'; + $orig = $docdir . 'html/tp' . $infos['document_page'] . '.svg'; + $opt = $docdir . 'html/to' . $infos['document_page'] . '.svg'; + + if (!file_exists($full) || filemtime($full) < 1503671520) { + if (!isset($doc) || $doc->document_id != $infos['document_id']) { + $dao = new wsDAODocument($core->con); + $doc = $dao->selectById($infos['document_id']); + } + $doc->makeSVGFile($infos['document_page']); + } + wsDocument::extractTexts($full, $orig); + wsTools::optimizeSVG($orig, $opt); + wsTools::optimizeSVG($full, $fullopt, [150, 300]); + + if (in_array($page, $this->config->vectorPages)) { + $this->vdir->copy(str_replace('%s', '-150', $fullopt), 'data/contents/p' . $page . '.svg'); + } else { + $this->vdir->copy($opt, 'data/contents/p' . $page . '.svg'); + } + } + + + foreach ($this->getResolutions() as $r) { + foreach ($this->backgroundsPrefix as $backgroundsPrefix) { + $srcPrefix = $backgroundsPrefix; + if ($backgroundsPrefix == 'p') { + $srcPrefix = 'h'; + } + $ok = $this->vdir->copy($docdir . 'html/' . $srcPrefix . $r . '-' . $infos['document_page'] . '.jpg', 'data/background/' . $r . '/' . $backgroundsPrefix . $page . '.jpg'); + if (!$ok && $r = 300) { + $this->maxRes = 150; + } + } + } + + $thumb = false; + if ($this->book->parametres->pdfThumbnails) { + $thumb = wsPDFConvert::getThumbFromPDF(WS_BOOKS . '/working/' . $this->book->book_id . '/' . $this->book->parametres->pdfThumbnails, $page); + } + if (!$thumb) { + $thumb = $docdir . 'p' . $infos['document_page'] . '.jpg'; + } + + $thumbs[$page] = $thumb; + $this->vdir->copy($thumb, 'data/thumbnails/p' . $page . '.jpg'); + + if ($page == 1) { + $this->_makeCover($docdir . 'html/t36-' . $infos['document_page'] . '.jpg'); + } + + $this->log('Copied image ' . $page); + } + + + $this->makeThumbSprites($thumbs); + $this->log('Made thumbnails'); + } + + public function makeThumbSprites(array $thumbs) + { + $cols = 10; + $rows = 10; + $perSprite = $cols * $rows; + $k = 0; + $res = ''; + $pages = count($thumbs); + + $hash = ''; + for ($i = 1; $i <= $pages; $i += $perSprite) { + $num = min(1 + $pages - $i, $perSprite); + $srows = ceil($num / $cols); + $files = array(); + $mtime = 0; + for ($j = 0; $j < $perSprite; $j++) { + $p = $i + $j; + if ($p > $pages) { + break; + } + $files[] = $thumbs[$p]; + $hash .= $thumbs[$p] . '--' . filemtime($thumbs[$p]); + } + + $cache = WS_CACHE . '/thumbsprites/' . hash('sha256', $hash) . '.jpg'; + $dest = 'data/thumbnails/s' . $k . '.jpg'; + if (!file_exists($cache)) { + $ratio = $this->width / $this->height; + $thumbh = round(100 / $ratio); + $cmd = 'montage ' . implode(' ', $files) . ' -geometry 100x' . $thumbh . '!+0+0 -background transparent -tile ' . $cols . 'x' . $srows . ' ' . $cache; + $res .= `$cmd`; + } + $this->vdir->copy($cache, $dest); + $k++; + } + return $res; + } + + protected function _makeCover($orig) + { + $size = CubeIT_Image::getimagesize($orig); + $w = $size[0]; + $h = $size[1]; + + $tmp = cubeFiles::tempnam() . '.png'; + + $c = new cubeCommandLine('convert'); + $c->setArg(null, ROOT . '/images/ws/shade-cover-app.png'); + $c->setManualArg('-resize ' . round($w / 3) . 'x' . $h); + $c->setArg(null, $tmp); + $c->execute(); + + $res = cubeFiles::tempnam() . '.jpg'; + + $convert = new cubeCommandLine('composite'); + $cmd = '-compose Multiply '; + $cmd .= $tmp . ' ' . $orig . ' '; + $cmd .= $res; + $convert->setManualArg($cmd); + $convert->execute(); + + $this->vdir->copy($res, 'cover.jpg', true); + + unlink($tmp); + } + + protected function _lessBoolean($val) + { + return $val ? 'true' : 'false'; + } + + protected function writeCSS($file, $links) + { + $res = array(); + + $lessContents = ''; + + $lessVariables = array(); + $lessVariables['slider-display'] = $this->_lessBoolean($this->theme->parametres->pagesBar); + $lessVariables['slider-thumb-background'] = wsHTML5::colorToCSS($this->theme->parametres->pageBarThumbBack); + + // General theme + $cssWidth = $this->cssWidth; + $cssHeight = $this->cssHeight; + $cssScale = $this->cssScale; + $w2 = ($cssWidth * 2) . 'px'; + + + $h = $cssHeight . 'px'; + + $wm = ($this->width * $this->multiply) . 'px'; + $hm = ($this->height * $this->multiply) . 'px'; + $w = $cssWidth . 'px'; + $offsetLeft = round(($this->optimalWidth - $cssWidth) / 2, 3); + $offsetLeft2 = $offsetLeft * 2; + $offsetTop = round(($this->optimalHeight - $cssHeight) / 2, 3); + $navTop = ($cssHeight - 40 - 100) / 2; + $leftOfRightPage = (floor($cssWidth) - 1) . 'px'; + + $lessVariables['z'] = $this->z; + $lessVariables['book-page-width'] = $w; + $lessVariables['book-page-height'] = $h; + $lessVariables['book-page-ratio'] = floatval($w) / floatval($h); + + $lessVariables['shadow-opacity'] = wsHTML5::colorToArray($this->theme->parametres->bookShadeColor)['opacity'] * 1.2; + $lessVariables['edges-display'] = $this->_lessBoolean($this->theme->parametres->usePageEdges); + + $res[] = '.portrait #pages,.portrait .doublePage.page,.page,.doublePage._3d{width:' . $w . ';max-width:' . $w . ';height:' . $h . ';max-height:' . $h . '}'; + $res[] = '.doublePage,#pages,#links,#searchHighlights{width:' . $w2 . ';max-width:' . $w2 . ';height:' . $h . ';max-height:' . $h . '}'; + $res[] = '.landscape .doublePage._2d.axis_x.next{' . wsHTML5::writeCSSUA('transform', 'translate3d(' . $w2 . ',0,0)') . '}'; + $res[] = '.landscape .doublePage._2d.axis_x.prev{' . wsHTML5::writeCSSUA('transform', 'translate3d(-' . $w2 . ',0,0)') . '}'; + $res[] = '.portrait .doublePage._2d.axis_x.next{' . wsHTML5::writeCSSUA('transform', 'translate3d(' . $w . ',0,0)') . '}'; + $res[] = '.portrait .doublePage._2d.axis_x.prev{' . wsHTML5::writeCSSUA('transform', 'translate3d(-' . $w . ',0,0)') . '}'; + $res[] = '.doublePage._2d.axis_y.next{' . wsHTML5::writeCSSUA('transform', 'translate3d(0,' . $h . ',0)') . '}'; + $res[] = '.doublePage._2d.axis_y.prev{' . wsHTML5::writeCSSUA('transform', 'translate3d(0,-' . $h . ',0)') . '}'; + + $res[] = '.doublePage._3d{left:' . $w . ';}'; + $res[] = '#links.right{left:-' . $w . ';}'; + $res[] = '.landscape .page.right{left:' . $w . '}'; + + $lessVariables['page-number-color'] = wsHTML5::colorToCSS($this->theme->parametres->colorPageNumber); + $lessVariables['display-page-number'] = $this->_lessBoolean($this->theme->parametres->displayPageNumber); + $lessVariables['page-transition-duration'] = $this->book->parametres->mobileTransitionDuration . 's'; + + + $res[] = '.background{width:100%;height:100%}'; + + if ($this->cssSVGScale != 1) { + $texts = '.texts{' . wsHTML5::writeCSSUA('transform-origin', 'top left') . ';'; + $texts .= wsHTML5::writeCSSUA('transform', 'scale(' . round((1 / $this->multiply) * $cssScale * $this->cssSVGScale, 3) . ')') . ';'; + $texts .= 'width:' . ($wm / $this->cssSVGScale) . 'px; max-width:' . ($wm / $this->cssSVGScale) . 'px;'; + $texts .= 'height:' . ($hm / $this->cssSVGScale) . 'px; max-height:' . ($hm / $this->cssSVGScale) . 'px;'; + $texts .= '}'; + } else { + $texts = '.texts{width:' . floor(floatval($w) + 4) . 'px;height:' . floor(floatval($h) + 4) . 'px;}'; + } + $res[] = $texts; + + // Theme + $shade = '.page .shade{'; + $shade .= 'opacity:' . min(($this->theme->parametres->shadeAlpha * 2) / 100, 1) . ';'; + $shade .= '}'; + $res[] = $shade; + + // SVG + $res[] = 'svg .fill-c-menu-back{fill:' . wsHTML5::colorToCSS($this->theme->parametres->couleurB) . ';}'; + $res[] = 'svg .fill-c-menu-text{fill:' . wsHTML5::colorToCSS($this->theme->parametres->subTextColor) . ';}'; + + // Background + $res[] = $this->_cssBackground(); + + // Archives + // Header + $header = 'header{'; + $header .= 'height:' . $this->theme->parametres->menuHeight . 'px;'; + if ($this->theme->parametres->menuImage != '') { + $this->vdir->copy($this->themeRoot . '/' . $this->theme->parametres->menuImage, 'data/images/' . $this->theme->parametres->menuImage); + $header .= 'background-image:url(../images/' . $this->theme->parametres->menuImage . ');'; + $header .= 'background-repeat:no-repeat;'; + $header .= 'background-size:100% ' . $this->theme->parametres->menuHeight . 'px;'; + } else { + $header .= 'background-color:' . wsHTML5::colorToCSS($this->theme->parametres->menuColor) . ';'; + } + $header .= '}'; + $res[] = $header; + + //Icons + $res = array_merge($res, $this->writeIcons()); + + // Logo + $logo = '#logo{'; + if ($this->theme->parametres->logo) { + $this->vdir->copy($this->themeRoot . '/' . $this->theme->parametres->logo, 'data/images/' . $this->theme->parametres->logo); + $dim = CubeIT_Image::getimagesize($this->themeRoot . '/' . $this->theme->parametres->logo); + $logo .= 'background-image:url(../images/' . $this->theme->parametres->logo . ');width:' . $dim[0] . 'px;height:' . $dim[1] . 'px;'; + } + $logo .= '}'; + $res[] = $logo; + + // Credits + $res[] = 'footer,footer a{color:' . wsHTML5::colorToCSS($this->theme->parametres->creditsColor) . ';}'; + + // Arrows + $lessVariables['arrows-background'] = wsHTML5::colorToCSS($this->theme->parametres->couleurA); + $lessVariables['arrows-color'] = wsHTML5::colorToCSS($this->theme->parametres->arrowsColor); + + // Loader + $lessVariables['loader-background-color'] = wsHTML5::colorToCSS($this->theme->parametres->couleurA); + $lessVariables['loader-foreground-color'] = wsHTML5::colorToCSS($this->theme->parametres->arrowsColor); + + // Audio description buttons + $lessVariables['audiodescription-background'] = wsHTML5::colorToCSS($this->theme->parametres->couleurA); + $lessVariables['audiodescription-color'] = wsHTML5::colorToCSS($this->theme->parametres->couleurA); + + // Links Styles + $lessVariables['links-color'] = wsHTML5::colorToCSS($this->theme->parametres->linksColor); + $res = array_merge($res, $links); + + // Bookmarks + if (!isset($this->book->parametres->bookmarkCornerSize)) { + $this->book->parametres->bookmarkCornerSize = 10; + } + $lessVariables['bookmark-corner-size'] = round($this->width * $this->book->parametres->bookmarkCornerSize * 0.0075 * $this->z) . 'px'; + $lessVariables['bookmark-corner-offset'] = $this->book->parametres->bookmarkOffset . 'px'; + + // Menus + $menuColor = new CubeIT_Graphics_Color($this->theme->parametres->couleurB); + $menuColor->setAlpha(1); + $menuTextColor = wsHTML5::colorToCSS($this->theme->parametres->subTextColor); + $menuBreakpoint = empty($this->book->parametres->menuBreakpoint) ? '1023px' : $this->book->parametres->menuBreakpoint; + + $lessVariables['menu-breakpoint'] = $menuBreakpoint; + $lessVariables['menu-background'] = $menuColor->toCSS(); + if ($this->theme->parametres->subSecondaryColor) { + $lessVariables['menu-button-background'] = wsHTML5::colorToCSS($this->theme->parametres->subSecondaryColor); + } else { + $lessVariables['menu-background-green'] = 'max(45, min(255-45, green(@menu-background)))'; + $lessVariables['menu-background-red'] = 'max(45, min(255-45, red(@menu-background)))'; + $lessVariables['menu-background-blue'] = 'max(45, min(255-45, blue(@menu-background)))'; + $lessVariables['menu-button-background'] = 'overlay(rgb(@menu-background-red, @menu-background-green, @menu-background-blue), #c0c0c0)'; + } + + $lessVariables['menu-text'] = $menuTextColor; + $lessVariables['menu-field-background'] = wsHTML5::colorToCSS($this->theme->parametres->subFieldColor); + $lessVariables['menu-field-text'] = wsHTML5::colorToCSS($this->theme->parametres->subTextFieldColor); + $lessVariables['menu-select-background'] = wsHTML5::colorToCSS($this->theme->parametres->subSelectColor); + $lessVariables['menu-select-text'] = wsHTML5::colorToCSS($this->theme->parametres->subTextSelectColor); + $lessVariables['icon-color'] = wsHTML5::colorToCSS($this->theme->parametres->couleurI); + $lessVariables['menu-overlay'] = wsHTML5::colorToCSS($this->theme->parametres->popupVideoOverlay); + + // Chapters + + + foreach ($this->book->chapters as $chapter) { + if (substr($chapter->page, 0, 1) != '#') { + continue; + } + if ($chapter->color == '') { + continue; + } + $color = trim($chapter->color, '#'); + $lessContents .= '.mview.c_' . $color . '{.menu-color(#' . $color . ');}'; + } + + // Archives + if ($this->book->parametres->externalArchivesBack) { + $this->vdir->copy($this->wdir . '/' . $this->book->parametres->externalArchivesBack, 'data/images/' . $this->book->parametres->externalArchivesBack); + $res[] = '.mview.archives{background-image:url("../images/' . $this->book->parametres->externalArchivesBack . '");}'; + } + + # Index + $ratio = $this->width / $this->height; + $thumbh = round(100 / $ratio); + $this->config->thumbHeight = $thumbh; + $lessVariables['thumb-height'] = $thumbh . 'px'; + + #tooltip + $lessVariables['tooltip-background'] = wsHTML5::colorToCSS($this->theme->parametres->tooltipBackColor); + $lessVariables['tooltip-color'] = wsHTML5::colorToCSS($this->theme->parametres->tooltipTextColor); + + # ZoomPopup close button background + $res[] = '.zoomPopupClose {background-color:' . wsHTML5::colorToCSS($this->theme->parametres->couleurB) . ';}'; + + + $this->_writeLess($lessVariables, $lessContents); + + $res = array_chunk($res, 3500); + foreach ($res as $k => $css) { + $this->stylesheets[] = 'data/style/style_' . $k . '.css'; + $this->vdir->file_put_contents(sprintf($file, $k), implode("\n", $css)); + $this->log('Write CSS ' . sprintf($file, $k)); + } + return count($res); + } + + protected function _writeLess($variables, $lessContents = '') + { + if ($this->widget) { + $this->lessFiles[] = 'widget'; + } + foreach ($this->specialCSS as $s) { + $this->lessFiles[] = 'special/' . $s; + } + + $tmp = CubeIT_Files::tmpdir(); + + $from = $this->assets . '/style/*'; + `cp -r $from $tmp`; + + $bookVariables = array(); + foreach ($variables as $k => $v) { + $bookVariables[] = '@' . trim($k) . ':' . $v . ';'; + } + file_put_contents($tmp . '/book-variables.less', implode("\n", $bookVariables)); + file_put_contents($tmp . '/additional.less', $lessContents); + + foreach ($this->lessFiles as $f) { + $source_less = $this->assets . '/style/' . $f . '.less'; + $destination_less = $tmp . '/' . $f . '.less'; + $destination_css = $tmp . '/' . $f . '.css'; + + if (!file_exists($source_less)) { + continue; + } + + // LESS file might be in a subfolder, so create if it doesn't exist + if (!is_dir(dirname($destination_less))) { + mkdir(dirname($destination_less), 0777, true); + } + + // Less files must be copied to temporary directory so they'll + // have access to the variables generated in book-variables.less + copy($source_less, $destination_less); + $less = new CubeIT_CommandLine('/usr/local/bin/lessc'); + $less->setArg(null, $destination_less); + $less->setArg(null, $destination_css); + $less->execute(); + $less->debug(); + if (!file_exists($destination_css)) { + die($less->output); + } + $this->vdir->copy($destination_css, 'style/' . $f . '.css'); + if ($f != 'widget') { + $this->stylesheets[] = 'style/' . $f . '.css'; + } + } + } + + protected function _cssBackground() + { + $body = '#background,#splash{'; + $body .= 'background-color:#' . $this->theme->parametres->backgroundColor . ' !important;'; + switch ($this->theme->parametres->repeat) { + case wsTheme::REPEAT: + $body .= 'background-repeat:repeat;'; + break; + case wsTheme::NONE: + $body .= 'background-repeat:no-repeat;'; + break; + case wsTheme::RATIO: + $body .= 'background-repeat:no-repeat;'; + $body .= 'background-size:cover;'; + break; + case wsTheme::STRETCH: + $body .= 'background-repeat:no-repeat;'; + $body .= 'background-size:100% 100%;'; + break; + } + if ($this->theme->parametres->backgroundImage != '') { + $bi = $this->themeRoot . '/' . $this->theme->parametres->backgroundImage; + if (file_exists($bi)) { + $dbi = CubeIT_Image::getimagesize($bi); + $this->config->backgroundImageDimensions = array('width' => $dbi[0], 'height' => $dbi[1]); + } + + $this->vdir->copy($this->themeRoot . '/' . $this->theme->parametres->backgroundImage, 'data/images/' . $this->theme->parametres->backgroundImage); + $body .= 'background-image:url(../images/' . $this->theme->parametres->backgroundImage . ');'; + $body .= 'background-position:'; + + switch ($this->theme->parametres->backgroundVAlign) { + case wsTheme::TOP: + $body .= 'top'; + break; + case wsTheme::MIDDLE: + $body .= 'center'; + break; + case wsTheme::BOTTOM: + $body .= 'bottom'; + break; + } + $body .= ' '; + switch ($this->theme->parametres->backgroundHAlign) { + case wsTheme::LEFT: + $body .= 'left'; + break; + case wsTheme::CENTER: + $body .= 'center'; + break; + case wsTheme::RIGHT: + $body .= 'right'; + break; + } + $body .= ';'; + } + + $body .= '}'; + + return $body; + } + + public static function writeCSSUA($property, $value) + { + $res = array(); + foreach (self::$uaPrefixes as $prefix) { + $res[] = $prefix . $property . ':' . $value; + } + return implode(';', $res); + } + + protected function base62($val) + { + $chars = '0123456789abcdefghijklmnopqrstuvwxyz'; + $base = strlen($chars); + $str = ''; + do { + $i = $val % $base; + $str = $chars[$i] . $str; + $val = ($val - $i) / $base; + } while ($val > 0); + return $str; + } + + public function copyLinkDir($source, $dest) + { + $this->vdir->copyDirectory($source, $dest); + } + + public function simpleCopyLinkFile($source, $dest, $addVdir = true) + { + if ($addVdir) { + $dest = $dest; + } + + $this->vdir->copy($source, $dest); + } + + public function copyLinkFile($source, $dest, $video = false) + { + if ($video && $this->book->parametres->mobileVideosPath != '') { + + } + + $origDir = $this->wdir; + $types = $this->getVideosFormats(); + if ($video) { + wsTools::encodeWebVideos($origDir . $source, null, true); + $e = explode('.', $source); + array_pop($e); + $base = implode('.', $e); + $source = array(); + foreach ($types as $type) { + $source[] = $base . '.' . $type; + } + } + + if (!is_array($source)) { + $source = array($source); + } + + foreach ($source as $so) { + $s = $origDir . $so; + if (file_exists($s)) { + $d = $dest . '/' . $so; + $this->simpleCopyLinkFile($s, $d, false); + } + } + } + + public function __destruct() + { + + } + + + public function unzipFile($file, $moveAssets = false, $baseDir = null) + { + $fdir = is_null($baseDir) ? 'data/links/' . str_replace('.', '_', $file) : $baseDir; + + $tmp = CubeIT_Files::tmpdir(); + $dir = $tmp . '/' . $fdir; + if (file_exists($dir) && is_file($dir)) { + unlink($dir); + } + if (!file_exists($dir)) { + mkdir($dir, 0777, true); + } + $unzip = new cubeCommandLine('unzip'); + $unzip->setArg(null, $this->wdir . '/' . $file); + $unzip->setArg('d', $dir); + $unzip->execute(); + + if ($moveAssets) { + `mv $dir/Assets/* $dir`; + rmdir($dir . '/Assets'); + } + + return array('dir' => $dir, 'fdir' => $fdir); + } + + public function getConfigZIP($d) + { + $res = array('width' => 0, 'height' => 0); + if (file_exists($d . '/index.html')) { + $doc = new DOMDocument(); + $doc->loadHTMLFile($d . '/index.html'); + $xpath = new DOMXPath($doc); + $c = $xpath->query("//canvas"); + foreach ($c as $canvas) { + /* @var $canvas DOMElement */ + $res['width'] = intval((string)$canvas->getAttribute('width')); + $res['height'] = intval((string)$canvas->getAttribute('height')); + } + + $r = array('html' => 'index.html', 'inject' => array(), 'injectcss' => array(), 'injectjs' => array()); + } else { + $r = array('html' => false, 'inject' => array(file_get_contents($d . '/init.js')), 'injectcss' => array('multimedia.css'), 'injectjs' => array('multimedia.js')); + } + $res = array_merge($res, $r); + return $res; + } }