From: vincent@cubedesigners.com Date: Wed, 3 May 2017 14:40:50 +0000 (+0000) Subject: wip #1381 @0.75 X-Git-Url: http://git.cubedesigners.com/?a=commitdiff_plain;h=40d17e5dd327d0b7bc0f470fa7afcf7548a1471a;p=cubeextranet.git wip #1381 @0.75 --- diff --git a/inc/ws/Controlleur/class.ws.maintenance.php b/inc/ws/Controlleur/class.ws.maintenance.php index c4bddbe67..7a4e34757 100644 --- a/inc/ws/Controlleur/class.ws.maintenance.php +++ b/inc/ws/Controlleur/class.ws.maintenance.php @@ -751,8 +751,14 @@ class wsMaintenance { public static function restoreComposition($args) { global $core; $book_id = $args[0]; + if (isset($args[1])) { + $date = $args[1]; + } else { + $date = TIME; + } + - $r = $core->con->select('SELECT * FROM book_pages_versions WHERE book_id=\'' . $core->con->escape($book_id) . '\' AND composition!=\'a:0:{}\' ORDER BY `update` DESC LIMIT 1'); + $r = $core->con->select('SELECT * FROM book_pages_versions WHERE book_id=\'' . $core->con->escape($book_id) . '\' AND composition!=\'a:0:{}\' AND `update`<=' . $date . ' ORDER BY `update` DESC LIMIT 1'); if (!$r->count()) { return; } diff --git a/inc/ws/DAO/class.ws.dao.book.php b/inc/ws/DAO/class.ws.dao.book.php index afb60a319..5b5312d3d 100644 --- a/inc/ws/DAO/class.ws.dao.book.php +++ b/inc/ws/DAO/class.ws.dao.book.php @@ -1618,7 +1618,7 @@ class wsDAOBook extends commonDAO { $version = 'dev'; } - $htmlCompiler = wsHTML5Compiler::factory($book_id, $version); + $htmlCompiler = wsHTML5::compilerFactory($book_id, $version); $htmlCompiler->compile(); } diff --git a/inc/ws/Util/_common.php b/inc/ws/Util/_common.php index 2a4932716..6ed480908 100644 --- a/inc/ws/Util/_common.php +++ b/inc/ws/Util/_common.php @@ -9,10 +9,7 @@ $__autoload['wsSWF2HTMLParagraph'] = dirname(__FILE__) . '/class.ws.swf2html.php $__autoload['wsSWF2HTMLMatrix'] = dirname(__FILE__) . '/class.ws.swf2html.php'; $__autoload['wsSecureSWF'] = dirname(__FILE__) . '/class.ws.secure.swf.php'; $__autoload['wsTools'] = dirname(__FILE__) . '/class.ws.tools.php'; -$__autoload['wsHTML5Compiler'] = dirname(__FILE__) . '/html5/class.ws.html5.compiler.php'; $__autoload['wsHTML5AppCompiler'] = dirname(__FILE__) . '/html5/app/class.ws.html5.app.compiler.php'; -$__autoload['wsHTML5CompilerDev'] = dirname(__FILE__) . '/html5/class.ws.html5.compiler.php'; -$__autoload['wsHTML5Link'] = dirname(__FILE__) . '/html5/class.ws.html5.links.php'; $__autoload['wsPDFFontExtractor'] = dirname(__FILE__) . '/fontextractor/class.ws.pdf.fontextractor.php'; $__autoload['wsPDFFont'] = dirname(__FILE__) . '/fontextractor/class.ws.pdf.font.php'; $__autoload['wsSVN'] = dirname(__FILE__) . '/class.ws.svn.php'; @@ -20,4 +17,5 @@ $__autoload['wsLinks'] = dirname(__FILE__) . '/class.ws.links.php'; $__autoload['wsExporter'] = dirname(__FILE__) . '/class.ws.exporter.php'; $__autoload['wsPDFConvert'] = dirname(__FILE__) . '/class.ws.pdf.convert.php'; $__autoload['wsUtil'] = dirname(__FILE__) . '/class.ws.util.php'; -?> \ No newline at end of file + +$__autoload['wsHTML5'] = dirname(__FILE__) . '/html5/class.ws.html5.php'; diff --git a/inc/ws/Util/class.ws.tools.php b/inc/ws/Util/class.ws.tools.php index 9b08cdce7..a5042f774 100644 --- a/inc/ws/Util/class.ws.tools.php +++ b/inc/ws/Util/class.ws.tools.php @@ -57,7 +57,7 @@ class wsTools { } $hash = sha1(json_encode($colors)); foreach ($colors as $k => $v) { - $colors[$k] = wsHTML5Compiler::colorToArray($colors[$k]); + $colors[$k] = wsHTML5::colorToArray($colors[$k]); } $e = explode('-', $icon); diff --git a/inc/ws/Util/html5/class.ws.html5.compiler.php b/inc/ws/Util/html5/class.ws.html5.compiler.php deleted file mode 100644 index fd73ada29..000000000 --- a/inc/ws/Util/html5/class.ws.html5.compiler.php +++ /dev/null @@ -1,1514 +0,0 @@ -con); - $book = $dao->selectById($book_id); - $version = $book->parametres->mobileLVersion; - } - - if ($version == 'stable') { - $class = 'wsHTML5Compiler'; - } else { - $class = 'wsHTML5CompilerDev'; - } - return new $class($book_id, $version, $phonegap, $phonegapVersion, $dir, $standalone, $appcache, $home); - } - - protected static $resolutions = array(150, 300); - protected $maxRes = 300; - protected static $uaPrefixes = array('-moz-', '-webkit-', '-o-', '-ms-', ''); - public $jsFiles = array( - 'js/libs/modernizr/modernizr.js', - 'js/libs/modernizr/tests.js', - 'js/libs/fix/ios-orientation.js', - 'js/libs/fix/detect-zoom.js', - 'js/libs/cube/fb.js', - 'js/libs/cube/util.js', - 'js/libs/fastclick/fastclick.js', - 'js/libs/json.js', - 'js/libs/flashdetect.js', - 'js/libs/screenfull.js', - 'js/libs/storage.js', - 'js/libs/keymaster.js', - 'js/libs/jquery/jquery.js', - 'js/libs/jquery/jquery.transform.js', - 'js/libs/jquery/jquery.form.js', - 'js/libs/jquery/jquery.mousewheel.js', - 'js/libs/jquery/jquery.hashchange.js', - 'js/libs/jquery/jquery.scrollto.js', - 'js/libs/jquery/jquery.localscroll.js', - 'js/libs/gsap/TweenMax.js', - 'js/libs/gsap/jquery.gsap.js', - 'js/libs/gal/gal.js', - 'js/libs/gal/gal.filesystem.js', - 'js/libs/interact.js', - 'js/libs/fluidbook/forms/fluidbook.form.bulle.js', - 'js/libs/fluidbook/fluidbook.utils.js', - 'js/libs/fluidbook/fluidbook.links.js', - 'js/libs/fluidbook/fluidbook.support.js', - 'js/libs/fluidbook/fluidbook.video.js', - 'js/libs/fluidbook/fluidbook.viewport.js', - 'js/libs/fluidbook/fluidbook.desktop.js', - 'js/libs/fluidbook/fluidbook.service.js', - 'js/libs/fluidbook/fluidbook.l10n.js', - 'js/libs/fluidbook/fluidbook.nav.js', - 'js/libs/fluidbook/fluidbook.touch.js', - 'js/libs/fluidbook/fluidbook.interact.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.coquillette.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/views/fluidbook.chapters.js', - 'js/libs/fluidbook/views/fluidbook.index.js', - 'js/libs/fluidbook/fluidbook.js', - 'js/main.js'); - - public $specialJsFiles = array(); - - public $debugJsFiles = array( - 'js/libs/Three.js', - 'data/search.index.js', - 'data/search.texts.js', - ); - public $testJsFiles = array( - 'js/libs/cube/fb.js', - 'js/libs/modernizr/modernizr.js', - 'js/libs/modernizr/tests.js', - 'js/libs/jquery/jquery.js', - 'js/libs/jquery/jquery.transform.js', - 'js/libs/jquery/jquery.mousewheel.js', - 'js/libs/jquery/jquery.hashchange.js', - 'js/tester.js' - ); - public $widgetJsFiles = array( - 'js/libs/cube/fb.js', - 'js/libs/modernizr/modernizr.js', - 'js/libs/modernizr/tests.js', - 'js/libs/jquery/jquery.js', - 'js/libs/jquery/jquery.transit.js', - 'js/widget.js' - ); - public $specialCSS = array(); - public $phonegapStandardPlugins = array('ios' => array('ExternalFileUtil'), - 'android' => array('webintent')); - public $pluginCSS = array(); - public $pluginJs = array(); - public $htmlmultimedia = array(); - protected $cssX = array(); - protected $cssY = array(); - protected $cssWidths = array(); - protected $pdf2htmlRatio; - protected $scale; - protected $multiply; - protected $div = array(); - protected $numerotation; - protected $fontDocs = array(); - protected $dir; - protected $z = 3; - public $vdir; - public $wdir; - - /** - * - * @var wsBook - */ - public $book; - protected $pages; - protected $theme; - public $version; - public $book_id; - protected $themeRoot; - - /** - * - * @var wsDAOBook - */ - protected $daoBook; - protected $needToRecompileContents = true; - protected $needToRecompileSettings = true; - public $width; - public $height; - protected $cssWidth; - protected $cssHeight; - protected $cssOneWidth; - protected $cssOneHeight; - protected $cssScale; - protected $cssSVGScale; - protected $optimalWidth = 567; - protected $optimalHeight = 709; - protected $additionalConfig = array(); - protected $fontScale = 1; - protected $cache = array(); - protected $backgroundsPrefix = 'p'; - protected $svg = true; - protected $config = array(); - protected $assets = ''; - protected $phonegap = false; - protected $phonegapVersion; - protected $standalone = false; - protected $hiddenContents = array(); - protected $appcache; - protected $home; - protected $widget = true; - protected $multiApp = false; - protected $pageLabels = array(); - - - function __construct($book_id, $version = 'stable', $phonegap = false, $phonegapVersion = 'latest', $dir = null, $standalone = false, $appcache = false, $home = false) { - global $core; - - $this->phonegapVersion = self::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; - - if (is_null($dir)) { - $this->dir = WS_BOOKS . '/html5/' . $book_id . '/'; - } else { - $this->dir = $dir; - } - $this->vdir = $this->dir; - $this->wdir = WS_BOOKS . '/working/' . $this->book_id . '/'; - - // Clean the folder - `rm -rf $this->vdir`; - if (!file_exists($this->dir)) { - mkdir($this->dir, 0777, true); - } - - $this->daoBook = new wsDAOBook($core->con); - $this->book = $this->daoBook->selectById($book_id); - $this->pages = $this->daoBook->getPagesOfBook($book_id); - - if ($this->book->parametres->mobileVersion == 'html5-images') { - $this->backgroundsPrefix = 't'; - $this->svg = false; - } - - $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->width = round($size[0], 3); - $this->height = round($size[1], 3); - - $imagesize = 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 = 0.75 / 2; - - $this->scale = 1; - if ($this->book->parametres->zoomMode == 1) { - $this->multiply = $this->pdf2htmlRatio * $this->scale * $this->cssOneScale; - } else { - $this->multiply = $this->pdf2htmlRatio * $this->scale * $this->cssScale; - } - $this->numerotation = explode(',', $this->book->numerotation); - - $this->config = cubeObject::merge($this->book->parametres->toStandardObject(), $this->theme->parametres->toStandardObject()); - } - - public function addPageLabel($page, $label) { - $this->pageLabels[$label] = $page; - } - - public function getResolutions() { - $res = self::$resolutions; - if ($this->widget) { - $res = array_merge(array(36), $res); - } - return $res; - } - - public static function getPhonegapVersion($v = 'latest') { - if ($v != 'latest') { - return $v; - } - - $versions = self::getPhonegapVersions(); - return array_pop($versions); - } - - public static function getPhonegapVersions() { - $versions = array(); - - $dr = opendir(WS_COMPILE_ASSETS . '/_html5/js/libs/phonegap'); - while ($file = readdir($dr)) { - if ($file == '.' || $file == '..' || $file == 'plugins') { - continue; - } - $versions[] = $file; - } - usort($versions, 'version_compare'); - return $versions; - } - - 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() { - $dirsToCreate = array('data/images', 'data/contents', 'data/background', 'data/thumbnails', 'data/style'); - if (in_array('flv', $this->getVideosFormats())) { - $dirsToCreate[] = 'swf'; - } - - foreach ($dirsToCreate as $dir) { - $d = $this->vdir . '/' . $dir; - if (!file_exists($d)) { - mkdir($d, 0777, true); - } - } - - // Copy style folder - $from = $this->assets . '/style'; - $to = $this->vdir; - `cp -p -r $from $to`; - - // Copy images folder - $from = $this->assets . '/images'; - `cp -p -r $from $to`; - - // Copy images folder - $from = $this->assets . '/video'; - `cp -p -r $from $to`; - - // Copy swf - if (file_exists($this->vdir . '/swf')) { - $this->copy($this->assets . '/swf/video.swf', $this->vdir . '/swf/video.swf'); - } - - $this->loadPlugins(); - $this->writeImages(); - $linksCSS = $this->writeLinks(); - $numCSS = $this->writeCSS($this->vdir . '/data/style/style_%d.css', $linksCSS); - $this->writeLangs(); - $this->writeIndex($numCSS); - $this->writeTexts(); - $this->writeExtras(); - $this->writeJs(); - if (!$this->widget) { - unlink($this->vdir . '/style/widget.css'); - } - $this->writeCache(); - } - - 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->copy($dir . '/plugin.js', $this->vdir . '/' . $f); - } - if (file_exists($dir . '/plugin.css')) { - $f = $d . '/plugin.css'; - $this->pluginCSS[] = $f; - $this->copy($dir . '/plugin.css', $this->vdir . '/' . $f); - } - } - - $this->config->plugins = $plugins; - - array_push($this->jsFiles, $main); - } - - protected function getVideosFormats($poster = true) { - if (!$this->phonegap) { - $res = array('ogv', 'webm', 'mp4', 'flv'); - } elseif ($this->phonegap == 'ios') { - $res = array('mp4'); - } else if ($this->phonegap == 'android') { - $res = array('webm', 'mp4'); - } - - if ($poster) { - $res[] = 'jpg'; - } - return $res; - } - - protected function writeCache() { - if (!$this->appcache) { - return; - } - - $cacheFile = $this->vdir . '/cache.appcache'; - - if (file_exists($cacheFile)) { - unlink($cacheFile); - } - - $dest = realpath($this->vdir); - $lines = array(); - - $network = array('NETWORK:', '*'); - - $lines[] = 'CACHE MANIFEST'; - $lines[] = '# ' . date('Y-m-d H:i:s'); - $lines[] = ''; - $lines[] = 'index.html'; - $lines[] = ''; - $lines[] = 'FALLBACK:'; - $lines[] = '/ index.html'; - $lines[] = 'index.html* index.html'; - $lines[] = ''; - $lines[] = 'CACHE:'; - - $iterator = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($dest), RecursiveIteratorIterator::SELF_FIRST); - - $exclude = array('index.html', 'indexu.html', 'widget.html', 'indext.html'); - - foreach ($iterator as $path) { - if (!$path->isFile()) { - continue; - } - - $p = str_replace($dest . '/', '', $path); - if (in_array($p, $exclude)) { - continue; - } - $lines[] = $p; - } - - $lines[] = ''; - $lines = array_merge($lines, $network); - - file_put_contents($cacheFile, implode("\n", $lines)); - } - - protected function writeIndex($numCSS) { - global $core; - - $html = file_get_contents($this->assets . '/_index.html'); - $uhtml = $html; - - $titre = $this->book->parametres->title; - - - $daoSignature = new wsDAOSignature($core->con); - $signature = $daoSignature->selectById($this->book->parametres->signature); - - $exportSignature = array('main' => $signature->main, - 'mainLink' => $signature->mainLink, - 'partner' => $signature->partner, - 'partnerLink' => $signature->partnerLink); - - $credits = ''; - if ($signature->partner != '') { - $credits = '' . $signature->partner . ' '; - } - $credits .= '' . $signature->main . ''; - - $hiddenContents = implode("\n", $this->hiddenContents); - - $bgcolor = $this->theme->parametres->loadingBackColor; - - // Google analytics - $ga = ''; - if ($this->book->parametres->googleAnalytics != '') { - $ga = cubePage::googleAnalytics($this->book->parametres->googleAnalytics); - } - if ($this->book->parametres->googleAnalyticsCustom != '') { - $ga .= $this->book->parametres->googleAnalyticsCustom; - } - // Feuilles de style - $sheets = array('style/fluidbook.css'); - for ($i = 0; $i < $numCSS; $i++) { - $sheets[] = 'data/style/style_' . $i . '.css'; - } - $sheets = array_merge($sheets, $this->pluginCSS, $this->specialCSS); - - $style = array(); - foreach ($sheets as $sheet) { - $style[] = ''; - } - $style = implode("\n\t\t", $style); - - $pagesContents = ''; - - $cache = ''; - if ($this->appcache) { - $cache = ' manifest="cache.appcache"'; - } - - $iscript = ''; - if (count($this->htmlmultimedia)) { - $iscript .= '' . "\n"; - } - - $script = ''; - $script .= '' . "\n"; - $script .= '' . "\n"; - if ($this->book->parametres->scorm_enable) { - $script .= '' . "\n"; - $this->writeScorm(); - } - if (count($this->specialJsFiles)) { - $script .= '' . "\n"; - } - foreach ($this->pluginJs as $p) { - $script .= '' . "\n"; - } - $script .= $iscript; - $description = ''; - - - $favicon = ''; - if ($this->theme->parametres->favicon != '') { - copy($this->themeRoot . '/' . $this->theme->parametres->favicon, $this->vdir . '/data/favicon.png'); - $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) { - $dim = getimagesize($this->themeRoot . '/' . $this->theme->parametres->logoLoader); - if ($dim !== false) { - $this->copy($this->themeRoot . '/' . $this->theme->parametres->logoLoader, $this->vdir . '/data/images/' . $this->theme->parametres->logoLoader); - $splash .= ''; - } - } - - $svgfiles = array($this->assets . '/images/interface.svg'); - $svg = ''; - foreach ($svgfiles as $svgfile) { - if (file_exists($svgfile)) { - $svg .= file_get_contents($svgfile); - } - } - - - $vars = array('titre', 'credits', 'ga', 'style', 'script', 'pagesContents', 'description', 'print', 'hiddenContents', 'splash', 'cache', 'bgcolor', 'message', 'favicon', 'svg'); - foreach ($vars as $v) { - $html = str_replace('', $$v, $html); - } - - $scripts = array(); - foreach ($this->debugJsFiles as $js) { - $scripts[] = ''; - } - foreach ($this->jsFiles as $js) { - $scripts[] = ''; - } - foreach ($this->pluginJs as $js) { - $scripts[] = ''; - } - - $scripts[] = ''; - $scripts[] = $iscript; - $script = implode("\n\t\t", $scripts); - - $scripts = array(); - foreach ($this->testJsFiles as $js) { - $scripts[] = ''; - } - $scripts[] = ''; - $script_test = implode("\n\t\t", $scripts); - - $thtml = $uhtml; - - $vars = array('titre', 'credits', 'ga', 'style', 'script', 'pagesContents', 'print', 'hiddenContents', 'splash', 'cache', 'bgcolor', 'message', 'favicon'); - foreach ($vars as $v) { - $uhtml = str_replace('', $$v, $uhtml); - } - - $script .= "\n\t\t" . ''; - $vars = array('titre', 'credits', 'ga', 'style', 'script', 'print', 'hiddenContents', 'splash', 'message'); - foreach ($vars as $v) { - $thtml = str_replace('', $$v, $thtml); - } - - file_put_contents($this->vdir . '/index.html', $html); - file_put_contents($this->vdir . '/indexu.html', $uhtml); - file_put_contents($this->vdir . '/indext.html', $uhtml); - - // Write widget html - if ($this->widget) { - $whtml = file_get_contents($this->assets . '/widget.html'); - $script = ''; - $script .= ''; - - $style = ''; - $vars = array('titre', 'style', 'script'); - foreach ($vars as $v) { - $whtml = str_replace('', $$v, $whtml); - } - file_put_contents($this->vdir . '/widget.html', $whtml); - } - } - - protected function writeScorm() { - $manifest = file_get_contents($this->assets . '/_imsmanifest.xml'); - if (!$this->book->parametres->scorm_title) { - $this->book->parametres->scorm_title = $this->book->parametres->title; - } - if (!$this->book->parametres->scorm_id) { - $this->book->parametres->scorm_id = 'fb_' . $this->book->parametres->id; - } - if (!$this->book->parametres->scorm_org) { - $this->book->parametres->scorm_org = 'Fluidbook'; - } - $vars = array('scorm_id', 'scorm_org', 'scorm_title'); - foreach ($vars as $v) { - $manifest = str_replace('$' . $v, $this->book->parametres->$v, $manifest); - } - file_put_contents($this->vdir . '/imsmanifest.xml', $manifest); - } - - protected function writePrint() { - - if (!$this->book->parametres->print && !$this->book->parametres->pdf) { - return; - } - - $this->copy(WS_BOOKS . '/final/' . $this->book->book_id . '/data/' . $this->book->parametres->pdfName, $this->vdir . '/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 = getimagesize($file); - if ($dim !== false) { - $infos['width'] = $dim[0]; - $infos['height'] = $dim[1]; - } - $this->config->filesInfos[$key] = $infos; - } - - protected function __($str) { - if (!isset($this->config->l10n)) { - $this->writeLangs(); - } - - if (isset($this->config->l10n['default']->$str)) { - return $this->config->l10n['default']->$str; - } else { - return $str; - } - } - - protected function writeLangs() { - global $core; - $daoLang = new wsDAOLang($core->con); - $lang = $daoLang->selectById($this->book->lang); - $langs = $daoLang->selectAll(); - - $traductions = (!count($this->book->traductions)) ? $lang->traductions : $this->book->traductions; - - $this->config->l10n = array(); - $this->config->l10n['default'] = $traductions; - $this->config->defaultLang = $this->book->lang; - - foreach ($langs as $lang) { - $this->config->l10n[$lang->lang_id] = $lang->traductions; - } - $iso = l10n::getISOcodes(); - if ($this->book->parametres->multilang != '') { - $flagsDir = $this->vdir . '/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->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->copy($this->themeRoot . '/' . $this->theme->parametres->afterSearch, $this->vdir . '/data/images/' . $this->theme->parametres->afterSearch); - } - if ($this->book->parametres->externalArchives != '') { - $this->addFilesInfos('archives', $this->wdir . '/' . $this->book->parametres->externalArchives); - $this->copy($this->wdir . '/' . $this->book->parametres->externalArchives, $this->vdir . '/data/images/' . $this->book->parametres->externalArchives); - } - } - - protected function writeLinks() { - global $core; - - if ($this->book->parametres->customLinkClass == 'WescoSalesLink') { - $this->specialJsFiles[] = 'js/libs/fluidbook/special/wescosales.js'; - $this->specialCSS[] = 'style/special/wescosales.css'; - } - - if ($this->book->parametres->customLinkClass == 'AtlanticDownloadLink') { - $this->specialJsFiles[] = 'js/libs/fluidbook/special/atlanticdownload.js'; - $this->specialCSS[] = 'style/special/atlanticdownload.css'; - } - - $this->config->links = array(); - $this->config->clinks = array(); - $this->config->bookmarkGroups = array(); - - $ignore = $this->book->parametres->ignoreLinksTypes; - if (!$ignore) { - $ignore = array(); - } else { - $ignore = split(',', $ignore); - } - - $daoDoc = new wsDAODocument($core->con); - $daoDoc->getLinksAndRulers($this->book_id, $links, $rulers); - - foreach ($links as $linkData) { - if (isset($linkData['image']) && $linkData['image']) { - $dupData = $linkData; - $dupData['image'] = ''; - $dupData['to'] = $linkData['image']; - $dupData['type'] = 15; - array_push($links, $dupData); - } - } - - $i = 0; - $pages = array(); - $cpages = array(); - $css = array(); - - usort($links, array($this, '_sortLinks')); - - foreach ($links as $linkData) { - if (in_array($linkData['type'], $ignore)) { - continue; - } - $link = wsHTML5Link::getInstance($this->base62($i), $linkData, $this); - if (is_null($link)) { - continue; - } - - $c = $link->getHTMLContainer(); - $css[] = $link->getCSSContainer(); - if (!isset($pages[$link->page])) { - $pages[$link->page] = ''; - $cpages[$link->page] = ''; - } - if ($link instanceof contentLink) { - $cpages[$link->page] .= $c; - } else { - $pages[$link->page] .= $c; - } - - if ($link->keep()) { - $this->hiddenContents[] = $c; - } - $i++; - } - - $allpages = range(0, $this->book->parametres->pages + 1); - if ($this->book->parametres->themeEnableAfterSearch) { - $allpages[] = 'aftersearch'; - } - $allpages[] = 'background'; - $allpages[] = 'archives'; - - foreach ($allpages as $i) { - - $c = ''; - $cc = ''; - if (isset($pages[$i])) { - $c = $pages[$i]; - } - if (isset($cpages[$i])) { - $cc = $cpages[$i]; - } - $this->config->links[$i] = $c; - $this->config->clinks[$i] = $cc; - } - return $css; - } - - public function _sortLinks($a, $b) { - $priorities = array(26 => 1); - - $pa = isset($priorities[$a['type']]) ? $priorities[$a['type']] : 0; - $pb = isset($priorities[$b['type']]) ? $priorities[$b['type']] : 0; - return $pb - $pa; - } - - public function addBookmarkGroup($link) { - if ($link['left'] > $this->book->parametres->width) { - //$link['page']++; - } - if ($link['page'] <= 0 || $link['page'] > $this->book->parametres->pages) { - return; - } - - $this->config->bookmarkGroups[] = array('page' => ($link['page']), 'nb' => $link['to'], 'name' => $link['extra']); - } - - public function addAudiodescription($link) { - $this->config->audiodescription[$link['page']] = $link['to']; - $this->copyLinkFile($link['to'], 'data/audiodescription/'); - } - - protected function writeJs() { - $config = $this->writeConfig(); - file_put_contents($this->vdir . '/data/datas.js', $config); - $finals = array('fluidbook' => $this->jsFiles); - if ($this->book->parametres->scorm_enable) { - $finals['scorm'] = array(); - $finals['scorm'][] = 'js/libs/scorm/apiwrapper.js'; - $finals['scorm'][] = 'js/libs/scorm/scorm.js'; - } - if (count($this->specialJsFiles)) { - $finals['special'] = $this->specialJsFiles; - } - if ($this->widget) { - $finals['widget'] = $this->widgetJsFiles; - } - - foreach ($finals as $jsfinal => $files) { - $mintime = 0; - $minimized = $this->assets . '/js/' . $jsfinal . '-min.js'; - if (file_exists($minimized)) { - $mintime = filemtime($minimized); - } - - $reminimize = false; - if ($jsfinal == 'special') { - $reminimize = true; - } - if (!$reminimize) { - foreach ($files as $file) { - if (filemtime($this->assets . '/' . $file) > $mintime) { - $reminimize = true; - break; - } - } - } - - if (!$reminimize) { - if (filemtime(__FILE__) > $mintime || filemtime(__DIR__ . '/class.ws.html5.links.php') > $mintime) { - $reminimize = true; - } - } - - if ($reminimize) { - $js = ''; - foreach ($files as $file) { - $js .= file_get_contents($this->assets . '/' . $file); - $js .= ";\n\n"; - } - $tmp = cubeFiles::tempnam(); - file_put_contents($tmp, $js); - - $uglify = new CubeIT_CommandLine('uglifyjs'); - $uglify->setPath(CONVERTER_PATH); - $uglify->setArg('o', $minimized); - $uglify->setArg('no-copyright'); - $uglify->setArg(null, $tmp); - $uglify->execute(); - //$uglify->debug(); - } - $dest = $this->vdir . '/data/' . $jsfinal . '.js'; - copy($minimized, $dest); - } - - - if ($this->phonegap) { - $this->copy(WS_COMPILE_ASSETS . '/_html5/js/libs/phonegap/' . $this->phonegapVersion . '/cordova-' . $this->phonegap . '.js', $this->vdir . '/data/cordova.js'); - } - - } - - public function writeTexts() { - $this->daoBook->makeTextsIndexes($this->book, $this->pages, $index, $textes, true); - $jsindex = 'var INDEX=' . $index . ';' . "\r"; - $jstexts = 'var TEXTS=' . $textes . ';' . "\r"; - - file_put_contents($this->vdir . '/data/search.index.js', $jsindex); - file_put_contents($this->vdir . '/data/search.texts.js', $jstexts); - } - - public function supportSVG() { - if (!$this->phonegap) { - return false; - } else if ($this->phonegap == 'ios') { - return true; - } else { - return false; - } - } - - protected function writeConfig() { - $this->config->numerotation = explode(',', $this->book->numerotation); - $this->config->id = $this->book->book_id; - $this->config->cid = $this->book->cid; - $this->config->cacheDate = TIME; - $this->config->width = $this->cssWidth; - $this->config->height = $this->cssHeight; - $this->config->optimalWidth = $this->optimalWidth; - $this->config->optimalHeight = $this->optimalHeight; - $this->config->chapters = $this->book->chapters; - $this->config->coquilletteBack = $this->colorToCSS($this->theme->parametres->couleurA); - $this->config->coquilletteFront = $this->colorToCSS($this->theme->parametres->arrowsColor); - $this->config->videoFormats = $this->getVideosFormats(false); - $this->config->htmlmultimedia = $this->htmlmultimedia; - $this->config->phonegap = $this->phonegap; - $this->config->retinaResolution = $this->maxRes; - $this->config->pageLabels = $this->pageLabels; - $this->config->pageZoomFactor = $this->z; - 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; - } - $o = trim($this->config->navOrderH) != '' ? $this->config->navOrderH : $this->config->navOrder; - $navOrder = array(); - $oo = explode(',', $o); - foreach ($oo as $ooo) { - $ooo = trim($ooo); - if ($ooo == '') { - continue; - } - $navOrder[] = $ooo; - } - $this->config->navOrder = $navOrder; - - $this->config->standalone = $this->standalone; - if ($this->config->phonegap) { - $this->config->manifest = $this->writeManifest(); - } - - if ($this->config->basket) { - if (file_exists($this->config->basketReferences) || CubeIT_Util_Url::isDistant($this->config->basketReferences)) { - $referencesFile = $this->config->basketReferences; - } else { - $referencesFile = $this->wdir . '/commerce/' . $this->config->basketReferences; - } - - if (file_exists($referencesFile) || CubeIT_Util_Url::isDistant($referencesFile)) { - $ext = CubeIT_Files::getExtension($referencesFile); - if ($ext == 'xlsx') { - $this->config->basketReferences = wsUtil::excelToArray($referencesFile); - } - } - } - - return 'var DATAS=' . json_encode($this->config) . ';' . "\n"; - } - - protected function writeManifest() { - $res = array(); - } - - protected function writeIcons() { - $res = array(); - // Get the colors used to colorize graphics - if ($this->theme->parametres->colorizeIcons) { - $couleurI = $this->theme->parametres->couleurI; - } else { - $couleurI = 'FFFFFF'; - } - - $couleurM = $this->theme->parametres->subTextColor; - - $bookmarksDisabledColors = array('star' => $this->theme->parametres->bookmarkStarDisabledColor, 'bookmark' => $this->theme->parametres->bookmarkBackgroundColor); - $bookmarksEnabledColors = array('star' => $this->theme->parametres->bookmarkStarEnabledColor, 'bookmark' => $this->theme->parametres->bookmarkBackgroundColor); - $subTextColor = $this->theme->parametres->subTextColor; - - $arrowsColor = $this->theme->parametres->arrowsColor; - // Set the icon list with the color - $icons = array('nav-bookmark' => $couleurI, 'nav-friend' => $couleurI, 'nav-help' => $couleurI, 'nav-index' => $couleurI, 'nav-sommaire' => $couleurI, - 'nav-zoomin' => $couleurI, 'nav-zoomout' => $couleurI, 'nav-fullscreen' => $couleurI, - 'interface-next' => $arrowsColor, 'interface-previous' => $arrowsColor, - 'interface-sharp-next' => $arrowsColor, 'interface-sharp-previous' => $arrowsColor, - 'interface-search' => $couleurI, 'interface-back-arrow' => $subTextColor, 'interface-print' => $subTextColor, - 'interface-down' => $arrowsColor, 'interface-close' => $arrowsColor, - 'interface-audio-description-on' => $arrowsColor, 'interface-audio-description-off' => $arrowsColor, - 'help-fingers' => $couleurI, 'help-mouse' => $couleurI, 'nav-home' => $couleurI, 'nav-archives' => $couleurI, 'nav-map' => $couleurI, - 'nav-tag' => $couleurI, 'nav-print' => $couleurI, 'nav-friend' => $couleurI, - 'share-facebook' => $couleurM, 'share-twitter' => $couleurM, 'share-email' => $couleurM, 'share-googleplus' => $couleurM, 'share-linkedin' => $couleurM, 'share-viadeo' => $couleurM, - 'bookmark-left-off' => $bookmarksDisabledColors, 'bookmark-left-on' => $bookmarksEnabledColors, - 'bookmark-right-off' => $bookmarksDisabledColors, 'bookmark-right-on' => $bookmarksEnabledColors - ); - - $this->config->iconsDimensions = array(); - $makepng = !$this->supportSVG(); - foreach ($icons as $icon => $color) { - wsTools::colorizeAndRasterizeIcon($this->theme->parametres->iconSet, $icon, $color, $this->vdir . '/data/images/', 4, $w, $h); - $this->config->iconsDimensions[$icon] = array($w, $h); - } - return $res; - } - - protected function writeImages() { - foreach ($this->getResolutions() as $r) { - mkdir($this->vdir . '/data/background/' . $r, 0777, true); - } - $srcPrefix = $this->backgroundsPrefix; - if ($this->backgroundsPrefix == 'p') { - $srcPrefix = 'h'; - } - foreach ($this->pages as $page => $infos) { - if ($this->svg) { - $orig = wsDocument::getDir($infos['document_id']) . 'html/p' . $infos['document_page'] . '.svg'; - $opt = wsDocument::getDir($infos['document_id']) . 'html/o' . $infos['document_page'] . '.svg'; - - $svg = $orig; - if (file_exists($opt) && filesize($opt) > 0) { - $svg = $opt; - } - - $this->copy($svg, $this->vdir . '/data/contents/p' . $page . '.svg'); - } - - foreach ($this->getResolutions() as $r) { - $ok = $this->copy(wsDocument::getDir($infos['document_id']) . 'html/' . $srcPrefix . $r . '-' . $infos['document_page'] . '.jpg', $this->vdir . '/data/background/' . $r . '/' . $this->backgroundsPrefix . $page . '.jpg'); - if (!$ok && $r = 300) { - $this->maxRes = 150; - } - } - - $thumb = false; - if ($this->book->parametres->pdfThumbnails) { - $thumb = wsPDFConvert::getThumbFromPDF(WS_BOOKS . '/working/' . $this->book->book_id . '/' . $this->book->parametres->pdfThumbnails, $page); - } - if (!$thumb) { - $thumb = wsDocument::getDir($infos['document_id']) . 'p' . $infos['document_page'] . '.jpg'; - } - - - $this->copy($thumb, $this->vdir . '/data/thumbnails/p' . $page . '.jpg'); - - if ($page == 1) { - $this->_makeCover(wsDocument::getDir($infos['document_id']) . 'html/t36-' . $infos['document_page'] . '.jpg'); - } - } - } - - protected function _makeCover($orig) { - $size = getimagesize($orig); - $w = $size[0]; - $h = $size[1]; - - //$tmp = cubeFiles::tempnam() . '.png'; - $tmp = $this->vdir . '/covers.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(); - - $convert = new cubeCommandLine('composite'); - $cmd = '-compose Multiply '; - $cmd .= $tmp . ' ' . $orig . ' '; - $cmd .= $this->vdir . '/cover.jpg'; - $convert->setManualArg($cmd); - $convert->execute(); - - unlink($tmp); - } - - protected function copy($s, $t) { - if (!file_exists($s)) { - fb($s . ' dont exists'); - return false; - } - if (file_exists($t) && filemtime($t) >= filemtime($s) && filesize($s) == filesize($t)) { - return true; - } - if (!file_exists(dirname($t))) { - mkdir(dirname($t), 0777, true); - } - - $res = copy($s, $t); - touch($t, filemtime($s)); - return true; - } - - protected function writeCSS($file, $links) { - $res = array(); - - // 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'; - - - $res[] = '.portrait #pages,.portrait .doublePage.page,.page,.doublePage._3d,#shadow>div{width:' . $w . ';max-width:' . $w . ';height:' . $h . ';max-height:' . $h . '}'; - $res[] = '.doublePage,#pages,#links{width:' . $w2 . ';max-width:' . $w2 . ';height:' . $h . ';max-height:' . $h . '}'; - $res[] = '.landscape .doublePage._2d.axis_x.next{' . self::writeCSSUA('transform', 'translate3d(' . $w2 . ',0,0)') . '}'; - $res[] = '.landscape .doublePage._2d.axis_x.prev{' . self::writeCSSUA('transform', 'translate3d(-' . $w2 . ',0,0)') . '}'; - $res[] = '.portrait .doublePage._2d.axis_x.next{' . self::writeCSSUA('transform', 'translate3d(' . $w . ',0,0)') . '}'; - $res[] = '.portrait .doublePage._2d.axis_x.prev{' . self::writeCSSUA('transform', 'translate3d(-' . $w . ',0,0)') . '}'; - $res[] = '.doublePage._2d.axis_y.next{' . self::writeCSSUA('transform', 'translate3d(0,' . $h . ',0)') . '}'; - $res[] = '.doublePage._2d.axis_y.prev{' . self::writeCSSUA('transform', 'translate3d(0,-' . $h . ',0)') . '}'; - - $res[] = '.doublePage._3d{left:' . $w . ';}'; - $res[] = '#links.right{left:-' . $w . ';}'; - $res[] = '.landscape #shadow>div.right{left: ' . $w . ';}'; - $res[] = '.landscape .page.right{left:' . $w . '}'; - if ($this->theme->parametres->displayPageNumber) { - $res[] = '#pagesnumbers{font-size: ' . (12 * $this->z) . 'px;margin: ' . (5 * $this->z) . 'px 0 0 0;top:' . $h . ';color:' . self::colorToCSS($this->theme->parametres->colorPageNumber) . '}'; - $res[] = '#pagesnumbers div{width:' . $w . '}'; - } else { - $res[] = '#pagesnumbers{display:none;}'; - } - $res[] = '.doublePage._2d,.doublePage._3d{' . self::writeCSSUA('transition', 'all ' . $this->book->parametres->mobileTransitionDuration . 's ease-in-out') . '}'; - - $res[] = '.background{' . self::writeCSSUA('transform-origin', 'top left') . ';}'; - foreach ($this->getResolutions() as $r) { - $ratio = round(72 / $r, 3) * $cssScale; - - $wr = $cssWidth / $ratio; - $hr = $cssHeight / $ratio; - - $br = '.background.r' . $r . '{'; - if ($ratio != 1) { - $br .= self::writeCSSUA('transform', 'scale(' . $ratio . ')') . ';'; - } - $br .= 'width:' . $wr . 'px;height:' . $hr . 'px;}'; - $res[] = $br; - } - $texts = '.texts{' . self::writeCSSUA('transform-origin', 'top left') . ';'; - $texts .= self::writeCSSUA('transform', 'scale(' . round((1 / $this->multiply) * $cssScale * $this->cssSVGScale, 3) . ')') . ';'; - $texts .= 'width:' . ($wm / $this->cssSVGScale) . '; max-width:' . ($wm / $this->cssSVGScale) . ';'; - $texts .= 'height:' . ($hm / $this->cssSVGScale) . '; max-height:' . ($hm / $this->cssSVGScale) . ';'; - $texts .= '}'; - $res[] = $texts; - - // Theme - $shade = '.page .shade{'; - $shade .= 'opacity:' . ($this->theme->parametres->shadeAlpha / 100) . ';'; - $shade .= '}'; - $res[] = $shade; - - // SVG - - $res[] = 'svg .fill-c-menu-back{fill:' . self::colorToCSS($this->theme->parametres->couleurB) . ';}'; - $res[] = 'svg .fill-c-menu-text{fill:' . self::colorToCSS($this->theme->parametres->subTextColor) . ';}'; - - // Search field - $searchColor = self::colorToCSS($this->theme->parametres->couleurS); - $searchBackColor = self::colorToCSS($this->theme->parametres->searchFieldColor); - $search = '#q{'; - $search .= 'color:' . $searchColor . ';'; - $search .= 'background-color:' . $searchBackColor . ';'; - if ($this->theme->parametres->searchShadeAlpha > 0) { - $search .= self::writeCSSUA('box-shadow', '1px 1px 4px rgba(0,0,0,' . ($this->theme->parametres->searchShadeAlpha / 100) . ')') . ' inset;'; - } - $search .= '}'; - $search .= '#searchHints,.hint{color:' . $searchColor . ';background-color:' . $searchBackColor . ';}'; - $search .= '.hint:hover{color:' . $searchBackColor . ';background-color:' . $searchColor . ';}'; - - $res[] = $search; - - // Background - $res[] = $this->_cssBackground(); - - // Archives - // Header - $header = 'header{'; - $header .= 'height:' . $this->theme->parametres->menuHeight . 'px;'; - $header .= 'background-color:' . self::colorToCSS($this->theme->parametres->menuColor) . ';'; - if ($this->theme->parametres->menuImage != '') { - $this->copy($this->themeRoot . '/' . $this->theme->parametres->menuImage, $this->vdir . '/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;'; - } - $header .= '}'; - $res[] = $header; - - //Icons - $res = array_merge($res, $this->writeIcons()); - $res[] = '#nav #locales{background-color:' . self::colorToCSS($this->theme->parametres->couleurI) . ';}'; - - // Logo - $logo = '#logo{'; - if ($this->theme->parametres->logo) { - $this->copy($this->themeRoot . '/' . $this->theme->parametres->logo, $this->vdir . '/data/images/' . $this->theme->parametres->logo); - $dim = getimagesize($this->vdir . '/data/images/' . $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:' . self::colorToCSS($this->theme->parametres->creditsColor) . ';}'; - - // Arrows - $res[] = '#next,#previous{background-color:' . self::colorToCSS($this->theme->parametres->couleurA) . ';}'; - - // Audio description buttons - $res[] = '.audio-description-button{background-color:' . self::colorToCSS($this->theme->parametres->couleurA) . ';}'; - - // Book shadow - $shadowColor = self::colorToCSS($this->theme->parametres->bookShadeColor); - if ($shadowColor != 'transparent') { - $res[] = '#shadow>div{' . self::writeCSSUA('box-shadow', '0 0 20px ' . $shadowColor) . '}'; - } - - // Links Styles - $res = array_merge($res, $links); - $res[] = '.link a.displayArea:hover,.link a.displayArea.animating{background-color:' . self::colorToCSS($this->theme->parametres->linksColor, 0.4) . ';}'; - $res[] = '.link a.displayArea:hover{opacity:1 !important;}'; - $res[] = '.link a.displayArea{-webkit-tap-highlight-color:' . self::colorToCSS($this->theme->parametres->linksColor, 0.4) . ';background-color:' . self::colorToCSS($this->theme->parametres->linksColor, 0.0001) . ';}'; - - // Bookmarks - if (!isset($this->book->parametres->bookmarkCornerSize)) { - $this->book->parametres->bookmarkCornerSize = 10; - } - $size = round($this->width * $this->book->parametres->bookmarkCornerSize * 0.0075 * $this->z); - $res[] = '#links .bookmark{width:' . $size . 'px;height:' . $size . 'px;background-size:' . $size . 'px ' . $size . 'px;}'; - $res[] = '.portrait #fluidbook .bookmark.left{left:' . ($cssWidth - $size) . 'px;}'; - - // Menus - $menuColor = new CubeIT_Graphics_Color($this->theme->parametres->couleurB); - $menuColor->setAlpha(1); - $menuTextColor = self::colorToCSS($this->theme->parametres->subTextColor); - - $menuMultiply = $menuColor->multiply($menuColor); - $menuMultiply2 = $menuMultiply->multiply($menuColor); - - # View - $res[] = '.portrait .mview{width:' . $w . ';min-height:' . $h . '}'; - $res[] = '.landscape .mview{width:' . $w2 . ';min-height:' . $h . '}'; - $res[] = '.mview{background-color:' . $menuColor->toCSS() . ';color:' . $menuTextColor . ';}'; - - # Inner View - $res[] .= '#innerView>div{background-color:' . $menuColor->toCSS() . ';color:' . $menuTextColor . ';}'; - $res[] .= 'form input[type="text"],form input[type="email"]{background-color:' . self::colorToCSS($this->theme->parametres->subFieldColor) . ';color:' . self::colorToCSS($this->theme->parametres->subTextFieldColor) . ';}'; - - // Archives - if ($this->book->parametres->externalArchivesBack) { - $this->copy($this->wdir . '/' . $this->book->parametres->externalArchivesBack, $this->vdir . '/data/images/' . $this->book->parametres->externalArchivesBack); - $res[] = '.mview.archives{background-image:url("../images/' . $this->book->parametres->externalArchivesBack . '");}'; - } - - # Topbar - $top = $menuColor->toCSS(); - $bottom = $menuMultiply->toCSS(); - $border = $menuMultiply2->setAlpha(0.6)->toCSS(); - - $caption = ".mview .caption{ - background-image: -moz-linear-gradient(top, $top 0%, $bottom 100%); /* FF3.6+ */ - background-image: -webkit-linear-gradient(top, $top 0%,$bottom 100%); /* Chrome10+,Safari5.1+ */ - background-image: -o-linear-gradient(top, $top 0%,$bottom 100%); /* Opera 11.10+ */ - background-image: -ms-linear-gradient(top, $top 0%,$bottom 100%); /* IE10+ */ - background-image: linear-gradient(top bottom, $top 0%,$bottom 100%); /* W3C */ -}"; - - $caption .= ".mview .caption a{ - border:1px solid $border; -}"; - $res[] = $caption; - - # Chapters (menu lists) - $top = $menuColor->setAlpha(0.5)->toCSS(); - $bottom = $menuMultiply->setAlpha(0.5)->toCSS(); - $border = $menuMultiply2->setAlpha(0.5)->toCSS(); - - $chapters = "ul.chapters a.level-1,ul.chapters a.level0,ul.chapters a.level1,ul.chapters a.level2,ul.chapters a.level3{ - background-image: -moz-linear-gradient(top, $top 0%, $bottom 100%); /* FF3.6+ */ - background-image: -webkit-linear-gradient(top, $top 0%,$bottom 100%); /* Chrome10+,Safari5.1+ */ - background-image: -o-linear-gradient(top, $top 0%,rgba(0,0,0,0.5) 100%); /* Opera 11.10+ */ - background-image: -ms-linear-gradient(top, $top 0%,$bottom 100%); /* IE10+ */ - background-image: linear-gradient(top bottom, $top 0%,$bottom 100%); /* W3C */ - border-bottom:1px solid $border; -}"; - $res[] = $chapters; - # Index - $ratio = $this->width / $this->height; - $thumbh = round(100 / $ratio); - $res[] = '#indexView .thumb img{width:100px;height:' . $thumbh . 'px;}'; - $res[] = '#indexView .doubleThumb{height:' . $thumbh . 'px;' . self::writeCSSUA('box-shadow', '0 0 3px ' . $shadowColor) . '}'; - $res[] = '#indexView .doubleThumb .overlay{height:' . $thumbh . 'px;}'; - $res[] = '#indexView .doubleThumb .hits.yes{background-color:' . self::colorToCSS($this->theme->parametres->subSelectColor) . ';color:' . self::colorToCSS($this->theme->parametres->subTextSelectColor) . '}'; - - # Tooltip - $res[] = '#tooltip{background-color:' . self::colorToCSS($this->theme->parametres->tooltipBackColor) . ';color:' . self::colorToCSS($this->theme->parametres->tooltipTextColor) . ';}'; - - # ZoomPopup close button background - $res[] = '.zoomPopupClose {background-color:'. self::colorToCSS($this->theme->parametres->couleurB) .';}'; - - $res = array_chunk($res, 3500); - foreach ($res as $k => $css) { - file_put_contents(sprintf($file, $k), implode("\n", $css)); - } - return count($res); - } - - protected function _cssBackground() { - $body = '#background,#splash{'; - $body .= 'background-color:#' . $this->theme->parametres->backgroundColor . ';'; - 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 = getimagesize($bi); - $this->config->backgroundImageDimensions = array('width' => $dbi[0], 'height' => $dbi[1]); - } - - $this->copy($this->themeRoot . '/' . $this->theme->parametres->backgroundImage, $this->vdir . '/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) { - `cp -a $source $this->vdir/$dest`; - } - - public function simpleCopyLinkFile($source, $dest, $addVdir = true) { - if ($addVdir) { - $dest = $this->vdir . '/' . $dest; - } - if (!file_exists(dirname($dest))) { - mkdir(dirname($dest), 0777, true); - } - if (file_exists($dest) && filemtime($dest) >= filemtime($source) && filesize($dest) == filesize($source)) { - return; - } - - $this->copy($source, $dest); - } - - public function copyLinkFile($source, $dest, $video = false) { - if ($video && $this->book->parametres->mobileVideosPath != '') { - - } - - $origDir = $this->wdir; - $types = $this->getVideosFormats(); - if ($video) { - wsTools::encodeWebVideos($origDir . $source, null, true); - $e = explode('.', $source); - array_pop($e); - $base = implode('.', $e); - $source = array(); - foreach ($types as $type) { - $source[] = $base . '.' . $type; - } - } - - if (!is_array($source)) { - $source = array($source); - } - - foreach ($source as $so) { - $s = $origDir . $so; - if (file_exists($s)) { - $d = $this->vdir . '/' . $dest . '/' . $so; - $this->simpleCopyLinkFile($s, $d, false); - } - } - } - - public function __destruct() { - - } - - public static function colorToArray($color, $forceAlpha = null) { - $color = ltrim($color, '#'); - if (strlen($color) == 6) { - $hex = $color; - $alpha = 1; - } else { - $alpha = hexdec(substr($color, 0, 2)) / 255; - $hex = substr($color, 2, 6); - } - - if (!is_null($forceAlpha)) { - $alpha = $forceAlpha; - } - - return array('hex' => strtoupper($hex), 'opacity' => number_format($alpha, 3, '.', '')); - } - - public static function colorToCSS($color, $forceAlpha = null) { - return CubeIT_Graphics_Color::colorToCSS($color, $forceAlpha); - } - -} - -class wsHTML5CompilerDev extends wsHTML5Compiler { - -} diff --git a/inc/ws/Util/html5/class.ws.html5.links.php b/inc/ws/Util/html5/class.ws.html5.links.php deleted file mode 100644 index 63c76a44b..000000000 --- a/inc/ws/Util/html5/class.ws.html5.links.php +++ /dev/null @@ -1,1151 +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); - } - 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: - if ($init['to'] == 'fullScreen') { - return null; - } - return new actionLink($id, $init, $compiler); - case 12: - - return new basketLink($id, $init, $compiler); - case 13: // zoom area - return new zoomLink($id, $init, $compiler); - case 14: - return new colorLink($id, $init, $compiler); - case 15: - 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: - return new tooltipLink($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; - default: - return null; - } - } - - 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 function __construct($id, $init, &$compiler) { - $this->_init = $init; - foreach ($init as $k => $v) { - if ($k == 'extra' && CubeIT_Util_Json::isJson($v)) { - $v = CubeIT_Util_Json::decode($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; - } - - 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 '
' . $this->getHTMLContent() . '
'; - } - - public function getHTMLContainerClass() { - $res = 'link'; - if ($this->page % 2 == 1) { - $res .= ' odd'; - } - return $res; - } - - public function getHTMLContent() { - return ''; - } - - public function getAdditionnalContent() { - - } - - public function getClasses() { - return array(); - } - - public function copyExternalFile($file, $video = false) { - $this->compiler->copyLinkFile($file, 'data/links/', $video); - } - - public function copyExternalDir($dir) { - $this->compiler->copyLinkDir($dir, 'data/links'); - } - - public function unzipFile($file, $moveAssets = false) { - $fdir = 'data/links/' . $file; - $dir = $this->compiler->vdir . '/' . $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->compiler->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 getCssScale() { - if (is_int($this->page)) { - return $this->compiler->getCssScale(); - } else { - return 1; - } - } - - public function getCSSContainer() { - if (!($this instanceof contentLink) && $this->page % 2 == 1) { - $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;'; - $origin = false; - if ($this->rot) { - $css .= wsHTML5Compiler::writeCSSUA('transform', 'rotate(' . $this->rot . 'deg)'); - $origin = true; - } - if (isset($this->extra->skewX)) { - $css .= wsHTML5Compiler::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'])) { - 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'; - } - $c = ''; - if (count($class)) { - $c = ' class="' . implode(' ', $class) . '"'; - } - $tooltip = ''; - $t = $this->getTooltip(); - if ($t !== false) { - $tooltip = ' data-tooltip="' . $t . '"'; - } - return 'getAdditionnalContent() . $this->getTrack() . '>'; - } - - public function getTrack() { - return ''; - } - - public function getURL() { - return '#'; - } - - public function getTarget() { - return '_self'; - } - -} - -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 htmlMultimediaImage extends wsHTML5Link { - - public function getHTMLContainerClass() { - return parent::getHTMLContainerClass() . ' multimedia'; - } - - public function getHTMLContent() { - $w = $this->width * $this->getCssScale(); - $h = $this->height * $this->getCssScale(); - $this->copyExternalFile($this->alternative); - $alt = ''; - return $alt; - } - -} - -class htmlMultimediaPopupLink extends htmlMultimediaPopupImage { - - public function getAdditionnalContent() { - $i = $this->_init; - $i['inline'] = true; - $i['width'] = $i['video_width']; - $i['height'] = $i['video_height']; - - $l = wsHTML5Link::getMultimediaInstance($this->id . '_content', $i, $this->compiler); - $markup = $l->getHTMLContainer(); - return ' data-multimedia="' . rawurlencode($markup) . '" '; - } -} - - -class htmlMultimediaPopupImage extends normalLink { - - public function getURL() { - $this->copyExternalFile($this->alternative); - return '#/multimedia/' . md5($this->alternative); - } - - public function getAdditionnalContent() { - $dim = getimagesize($this->wdir . '/' . $this->alternative); - $markup = '
'; - return ' data-multimedia="' . rawurlencode($markup) . '" '; - } - - public function keep() { - return true; - } - -} - -class contentLink extends wsHTML5Link { - - public function getHTMLContainerClass() { - return parent::getHTMLContainerClass() . ' contentLink'; - } - -} - -class eventOverlayLink extends wsHTML5Link { - 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 function getHTMLContent() { - $this->copyExternalFile($this->to, true); - - $w = round($this->width * $this->getCssScale()); - $h = round($this->height * $this->getCssScale()); - - return self::makeVideoTag($this, $w, $h, $this->compiler); - } - - public static function makeVideoTag($linkDatas, $w = null, $h = null, $compiler = null) { - $file = $linkDatas->to; - $e = explode('.', $file); - $ext = array_pop($e); - $basename = implode('.', $e); - - $autoplay = ($linkDatas->video_auto_start ? '1' : '0'); - $controls = ($linkDatas->video_controls ? '1' : '0'); - $loop = ($linkDatas->video_loop ? '1' : '0'); - $sound = ($linkDatas->video_sound_on ? '1' : '0'); - - $res = '
book_id . '/' . $basename . '.jpg'; - $dim = getimagesize($path); - $res .= 'data-width="' . $dim[0] . '" data-height="' . $dim[1] . '" '; - } - $res .= ' data-autoplay="' . $autoplay . '"'; - $res .= ' data-controls="' . $controls . '"'; - $res .= ' data-loop="' . $loop . '"'; - $res .= ' data-sound="' . $sound . '"'; - $res .= ' data-name="' . $basename . '"'; - $res .= '>
'; - return $res; - } - -} - -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() { - return ' data-video="' . rawurlencode(videoLink::makeVideoTag($this, $this->video_width, $this->video_height, $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 function getHTMLContent() { - return $this->getEmbed(); - } - - 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 = ''; - } 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() { - if (in_array($this->to, $this->_share)) { - return '#'; - } - return '#/' . $this->to; - } - - public function getClasses() { - if (in_array($this->to, $this->_share)) { - return array_merge(array('share'), parent::getClasses()); - } else { - return parent::getClasses(); - } - } - - public function getAdditionnalContent() { - if (in_array($this->to, $this->_share)) { - return parent::getAdditionnalContent() . ' data-service="' . $this->to . '" '; - } else { - return parent::getClasses(); - } - } - - public function getDefaultTooltip() { - return false; - } - - -} - -class basketLink extends contentLink { - - public function getCSS() { - return 'background-color:#fff;'; - } - -} - -class colorLink extends contentLink { - - public function getCSS() { - return 'background-color:' . wsHTML5Compiler::colorToCSS($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;'; - } - -} - -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 htmlMultimediaLink extends wsHTML5Link { - - protected $_config = null; - protected $_content = ''; - protected $_url; - - 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']); - } elseif ($ext == 'zip') { - $d = $this->unzipFile($this->alternative, false); - $this->_config = $this->getConfigZIP($d['dir']); - $this->copyExternalDir($d['dir']); - } elseif ($ext == 'html') { - $fdir = 'data/links'; - $dir = $this->compiler->vdir . '/' . $fdir; - - $d = array('fdir' => $fdir, 'dir' => $dir); - if (!file_exists($d['dir'])) { - fb($d['dir']); - mkdir($d['dir'], 0777, true); - } - 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 = $externalIframe = $this->alternative; - $this->_config = array('html' => false, 'width' => $this->width * $this->getCssScale(), 'height' => $this->height * $this->getCssScale()); - } - - $w = $this->width * $this->getCssScale(); - $h = $this->height * $this->getCssScale(); - $res = ''; - 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']; - - $res = ''; - } - if (isset($externalIframe)) { - $iw = $this->_config['width']; - $ih = $this->_config['height']; - $res = ''; - } - - foreach ($this->_config['inject'] as $i) { - $i = str_replace('$id', '"#l_' . $this->id . '"', $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->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->getCSS(); - $css .= '}'; - return $css; - } - - public function getCSS() { - $sx = ($this->width / ($this->_config['width'])) * $this->getCssScale(); - $sy = ($this->height / ($this->_config['height'])) * $this->getCssScale(); - - $res = wsHTML5Compiler::writeCSSUA('transform', 'scale(' . $sx . ',' . $sy . ')'); - $res .= wsHTML5Compiler::writeCSSUA('transform-origin', '0% 0%'); - - if (!$this->_config['html']) { - return ''; - } - return $res; - } - - public function getConfigZIP($d) { - $res = array('width' => $this->video_width, 'height' => $this->video_height); - if (file_exists($d . '/index.html')) { - $doc = new DOMDocument(); - $doc->loadHTMLFile($d . '/index.html'); - $xpath = new DOMXPath($doc); - $c = $xpath->query("//canvas"); - foreach ($c as $canvas) { - /* @var $canvas DOMElement */ - $res['width'] = intval((string)$canvas->getAttribute('width')); - $res['height'] = intval((string)$canvas->getAttribute('height')); - } - - $r = array('html' => 'index.html', 'inject' => array(), 'injectcss' => array(), 'injectjs' => array()); - } else { - $r = array('html' => false, 'inject' => array(file_get_contents($d . '/init.js')), 'injectcss' => array('multimedia.css'), 'injectjs' => array('multimedia.js')); - } - $res = array_merge($res, $r); - return $res; - } - - 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; - } - -} - -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 getUrl() { - return '#'; - } - - public function getAdditionnalContent() { - 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="' . $t . '"'; - } - return 'getAdditionnalContent() . '>'; - } - - public function getCSSContainer() { - if (!($this instanceof contentLink) && $this->page % 2 == 1) { - $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;'; - if ($this->rot) { - $css .= wsHTML5Compiler::writeCSSUA('transform', 'rotate(' . $this->rot . 'deg)'); - $css .= wsHTML5Compiler::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 zoomLink extends normalLink { - - public function getDefaultTooltip() { - return 'zoom in'; - } - - public function __construct($id, $init, $compiler) { - parent::__construct($id, $init, $compiler); - } - - public function getAdditionnalContent() { - $res = parent::getAdditionnalContent(); - - // Data attributes - $attributes = [ - 'maxzoom' => $this->to, - ]; - - // Set data attributes - foreach ($attributes as $key => $val) { - $res .= ' data-' . $key . '="' . $val . '"'; - } - - $this->generateImage(); - - return $res; - } - - public function generateImage() { - $left = CubeIT_Files::tempnam(); - - $p = wsDAOBook::getDocumentPage($this->compiler->book_id, $this->page); - $pdfpath = wsDocument::getDir($p['document_id']) . 'original.pdf'; - - CubeIT_CommandLine_Poppler::extractArea($pdfpath, - $p['document_page'], - array('x' => $this->left, 'y' => $this->top, 'width' => $this->width, 'height' => $this->height), - $left, array(), WS_CACHE . '/zoomarea/'); - - $bookwidth = $this->compiler->book->parametres->width; - - if (($this->left + $this->width) > $bookwidth) { - $p = wsDAOBook::getDocumentPage($this->compiler->book_id, $this->page + 1); - $pdfpath = wsDocument::getDir($p['document_id']) . 'original.pdf'; - $diff = ($this->width + $this->left) - $bookwidth; - $right = CubeIT_Files::tempnam(); - CubeIT_CommandLine_Poppler::extractArea($pdfpath, - $p['document_page'], - array('x' => 0, 'y' => $this->top, 'width' => $diff, 'height' => $this->height), - $right, array(), WS_CACHE . '/zoomarea/'); - - $both = CubeIT_Files::tempnam() . '.png'; - CubeIT_CommandLine_Imagemagick::append(array($left . '.png', $right . '.png'), $both, 'horizontal'); - } else { - $both = $left . '.png'; - } - - $this->compiler->simpleCopyLinkFile($both, 'data/links/zoom_' . $this->id . '.png'); - } - - - public function getClasses() { - return array_merge(['zoomPopup'], parent::getClasses()); - } -} \ No newline at end of file diff --git a/inc/ws/Util/html5/class.ws.html5.php b/inc/ws/Util/html5/class.ws.html5.php new file mode 100644 index 000000000..d08bf868e --- /dev/null +++ b/inc/ws/Util/html5/class.ws.html5.php @@ -0,0 +1,87 @@ +con); + $book = $dao->selectById($book_id); + $version = $book->parametres->mobileLVersion; + } + + if ($version == 'stable' || $version == 'dev') { + $branch = 'master'; + } else { + list($branch, $w) = explode('|', $version); + } + + + $branchDir = __DIR__ . '/' . $branch . '/'; + $masterDir = __DIR__ . '/master/'; + $files = array('class.ws.html5.compiler.php', 'class.ws.html5.links.php'); + + foreach ($files as $file) { + if (file_exists($branchDir . $file)) { + require_once $branchDir . $file; + } else { + require_once $masterDir . $file; + } + } + + return new wsHTML5Compiler($book_id, $version, $phonegap, $phonegapVersion, $dir, $standalone, $appcache, $home); + } + + public static function getPhonegapVersion($v = 'latest') { + if ($v != 'latest') { + return $v; + } + + $versions = self::getPhonegapVersions(); + return array_pop($versions); + } + + public static function getPhonegapVersions() { + $versions = array(); + + $dr = opendir(WS_COMPILE_ASSETS . '/_html5/js/libs/phonegap'); + while ($file = readdir($dr)) { + if ($file == '.' || $file == '..' || $file == 'plugins') { + continue; + } + $versions[] = $file; + } + usort($versions, 'version_compare'); + return $versions; + } + + public static function writeCSSUA($property, $value) { + $res = array(); + foreach (self::$uaPrefixes as $prefix) { + $res[] = $prefix . $property . ':' . $value; + } + return implode(';', $res); + } + + public static function colorToArray($color, $forceAlpha = null) { + $color = ltrim($color, '#'); + if (strlen($color) == 6) { + $hex = $color; + $alpha = 1; + } else { + $alpha = hexdec(substr($color, 0, 2)) / 255; + $hex = substr($color, 2, 6); + } + + if (!is_null($forceAlpha)) { + $alpha = $forceAlpha; + } + + return array('hex' => strtoupper($hex), 'opacity' => number_format($alpha, 3, '.', '')); + } + + public static function colorToCSS($color, $forceAlpha = null) { + return CubeIT_Graphics_Color::colorToCSS($color, $forceAlpha); + } +} \ No newline at end of file diff --git a/inc/ws/Util/html5/master/class.ws.html5.compiler.php b/inc/ws/Util/html5/master/class.ws.html5.compiler.php new file mode 100644 index 000000000..191b0fa74 --- /dev/null +++ b/inc/ws/Util/html5/master/class.ws.html5.compiler.php @@ -0,0 +1,1449 @@ + array('ExternalFileUtil'), + 'android' => array('webintent')); + public $pluginCSS = array(); + public $pluginJs = array(); + public $htmlmultimedia = array(); + protected $cssX = array(); + protected $cssY = array(); + protected $cssWidths = array(); + protected $pdf2htmlRatio; + protected $scale; + protected $multiply; + protected $div = array(); + protected $numerotation; + protected $fontDocs = array(); + protected $dir; + protected $z = 3; + public $vdir; + public $wdir; + + /** + * + * @var wsBook + */ + public $book; + protected $pages; + protected $theme; + public $version; + public $book_id; + protected $themeRoot; + + /** + * + * @var wsDAOBook + */ + protected $daoBook; + protected $needToRecompileContents = true; + protected $needToRecompileSettings = true; + public $width; + public $height; + protected $cssWidth; + protected $cssHeight; + protected $cssOneWidth; + protected $cssOneHeight; + protected $cssScale; + protected $cssSVGScale; + protected $optimalWidth = 567; + protected $optimalHeight = 709; + protected $additionalConfig = array(); + protected $fontScale = 1; + protected $cache = array(); + protected $backgroundsPrefix = 'p'; + protected $svg = true; + protected $config = array(); + protected $assets = ''; + protected $phonegap = false; + protected $phonegapVersion; + protected $standalone = false; + protected $hiddenContents = array(); + protected $appcache; + protected $home; + protected $widget = true; + protected $multiApp = false; + protected $pageLabels = array(); + + + function __construct($book_id, $version = 'stable', $phonegap = false, $phonegapVersion = 'latest', $dir = null, $standalone = false, $appcache = false, $home = false) { + global $core; + + $this->phonegapVersion = wsHTML5::getPhonegapVersion($phonegapVersion); + $this->appcache = $appcache; + $this->multiApp = $this->home = $home; + $this->version = $version; + + if ($version == 'stable') { + $this->assets = WS_COMPILE_ASSETS . '/player/branches/master'; + } else if ($version == 'dev') { + $this->assets = WS_COMPILE_ASSETS . '/player/local/master'; + } else { + list($branch, $location) = explode('|', $version); + $this->assets = WS_COMPILE_ASSETS . '/player/' . ($location == 'git' ? 'branches' : $location) . '/' . $branch; + } + + $this->phonegap = $phonegap; + $this->standalone = $standalone || $this->phonegap; + $this->appcache = $appcache; + $this->widget = !$this->phonegap; + + cubePHP::set_memory('4G'); + + if (trim($book_id) == '') { + return; + } + $this->book_id = $book_id; + + if (is_null($dir)) { + $this->dir = WS_BOOKS . '/html5/' . $book_id . '/'; + } else { + $this->dir = $dir; + } + $this->vdir = $this->dir; + $this->wdir = WS_BOOKS . '/working/' . $this->book_id . '/'; + + // Clean the folder + `rm -rf $this->vdir`; + if (!file_exists($this->dir)) { + mkdir($this->dir, 0777, true); + } + + $this->daoBook = new wsDAOBook($core->con); + $this->book = $this->daoBook->selectById($book_id); + $this->pages = $this->daoBook->getPagesOfBook($book_id); + + if ($this->book->parametres->mobileVersion == 'html5-images') { + $this->backgroundsPrefix = 't'; + $this->svg = false; + } + + $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->width = round($size[0], 3); + $this->height = round($size[1], 3); + + $imagesize = 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 = 0.75 / 2; + + $this->scale = 1; + if ($this->book->parametres->zoomMode == 1) { + $this->multiply = $this->pdf2htmlRatio * $this->scale * $this->cssOneScale; + } else { + $this->multiply = $this->pdf2htmlRatio * $this->scale * $this->cssScale; + } + $this->numerotation = explode(',', $this->book->numerotation); + + $this->config = cubeObject::merge($this->book->parametres->toStandardObject(), $this->theme->parametres->toStandardObject()); + } + + public function addPageLabel($page, $label) { + $this->pageLabels[$label] = $page; + } + + public function getResolutions() { + $res = self::$resolutions; + 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() { + $dirsToCreate = array('data/images', 'data/contents', 'data/background', 'data/thumbnails', 'data/style'); + if (in_array('flv', $this->getVideosFormats())) { + $dirsToCreate[] = 'swf'; + } + + foreach ($dirsToCreate as $dir) { + $d = $this->vdir . '/' . $dir; + if (!file_exists($d)) { + mkdir($d, 0777, true); + } + } + + // Copy style folder + $from = $this->assets . '/style'; + $to = $this->vdir; + `cp -p -r $from $to`; + + // Copy images folder + $from = $this->assets . '/images'; + `cp -p -r $from $to`; + + // Copy images folder + $from = $this->assets . '/video'; + `cp -p -r $from $to`; + + // Copy swf + if (file_exists($this->vdir . '/swf')) { + $this->copy($this->assets . '/swf/video.swf', $this->vdir . '/swf/video.swf'); + } + + $this->loadPlugins(); + $this->writeImages(); + $linksCSS = $this->writeLinks(); + $numCSS = $this->writeCSS($this->vdir . '/data/style/style_%d.css', $linksCSS); + $this->writeLangs(); + $this->writeIndex($numCSS); + $this->writeTexts(); + $this->writeExtras(); + $this->writeJs(); + if (!$this->widget) { + unlink($this->vdir . '/style/widget.css'); + } + $this->writeCache(); + } + + 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->copy($dir . '/plugin.js', $this->vdir . '/' . $f); + } + if (file_exists($dir . '/plugin.css')) { + $f = $d . '/plugin.css'; + $this->pluginCSS[] = $f; + $this->copy($dir . '/plugin.css', $this->vdir . '/' . $f); + } + } + + $this->config->plugins = $plugins; + + array_push($this->jsFiles, $main); + } + + protected function getVideosFormats($poster = true) { + if (!$this->phonegap) { + $res = array('ogv', 'webm', 'mp4', 'flv'); + } elseif ($this->phonegap == 'ios') { + $res = array('mp4'); + } else if ($this->phonegap == 'android') { + $res = array('webm', 'mp4'); + } + + if ($poster) { + $res[] = 'jpg'; + } + return $res; + } + + protected function writeCache() { + if (!$this->appcache) { + return; + } + + $cacheFile = $this->vdir . '/cache.appcache'; + + if (file_exists($cacheFile)) { + unlink($cacheFile); + } + + $dest = realpath($this->vdir); + $lines = array(); + + $network = array('NETWORK:', '*'); + + $lines[] = 'CACHE MANIFEST'; + $lines[] = '# ' . date('Y-m-d H:i:s'); + $lines[] = ''; + $lines[] = 'index.html'; + $lines[] = ''; + $lines[] = 'FALLBACK:'; + $lines[] = '/ index.html'; + $lines[] = 'index.html* index.html'; + $lines[] = ''; + $lines[] = 'CACHE:'; + + $iterator = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($dest), RecursiveIteratorIterator::SELF_FIRST); + + $exclude = array('index.html', 'indexu.html', 'widget.html', 'indext.html'); + + foreach ($iterator as $path) { + if (!$path->isFile()) { + continue; + } + + $p = str_replace($dest . '/', '', $path); + if (in_array($p, $exclude)) { + continue; + } + $lines[] = $p; + } + + $lines[] = ''; + $lines = array_merge($lines, $network); + + file_put_contents($cacheFile, implode("\n", $lines)); + } + + protected function writeIndex($numCSS) { + global $core; + + $html = file_get_contents($this->assets . '/_index.html'); + $uhtml = $html; + + $titre = $this->book->parametres->title; + + + $daoSignature = new wsDAOSignature($core->con); + $signature = $daoSignature->selectById($this->book->parametres->signature); + + $exportSignature = array('main' => $signature->main, + 'mainLink' => $signature->mainLink, + 'partner' => $signature->partner, + 'partnerLink' => $signature->partnerLink); + + $credits = ''; + if ($signature->partner != '') { + $credits = '' . $signature->partner . ' '; + } + $credits .= '' . $signature->main . ''; + + $hiddenContents = implode("\n", $this->hiddenContents); + + $bgcolor = $this->theme->parametres->loadingBackColor; + + // Google analytics + $ga = ''; + if ($this->book->parametres->googleAnalytics != '') { + $ga = cubePage::googleAnalytics($this->book->parametres->googleAnalytics); + } + if ($this->book->parametres->googleAnalyticsCustom != '') { + $ga .= $this->book->parametres->googleAnalyticsCustom; + } + // Feuilles de style + $sheets = array('style/fluidbook.css'); + for ($i = 0; $i < $numCSS; $i++) { + $sheets[] = 'data/style/style_' . $i . '.css'; + } + $sheets = array_merge($sheets, $this->pluginCSS, $this->specialCSS); + + $style = array(); + foreach ($sheets as $sheet) { + $style[] = ''; + } + $style = implode("\n\t\t", $style); + + $pagesContents = ''; + + $cache = ''; + if ($this->appcache) { + $cache = ' manifest="cache.appcache"'; + } + + $iscript = ''; + if (count($this->htmlmultimedia)) { + $iscript .= '' . "\n"; + } + + $script = ''; + $script .= '' . "\n"; + $script .= '' . "\n"; + if ($this->book->parametres->scorm_enable) { + $script .= '' . "\n"; + $this->writeScorm(); + } + if (count($this->specialJsFiles)) { + $script .= '' . "\n"; + } + foreach ($this->pluginJs as $p) { + $script .= '' . "\n"; + } + $script .= $iscript; + $description = ''; + + + $favicon = ''; + if ($this->theme->parametres->favicon != '') { + copy($this->themeRoot . '/' . $this->theme->parametres->favicon, $this->vdir . '/data/favicon.png'); + $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) { + $dim = getimagesize($this->themeRoot . '/' . $this->theme->parametres->logoLoader); + if ($dim !== false) { + $this->copy($this->themeRoot . '/' . $this->theme->parametres->logoLoader, $this->vdir . '/data/images/' . $this->theme->parametres->logoLoader); + $splash .= ''; + } + } + + $svgfiles = array($this->assets . '/images/interface.svg'); + $svg = ''; + foreach ($svgfiles as $svgfile) { + if (file_exists($svgfile)) { + $svg .= file_get_contents($svgfile); + } + } + + + $vars = array('titre', 'credits', 'ga', 'style', 'script', 'pagesContents', 'description', 'print', 'hiddenContents', 'splash', 'cache', 'bgcolor', 'message', 'favicon', 'svg'); + foreach ($vars as $v) { + $html = str_replace('', $$v, $html); + } + + $scripts = array(); + foreach ($this->debugJsFiles as $js) { + $scripts[] = ''; + } + foreach ($this->jsFiles as $js) { + $scripts[] = ''; + } + foreach ($this->pluginJs as $js) { + $scripts[] = ''; + } + + $scripts[] = ''; + $scripts[] = $iscript; + $script = implode("\n\t\t", $scripts); + + $scripts = array(); + foreach ($this->testJsFiles as $js) { + $scripts[] = ''; + } + $scripts[] = ''; + $script_test = implode("\n\t\t", $scripts); + + $thtml = $uhtml; + + $vars = array('titre', 'credits', 'ga', 'style', 'script', 'pagesContents', 'print', 'hiddenContents', 'splash', 'cache', 'bgcolor', 'message', 'favicon'); + foreach ($vars as $v) { + $uhtml = str_replace('', $$v, $uhtml); + } + + $script .= "\n\t\t" . ''; + $vars = array('titre', 'credits', 'ga', 'style', 'script', 'print', 'hiddenContents', 'splash', 'message'); + foreach ($vars as $v) { + $thtml = str_replace('', $$v, $thtml); + } + + file_put_contents($this->vdir . '/index.html', $html); + file_put_contents($this->vdir . '/indexu.html', $uhtml); + file_put_contents($this->vdir . '/indext.html', $uhtml); + + // Write widget html + if ($this->widget) { + $whtml = file_get_contents($this->assets . '/widget.html'); + $script = ''; + $script .= ''; + + $style = ''; + $vars = array('titre', 'style', 'script'); + foreach ($vars as $v) { + $whtml = str_replace('', $$v, $whtml); + } + file_put_contents($this->vdir . '/widget.html', $whtml); + } + } + + protected function writeScorm() { + $manifest = file_get_contents($this->assets . '/_imsmanifest.xml'); + if (!$this->book->parametres->scorm_title) { + $this->book->parametres->scorm_title = $this->book->parametres->title; + } + if (!$this->book->parametres->scorm_id) { + $this->book->parametres->scorm_id = 'fb_' . $this->book->parametres->id; + } + if (!$this->book->parametres->scorm_org) { + $this->book->parametres->scorm_org = 'Fluidbook'; + } + $vars = array('scorm_id', 'scorm_org', 'scorm_title'); + foreach ($vars as $v) { + $manifest = str_replace('$' . $v, $this->book->parametres->$v, $manifest); + } + file_put_contents($this->vdir . '/imsmanifest.xml', $manifest); + } + + protected function writePrint() { + + if (!$this->book->parametres->print && !$this->book->parametres->pdf) { + return; + } + + $this->copy(WS_BOOKS . '/final/' . $this->book->book_id . '/data/' . $this->book->parametres->pdfName, $this->vdir . '/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 = getimagesize($file); + if ($dim !== false) { + $infos['width'] = $dim[0]; + $infos['height'] = $dim[1]; + } + $this->config->filesInfos[$key] = $infos; + } + + protected function __($str) { + if (!isset($this->config->l10n)) { + $this->writeLangs(); + } + + if (isset($this->config->l10n['default']->$str)) { + return $this->config->l10n['default']->$str; + } else { + return $str; + } + } + + protected function writeLangs() { + global $core; + $daoLang = new wsDAOLang($core->con); + $lang = $daoLang->selectById($this->book->lang); + $langs = $daoLang->selectAll(); + + $traductions = (!count($this->book->traductions)) ? $lang->traductions : $this->book->traductions; + + $this->config->l10n = array(); + $this->config->l10n['default'] = $traductions; + $this->config->defaultLang = $this->book->lang; + + foreach ($langs as $lang) { + $this->config->l10n[$lang->lang_id] = $lang->traductions; + } + $iso = l10n::getISOcodes(); + if ($this->book->parametres->multilang != '') { + $flagsDir = $this->vdir . '/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->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->copy($this->themeRoot . '/' . $this->theme->parametres->afterSearch, $this->vdir . '/data/images/' . $this->theme->parametres->afterSearch); + } + if ($this->book->parametres->externalArchives != '') { + $this->addFilesInfos('archives', $this->wdir . '/' . $this->book->parametres->externalArchives); + $this->copy($this->wdir . '/' . $this->book->parametres->externalArchives, $this->vdir . '/data/images/' . $this->book->parametres->externalArchives); + } + } + + protected function writeLinks() { + global $core; + + if ($this->book->parametres->customLinkClass == 'WescoSalesLink') { + $this->specialJsFiles[] = 'js/libs/fluidbook/special/wescosales.js'; + $this->specialCSS[] = 'style/special/wescosales.css'; + } + + if ($this->book->parametres->customLinkClass == 'AtlanticDownloadLink') { + $this->specialJsFiles[] = 'js/libs/fluidbook/special/atlanticdownload.js'; + $this->specialCSS[] = 'style/special/atlanticdownload.css'; + } + + $this->config->links = array(); + $this->config->clinks = array(); + $this->config->bookmarkGroups = array(); + + $ignore = $this->book->parametres->ignoreLinksTypes; + if (!$ignore) { + $ignore = array(); + } else { + $ignore = split(',', $ignore); + } + + $daoDoc = new wsDAODocument($core->con); + $daoDoc->getLinksAndRulers($this->book_id, $links, $rulers); + + foreach ($links as $linkData) { + if (isset($linkData['image']) && $linkData['image']) { + $dupData = $linkData; + $dupData['image'] = ''; + $dupData['to'] = $linkData['image']; + $dupData['type'] = 15; + array_push($links, $dupData); + } + } + + $i = 0; + $pages = array(); + $cpages = array(); + $css = array(); + + usort($links, array($this, '_sortLinks')); + + foreach ($links as $linkData) { + if (in_array($linkData['type'], $ignore)) { + continue; + } + $link = wsHTML5Link::getInstance($this->base62($i), $linkData, $this); + if (is_null($link)) { + continue; + } + + $c = $link->getHTMLContainer(); + $css[] = $link->getCSSContainer(); + if (!isset($pages[$link->page])) { + $pages[$link->page] = ''; + $cpages[$link->page] = ''; + } + if ($link instanceof contentLink) { + $cpages[$link->page] .= $c; + } else { + $pages[$link->page] .= $c; + } + + if ($link->keep()) { + $this->hiddenContents[] = $c; + } + $i++; + } + + $allpages = range(0, $this->book->parametres->pages + 1); + if ($this->book->parametres->themeEnableAfterSearch) { + $allpages[] = 'aftersearch'; + } + $allpages[] = 'background'; + $allpages[] = 'archives'; + + foreach ($allpages as $i) { + + $c = ''; + $cc = ''; + if (isset($pages[$i])) { + $c = $pages[$i]; + } + if (isset($cpages[$i])) { + $cc = $cpages[$i]; + } + $this->config->links[$i] = $c; + $this->config->clinks[$i] = $cc; + } + return $css; + } + + public function _sortLinks($a, $b) { + $priorities = array(26 => 1); + + $pa = isset($priorities[$a['type']]) ? $priorities[$a['type']] : 0; + $pb = isset($priorities[$b['type']]) ? $priorities[$b['type']] : 0; + return $pb - $pa; + } + + public function addBookmarkGroup($link) { + if ($link['left'] > $this->book->parametres->width) { + //$link['page']++; + } + if ($link['page'] <= 0 || $link['page'] > $this->book->parametres->pages) { + return; + } + + $this->config->bookmarkGroups[] = array('page' => ($link['page']), 'nb' => $link['to'], 'name' => $link['extra']); + } + + public function addAudiodescription($link) { + $this->config->audiodescription[$link['page']] = $link['to']; + $this->copyLinkFile($link['to'], 'data/audiodescription/'); + } + + protected function writeJs() { + $config = $this->writeConfig(); + file_put_contents($this->vdir . '/data/datas.js', $config); + $finals = array('fluidbook' => $this->jsFiles); + if ($this->book->parametres->scorm_enable) { + $finals['scorm'] = array(); + $finals['scorm'][] = 'js/libs/scorm/apiwrapper.js'; + $finals['scorm'][] = 'js/libs/scorm/scorm.js'; + } + if (count($this->specialJsFiles)) { + $finals['special'] = $this->specialJsFiles; + } + if ($this->widget) { + $finals['widget'] = $this->widgetJsFiles; + } + + foreach ($finals as $jsfinal => $files) { + $mintime = 0; + $minimized = $this->assets . '/js/' . $jsfinal . '-min.js'; + if (file_exists($minimized)) { + $mintime = filemtime($minimized); + } + + $reminimize = false; + if ($jsfinal == 'special') { + $reminimize = true; + } + if (!$reminimize) { + foreach ($files as $file) { + if (filemtime($this->assets . '/' . $file) > $mintime) { + $reminimize = true; + break; + } + } + } + + if (!$reminimize) { + if (filemtime(__FILE__) > $mintime || filemtime(__DIR__ . '/class.ws.html5.links.php') > $mintime) { + $reminimize = true; + } + } + + if ($reminimize) { + $js = ''; + foreach ($files as $file) { + $js .= file_get_contents($this->assets . '/' . $file); + $js .= ";\n\n"; + } + $tmp = cubeFiles::tempnam(); + file_put_contents($tmp, $js); + + $uglify = new CubeIT_CommandLine('uglifyjs'); + $uglify->setPath(CONVERTER_PATH); + $uglify->setArg('o', $minimized); + $uglify->setArg('no-copyright'); + $uglify->setArg(null, $tmp); + $uglify->execute(); + //$uglify->debug(); + } + $dest = $this->vdir . '/data/' . $jsfinal . '.js'; + copy($minimized, $dest); + } + + + if ($this->phonegap) { + $this->copy(WS_COMPILE_ASSETS . '/_html5/js/libs/phonegap/' . $this->phonegapVersion . '/cordova-' . $this->phonegap . '.js', $this->vdir . '/data/cordova.js'); + } + + } + + public function writeTexts() { + $this->daoBook->makeTextsIndexes($this->book, $this->pages, $index, $textes, true); + $jsindex = 'var INDEX=' . $index . ';' . "\r"; + $jstexts = 'var TEXTS=' . $textes . ';' . "\r"; + + file_put_contents($this->vdir . '/data/search.index.js', $jsindex); + file_put_contents($this->vdir . '/data/search.texts.js', $jstexts); + } + + public function supportSVG() { + if (!$this->phonegap) { + return false; + } else if ($this->phonegap == 'ios') { + return true; + } else { + return false; + } + } + + protected function writeConfig() { + $this->config->numerotation = explode(',', $this->book->numerotation); + $this->config->id = $this->book->book_id; + $this->config->cid = $this->book->cid; + $this->config->cacheDate = TIME; + $this->config->width = $this->cssWidth; + $this->config->height = $this->cssHeight; + $this->config->optimalWidth = $this->optimalWidth; + $this->config->optimalHeight = $this->optimalHeight; + $this->config->chapters = $this->book->chapters; + $this->config->coquilletteBack = wsHTML5::colorToCSS($this->theme->parametres->couleurA); + $this->config->coquilletteFront = wsHTML5::colorToCSS($this->theme->parametres->arrowsColor); + $this->config->videoFormats = $this->getVideosFormats(false); + $this->config->htmlmultimedia = $this->htmlmultimedia; + $this->config->phonegap = $this->phonegap; + $this->config->retinaResolution = $this->maxRes; + $this->config->pageLabels = $this->pageLabels; + $this->config->pageZoomFactor = $this->z; + 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; + } + $o = trim($this->config->navOrderH) != '' ? $this->config->navOrderH : $this->config->navOrder; + $navOrder = array(); + $oo = explode(',', $o); + foreach ($oo as $ooo) { + $ooo = trim($ooo); + if ($ooo == '') { + continue; + } + $navOrder[] = $ooo; + } + $this->config->navOrder = $navOrder; + + $this->config->standalone = $this->standalone; + if ($this->config->phonegap) { + $this->config->manifest = $this->writeManifest(); + } + + if ($this->config->basket) { + if (file_exists($this->config->basketReferences) || CubeIT_Util_Url::isDistant($this->config->basketReferences)) { + $referencesFile = $this->config->basketReferences; + } else { + $referencesFile = $this->wdir . '/commerce/' . $this->config->basketReferences; + } + + if (file_exists($referencesFile) || CubeIT_Util_Url::isDistant($referencesFile)) { + $ext = CubeIT_Files::getExtension($referencesFile); + if ($ext == 'xlsx') { + $this->config->basketReferences = wsUtil::excelToArray($referencesFile); + } + } + } + + return 'var DATAS=' . json_encode($this->config) . ';' . "\n"; + } + + protected function writeManifest() { + $res = array(); + } + + protected function writeIcons() { + $res = array(); + // Get the colors used to colorize graphics + if ($this->theme->parametres->colorizeIcons) { + $couleurI = $this->theme->parametres->couleurI; + } else { + $couleurI = 'FFFFFF'; + } + + $couleurM = $this->theme->parametres->subTextColor; + + $bookmarksDisabledColors = array('star' => $this->theme->parametres->bookmarkStarDisabledColor, 'bookmark' => $this->theme->parametres->bookmarkBackgroundColor); + $bookmarksEnabledColors = array('star' => $this->theme->parametres->bookmarkStarEnabledColor, 'bookmark' => $this->theme->parametres->bookmarkBackgroundColor); + $subTextColor = $this->theme->parametres->subTextColor; + + $arrowsColor = $this->theme->parametres->arrowsColor; + // Set the icon list with the color + $icons = array('nav-bookmark' => $couleurI, 'nav-friend' => $couleurI, 'nav-help' => $couleurI, 'nav-index' => $couleurI, 'nav-sommaire' => $couleurI, + 'nav-zoomin' => $couleurI, 'nav-zoomout' => $couleurI, 'nav-fullscreen' => $couleurI, + 'interface-next' => $arrowsColor, 'interface-previous' => $arrowsColor, + 'interface-sharp-next' => $arrowsColor, 'interface-sharp-previous' => $arrowsColor, + 'interface-search' => $couleurI, 'interface-back-arrow' => $subTextColor, 'interface-print' => $subTextColor, + 'interface-down' => $arrowsColor, 'interface-close' => $arrowsColor, + 'interface-audio-description-on' => $arrowsColor, 'interface-audio-description-off' => $arrowsColor, + 'help-fingers' => $couleurI, 'help-mouse' => $couleurI, 'nav-home' => $couleurI, 'nav-archives' => $couleurI, 'nav-map' => $couleurI, + 'nav-tag' => $couleurI, 'nav-print' => $couleurI, 'nav-friend' => $couleurI, + 'share-facebook' => $couleurM, 'share-twitter' => $couleurM, 'share-email' => $couleurM, 'share-googleplus' => $couleurM, 'share-linkedin' => $couleurM, 'share-viadeo' => $couleurM, + 'bookmark-left-off' => $bookmarksDisabledColors, 'bookmark-left-on' => $bookmarksEnabledColors, + 'bookmark-right-off' => $bookmarksDisabledColors, 'bookmark-right-on' => $bookmarksEnabledColors + ); + + $this->config->iconsDimensions = array(); + $makepng = !$this->supportSVG(); + foreach ($icons as $icon => $color) { + wsTools::colorizeAndRasterizeIcon($this->theme->parametres->iconSet, $icon, $color, $this->vdir . '/data/images/', 4, $w, $h); + $this->config->iconsDimensions[$icon] = array($w, $h); + } + return $res; + } + + protected function writeImages() { + foreach ($this->getResolutions() as $r) { + mkdir($this->vdir . '/data/background/' . $r, 0777, true); + } + $srcPrefix = $this->backgroundsPrefix; + if ($this->backgroundsPrefix == 'p') { + $srcPrefix = 'h'; + } + foreach ($this->pages as $page => $infos) { + if ($this->svg) { + $orig = wsDocument::getDir($infos['document_id']) . 'html/p' . $infos['document_page'] . '.svg'; + $opt = wsDocument::getDir($infos['document_id']) . 'html/o' . $infos['document_page'] . '.svg'; + + $svg = $orig; + if (file_exists($opt) && filesize($opt) > 0) { + $svg = $opt; + } + + $this->copy($svg, $this->vdir . '/data/contents/p' . $page . '.svg'); + } + + foreach ($this->getResolutions() as $r) { + $ok = $this->copy(wsDocument::getDir($infos['document_id']) . 'html/' . $srcPrefix . $r . '-' . $infos['document_page'] . '.jpg', $this->vdir . '/data/background/' . $r . '/' . $this->backgroundsPrefix . $page . '.jpg'); + if (!$ok && $r = 300) { + $this->maxRes = 150; + } + } + + $thumb = false; + if ($this->book->parametres->pdfThumbnails) { + $thumb = wsPDFConvert::getThumbFromPDF(WS_BOOKS . '/working/' . $this->book->book_id . '/' . $this->book->parametres->pdfThumbnails, $page); + } + if (!$thumb) { + $thumb = wsDocument::getDir($infos['document_id']) . 'p' . $infos['document_page'] . '.jpg'; + } + + + $this->copy($thumb, $this->vdir . '/data/thumbnails/p' . $page . '.jpg'); + + if ($page == 1) { + $this->_makeCover(wsDocument::getDir($infos['document_id']) . 'html/t36-' . $infos['document_page'] . '.jpg'); + } + } + } + + protected function _makeCover($orig) { + $size = getimagesize($orig); + $w = $size[0]; + $h = $size[1]; + + //$tmp = cubeFiles::tempnam() . '.png'; + $tmp = $this->vdir . '/covers.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(); + + $convert = new cubeCommandLine('composite'); + $cmd = '-compose Multiply '; + $cmd .= $tmp . ' ' . $orig . ' '; + $cmd .= $this->vdir . '/cover.jpg'; + $convert->setManualArg($cmd); + $convert->execute(); + + unlink($tmp); + } + + protected function copy($s, $t) { + if (!file_exists($s)) { + fb($s . ' dont exists'); + return false; + } + if (file_exists($t) && filemtime($t) >= filemtime($s) && filesize($s) == filesize($t)) { + return true; + } + if (!file_exists(dirname($t))) { + mkdir(dirname($t), 0777, true); + } + + $res = copy($s, $t); + touch($t, filemtime($s)); + return true; + } + + protected function writeCSS($file, $links) { + $res = array(); + + // 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'; + + + $res[] = '.portrait #pages,.portrait .doublePage.page,.page,.doublePage._3d,#shadow>div{width:' . $w . ';max-width:' . $w . ';height:' . $h . ';max-height:' . $h . '}'; + $res[] = '.doublePage,#pages,#links{width:' . $w2 . ';max-width:' . $w2 . ';height:' . $h . ';max-height:' . $h . '}'; + $res[] = '.landscape .doublePage._2d.axis_x.next{' . wsHTML5::writeCSSUA('transform', 'translate3d(' . $w2 . ',0,0)') . '}'; + $res[] = '.landscape .doublePage._2d.axis_x.prev{' . wsHTML5::writeCSSUA('transform', 'translate3d(-' . $w2 . ',0,0)') . '}'; + $res[] = '.portrait .doublePage._2d.axis_x.next{' . wsHTML5::writeCSSUA('transform', 'translate3d(' . $w . ',0,0)') . '}'; + $res[] = '.portrait .doublePage._2d.axis_x.prev{' . wsHTML5::writeCSSUA('transform', 'translate3d(-' . $w . ',0,0)') . '}'; + $res[] = '.doublePage._2d.axis_y.next{' . wsHTML5::writeCSSUA('transform', 'translate3d(0,' . $h . ',0)') . '}'; + $res[] = '.doublePage._2d.axis_y.prev{' . wsHTML5::writeCSSUA('transform', 'translate3d(0,-' . $h . ',0)') . '}'; + + $res[] = '.doublePage._3d{left:' . $w . ';}'; + $res[] = '#links.right{left:-' . $w . ';}'; + $res[] = '.landscape #shadow>div.right{left: ' . $w . ';}'; + $res[] = '.landscape .page.right{left:' . $w . '}'; + if ($this->theme->parametres->displayPageNumber) { + $res[] = '#pagesnumbers{font-size: ' . (12 * $this->z) . 'px;margin: ' . (5 * $this->z) . 'px 0 0 0;top:' . $h . ';color:' . wsHTML5::colorToCSS($this->theme->parametres->colorPageNumber) . '}'; + $res[] = '#pagesnumbers div{width:' . $w . '}'; + } else { + $res[] = '#pagesnumbers{display:none;}'; + } + $res[] = '.doublePage._2d,.doublePage._3d{' . wsHTML5::writeCSSUA('transition', 'all ' . $this->book->parametres->mobileTransitionDuration . 's ease-in-out') . '}'; + + $res[] = '.background{' . wsHTML5::writeCSSUA('transform-origin', 'top left') . ';}'; + foreach ($this->getResolutions() as $r) { + $ratio = round(72 / $r, 3) * $cssScale; + + $wr = $cssWidth / $ratio; + $hr = $cssHeight / $ratio; + + $br = '.background.r' . $r . '{'; + if ($ratio != 1) { + $br .= wsHTML5::writeCSSUA('transform', 'scale(' . $ratio . ')') . ';'; + } + $br .= 'width:' . $wr . 'px;height:' . $hr . 'px;}'; + $res[] = $br; + } + $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) . '; max-width:' . ($wm / $this->cssSVGScale) . ';'; + $texts .= 'height:' . ($hm / $this->cssSVGScale) . '; max-height:' . ($hm / $this->cssSVGScale) . ';'; + $texts .= '}'; + $res[] = $texts; + + // Theme + $shade = '.page .shade{'; + $shade .= 'opacity:' . ($this->theme->parametres->shadeAlpha / 100) . ';'; + $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) . ';}'; + + // Search field + $searchColor = wsHTML5::colorToCSS($this->theme->parametres->couleurS); + $searchBackColor = wsHTML5::colorToCSS($this->theme->parametres->searchFieldColor); + $search = '#q{'; + $search .= 'color:' . $searchColor . ';'; + $search .= 'background-color:' . $searchBackColor . ';'; + if ($this->theme->parametres->searchShadeAlpha > 0) { + $search .= wsHTML5::writeCSSUA('box-shadow', '1px 1px 4px rgba(0,0,0,' . ($this->theme->parametres->searchShadeAlpha / 100) . ')') . ' inset;'; + } + $search .= '}'; + $search .= '#searchHints,.hint{color:' . $searchColor . ';background-color:' . $searchBackColor . ';}'; + $search .= '.hint:hover{color:' . $searchBackColor . ';background-color:' . $searchColor . ';}'; + + $res[] = $search; + + // Background + $res[] = $this->_cssBackground(); + + // Archives + // Header + $header = 'header{'; + $header .= 'height:' . $this->theme->parametres->menuHeight . 'px;'; + $header .= 'background-color:' . wsHTML5::colorToCSS($this->theme->parametres->menuColor) . ';'; + if ($this->theme->parametres->menuImage != '') { + $this->copy($this->themeRoot . '/' . $this->theme->parametres->menuImage, $this->vdir . '/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;'; + } + $header .= '}'; + $res[] = $header; + + //Icons + $res = array_merge($res, $this->writeIcons()); + $res[] = '#nav #locales{background-color:' . wsHTML5::colorToCSS($this->theme->parametres->couleurI) . ';}'; + + // Logo + $logo = '#logo{'; + if ($this->theme->parametres->logo) { + $this->copy($this->themeRoot . '/' . $this->theme->parametres->logo, $this->vdir . '/data/images/' . $this->theme->parametres->logo); + $dim = getimagesize($this->vdir . '/data/images/' . $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 + $res[] = '#next,#previous{background-color:' . wsHTML5::colorToCSS($this->theme->parametres->couleurA) . ';}'; + + // Audio description buttons + $res[] = '.audio-description-button{background-color:' . wsHTML5::colorToCSS($this->theme->parametres->couleurA) . ';}'; + + // Book shadow + $shadowColor = wsHTML5::colorToCSS($this->theme->parametres->bookShadeColor); + if ($shadowColor != 'transparent') { + $res[] = '#shadow>div{' . wsHTML5::writeCSSUA('box-shadow', '0 0 20px ' . $shadowColor) . '}'; + } + + // Links Styles + $res = array_merge($res, $links); + $res[] = '.link a.displayArea:hover,.link a.displayArea.animating{background-color:' . wsHTML5::colorToCSS($this->theme->parametres->linksColor, 0.4) . ';}'; + $res[] = '.link a.displayArea:hover{opacity:1 !important;}'; + $res[] = '.link a.displayArea{-webkit-tap-highlight-color:' . wsHTML5::colorToCSS($this->theme->parametres->linksColor, 0.4) . ';background-color:' . wsHTML5::colorToCSS($this->theme->parametres->linksColor, 0.0001) . ';}'; + + // Bookmarks + if (!isset($this->book->parametres->bookmarkCornerSize)) { + $this->book->parametres->bookmarkCornerSize = 10; + } + $size = round($this->width * $this->book->parametres->bookmarkCornerSize * 0.0075 * $this->z); + $res[] = '#links .bookmark{width:' . $size . 'px;height:' . $size . 'px;background-size:' . $size . 'px ' . $size . 'px;}'; + $res[] = '.portrait #fluidbook .bookmark.left{left:' . ($cssWidth - $size) . 'px;}'; + + // Menus + $menuColor = new CubeIT_Graphics_Color($this->theme->parametres->couleurB); + $menuColor->setAlpha(1); + $menuTextColor = wsHTML5::colorToCSS($this->theme->parametres->subTextColor); + + $menuMultiply = $menuColor->multiply($menuColor); + $menuMultiply2 = $menuMultiply->multiply($menuColor); + + # View + $res[] = '.portrait .mview{width:' . $w . ';min-height:' . $h . '}'; + $res[] = '.landscape .mview{width:' . $w2 . ';min-height:' . $h . '}'; + $res[] = '.mview{background-color:' . $menuColor->toCSS() . ';color:' . $menuTextColor . ';}'; + + # Inner View + $res[] .= '#innerView>div{background-color:' . $menuColor->toCSS() . ';color:' . $menuTextColor . ';}'; + $res[] .= 'form input[type="text"],form input[type="email"]{background-color:' . wsHTML5::colorToCSS($this->theme->parametres->subFieldColor) . ';color:' . wsHTML5::colorToCSS($this->theme->parametres->subTextFieldColor) . ';}'; + + // Archives + if ($this->book->parametres->externalArchivesBack) { + $this->copy($this->wdir . '/' . $this->book->parametres->externalArchivesBack, $this->vdir . '/data/images/' . $this->book->parametres->externalArchivesBack); + $res[] = '.mview.archives{background-image:url("../images/' . $this->book->parametres->externalArchivesBack . '");}'; + } + + # Topbar + $top = $menuColor->toCSS(); + $bottom = $menuMultiply->toCSS(); + $border = $menuMultiply2->setAlpha(0.6)->toCSS(); + + $caption = ".mview .caption{ + background-image: -moz-linear-gradient(top, $top 0%, $bottom 100%); /* FF3.6+ */ + background-image: -webkit-linear-gradient(top, $top 0%,$bottom 100%); /* Chrome10+,Safari5.1+ */ + background-image: -o-linear-gradient(top, $top 0%,$bottom 100%); /* Opera 11.10+ */ + background-image: -ms-linear-gradient(top, $top 0%,$bottom 100%); /* IE10+ */ + background-image: linear-gradient(top bottom, $top 0%,$bottom 100%); /* W3C */ +}"; + + $caption .= ".mview .caption a{ + border:1px solid $border; +}"; + $res[] = $caption; + + # Chapters (menu lists) + $top = $menuColor->setAlpha(0.5)->toCSS(); + $bottom = $menuMultiply->setAlpha(0.5)->toCSS(); + $border = $menuMultiply2->setAlpha(0.5)->toCSS(); + + $chapters = "ul.chapters a.level-1,ul.chapters a.level0,ul.chapters a.level1,ul.chapters a.level2,ul.chapters a.level3{ + background-image: -moz-linear-gradient(top, $top 0%, $bottom 100%); /* FF3.6+ */ + background-image: -webkit-linear-gradient(top, $top 0%,$bottom 100%); /* Chrome10+,Safari5.1+ */ + background-image: -o-linear-gradient(top, $top 0%,rgba(0,0,0,0.5) 100%); /* Opera 11.10+ */ + background-image: -ms-linear-gradient(top, $top 0%,$bottom 100%); /* IE10+ */ + background-image: linear-gradient(top bottom, $top 0%,$bottom 100%); /* W3C */ + border-bottom:1px solid $border; +}"; + $res[] = $chapters; + # Index + $ratio = $this->width / $this->height; + $thumbh = round(100 / $ratio); + $res[] = '#indexView .thumb img{width:100px;height:' . $thumbh . 'px;}'; + $res[] = '#indexView .doubleThumb{height:' . $thumbh . 'px;' . wsHTML5::writeCSSUA('box-shadow', '0 0 3px ' . $shadowColor) . '}'; + $res[] = '#indexView .doubleThumb .overlay{height:' . $thumbh . 'px;}'; + $res[] = '#indexView .doubleThumb .hits.yes{background-color:' . wsHTML5::colorToCSS($this->theme->parametres->subSelectColor) . ';color:' . wsHTML5::colorToCSS($this->theme->parametres->subTextSelectColor) . '}'; + + # Tooltip + $res[] = '#tooltip{background-color:' . wsHTML5::colorToCSS($this->theme->parametres->tooltipBackColor) . ';color:' . wsHTML5::colorToCSS($this->theme->parametres->tooltipTextColor) . ';}'; + + # ZoomPopup close button background + $res[] = '.zoomPopupClose {background-color:' . wsHTML5::colorToCSS($this->theme->parametres->couleurB) . ';}'; + + $res = array_chunk($res, 3500); + foreach ($res as $k => $css) { + file_put_contents(sprintf($file, $k), implode("\n", $css)); + } + return count($res); + } + + protected function _cssBackground() { + $body = '#background,#splash{'; + $body .= 'background-color:#' . $this->theme->parametres->backgroundColor . ';'; + 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 = getimagesize($bi); + $this->config->backgroundImageDimensions = array('width' => $dbi[0], 'height' => $dbi[1]); + } + + $this->copy($this->themeRoot . '/' . $this->theme->parametres->backgroundImage, $this->vdir . '/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) { + `cp -a $source $this->vdir/$dest`; + } + + public function simpleCopyLinkFile($source, $dest, $addVdir = true) { + if ($addVdir) { + $dest = $this->vdir . '/' . $dest; + } + if (!file_exists(dirname($dest))) { + mkdir(dirname($dest), 0777, true); + } + if (file_exists($dest) && filemtime($dest) >= filemtime($source) && filesize($dest) == filesize($source)) { + return; + } + + $this->copy($source, $dest); + } + + public function copyLinkFile($source, $dest, $video = false) { + if ($video && $this->book->parametres->mobileVideosPath != '') { + + } + + $origDir = $this->wdir; + $types = $this->getVideosFormats(); + if ($video) { + wsTools::encodeWebVideos($origDir . $source, null, true); + $e = explode('.', $source); + array_pop($e); + $base = implode('.', $e); + $source = array(); + foreach ($types as $type) { + $source[] = $base . '.' . $type; + } + } + + if (!is_array($source)) { + $source = array($source); + } + + foreach ($source as $so) { + $s = $origDir . $so; + if (file_exists($s)) { + $d = $this->vdir . '/' . $dest . '/' . $so; + $this->simpleCopyLinkFile($s, $d, false); + } + } + } + + public function __destruct() { + + } + +} \ No newline at end of file diff --git a/inc/ws/Util/html5/master/class.ws.html5.links.php b/inc/ws/Util/html5/master/class.ws.html5.links.php new file mode 100644 index 000000000..67692fa83 --- /dev/null +++ b/inc/ws/Util/html5/master/class.ws.html5.links.php @@ -0,0 +1,1151 @@ +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); + } + 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: + if ($init['to'] == 'fullScreen') { + return null; + } + return new actionLink($id, $init, $compiler); + case 12: + + return new basketLink($id, $init, $compiler); + case 13: // zoom area + return new zoomLink($id, $init, $compiler); + case 14: + return new colorLink($id, $init, $compiler); + case 15: + 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: + return new tooltipLink($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; + default: + return null; + } + } + + 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 function __construct($id, $init, &$compiler) { + $this->_init = $init; + foreach ($init as $k => $v) { + if ($k == 'extra' && CubeIT_Util_Json::isJson($v)) { + $v = CubeIT_Util_Json::decode($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; + } + + 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 '
' . $this->getHTMLContent() . '
'; + } + + public function getHTMLContainerClass() { + $res = 'link'; + if ($this->page % 2 == 1) { + $res .= ' odd'; + } + return $res; + } + + public function getHTMLContent() { + return ''; + } + + public function getAdditionnalContent() { + + } + + public function getClasses() { + return array(); + } + + public function copyExternalFile($file, $video = false) { + $this->compiler->copyLinkFile($file, 'data/links/', $video); + } + + public function copyExternalDir($dir) { + $this->compiler->copyLinkDir($dir, 'data/links'); + } + + public function unzipFile($file, $moveAssets = false) { + $fdir = 'data/links/' . $file; + $dir = $this->compiler->vdir . '/' . $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->compiler->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 getCssScale() { + if (is_int($this->page)) { + return $this->compiler->getCssScale(); + } else { + return 1; + } + } + + public function getCSSContainer() { + if (!($this instanceof contentLink) && $this->page % 2 == 1) { + $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;'; + $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'])) { + 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'; + } + $c = ''; + if (count($class)) { + $c = ' class="' . implode(' ', $class) . '"'; + } + $tooltip = ''; + $t = $this->getTooltip(); + if ($t !== false) { + $tooltip = ' data-tooltip="' . $t . '"'; + } + return 'getAdditionnalContent() . $this->getTrack() . '>'; + } + + public function getTrack() { + return ''; + } + + public function getURL() { + return '#'; + } + + public function getTarget() { + return '_self'; + } + +} + +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 htmlMultimediaImage extends wsHTML5Link { + + public function getHTMLContainerClass() { + return parent::getHTMLContainerClass() . ' multimedia'; + } + + public function getHTMLContent() { + $w = $this->width * $this->getCssScale(); + $h = $this->height * $this->getCssScale(); + $this->copyExternalFile($this->alternative); + $alt = ''; + return $alt; + } + +} + +class htmlMultimediaPopupLink extends htmlMultimediaPopupImage { + + public function getAdditionnalContent() { + $i = $this->_init; + $i['inline'] = true; + $i['width'] = $i['video_width']; + $i['height'] = $i['video_height']; + + $l = wsHTML5Link::getMultimediaInstance($this->id . '_content', $i, $this->compiler); + $markup = $l->getHTMLContainer(); + return ' data-multimedia="' . rawurlencode($markup) . '" '; + } +} + + +class htmlMultimediaPopupImage extends normalLink { + + public function getURL() { + $this->copyExternalFile($this->alternative); + return '#/multimedia/' . md5($this->alternative); + } + + public function getAdditionnalContent() { + $dim = getimagesize($this->wdir . '/' . $this->alternative); + $markup = '
'; + return ' data-multimedia="' . rawurlencode($markup) . '" '; + } + + public function keep() { + return true; + } + +} + +class contentLink extends wsHTML5Link { + + public function getHTMLContainerClass() { + return parent::getHTMLContainerClass() . ' contentLink'; + } + +} + +class eventOverlayLink extends wsHTML5Link { + 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 function getHTMLContent() { + $this->copyExternalFile($this->to, true); + + $w = round($this->width * $this->getCssScale()); + $h = round($this->height * $this->getCssScale()); + + return self::makeVideoTag($this, $w, $h, $this->compiler); + } + + public static function makeVideoTag($linkDatas, $w = null, $h = null, $compiler = null) { + $file = $linkDatas->to; + $e = explode('.', $file); + $ext = array_pop($e); + $basename = implode('.', $e); + + $autoplay = ($linkDatas->video_auto_start ? '1' : '0'); + $controls = ($linkDatas->video_controls ? '1' : '0'); + $loop = ($linkDatas->video_loop ? '1' : '0'); + $sound = ($linkDatas->video_sound_on ? '1' : '0'); + + $res = '
book_id . '/' . $basename . '.jpg'; + $dim = getimagesize($path); + $res .= 'data-width="' . $dim[0] . '" data-height="' . $dim[1] . '" '; + } + $res .= ' data-autoplay="' . $autoplay . '"'; + $res .= ' data-controls="' . $controls . '"'; + $res .= ' data-loop="' . $loop . '"'; + $res .= ' data-sound="' . $sound . '"'; + $res .= ' data-name="' . $basename . '"'; + $res .= '>
'; + return $res; + } + +} + +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() { + return ' data-video="' . rawurlencode(videoLink::makeVideoTag($this, $this->video_width, $this->video_height, $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 function getHTMLContent() { + return $this->getEmbed(); + } + + 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 = ''; + } 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() { + if (in_array($this->to, $this->_share)) { + return '#'; + } + return '#/' . $this->to; + } + + public function getClasses() { + if (in_array($this->to, $this->_share)) { + return array_merge(array('share'), parent::getClasses()); + } else { + return parent::getClasses(); + } + } + + public function getAdditionnalContent() { + if (in_array($this->to, $this->_share)) { + return parent::getAdditionnalContent() . ' data-service="' . $this->to . '" '; + } else { + return parent::getClasses(); + } + } + + public function getDefaultTooltip() { + return false; + } + + +} + +class basketLink extends contentLink { + + public function getCSS() { + return 'background-color:#fff;'; + } + +} + +class colorLink extends contentLink { + + public function getCSS() { + return 'background-color:' . wsHTML5::colorToCSS($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;'; + } + +} + +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 htmlMultimediaLink extends wsHTML5Link { + + protected $_config = null; + protected $_content = ''; + protected $_url; + + 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']); + } elseif ($ext == 'zip') { + $d = $this->unzipFile($this->alternative, false); + $this->_config = $this->getConfigZIP($d['dir']); + $this->copyExternalDir($d['dir']); + } elseif ($ext == 'html') { + $fdir = 'data/links'; + $dir = $this->compiler->vdir . '/' . $fdir; + + $d = array('fdir' => $fdir, 'dir' => $dir); + if (!file_exists($d['dir'])) { + fb($d['dir']); + mkdir($d['dir'], 0777, true); + } + 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 = $externalIframe = $this->alternative; + $this->_config = array('html' => false, 'width' => $this->width * $this->getCssScale(), 'height' => $this->height * $this->getCssScale()); + } + + $w = $this->width * $this->getCssScale(); + $h = $this->height * $this->getCssScale(); + $res = ''; + 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']; + + $res = ''; + } + if (isset($externalIframe)) { + $iw = $this->_config['width']; + $ih = $this->_config['height']; + $res = ''; + } + + foreach ($this->_config['inject'] as $i) { + $i = str_replace('$id', '"#l_' . $this->id . '"', $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->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->getCSS(); + $css .= '}'; + 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) { + $res = array('width' => $this->video_width, 'height' => $this->video_height); + if (file_exists($d . '/index.html')) { + $doc = new DOMDocument(); + $doc->loadHTMLFile($d . '/index.html'); + $xpath = new DOMXPath($doc); + $c = $xpath->query("//canvas"); + foreach ($c as $canvas) { + /* @var $canvas DOMElement */ + $res['width'] = intval((string)$canvas->getAttribute('width')); + $res['height'] = intval((string)$canvas->getAttribute('height')); + } + + $r = array('html' => 'index.html', 'inject' => array(), 'injectcss' => array(), 'injectjs' => array()); + } else { + $r = array('html' => false, 'inject' => array(file_get_contents($d . '/init.js')), 'injectcss' => array('multimedia.css'), 'injectjs' => array('multimedia.js')); + } + $res = array_merge($res, $r); + return $res; + } + + 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; + } + +} + +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 getUrl() { + return '#'; + } + + public function getAdditionnalContent() { + 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="' . $t . '"'; + } + return 'getAdditionnalContent() . '>'; + } + + public function getCSSContainer() { + if (!($this instanceof contentLink) && $this->page % 2 == 1) { + $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;'; + 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 zoomLink extends normalLink { + + public function getDefaultTooltip() { + return 'zoom in'; + } + + public function __construct($id, $init, $compiler) { + parent::__construct($id, $init, $compiler); + } + + public function getAdditionnalContent() { + $res = parent::getAdditionnalContent(); + + // Data attributes + $attributes = [ + 'maxzoom' => $this->to, + ]; + + // Set data attributes + foreach ($attributes as $key => $val) { + $res .= ' data-' . $key . '="' . $val . '"'; + } + + $this->generateImage(); + + return $res; + } + + public function generateImage() { + $left = CubeIT_Files::tempnam(); + + $p = wsDAOBook::getDocumentPage($this->compiler->book_id, $this->page); + $pdfpath = wsDocument::getDir($p['document_id']) . 'original.pdf'; + + CubeIT_CommandLine_Poppler::extractArea($pdfpath, + $p['document_page'], + array('x' => $this->left, 'y' => $this->top, 'width' => $this->width, 'height' => $this->height), + $left, array(), WS_CACHE . '/zoomarea/'); + + $bookwidth = $this->compiler->book->parametres->width; + + if (($this->left + $this->width) > $bookwidth) { + $p = wsDAOBook::getDocumentPage($this->compiler->book_id, $this->page + 1); + $pdfpath = wsDocument::getDir($p['document_id']) . 'original.pdf'; + $diff = ($this->width + $this->left) - $bookwidth; + $right = CubeIT_Files::tempnam(); + CubeIT_CommandLine_Poppler::extractArea($pdfpath, + $p['document_page'], + array('x' => 0, 'y' => $this->top, 'width' => $diff, 'height' => $this->height), + $right, array(), WS_CACHE . '/zoomarea/'); + + $both = CubeIT_Files::tempnam() . '.png'; + CubeIT_CommandLine_Imagemagick::append(array($left . '.png', $right . '.png'), $both, 'horizontal'); + } else { + $both = $left . '.png'; + } + + $this->compiler->simpleCopyLinkFile($both, 'data/links/zoom_' . $this->id . '.png'); + } + + + public function getClasses() { + return array_merge(['zoomPopup'], parent::getClasses()); + } +} \ No newline at end of file diff --git a/inc/ws/Util/packager/class.ws.packager.phonegap.php b/inc/ws/Util/packager/class.ws.packager.phonegap.php index 65b8081c4..a6e345184 100644 --- a/inc/ws/Util/packager/class.ws.packager.phonegap.php +++ b/inc/ws/Util/packager/class.ws.packager.phonegap.php @@ -31,7 +31,7 @@ class wsPackagerPhonegap extends wsPackager { $vdir .= '/' . $os; } - $compiler = wsHTML5Compiler::factory($this->book_id, null, $os, 'latest', $vdir, false, !$this->ignoreCache, $this->home); + $compiler = wsHTML5::compilerFactory($this->book_id, null, $os, 'latest', $vdir, false, !$this->ignoreCache, $this->home); $compiler->compile(); unlink($vdir . '/indext.html');