From 87d961289762327c69e3f014b9099ffe8d3736d8 Mon Sep 17 00:00:00 2001 From: "vincent@cubedesigners.com" Date: Sat, 20 Feb 2021 16:17:06 +0000 Subject: [PATCH] wip #4240 @1.5 --- .../html5/master/class.ws.html5.compiler.php | 74 +++++++++++++++++-- 1 file changed, 69 insertions(+), 5 deletions(-) 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 fca835b2a..b5eefec41 100644 --- a/inc/ws/Util/html5/master/class.ws.html5.compiler.php +++ b/inc/ws/Util/html5/master/class.ws.html5.compiler.php @@ -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 .= '' . $legend . '' . $caption . ''; + $res .= '' . $legend . '' . $caption . ''; } else { $c = trim($this->SimpleXMLElement_innerXML($child)); if (!$c) { -- 2.39.5