]> _ Git - fluidbook_tools.git/commitdiff
wip #5817 @0.5
authorVincent Vanwaelscappel <vincent@cubedesigners.com>
Wed, 22 Mar 2023 09:20:49 +0000 (10:20 +0100)
committerVincent Vanwaelscappel <vincent@cubedesigners.com>
Wed, 22 Mar 2023 09:20:49 +0000 (10:20 +0100)
src/Compiler/CompilerInterface.php
src/Compiler/DummyCompiler.php
src/Compiler/Links.php
src/Links/Link.php
src/Links/SlideshowLink.php
src/SVG/SVGTools.php

index 192910efe98abb4604d86773d1a78e8e06291d4c..36a79f90a685ae345c9c4cf7da9f96840d988bd6 100644 (file)
@@ -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);
 }
index ae368572bdee3cf0e096994929e2ca1d47c3d346..f5e15d614a26cb6a1c778a86645286a0b64a2860 100644 (file)
@@ -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.
+    }
 }
index 59bfc03af26b6f5429b9592004b1dc55d1e7b818..709b15edc769b1b3dab04a7cea80133fad16d55c 100644 (file)
@@ -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`;
index 5fd2d0370e8729cb587c22c20dc10538c4f2f24d..344f055dbd0ff047b9ce0bacd24d6d5d69550ac7 100644 (file)
@@ -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() {
index abb3e7b7058b1a3e057f03813d03b781a06a11e8..58886d27633d1c9b93ed4762bacc0399f28e6696 100644 (file)
@@ -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 .= '<ul class="splide__list">';
 
         foreach ($slides as $slide) {
-
-            $image_path_relative = str_replace($this->compiler->getWorkingDir() . "/", '', $slide['path']);
+            $s=new \SplFileInfo($slide['path']);
+            $image_path_relative = $this->path.'/'.$s->getFilename();
 
             $image_info = Image::getimagesize($slide['path']);
             $image_info_json = ($image_info) ? json_encode(['width' => $image_info[0], 'height' => $image_info[1], 'ratio' => round($image_info[0] / $image_info[1], 4)]) : '';
@@ -201,13 +188,11 @@ class SlideshowLink extends NormalLink
     }
 
 
-    protected function _orderSlidesByFilename($a, $b)
-    {
+    protected function _orderSlidesByFilename($a, $b) {
         return strcmp($a['path'], $b['path']);
     }
 
-    public function keep()
-    {
+    public function keep() {
         return true;
     }
 }
index 4fe4d6ce426e8c50a638d0912dc0efaea21ddca9..64fe55ed28473fd4728aafb487291f29f2961a22 100644 (file)
@@ -31,6 +31,7 @@ class SVGTools {
     public static function optimizeSVGStr($in, $fix = false) {
 
         $dir = Files::mkdir(sys_get_temp_dir() . '/svgopt');
+        `rm $dir/*.svg`;
 
 
         $infile = Files::tempnam($dir, 'svgopt') . '.svg';
@@ -152,5 +153,9 @@ class SVGTools {
         $cli->setArg('s', $source);
         $cli->setArg('d', $dest);
         $cli->execute();
+        if(!stristr($cli->getOutput(),'done')){
+
+            $cli->dd();
+        }
     }
 }