From 4b69fa3da5d537ffd68bbf686292ecdaff796c71 Mon Sep 17 00:00:00 2001 From: Vincent Vanwaelscappel Date: Fri, 10 Feb 2023 15:48:20 +0100 Subject: [PATCH] wip #5721 @1 --- .docker/docker-compose.yml | 2 ++ .../Commands/FluidbookLinksFromPDF.php | 20 ++++++++++++++++ app/Fluidbook/Links.php | 23 ++++++++----------- app/Jobs/FluidbookCompiler.php | 14 ++++------- resources/linkeditor/style/inc/_toolbar.sass | 2 +- 5 files changed, 37 insertions(+), 24 deletions(-) create mode 100644 app/Console/Commands/FluidbookLinksFromPDF.php diff --git a/.docker/docker-compose.yml b/.docker/docker-compose.yml index 8bea06a33..2f868d7e3 100644 --- a/.docker/docker-compose.yml +++ b/.docker/docker-compose.yml @@ -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 index 000000000..3a5eae929 --- /dev/null +++ b/app/Console/Commands/FluidbookLinksFromPDF.php @@ -0,0 +1,20 @@ +argument('id')); + } + +} diff --git a/app/Fluidbook/Links.php b/app/Fluidbook/Links.php index c94a86f8e..6a8f91b58 100644 --- a/app/Fluidbook/Links.php +++ b/app/Fluidbook/Links.php @@ -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; } diff --git a/app/Jobs/FluidbookCompiler.php b/app/Jobs/FluidbookCompiler.php index dab83687d..44667a345 100644 --- a/app/Jobs/FluidbookCompiler.php +++ b/app/Jobs/FluidbookCompiler.php @@ -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"> 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"> '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"> 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"> } 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"> } - $allpages = range(0, $this->fluidbookSettings->pages + 1); + $allpages = range(0, $this->getFluidbook()->getPagesNumber() + 1); if ($this->fluidbookSettings->themeEnableAfterSearch) { $allpages[] = 'aftersearch'; } diff --git a/resources/linkeditor/style/inc/_toolbar.sass b/resources/linkeditor/style/inc/_toolbar.sass index df7b4a892..c844536a9 100644 --- a/resources/linkeditor/style/inc/_toolbar.sass +++ b/resources/linkeditor/style/inc/_toolbar.sass @@ -58,7 +58,7 @@ cursor: text font-size: 13px position: relative - top: -9px + top: 2px user-select: none margin: 0 8px font-weight: 600 -- 2.39.5