From: vincent@cubedesigners.com Date: Tue, 29 Jan 2019 10:56:32 +0000 (+0000) Subject: wip #809 @1 X-Git-Url: http://git.cubedesigners.com/?a=commitdiff_plain;h=5ad81d5875adcb0adfe5b68de28ead0507b0d985;p=cubeextranet.git wip #809 @1 --- diff --git a/inc/ws/Util/html5/3dflip/class.ws.html5.compiler.php b/inc/ws/Util/html5/3dflip/class.ws.html5.compiler.php index d32e8e9d2..782bc3300 100644 --- a/inc/ws/Util/html5/3dflip/class.ws.html5.compiler.php +++ b/inc/ws/Util/html5/3dflip/class.ws.html5.compiler.php @@ -183,14 +183,14 @@ class wsHTML5Compiler public $logtime = null; public $beginBody = array(); public $seoArticles = []; - public $securityPolicyWhitelist = ['*.google-analytics.com', '*.youtube.com', '*.ytimg.com']; + public $securityPolicyWhitelist = ['*.google-analytics.com', '*.youtube.com', '*.ytimg.com', '*.googletagmanager.com']; public $writeLinksData = false; public $content_lock = []; protected $_indexVars = null; public $_signature; /** - * @var wsHTML5Seo + * @var wsHTML5SeolinksData */ public $seo = null; @@ -505,6 +505,8 @@ class wsHTML5Compiler $this->log('Widget written'); $this->writeSounds(); $this->log('Sound written'); + $this->writeAccessibility(); + $this->log('Sound accessibility'); $this->writeTexts(); $this->log('Texts written'); $this->writeExtras(); @@ -520,7 +522,7 @@ class wsHTML5Compiler } $this->writeJs(); $this->log('Js written'); - $this->vdir->sync($delete); + $this->vdir->sync($delete, $this); $this->log('Files Synced'); } @@ -615,6 +617,109 @@ class wsHTML5Compiler $this->vdir->copyDirectory(WS_SOUNDS . '/' . $this->book->parametres->soundTheme, 'data/sounds'); } + protected function writeAccessibility() + { + if ($this->book->parametres->audiodescriptionTexts == '' || $this->book->parametres->audiodescriptionVoice == '') { + return; + } + $file = $this->wdir . '/' . $this->book->parametres->audiodescriptionTexts; + new PHPExcel(); + $reader = new PHPExcel_Reader_Excel2007(); + $phpexcel = $reader->load($file); + + $sheet = $phpexcel->getActiveSheet(); + $maxRow = $sheet->getHighestRow(0); + + for ($i = 0; $i <= $maxRow; $i++) { + $page = trim($sheet->getCellByColumnAndRow(0, $i)->getValue()); + $text = trim($sheet->getCellByColumnAndRow(1, $i)->getValue()); + if ($page == '' || $text == '') { + continue; + } + + $replace = ['`' => "'", + '“' => '"', + '”' => '"', + '’' => "'", + '—' => " - ", + '‘' => "'", + ]; + + $text = str_replace(array_keys($replace), array_values($replace), $text); + + $hash = hash('sha256', $this->book->parametres->audiodescriptionVoice . '_^_' . $text); + $fname = $hash . '.mp3'; + $dir = WS_BOOKS . '/audiodescription/'; + if (!file_exists($dir)) { + mkdir($dir, 0777, true); + } + + $file = $dir . $fname; + if (!file_exists($file)) { + $e = explode(':', $this->book->parametres->audiodescriptionVoice); + + $engine = $e[0]; + $voice = $e[1]; + + if ($engine == 'festival') { + $tmp = CubeIT_Files::tempnam() . '.wav'; + $tmptext = CubeIT_Files::tempnam() . '.txt'; + + file_put_contents($tmptext, $text); + $cmd = "text2wave -o $tmp $tmptext -eval \"($voice)\""; + `$cmd`; + + `lame $tmp $file`; + unlink($tmp); + unlink($tmptext); + } else if ($engine == 'readspeaker') { + $e = explode('/', $voice); + $this->_readSpeaker($text, $e[1], $e[0], $file); + } + } + + $this->config->audiodescription[$page] = $fname; + $this->vdir->copy($file, 'data/audiodescription/' . $fname); + } + } + + protected function _readSpeaker($text, $language, $voice, $output) + { + $text_to_read = urlencode($text); + // Your API key here + $apikey = 'e9c321908f2dd016f6a0c34d2d786aff'; + + // File path and file name + $filepath = $output; + + // API URL of text-to-speech enabler + $api_url = 'https://tts.readspeaker.com/a/speak'; + + // Compose API call url + $url = $api_url . '?key=' . $apikey . '&streaming=0&lang=' . $language . '&voice=' . $voice . '&text=' . $text_to_read; + + // Initiating curl + $ch = curl_init($url); + + curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); + curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true); + + $data = curl_exec($ch); + + $status = curl_getinfo($ch, CURLINFO_HTTP_CODE); + + if ($status == 200 && !curl_errno($ch)) { + // Everything is fine, close curl and save file + curl_close($ch); + file_put_contents($filepath, $data); + } else { + // Cannot translate text to speech because of text-to-speech API error + error_log(__FILE__ . ': API error while text-to-speech. error code=' . $status); + curl_close($ch); + } + + } + protected function _writeIndex($page) { @@ -624,18 +729,16 @@ class wsHTML5Compiler $seo = $this->seo->pages[$page]; $html = $seo->getHTML(); - $iv = $this->getIndexVars(); - - foreach ($iv as $k => $v) { - $html = str_replace($k, $v, $html); - } - if ($this->book->parametres->seoVersion) { $seo->writePage($html, $this->vdir); } if ($page == 1) { $seo->writePage($html, $this->vdir, 'index.html'); } + + if ($page % 10 == 0) { + $this->log('Written page ' . $page); + } } public function getIndexVars() @@ -776,6 +879,10 @@ class wsHTML5Compiler protected function writeIndex() { + $iv = $this->getIndexVars(); + foreach ($iv as $k => $v) { + $this->seo->html = str_replace($k, $v, $this->seo->html); + } if ($this->book->parametres->seoVersion) { foreach ($this->pages as $page => $infos) { $this->_writeIndex($page); @@ -1302,7 +1409,7 @@ class wsHTML5Compiler copy($tmp, $minimized); } - if (!file_exists($minimized)) { + if (!file_exists($minimized) || filesize($minimized) == 0) { die('An error occured while uglifying : ' . $uglify->output); } } @@ -1371,6 +1478,8 @@ class wsHTML5Compiler $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; @@ -1482,8 +1591,10 @@ class wsHTML5Compiler $this->_makeCover($docdir . 'html/t36-' . $infos['document_page'] . '.jpg'); } + if ($page % 10 == 0) { $this->log('Copied image ' . $page); } + } $this->makeThumbSprites($thumbs); 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 0d616bb8a..0f8a83c2c 100644 --- a/inc/ws/Util/html5/master/class.ws.html5.compiler.php +++ b/inc/ws/Util/html5/master/class.ws.html5.compiler.php @@ -12,26 +12,28 @@ class wsHTML5Compiler 'modernizr' => ['js/libs/modernizr/modernizr.min.js', 'js/libs/modernizr/tests.js',], + 'modifier' => ['js/libs/threejs/modifier.min.js'], 'threejs' => - ['js/libs/threejs/three.min.js', - 'js/libs/threejs/Projector.js', - 'js/libs/threejs/CanvasRenderer.js', - 'js/libs/threejs/modifier.js', - 'js/libs/threejs/stats.js',], + ['js/libs/threejs/legacy/three.min.js', + 'js/libs/threejs/legacy/Projector.js', + 'js/libs/threejs/legacy/CanvasRenderer.js', + ], +// 'threejs-latest' => +// ['js/libs/threejs/latest/three.min.js', +// ], 'jquery' => ['js/libs/jquery/jquery.min.js', 'js/libs/jquery/jquery.transform.js', 'js/libs/jquery/jquery.form.min.js', 'js/libs/jquery/jquery.mousewheel.min.js', 'js/libs/jquery/jquery.hashchange.min.js',], - 'screenfull' => ['js/libs/screenfull.min.js',], + 'screenfull' => ['js/libs/screenfull.min.js'], 'storage' => ['js/libs/storage.js',], 'keymaster' => ['js/libs/keymaster.js',], - 'perfectscrollbar' => ['js/libs/jquery/perfect-scrollbar.jquery.min.js',], + 'perfectscrollbar' => ['js/libs/perfect-scrollbar/perfect-scrollbar.min.js', + 'js/libs/perfect-scrollbar/perfect-scrollbar.jquery.js'], 'mmenu' => - ['js/libs/mmenu/jquery.mmenu.min.js', - 'js/libs/mmenu/jquery.mmenu.rtl.min.js', - 'js/libs/mmenu/jquery.mmenu.offcanvas.min.js',], + ['js/libs/mmenu/jquery.mmenu.all.js'], 'tweenmax' => ['js/libs/gsap/TweenMax.min.js', 'js/libs/gsap/jquery.gsap.min.js', @@ -333,6 +335,8 @@ class wsHTML5Compiler $this->config->manifest = $this->writeManifest(); } + $this->writeGPUDatabase(); + if ($this->config->form == 'bulle') { $this->addJsLib('bulle', 'js/libs/fluidbook/forms/fluidbook.form.bulle.js'); } else if ($this->config->form == 'bourbon') { @@ -377,6 +381,18 @@ class wsHTML5Compiler $this->config->seoArticles = $this->seoArticles; } + public function writeGPUDatabase() + { + global $core; + $r = $core->con->select('SELECT gpu,score FROM gpu'); + $gpu = []; + while ($r->fetch()) { + $gpu[$r->gpu] = $r->score; + } + $this->config->gupsc = $gpu; + $this->config->gupse = wsServices::gpuSeparators(); + } + public function log($step) { $currenttime = microtime(true); @@ -805,30 +821,16 @@ class wsHTML5Compiler if ($this->theme->parametres->iosicon != '') { $hasIos = true; $this->vdir->copy($this->themeRoot . '/' . $this->theme->parametres->iosicon, 'data/apple-touch-icon.png'); - $favicon .= ''; + $favicon .= '' . "\n\t"; } if ($this->theme->parametres->favicon != '') { $pngFile = $this->themeRoot . '/' . $this->theme->parametres->favicon; - $icoFile = $this->themeRoot . '/favicon.ico'; - if (!file_exists($icoFile) || filemtime($icoFile) < filemtime($pngFile) || filemtime(__FILE__) > filemtime($icoFile)) { - $tmp = CubeIT_Files::tempnam() . '.png'; - $convert = "convert $pngFile -resize 64x64^ -gravity center $tmp"; - `$convert`; - - $icotool = new cubeCommandLine('icotool'); - $icotool->setArg('c'); - $icotool->setArg('o', $icoFile); - $icotool->setArg(null, $tmp); - $icotool->execute(); - unlink($tmp); - } $this->vdir->copy($pngFile, 'data/favicon.png'); - $this->vdir->copy($icoFile, 'data/favicon.ico'); - $favicon .= ''; - $favicon .= ''; - $favicon .= ''; + $datapng = 'data:image/png;base64,' . base64_encode(file_get_contents($pngFile)); + + $favicon .= '' . "\n\t"; if (!$hasIos) { $favicon .= ''; } @@ -850,7 +852,7 @@ class wsHTML5Compiler $svg = ''; foreach ($svgfiles as $svgfile) { if (file_exists($svgfile)) { - $svg .= file_get_contents($svgfile); + $svg .= str_replace('$bookmark-color', wsHTML5::colorToCSS($this->theme->parametres->bookmarkBackgroundColor), file_get_contents($svgfile)); } else { die($svgfile . ' does not exist'); } @@ -1483,9 +1485,7 @@ class wsHTML5Compiler // Set the icon list with the color $icons = array('interface-down' => $arrowsColor, 'interface-close' => $arrowsColor, 'interface-audio-description-on' => $arrowsColor, 'interface-audio-description-off' => $arrowsColor, - 'help-fingers' => $couleurI, 'help-mouse' => $couleurI, - 'bookmark-left-off' => $bookmarksDisabledColors, 'bookmark-left-on' => $bookmarksEnabledColors, - 'bookmark-right-off' => $bookmarksDisabledColors, 'bookmark-right-on' => $bookmarksEnabledColors + 'help-fingers' => $couleurI, 'help-mouse' => $couleurI ); $this->config->iconsDimensions = array(); @@ -1701,6 +1701,13 @@ class wsHTML5Compiler $lessVariables['z'] = $this->z; $lessVariables['book-page-width'] = $w; + if ($this->book->parametres->correctCenter) { + $lessVariables['book-page-correct-width'] = ceil($w + 1); + $lessVariables['book-page-correct-height'] = ceil($h + 1); + } else { + $lessVariables['book-page-correct-width'] = $w; + $lessVariables['book-page-correct-height'] = $h; + } $lessVariables['book-page-height'] = $h; $lessVariables['book-page-ratio'] = floatval($w) / floatval($h); @@ -1718,13 +1725,6 @@ class wsHTML5Compiler $left = $w; - $centerOffset = 0; - if ($this->book->parametres->correctCenter) { - $centerOffset = 3; - $left = ($cssWidth - $centerOffset) . 'px'; - $res[] = '.doublePage._3d .page.left{left:-' . ($centerOffset + 1) . 'px !important;}'; - } - $lessVariables['correct-center'] = ($centerOffset * -1); $res[] = '.doublePage._3d{left:' . $left . ';}'; $res[] = '#links.right{left:-' . $left . ';}'; @@ -1734,9 +1734,6 @@ class wsHTML5Compiler $lessVariables['display-page-number'] = $this->_lessBoolean($this->theme->parametres->displayPageNumber); $lessVariables['page-transition-duration'] = $this->book->parametres->mobileTransitionDuration . 's'; - - $res[] = '.background{width:100%;height:100%}'; - if ($this->cssSVGScale != 1) { $texts = '.texts{' . wsHTML5::writeCSSUA('transform-origin', 'top left') . ';'; $texts .= wsHTML5::writeCSSUA('transform', 'scale(' . round((1 / $this->multiply) * $cssScale * $this->cssSVGScale, 3) . ')') . ';'; @@ -1813,6 +1810,10 @@ class wsHTML5Compiler if (!isset($this->book->parametres->bookmarkCornerSize)) { $this->book->parametres->bookmarkCornerSize = 10; } + + $lessVariables['bookmark-star-disabled-color'] = wsHTML5::colorToCSS($this->theme->parametres->bookmarkStarDisabledColor); + $lessVariables['bookmark-star-enabled-color'] = wsHTML5::colorToCSS($this->theme->parametres->bookmarkStarEnabledColor); + $lessVariables['bookmark-color'] = wsHTML5::colorToCSS($this->theme->parametres->bookmarkBackgroundColor); $lessVariables['bookmark-corner-size'] = round($this->width * $this->book->parametres->bookmarkCornerSize * 0.0075 * $this->z) . 'px'; $lessVariables['bookmark-corner-offset'] = $this->book->parametres->bookmarkOffset . 'px';