]> _ Git - fluidbook_tools.git/commitdiff
wip #4793 @1
authorVincent Vanwaelscappel <vincent@cubedesigners.com>
Fri, 15 Oct 2021 10:40:06 +0000 (12:40 +0200)
committerVincent Vanwaelscappel <vincent@cubedesigners.com>
Fri, 15 Oct 2021 10:40:06 +0000 (12:40 +0200)
src/Compiler/Compiler.php
src/Compiler/Links.php
src/Links/SlideshowLink.php

index c35f8dd320778854f7c62c1f462ff34181f508af..1f3ec235768932d79fb0eadf5e046886210da364 100644 (file)
@@ -5,7 +5,6 @@ namespace Fluidbook\Tools\Compiler;
 use Cubist\Util\Files\Files;
 use Cubist\Util\Files\VirtualDirectory;
 use Cubist\Util\PHP;
-use Cubist\Util\Zip;
 use Exception;
 use Fluidbook\Tools\Jobs\ProcessFile;
 use Fluidbook\Tools\Jobs\ProcessPage;
@@ -20,7 +19,6 @@ use Illuminate\Queue\Jobs\SyncJob;
 use Illuminate\Queue\SerializesModels;
 use JsonException;
 use stdClass;
-use ZipStream\File;
 
 class Compiler implements ShouldQueue, ShouldBeUnique
 {
@@ -55,7 +53,7 @@ class Compiler implements ShouldQueue, ShouldBeUnique
     /**
      * @var string
      */
-    public $wdir;
+    public $wdir = '';
 
     /**
      * @var string
@@ -166,8 +164,11 @@ class Compiler implements ShouldQueue, ShouldBeUnique
     {
         start_measure('Compile fluidbook');
 
-        $this->wdir = resource_path('fluidbook/working/');
-        Files::mkdir($this->wdir);
+        if ($this->wdir === '') {
+            $this->wdir = resource_path('fluidbook/working/');
+            Files::mkdir($this->wdir);
+        }
+
         $this->vdir = new VirtualDirectory($this->out);
         if ($this->stub !== '') {
             $this->vdir->copyDirectory($this->stub, '/');
@@ -269,24 +270,6 @@ class Compiler implements ShouldQueue, ShouldBeUnique
         }
     }
 
-    public function unzipFile($file, $moveAssets = false, $baseDir = null)
-    {
-        $fdir = is_null($baseDir) ? 'data/links/' . str_replace('.', '_', $file) : $baseDir;
-
-        $tmp = Files::tmpdir();
-        $dir = $tmp . '/' . $fdir;
-        Files::mkdir($dir);
-
-        Zip::extract($this->wdir . '/' . $file, $dir);
-
-        if ($moveAssets) {
-            `mv $dir/Assets/* $dir`;
-            rmdir($dir . '/Assets');
-        }
-
-        return array('dir' => $dir, 'fdir' => $fdir);
-    }
-
     protected function compilePageNumbers()
     {
 
index 8b157903a4216586ff8d00be9914c98caffca488..7a0e7d0ec68232db066300a497062a45f0d20f64 100644 (file)
@@ -3,6 +3,9 @@
 namespace Fluidbook\Tools\Compiler;
 
 use Cubist\Util\ArrayUtil;
+use Cubist\Util\Files\Files;
+use Cubist\Util\Zip;
+use Exception;
 use Fluidbook\Tools\Links\ContentLink;
 use Fluidbook\Tools\Links\Link;
 use Nette\Utils\Image;
@@ -431,11 +434,39 @@ trait Links
 
         foreach ($source as $so) {
             $s = $this->wdir . $so;
-            //dd($s,$so,$dest);
             if (file_exists($s)) {
                 $d = $dest . '/' . $so;
                 $this->simpleCopyLinkFile($s, $d, false);
             }
         }
     }
+
+    /**
+     * @throws Exception
+     */
+    public function unzipFile($file, $moveAssets = false, $baseDir = null)
+    {
+        $fdir = is_null($baseDir) ? 'data/links/' . str_replace('.', '_', Files::getFilename($file)) : $baseDir;
+
+        $dir = $this->wdir . $fdir;
+        Files::mkdir($dir);
+
+        if (!file_exists($file) && file_exists($this->wdir . '/' . $file)) {
+            $file = $this->wdir . '/' . $file;
+        }
+
+        if (!file_exists($file)) {
+            throw new Exception('Zip file ' . $file . ' does not exist');
+        }
+
+
+        Zip::extract($file, $dir);
+
+        if ($moveAssets) {
+            `mv $dir/Assets/* $dir`;
+            rmdir($dir . '/Assets');
+        }
+
+        return array('dir' => $dir, 'fdir' => $fdir);
+    }
 }
index 32c6ece5acee4fec02a5a74e1994f8c000d03c40..5b3b9b8ad0490112a3c7ce6ae8b1aa6f9be30714 100644 (file)
@@ -25,7 +25,7 @@ class SlideshowLink extends NormalLink
         $this->copyExternalDir($d['dir'], $d['fdir']);
 
         $this->path = $d['fdir'];
-        $this->path_absolute = $this->compiler->getVirtualDirectory()->path($d['fdir']);
+        $this->path_absolute = $d['dir'];
 
         return '#/slideshow/' . $this->uid;
     }
@@ -163,9 +163,12 @@ class SlideshowLink extends NormalLink
         $res .= '<ul class="splide__list">';
 
         foreach ($slides as $slide) {
-            $image_path_relative = $this->compiler->getVirtualDirectory()->relativePath($slide['path']);
+
+            $image_path_relative = str_replace($this->compiler->wdir, '', $slide['path']);
+
             $image_info = Image::getimagesize($slide['path']);
             $image_info_json = ($image_info) ? json_encode(['width' => $image_info[0], 'height' => $image_info[1], 'ratio' => round($image_info[0] / $image_info[1], 4)]) : '';
+
             $image_dimensions = ($image_info) ? $image_info[3] : '';
 
             // When displaying thumbnails, they are a fixed size, based on height