From: Vincent Vanwaelscappel Date: Mon, 22 Aug 2022 15:11:45 +0000 (+0200) Subject: wip #5408 @1 X-Git-Url: http://git.cubedesigners.com/?a=commitdiff_plain;h=1425e14673012bdf46889327a7b64eaf217788d9;p=fluidbook_tools.git wip #5408 @1 --- diff --git a/src/Compiler/Compiler.php b/src/Compiler/Compiler.php index d9c76ed..7d37b8c 100644 --- a/src/Compiler/Compiler.php +++ b/src/Compiler/Compiler.php @@ -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); + } } diff --git a/src/Compiler/CompilerInterface.php b/src/Compiler/CompilerInterface.php index 93bc8c4..ae4a3c3 100644 --- a/src/Compiler/CompilerInterface.php +++ b/src/Compiler/CompilerInterface.php @@ -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; } diff --git a/src/Links/ArticleLink.php b/src/Links/ArticleLink.php index 44c3df8..7ceda71 100644 --- a/src/Links/ArticleLink.php +++ b/src/Links/ArticleLink.php @@ -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); } } diff --git a/src/Links/AudioLink.php b/src/Links/AudioLink.php index 356d538..121ee9a 100644 --- a/src/Links/AudioLink.php +++ b/src/Links/AudioLink.php @@ -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 '; diff --git a/src/Links/DownloadPortionLink.php b/src/Links/DownloadPortionLink.php index 522fa2f..c072e07 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->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), diff --git a/src/Links/FileLink.php b/src/Links/FileLink.php index 7a886a7..d113af6 100644 --- a/src/Links/FileLink.php +++ b/src/Links/FileLink.php @@ -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 { diff --git a/src/Links/HTMLMultimediaLink.php b/src/Links/HTMLMultimediaLink.php index 7465a25..8be0da2 100644 --- a/src/Links/HTMLMultimediaLink.php +++ b/src/Links/HTMLMultimediaLink.php @@ -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 .= '}'; } diff --git a/src/Links/InlineSlideshowLink.php b/src/Links/InlineSlideshowLink.php index 0cd188b..df435fb 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->config->inlineSlideshowLibrary === 'dummy') { + if ($this->compiler->getSetting('inlineSlideshowLibrary', 'dummy') === 'dummy') { $this->defaultZIndex = 30; } return parent::getDepth(); diff --git a/src/Links/Link.php b/src/Links/Link.php index cb992cf..4dcf849 100644 --- a/src/Links/Link.php +++ b/src/Links/Link.php @@ -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; diff --git a/src/Links/SlideshowLink.php b/src/Links/SlideshowLink.php index 5b3b9b8..35fbf8b 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->config->popupSlideshowLibrary : $this->compiler->config->inlineSlideshowLibrary; + $lib = $context === 'popup' ? $this->compiler->getSetting('popupSlideshowLibrary', 'splide') : $this->compiler->getSetting('inlineSlideshowLibrary', 'dummy'); $res = '
' . $res . '
'; return $res; diff --git a/src/Links/StatsTagLink.php b/src/Links/StatsTagLink.php index 4ec82b9..2e5f0fe 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->config->xiti_page); + return str_replace('%tag%', $this->to, $this->compiler->getSetting('xiti_page', '')); } } diff --git a/src/Links/TooltipLink.php b/src/Links/TooltipLink.php index 9476316..9641cef 100644 --- a/src/Links/TooltipLink.php +++ b/src/Links/TooltipLink.php @@ -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; diff --git a/src/Links/ZoomLink.php b/src/Links/ZoomLink.php index 0447606..1ff13bb 100644 --- a/src/Links/ZoomLink.php +++ b/src/Links/ZoomLink.php @@ -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); diff --git a/src/Links/ZoomProductLink.php b/src/Links/ZoomProductLink.php index 4d318ee..334552b 100644 --- a/src/Links/ZoomProductLink.php +++ b/src/Links/ZoomProductLink.php @@ -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;