]> _ Git - fluidbook_tools.git/commitdiff
wait #5929 @0.75
authorVincent Vanwaelscappel <vincent@cubedesigners.com>
Tue, 29 Aug 2023 10:30:40 +0000 (12:30 +0200)
committerVincent Vanwaelscappel <vincent@cubedesigners.com>
Tue, 29 Aug 2023 10:30:40 +0000 (12:30 +0200)
src/Links/LottieLink.php

index 9e0903dcfa03052e1a3e7c3cdfa64fe96c84fad3..485c863bca20487bb0f57ef569dfd04cfcc8ca96 100644 (file)
@@ -4,6 +4,7 @@ namespace Fluidbook\Tools\Links;
 
 use Cubist\Util\CSS;
 use Cubist\Util\Files\Files;
+use Cubist\Util\Graphics\Color;
 use Cubist\Util\Json;
 use SplFileInfo;
 
@@ -24,22 +25,35 @@ class LottieLink extends HTMLMultimediaLink
             if ($ext === 'zip') {
                 $d = $this->unzipFile($this->to, false);
                 $this->_config = $this->getConfigZIP($d['dir']);
-                $this->copyExternalDir($d['dir'], $d['fdir']);
-                if (file_exists($d['dir'] . '/index.html')) {
-                    $html = file_get_contents($d['dir'] . '/index.html');
-                    $html = str_replace('var pRatio = window.devicePixelRatio || 1,', 'var pRatio = 0.5,', $html);
-                    $this->_config['lowDef'] = 'index_ld.html';
-                    $this->compiler->getVirtualDirectory()->file_put_contents($d['fdir'] . '/' . $this->_config['lowDef'], $html);
-                }
+
+                $htmlfile = $d['dir'] . '/index.html';
             } elseif ($ext === 'html') {
                 $fdir = 'data/links';
                 $dir = $fdir;
-
-                $d = array('fdir' => $fdir, 'dir' => $dir);
-                $this->compiler->getVirtualDirectory()->copy($this->compiler->working_path($this->to), $d['dir'] . '/' . $this->to);
+                $d = array('fdir' => $fdir, 'dir' => $this->compiler->working_path());
                 $this->_config = $this->getConfigHTML($d['dir'], $this->to);
                 $this->copyExternalFile($d['dir'] . '/' . $this->to);
+                $htmlfile = $this->compiler->working_path($this->to);
+
+            }
+
+
+            $html = file_get_contents($htmlfile);
+            $bgc = new Color($this->background);
+            $html = preg_replace('/background-color:.*$/m', 'background-color:' . $bgc->toCSS() . ';', $html);
+            $html = preg_replace('/loop:\s*(true|false),\s*$/m', 'loop: ' . ($this->video_loop ? 'true' : 'false') . ',', $html);
+            $html = preg_replace('/autoplay:\s*(true|false),\s*$/m', 'autoplay: ' . ($this->video_auto_start ? 'true' : 'false') . ',', $html);
+            $html = preg_replace('/renderer:\s*\'(svg|canvas|html)\',\s*$/m', 'renderer: \'' . $this->renderer . '\',', $html);
+            $replacedHTML = $this->_htmlReplacedName($htmlfile);
+            file_put_contents($replacedHTML, $html);
+
+            if ($ext === 'zip') {
+                $this->copyExternalDir($d['dir'], $d['fdir']);
+            } else {
+                $this->compiler->getVirtualDirectory()->copy($replacedHTML, $d['fdir'] . '/' . $this->_htmlReplacedName($this->to));
             }
+
+
             if ($this->_config['width'] == 0) {
                 $this->_config['width'] = $this->width;
             }
@@ -50,7 +64,7 @@ class LottieLink extends HTMLMultimediaLink
             $res = '';
             $s = $this->in_popup ? 1 : $this->getCssScale();
             if ($this->_config['html']) {
-                $this->_url = $d['fdir'] . '/' . $this->_config['html'];
+                $this->_url = $d['fdir'] . '/' . $this->_htmlReplacedName($this->_config['html']);
                 if ($this->extra) {
                     $this->_url .= '?' . $this->extra;
                 }
@@ -64,4 +78,9 @@ class LottieLink extends HTMLMultimediaLink
         }
         return $this->_content;
     }
+
+    protected function _htmlReplacedName($html)
+    {
+        return str_replace('.html', '.r.html', $html);
+    }
 }