]> _ Git - cubeextranet.git/commitdiff
#809
authorvincent@cubedesigners.com <vincent@cubedesigners.com@f5622870-0f3c-0410-866d-9cb505b7a8ef>
Thu, 31 Jan 2019 15:54:39 +0000 (15:54 +0000)
committervincent@cubedesigners.com <vincent@cubedesigners.com@f5622870-0f3c-0410-866d-9cb505b7a8ef>
Thu, 31 Jan 2019 15:54:39 +0000 (15:54 +0000)
inc/ws/Util/html5/printing/class.ws.html5.compiler.php

index fee62e37708e28c9e6546bb9904ca1654cd73afe..0f8a83c2c3a1cf08faad1b8304d5b0fb45dcc270 100644 (file)
@@ -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);
@@ -488,6 +504,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();
@@ -598,6 +616,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)
        {
                if (!isset($this->seo->pages[$page])) {
@@ -700,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 .= '<link rel="apple-touch-icon" href="data/apple-touch-icon.png" />';
+                               $favicon .= '<link rel="apple-touch-icon" href="data/apple-touch-icon.png" />' . "\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 .= '<link rel="shortcut icon" href="data/favicon.ico" />';
-                               $favicon .= '<link rel="icon" type="image/vnd.microsoft.icon" href="data/favicon.ico" />';
-                               $favicon .= '<link rel="icon" type="image/png" href="data/favicon.png" />';
+                               $datapng = 'data:image/png;base64,' . base64_encode(file_get_contents($pngFile));
+
+                               $favicon .= '<link rel="icon" type="image/png" href="' . $datapng . '" />' . "\n\t";
                                if (!$hasIos) {
                                        $favicon .= '<link rel="apple-touch-icon" href="data/favicon.png" />';
                                }
@@ -745,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');
                                }
@@ -1378,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();
@@ -1596,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);
 
@@ -1613,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 . ';}';
@@ -1629,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) . ')') . ';';
@@ -1708,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';