From 33fbc5559c17ac4bd4dde13a7d04810e2d9fa283 Mon Sep 17 00:00:00 2001 From: "vincent@cubedesigners.com" Date: Tue, 23 Mar 2021 19:12:24 +0000 Subject: [PATCH] wip #4367 @6 --- inc/ws/Controlleur/class.ws.ajax.php | 9 +--- inc/ws/Controlleur/class.ws.flash.php | 12 +++-- inc/ws/Controlleur/class.ws.maintenance.php | 7 ++- inc/ws/Util/class.ws.pdf.convert.php | 4 +- .../html5/master/class.ws.html5.compiler.php | 50 +++++++++++++------ 5 files changed, 52 insertions(+), 30 deletions(-) diff --git a/inc/ws/Controlleur/class.ws.ajax.php b/inc/ws/Controlleur/class.ws.ajax.php index 78a3edb4a..803cfd5a9 100644 --- a/inc/ws/Controlleur/class.ws.ajax.php +++ b/inc/ws/Controlleur/class.ws.ajax.php @@ -512,18 +512,11 @@ class wsAjax extends cubeAjax $_POST = array_merge($defaults, $_POST); - foreach ($_POST as $k => $v) { - if (!is_array($v)) { - $_POST[$k] = htmlspecialchars($v); - } - } - - if (!self::valideDemandeDevis($x)) { $x->addAlert(sprintf(__("Une erreur s'est produite. Nous avons été averti de l'erreur que vous rencontrez. Vous pouvez nous contacter par e-mail à l'adresse suivante : %s"), 'info@fluidbook.com')); return; } - $spam = (strlen($_POST['fax']) > 0); + $spam = (strlen($_POST['fax']) > 0) || strpos('<', $_POST['rs']) !== false || strpos('<', $_POST['prenom']) !== false || strpos('<', $_POST['nom']) !== false; $_POST['spam'] = $spam ? 'Oui' : 'Non'; diff --git a/inc/ws/Controlleur/class.ws.flash.php b/inc/ws/Controlleur/class.ws.flash.php index 5bc8b8d3d..f26656af1 100644 --- a/inc/ws/Controlleur/class.ws.flash.php +++ b/inc/ws/Controlleur/class.ws.flash.php @@ -835,12 +835,16 @@ class wsFlash extends cubeFlashGateway { global $core; $dao = new wsDAOBook($core->con); - $dao->setComposition($this->args['book_id'], json_decode($this->args['pages'])); + $pages = json_decode($this->args['pages']); + $dao->setComposition($this->args['book_id'], $pages); // Begin to generate files async - $book = $dao->selectById($this->args['book_id']); - $url = 'https://workshop.fluidbook.com/viewerh/' . $book->book_id . '_' . $book->hash . '_' . time(); - `wget -t 1 -T 1 $url`; + $url = 'https://workshop.fluidbook.com/maintenance/processPage/' . $this->args['book_id'] . '/all/0'; + $ctx = stream_context_create(["http" => ["timeout" => 1]]); + $it = max(4, min(12, ceil(count($pages) / 20))); + for ($i = 0; $i < $it; $i++) { + file_get_contents($url, 0, $ctx); + } } public function getTexts() diff --git a/inc/ws/Controlleur/class.ws.maintenance.php b/inc/ws/Controlleur/class.ws.maintenance.php index 7de231297..4450d3ba6 100644 --- a/inc/ws/Controlleur/class.ws.maintenance.php +++ b/inc/ws/Controlleur/class.ws.maintenance.php @@ -1493,7 +1493,7 @@ class wsMaintenance $working = WS_BOOKS . '/working/' . $book . '/commerce/opt/'; $res = [['EAN', 'front', 'angle', '360']]; foreach ($eans as $ean) { - $res[] = [$ean." ", file_exists($working.'/'.$ean . '-front.jpg') ? 'Y' : 'N', file_exists($working.'/'.$ean . '-angle.jpg') ? 'Y' : 'N', file_exists($working.'/'.$ean . '-360.mp4') ? 'Y' : 'N']; + $res[] = [$ean . " ", file_exists($working . '/' . $ean . '-front.jpg') ? 'Y' : 'N', file_exists($working . '/' . $ean . '-angle.jpg') ? 'Y' : 'N', file_exists($working . '/' . $ean . '-360.mp4') ? 'Y' : 'N']; } $excel = CubeIT_Excel::simple('GrandVisionLibrary', $res); ob_end_clean(); @@ -1513,6 +1513,7 @@ class wsMaintenance $book_id = $args[0]; $page = $args[1]; + $force = !isset($args[2]) || $args[2] != '0'; $daoBook = new wsDAOBook($core->con); @@ -1536,9 +1537,11 @@ class wsMaintenance $pages = [$page]; } + shuffle($pages); + foreach ($pages as $page) { foreach ($files as $file) { - $book->getFile($page, $file[0], $file[1], $file[2], $file[3], $file[4], true); + $book->getFile($page, $file[0], $file[1], $file[2], $file[3], $file[4], $force); } } } diff --git a/inc/ws/Util/class.ws.pdf.convert.php b/inc/ws/Util/class.ws.pdf.convert.php index 0c68767d8..876d5368d 100644 --- a/inc/ws/Util/class.ws.pdf.convert.php +++ b/inc/ws/Util/class.ws.pdf.convert.php @@ -255,8 +255,8 @@ class wsPDFConvert unlink($tmp); } else { $pdftoppm->debug(); - echo $pdftoppm->command . ':' . $pdftoppm->output; - exit; +// echo $pdftoppm->command . ':' . $pdftoppm->output; +// exit; } } 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 0cbdb69b6..67c2d4977 100644 --- a/inc/ws/Util/html5/master/class.ws.html5.compiler.php +++ b/inc/ws/Util/html5/master/class.ws.html5.compiler.php @@ -1125,10 +1125,6 @@ class wsHTML5Compiler if ($page == 1) { $seo->writePage($html, $this->vdir, 'index.html'); } - - if ($page % 10 == 0) { - $this->log('Written page ' . $page); - } } public function getIndexVars() @@ -2038,13 +2034,27 @@ class wsHTML5Compiler public function writeTexts() { - $this->daoBook->makeTextsIndexes($this->book, $this->pages, $index, $textes, true); - $this->vdir->file_put_contents('data/search.index.js', 'var INDEX=' . $index . ';' . "\r"); + $cache = sha1($this->book->parametres->highlightResults . '/--/' . $this->book->parametres->searchWordSelectionAlgorithm . '///' . $this->book->parametres->textExtraction . '|--|' . $this->book->parametres->ignoreSearchSeparators . '|||' . max($this->book->composition_update, filemtime(WS_TOOLS . '/fwstk/out/artifacts/fwstk_jar/fwstk.jar'))); + $cacheDir = WS_BOOKS . '/index/' . $this->book_id . '/' . $cache . '/'; + if (!file_exists($cacheDir)) { + mkdir($cacheDir, 0777, true); + + $this->daoBook->makeTextsIndexes($this->book, $this->pages, $index, $textes, true); + file_put_contents($cacheDir . '/search.index.js', 'var INDEX=' . $index . ';' . "\r"); + if ($this->book->parametres->highlightResults) { + file_put_contents($cacheDir . '/search.highlight.js', 'var HIGHLIGHTS=' . json_encode($this->daoBook->makeHighlightIndex($this->book, $this->pages)) . ";\r"); + } + if ($this->book->parametres->searchWordSelectionAlgorithm == 'expression') { + file_put_contents($cacheDir . '/search.texts.js', 'var TEXTS=' . $textes . ";\r"); + } + } + + $this->vdir->copy($cacheDir . '/search.index.js', 'data/search.index.js'); if ($this->book->parametres->highlightResults) { - $this->vdir->file_put_contents('data/search.highlight.js', 'var HIGHLIGHTS=' . json_encode($this->daoBook->makeHighlightIndex($this->book, $this->pages)) . ";\r"); + $this->vdir->copy($cacheDir . '/search.highlight.js', 'data/search.highlight.js'); } if ($this->book->parametres->searchWordSelectionAlgorithm == 'expression') { - $this->vdir->file_put_contents('data/search.texts.js', 'var TEXTS=' . $textes . ";\r"); + $this->vdir->copy($cacheDir . '/search.texts.js', 'data/search.texts.js'); } } @@ -2106,13 +2116,8 @@ class wsHTML5Compiler $imdir = 'html'; } - $pages= array_slice($this->pages, 0);; - shuffle($pages); - $thumbs = array(); foreach ($this->pages as $page => $infos) { - $docdir = wsDocument::getDir($infos['document_id']); - $thisrasterize = in_array($page, $rasterizePages); $thisimagesvg = !$thisrasterize && $this->svg; $thisbackgroundPrefix = $thisrasterize ? [true] : $this->backgroundsPrefix; @@ -2137,11 +2142,12 @@ class wsHTML5Compiler } $this->vdir->copy($this->book->getThumbFile($page, $this->imageFormat), 'data/thumbnails/p' . $page . '.' . $this->imageFormat); + $this->log('Made image page ' . $page); } $this->_makeCover($this->book->getFile(1, 'jpg', 150, true, true)); - $this->log('Made thumbnails'); + $this->log('Made images'); } protected function _makeCover($orig) @@ -2188,6 +2194,7 @@ class wsHTML5Compiler $this->lessVariables['css-scale'] = $this->cssScale; $this->lessVariables['slider-display'] = $this->_lessBoolean($this->theme->parametres->pagesBar); $this->lessVariables['slider-thumb-background'] = wsHTML5::colorToCSS($this->theme->parametres->pageBarThumbBack); + $this->lessVariables['pages-background'] = $this->book->parametres->forceWhiteBackground ? '#ffffff' : 'transparent'; // General theme $cssWidth = $this->cssWidth; @@ -3013,3 +3020,18 @@ if (!function_exists('is_countable')) { } } + +function shuffle_assoc(&$array) +{ + $keys = array_keys($array); + + shuffle($keys); + + foreach ($keys as $key) { + $new[$key] = $array[$key]; + } + + $array = $new; + + return true; +} -- 2.39.5