]> _ Git - fluidbook_tools.git/commitdiff
wip #5408 @1
authorVincent Vanwaelscappel <vincent@cubedesigners.com>
Mon, 22 Aug 2022 15:11:45 +0000 (17:11 +0200)
committerVincent Vanwaelscappel <vincent@cubedesigners.com>
Mon, 22 Aug 2022 15:11:45 +0000 (17:11 +0200)
14 files changed:
src/Compiler/Compiler.php
src/Compiler/CompilerInterface.php
src/Links/ArticleLink.php
src/Links/AudioLink.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/TooltipLink.php
src/Links/ZoomLink.php
src/Links/ZoomProductLink.php

index d9c76ed2dbfd29180448b5614467266f1d4d743d..7d37b8c413126bea68debc85f6f314cb0cac714d 100644 (file)
@@ -2,6 +2,7 @@
 
 namespace Fluidbook\Tools\Compiler;
 
+use Cubist\Util\Data;
 use Cubist\Util\Files\Files;
 use Cubist\Util\Files\VirtualDirectory;
 use Cubist\Util\PHP;
@@ -18,7 +19,6 @@ use Illuminate\Queue\InteractsWithQueue;
 use Illuminate\Queue\Jobs\SyncJob;
 use Illuminate\Queue\SerializesModels;
 use JsonException;
-use stdClass;
 
 class Compiler implements ShouldQueue, ShouldBeUnique, CompilerInterface
 {
@@ -36,7 +36,7 @@ class Compiler implements ShouldQueue, ShouldBeUnique, CompilerInterface
     protected $out;
 
     /**
-     * @var stdClass
+     * @var Data
      */
     public $config;
 
@@ -75,7 +75,7 @@ class Compiler implements ShouldQueue, ShouldBeUnique, CompilerInterface
         }
     }
 
-    public function getVirtualDirectory()
+    public function getVirtualDirectory() : VirtualDirectory
     {
         return $this->vdir;
     }
@@ -363,4 +363,14 @@ class Compiler implements ShouldQueue, ShouldBeUnique, CompilerInterface
     {
         // TODO: Implement addContentLock() method.
     }
+
+    public function getSetting($key, $default = null)
+    {
+        return $this->config->get($key, $default);
+    }
+
+    public function setSetting($key, $value)
+    {
+        $this->config->set($key, $value);
+    }
 }
index 93bc8c48a61416fa9f7245beb4be44ad8bf24f6b..ae4a3c3dc6b6006d527dee373d9f33dbc7ad1b60 100644 (file)
@@ -2,6 +2,8 @@
 
 namespace Fluidbook\Tools\Compiler;
 
+use Cubist\Util\Files\VirtualDirectory;
+
 interface CompilerInterface
 {
     public function addContentLock($page, $unlockConditions = '');
@@ -13,4 +15,13 @@ interface CompilerInterface
     public function addBookmarkGroup($link);
 
     public function getConfigZIP($d);
+
+    public function getSetting($key, $default = null);
+
+    public function setSetting($key, $value);
+
+    /**
+     * @return VirtualDirectory
+     */
+    public function getVirtualDirectory(): VirtualDirectory;
 }
index 44c3df810882441ec2a11dbcfa2d3e9a49d34240..7ceda71cbe813e58a11fa40dc10828e75713d81a 100644 (file)
@@ -10,9 +10,9 @@ class ArticleLink extends NormalLink
     public function init()
     {
         parent::init();
-        $this->article = $this->compiler->config->articlesList[$this->to];
-        if (!isset($this->compiler->config->articlesList[$this->to]['page'])) {
-            $this->compiler->config->articlesList[$this->to]['page'] = $this->page;
+        $this->article = $this->compiler->getSetting('articlesList.' . $this->to);
+        if (!isset($this->article['page'])) {
+            $this->compiler->setSetting('articlesList.' . $this->to . '.page', $this->page);
         }
     }
 
index 356d53895dbe97a51be9673cc82a5b4ba5fcca67..121ee9a2bf41189b1308b92ffd9fd8261971a7ec 100644 (file)
@@ -37,7 +37,7 @@ class AudioLink extends Link
      */
     public static function makeAudioTag($linkDatas, $w = null, $h = null, $compiler = null)
     {
-        $theme = $compiler->config->audioPlayerTheme;
+        $theme = $compiler->getSetting('audioPlayerTheme');
         $controls = '';
         if ($theme === 'native') {
             $controls = 'controls ';
index 522fa2fda603b7998aa0b9799f9ae2b5bf7cdd48..c072e0712e428296d16846a0546a5597ff86e9e2 100644 (file)
@@ -15,15 +15,15 @@ class DownloadPortionLink extends FileLink
 
     public function getZoomAttributes()
     {
-        $pdf = $this->compiler->config->downloadPortionPDF;
+        $pdf = $this->compiler->getSetting('downloadPortionPDF', '');
         if ($pdf !== '') {
-            $pdf = $this->compiler->wdir . '/' . $this->compiler->config->downloadPortionPDF;
+            $pdf = $this->compiler->wdir . '/' . $pdf;
         }
 
         $res = [
             'id' => $this->id,
             'page' => $this->page,
-            'maxzoom' => $this->compiler->config->downloadPortionZoom,
+            'maxzoom' => $this->compiler->getSetting('downloadPortionZoom', '8'),
             'group' => '',
             'group-count' => 0,
             'width' => round($this->width),
index 7a886a73b481a33c3f7cc225cb4dca2b24eb1cca..d113af632341627212b01f03ee49b94e14c996ed 100644 (file)
@@ -13,12 +13,13 @@ class FileLink extends NormalLink
     {
         $this->copyExternalFile($this->to);
 
-        if ($this->compiler->config->linkFilePrefix && !Url::isDistant($this->to)) {
-            return $this->compiler->config->linkFilePrefix . $this->to;
+        if ($this->compiler->getSetting('linkFilePrefix', '') && !Url::isDistant($this->to)) {
+            return $this->compiler->getSetting('linkFilePrefix') . $this->to;
         }
 
         $res = Link::getUniversalLocation($this->to);
-        if (strpos($this->to, '.pdf') >= 0 && ($this->compiler->config->PDFRenderer === 'pdfjs' || $this->compiler->config->PDFRenderer === 'pdfjs-legacy')) {
+        $renderer = $this->compiler->getSetting('PDFRenderer', 'native');
+        if (strpos($this->to, '.pdf') >= 0 && ($renderer === 'pdfjs' || $renderer === 'pdfjs-legacy')) {
             if (is_int($this->pdfpage)) {
                 $hash = '#page=' . $this->pdfpage;
             } else {
index 7465a259876ab1484de2446a88e31fda395e2f76..8be0da21f43acc60de2bf020ea3c0c214036823c 100644 (file)
@@ -33,7 +33,7 @@ class HTMLMultimediaLink extends Link
                     $html = file_get_contents($d['dir'] . '/index.html');
                     $html = str_replace('var pRatio = window.devicePixelRatio || 1,', 'var pRatio = 0.5,', $html);
                     $this->_config['lowDef'] = 'index_ld.html';
-                    $this->compiler->vdir->file_put_contents($d['fdir'] . '/' . $this->_config['lowDef'], $html);
+                    $this->compiler->getVirtualDirectory()->file_put_contents($d['fdir'] . '/' . $this->_config['lowDef'], $html);
                 }
             } elseif ($ext === 'html') {
                 $fdir = 'data/links';
@@ -41,7 +41,7 @@ class HTMLMultimediaLink extends Link
 
                 $d = array('fdir' => $fdir, 'dir' => $dir);
                 $file = $this->compiler->wdir . '/' . $this->alternative;
-                $this->compiler->vdir->copy($this->compiler->wdir . '/' . $this->alternative, $d['dir'] . '/' . $this->alternative);
+                $this->compiler->getVirtualDirectory()->copy($this->compiler->wdir . '/' . $this->alternative, $d['dir'] . '/' . $this->alternative);
                 $this->_config = $this->getConfigHTML($d['dir'], $this->alternative);
                 $this->copyExternalFile($d['dir'] . '/' . $this->alternative);
             }
@@ -161,16 +161,18 @@ 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->config->OAMChromeFactor != 1) {
+            $oamfactor = $this->compiler->getSetting('OAMChromeFactor', 1);
+            if ($oamfactor != 1) {
                 $css .= '.chrome #l_' . $this->id . '{';
-                $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 .= 'width:' . ($this->_config['width'] * $oamfactor) . 'px;height:' . ($this->_config['height'] * $oamfactor) . 'px;';
+                $css .= CSS::writeCSSUA('transform', 'scale(' . ($sx / $oamfactor) . ',' . ($sy / $oamfactor) . ')');
                 $css .= '}';
             }
-            if ($this->compiler->config->OAMIEFactor != 1) {
+            $this->compiler->getSetting('OAMIEFactor', 1);
+            if ($oamfactor != 1) {
                 $css .= '.msie #l_' . $this->id . '{';
-                $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 .= 'width:' . ($this->_config['width'] * $oamfactor) . 'px;height:' . ($this->_config['height'] * $oamfactor) . 'px;';
+                $css .= CSS::writeCSSUA('transform', 'scale(' . ($sx / $oamfactor) . ',' . ($sy / $oamfactor) . ')');
                 $css .= '}';
             }
 
index 0cd188bc25ca327a373505a1628a3e697035d0d3..df435fbe699ad0f6330717d026bb8915dbfc917b 100644 (file)
@@ -6,7 +6,7 @@ class InlineSlideshowLink extends SlideshowLink
 {
     public function getDepth()
     {
-        if ($this->compiler->config->inlineSlideshowLibrary === 'dummy') {
+        if ($this->compiler->getSetting('inlineSlideshowLibrary', 'dummy') === 'dummy') {
             $this->defaultZIndex = 30;
         }
         return parent::getDepth();
index cb992cf1cddb3764724b9c0ae1cdb9f22a72c9ac..4dcf8496e157a8ac2f9ac0187b587208a0b5ffac 100644 (file)
@@ -70,7 +70,7 @@ class Link
 
     /**
      *
-     * @var Compiler
+     * @var CompilerInterface
      */
     public $compiler;
 
@@ -322,6 +322,11 @@ class Link
         return stristr($url, 'scorm');
     }
 
+    /**
+     * @param $id string
+     * @param $init array
+     * @param $compiler CompilerInterface
+     */
     public function __construct($id, $init, &$compiler)
     {
         $this->_init = $init;
index 5b3b9b8ad0490112a3c7ce6ae8b1aa6f9be30714..35fbf8bf2ac332760355b4993564f5740d2455ef 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->config->popupSlideshowLibrary : $this->compiler->config->inlineSlideshowLibrary;
+        $lib = $context === 'popup' ? $this->compiler->getSetting('popupSlideshowLibrary', 'splide') : $this->compiler->getSetting('inlineSlideshowLibrary', 'dummy');
         $res = '<div class="fb-slideshow-wrapper ' . $lib . ' fb-slideshow-' . $context . '">' . $res . '</div>';
 
         return $res;
index 4ec82b97beff0eab121a2450959b5a9d6de41093..2e5f0fef3823185809b05487b527dfa3dfc66157 100644 (file)
@@ -13,6 +13,6 @@ class StatsTagLink extends Link
 
     public function getHTMLContent()
     {
-        return str_replace('%tag%', $this->to, $this->compiler->config->xiti_page);
+        return str_replace('%tag%', $this->to, $this->compiler->getSetting('xiti_page', ''));
     }
 }
index 9476316c7800569765740309e7a323604ccdda0d..9641cef5e248a8bbb9eecd18523650b9e450ed63 100644 (file)
@@ -25,7 +25,7 @@ class TooltipLink extends NormalLink
         if ($this->tooltipMaxWidth) {
             $res .= ' data-tooltip-maxwidth="' . $this->tooltipMaxWidth . '" ';
         } else {
-            $res .= ' data-tooltip-maxwidth="' . $this->compiler->config->linkTooltipMaxWidth . '" ';
+            $res .= ' data-tooltip-maxwidth="' . $this->compiler->getSetting('linkTooltipMaxWidth',140) . '" ';
         }
         $res .= ' data-tooltip-touch="1" ';
         return $res;
index 044760635c8ba43fc63dae7bb367a2e7c22a6e8f..1ff13bb76434f441780c5c58715fdad3f7644c89 100644 (file)
@@ -121,7 +121,7 @@ class ZoomLink extends NormalLink
         $y = $attributes['y'];
         $w = $attributes['width'];
         $h = $attributes['height'];
-        $bookwidth = round($compiler->config->width);
+        $bookwidth = round($compiler->getSetting('width'));
 
         //error_log("--- Book Width: $bookwidth ---");
 
@@ -133,13 +133,13 @@ class ZoomLink extends NormalLink
             $extractPage = $attributes['page'];
         }
 
-        $cache=storage_path('fluidbook/cache/zoomarea');
+        $cache = storage_path('fluidbook/cache/zoomarea');
 
         $left = Files::tempnam();
         $leftfile = PDF::extractArea($pdfpath,
             $extractPage,
             array('x' => $x, 'y' => $y, 'width' => $w, 'height' => $h),
-            $left, $extractOptions,$cache);
+            $left, $extractOptions, $cache);
 
         if (($x + $w) > $bookwidth) {
             if (!isset($attributes['pdf']) || !$attributes['pdf']) {
@@ -156,7 +156,7 @@ class ZoomLink extends NormalLink
             $rightfile = PDF::extractArea($pdfpath,
                 $extractPage,
                 array('x' => 0, 'y' => $y, 'width' => $diff, 'height' => $h),
-                $right, $extractOptions,$cache);
+                $right, $extractOptions, $cache);
 
             if (!file_exists($rightfile)) {
                 die('Error generating right part ' . $rightfile);
index 4d318eeef48dd4ec519d9db25ecb1a623fbb61d6..334552bffe511fca8f6330fc83882b8f3c190044 100644 (file)
@@ -14,7 +14,7 @@ class ZoomProductLink extends ZoomLink
 
     public function getZoomAttributes()
     {
-        $url = isset($this->compiler->config->product_zoom_references[$this->to]) ? $this->compiler->config->product_zoom_references[$this->to] : '';
+        $url = $this->compiler->getSetting('product_zoom_references.' . $this->to, '');
 
         $res = parent::getZoomAttributes();
         $res['maxzoom'] = $this->maxzoom_default;