From 7e60961322fa9237ad1b965a7dbd469f6864d63f Mon Sep 17 00:00:00 2001 From: "vincent@cubedesigners.com" Date: Tue, 14 Feb 2023 10:03:00 +0000 Subject: [PATCH] wait #5725 @1 --- .docker/images/php/Dockerfile | 1 + inc/ws/Util/class.ws.util.php | 33 ++++++++++++ .../html5/master/class.ws.html5.compiler.php | 24 ++++++++- .../html5/master/class.ws.html5.links.php | 42 ++++++++++++--- inc/ws/Util/packager/class.ws.packager.php | 53 ++++++++++++------- 5 files changed, 125 insertions(+), 28 deletions(-) diff --git a/.docker/images/php/Dockerfile b/.docker/images/php/Dockerfile index b3dd96f07..1de25a144 100644 --- a/.docker/images/php/Dockerfile +++ b/.docker/images/php/Dockerfile @@ -71,6 +71,7 @@ RUN apt -y --no-install-recommends install sshfs lftp RUN apt -y --no-install-recommends install sshfs python3 python3-pip RUN apt -y --no-install-recommends install openssh-server rsyslog RUN apt -y --no-install-recommends install mariadb-client +RUN apt -y --no-install-recommends install pdfposter rename RUN cd /root;wget https://github.com/Medium/phantomjs/releases/download/v2.1.1/phantomjs-2.1.1-linux-x86_64.tar.bz2;tar xvjf phantomjs-2.1.1-linux-x86_64.tar.bz2;mv phantomjs-2.1.1-linux-x86_64 /usr/local/share;ln -sf /usr/local/share/phantomjs-2.1.1-linux-x86_64/bin/phantomjs /usr/local/bin RUN cd /root;wget https://github.com/nwutils/Web2Executable/releases/download/v0.7.1b/Web2ExeLinux-CMD.zip;unzip Web2ExeLinux-CMD.zip;mv Web2ExeLinux-CMD /usr/local/web2exe diff --git a/inc/ws/Util/class.ws.util.php b/inc/ws/Util/class.ws.util.php index 3652099f0..e47834691 100644 --- a/inc/ws/Util/class.ws.util.php +++ b/inc/ws/Util/class.ws.util.php @@ -1,5 +1,9 @@ ['host' => 'kingkong.cubedesigners.com', 'port' => 9458]]; + $params = array_merge($args, ['function' => $operation]); + $server = $servers[$region]; + + $timeout = 180; + + $timeout *= 1000; + $socket = new NetworkSocket( + $server['host'], + $server['port'] ?? 9458, + $timeout * 1000, + $timeout * 1000 + ); + + $client = new Client(); + $q=http_build_query($params); + $response = $client->sendRequest($socket, new PostRequest('tools.php', $q)); + return trim($response->getBody()); + } } \ 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 index fd06bd0ac..871724d58 100644 --- a/inc/ws/Util/html5/master/class.ws.html5.compiler.php +++ b/inc/ws/Util/html5/master/class.ws.html5.compiler.php @@ -285,12 +285,24 @@ class wsHTML5Compiler } $this->vdir = new CubeIT_Files_VirtualDirectory($this->dir); + $this->daoBook = new wsDAOBook($core->con); if (null === $book) { $this->book = $this->daoBook->selectById($book_id); } else { $this->book = $book; } + if ($this->book->region == 'US') { + $this->vdir->setHandler('copy', '/application/usstorage', function ($files) { + $nfiles = []; + foreach ($files as $from => $to) { + $from = str_replace('/application/usstorage/', '/storage/', $from); + $to = str_replace('/application/usstorage/', '/storage/', $to); + $nfiles[$from] = $to; + } + wsUtil::distantStorageOperation('copy', ['files' => $nfiles], 'US'); + }); + } $this->wdir = $this->book->getAssetDir(); @@ -1239,7 +1251,6 @@ class wsHTML5Compiler set_time_limit(0); - } else { $this->config->statsMatomo = false; } @@ -2208,6 +2219,7 @@ height="0" width="0" style="display:none;visibility:hidden"> } wsLinks::getLinksAndRulersFromFile($this->book_id, $links, $rulers); + $this->log('Links 1'); if ($this->book->parametres->basketManager === 'Puma') { foreach ($links as $k => $init) { @@ -2273,6 +2285,7 @@ height="0" width="0" style="display:none;visibility:hidden"> } } } + $this->log('Links 2'); $pagesOfCustomLinks = []; $hiddenLinks = []; @@ -2281,7 +2294,6 @@ height="0" width="0" style="display:none;visibility:hidden"> $linksCopy = $links; - foreach ($linksCopy as $k => $linkData) { if ($this->book->parametres->PDFRendererIframe === 'svg' && (($linkData['type'] == 31 && stristr($linkData['to'], '.pdf')) || ($linkData['type'] == 6 && stristr($linkData['alternative'], '.pdf')))) { if ($linkData['type'] == 6) { @@ -2385,6 +2397,8 @@ height="0" width="0" style="display:none;visibility:hidden"> } } + $this->log('Links 3'); + if ($this->book->parametres->anchorsAliases && file_exists(commonTools::fixpath($this->book->parametres->anchorsAliases))) { $aliases = []; $anchors = []; @@ -2433,8 +2447,11 @@ height="0" width="0" style="display:none;visibility:hidden"> $allLinksData = []; $gamifyCoins = []; + usort($links, array($this, '_sortLinks')); + $this->log('Links 3.5'); + foreach ($links as $linkData) { if (in_array($linkData['type'], $ignore)) { continue; @@ -2515,8 +2532,11 @@ height="0" width="0" style="display:none;visibility:hidden"> if ($link->keep()) { $this->hiddenContents[] = $link->getHTMLContainer(); } + $this->log('Links 4 :: ' . $link->to); } + $this->log('Links 4'); + $allpages = range(0, $this->book->parametres->pages + 1); if ($this->book->parametres->themeEnableAfterSearch) { diff --git a/inc/ws/Util/html5/master/class.ws.html5.links.php b/inc/ws/Util/html5/master/class.ws.html5.links.php index aabd683a8..c18f7e77e 100644 --- a/inc/ws/Util/html5/master/class.ws.html5.links.php +++ b/inc/ws/Util/html5/master/class.ws.html5.links.php @@ -61,6 +61,9 @@ class wsHTML5Link protected $role = 'button'; + protected $htmlContainer = null; + protected $cssContainer = null; + protected $_init; /** @@ -593,6 +596,14 @@ class wsHTML5Link } public function getHTMLContainer() + { + if (null === $this->htmlContainer) { + $this->htmlContainer = $this->_getHTMLContainer(); + } + return $this->htmlContainer; + } + + public function _getHTMLContainer() { $addContent = $this->getAdditionnalContent(); if ($this->relatedAnimation) { @@ -777,6 +788,15 @@ class wsHTML5Link } public function getCSSContainer() + { + if (null === $this->cssContainer) { + $this->cssContainer = $this->_getCSSContainer(); + } + return $this->cssContainer; + } + + + public function _getCSSContainer() { if ($this->moveOnEvenPage()) { $this->page--; @@ -949,7 +969,7 @@ class anchorLink extends wsHTML5Link { protected $role = ''; - public function getHTMLContainer() + public function _getHTMLContainer() { $this->to = self::normalizeAnchor($this->to); $this->compiler->addPageLabel($this->page, $this->to); @@ -1122,7 +1142,7 @@ class htmlMultimediaPopupLink extends htmlMultimediaPopupImage $i['height'] = $i['video_height']; $l = self::getMultimediaInstance($this->id . '_content', $i, $this->compiler); - $markup = $l->getHTMLContainer(); + $markup = $l->_getHTMLContainer(); return ' data-multimedia="' . rawurlencode($markup) . '" '; } } @@ -1448,7 +1468,15 @@ class videoLink extends wsHTML5Link } else { $path = $data->to; } - $e = explode(',', `ffprobe -v error -select_streams v:0 -show_entries stream=width,height -of csv=p=0 $path`); + + $videoSize = $path . '.size'; + if (!file_exists($videoSize) || filemtime($videoSize) < filemtime($path)) { + $probe = `ffprobe -v error -select_streams v:0 -show_entries stream=width,height -of csv=p=0 $path`; + file_put_contents($videoSize, $probe); + } else { + $probe = file_get_contents($videoSize); + } + $e = explode(',', $probe); if (isset($e[0]) && is_numeric($e[0])) { $attr['width'] = $e[0]; $attr['height'] = $e[1]; @@ -2220,7 +2248,7 @@ class htmlMultimediaLink extends wsHTML5Link } } - public function getCSSContainer() + public function _getCSSContainer() { if ($this->moveOnEvenPage()) { $this->page--; @@ -2357,9 +2385,9 @@ class audioLink extends wsHTML5Link return self::makeAudioTag($this, $w, $h, $this->compiler); } - public function getCSSContainer() + public function _getCSSContainer() { - $css = parent::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;'; @@ -2658,7 +2686,7 @@ class inpesPopinLink extends htmlMultimediaLink return 'getAdditionnalContent() . '>'; } - public function getCSSContainer() + public function _getCSSContainer() { if ($this->moveOnEvenPage()) { $this->page--; diff --git a/inc/ws/Util/packager/class.ws.packager.php b/inc/ws/Util/packager/class.ws.packager.php index e5964fcc5..7fb6b12f5 100644 --- a/inc/ws/Util/packager/class.ws.packager.php +++ b/inc/ws/Util/packager/class.ws.packager.php @@ -200,6 +200,12 @@ class wsPackager return $res; } + /** + * @throws \hollodotme\FastCGI\Exceptions\WriteFailedException + * @throws \hollodotme\FastCGI\Exceptions\ConnectException + * @throws Throwable + * @throws \hollodotme\FastCGI\Exceptions\TimedoutException + */ protected function zip($zipfile = null) { if (!$this->whole) { @@ -215,18 +221,25 @@ class wsPackager } $dir = $this->getFinalPackageDir(); - if (file_exists($dir)) { - $zip = new CubeIT_CommandLine('zip'); - $zip->cd($dir); - $zip->setArg(null, $zipfile); - $zip->setArg('symlinks'); - $zip->setArg('0'); - $zip->setArg('r'); - $zip->setArg('u'); - $zip->setArg(null, '.'); - $zip->setManualArg('-x "*/\.*"'); - $zip->execute(); - $zip->debug(); + + if ($this->book->region !== 'UE') { + $dir = str_replace('/application/usstorage', '/storage', $dir); + $zipfile = str_replace('/application/usstorage', '/storage', $zipfile); + wsUtil::distantStorageOperation('zip', ['source' => $dir, 'dest' => $zipfile], $this->book->region); + } else { + if (file_exists($dir)) { + $zip = new CubeIT_CommandLine('zip'); + $zip->cd($dir); + $zip->setArg(null, $zipfile); + $zip->setArg('symlinks'); + $zip->setArg('0'); + $zip->setArg('r'); + $zip->setArg('u'); + $zip->setArg(null, '.'); + $zip->setManualArg('-x "*/\.*"'); + $zip->execute(); + $zip->debug(); + } } if ($rename) { @@ -258,13 +271,15 @@ class wsPackager if (!$this->_clean) { return; } - if (file_exists($this->vdir)) { - // Suppression du répertoire si il existe - $rm = new cubeCommandLine('rm'); - $rm->setArg('r'); - $rm->setArg('f'); - $rm->setArg(null, $this->vdir); - $rm->execute(); + if ($this->book->region === 'UE') { + if (file_exists($this->vdir)) { + // Suppression du répertoire si il existe + $rm = new cubeCommandLine('rm'); + $rm->setArg('r'); + $rm->setArg('f'); + $rm->setArg(null, $this->vdir); + $rm->execute(); + } } } -- 2.39.5