]> _ Git - cubeextranet.git/commitdiff
wait #5725 @1
authorvincent@cubedesigners.com <vincent@cubedesigners.com@f5622870-0f3c-0410-866d-9cb505b7a8ef>
Tue, 14 Feb 2023 10:03:00 +0000 (10:03 +0000)
committervincent@cubedesigners.com <vincent@cubedesigners.com@f5622870-0f3c-0410-866d-9cb505b7a8ef>
Tue, 14 Feb 2023 10:03:00 +0000 (10:03 +0000)
.docker/images/php/Dockerfile
inc/ws/Util/class.ws.util.php
inc/ws/Util/html5/master/class.ws.html5.compiler.php
inc/ws/Util/html5/master/class.ws.html5.links.php
inc/ws/Util/packager/class.ws.packager.php

index b3dd96f072ea805a415f3212b694ed4abd2cb079..1de25a14455ec2f7bf514149d8a432ab59c41362 100644 (file)
@@ -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
index 3652099f0768420063e5064db25a2285ae37e3ed..e47834691d9a717616fa71fa3179102f281166ce 100644 (file)
@@ -1,5 +1,9 @@
 <?php\r
 \r
+use hollodotme\FastCGI\Client;\r
+use hollodotme\FastCGI\Requests\PostRequest;\r
+use hollodotme\FastCGI\SocketConnections\NetworkSocket;\r
+\r
 class wsUtil\r
 {\r
     public static function excelToArray($excelFile, $assoc = false, $reader = 'Excel2007', $force = false)\r
@@ -512,4 +516,33 @@ class wsUtil
             }\r
         }\r
     }\r
+\r
+\r
+    /**\r
+     * @throws Throwable\r
+     * @throws \hollodotme\FastCGI\Exceptions\WriteFailedException\r
+     * @throws \hollodotme\FastCGI\Exceptions\ConnectException\r
+     * @throws \hollodotme\FastCGI\Exceptions\TimedoutException\r
+     */\r
+    public static function distantStorageOperation($operation, $args = [], $region = 'US')\r
+    {\r
+        $servers = ['US' => ['host' => 'kingkong.cubedesigners.com', 'port' => 9458]];\r
+        $params = array_merge($args, ['function' => $operation]);\r
+        $server = $servers[$region];\r
+\r
+        $timeout = 180;\r
+\r
+        $timeout *= 1000;\r
+        $socket = new NetworkSocket(\r
+            $server['host'],\r
+            $server['port'] ?? 9458,\r
+            $timeout * 1000,\r
+            $timeout * 1000\r
+        );\r
+\r
+        $client = new Client();\r
+        $q=http_build_query($params);\r
+        $response = $client->sendRequest($socket, new PostRequest('tools.php', $q));\r
+        return trim($response->getBody());\r
+    }\r
 }
\ No newline at end of file
index fd06bd0ac0ac69645442fa9160b4af45813c94a3..871724d58cdccee47f98a4fe45fdbee0cd6b39c5 100644 (file)
@@ -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"></iframe></noscript>
         }
 
         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"></iframe></noscript>
                 }
             }
         }
+        $this->log('Links 2');
 
         $pagesOfCustomLinks = [];
         $hiddenLinks = [];
@@ -2281,7 +2294,6 @@ height="0" width="0" style="display:none;visibility:hidden"></iframe></noscript>
 
         $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"></iframe></noscript>
             }
         }
 
+        $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"></iframe></noscript>
         $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"></iframe></noscript>
             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) {
index aabd683a87bddd8ffc81dbd5a605df2413bda13d..c18f7e77e2f7dbb3b137c15cafa300fbc3fcf5c3 100644 (file)
@@ -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 '<a href="#" ' . $tooltip . $c . $this->getAdditionnalContent() . '></a>';
     }
 
-    public function getCSSContainer()
+    public function _getCSSContainer()
     {
         if ($this->moveOnEvenPage()) {
             $this->page--;
index e5964fcc54f4872367cc52ed6fbc7115f4067463..7fb6b12f5bd0540a0848988946bd03eba6b84fe3 100644 (file)
@@ -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();
+            }
         }
     }