]> _ Git - fluidbook-toolbox.git/commitdiff
wait #6264 @1
authorVincent Vanwaelscappel <vincent@cubedesigners.com>
Mon, 11 Sep 2023 10:23:11 +0000 (12:23 +0200)
committerVincent Vanwaelscappel <vincent@cubedesigners.com>
Mon, 11 Sep 2023 10:23:11 +0000 (12:23 +0200)
app/Models/FluidbookDocument.php

index 8d98dc0e02c3b31ced3da860323dc839e4bd53cc..870b0a376c6da9eb14c456006c8dfa654b5cb45b 100644 (file)
@@ -205,11 +205,25 @@ class FluidbookDocument extends ToolboxModel
      */
     public function path($path = ''): string
     {
+        $path = trim($path, DIRECTORY_SEPARATOR);
+        $fname = false;
+        if ($path) {
+            $e = explode(DIRECTORY_SEPARATOR, $path);
+            if (stristr($e[count($e) - 1], '.')) {
+                $fname = array_pop($e);
+                $path = implode(DIRECTORY_SEPARATOR, $e);
+            }
+        }
+
         $res = rtrim(self::WS_DOCS . $this->id . ($path ? DIRECTORY_SEPARATOR . ltrim($path, DIRECTORY_SEPARATOR) : $path), DIRECTORY_SEPARATOR);
         if (!$path) {
             $res .= DIRECTORY_SEPARATOR;
         }
-        return Files::mkdir($res);
+        $res = Files::mkdir($res);
+        if ($fname) {
+            $res .= $fname;
+        }
+        return $res;
     }
 
     public function hasFile($page, $format = 'jpg', $resolution = 150, $quality = 85, $withText = true, $withGraphics = true, $version = 'html', $forceCheck = false)
@@ -232,7 +246,7 @@ class FluidbookDocument extends ToolboxModel
                 return false;
             }
             if ($format === 'svg') {
-                $reffile = $this->path('/html/').'fp' . $page . '.svg';
+                $reffile = $this->path('/html/') . 'fp' . $page . '.svg';
                 if (!file_exists($reffile) || filemtime($path) < filemtime($reffile)) {
                     return false;
                 }
@@ -382,7 +396,7 @@ class FluidbookDocument extends ToolboxModel
     public function _getHightlightFilePath($page, $mode = 'standard')
     {
         $dir = $mode !== 'standard' ? $mode . '/' : '';
-        return $this->path('texts/' . $dir ). 'p' . $page . '.fby';
+        return $this->path('texts/' . $dir. 'p' . $page . '.fby';
     }
 
     public function _getTextPath($page, $type = self::TEXT_PLAIN, $mode = 'standard', $extractionMethod = 'fluidbook', $ignoreSeparators = '')
@@ -394,12 +408,12 @@ class FluidbookDocument extends ToolboxModel
 
         $prefix = self::_getTextFilePrefix($extractionMethod);
         $dir = $mode !== 'standard' ? $mode . '/' : '';
-        return $this->path('texts/' . $dir . $sepFolder  ).$prefix . $type . $page . '.txt';
+        return $this->path('texts/' . $dir . $sepFolder) . $prefix . $type . $page . '.txt';
     }
 
     public function getPDFSource($type = 'crop'): string
     {
-        return $this->path().$type . '.pdf';
+        return $this->path() . $type . '.pdf';
     }
 
     public function cutDocument($mode)