From 4b27a53ad22052e96911812089a6b2e35448f74b Mon Sep 17 00:00:00 2001 From: "vincent@cubedesigners.com" Date: Mon, 19 Jun 2017 15:52:00 +0000 Subject: [PATCH] #1445 --- .../html5/master/class.ws.html5.compiler.php | 68 ++++++++++++++++--- .../html5/slider/class.ws.html5.compiler.php | 57 +++++++++++++--- .../html5/slider/class.ws.html5.links.php | 13 +++- 3 files changed, 115 insertions(+), 23 deletions(-) diff --git a/inc/ws/Util/html5/master/class.ws.html5.compiler.php b/inc/ws/Util/html5/master/class.ws.html5.compiler.php index 5b847872a..5dc694105 100644 --- a/inc/ws/Util/html5/master/class.ws.html5.compiler.php +++ b/inc/ws/Util/html5/master/class.ws.html5.compiler.php @@ -38,6 +38,7 @@ class wsHTML5Compiler { 'js/libs/fluidbook/fluidbook.desktop.js', 'js/libs/fluidbook/fluidbook.service.js', 'js/libs/fluidbook/fluidbook.l10n.js', + 'js/libs/fluidbook/fluidbook.slider.js', 'js/libs/fluidbook/fluidbook.nav.js', 'js/libs/fluidbook/fluidbook.touch.js', 'js/libs/fluidbook/fluidbook.interact.js', @@ -1094,6 +1095,7 @@ class wsHTML5Compiler { if ($this->backgroundsPrefix == 'p') { $srcPrefix = 'h'; } + $thumbs = array(); foreach ($this->pages as $page => $infos) { $docdir = wsDocument::getDir($infos['document_id']); if ($this->svg) { @@ -1123,17 +1125,53 @@ class wsHTML5Compiler { $thumb = $docdir . 'p' . $infos['document_page'] . '.jpg'; } - - $this->copy($thumb, $this->vdir . '/data/thumbnails/p' . $page . '.jpg'); + $thumbs[$page] = $thumb; if ($page == 1) { $this->_makeCover($docdir . 'html/t36-' . $infos['document_page'] . '.jpg'); } - + $this->makeThumbSprites($thumbs); $this->log('Copied image ' . $page); } } + public function makeThumbSprites(array $thumbs) { + $cols = 10; + $rows = 10; + $perSprite = $cols * $rows; + $k = 0; + $res = ''; + $pages = count($thumbs); + + $hash = ''; + for ($i = 1; $i <= $pages; $i += $perSprite) { + $num = min(1 + $pages - $i, $perSprite); + $srows = ceil($num / $cols); + $files = array(); + $mtime = 0; + for ($j = 0; $j < $perSprite; $j++) { + $p = $i + $j; + if ($p > $pages) { + break; + } + $files[] = $thumbs[$p]; + $hash .= $thumbs[$p] . '--' . filemtime($thumbs[$p]); + } + + $cache = WS_CACHE . '/thumbsprites/' . hash('sha256', $hash) . '.jpg'; + $dest = $this->vdir . '/data/thumbnails/s' . $k . '.jpg'; + if (!file_exists($cache)) { + $ratio = $this->width / $this->height; + $thumbh = round(100 / $ratio); + $cmd = 'montage ' . implode(' ', $files) . ' -geometry 100x' . $thumbh . '!+0+0 -background transparent -tile ' . $cols . 'x' . $srows . ' ' . $cache; + $res .= `$cmd`; + } + copy($cache, $dest); + $k++; + } + return $res; + } + protected function _makeCover($orig) { $size = getimagesize($orig); $w = $size[0]; @@ -1175,10 +1213,16 @@ class wsHTML5Compiler { return true; } + protected function _lessBoolean($val) { + return $val ? 'true' : 'false'; + } + protected function writeCSS($file, $links) { $res = array(); $lessVariables = array(); + $lessVariables['slider-display'] = $this->_lessBoolean($this->theme->parametres->pagesBar); + $lessVariables['slider-thumb-background'] = wsHTML5::colorToCSS($this->theme->parametres->pageBarThumbBack); // General theme $cssWidth = $this->cssWidth; @@ -1198,6 +1242,9 @@ class wsHTML5Compiler { $navTop = ($cssHeight - 40 - 100) / 2; $leftOfRightPage = (floor($cssWidth) - 1) . 'px'; + $lessVariables['z'] = $this->z; + $lessVariables['book-page-width'] = $w; + $lessVariables['book-page-height'] = $h; $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 . '}'; @@ -1212,12 +1259,10 @@ class wsHTML5Compiler { $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;}'; - } + + $lessVariables['page-number-color'] = wsHTML5::colorToCSS($this->theme->parametres->colorPageNumber); + $lessVariables['display-page-number'] = $this->_lessBoolean($this->theme->parametres->displayPageNumber); + $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') . ';}'; @@ -1351,6 +1396,7 @@ class wsHTML5Compiler { # Index $ratio = $this->width / $this->height; $thumbh = round(100 / $ratio); + $this->config->thumbHeight = $thumbh; $lessVariables['thumb-height'] = $thumbh . 'px'; # Tooltip @@ -1380,8 +1426,8 @@ class wsHTML5Compiler { $tmp = CubeIT_Files::tmpdir(); - copy($this->assets . '/style/variables.less', $tmp . '/variables.less'); - copy($this->assets . '/style/mixins.less', $tmp . '/mixins.less'); + $from = $this->assets . '/style/*'; + `cp -r $from $tmp`; $bookVariables = array(); foreach ($variables as $k => $v) { diff --git a/inc/ws/Util/html5/slider/class.ws.html5.compiler.php b/inc/ws/Util/html5/slider/class.ws.html5.compiler.php index 285db98a4..9dc60a5e5 100644 --- a/inc/ws/Util/html5/slider/class.ws.html5.compiler.php +++ b/inc/ws/Util/html5/slider/class.ws.html5.compiler.php @@ -158,6 +158,8 @@ class wsHTML5Compiler { protected $multiApp = false; protected $pageLabels = array(); protected $stylesheets = array(); + protected $logfp = null; + protected $logtime = null; function __construct($book_id, $version = 'stable', $phonegap = false, $phonegapVersion = 'latest', $dir = null, $standalone = false, $appcache = false, $home = false) { @@ -188,6 +190,7 @@ class wsHTML5Compiler { return; } $this->book_id = $book_id; + $this->log('Start compilation'); if (is_null($dir)) { $this->dir = WS_BOOKS . '/html5/' . $book_id . '/'; @@ -202,6 +205,7 @@ class wsHTML5Compiler { if (!file_exists($this->dir)) { mkdir($this->dir, 0777, true); } + $this->log('Clean vdir'); $this->daoBook = new wsDAOBook($core->con); $this->book = $this->daoBook->selectById($book_id); @@ -248,6 +252,20 @@ class wsHTML5Compiler { $this->config = cubeObject::merge($this->book->parametres->toStandardObject(), $this->theme->parametres->toStandardObject()); } + public function log($step) { + $currenttime = microtime(true); + if (null === $this->logfp) { + $this->logfp = fopen('/var/log/extranet/htmlconversions/' . $this->book_id . '.log', 'w+'); + } + if (null === $this->logtime) { + $this->logtime = $currenttime; + } + $time = $currenttime - $this->logtime; + $log = $step . ' | ' . round($time, 3) . 's' . "\n"; + fwrite($this->logfp, $log); + $this->logtime = $currenttime; + } + public function addPageLabel($page, $label) { $this->pageLabels[$label] = $page; } @@ -277,6 +295,8 @@ class wsHTML5Compiler { public function compile() { + $this->log('Start compile process'); + $dirsToCreate = array('data/images', 'data/contents', 'data/background', 'data/thumbnails', 'data/style'); if (in_array('flv', $this->getVideosFormats())) { $dirsToCreate[] = 'swf'; @@ -311,17 +331,27 @@ class wsHTML5Compiler { if (file_exists($this->vdir . '/swf')) { $this->copy($this->assets . '/swf/video.swf', $this->vdir . '/swf/video.swf'); } - + $this->log('Copied assets'); $this->loadPlugins(); + $this->log('Plugins loaded'); $this->writeImages(); + $this->log('Images written'); $linksCSS = $this->writeLinks(); + $this->log('Links written'); $this->writeCSS($this->vdir . '/data/style/style_%d.css', $linksCSS); + $this->log('CSS written'); $this->writeLangs(); + $this->log('Langs written'); $this->writeIndex(); + $this->log('Index written'); $this->writeTexts(); + $this->log('Texts written'); $this->writeExtras(); + $this->log('Extras written'); $this->writeJs(); + $this->log('Js written'); $this->writeCache(); + $this->log('Cache written'); } protected function loadPlugins() { @@ -498,6 +528,11 @@ class wsHTML5Compiler { if ($this->book->parametres->googleAnalyticsCustom != '') { $ga .= $this->book->parametres->googleAnalyticsCustom; } + + $statsfooter = ''; + if ($this->book->parametres->statsCustom != '') { + $statsfooter = $this->book->parametres->statsCustom; + } // Feuilles de style $sheets = array_merge($this->stylesheets, $this->specialCSS); @@ -565,7 +600,7 @@ class wsHTML5Compiler { } - $vars = array('titre', 'credits', 'ga', 'style', 'script', 'pagesContents', 'description', 'print', 'hiddenContents', 'splash', 'cache', 'bgcolor', 'message', 'favicon', 'svg'); + $vars = array('titre', 'credits', 'statsfooter', 'ga', 'style', 'script', 'pagesContents', 'description', 'print', 'hiddenContents', 'splash', 'cache', 'bgcolor', 'message', 'favicon', 'svg'); foreach ($vars as $v) { $html = str_replace('', $$v, $html); } @@ -594,13 +629,13 @@ class wsHTML5Compiler { $thtml = $uhtml; - $vars = array('titre', 'credits', 'ga', 'style', 'script', 'pagesContents', 'print', 'hiddenContents', 'splash', 'cache', 'bgcolor', 'message', 'favicon'); + $vars = array('titre', 'credits', 'statsfooter', 'ga', 'style', 'script', 'pagesContents', 'print', 'hiddenContents', 'splash', 'cache', 'bgcolor', 'message', 'favicon'); foreach ($vars as $v) { $uhtml = str_replace('', $$v, $uhtml); } $script .= "\n\t\t" . ''; - $vars = array('titre', 'credits', 'ga', 'style', 'script', 'print', 'hiddenContents', 'splash', 'message'); + $vars = array('titre', 'credits', 'statsfooter', 'ga', 'style', 'script', 'print', 'hiddenContents', 'splash', 'message'); foreach ($vars as $v) { $thtml = str_replace('', $$v, $thtml); } @@ -1061,9 +1096,10 @@ class wsHTML5Compiler { } $thumbs = array(); foreach ($this->pages as $page => $infos) { + $docdir = wsDocument::getDir($infos['document_id']); 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'; + $orig = $docdir . 'html/p' . $infos['document_page'] . '.svg'; + $opt = $docdir . 'html/o' . $infos['document_page'] . '.svg'; $svg = $orig; if (file_exists($opt) && filesize($opt) > 0) { @@ -1074,7 +1110,7 @@ class wsHTML5Compiler { } 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'); + $ok = $this->copy($docdir . 'html/' . $srcPrefix . $r . '-' . $infos['document_page'] . '.jpg', $this->vdir . '/data/background/' . $r . '/' . $this->backgroundsPrefix . $page . '.jpg'); if (!$ok && $r = 300) { $this->maxRes = 150; } @@ -1085,16 +1121,17 @@ class wsHTML5Compiler { $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'; + $thumb = $docdir . 'p' . $infos['document_page'] . '.jpg'; } $thumbs[$page] = $thumb; if ($page == 1) { - $this->_makeCover(wsDocument::getDir($infos['document_id']) . 'html/t36-' . $infos['document_page'] . '.jpg'); - } + $this->_makeCover($docdir . 'html/t36-' . $infos['document_page'] . '.jpg'); } $this->makeThumbSprites($thumbs); + $this->log('Copied image ' . $page); + } } public function makeThumbSprites(array $thumbs) { diff --git a/inc/ws/Util/html5/slider/class.ws.html5.links.php b/inc/ws/Util/html5/slider/class.ws.html5.links.php index a11e45a5b..ab8d64e9e 100644 --- a/inc/ws/Util/html5/slider/class.ws.html5.links.php +++ b/inc/ws/Util/html5/slider/class.ws.html5.links.php @@ -712,8 +712,7 @@ class webVideoLink extends videoLink { } elseif ($this->video_service == 1) { $url = 'https://www.dailymotion.com/embed/video/' . $this->to; } elseif ($this->video_service == 2) { - //Todo: get vimeo embed URL - $url = ''; + $url = 'https://player.vimeo.com/video/' . $this->to; } elseif ($this->video_service == 3) { list($playerId, $videoId) = explode('|', $this->to); $url = 'https://link.brightcove.com/services/player/bcpid' . $playerId . '?bctid=' . $videoId . '&autoStart=false&width=100%25&height=100%25'; @@ -994,8 +993,18 @@ class webVideoPopupLink extends videoPopupLink { // } public function getURL() { + + switch ($this->video_service) { + case 1: // Dailymotion + return '#/webvideo/dailymotion/' . $this->to; + break; + case 2: // Vimeo + return '#/webvideo/vimeo/' . $this->to; + break; + default: return '#/video/' . $this->to; } + } public function getAdditionnalContent() { $this->video_auto_start = true; // Videos should always autoplay -- 2.39.5