From: Vincent Vanwaelscappel Date: Wed, 22 Mar 2023 09:20:49 +0000 (+0100) Subject: wip #5817 @0.5 X-Git-Url: http://git.cubedesigners.com/?a=commitdiff_plain;h=3f6b70720861477bd6d3073f2e4b65d587315d7e;p=fluidbook_tools.git wip #5817 @0.5 --- diff --git a/src/Compiler/CompilerInterface.php b/src/Compiler/CompilerInterface.php index 192910e..36a79f9 100644 --- a/src/Compiler/CompilerInterface.php +++ b/src/Compiler/CompilerInterface.php @@ -49,4 +49,6 @@ interface CompilerInterface { public function isOnePage(): bool; public function simpleCopyLinkFile($source, $dest); + + public function unzipFile($file, $moveAssets = false, $baseDir = null, $junkPaths = false); } diff --git a/src/Compiler/DummyCompiler.php b/src/Compiler/DummyCompiler.php index ae36857..f5e15d6 100644 --- a/src/Compiler/DummyCompiler.php +++ b/src/Compiler/DummyCompiler.php @@ -99,4 +99,12 @@ class DummyCompiler implements CompilerInterface { public function isOnePage(): bool { // TODO: Implement isOnePage() method. } + + public function simpleCopyLinkFile($source, $dest) { + // TODO: Implement simpleCopyLinkFile() method. + } + + public function unzipFile($file, $moveAssets = false, $baseDir = null, $junkPaths = false) { + // TODO: Implement unzipFile() method. + } } diff --git a/src/Compiler/Links.php b/src/Compiler/Links.php index 59bfc03..709b15e 100644 --- a/src/Compiler/Links.php +++ b/src/Compiler/Links.php @@ -10,13 +10,11 @@ use Fluidbook\Tools\Links\ContentLink; use Fluidbook\Tools\Links\Link; use Nette\Utils\Image; -trait Links -{ +trait Links { /** * @throws \SodiumException */ - public function compileLinks() - { + public function compileLinks() { /** @var Link[] $links */ $links = $this->getLinks(); @@ -26,47 +24,47 @@ trait Links // Custom landing page content -// if ($this->book->parametres->tabsHTML5 != '' && file_exists($this->wdir . '/' . $this->book->parametres->tabsHTML5)) { -// $ext = CubeIT_Files::getExtension($this->book->parametres->tabsHTML5); -// if ($ext === 'zip') { -// $links[] = [ -// 'page' => 'background', -// 'top' => 0, -// 'left' => 0, -// 'width' => 100, -// 'height' => 100, -// 'type' => 6, -// 'to' => $this->book->parametres->tabsHTML5, -// 'alternative' => $this->book->parametres->tabsHTML5, -// 'image' => '', -// 'inline' => 1, -// 'interactive' => 1, -// 'class' => 'tabslink', -// 'uid' => 'tabs', -// ]; -// } else if ($ext === 'svg') { -// $this->vdir->copy($this->wdir . '/' . $this->book->parametres->tabsHTML5, 'data/tabs.svg'); -// $this->config->svgTabs = true; -// $pagesLists = ['tabsPages', 'tabsSections']; -// foreach ($pagesLists as $pagesList) { -// $e = explode(',', $this->book->parametres->$pagesList); -// $list = []; -// foreach ($e as $k => $v) { -// $v = trim($v); -// if ($v === '') { -// continue; -// } -// if ($v !== '-') { -// if ($this->book->parametres->tabsPagesNumbers === 'virtual') { -// $v = $this->virtualToPhysical($v); -// } -// } -// $list[] = $v; -// } -// $this->config->$pagesList = $list; -// } -// } -// } + // if ($this->book->parametres->tabsHTML5 != '' && file_exists($this->wdir . '/' . $this->book->parametres->tabsHTML5)) { + // $ext = CubeIT_Files::getExtension($this->book->parametres->tabsHTML5); + // if ($ext === 'zip') { + // $links[] = [ + // 'page' => 'background', + // 'top' => 0, + // 'left' => 0, + // 'width' => 100, + // 'height' => 100, + // 'type' => 6, + // 'to' => $this->book->parametres->tabsHTML5, + // 'alternative' => $this->book->parametres->tabsHTML5, + // 'image' => '', + // 'inline' => 1, + // 'interactive' => 1, + // 'class' => 'tabslink', + // 'uid' => 'tabs', + // ]; + // } else if ($ext === 'svg') { + // $this->vdir->copy($this->wdir . '/' . $this->book->parametres->tabsHTML5, 'data/tabs.svg'); + // $this->config->svgTabs = true; + // $pagesLists = ['tabsPages', 'tabsSections']; + // foreach ($pagesLists as $pagesList) { + // $e = explode(',', $this->book->parametres->$pagesList); + // $list = []; + // foreach ($e as $k => $v) { + // $v = trim($v); + // if ($v === '') { + // continue; + // } + // if ($v !== '-') { + // if ($this->book->parametres->tabsPagesNumbers === 'virtual') { + // $v = $this->virtualToPhysical($v); + // } + // } + // $list[] = $v; + // } + // $this->config->$pagesList = $list; + // } + // } + // } $pagesOfCustomLinks = []; $hiddenLinks = []; @@ -180,7 +178,7 @@ trait Links $$v[$lta->page][$lta->blendmode] = []; } - array_push($$v[$lta->page][$lta->blendmode],$lta); + array_push($$v[$lta->page][$lta->blendmode], $lta); $i++; } // Make old "aftersearch" link compatible with new "extra" menu option by extracting link URL @@ -236,13 +234,11 @@ trait Links return $css; } - public function getLinks() - { + public function getLinks() { return []; } - protected function getLinksFromPDF() - { + protected function getLinksFromPDF() { $booleans = ['video_loop', 'video_auto_start', 'video_controls', 'video_sound_on']; $numbers = ['left', 'top', 'width', 'height']; @@ -301,13 +297,11 @@ trait Links return $links; } - protected static function makeUID() - { + protected static function makeUID() { return substr(md5(uniqid('fblink_', true)), 2, 8) . '00'; } - protected function _htmlLinkList($list) - { + protected function _htmlLinkList($list) { if (!count($list)) { return []; } @@ -324,8 +318,7 @@ trait Links } - protected function _sortLinksByDepth($a, $b) - { + protected function _sortLinksByDepth($a, $b) { $c = $a->getDepth() - $b->getDepth(); if ($c === 0) { $c = $b->getSurface() - $a->getSurface(); @@ -337,8 +330,7 @@ trait Links return $c; } - public function _sortLinks($a, $b) - { + public function _sortLinks($a, $b) { $priorities = array(26 => -1, 35 => 1); @@ -347,8 +339,7 @@ trait Links return $pb - $pa; } - protected static function base36($val) - { + protected static function base36($val) { $chars = '0123456789abcdefghijklmnopqrstuvwxyz'; $base = strlen($chars); $str = ''; @@ -363,21 +354,18 @@ trait Links /** * @return number */ - public function getLinkScale() - { + public function getLinkScale() { return (float)$this->config->cssScale; } /** * @throws \Exception */ - public function copyLinkDir($source, $dest) - { + public function copyLinkDir($source, $dest) { $this->vdir->copyDirectory($source, $dest); } - public function simpleCopyLinkFile($source, $dest, $addVdir = true) - { + public function simpleCopyLinkFile($source, $dest, $addVdir = true) { if ($addVdir) { $dest = $dest; } @@ -389,8 +377,7 @@ trait Links $this->vdir->copy($source, $dest); } - protected function _fixSVG($source) - { + protected function _fixSVG($source) { $fixed = str_replace('.svg', '.f.svg', $source); if (file_exists($fixed) && filemtime($fixed) >= filemtime($source)) { return $fixed; @@ -411,13 +398,11 @@ trait Links return $fixed; } - public function getVideosFormats() - { + public function getVideosFormats() { return ['mp4', 'jpg']; } - public function copyLinkFile($source, $dest, $video = false) - { + public function copyLinkFile($source, $dest, $video = false) { $types = $this->getVideosFormats(); if ($video) { $e = explode('.', $source); @@ -445,8 +430,7 @@ trait Links /** * @throws Exception */ - public function unzipFile($file, $moveAssets = false, $baseDir = null) - { + public function unzipFile($file, $moveAssets = false, $baseDir = null) { $fdir = is_null($baseDir) ? 'data/links/' . str_replace('.', '_', Files::getFilename($file)) : $baseDir; $dir = $this->wdir . $fdir; @@ -461,7 +445,11 @@ trait Links } - Zip::extract($file, $dir); + $fmtime = filemtime($file); + if (!file_exists($dir) || filemtime($dir) !== $fmtime) { + Zip::extract($file, $dir); + touch($dir, $fmtime); + } if ($moveAssets) { `mv $dir/Assets/* $dir`; diff --git a/src/Links/Link.php b/src/Links/Link.php index 5fd2d03..344f055 100644 --- a/src/Links/Link.php +++ b/src/Links/Link.php @@ -137,7 +137,6 @@ class Link { case 16: return new FileLink($id, $init, $compiler); case 17: - $init['inline'] = self::normalizeInlineIntegration($init['inline']); if ($init['inline'] === 'inline') { return new AudioLink($id, $init, $compiler); @@ -170,7 +169,11 @@ class Link { case 29: return new FacebookLikeLink($id, $init, $compiler); case 30: - return new SlideshowLink($id, $init, $compiler); + if (stristr($init['to'], '.zip')) { + return new SlideshowLink($id, $init, $compiler); + }else{ + return new HTMLMultimediaPopupImage($id, $init, $compiler); + } case 31: $init['inline'] = self::normalizeInlineIntegration($init['inline']); if ($init['inline'] === 'inline') { @@ -508,8 +511,8 @@ class Link { $this->compiler->copyLinkDir($dir, $dest); } - public function unzipFile($file, $moveAssets = false) { - return $this->compiler->unzipFile($file, $moveAssets); + public function unzipFile($file, $junkPaths = false) { + return $this->compiler->unzipFile($file, false, null, $junkPaths); } public function getCssScale() { diff --git a/src/Links/SlideshowLink.php b/src/Links/SlideshowLink.php index abb3e7b..58886d2 100644 --- a/src/Links/SlideshowLink.php +++ b/src/Links/SlideshowLink.php @@ -6,22 +6,20 @@ use Cubist\Util\Files\Files; use Cubist\Util\Graphics\Image; use Cubist\Util\Xml; -class SlideshowLink extends NormalLink -{ +class SlideshowLink extends NormalLink { protected $path; protected $path_absolute; protected $allowed_extensions; protected $thumbnail_height = 80; // Height in px of thumbnail slider - public function getURL() - { + public function getURL() { if (empty($this->to)) { return ''; } - $d = $this->unzipFile($this->to, false); + $d = $this->unzipFile($this->to, true); $this->copyExternalDir($d['dir'], $d['fdir']); $this->path = $d['fdir']; @@ -30,22 +28,15 @@ class SlideshowLink extends NormalLink return '#/slideshow/' . $this->uid; } - public function getAdditionnalContent() - { + public function getAdditionnalContent() { return 'data-slideshow="' . rawurlencode($this->generateSlideshow('popup')) . '" '; } -// public function keep() { -// return true; -// } - - public function getDefaultTooltip() - { + public function getDefaultTooltip() { return 'view slideshow'; } - public function generateSlideshow($context) - { + public function generateSlideshow($context) { $this->compiler->addSlideshowLibrary($context === 'inline'); $this->allowed_extensions = ['jpg', 'png', 'jpeg', 'gif', 'svg']; @@ -83,7 +74,6 @@ class SlideshowLink extends NormalLink // Allow caption font-size to be overridden from XML file $slides_options['caption_size'] = $slideshowData->_captionsize ?? null; - if (isset($slideshowData->image)) { $images = []; if (is_array($slideshowData->image)) { @@ -124,20 +114,18 @@ class SlideshowLink extends NormalLink return $res; } - protected function _getSlidesFromDirectory($path) - { - // Previously this was getting all files recursively but it caused problems - // when there was a __MACOSX sub directory inside the zip file containing - // resource forks for the JPGs. There's no need to support nested directories - // in the zip so we only look at the zip's root directory... - $files = Files::getDirectoryIterator($path); + protected function _getSlidesFromDirectory($path) { + $files = Files::getRecursiveDirectoryIterator($path); $slides = []; foreach ($files as $file) { - /** @var SplFileInfo $file */ + /** @var \SplFileInfo $file */ if (!$file->isFile()) { continue; } + if (stristr($file->getPathname(), '__MACOSX')) { + continue; + } $ext = mb_strtolower($file->getExtension()); if (!in_array($ext, $this->allowed_extensions)) { continue; @@ -149,8 +137,7 @@ class SlideshowLink extends NormalLink return $slides; } - protected function _slides($slides, $options = []) - { + protected function _slides($slides, $options = []) { $default_options = [ 'show_captions' => true, 'caption_size' => null, @@ -163,8 +150,8 @@ class SlideshowLink extends NormalLink $res .= '