From 84663184d9a6f6419f380c1093311a7cf78f5704 Mon Sep 17 00:00:00 2001 From: Vincent Vanwaelscappel Date: Tue, 5 Oct 2021 15:26:54 +0200 Subject: [PATCH] wip #4751 @0.5 --- .idea/fluidbook_tools.iml | 2 - src/Compiler/Compiler.php | 10 ++++ src/Compiler/Links.php | 77 +++++++++++++++++++++++++++++-- src/Links/DownloadPortionLink.php | 6 +-- src/Links/FileLink.php | 7 ++- src/Links/HTMLMultimediaLink.php | 12 ++--- src/Links/InlineSlideshowLink.php | 2 +- src/Links/Link.php | 1 - src/Links/SlideshowLink.php | 2 +- src/Links/StatsTagLink.php | 2 +- src/Links/VideoLink.php | 4 +- 11 files changed, 101 insertions(+), 24 deletions(-) diff --git a/.idea/fluidbook_tools.iml b/.idea/fluidbook_tools.iml index b2be28e..f942f8f 100644 --- a/.idea/fluidbook_tools.iml +++ b/.idea/fluidbook_tools.iml @@ -5,8 +5,6 @@ - - diff --git a/src/Compiler/Compiler.php b/src/Compiler/Compiler.php index ce89fe7..5675017 100644 --- a/src/Compiler/Compiler.php +++ b/src/Compiler/Compiler.php @@ -2,6 +2,7 @@ namespace Fluidbook\Tools\Compiler; +use Cubist\Util\Files\Files; use Cubist\Util\Files\VirtualDirectory; use Cubist\Util\PHP; use Exception; @@ -49,6 +50,10 @@ class Compiler implements ShouldQueue, ShouldBeUnique */ protected $pages = []; + /** + * @var string + */ + public $wdir; /** * @var string @@ -154,6 +159,8 @@ class Compiler implements ShouldQueue, ShouldBeUnique { start_measure('Compile fluidbook'); + $this->wdir = resource_path('fluidbook/working/'); + Files::mkdir($this->wdir); $this->vdir = new VirtualDirectory($this->out); if ($this->stub !== '') { $this->vdir->copyDirectory($this->stub, '/'); @@ -288,5 +295,8 @@ class Compiler implements ShouldQueue, ShouldBeUnique return $this->getSourceOfPage(1)->getSource()->getDocument()->getHeight(); } + public function addVideoJs() + { + } } diff --git a/src/Compiler/Links.php b/src/Compiler/Links.php index 0044da6..5a01187 100644 --- a/src/Compiler/Links.php +++ b/src/Compiler/Links.php @@ -5,6 +5,7 @@ namespace Fluidbook\Tools\Compiler; use Cubist\Util\ArrayUtil; use Fluidbook\Tools\Links\ContentLink; use Fluidbook\Tools\Links\Link; +use Nette\Utils\Image; trait Links { @@ -205,9 +206,9 @@ trait Links $allpages[] = $linkPage; } - $this->config->links=[]; - $this->config->clinks=[]; - $this->config->ctlinks=[]; + $this->config->links = []; + $this->config->clinks = []; + $this->config->ctlinks = []; foreach ($allpages as $i) { $this->config->links[$i] = $this->_htmlLinkList($pages[$i] ?? []); @@ -358,4 +359,74 @@ trait Links return (float)$this->config->cssScale; } + /** + * @throws \Exception + */ + public function copyLinkDir($source, $dest) + { + $this->vdir->copyDirectory($source, $dest); + } + + public function simpleCopyLinkFile($source, $dest, $addVdir = true) + { + if ($addVdir) { + $dest = $dest; + } + + if (stripos($source, '.svg') !== false) { + $source = $this->_fixSVG($source); + } + + $this->vdir->copy($source, $dest); + } + + protected function _fixSVG($source) + { + $fixed = str_replace('.svg', '.f.svg', $source); + if (file_exists($fixed) && filemtime($fixed) >= filemtime($source)) { + return $fixed; + } + $svg = simplexml_load_string(file_get_contents($source)); + $attr = $svg->attributes(); + if (isset($attr['width'], $attr['height'])) { + copy($source, $fixed); + return $fixed; + } + + $dim = Image::getimagesize($source); + $svg->addAttribute('preserveAspectRatio', 'none'); + $svg->addAttribute('width', $dim[0]); + $svg->addAttribute('height', $dim[1]); + file_put_contents($fixed, $svg->asXML()); + + return $fixed; + } + + public function copyLinkFile($source, $dest, $video = false) + { +// $types = $this->getVideosFormats(); +// if ($video) { +// wsTools::encodeWebVideos($origDir . $source, null, true); +// $e = explode('.', $source); +// array_pop($e); +// $base = implode('.', $e); +// $source = array(); +// foreach ($types as $type) { +// $source[] = $base . '.' . $type; +// } +// } + + if (!is_array($source)) { + $source = array($source); + } + + foreach ($source as $so) { + $s = $this->wdir . $so; + //dd($s,$so,$dest); + if (file_exists($s)) { + $d = $dest . '/' . $so; + $this->simpleCopyLinkFile($s, $d, false); + } + } + } } diff --git a/src/Links/DownloadPortionLink.php b/src/Links/DownloadPortionLink.php index 2f23073..522fa2f 100644 --- a/src/Links/DownloadPortionLink.php +++ b/src/Links/DownloadPortionLink.php @@ -15,15 +15,15 @@ class DownloadPortionLink extends FileLink public function getZoomAttributes() { - $pdf = $this->compiler->book->parametres->downloadPortionPDF; + $pdf = $this->compiler->config->downloadPortionPDF; if ($pdf !== '') { - $pdf = $this->compiler->wdir . '/' . $this->compiler->book->parametres->downloadPortionPDF; + $pdf = $this->compiler->wdir . '/' . $this->compiler->config->downloadPortionPDF; } $res = [ 'id' => $this->id, 'page' => $this->page, - 'maxzoom' => $this->compiler->book->parametres->downloadPortionZoom, + 'maxzoom' => $this->compiler->config->downloadPortionZoom, 'group' => '', 'group-count' => 0, 'width' => round($this->width), diff --git a/src/Links/FileLink.php b/src/Links/FileLink.php index 6c6a626..7c805d4 100644 --- a/src/Links/FileLink.php +++ b/src/Links/FileLink.php @@ -12,13 +12,12 @@ class FileLink extends NormalLink { $this->copyExternalFile($this->to); - if ($this->compiler->book->parametres->linkFilePrefix && !Url::isDistant($this->to)) { - return $this->compiler->book->parametres->linkFilePrefix . $this->to; + if ($this->compiler->config->linkFilePrefix && !Url::isDistant($this->to)) { + return $this->compiler->config->linkFilePrefix . $this->to; } - $res = Link::getUniversalLocation($this->to); - if (strpos($this->to, '.pdf') >= 0 && ($this->compiler->book->parametres->PDFRenderer === 'pdfjs' || $this->compiler->book->parametres->PDFRenderer === 'pdfjs-legacy')) { + if (strpos($this->to, '.pdf') >= 0 && ($this->compiler->config->PDFRenderer === 'pdfjs' || $this->compiler->config->PDFRenderer === 'pdfjs-legacy')) { return 'pdfjs/web/viewer.html?file=' . rawurlencode('../../' . $res); } return $res; diff --git a/src/Links/HTMLMultimediaLink.php b/src/Links/HTMLMultimediaLink.php index 1da2864..7465a25 100644 --- a/src/Links/HTMLMultimediaLink.php +++ b/src/Links/HTMLMultimediaLink.php @@ -161,16 +161,16 @@ class HTMLMultimediaLink extends Link if ($this->_config['type'] === 'oam') { $sx = ($this->width / ($this->_config['width'])) * $this->getCssScale(); $sy = ($this->height / ($this->_config['height'])) * $this->getCssScale(); - if ($this->compiler->book->parametres->OAMChromeFactor != 1) { + if ($this->compiler->config->OAMChromeFactor != 1) { $css .= '.chrome #l_' . $this->id . '{'; - $css .= 'width:' . ($this->_config['width'] * $this->compiler->book->parametres->OAMChromeFactor) . 'px;height:' . ($this->_config['height'] * $this->compiler->book->parametres->OAMChromeFactor) . 'px;'; - $css .= CSS::writeCSSUA('transform', 'scale(' . ($sx / $this->compiler->book->parametres->OAMChromeFactor) . ',' . ($sy / $this->compiler->book->parametres->OAMChromeFactor) . ')'); + $css .= 'width:' . ($this->_config['width'] * $this->compiler->config->OAMChromeFactor) . 'px;height:' . ($this->_config['height'] * $this->compiler->config->OAMChromeFactor) . 'px;'; + $css .= CSS::writeCSSUA('transform', 'scale(' . ($sx / $this->compiler->config->OAMChromeFactor) . ',' . ($sy / $this->compiler->config->OAMChromeFactor) . ')'); $css .= '}'; } - if ($this->compiler->book->parametres->OAMIEFactor != 1) { + if ($this->compiler->config->OAMIEFactor != 1) { $css .= '.msie #l_' . $this->id . '{'; - $css .= 'width:' . ($this->_config['width'] * $this->compiler->book->parametres->OAMIEFactor) . 'px;height:' . ($this->_config['height'] * $this->compiler->book->parametres->OAMIEFactor) . 'px;'; - $css .= CSS::writeCSSUA('transform', 'scale(' . ($sx / $this->compiler->book->parametres->OAMIEFactor) . ',' . ($sy / $this->compiler->book->parametres->OAMIEFactor) . ')'); + $css .= 'width:' . ($this->_config['width'] * $this->compiler->config->OAMIEFactor) . 'px;height:' . ($this->_config['height'] * $this->compiler->config->OAMIEFactor) . 'px;'; + $css .= CSS::writeCSSUA('transform', 'scale(' . ($sx / $this->compiler->config->OAMIEFactor) . ',' . ($sy / $this->compiler->config->OAMIEFactor) . ')'); $css .= '}'; } diff --git a/src/Links/InlineSlideshowLink.php b/src/Links/InlineSlideshowLink.php index 45781af..0cd188b 100644 --- a/src/Links/InlineSlideshowLink.php +++ b/src/Links/InlineSlideshowLink.php @@ -6,7 +6,7 @@ class InlineSlideshowLink extends SlideshowLink { public function getDepth() { - if ($this->compiler->book->parametres->inlineSlideshowLibrary === 'dummy') { + if ($this->compiler->config->inlineSlideshowLibrary === 'dummy') { $this->defaultZIndex = 30; } return parent::getDepth(); diff --git a/src/Links/Link.php b/src/Links/Link.php index 16ede57..8eca28a 100644 --- a/src/Links/Link.php +++ b/src/Links/Link.php @@ -580,7 +580,6 @@ class Link $datas = parse_url($loc); if ((isset($datas['scheme']) && !is_null($datas['scheme'])) || strpos($loc, '#') === 0) { - return $loc; } else { if ($css) { diff --git a/src/Links/SlideshowLink.php b/src/Links/SlideshowLink.php index c8f5692..3ba4b1c 100644 --- a/src/Links/SlideshowLink.php +++ b/src/Links/SlideshowLink.php @@ -118,7 +118,7 @@ class SlideshowLink extends NormalLink $res .= '
' . $this->_slides($slides, ['show_captions' => false, 'max_height' => $this->thumbnail_height]) . '
'; } - $lib = $context === 'popup' ? $this->compiler->book->parametres->popupSlideshowLibrary : $this->compiler->book->parametres->inlineSlideshowLibrary; + $lib = $context === 'popup' ? $this->compiler->config->popupSlideshowLibrary : $this->compiler->config->inlineSlideshowLibrary; $res = '
' . $res . '
'; return $res; diff --git a/src/Links/StatsTagLink.php b/src/Links/StatsTagLink.php index bfa4d05..4ec82b9 100644 --- a/src/Links/StatsTagLink.php +++ b/src/Links/StatsTagLink.php @@ -13,6 +13,6 @@ class StatsTagLink extends Link public function getHTMLContent() { - return str_replace('%tag%', $this->to, $this->compiler->book->parametres->xiti_page); + return str_replace('%tag%', $this->to, $this->compiler->config->xiti_page); } } diff --git a/src/Links/VideoLink.php b/src/Links/VideoLink.php index 1cd64f2..bb9c18c 100644 --- a/src/Links/VideoLink.php +++ b/src/Links/VideoLink.php @@ -62,7 +62,7 @@ class VideoLink extends Link public static function getVideoAttributes($data, $w = null, $h = null, $compiler = null) { - $attr['name'] = videoPopupLink::getBasename($data->to); + $attr['name'] = VideoPopupLink::getBasename($data->to); if (Url::isDistant($data->to)) { $attr['url'] = $data->to; } @@ -80,7 +80,7 @@ class VideoLink extends Link $attr['height'] = $h; } else if (!is_null($compiler) && Url::isLocal($data->to)) { // Get video dimensions from thumbnail if possible (locally uploaded files) - $path = $compiler->wdir . '/' . $data->to; + $path = file_exists($data->to) ? $data->to : $compiler->wdir . '/' . $data->to; $e = explode(',', `ffprobe -v error -select_streams v:0 -show_entries stream=width,height -of csv=p=0 $path`); $attr['width'] = $e[0]; $attr['height'] = $e[1]; -- 2.39.5