From: vincent@cubedesigners.com Date: Wed, 29 May 2019 09:17:24 +0000 (+0000) Subject: #2806 X-Git-Url: http://git.cubedesigners.com/?a=commitdiff_plain;h=b0350cd972a5ebd6d0bb8d5723711a719ad58738;p=cubeextranet.git #2806 --- 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 94dda2e57..7d034d8bb 100644 --- a/inc/ws/Util/html5/master/class.ws.html5.compiler.php +++ b/inc/ws/Util/html5/master/class.ws.html5.compiler.php @@ -297,8 +297,6 @@ class wsHTML5Compiler if ($this->book->parametres->mobileNavigationType === 'mobilefirst') { $this->initMobileFirst(); - } else { - } $this->initConfig(); @@ -1192,7 +1190,7 @@ class wsHTML5Compiler $this->vdir->copyDirectory($d['dir'], $d['fdir']); } - if ($this->book->parametres->tabsHTML5 != '') { + if ($this->book->parametres->tabsHTML5 != '' && file_exists($this->wdir . '/' . $this->book->parametres->tabsHTML5)) { $links[] = [ 'page' => 'background', 'top' => 0, @@ -1478,7 +1476,7 @@ class wsHTML5Compiler } if (!file_exists($minimized) || filesize($minimized) == 0) { - die('An error occured while uglifying : ' . $uglify->output); + die('An error occured while uglifying ' . $hasNonMin . '? ' . $minimized . ': ' . $uglify->commande . ' :: ' . $uglify->output); } } $dest = 'data/' . $jsfinal . '.js'; @@ -1854,8 +1852,8 @@ class wsHTML5Compiler $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); + $lessVariables['loader-background-color'] = wsHTML5::colorToCSS($this->theme->parametres->couleurL); + $lessVariables['loader-foreground-color'] = wsHTML5::colorToCSS($this->theme->parametres->loadingSecColor); // Audio description buttons $lessVariables['audiodescription-background'] = wsHTML5::colorToCSS($this->theme->parametres->couleurA); diff --git a/inc/ws/Util/html5/master/class.ws.html5.links.php b/inc/ws/Util/html5/master/class.ws.html5.links.php index 1265fb494..86fb08f77 100644 --- a/inc/ws/Util/html5/master/class.ws.html5.links.php +++ b/inc/ws/Util/html5/master/class.ws.html5.links.php @@ -345,9 +345,14 @@ class wsHTML5Link return 'z-index:' . $zindex . ';'; } + public function moveOnEvenPage() + { + return false; + } + public function getCSSContainer() { - if (!($this instanceof contentLink) && intval($this->page) % 2 == 1 && $this->compiler->book->parametres->mobileNavigationType != 'mobilefirst') { + if ($this->moveOnEvenPage()) { $this->page--; $this->left += $this->compiler->width; } @@ -1320,7 +1325,7 @@ class htmlMultimediaLink extends wsHTML5Link public function getCSSContainer() { - if (!($this instanceof contentLink) && $this->page % 2 == 1 && $this->compiler->book->parametres->mobileNavigationType != 'mobilefirst') { + if ($this->moveOnEvenPage()) { $this->page--; $this->left += $this->compiler->width; } @@ -1576,7 +1581,7 @@ class inpesPopinLink extends htmlMultimediaLink public function getCSSContainer() { - if (!($this instanceof contentLink) && $this->page % 2 == 1 && $this->compiler->book->parametres->mobileNavigationType != 'mobilefirst') { + if ($this->moveOnEvenPage()) { $this->page--; $this->left += $this->compiler->width; } diff --git a/inc/ws/Util/html5/mobilefirst/class.ws.html5.compiler.php b/inc/ws/Util/html5/mobilefirst/class.ws.html5.compiler.php deleted file mode 100644 index aaf96612f..000000000 --- a/inc/ws/Util/html5/mobilefirst/class.ws.html5.compiler.php +++ /dev/null @@ -1,2270 +0,0 @@ - - ['js/libs/cube/util.js', - 'js/libs/cube/fb.js',], - 'modernizr' => - ['js/libs/modernizr/modernizr.min.js', - 'js/libs/modernizr/tests.js',], - 'modifier' => ['js/libs/threejs/modifier.min.js'], - 'threejs' => - ['js/libs/threejs/legacy/three.min.js', - 'js/libs/threejs/legacy/Projector.js', - 'js/libs/threejs/legacy/CanvasRenderer.js', - ], -// 'threejs-latest' => -// ['js/libs/threejs/latest/three.min.js', -// ], - 'jquery' => - ['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' - ], - 'screenfull' => ['js/libs/screenfull.min.js'], - 'storage' => ['js/libs/storage.js',], - 'keymaster' => ['js/libs/keymaster.js',], - 'perfectscrollbar' => ['js/libs/perfect-scrollbar/perfect-scrollbar.min.js', - 'js/libs/perfect-scrollbar/perfect-scrollbar.jquery.js'], - 'mmenu' => - ['js/libs/mmenu/jquery.mmenu.all.js'], - 'tweenmax' => - ['js/libs/gsap/TweenMax.min.js', - 'js/libs/gsap/jquery.gsap.min.js', - 'js/libs/gsap/plugins/ScrollToPlugin.min.js', - 'js/libs/threejs/Tweenmax.threejs.js',], - 'hammer' => ['js/libs/hammer.min.js',], - 'gal' => - ['js/libs/gal/gal.js', - 'js/libs/gal/gal.filesystem.js',], - 'raphael' => - ['js/libs/raphael/raphael.min.js', - 'js/libs/gsap/plugins/RaphaelPlugin.min.js'], - 'countup' => - ['js/libs/countup/countup.min.js'], - 'fluidbook' => - ['js/libs/fluidbook/fluidbook.utils.js', - 'js/libs/fluidbook/fluidbook.networkcontrol.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.pagetransitions.js', - 'js/libs/fluidbook/fluidbook.nav.js', - 'js/libs/fluidbook/fluidbook.interface.js', - 'js/libs/fluidbook/fluidbook.input.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.contentlock.js', - 'js/libs/fluidbook/fluidbook.scorm.js', - 'js/libs/fluidbook/fluidbook.3dflip.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.slideshow.js', - 'js/libs/fluidbook/fluidbook.print.js', - 'js/libs/fluidbook/fluidbook.secure.js', - 'js/libs/fluidbook/fluidbook.js', - 'js/main.js'], - 'mobilefirst' => [ - 'js/libs/fluidbook/fluidbook.mobilefirst.js', - 'js/libs/fluidbook/mobilefirst/fluidbook.mobilefirst.slider.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(); - public $cssX = array(); - public $cssY = array(); - public $cssWidths = array(); - public $pdf2htmlRatio; - public $scale; - public $multiply; - public $div = array(); - public $numerotation; - public $fontDocs = array(); - public $dir; - public $z = 3; - public $vdir; - public $wdir; - - /** - * - * @var wsBook - */ - public $book; - public $pages; - public $theme; - public $version; - public $book_id; - public $themeRoot; - - /** - * - * @var wsDAOBook - */ - public $daoBook; - public $needToRecompileContents = true; - public $needToRecompileSettings = true; - public $width; - public $height; - public $cssWidth; - public $cssHeight; - public $cssOneWidth; - public $cssOneHeight; - public $cssScale; - public $cssSVGScale; - public $optimalWidth = 567; - public $optimalHeight = 709; - public $additionalConfig = array(); - public $fontScale = 1; - public $cache = array(); - public $backgroundsPrefix = array(); - public $svg = true; - public $config = array(); - public $assets = ''; - public $phonegap = false; - public $phonegapVersion; - public $standalone = false; - public $hiddenContents = array(); - public $appcache; - public $home; - public $widget = true; - public $multiApp = false; - public $pageLabels = array(); - public $stylesheets = array(); - public $logfp = null; - public $logtime = null; - public $beginBody = array(); - public $seoArticles = []; - public $securityPolicyWhitelist = ['*.google-analytics.com', '*.youtube.com', '*.ytimg.com', '*.googletagmanager.com']; - public $writeLinksData = false; - public $content_lock = []; - public $cssfont = []; - protected $_indexVars = null; - - public $_signature; - /** - * @var wsHTML5SeolinksData - */ - public $seo = null; - - - function __construct($book_id, $version = 'stable', $phonegap = false, $phonegapVersion = 'latest', $dir = null, $standalone = false, $appcache = false, $home = false, $book = null) - { - 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); - if (null === $book) { - $this->book = $this->daoBook->selectById($book_id); - } else { - $this->book = $book; - } - - $this->widget = !$this->phonegap && $this->book->parametres->widget; - - $this->pages = $this->daoBook->getPagesOfBook($book_id); - $this->maxRes = min(300, $this->book->parametres->maxResolution); - - $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); - - if ($this->book->parametres->mobileNavigationType === 'mobilefirst') { - $this->initMobileFirst(); - } else { - - } - - $this->initConfig(); - $this->log('Defined dimensions'); - } - - public function initMobileFirst() - { - $this->theme->parametres->usePageEdges = false; - } - - 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); - } - - protected function populateConfig() - { - $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; - } - if ($this->config->maxPages > 0) { - $this->addContentLock($this->config->maxPages); - } - - // 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(); - } - - $this->writeGPUDatabase(); - - if ($this->config->form == 'bulle') { - $this->addJsLib('bulle', 'js/libs/fluidbook/forms/fluidbook.form.bulle.js'); - } else if ($this->config->form == 'bourbon') { - $this->addJsLib('parsley', 'js/libs/parsley.min.js'); - $this->addJsLib('bourbon', 'js/libs/fluidbook/forms/fluidbook.form.bourbon.js'); - } else if ($this->config->form == 'avery') { - $this->addJsLib('parsley', 'js/libs/parsley.min.js'); - $this->addJsLib('avery', 'js/libs/fluidbook/forms/fluidbook.form.avery.js'); - $this->addLess('form/avery'); - $this->writeCountries(); - } - - if ($this->config->basket) { - $this->addJsLib('cart', 'js/libs/fluidbook/fluidbook.cart.js'); - switch ($this->config->basketManager) { - case 'Remarkable': - $this->addJsLib('parsley', 'js/libs/parsley.min.js'); - $this->addJsLib('cookie', 'js/libs/jquery/jquery.cookie.js'); - $this->addJsLib('remarkable', '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; - } - - public function writeGPUDatabase() - { - global $core; - $r = $core->con->select('SELECT gpu,score FROM gpu'); - $gpu = []; - while ($r->fetch()) { - $gpu[$r->gpu] = $r->score; - } - $this->config->gupsc = $gpu; - $this->config->gupse = wsServices::gpuSeparators(); - } - - 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); - } - - if ($this->book->parametres->scorm_enable) { - $this->book->parametres->seoVersion = false; - } - - $this->log('Copied assets'); - $this->loadPlugins(); - $this->log('Plugins loaded'); - $this->writeImages(); - $this->log('Images written'); - $linksCSS = $this->writeLinks(); - $this->log('Links written'); - $this->writeLangs(); - $this->log('Langs written'); - $this->writeSEO(); - $this->log('SEO written'); - $this->writeWidget(); - $this->log('Widget written'); - $this->writeSounds(); - $this->log('Sound written'); - $this->writeAccessibility(); - $this->log('Sound accessibility'); - $this->writeTexts(); - $this->log('Texts written'); - $this->writeExtras(); - $this->log('Extras written'); - $this->populateConfig(); - $this->writeCSS($linksCSS); - $this->log('CSS written'); - $this->writeIndex(); - $this->log('Index written'); - if ($this->book->parametres->scorm_enable) { - $this->writeScorm(); - $this->log('SCORM written'); - } - $this->writeJs(); - $this->log('Js written'); - $this->vdir->sync($delete, $this); - $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 = []; - $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 string The path of the file relative to the /style folder, without any extension - */ - 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 writeAccessibility() - { - if ($this->book->parametres->audiodescriptionTexts == '' || $this->book->parametres->audiodescriptionVoice == '') { - return; - } - $file = $this->wdir . '/' . $this->book->parametres->audiodescriptionTexts; - new PHPExcel(); - $reader = new PHPExcel_Reader_Excel2007(); - $phpexcel = $reader->load($file); - - $sheet = $phpexcel->getActiveSheet(); - $maxRow = $sheet->getHighestRow(0); - - for ($i = 0; $i <= $maxRow; $i++) { - $page = trim($sheet->getCellByColumnAndRow(0, $i)->getValue()); - $text = trim($sheet->getCellByColumnAndRow(1, $i)->getValue()); - if ($page == '' || $text == '') { - continue; - } - - $replace = ['`' => "'", - '“' => '"', - '”' => '"', - '’' => "'", - '—' => " - ", - '‘' => "'", - ]; - - $text = str_replace(array_keys($replace), array_values($replace), $text); - - $hash = hash('sha256', $this->book->parametres->audiodescriptionVoice . '_^_' . $text); - $fname = $hash . '.mp3'; - $dir = WS_BOOKS . '/audiodescription/'; - if (!file_exists($dir)) { - mkdir($dir, 0777, true); - } - - $file = $dir . $fname; - if (!file_exists($file)) { - $e = explode(':', $this->book->parametres->audiodescriptionVoice); - - $engine = $e[0]; - $voice = $e[1]; - - if ($engine == 'festival') { - $tmp = CubeIT_Files::tempnam() . '.wav'; - $tmptext = CubeIT_Files::tempnam() . '.txt'; - - file_put_contents($tmptext, $text); - $cmd = "text2wave -o $tmp $tmptext -eval \"($voice)\""; - `$cmd`; - - `lame $tmp $file`; - unlink($tmp); - unlink($tmptext); - } else if ($engine == 'readspeaker') { - $e = explode('/', $voice); - $this->_readSpeaker($text, $e[1], $e[0], $file); - } - } - - $this->config->audiodescription[$page] = $fname; - $this->vdir->copy($file, 'data/audiodescription/' . $fname); - } - } - - protected function _readSpeaker($text, $language, $voice, $output) - { - $text_to_read = urlencode($text); - // Your API key here - $apikey = 'e9c321908f2dd016f6a0c34d2d786aff'; - - // File path and file name - $filepath = $output; - - // API URL of text-to-speech enabler - $api_url = 'https://tts.readspeaker.com/a/speak'; - - // Compose API call url - $url = $api_url . '?key=' . $apikey . '&streaming=0&lang=' . $language . '&voice=' . $voice . '&text=' . $text_to_read; - - // Initiating curl - $ch = curl_init($url); - - curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); - curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true); - - $data = curl_exec($ch); - - $status = curl_getinfo($ch, CURLINFO_HTTP_CODE); - - if ($status == 200 && !curl_errno($ch)) { - // Everything is fine, close curl and save file - curl_close($ch); - file_put_contents($filepath, $data); - } else { - // Cannot translate text to speech because of text-to-speech API error - error_log(__FILE__ . ': API error while text-to-speech. error code=' . $status); - curl_close($ch); - } - - } - - protected function _writeIndex($page) - { - if (!isset($this->seo->pages[$page])) { - return; - } - $seo = $this->seo->pages[$page]; - $html = $seo->getHTML(); - - if ($this->book->parametres->seoVersion) { - $seo->writePage($html, $this->vdir); - } - if ($page == 1) { - $seo->writePage($html, $this->vdir, 'index.html'); - } - - if ($page % 10 == 0) { - $this->log('Written page ' . $page); - } - } - - public function getIndexVars() - { - if (null === $this->_indexVars) { - global $core; - $titre = $this->book->parametres->title; - - - if (null === $this->_signature) { - $daoSignature = new wsDAOSignature($core->con); - $this->_signature = $daoSignature->selectById($this->book->parametres->signature); - } - - $credits = ''; - if ($this->_signature->partner != '') { - $credits = '' . $this->_signature->partner . ' '; - } - $credits .= '' . $this->_signature->main . ''; - - $hiddenContents = implode("\n", $this->hiddenContents); - - $bgcolor = $this->theme->parametres->loadingBackColor; - - // 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 = '' . "\n"; - foreach ($this->jsLibs as $jsLib => $files) { - $script .= "\t" . '' . "\n"; - } - if ($this->book->parametres->scorm_enable) { - $script .= "\t" . '' . "\n"; - } - if (count($this->specialJsFiles)) { - $script .= "\t" . '' . "\n"; - } - foreach ($this->pluginJs as $p) { - $script .= "\t" . '' . "\n"; - } - $script .= $iscript; - - $socialTitle = html::escapeHTML($this->book->parametres->facebook_title ? $this->book->parametres->facebook_title : $titre); - $socialDescription = html::escapeHTML($this->book->parametres->facebook_description ? $this->book->parametres->facebook_description : $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 = ' - - - - '; - - $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 .= '' . "\n\t"; - } - 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($icoFile, 'data/favicon.ico'); - $this->vdir->copy($pngFile, 'data/favicon.png'); - - $datapng = 'data:image/png;base64,' . base64_encode(file_get_contents($pngFile)); - - $favicon .= '' . "\n\t"; - 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 .= str_replace('$bookmark-color', wsHTML5::colorToCSS($this->theme->parametres->bookmarkBackgroundColor), file_get_contents($svgfile)); - } else { - die($svgfile . ' does not exist'); - } - } - - if ($this->phonegap) { - $csp = "securityPolicyWhitelist)) . "; img-src * data:\">"; - } - $vars = array('credits', 'style', 'script', 'pagesContents', 'print', 'hiddenContents', 'splash', 'cache', 'bgcolor', 'message', 'favicon', 'svg', 'beginbody', 'csp', 'opengraph', 'twittercard'); - - $res = []; - foreach ($vars as $v) { - if (isset($$v)) { - $res[''] = $$v; - } else { - $res[''] = ''; - } - } - $this->_indexVars = $res; - } - return $this->_indexVars; - } - - protected function writeIndex() - { - $iv = $this->getIndexVars(); - foreach ($iv as $k => $v) { - $this->seo->html = str_replace($k, $v, $this->seo->html); - } - if ($this->book->parametres->seoVersion) { - foreach ($this->pages as $page => $infos) { - $this->_writeIndex($page); - } - } else { - $this->_writeIndex(1); - } - } - - protected function writeWidget() - { - // 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) { - if (isset($$v)) { - $whtml = str_replace('', $$v, $whtml); - } else { - $whtml = str_replace('', '', $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); - } - $this->seo = new wsHTML5Seo($this); - } - - public function addContentLock($page, $unlockConditions = '') - { - $unlockConditions = CubeIT_Text::explodeNewLines($unlockConditions); - $conditions = []; - foreach ($unlockConditions as $unlockCondition) { - $e = explode(',', $unlockCondition); - if (!isset($e[1])) { - $e[1] = 'click'; - } - $conditions[] = $e; - } - $page = max(1, $page); - if (!isset($this->content_lock[$page])) { - $this->content_lock[$page] = ['unlocked' => 0, 'conditions' => []]; - } - $this->content_lock[$page]['conditions'] = array_merge($this->content_lock[$page]['conditions'], $conditions); - } - - protected function writeScorm() - { - if ($this->book->parametres->scorm_version == '1.2') { - $manifestfile = '_imsmanifest.12.xml'; - } elseif ($this->book->parametres->scorm_version = '2004') { - $manifestfile = '_imsmanifest.2004.xml'; - } - - $manifest = file_get_contents($this->assets . '/' . $manifestfile); - if (!$this->book->parametres->scorm_title) { - $this->book->parametres->scorm_title = $this->book->parametres->title; - } - if (!$this->book->parametres->scorm_id || ($this->book->book_id > 16614 && $this->book->parametres->scorm_id == 'MFMCTE091mobile')) { - $this->book->parametres->scorm_id = 'fb_' . $this->book->book_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; - if ($this->book->parametres->scorm_quizdata) { - $this->config->scorm_quizdata = wsUtil::excelToArray($this->wdir . '/' . $this->book->parametres->scorm_quizdata); - } - } - - protected function writePrint() - { - if (!$this->book->parametres->print && !$this->book->parametres->pdf) { - return; - } - - $res = wsUtil::compilePDF($this->book, $this->pages); - if ($res !== false) { - $this->vdir->copy($res, '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(); - - $t = CubeIT_Util_Object::toArray($this->book->traductions); - - $traductions = (!is_countable($t) || !count($t)) ? $lang->traductions : $t; - - $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 = explode(',', $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', - 'uid' => 'tabs', - ]; - } - - $pagesOfCustomLinks = []; - $hiddenLinks = []; - - $linksCopy = $links; - - foreach ($linksCopy as $k => $linkData) { - if ($linkData['type'] == 35) { - $linkData = wsLinks::decryptLink($linkData); - $animation = contentLink::parseAnimation($linkData['image_rollover']); - if (isset($animation['backgroundColor']) && $animation['backgroundColor'] != 'transparent') { - $dupData = $linkData; - $dupData['type'] = 14; - $dupData['to'] = $animation['backgroundColor']; - $dupData['image_rollover'] = ''; - $dupData['uid'] = 'b_' . $linkData['uid']; - array_push($links, $dupData); - array_push($links, $linkData); - unset($links[$k]); - } - } - if (isset($linkData['image']) && $linkData['image'] && $linkData['type'] != 28 && $linkData['type'] != 35) { - $dupData = $linkData; - $dupData['image'] = ''; - $dupData['to'] = $linkData['image']; - $dupData['rollover'] = $linkData['image_rollover']; - $dupData['type'] = 15; - $dupData['uid'] = 'i_' . $linkData['uid']; - if (wsHTML5Link::isScorm($linkData)) { - $dupData['scorm'] = true; - } - array_push($links, $dupData); - } - if ($linkData['type'] == 7) { - $k = $linkData['to']; - $e = explode(':', $k); - if (count($e) > 1) { - $k = $e[1]; - } - if (!isset($pagesOfCustomLinks[$k])) { - $pagesOfCustomLinks[$k] = []; - } - if (!in_array($linkData['page'], $pagesOfCustomLinks[$k])) { - $pagesOfCustomLinks[$k][] = $linkData['page']; - } - } - if ($linkData['type'] == 32) { - $hiddenLinks[] = $linkData['to']; - } - } - - $this->config->pagesOfCustomLinks = $pagesOfCustomLinks; - - $i = 0; - $pages = array(); - $cpages = array(); - $css = array(); - $linkPages = []; - $allLinksData = []; - - usort($links, array($this, '_sortLinks')); - - foreach ($links as $linkData) { - if (in_array($linkData['type'], $ignore)) { - continue; - } - - $linkData['hidden'] = in_array($linkData['uid'], $hiddenLinks); - 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; - } - - if (strpos($link->page, 'link_') === 0) { - $linkPages[$link->page] = true; - } - - $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; - } - - $allLinksData[$linkData['uid']] = $linkData; - - 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 ($linkPages as $linkPage => $true) { - $allpages[] = $linkPage; - } - - 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; - } - - if ($this->writeLinksData) { - $this->config->linksData = $allLinksData; - } - - 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, 35 => 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 beforeWriteConfig() - { - uasort($this->content_lock, function ($a, $b) { - return $a['page'] - $b['page']; - }); - - $this->config->content_lock = $this->content_lock; - } - - protected function writeJs() - { - $this->beforeWriteConfig(); - - $config = $this->writeConfig(); - $this->vdir->file_put_contents('data/datas.js', $config); - $finals = $this->jsLibs; - 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; - } - - $dirminimized = $this->assets . '/js/min/'; - if (!file_exists($dirminimized)) { - mkdir($dirminimized, 0777, true); - } - - foreach ($finals as $jsfinal => $files) { - $mintime = 0; - $hash = hash('sha256', json_encode($files)); - $minimized = $dirminimized . $jsfinal . '-' . $hash . '-min.js'; - if (!file_exists(dirname($minimized))) { - mkdir(dirname($minimized)); - } - if (file_exists($minimized) && filesize($minimized) > 0) { - $mintime = filemtime($minimized); - $reminimize = false; - } else { - $mintime = 0; - $reminimize = true; - } - - if (!$reminimize) { - foreach ($files as $file) { - $f = $this->assets . '/' . $file; - if (file_exists($f) && filemtime($f) > $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 = ''; - $hasNonMin = false; - foreach ($files as $file) { - $f = $this->assets . '/' . $file; - if (!file_exists($f)) { - continue; - } - if (strpos($f, '.min.') === false) { - $hasNonMin = true; - } - $js .= file_get_contents($f); - $js .= ";\n\n"; - } - $tmp = cubeFiles::tempnam(); - file_put_contents($tmp, $js); - - if (file_exists($minimized)) { - unlink($minimized); - } - - if ($hasNonMin) { - $uglify = new CubeIT_CommandLine('/usr/local/bin/uglifyjs'); - $uglify->setArg('o', $minimized); - $uglify->setArg(null, $tmp); - $uglify->execute(); - $uglify->debug(); - } else { - copy($tmp, $minimized); - } - - if (!file_exists($minimized) || filesize($minimized) == 0) { - 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'); - } - $this->vdir->copyDirectory($this->assets . '/js/libs/fluidbook/workers', 'js/libs/fluidbook/workers'); - $this->vdir->copyDirectory($this->assets . '/js/libs/stand', 'js/libs/stand'); - $this->vdir->copyDirectory($this->assets . '/js/libs/polyfills', 'js/libs/polyfills'); - } - - 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() - { - return 'var DATAS=' . json_encode($this->config) . ';' . "\n"; - } - - protected function writeCountries() - { - $c = Zend_Locale::getTranslationList('Territory', $this->book->lang, 2); - asort($c); - $this->config->countries = $c; - } - - 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 - ); - - $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; - } - - $rasterizePages = $this->config->rasterizePages; - $this->config->pagesDimensions = []; - - $thumbs = array(); - foreach ($this->pages as $page => $infos) { - $docdir = wsDocument::getDir($infos['document_id']); - - $thisrasterize = in_array($page, $rasterizePages); - $thisimagesvg = !$thisrasterize && $this->svg; - $thisbackgroundPrefix = $thisrasterize ? ['t'] : $this->backgroundsPrefix; - - foreach ($this->getResolutions() as $r) { - foreach ($thisbackgroundPrefix as $backgroundsPrefix) { - $srcPrefix = $backgroundsPrefix; - if ($backgroundsPrefix == 'p') { - $srcPrefix = 'h'; - } - $source = $docdir . 'html/' . $srcPrefix . $r . '-' . $infos['document_page'] . '.jpg'; - if (!file_exists($source)) { - if (!isset($doc) || $doc->document_id != $infos['document_id']) { - $dao = new wsDAODocument($core->con); - $doc = $dao->selectById($infos['document_id']); - } - $doc->makeHTML5Files($infos['document_page']); - } - if ($r == 150 && file_exists($source)) { - $d = getimagesize($source); - $this->config->pagesDimensions[$page] = array($this->cssWidth, $d[1] * ($this->cssWidth / $d[0])); - } - $ok = $this->vdir->copy($source, 'data/background/' . $r . '/' . $backgroundsPrefix . $page . '.jpg'); - if (!$ok && $r = 300) { - $this->maxRes = 150; - } - } - } - - if ($thisimagesvg) { - $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'); - } - } - - - $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'); - } - - if ($page % 10 == 0) { - $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($links) - { - $res = array(); - - $lessContents = ''; - - $lessVariables = array(); - $lessVariables['css-scale'] = $this->cssScale; - $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; - if ($this->book->parametres->correctCenter) { - $lessVariables['book-page-correct-width'] = ceil($w + 1); - $lessVariables['book-page-correct-height'] = ceil($h + 1); - } else { - $lessVariables['book-page-correct-width'] = $w; - $lessVariables['book-page-correct-height'] = $h; - } - $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); - - $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'; - - 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 { - // Force redo - $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); - $lessVariables['inlineslideshow-transition-time'] = (floatval($this->book->parametres->inlineSlideshowTransitionDuration) * 1000) . 'ms'; - $res = array_merge($res, $links); - - // Bookmarks - if (!isset($this->book->parametres->bookmarkCornerSize)) { - $this->book->parametres->bookmarkCornerSize = 10; - } - - $lessVariables['bookmark-star-disabled-color'] = wsHTML5::colorToCSS($this->theme->parametres->bookmarkStarDisabledColor); - $lessVariables['bookmark-star-enabled-color'] = wsHTML5::colorToCSS($this->theme->parametres->bookmarkStarEnabledColor); - $lessVariables['bookmark-color'] = wsHTML5::colorToCSS($this->theme->parametres->bookmarkBackgroundColor); - $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); - $lessVariables['tooltip-font-size'] = 14 * ($this->theme->parametres->tooltipTextSize / 100); - - #fonts - foreach ($this->cssfont as $hash => $item) { - $res[] = '@font-face{font-family: "' . $hash . '";src:url("../../data/fonts/' . $hash . '.woff") format("woff");}'; - } - - # ZoomPopup close button background - $res[] = '.zoomPopupClose {background-color:' . wsHTML5::colorToCSS($this->theme->parametres->couleurB) . ';}'; - - if ($this->book->parametres->textPopupStylesheet) { - $res[] = file_get_contents($this->wdir . '/' . $this->book->parametres->textPopupStylesheet); - } - - $this->_writeLess($lessVariables, $lessContents); - $this->stylesheets[] = 'data/style/style.css'; - $this->vdir->file_put_contents('data/style/style.css', implode("\n", $res)); - $this->log('Write CSS'); - } - - 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)) { - die($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)) { - continue; - } - $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 addVideoJs() - { - $locale = $this->book->lang; - $map = ['pt' => 'pt-PT', 'pt-br' => 'pt-BR', 'zh' => 'zh-CN', 'es-pr' => 'es']; - if (isset($map[$locale])) { - $locale = $map[$locale]; - } - - $this->addJsLib('videojs', ['js/libs/videojs/video.withscalefix.js', 'js/libs/videojs/lang/' . $locale . '.js']); - $this->addLess('videojs/videojs'); - } - - public function addFont($fontFile) - { - $f = $this->wdir . '/' . $fontFile; - $e = explode('.', $f); - $ext = array_pop($f); - $hash = 'fb_' . substr(md5($fontFile), 0, 10); - if (!isset($this->cssfont[$hash])) { - $final = $hash . '.woff'; - $dest = $this->wdir . '/' . $final; - if (!file_exists($dest) || filemtime($dest) < filemtime($f)) { - $fontforge = new cubeCommandLine('convertrn.pe'); - $fontforge->setPath(CONVERTER_PATH); - $fontforge->setArg(null, $f); - $fontforge->setArg(null, $dest); - $fontforge->execute(); - } - $this->vdir->copy($dest, 'data/fonts/' . $hash . '.woff'); - $cmd = "font-line report $f"; - $fontline = `$cmd`; - $report = explode("\n", $fontline); - - foreach ($report as $item) { - $item = trim($item); - list($k, $v) = explode(':', $item, 2); - if ($k == '[head] Units per Em') { - $fontHeight = trim($v); - } - if ($k == '[OS/2] CapHeight') { - $fontCapHeight = trim($v); - } - if ($k == '[OS/2] TypoAscender') { - $ascender = abs(trim($v)); - } - if ($k == '[OS/2] TypoDescender') { - $descender = abs(trim($v)); - } - } - $capHeight = 1; - if (isset($fontCapHeight) && isset($fontHeight)) { - $capHeight = $fontCapHeight / $fontHeight; - } - $font = ['family' => $hash, 'capHeight' => $capHeight, 'ascender' => $ascender / $fontHeight, 'descender' => $descender / $fontHeight]; - $this->cssfont[$hash] = $font; - } - return $this->cssfont[$hash]; - } - - public function addJsLib($name, $files) - { - if (!is_array($files)) { - $files = [$files]; - } - $this->jsLibs[$name] = $files; - } - - 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')); - } - - $m = $xpath->query('//meta[@name="width"]'); - foreach ($m as $meta) { - $res['width'] = intval((string)$meta->getAttribute('content')); - } - - $m = $xpath->query('//meta[@name="height"]'); - foreach ($m as $meta) { - $res['height'] = intval((string)$meta->getAttribute('content')); - } - - $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; - } - -} - -if (!function_exists('is_countable')) { - - function is_countable($c) - { - return is_array($c) || $c instanceof Countable; - } - -} diff --git a/inc/ws/Util/html5/mobilefirst/class.ws.html5.links.php b/inc/ws/Util/html5/mobilefirst/class.ws.html5.links.php deleted file mode 100644 index 1265fb494..000000000 --- a/inc/ws/Util/html5/mobilefirst/class.ws.html5.links.php +++ /dev/null @@ -1,1991 +0,0 @@ -book->parametres->customLinkClass) { - case 'WescoLink': - return new wescoLink($id, $init, $compiler); - case 'HaguenauManifLink': - return new haguenauManifLink($id, $init, $compiler); - case 'FLFLink': - return new flfLink($id, $init, $compiler); - case 'InpesPopinLink': - return new inpesPopinLink($id, $init, $compiler); - case 'PierronLink': - return new pierronLink($id, $init, $compiler); - case 'WescoSalesLink': - return new wescoSalesLink($id, $init, $compiler); - case 'AtlanticDownloadLink': - return new atlanticDownloadLink($id, $init, $compiler); - default : - return customLink::getCustomInstance($id, $init, $compiler); - } - break; - case 8: - case 9: - return null; - case 10: - if ($init['inline']) { - return new webVideoLink($id, $init, $compiler); - } else { - return new webVideoPopupLink($id, $init, $compiler); - } - case 11: - return new actionLink($id, $init, $compiler); - case 12: - switch ($compiler->book->parametres->basketManager) { - case 'Remarkable': - return new remarkableCartLink($id, $init, $compiler); - break; - default : - return new cartLink($id, $init, $compiler); - break; - } - case 13: // zoom area - return new zoomLink($id, $init, $compiler); - case 14: - return new colorLink($id, $init, $compiler); - case 15: - - if (stristr($init['to'], '.zip')) { - return new inlineSlideshowLink($id, $init, $compiler); - } else { - return new imageLink($id, $init, $compiler); - } - case 16: - return new fileLink($id, $init, $compiler); - case 17: - if ($init['inline']) { - return new audioLink($id, $init, $compiler); - } else { - return new audioPopupLink($id, $init, $compiler); - } - case 18: - if ($init['inline']) { - return new tooltipLink($id, $init, $compiler); - } else { - return new textPopupLink($id, $init, $compiler); - } - case 19: - break; - case 20: - $compiler->addBookmarkGroup($init); - break; - case 21: - case 6: - return self::getMultimediaInstance($id, $init, $compiler); - case 23: - return new statsTagLink($id, $init, $compiler); - case 24: - return new phoneLink($id, $init, $compiler); - case 25: - $compiler->addAudiodescription($init); - break; - case 26: - $compiler->addPageLabel($init['page'], $init['to']); - break; - case 27: - return new eventOverlayLink($id, $init, $compiler); - break; - case 29: - return new facebookLikeLink($id, $init, $compiler); - break; - case 30: - return new slideshowLink($id, $init, $compiler); - break; - case 31: - if ($init['inline']) { - return new iframeLink($id, $init, $compiler); - } else { - return new iframePopupLink($id, $init, $compiler); - } - case 32: - return new showLinkLink($id, $init, $compiler); - case 33: - return new zoomhdLink($id, $init, $compiler); - case 34: - $compiler->addContentLock($init['page'], $init['to']); - break; - case 35: - return new textLink($id, $init, $compiler); - break; - default: - return null; - } - } - - public static function replaceCustomURL($url) - { - $url = trim($url); - if (strpos($url, 'custom:') === 0) { - $e = explode(':', $url, 2); - return customLink::_getURL($e[1]); - } - - return $url; - } - - public static function getMultimediaInstance($id, $init, &$compiler) - { - if ($init['alternative'] == '') { - return null; - } - - $ext = mb_strtolower(files::getExtension($init['alternative'])); - - if (in_array($ext, array('oam', 'zip', 'html')) || substr($init['alternative'], 0, 4) == 'http') { - if ($init['inline']) { - return new htmlMultimediaLink($id, $init, $compiler); - } else { - return new htmlMultimediaPopupLink($id, $init, $compiler); - } - } else if (in_array($ext, array('gif', 'jpeg', 'jpg', 'png', 'svg'))) { - if ($init['inline']) { - return new htmlMultimediaImage($id, $init, $compiler); - } else { - return new htmlMultimediaPopupImage($id, $init, $compiler); - } - } - return null; - } - - public static function isScorm($linkData) - { - return (isset($linkData['scorm']) && $linkData['scorm']) || (stristr($linkData['to'], 'scorm') || (isset($linkData['alternative']) && stristr($linkData['alternative'], 'scorm'))); - } - - public function __construct($id, $init, &$compiler) - { - $this->_init = $init; - foreach ($init as $k => $v) { - if ($k == 'extra') { - if (CubeIT_Util_Json::isJson($v)) { - $v = CubeIT_Util_Json::decode($v); - } else if (stristr($v, '=')) { - $vv = $v; - $v = []; - parse_str($vv, $v); - $v = CubeIT_Util_Object::asObject($v); - } - } - $this->$k = $v; - } - if (!$this->video_width) { - $this->video_width = $this->width; - } - if (!$this->video_height) { - $this->video_height = $this->height; - } - if ($this->target == '') { - $this->target = '_blank'; - } - $this->wdir = WS_BOOKS . '/working/' . $compiler->book_id . '/'; - $this->id = $id; - $this->compiler = $compiler; - $this->init(); - } - - public function init() - { - - } - - public function getDefaultTooltip() - { - return false; - } - - public function getTooltip() - { - if (is_null($this->infobulle) || !$this->infobulle) { - if ($this->getDefaultTooltip() === false) { - return; - } - return '~' . $this->getDefaultTooltip(); - } - return $this->infobulle; - } - - public function getHTMLContainer() - { - return '
getAdditionnalContent() . '>' . $this->getHTMLContent() . '
'; - } - - public function getHTMLContainerClass() - { - $res = trim('link ' . $this->class); - if (intval($this->page) % 2 == 1) { - $res .= ' odd'; - } - return $res; - } - - public function getHTMLContent() - { - return ''; - } - - public function getAdditionnalContent() - { - return ''; - - } - - public function getClasses() - { - - $res = array(); - if ($this->image_rollover != 'none') { - $res[] = 'image_rollover'; - } - return $res; - } - - public function copyExternalFile($file, $video = false) - { - $this->compiler->copyLinkFile($file, 'data/links/', $video); - } - - public function copyExternalDir($dir, $dest = 'data/links') - { - $this->compiler->copyLinkDir($dir, $dest); - } - - public function unzipFile($file, $moveAssets = false) - { - return $this->compiler->unzipFile($file, $moveAssets); - } - - public function getCssScale() - { - if (is_int($this->page)) { - return $this->compiler->getCssScale(); - } else { - return 1; - } - } - - public function getCSSZIndex() - { - $zindex = (($this->zindex + 1) * 1000) - min(999, round(($this->width * $this->height) / 300)); - return 'z-index:' . $zindex . ';'; - } - - public function getCSSContainer() - { - if (!($this instanceof contentLink) && intval($this->page) % 2 == 1 && $this->compiler->book->parametres->mobileNavigationType != 'mobilefirst') { - $this->page--; - $this->left += $this->compiler->width; - } - - $css = '#l_' . $this->id . '{'; - $css .= 'left:' . round($this->left * $this->getCssScale()) . 'px;top:' . round($this->top * $this->getCssScale()) . 'px;'; - $css .= 'width:' . round($this->width * $this->getCssScale()) . 'px;height:' . round($this->height * $this->getCssScale()) . 'px;'; - $css .= $this->getCSSZIndex(); - $origin = false; - if ($this->rot) { - $css .= wsHTML5::writeCSSUA('transform', 'rotate(' . $this->rot . 'deg)'); - $origin = true; - } - if (isset($this->extra->skewX)) { - $css .= wsHTML5::writeCSSUA('transform', 'skewX(' . $this->extra->skewX . 'deg)'); - $origin = true; - } - - $css .= $this->getCSS(); - $css .= '}'; - return $css; - } - - public function getCSS() - { - return ''; - } - - public function keep() - { - return false; - } - - public static function getUniversalLocation($loc, $css = false) - { - $datas = parse_url($loc); - - if (isset($datas['scheme']) && !is_null($datas['scheme']) || strpos($loc, '#') === 0) { - return $loc; - } else { - if ($css) { - return '../links/' . $loc; - } else { - return 'data/links/' . $loc; - } - } - } - -} - -class normalLink extends wsHTML5Link -{ - - public function getHTMLContent() - { - $class = $this->getClasses(); - if ($this->display_area) { - $class[] = 'displayArea'; - } - $attrs = ''; - if (count($class)) { - $attrs .= ' class="' . implode(' ', $class) . '"'; - } - $t = $this->getTooltip(); - if ($t !== false) { - $attrs .= ' data-tooltip="' . htmlentities($t, ENT_QUOTES) . '"'; - } - if (isset($this->extra->blinkdelay)) { - $attrs .= ' data-blinkdelay="' . intval($this->extra->blinkdelay) . '"'; - } - return 'getAdditionnalContent() . $this->getTrack() . '>'; - } - - public function getTrack() - { - return ''; - } - - public function getURL() - { - return '#'; - } - - public function getTarget() - { - return '_self'; - } - -} - -class showLinkLink extends normalLink -{ - public function getURL() - { - return '#'; - } - - public function getClasses() - { - $res = parent::getClasses(); - $res[] = 'showlink'; - } - - public function getAdditionnalContent() - { - $res = parent::getAdditionnalContent(); - $res .= ' data-showmode="' . $this->target . '" data-showid="' . $this->to . '"'; - return $res; - } -} - -class tooltipLink extends normalLink -{ - public function getClasses() - { - return array_merge(array('lazy'), parent::getClasses()); - } - - public function getAdditionnalContent() - { - $res = parent::getAdditionnalContent(); - $res .= ' data-tooltip-maxwidth="' . $this->compiler->book->parametres->linkTooltipMaxWidth . '" '; - $res .= ' data-tooltip-touch="1" '; - return $res; - } - - public function getURL() - { - return '#'; - } -} - -class textPopupLink extends normalLink -{ - public function getClasses() - { - return array_merge(array('lazy', 'textpopup'), parent::getClasses()); - } - - public function getAdditionnalContent() - { - $res = parent::getAdditionnalContent(); - $res .= ' data-text="' . htmlspecialchars($this->infobulle, ENT_QUOTES) . '" '; - return $res; - } - - public function getURL() - { - return '#'; - } - - public function getTooltip() - { - return ''; - } -} - -class htmlMultimediaImage extends wsHTML5Link -{ - public $zindex = 2; - - public function getHTMLContainerClass() - { - return parent::getHTMLContainerClass() . ' multimedia notinteractive'; - } - - public function getHTMLContent() - { - $w = $this->width; - $h = $this->height; - $this->copyExternalFile($this->alternative); - $alt = ''; - return $alt; - } - -} - -class htmlMultimediaPopupLink extends htmlMultimediaPopupImage -{ - - public function getAdditionnalContent() - { - $i = $this->_init; - $i['inline'] = true; - $i['in_popup'] = true; - $i['width'] = $i['video_width']; - $i['height'] = $i['video_height']; - - $l = self::getMultimediaInstance($this->id . '_content', $i, $this->compiler); - $markup = $l->getHTMLContainer(); - return ' data-multimedia="' . rawurlencode($markup) . '" '; - } -} - -class zoomhdLink extends normalLink -{ - public function init() - { - $this->compiler->addJsLib('fluidbook-zoomhd', 'js/libs/fluidbook/links/fluidbook.links.zoomhd.js'); - $this->compiler->writeLinksData = true; - } - - public function getURL() - { - $this->copyExternalFile($this->to); - return '#/zoomhd/' . $this->uid; - } - - public function getAdditionnalContent() - { - $res = parent::getAdditionnalContent(); - $res .= ' data-image="' . $this->to . '" '; - return $res; - } - - public function getDefaultTooltip() - { - return 'zoom in'; - } -} - -class htmlMultimediaPopupImage extends normalLink -{ - - public function getURL() - { - $this->copyExternalFile($this->alternative); - $read = ($this->read_mode) ? 'r_' : ''; - return '#/multimedia/' . $read . md5($this->alternative); - } - - - public function getAdditionnalContent() - { - $res = parent::getAdditionnalContent(); - $dim = getimagesize($this->wdir . '/' . $this->alternative); - - $markup = '
'; - $read = ''; - if ($this->read_mode) { - $read = ' data-readmode="1"'; - } - return $res . ' ' . $read . ' data-multimedia="' . rawurlencode($markup) . '" '; - } - - public function keep() - { - return true; - } - -} - -class contentLink extends wsHTML5Link -{ - public $zindex = 1; - - public function getHTMLContainerClass() - { - return parent::getHTMLContainerClass() . ' contentLink'; - } - - public function getAdditionnalContent() - { - $res = parent::getAdditionnalContent(); - $variables = self::parseAnimation($this->image_rollover); - - if (isset($variables['type'])) { - $res .= ' data-animation-type="' . $variables['type'] . '" data-animation="' . htmlspecialchars(json_encode($variables), ENT_QUOTES) . '" '; - } - - return $res; - } - - public static function parseAnimation($animation) - { - $animation = trim($animation); - $variables = []; - if ($animation != '') { - $lines = CubeIT_Text::splitLines($animation); - foreach ($lines as $line) { - $e = explode('=', $line); - $v = trim($e[1]); - // Handle values surronded by quotes - if (preg_match('|^\"([^\"]+)\"$|', $v, $matches)) { - $v = $matches[1]; - } - $variables[trim($e[0])] = $v; - } - if ($variables['direction'] == 'top') { - $variables['direction'] = 'up'; - } - if ($variables['direction'] == 'bottom') { - $variables['direction'] = 'down'; - } - } - return $variables; - } -} - -class eventOverlayLink extends wsHTML5Link -{ - public $zindex = 3; - - public function getHTMLContainerClass() - { - return parent::getHTMLContainerClass() . ' eventOverlayLink'; - } - - public function getHTMLContent() - { - return '
'; - } -} - -class webLink extends normalLink -{ - public function getURL() - { - $res = str_replace('"', '\'', wsHTML5Link::getUniversalLocation($this->to)); - return $res; - } - - public function getTarget() - { - if (strpos($this->getURL(), 'javascript:') === 0) { - return '_self'; - } - return $this->target; - } - - public function getTrack() - { - return ' data-track="' . $this->getURL() . '"'; - } - - public function getCSS() - { - - } - - public function getDefaultTooltip() - { - return 'click to open the link'; - } - -} - -class mailLink extends normalLink -{ - - public function getURL() - { - return 'mailto:' . $this->to; - } - - public function getTrack() - { - return ' data-track="' . $this->to . '"'; - } - - public function getTarget() - { - return '_self'; - } - - public function getDefaultTooltip() - { - return 'click to send an e-mail'; - } - -} - -class phoneLink extends mailLink -{ - - public function getURL() - { - return 'tel:' . $this->to; - } - - public function getTarget() - { - return '_blank'; - } - - public function getDefaultTooltip() - { - return 'click to call this number'; - } - -} - -class internalLink extends normalLink -{ - - public function getURL() - { - return '#/page/' . $this->getPage(); - } - - public function getPage() - { - if ($this->numerotation == 'physical') { - return $this->to; - } else { - return $this->compiler->virtualToPhysical($this->to); - } - } - - public function getDefaultTooltip() - { - return 'go to page'; - } - -} - -class videoLink extends wsHTML5Link -{ - public $zindex = 2; - - public static function addVideoJS($compiler) - { - $compiler->addVideoJs(); - } - - public function getClasses() - { - return array_merge(['videoLink'], parent::getClasses()); - } - - public function getHTMLContent() - { - - - $this->copyExternalFile($this->to, true); - - $w = round($this->width * $this->getCssScale()); - $h = round($this->height * $this->getCssScale()); - - // Note: width and height for the video is normally measured from the - // preview frame for local files or set to 1280 x 720 for web videos. - // The $w and $h variables here seem to be null generally... - - return $this->makeVideoTag($this, $w, $h, $this->compiler); - } - - public static function makeVideoTag($linkDatas, $w = null, $h = null, $compiler = null) - { - static::addVideoJS($compiler); - - $attributes = static::getVideoAttributes($linkDatas, $w, $h, $compiler); - - $res = '
$value) { - $res .= " data-{$name}='{$value}'"; - } - $res .= '>
'; - - return $res; - } - - public static function getVideoAttributes($data, $w = null, $h = null, $compiler = null) - { - - $file = $data->to; - $e = explode('.', $file); - $ext = array_pop($e); - $basename = implode('.', $e); - - $attr['name'] = $basename; - $attr['id'] = 'video_' . $data->id; - $attr['autoplay'] = ($data->video_auto_start ? '1' : '0'); - $attr['controls'] = ($data->video_controls ? '1' : '0'); - $attr['loop'] = ($data->video_loop ? '1' : '0'); - $attr['sound'] = ($data->video_sound_on ? '1' : '0'); - $attr['link-id'] = $data->uid; - - if (!is_null($w) && !is_null($h)) { - $attr['width'] = $w; - $attr['height'] = $h; - - } else if (!is_null($compiler)) { - // Get video dimensions from thumbnail if possible (locally uploaded files) - $path = WS_BOOKS . '/working/' . $compiler->book_id . '/' . $basename . '.jpg'; - $dim = getimagesize($path); - $attr['width'] = $dim[0]; - $attr['height'] = $dim[1]; - } - - return $attr; - } - -} - -class videoPopupLink extends normalLink -{ - - public function getURL() - { - $this->copyExternalFile($this->to, true); - $file = $this->to; - $e = explode('.', $file); - $ext = array_pop($e); - $basename = implode('.', $e); - - return '#/video/' . $basename; - } - - public function getAdditionnalContent() - { - $this->video_auto_start = true; // Videos should always autoplay - return ' data-video="' . rawurlencode(videoLink::makeVideoTag($this, null, null, $this->compiler)) . '" '; - } - - public function keep() - { - return true; - } - - public function getDefaultTooltip() - { - return 'click to play the video'; - } - -} - -class audioPopupLink extends normalLink -{ - - public function getURL() - { - $this->copyExternalFile($this->to, false); - $file = $this->to; - $e = explode('.', $file); - $ext = array_pop($e); - $basename = implode('.', $e); - - return '#/audio/' . $basename; - } - - public function getAdditionnalContent() - { - return ' data-audio="' . rawurlencode(audioLink::makeAudioTag($this, null, null, $this->compiler)) . '" '; - } - - public function keep() - { - return true; - } - - public function getDefaultTooltip() - { - return 'click to play the audio'; - } - -} - -class webVideoLink extends videoLink -{ - - public static function getVideoAttributes($data, $w = null, $h = null, $compiler = null) - { - $attributes = parent::getVideoAttributes($data, $w, $h, $compiler); - - // Since the admin interface doesn't offer options for setting controls or sound, we will set some defaults here - $attributes['controls'] = '1'; - $attributes['sound'] = '1'; - - $attributes['setup'] = static::getVideoSetup($data, $compiler); - - return $attributes; - } - - public static function getVideoSetup($data, $compiler) - { - - static::addVideoJS($compiler); // Ensure videoJS core is included first - - switch ($data->video_service) { - case 0: // YouTube - $compiler->addJsLib('videojs-youtube', 'js/libs/videojs/Youtube.js'); - // $compiler->addJs('https://rawgit.com/videojs/videojs-youtube/master/dist/Youtube.js'); - $setup = [ - 'techOrder' => ['youtube'], - 'sources' => [ - [ - 'type' => 'video/youtube', - 'src' => 'https://www.youtube.com/watch?v=' . $data->to - ] - ] - ]; - break; - case 1: // Dailymotion - // Todo: add local version of script... - // Note: this plugin doesn't seem to work currently so it is not included - //$compiler->addJs('https://rawgit.com/benjipott/video.js-dailymotion/master/dist-test/videojs-dailymotion.js'); - $setup = [ - // 'techOrder' => ['dailymotion'], - // 'sources' => [ - // [ - // 'src' => 'http://www.dailymotion.com/video/' . $data->to - // ] - // ] - ]; - break; - case 2: // Vimeo - // Todo: add local version of script... - // Note: Vimeo plugin doesn't seem to be working currently - might need updates to work with latest VideoJS module - //$compiler->addJs('https://rawgit.com/videojs/videojs-vimeo/master/dist/videojs-vimeo.min.js'); - $setup = [ - // 'techOrder' => ['vimeo'], - // 'sources' => [ - // [ - // 'type' => 'vimeo/vimeo', - // 'src' => 'https://www.vimeo.com/' . $data->to - // ] - // ] - ]; - break; - default: - $setup = []; - } - - return json_encode($setup, JSON_UNESCAPED_SLASHES); - - } - - public function getHTMLContent() - { - - if ($this->video_service !== 0) { - return $this->getEmbed(); - } - - $w = round($this->width * $this->getCssScale()); - $h = round($this->height * $this->getCssScale()); - - return $this->makeVideoTag($this, $w, $h, $this->compiler); - } - - public function getEmbed() - { - return ''; - } - - public function getEmbedURL() - { - if ($this->video_service == 0) { - $url = 'https://www.youtube.com/embed/' . $this->to . '?html5=1'; - } elseif ($this->video_service == 1) { - $url = 'https://www.dailymotion.com/embed/video/' . $this->to; - } elseif ($this->video_service == 2) { - $url = 'https://player.vimeo.com/video/' . $this->to; - } elseif ($this->video_service == 3) { - list($playerId, $videoId) = explode('|', $this->to); - $url = 'https://link.brightcove.com/services/player/bcpid' . $playerId . '?bctid=' . $videoId . '&autoStart=false&width=100%25&height=100%25'; - } - return $url; - } - -} - -class actionLink extends internalLink -{ - protected $_share = array('facebook', 'twitter', 'googleplus', 'linkedin', 'viadeo'); - - public function getURL() - { - return '#'; - } - - public function getClasses() - { - if (in_array($this->to, $this->_share)) { - return array_merge(array('share'), parent::getClasses()); - } else { - return parent::getClasses(); - } - } - - public function getAdditionnalContent() - { - $res = parent::getAdditionnalContent(); - if (is_object($this->extra) || is_array($this->extra)) { - $extra = json_encode($this->extra); - } else { - $extra = $this->extra; - } - if ($extra) { - $res .= ' data-extra="' . htmlspecialchars($extra, ENT_QUOTES) . '"'; - } - - if (in_array($this->to, $this->_share)) { - $res .= ' data-service="' . $this->to . '" '; - } else { - $res .= /*parent::getClasses()*/ - ' data-action="' . $this->to . '" '; - } - return $res; - } - - public function getDefaultTooltip() - { - return false; - } - - -} - -class cartLink extends normalLink -{ - - public function getURL() - { - return '#'; - } - - public function getDefaultTooltip() - { - return 'add to cart'; - } - - public function getAdditionnalContent() - { - $res = parent::getAdditionnalContent(); - $e = explode("|", $this->to); - $ref = $e[0]; - $qty = isset($e[1]) ? $e[1] : '1'; - - $res .= 'data-cart-ref="' . $ref . '" data-cart-qty="' . $qty . '" '; - return $res; - } -} - -class remarkableCartLink extends cartLink -{ - -} - -class colorLink extends contentLink -{ - public function getCSS() - { - return 'background-color:' . wsHTML5::colorToCSS($this->to, 1) . ';'; - } - - public function getAdditionnalContent() - { - $res = parent::getAdditionnalContent(); - $res .= ' data-color="' . wsHTML5::colorToCSS($this->to, 1) . '"'; - return $res; - } -} - -class textLink extends contentLink -{ - public function getCSS() - { - $font = $this->compiler->addFont($this->image); - $fz = round($this->height * $this->getCssScale() / $font['capHeight'], 2); - return 'line-height:' . $font['capHeight'] . ';font-size:' . $fz . 'px;font-family:' . $font['family'] . ';color:' . wsHTML5::colorToCSS($this->extra, 1) . ';'; - } - - public function getHTMLContainerClass() - { - return parent::getHTMLContainerClass() . ' textLink'; - } - - - public function getAdditionnalContent() - { - $res = parent::getAdditionnalContent(); - return $res; - } - - public function getHTMLContent() - { - return $this->to; - } -} - -class imageLink extends contentLink -{ - - public function getCSS() - { - $this->copyExternalFile($this->to); - return 'background-image:url(' . wsHTML5Link::getUniversalLocation($this->to, true) . ');background-size:100% 100%;background-repeat:no-repeat;'; - } - - public function getAdditionnalContent() - { - $res = parent::getAdditionnalContent(); - $res .= ' data-rollover="' . $this->rollover . '"'; - return $res; - } - -} - -class inlineSlideshowLink extends contentLink -{ - public function getHTMLContent() - { - $d = $this->unzipFile($this->to, false); - $this->compiler->vdir->copyDirectory($d['dir'], $d['fdir']); - - $iterator = CubeIT_Files::getRecursiveDirectoryIterator($d['dir']); - - $files = array(); - foreach ($iterator as $f) { - /* @var $f SplFileInfo */ - $files[] = $f->getFilename(); - } - sort($files); - $f = htmlspecialchars(json_encode($files), ENT_QUOTES); - - return '
'; - } -} - -class fileLink extends normalLink -{ - - public function getURL() - { - if ($this->compiler->book->parametres->linkFilePrefix && !CubeIT_Util_Url::isDistant($this->to)) { - return $this->compiler->book->parametres->linkFilePrefix . $this->to; - } - $this->copyExternalFile($this->to); - return wsHTML5Link::getUniversalLocation($this->to); - } - - public function getTarget() - { - return '_blank'; - } - - public function getDefaultTooltip() - { - return 'click to open the file'; - } - -} - -class facebookLikeLink extends wsHTML5Link -{ - public function getHTMLContent() - { - $this->compiler->addFacebookSDK(); - return '
'; - } -} - -class htmlMultimediaLink extends wsHTML5Link -{ - - protected $_config = null; - protected $_content = ''; - protected $_url; - protected $_externalIframe = false; - public $zindex = 2; - - public function getHTMLContent() - { - if ($this->_content == '') { - $ext = files::getExtension($this->alternative); - - if ($ext == 'oam') { - $d = $this->unzipFile($this->alternative, true); - $this->_config = $this->getConfigOAM($d['dir']); - $this->copyExternalDir($d['dir'], $d['fdir']); - } elseif ($ext == 'zip') { - $d = $this->unzipFile($this->alternative, false); - $this->_config = $this->getConfigZIP($d['dir']); - $this->copyExternalDir($d['dir'], $d['fdir']); - if (file_exists($d['dir'] . '/index.html')) { - $html = file_get_contents($d['dir'] . '/index.html'); - $html = str_replace('var pRatio = window.devicePixelRatio || 1,', 'var pRatio = 0.5,', $html); - $this->_config['lowDef'] = 'index_ld.html'; - $this->compiler->vdir->file_put_contents($d['fdir'] . '/' . $this->_config['lowDef'], $html); - } - } elseif ($ext == 'html') { - $fdir = 'data/links'; - $dir = $fdir; - - $d = array('fdir' => $fdir, 'dir' => $dir); - - $this->compiler->vdir->copy($this->compiler->wdir . '/' . $this->alternative, $d['dir'] . '/' . $this->alternative); - $this->_config = $this->getConfigHTML($d['dir'], $this->alternative); - $this->copyExternalFile($d['dir'] . '/' . $this->alternative); - } - if (substr($this->alternative, 0, 4) == 'http') { - $this->_url = $this->_externalIframe = $this->alternative; - $this->_config = array('html' => false, 'width' => $this->width, 'height' => $this->height); - } - - if ($this->_config['width'] == 0) { - $this->_config['width'] = $this->width; - } - if ($this->_config['height'] == 0) { - $this->_config['height'] = $this->height; - } - - $res = ''; - $s = $this->in_popup ? 1 : $this->getCssScale(); - if ($this->_config['html']) { - $this->_url = $d['fdir'] . '/' . $this->_config['html']; - if ($this->extra) { - $this->_url .= '?' . $this->extra; - } - - $iw = $this->_config['width']; - $ih = $this->_config['height']; - - $ld = ' '; - if (isset($this->_config['lowDef'])) { - $ld = ' data-ld="' . str_replace('index.html', $this->_config['lowDef'], $this->_url) . '" '; - } - - $res = ''; - } - if ($this->_externalIframe !== false) { - $iw = $this->_config['width'] * $s; - $ih = $this->_config['height'] * $s; - $res = ''; - } - - foreach ($this->_config['inject'] as $i) { - $infos = ['path' => 'data/links/' . str_replace('.', '_', $this->alternative) . '/']; - $i = str_replace('$id', '"#l_' . $this->id . '"', $i); - $i = str_replace('$init', CubeIT_Util_Json::encode($infos), $i); - $this->compiler->htmlmultimedia[] = $i; - } - - foreach ($this->_config['injectcss'] as $i) { - - } - - foreach ($this->_config['injectjs'] as $i) { - $this->compiler->pluginJs[] = $d['fdir'] . '/' . $i; - } - - - $this->_content = $res; - } - return $this->_content; - } - - public function getHTMLContainerClass() - { - $res = parent::getHTMLContainerClass() . ' multimedia'; - if (!$this->interactive) { - $res .= ' notinteractive'; - } - - return $res; - } - - - protected function _correctFiles($dir) - { - $files = CubeIT_Files::getRecursiveDirectoryIterator($dir); - foreach ($files as $f) { - /* @var $f SplFileInfo */ - if ($f->getExtension() == 'js') { - $this->_correctFile($f); - } - } - } - - public function getCSSContainer() - { - if (!($this instanceof contentLink) && $this->page % 2 == 1 && $this->compiler->book->parametres->mobileNavigationType != 'mobilefirst') { - $this->page--; - $this->left += $this->compiler->width; - } - - $css = '#l_' . $this->id . '{'; - $css .= 'left:' . $this->left * $this->getCssScale() . 'px;top:' . $this->top * $this->getCssScale() . 'px;'; - $css .= 'width:' . $this->_config['width'] . 'px;height:' . $this->_config['height'] . 'px;'; - $css .= $this->getCSSZIndex(); - $css .= $this->getCSS(); - $css .= '}'; - if ($this->_externalIframe !== false && $this->in_popup) { - $css .= '#l_' . $this->id . '>iframe{' . wsHTML5::writeCSSUA('transform', 'scale(' . $this->getCssScale() . ')') . '}'; - } - return $css; - } - - public function getCSS() - { - $sx = ($this->width / ($this->_config['width'])) * $this->getCssScale(); - $sy = ($this->height / ($this->_config['height'])) * $this->getCssScale(); - - $res = wsHTML5::writeCSSUA('transform', 'scale(' . $sx . ',' . $sy . ')'); - $res .= wsHTML5::writeCSSUA('transform-origin', '0% 0%'); - - if (!$this->_config['html']) { - return ''; - } - return $res; - } - - public function getConfigZIP($d) - { - return $this->compiler->getConfigZIP($d); - } - - public function getConfigHTML($d, $html) - { - $res = array('width' => $this->video_width, 'height' => $this->video_height); - $r = array('html' => $html, 'inject' => array(), 'injectcss' => array(), 'injectjs' => array()); - - return array_merge($res, $r); - } - - public function getConfigOAM($d) - { - $x = simplexml_load_file($d . '/config.xml'); - $config = (string)$x->oamfile['src']; - $config = str_replace('/Assets', '', $d . '/' . $config); - $x = simplexml_load_file($config, 'SimpleXMLElement', LIBXML_NOCDATA); - $c = CubeIT_Util_Xml::toObject($x); - - $props = array('default-width' => 'width', 'default-height' => 'height', 'html-page' => 'html'); - - - $res = array('inject' => array(), 'injectcss' => array(), 'injectjs' => array(), 'content' => trim($c->content), 'name' => $c->_name, 'assets' => array()); - foreach ($c->properties->property as $p) { - if (isset($props[$p->_name])) { - $res[$props[$p->_name]] = $p->_defaultValue; - } - } - foreach ($c->require as $r) { - if ($r->_type == 'folder') { - continue; - } - $res['assets'][] = $r->_src; - } - return $res; - } - -} - -class webVideoPopupLink extends videoPopupLink -{ - - // public function getURL() { - // if ($this->video_service == 0) { - // $service = 'youtube'; - // } elseif ($this->video_service == 1) { - // $service = 'dailymotion'; - // } elseif ($this->video_service == 2) { - // $service = 'vimeo'; - // } elseif ($this->video_service == 3) { - // $service = 'brightcove'; - // } - // return '#/webvideo/' . $service . '/' . $this->to; - // } - - public function getURL() - { - - switch ($this->video_service) { - case 1: // Dailymotion - return '#/webvideo/dailymotion/' . $this->to; - break; - case 2: // Vimeo - return '#/webvideo/vimeo/' . $this->to; - break; - default: - return '#/video/' . $this->to; - } - } - - public function getAdditionnalContent() - { - $this->video_auto_start = true; // Videos should always autoplay - return ' data-video="' . rawurlencode(webVideoLink::makeVideoTag($this, 1280, 720, $this->compiler)) . '" '; - } - -} - -class audioLink extends wsHTML5Link -{ - - public function getHTMLContent() - { - $this->copyExternalFile($this->to); - - $w = round($this->width * $this->getCssScale()); - $h = round($this->height * $this->getCssScale()); - - return self::makeAudioTag($this, $w, $h, $this->compiler); - } - - public function getCSSContainer() - { - $css = parent::getCSSContainer(); - $css .= '#l_' . $this->id . ' audio{'; - $css .= 'width:' . round($this->width * $this->getCssScale()) . 'px;'; - $css .= 'height:' . round($this->height * $this->getCssScale()) . 'px;'; - $css .= 'display:block;'; - $css .= '}'; - return $css; - } - - public static function makeAudioTag($linkDatas, $w = null, $h = null, $compiler = null) - { - $res = ''; - return $res; - } - -} - -class wescoLink extends normalLink -{ - - public function getURL() - { - return 'https://workshop.fluidbook.com/services/wescoRef?ref=' . $this->to; - } - - public function getTarget() - { - return '_blank'; - } - -} - -class pierronLink extends normalLink -{ - - public function getURL() - { - return 'https://workshop.fluidbook.com/services/pierronRef?ref=' . $this->to; - } - - public function getTarget() - { - return '_blank'; - } - -} - -class wescoSalesLink extends normalLink -{ - public function __construct($id, $init, $compiler) - { - $e = explode(':', $init['to']); - if (count($e) > 1) { - $init['to'] = $e[1]; - } - parent::__construct($id, $init, $compiler); - } - - public function getUrl() - { - return '#'; - } - - public function getAdditionnalContent() - { - $e = explode(':', $this->to); - if (count($e) > 1) { - $this->to = $e[1]; - } - return parent::getAdditionnalContent() . ' data-wescosales-ref="' . $this->to . '" '; - } - - public function getTooltip() - { - return 'Consulter les ventes de ce produit'; - } -} - -class atlanticDownloadLink extends normalLink -{ - public function getUrl() - { - return '#'; - } - - public function getAdditionnalContent() - { - return parent::getAdditionnalContent() . ' data-atlanticdownload-ref="' . $this->to . '" '; - } - - public function getTooltip() - { - return 'Télécharger les documents'; - } -} - -class inpesPopinLink extends htmlMultimediaLink -{ - - public function getHTMLContent() - { - $this->alternative = $this->to; - $c = parent::getHTMLContent(); - - $class = $this->getClasses(); - if ($this->display_area) { - $class[] = 'displayArea'; - } - $c = ''; - if (count($class)) { - $c = ' class="' . implode(' ', $class) . '"'; - } - $tooltip = ''; - $t = $this->getTooltip(); - if ($t !== false) { - $tooltip = ' data-tooltip="' . htmlspecialchars($t, ENT_QUOTES) . '"'; - } - return 'getAdditionnalContent() . '>'; - } - - public function getCSSContainer() - { - if (!($this instanceof contentLink) && $this->page % 2 == 1 && $this->compiler->book->parametres->mobileNavigationType != 'mobilefirst') { - $this->page--; - $this->left += $this->compiler->width; - } - - $css = '#l_' . $this->id . '{'; - $css .= 'left:' . $this->left * $this->getCssScale() . 'px;top:' . $this->top * $this->getCssScale() . 'px;'; - $css .= 'width:' . $this->width * $this->getCssScale() . 'px;height:' . $this->height * $this->getCssScale() . 'px;'; - $css .= $this->getCSSZIndex(); - if ($this->rot) { - $css .= wsHTML5::writeCSSUA('transform', 'rotate(' . $this->rot . 'deg)'); - $css .= wsHTML5::writeCSSUA('transform-origin', '0% 0%'); - } - $css .= $this->getCSS(); - $css .= '}'; - return $css; - } - - public function getCSS() - { - return ""; - } - - public function getClasses() - { - $res = parent::getClasses(); - $res[] = 'popin'; - return $res; - } - - public function getAdditionnalContent() - { - $res = parent::getAdditionnalContent(); - $res .= ' data-src="' . $this->_url . '" data-width="900" data-height="650"'; - return $res; - } - -} - -class statsTagLink extends wsHTML5Link -{ - public function __construct($id, $init, &$compiler) - { - parent::__construct($id, $init, $compiler); - $this->width = 1; - $this->height = 1; - } - - public function getHTMLContent() - { - return str_replace('%tag%', $this->to, $this->compiler->book->parametres->xiti_page); - } -} - -class flfLink extends wescoLink -{ - - public function getURL() - { - return 'https://workshop.fluidbook.com/services/flfRef?ref=' . $this->to; - } - - public function getTarget() - { - return '_blank'; - } - - public function getTooltip() - { - return 'Accéder à la fiche du stage sur notre site flf.fr'; - } - -} - -class haguenauManifLink extends internalLink -{ - - public function getPage() - { - $fiches = array( - "1" => 7, "2" => 8, "3" => 14, "4" => 16, "5" => 17, "6" => 18, "7" => 19, "8" => 20, "9" => 22, "10" => 23, "11" => 24, "12" => 27 - , "13" => 29, "14" => 32, "15" => 34, "16" => 37, "17" => 38, "18" => 41, "19" => 43, - "20" => 45, "21" => 46, "22" => 52, "23" => 53, "24" => 54, "25" => 56, "26" => 59, "27" => 60 - ); - return $fiches[$this->to]; - } - -} - -class customLink extends wescoLink -{ - public static function getCustomInstance($id, $init, &$compiler) - { - $e = explode(':', $init['to']); - if ($e[0] == '10doigts') { - $init['to'] = self::_getURL($init['to']); - $init['iframeType'] = '10doigts'; - $init['infobulle'] = 'Voir le produit'; - return new iframePopupLink($id, $init, $compiler); - } - return new customLink($id, $init, $compiler); - } - - public static function _getURL($to) - { - global $core; - $e = explode(':', $to, 2); - if (!count($e) == 1) { - return 'https://workshop.fluidbook.com/services/wsref?ref=' . urlencode($to); - } - $type = trim($e[0]); - $ref = trim($e[1]); - - $r = $core->con->select("SELECT * FROM wsref WHERE ref='" . $core->con->escape($ref) . "' AND type='" . $core->con->escape($type) . "'"); - if ($r->count()) { - return $r->url; - } - return 'https://workshop.fluidbook.com/services/wsref?ref=' . urlencode($type . '|' . $ref); - } - - public function getURL() - { - return self::_getURL($this->to); - } - - public function getDefaultTooltip() - { - return 'click to open the link'; - } -} - -class zoomLink extends normalLink -{ - protected $maxzoom_default = 2; - - public function getHTMLContainerClass() - { - $class = ' zoomarea'; - - $groups = explode(',', $this->group); - - // If there's more than one group assigned, this link shouldn't be clickable (disabled via CSS) - // This needs to be set here (parent element) instead of on the actual link so we don't end up with a dead zone - if (count($groups) > 1) { - $class .= ' pointer-events-none'; - } - - return parent::getHTMLContainerClass() . $class; - } - - public function getDefaultTooltip() - { - return 'zoom in'; - } - - public function __construct($id, $init, $compiler) - { - parent::__construct($id, $init, $compiler); - } - - public function getAdditionnalContent() - { - $res = parent::getAdditionnalContent(); - - $res .= ' id="' . $this->uid . '"'; - - // Data attributes - $attributes = [ - 'maxzoom' => empty($this->to) ? $this->maxzoom_default : $this->to, - 'group' => $this->group, - 'group-count' => empty($this->group) ? 0 : count(explode(',', $this->group)), - 'width' => round($this->width), - 'height' => round($this->height), - 'x' => round($this->left), - 'y' => round($this->top) - ]; - - // Set data attributes - foreach ($attributes as $key => $val) { - $res .= ' data-' . $key . '="' . $val . '"'; - } - - $this->generateImage(); - - return $res; - } - - public function generateImage() - { - - $maxzoom = ((int)$this->to !== 0) ? $this->to : $this->maxzoom_default; // Max zoom level might not always be set in the link editor - $maxzoom = min($maxzoom, 4.166666667); - - // TODO: Consider generating higher-res images (eg. 2x) for HiDPI screens. Maybe some extra optimisations can be done on the larger images... - - $extractOptions = [ - // The Poppler::extractArea function accepts a resolution setting and uses that to determine the - // scale factor on the extracted images. It does so by dividing by 72, so we can pass our own scale - // factor by setting the resolution to 72 * $maxzoom - 'resolution' => 72 * $maxzoom - ]; - - // Round all link co-ordinates because there seems to be a problem with the the Workshop link editor - // where link "left" values (and maybe others) change fractionally upon saves. This causes problems later when - // extracting the zoom images from the PDF because it causes a cache-miss and the images are regenerated again. - $x = round($this->left); - $y = round($this->top); - $w = round($this->width); - $h = round($this->height); - $bookwidth = round($this->compiler->book->parametres->width); - - //error_log("--- Book Width: $bookwidth ---"); - - $p = wsDAOBook::getDocumentPage($this->compiler->book_id, $this->page); - $pdfpath = wsDocument::getDir($p['document_id']) . 'original.pdf'; - - $left = CubeIT_Files::tempnam(); - $leftfile = CubeIT_CommandLine_Poppler::extractArea($pdfpath, - $p['document_page'], - array('x' => $x, 'y' => $y, 'width' => $w, 'height' => $h), - $left, $extractOptions, WS_CACHE . '/zoomarea/' . $this->compiler->book_id . '/'); - - if (($x + $w) > $bookwidth) { - $p = wsDAOBook::getDocumentPage($this->compiler->book_id, $this->page + 1); - $pdfpath = wsDocument::getDir($p['document_id']) . 'original.pdf'; - $diff = ($w + $x) - $bookwidth; - $right = CubeIT_Files::tempnam(); - $rightfile = CubeIT_CommandLine_Poppler::extractArea($pdfpath, - $p['document_page'], - array('x' => 0, 'y' => $y, 'width' => $diff, 'height' => $h), - $right, $extractOptions, WS_CACHE . '/zoomarea/' . $this->compiler->book_id . '/'); - - $both = CubeIT_Files::tempnam() . '.jpg'; - CubeIT_CommandLine_Imagemagick::append(array($leftfile, $rightfile), $both, 'horizontal'); - } else { - $both = $leftfile; - } - - $this->compiler->simpleCopyLinkFile($both, 'data/links/zoom_' . $this->id . '.jpg'); - - // Perform tidy up and delete temporary files if they exist - $files_to_delete = ['left', 'leftfile', 'right', 'rightfile', 'both']; - foreach ($files_to_delete as $file) { - if (isset($$file)) { - $this->compiler->vdir->addTemp($$file); - } - } - } - - - public function getClasses() - { - // Assign CSS classes for all groups so we can match and group them via JS - $groups = explode(',', $this->group); - $group_classes = []; - - foreach ($groups as $group) { - if (empty($group)) continue; - - $group_classes[] = 'zoom-group-' . trim($group); - } - - return array_merge($group_classes, ['zoomPopup'], parent::getClasses()); - } -} - - -class slideshowLink extends normalLink -{ - - protected $path; - protected $path_absolute; - - public function getURL() - { - - if (empty($this->to)) { - return ''; - } - - $d = $this->unzipFile($this->to, false); - $this->copyExternalDir($d['dir'], $d['fdir']); - - $this->path = $d['fdir']; - $this->path_absolute = $this->compiler->vdir->path($d['fdir']); - - return '#/slideshow/' . $this->uid; - } - - public function getAdditionnalContent() - { - return ' data-slideshow="' . rawurlencode($this->generateSlideshow()) . '" '; - } - -// public function keep() { -// return true; -// } - - public function getDefaultTooltip() - { - return 'view slideshow'; - } - - public function generateSlideshow() - { - - $this->compiler->addJsLib('slick', 'js/libs/slick/slick.js'); - $this->compiler->addLess('slick/slick-bundle'); - $this->compiler->addLess('fluidbook.slideshow'); - - $extensions = ['jpg', 'png', 'jpeg', 'gif']; - - $slideshowID = 'slideshow_' . $this->uid; - $XML_path = $this->path_absolute . '/slideshow.xml'; // Optional file so it may not exist - - $this->getURL(); - - $slides = []; - // If the zip file contained a slideshow.xml file, use that for fetching images and their captions - if (file_exists($XML_path)) { - - $slideshow_XML = simplexml_load_file($XML_path); - $slideshowData = CubeIT_Util_Xml::toObject($slideshow_XML); - foreach ($slideshowData->image as $img) { - $full_path = $this->path_absolute . '/' . $img->_name; - $slides[] = ['caption' => $img->_caption, 'path' => $full_path]; - } - - } else { - // Or by default, just get all the images that were in the zip file... - $afiles = CubeIT_Files::getRecursiveDirectoryIterator($this->path_absolute); - - foreach ($afiles as $afile) { - /** @var SplFileInfo $afile */ - if (!$afile->isFile()) { - continue; - } - $ext = mb_strtolower($afile->getExtension()); - if (!in_array($ext, $extensions)) { - continue; - } - $slides[] = ['path' => $afile->getPathname(), 'caption' => null]; - uasort($slides, [$this, '_orderSlidesByFilename']); - } - } - - $res = ''; - foreach ($slides as $slide) { - $res .= '
'; - $res .= ''; - if (null !== $slide['caption']) { - $res .= '

' . $slide['caption'] . '

'; - } - - $res .= '
'; // .fb-slideshow-slide - } - - $res = '
' . $res . '
'; - - $res .= ''; - - return $res; - } - - - protected function _orderSlidesByFilename($a, $b) - { - return strcmp($a['path'], $b['path']); - } -} - -class iframeLink extends wsHTML5Link -{ - function getHTMLContainerClass() - { - return parent::getHTMLContainerClass() . ' iframe'; - } - - function getHTMLContent() - { - return ''; - } -} - -class iframePopupLink extends normalLink -{ - public function getURL() - { - return '#/iframe/' . md5($this->to); - } - - public function getTrack() - { - return ' data-track="' . $this->to . '"'; - } - - public function getAdditionnalContent() - { - $res = parent::getAdditionnalContent(); - $markup = '
'; - $markup .= ''; - $markup .= '
'; - return $res . ' data-iframe="' . rawurlencode($markup) . '" '; - } - - public function keep() - { - return false; - } - -}