From 829cad3cf525439b9bb3b02a69d9c155bd4c153c Mon Sep 17 00:00:00 2001 From: Vincent Vanwaelscappel Date: Tue, 29 Aug 2023 10:59:09 +0200 Subject: [PATCH] wip #5929 @0.75 --- src/Links/Link.php | 153 ++++++++++++++++++++++++++------------- src/Links/LottieLink.php | 67 +++++++++++++++++ 2 files changed, 170 insertions(+), 50 deletions(-) create mode 100644 src/Links/LottieLink.php diff --git a/src/Links/Link.php b/src/Links/Link.php index 007f86e..ef9b44e 100644 --- a/src/Links/Link.php +++ b/src/Links/Link.php @@ -16,7 +16,8 @@ use Fluidbook\Tools\Compiler\CompilerInterface; use SodiumException; use stdClass; -class Link { +class Link +{ const WEB_INFOS = 1; const PRODUCT = 1; @@ -65,6 +66,7 @@ class Link { const FLIPCARD = 41; const PDF = 42; const TEXT_POPUP = 43; + const LOTTIE = 44; protected static string|false|null $_linksKey = null; @@ -144,7 +146,8 @@ class Link { * @param CompilerInterface $compiler * @return Link */ - public static function getInstance($id, $init, &$compiler) { + public static function getInstance($id, $init, &$compiler) + { $init = ArrayUtil::asArray($init); static::normalizeAttributes($init); @@ -211,6 +214,8 @@ class Link { case static::HTML5MULTIMEDIA: case static::MULTIMEDIA: return self::getMultimediaInstance($id, $init, $compiler); + case static::LOTTIE: + return new LottieLink($id, $init, $compiler); case static::STATSTAG: return new StatsTagLink($id, $init, $compiler); case static::PHONE: @@ -288,7 +293,8 @@ class Link { } - public static function normalizeAttributes(&$a) { + public static function normalizeAttributes(&$a) + { $numbers = ['left', 'top', 'rot', 'width', 'height']; foreach ($a as $k => $v) { if (in_array($k, $numbers)) { @@ -305,11 +311,13 @@ class Link { } } - public function getSurface() { + public function getSurface() + { return $this->width * $this->height; } - public static function normalizeInlineIntegration($inline) { + public static function normalizeInlineIntegration($inline) + { if ($inline == '1' || $inline === 'true' || $inline === true) { return 'inline'; } else if (!$inline || $inline === 'false') { @@ -318,7 +326,8 @@ class Link { return $inline; } - public static function parseExtras($extras, $normalizeKey = false) { + public static function parseExtras($extras, $normalizeKey = false) + { $extras = trim($extras); if ($extras === '') { return []; @@ -345,7 +354,8 @@ class Link { return $res; } - public static function parseAnimations($animations) { + public static function parseAnimations($animations) + { $anims = explode('---', $animations); $res = []; @@ -371,7 +381,8 @@ class Link { return $res; } - public static function replaceCustomURL($url) { + public static function replaceCustomURL($url) + { $url = trim($url); if (strpos($url, 'custom:') === 0) { $e = explode(':', $url, 2); @@ -381,7 +392,8 @@ class Link { return $url; } - public static function getMultimediaInstance($id, $init, &$compiler) { + public static function getMultimediaInstance($id, $init, &$compiler) + { if ($init['to'] == '') { return null; } @@ -405,11 +417,13 @@ class Link { return null; } - public static function isScorm($linkData) { + public static function isScorm($linkData) + { return (isset($linkData['scorm']) && $linkData['scorm']) || (self::_isScormLink($linkData['to'])); } - protected static function _isScormLink($url) { + protected static function _isScormLink($url) + { if (strpos($url, 'http://') >= 0 || strpos($url, 'https://') > 0) { return false; } @@ -421,7 +435,8 @@ class Link { * @param $init array * @param $compiler CompilerInterface */ - public function __construct($id, $init, &$compiler) { + public function __construct($id, $init, &$compiler) + { $this->_init = $init; foreach ($init as $k => $v) { @@ -456,18 +471,21 @@ class Link { /** * @param int $initialOrder */ - public function setInitialOrder(int $initialOrder): void { + public function setInitialOrder(int $initialOrder): void + { $this->initialOrder = $initialOrder; } /** * @return int */ - public function getInitialOrder(): int { + public function getInitialOrder(): int + { return $this->initialOrder; } - public function getDepth() { + public function getDepth() + { if ($this->zindex == -1 || null === $this->zindex || !$this->zindex) { return $this->defaultZIndex; } @@ -477,7 +495,8 @@ class Link { return $this->zindex; } - public function getTooltipAttribute($t = null) { + public function getTooltipAttribute($t = null) + { if (null === $t) { $t = $this->getTooltip(); } @@ -491,19 +510,22 @@ class Link { } } - public function isOnNormalPage() { + public function isOnNormalPage() + { // $this->page is normally an integer but it can also be a string (eg. background / aftersearch) return is_int($this->page) || preg_match('/^\d+$/', $this->page, $matches); } - public function overlapDoublePage() { + public function overlapDoublePage() + { if (!$this->isOnNormalPage()) { return false; } return ($this->page % 2 == 0 && ($this->left + $this->width) > $this->compiler->getWidthForLinks()); } - public function getRightClone() { + public function getRightClone() + { $res = clone $this; $res->page++; $res->left -= $this->compiler->getWidthForLinks(); @@ -513,15 +535,18 @@ class Link { return $res; } - public function init() { + public function init() + { } - public function getDefaultTooltip() { + public function getDefaultTooltip() + { return false; } - public function getTooltip() { + public function getTooltip() + { if (!$this->tooltip) { if (!$this->getDefaultTooltip()) { return ''; @@ -532,21 +557,24 @@ class Link { } - public function getHTMLContainer() { + public function getHTMLContainer() + { if (null === $this->_htmlContainer) { $this->_htmlContainer = $this->_getHTMLContainer(); } return $this->_htmlContainer; } - protected function _getHTMLContainer() { + protected function _getHTMLContainer() + { $addContent = $this->getAdditionnalContent(); $attached = $this->attached ? ' data-attached="' . $this->attached . '" ' : ''; return '
' . $this->getHTMLContent() . '
'; } - public function getHTMLContainerClass() { + public function getHTMLContainerClass() + { $res = trim('link ' . $this->class); if ((int)$this->page % 2 == 1) { $res .= ' odd'; @@ -558,11 +586,13 @@ class Link { return $res; } - public function getHTMLContent() { + public function getHTMLContent() + { return ''; } - public function getAdditionnalContent() { + public function getAdditionnalContent() + { $res = ''; if ($this->role !== '') { $res .= ' role="' . $this->role . '"'; @@ -585,7 +615,8 @@ class Link { } - public function getClasses() { + public function getClasses() + { $res = array(); if (isset($this->image_rollover) && $this->image_rollover != 'none') { @@ -594,19 +625,23 @@ class Link { return $res; } - public function copyExternalFile($file, $video = false) { + public function copyExternalFile($file, $video = false) + { $this->compiler->copyLinkFile($file, 'data/links/', $video); } - public function copyExternalDir($dir, $dest = 'data/links') { + public function copyExternalDir($dir, $dest = 'data/links') + { $this->compiler->copyLinkDir($dir, $dest); } - public function unzipFile($file, $junkPaths = false) { + public function unzipFile($file, $junkPaths = false) + { return $this->compiler->unzipFile($file, false, null, $junkPaths); } - public function getCssScale() { + public function getCssScale() + { if (is_numeric($this->page) || is_int($this->page)) { return $this->compiler->getLinkScale(); } else { @@ -614,27 +649,32 @@ class Link { } } - public function getCSSZIndex() { + public function getCSSZIndex() + { $zindex = $this->getAddZIndex() + (($this->getDepth() + 1) * 10000) - min(9999, max(1, round(9999 * (($this->width * $this->height) / $this->compiler->getBookSurface())))); return 'z-index:' . $zindex . ';'; } - public function getAddZIndex() { + public function getAddZIndex() + { return $this->addzindex; } - public function moveOnEvenPage() { + public function moveOnEvenPage() + { return false; } - public function getCSSContainer() { + public function getCSSContainer() + { if (null === $this->_cssContainer) { $this->_cssContainer = $this->_getCSSContainer(); } return $this->_cssContainer; } - protected function _getCSSContainer() { + protected function _getCSSContainer() + { if ($this->moveOnEvenPage()) { $this->page--; $this->left += $this->compiler->getWidth(); @@ -679,15 +719,18 @@ class Link { return $css; } - public function getCSS() { + public function getCSS() + { return ''; } - public function keep() { + public function keep() + { return false; } - public static function getUniversalLocation($loc, $css = false) { + public static function getUniversalLocation($loc, $css = false) + { $datas = parse_url($loc); if ((isset($datas['scheme']) && !is_null($datas['scheme'])) || strpos($loc, '#') === 0) { @@ -701,19 +744,23 @@ class Link { } } - public function isOutsidePage() { + public function isOutsidePage() + { return $this->top > $this->compiler->getHeightForLinks($this->page) || $this->left > $this->compiler->getWidthForLinks($this->page); } - public function ignore() { + public function ignore() + { return false; } - public function getConfigZIP($d) { + public function getConfigZIP($d) + { return $this->compiler->getConfigZIP($d); } - public function getConfigHTML($d, $html) { + public function getConfigHTML($d, $html) + { $c = file_get_contents($this->compiler->working_path($html)); $res = array('width' => $this->video_width, 'height' => $this->video_height); if (stristr($c, '
')) { @@ -728,7 +775,8 @@ class Link { return array_merge($res, $r); } - public function getConfigOAM($d) { + public function getConfigOAM($d) + { $x = simplexml_load_string(file_get_contents($d . '/config.xml')); $config = (string)$x->oamfile['src']; $config = str_replace('/Assets', '', $d . '/' . $config); @@ -753,7 +801,8 @@ class Link { return $res; } - public static function _getLinkKey() { + public static function _getLinkKey() + { if (self::$_linksKey === null) { self::$_linksKey = base64_decode('o2p2yYGI8yMEHf+Y5/e6NdTINbbXg3NIo8BODgdhPxI='); } @@ -763,7 +812,8 @@ class Link { /** * @throws \SodiumException */ - public static function decryptLink($link) { + public static function decryptLink($link) + { if (!in_array($link['type'], self::$_encryptedTypes)) { return $link; } @@ -782,7 +832,8 @@ class Link { return $link; } - public static function decryptLinks($links) { + public static function decryptLinks($links) + { $res = []; foreach ($links as $key => $link) { @@ -792,7 +843,8 @@ class Link { } - public static function encryptLinks($links) { + public static function encryptLinks($links) + { $res = []; foreach ($links as $key => $link) { $res[$key] = self::encryptLinkAttrs($link); @@ -803,7 +855,8 @@ class Link { /** * @throws SodiumException */ - public static function encryptLinkAttrs($link) { + public static function encryptLinkAttrs($link) + { if (!isset($link['type']) || !in_array($link['type'], self::$_encryptedTypes)) { return $link; } diff --git a/src/Links/LottieLink.php b/src/Links/LottieLink.php new file mode 100644 index 0000000..9e0903d --- /dev/null +++ b/src/Links/LottieLink.php @@ -0,0 +1,67 @@ +_content == '') { + $ext = files::getExtension($this->to); + + if ($ext === 'zip') { + $d = $this->unzipFile($this->to, false); + $this->_config = $this->getConfigZIP($d['dir']); + $this->copyExternalDir($d['dir'], $d['fdir']); + if (file_exists($d['dir'] . '/index.html')) { + $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->getVirtualDirectory()->file_put_contents($d['fdir'] . '/' . $this->_config['lowDef'], $html); + } + } elseif ($ext === 'html') { + $fdir = 'data/links'; + $dir = $fdir; + + $d = array('fdir' => $fdir, 'dir' => $dir); + $this->compiler->getVirtualDirectory()->copy($this->compiler->working_path($this->to), $d['dir'] . '/' . $this->to); + $this->_config = $this->getConfigHTML($d['dir'], $this->to); + $this->copyExternalFile($d['dir'] . '/' . $this->to); + } + if ($this->_config['width'] == 0) { + $this->_config['width'] = $this->width; + } + if ($this->_config['height'] == 0) { + $this->_config['height'] = $this->height; + } + + $res = ''; + $s = $this->in_popup ? 1 : $this->getCssScale(); + if ($this->_config['html']) { + $this->_url = $d['fdir'] . '/' . $this->_config['html']; + if ($this->extra) { + $this->_url .= '?' . $this->extra; + } + + $iw = $this->_config['width']; + $ih = $this->_config['height']; + $res = '
'; + $res .= ''; + } + $this->_content = $res; + } + return $this->_content; + } +} -- 2.39.5