]> _ Git - cubeextranet.git/commitdiff
wip #4240 @1.5
authorvincent@cubedesigners.com <vincent@cubedesigners.com@f5622870-0f3c-0410-866d-9cb505b7a8ef>
Sat, 20 Feb 2021 16:17:06 +0000 (16:17 +0000)
committervincent@cubedesigners.com <vincent@cubedesigners.com@f5622870-0f3c-0410-866d-9cb505b7a8ef>
Sat, 20 Feb 2021 16:17:06 +0000 (16:17 +0000)
inc/ws/Util/html5/master/class.ws.html5.compiler.php

index fca835b2a7b3cb24d081ca625b53c02d43cc2fc9..b5eefec41934e196aec08e8cacd466bed6c1ddb4 100644 (file)
@@ -421,7 +421,8 @@ class wsHTML5Compiler
         $this->config->seoArticles = $this->seoArticles;
     }
 
-    public function writeGrandVisionCart(){
+    public function writeGrandVisionCart()
+    {
         $this->lessVariables['import-cart-styles'] = 'grandvision';
 
         $this->addJsLib('cookie', 'js/libs/jquery/jquery.cookie.js');
@@ -432,6 +433,69 @@ class wsHTML5Compiler
         $file = $cdir . $this->book->parametres->basketReferences;
         $this->config->basketReferences = wsUtil::excelToArrayKeyVars($file);
 
+        $odir = $cdir . '/opt/';
+        if (!file_exists($odir)) {
+            mkdir($odir, 0777, true);
+        }
+
+        $it = CubeIT_Files::getDirectoryIterator($cdir . '/raw/');
+        $exts = ['png', 'jpg', 'tif', 'mp4'];
+        foreach ($it as $file) {
+
+            /** @var $file SplFileInfo */
+            if ($file->isDir()) {
+                continue;
+            }
+            $ext = $file->getExtension();
+            if (!in_array($ext, $exts)) {
+                continue;
+            }
+
+            $e = explode('-', $file->getFilename());
+            $ean = $this->findEAN($e);
+            if (!$ean) {
+                continue;
+            }
+
+            $f = $file->getPathname();
+
+            if ($ext === 'mp4') {
+                $this->config->basketReferences[$ean]['360'] = true;
+                $opt = $odir . '/' . $ean . '-360.mp4';
+                if (!file_exists($opt) || !filesize($opt) || filemtime($opt) < filemtime($f)) {
+                    // Optimize original video
+                    `ffmpeg -i $f -filter:v scale=360:-2 -vcodec libx264 -an $opt`;
+                }
+            } else {
+                if (in_array('front', $e)) {
+                    $type = 'front';
+                } else if (in_array('angle', $e)) {
+                    $type = 'angle';
+                }
+                $this->config->basketReferences[$ean][$type] = true;
+                $opt = $odir . '/' . $ean . '-' . $type . '.jpg';
+                if (!file_exists($opt) || !filesize($opt) || filemtime($opt) < filemtime($f)) {
+                    // Optimize original image
+                    $convert = new CubeIT_Image_Resizer_ImageMagick();
+                    $convert->loadImage($f);
+                    $convert->resize(1080, null, 'ratio', false, 'C', 'M', 'ffffff');
+                    $convert->output('jpg', $f, 75);
+                }
+            }
+
+
+        }
+
+    }
+
+    public function findEAN($array)
+    {
+        foreach ($array as $item) {
+            if (strlen($item) === 13 && preg_match('/^\d{13}$/', $item)) {
+                return $item;
+            }
+        }
+        return false;
     }
 
     public function writeMIFCart()
@@ -1652,9 +1716,9 @@ class wsHTML5Compiler
                 $ids = explode(',', $linkData['to']);
                 foreach ($ids as $id) {
                     $id = trim($id);
-                    if($id==='tabs'){
-                        $this->config->tabsHiddenAtStartup=true;
-                    }else {
+                    if ($id === 'tabs') {
+                        $this->config->tabsHiddenAtStartup = true;
+                    } else {
                         $hiddenLinks[] = $id;
                         $hiddenLinks[] = 'i_' . $id;
                     }
@@ -2889,7 +2953,7 @@ class wsHTML5Compiler
             } else {
                 $dim = [0 => 1024, 1 => 10];
             }
-            $res .= '<figure'.$dirattr.'><img src="data/articles/' . $file . '" alt="' . $legend . '" width="' . $dim[0] . '" height="' . $dim[1] . '">' . $caption . '</figure>';
+            $res .= '<figure' . $dirattr . '><img src="data/articles/' . $file . '" alt="' . $legend . '" width="' . $dim[0] . '" height="' . $dim[1] . '">' . $caption . '</figure>';
         } else {
             $c = trim($this->SimpleXMLElement_innerXML($child));
             if (!$c) {