]> _ Git - fluidbook-toolbox.git/commitdiff
wip #5721 @1
authorVincent Vanwaelscappel <vincent@cubedesigners.com>
Fri, 10 Feb 2023 14:48:20 +0000 (15:48 +0100)
committerVincent Vanwaelscappel <vincent@cubedesigners.com>
Fri, 10 Feb 2023 14:48:20 +0000 (15:48 +0100)
.docker/docker-compose.yml
app/Console/Commands/FluidbookLinksFromPDF.php [new file with mode: 0644]
app/Fluidbook/Links.php
app/Jobs/FluidbookCompiler.php
resources/linkeditor/style/inc/_toolbar.sass

index 8bea06a33a2a332ac7e71e5a4beeacf09daa2052..2f868d7e3bf6db4a8279ed76d266a8bee5779551 100644 (file)
@@ -14,6 +14,7 @@ services:
       - '/data/extranet/ftp/:/application/ftp/'
       - '/mnt/sshfs/godzilla/data/fluidbook/docs/:/application/protected/fluidbookpublication/docs/'
       - '/data/extranet/www/fluidbook/books/working/:/application/protected/fluidbookpublication/working/'
+      - '/data/extranet/www/fluidbook/books/links/:/application/protected/fluidbookpublication/links/'
       - '/home/extranet:/home/extranet'
       - '/data/extranet:/data/extranet'
       - '/mnt:/mnt'
@@ -75,6 +76,7 @@ services:
       - '/data/extranet/ftp/:/application/ftp/'
       - '/mnt/sshfs/godzilla/data/fluidbook/docs/:/application/protected/fluidbookpublication/docs/'
       - '/data/extranet/www/fluidbook/books/working/:/application/protected/fluidbookpublication/working/'
+      - '/data/extranet/www/fluidbook/books/links/:/application/protected/fluidbookpublication/links/'
       - '/home/extranet:/home/extranet'
       - '/data/extranet:/data/extranet'
       - '/mnt:/mnt'
diff --git a/app/Console/Commands/FluidbookLinksFromPDF.php b/app/Console/Commands/FluidbookLinksFromPDF.php
new file mode 100644 (file)
index 0000000..3a5eae9
--- /dev/null
@@ -0,0 +1,20 @@
+<?php
+
+namespace App\Console\Commands;
+
+use App\Fluidbook\Links;
+use App\Models\Traits\FluidbookPlayerBranches;
+use Cubist\Backpack\Console\Commands\CubistCommand;
+use Cubist\Util\PHP;
+
+class FluidbookLinksFromPDF extends CubistCommand
+{
+    protected $signature = 'fluidbook:links:importfrompdf  {id}';
+    protected $description = 'Import links from PDF';
+
+    public function handle()
+    {
+        Links::addLinksFromPDF($this->argument('id'));
+    }
+
+}
index c94a86f8e63030ce96e1445718dace5e54c4bd7d..6a8f91b584b88e92d3c53fce42cfc20bfd1ac99b 100644 (file)
@@ -170,7 +170,6 @@ class Links
             $links = Link::encryptLinks($links);
         }
 
-
         self::_correctImageSpecialLinks($links);
     }
 
@@ -236,7 +235,6 @@ class Links
                 }
                 $links[] = $link;
             }
-
             $i++;
         }
 
@@ -318,7 +316,7 @@ class Links
 
     public static function getLinksDir($book_id)
     {
-        return Files::mkdir('/data/extranet/www/fluidbook/books/links/' . $book_id);
+        return Files::mkdir(protected_path('fluidbookpublication/links/' . $book_id));
     }
 
     public static function getLinksVersions($book_id)
@@ -391,17 +389,14 @@ class Links
     public static function addLinksFromPDF($book_id)
     {
         /** @var FluidbookPublication $book */
-        $book = FluidbookPublication::withoutGlobalScopes()->find($book_id);
+        $book = FluidbookPublication::find($book_id);
 
         $booleans = array('video_loop', 'video_auto_start', 'video_controls', 'video_sound_on');
         $numbers = ['left', 'top', 'width', 'height'];
 
         $links = [];
-
-        $pages = $book->getComposition();
-
-        foreach ($pages as $page => $doc) {
-            $fp = Gzip::fopen($book->getDocument($doc[0])->path('p' . $doc[1] . '.csv'));
+        foreach ($book->composition as $page => $doc) {
+            $fp = Gzip::fopen($book->getDocument($page)->path('links/p' . $doc[1] . '.csv'));
             while (true) {
                 $line = fgetcsv($fp, 512, ';', '"');
                 // End of file
@@ -410,7 +405,7 @@ class Links
                 }
 
                 // Commentaire || ligne vide
-                if (substr($line[0], 0, 1) == '#' || is_null($line[0])) {
+                if (str_starts_with($line[0], '#') || is_null($line[0])) {
                     continue;
                 }
 
@@ -419,9 +414,9 @@ class Links
                 $k = 0;
                 foreach ($cols as $col => $default) {
                     if (isset($line[$k])) {
-                        if (in_array($k, $numbers)) {
+                        if (in_array($col, $numbers)) {
                             $link[$col] = (float)str_replace(',', '.', $line[$k]);
-                        } else if (in_array($k, $booleans)) {
+                        } else if (in_array($col, $booleans)) {
                             $link[$col] = ($line[$k] == '1');
                         } else {
                             $link[$col] = $line[$k];
@@ -445,7 +440,7 @@ class Links
             fclose($fp);
         }
 
-        self::saveLinksInFile($book_id, backpack_user()->id, 'Links imported from PDF', $links);
+        self::saveLinksInFile($book_id, backpack_user() ? backpack_user()->id : 0, 'Links imported from PDF', $links);
     }
 
     public static function getLinksAndRulersFromExcelFile($path, &$links, &$rulers)
@@ -460,7 +455,7 @@ class Links
         $characters = '0123456789abcdefghijklmnopqrstuvwxyz';
         $randstring = '';
         for ($i = 0; $i < 12; $i++) {
-            $randstring = $characters[rand(0, 35)];
+            $randstring .= $characters[rand(0, 35)];
         }
         return $randstring;
     }
index dab83687dd77aad547cf68906921692c1397c4c5..44667a345a8dc9bb87129772d8ac2503a40f2957 100644 (file)
@@ -198,10 +198,6 @@ class FluidbookCompiler extends Base implements CompilerInterface
     public $z = 3;
     protected $_lottieIDByHash = [];
 
-    /**
-     * @var FluidbookPublication
-     */
-    public $book;
     public $pages;
     public $theme;
     public $devversion;
@@ -2212,7 +2208,7 @@ height="0" width="0" style="display:none;visibility:hidden"></iframe></noscript>
         if ($this->fluidbookSettings->tabsHTML5 != '' && file_exists($this->wdir . '/' . $this->fluidbookSettings->tabsHTML5)) {
             $ext = Files::getExtension($this->fluidbookSettings->tabsHTML5);
             if ($ext === 'zip') {
-                $links[] = [
+                $links['tabs'] = [
                     'page' => 'background',
                     'top' => 0,
                     'left' => 0,
@@ -2382,7 +2378,7 @@ height="0" width="0" style="display:none;visibility:hidden"></iframe></noscript>
                             'height' => 100,
                             'type' => 26,
                             'to' => $from,
-                            'uid' => Link::generateUID()
+                            'uid' => Links::generateUID()
                         ];
                         $anchorExists[$from] = $anchor;
                         $links[] = $anchor;
@@ -2390,7 +2386,7 @@ height="0" width="0" style="display:none;visibility:hidden"></iframe></noscript>
                         if (!isset($anchorExists[$from]) && isset($anchorExists[$to])) {
                             $anchor = $anchorExists[$to];
                             $anchor['to'] = $from;
-                            $anchor['uid'] = Link::generateUID();
+                            $anchor['uid'] = Links::generateUID();
                             $anchorExists[$from] = $anchor;
                             $links[] = $anchor;
                         }
@@ -2441,7 +2437,7 @@ height="0" width="0" style="display:none;visibility:hidden"></iframe></noscript>
             }
 
             foreach ($linksToAdd as $lta) {
-                /** @var $lta wsLink */
+                /** @var $lta Link */
                 // Keep this line because some properties of the link (like blend mode) are parsed with this function
                 $c = $lta->getHTMLContainer();
                 $css[] = $lta->getCSSContainer();
@@ -2491,7 +2487,7 @@ height="0" width="0" style="display:none;visibility:hidden"></iframe></noscript>
         }
 
 
-        $allpages = range(0, $this->fluidbookSettings->pages + 1);
+        $allpages = range(0, $this->getFluidbook()->getPagesNumber() + 1);
         if ($this->fluidbookSettings->themeEnableAfterSearch) {
             $allpages[] = 'aftersearch';
         }
index df7b4a89284da6be34f03cb44fa69f9b90accbf6..c844536a9848a4f6db894b5b9fa0c46555b3dd35 100644 (file)
@@ -58,7 +58,7 @@
         cursor: text
         font-size: 13px
         position: relative
-        top: -9px
+        top: 2px
         user-select: none
         margin: 0 8px
         font-weight: 600