namespace Fluidbook\Tools\Compiler;
+use Cubist\Util\Data;
use Cubist\Util\Files\Files;
use Cubist\Util\Files\VirtualDirectory;
use Cubist\Util\PHP;
use Illuminate\Queue\Jobs\SyncJob;
use Illuminate\Queue\SerializesModels;
use JsonException;
-use stdClass;
class Compiler implements ShouldQueue, ShouldBeUnique, CompilerInterface
{
protected $out;
/**
- * @var stdClass
+ * @var Data
*/
public $config;
}
}
- public function getVirtualDirectory()
+ public function getVirtualDirectory() : VirtualDirectory
{
return $this->vdir;
}
{
// 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);
+ }
}
namespace Fluidbook\Tools\Compiler;
+use Cubist\Util\Files\VirtualDirectory;
+
interface CompilerInterface
{
public function addContentLock($page, $unlockConditions = '');
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;
}
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);
}
}
*/
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 ';
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),
{
$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 {
$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';
$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);
}
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 .= '}';
}
{
public function getDepth()
{
- if ($this->compiler->config->inlineSlideshowLibrary === 'dummy') {
+ if ($this->compiler->getSetting('inlineSlideshowLibrary', 'dummy') === 'dummy') {
$this->defaultZIndex = 30;
}
return parent::getDepth();
/**
*
- * @var Compiler
+ * @var CompilerInterface
*/
public $compiler;
return stristr($url, 'scorm');
}
+ /**
+ * @param $id string
+ * @param $init array
+ * @param $compiler CompilerInterface
+ */
public function __construct($id, $init, &$compiler)
{
$this->_init = $init;
$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;
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', ''));
}
}
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;
$y = $attributes['y'];
$w = $attributes['width'];
$h = $attributes['height'];
- $bookwidth = round($compiler->config->width);
+ $bookwidth = round($compiler->getSetting('width'));
//error_log("--- Book Width: $bookwidth ---");
$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']) {
$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);
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;