]> _ Git - fluidbook_tools.git/commitdiff
wip #4751 @0.5
authorVincent Vanwaelscappel <vincent@cubedesigners.com>
Tue, 5 Oct 2021 13:26:54 +0000 (15:26 +0200)
committerVincent Vanwaelscappel <vincent@cubedesigners.com>
Tue, 5 Oct 2021 13:26:54 +0000 (15:26 +0200)
.idea/fluidbook_tools.iml
src/Compiler/Compiler.php
src/Compiler/Links.php
src/Links/DownloadPortionLink.php
src/Links/FileLink.php
src/Links/HTMLMultimediaLink.php
src/Links/InlineSlideshowLink.php
src/Links/Link.php
src/Links/SlideshowLink.php
src/Links/StatsTagLink.php
src/Links/VideoLink.php

index b2be28e8b76055b66a60de223d1e2e5ea90c074a..f942f8f7ccff1ef772b6d0141499b7622c8674e8 100644 (file)
@@ -5,8 +5,6 @@
     <output-test url="file://$MODULE_DIR$/out/test/fluidbook_tools" />
     <exclude-output />
     <content url="file://$MODULE_DIR$">
-      <sourceFolder url="file://$MODULE_DIR$/resources/tools/fwstk/project_resources" type="java-resource" />
-      <sourceFolder url="file://$MODULE_DIR$/resources/tools/fwstk/src" isTestSource="false" />
       <sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" packagePrefix="Fluidbook\Tools\" />
       <excludeFolder url="file://$MODULE_DIR$/vendor/composer" />
       <excludeFolder url="file://$MODULE_DIR$/vendor/brick/math" />
index ce89fe7995018b446c45578e5df2aa3b39deb9f8..56750179c659efaf836f1532617c2848f07c934c 100644 (file)
@@ -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()
+    {
 
+    }
 }
index 0044da6470689934e0e9903d68550ba5731268cf..5a01187576c413b9f2e86f63b7d84748f394f60b 100644 (file)
@@ -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);
+            }
+        }
+    }
 }
index 2f2307364d464b981943812c0e41a91e90cef1f4..522fa2fda603b7998aa0b9799f9ae2b5bf7cdd48 100644 (file)
@@ -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),
index 6c6a626ac6073949c5224d9a6c5496ec13ec6695..7c805d4134c6cda0a5c6373ef9754212176d9051 100644 (file)
@@ -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;
index 1da2864dc5d68c1d101fca97ccc401550479270c..7465a259876ab1484de2446a88e31fda395e2f76 100644 (file)
@@ -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 .= '}';
             }
 
index 45781af9ebe17cb8bb8ce2571c45baebb7fc31cf..0cd188bc25ca327a373505a1628a3e697035d0d3 100644 (file)
@@ -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();
index 16ede57daa89100a6dd42626b795c7c32df68eb0..8eca28af23e6456f2f4c3e0d460dd68f97a32318 100644 (file)
@@ -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) {
index c8f5692a3ff54b0ed904f3134c2f5f6be442f889..3ba4b1c448813834beea92d31558fc929cf93c72 100644 (file)
@@ -118,7 +118,7 @@ class SlideshowLink extends NormalLink
             $res .= '<div class="fb-slideshow-thumbnails splide" id="' . $slideshowID . '_thumbnails">' . $this->_slides($slides, ['show_captions' => false, 'max_height' => $this->thumbnail_height]) . '</div>';
         }
 
-        $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 = '<div class="fb-slideshow-wrapper ' . $lib . ' fb-slideshow-' . $context . '">' . $res . '</div>';
 
         return $res;
index bfa4d052309c8c28067e6c63ecf3c868c704ab00..4ec82b97beff0eab121a2450959b5a9d6de41093 100644 (file)
@@ -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);
     }
 }
index 1cd64f2f2efb1e721f213ad8f80654d73fdcbaf1..bb9c18c7d3188964feaa96a2e49a440933ec6da8 100644 (file)
@@ -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];