use SodiumException;
use stdClass;
-class Link {
+class Link
+{
const WEB_INFOS = 1;
const PRODUCT = 1;
const FLIPCARD = 41;
const PDF = 42;
const TEXT_POPUP = 43;
+ const LOTTIE = 44;
protected static string|false|null $_linksKey = null;
* @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);
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:
}
- 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)) {
}
}
- 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') {
return $inline;
}
- public static function parseExtras($extras, $normalizeKey = false) {
+ public static function parseExtras($extras, $normalizeKey = false)
+ {
$extras = trim($extras);
if ($extras === '') {
return [];
return $res;
}
- public static function parseAnimations($animations) {
+ public static function parseAnimations($animations)
+ {
$anims = explode('---', $animations);
$res = [];
return $res;
}
- public static function replaceCustomURL($url) {
+ public static function replaceCustomURL($url)
+ {
$url = trim($url);
if (strpos($url, 'custom:') === 0) {
$e = explode(':', $url, 2);
return $url;
}
- public static function getMultimediaInstance($id, $init, &$compiler) {
+ public static function getMultimediaInstance($id, $init, &$compiler)
+ {
if ($init['to'] == '') {
return null;
}
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;
}
* @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) {
/**
* @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;
}
return $this->zindex;
}
- public function getTooltipAttribute($t = null) {
+ public function getTooltipAttribute($t = null)
+ {
if (null === $t) {
$t = $this->getTooltip();
}
}
}
- 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();
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 '';
}
- 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 '<div class="' . $this->getHTMLContainerClass() . '" style="mix-blend-mode:' . $this->blendmode . ';" data-blendmode="' . $this->blendmode . '" ' . $attached . ' data-hidden="' . $this->hidden . '" data-scorm="' . $this->scorm . '" data-id="' . $this->uid . '" id="l_' . $this->id . '"' . $addContent . '>' . $this->getHTMLContent() . '</div>';
}
- public function getHTMLContainerClass() {
+ public function getHTMLContainerClass()
+ {
$res = trim('link ' . $this->class);
if ((int)$this->page % 2 == 1) {
$res .= ' odd';
return $res;
}
- public function getHTMLContent() {
+ public function getHTMLContent()
+ {
return '';
}
- public function getAdditionnalContent() {
+ public function getAdditionnalContent()
+ {
$res = '';
if ($this->role !== '') {
$res .= ' role="' . $this->role . '"';
}
- public function getClasses() {
+ public function getClasses()
+ {
$res = array();
if (isset($this->image_rollover) && $this->image_rollover != 'none') {
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 {
}
}
- 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();
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) {
}
}
- 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, '<div id="lottie"></div>')) {
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);
return $res;
}
- public static function _getLinkKey() {
+ public static function _getLinkKey()
+ {
if (self::$_linksKey === null) {
self::$_linksKey = base64_decode('o2p2yYGI8yMEHf+Y5/e6NdTINbbXg3NIo8BODgdhPxI=');
}
/**
* @throws \SodiumException
*/
- public static function decryptLink($link) {
+ public static function decryptLink($link)
+ {
if (!in_array($link['type'], self::$_encryptedTypes)) {
return $link;
}
return $link;
}
- public static function decryptLinks($links) {
+ public static function decryptLinks($links)
+ {
$res = [];
foreach ($links as $key => $link) {
}
- public static function encryptLinks($links) {
+ public static function encryptLinks($links)
+ {
$res = [];
foreach ($links as $key => $link) {
$res[$key] = self::encryptLinkAttrs($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;
}
--- /dev/null
+<?php
+
+namespace Fluidbook\Tools\Links;
+
+use Cubist\Util\CSS;
+use Cubist\Util\Files\Files;
+use Cubist\Util\Json;
+use SplFileInfo;
+
+class LottieLink extends HTMLMultimediaLink
+{
+ protected $role = '';
+ protected $_config = null;
+ protected $_content = '';
+ protected $_url;
+ protected $_externalIframe = false;
+ public $defaultZIndex = 50;
+
+ public function getHTMLContent()
+ {
+ if ($this->_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 = '<div class="mask"></div>';
+ $res .= '<iframe data-scale="' . $s . '" data-width="' . $iw . '" data-height="' . $ih . '" width="' . $iw . '" height="' . $ih . '" src="' . $this->_url . '" frameborder="0" marginwidth="0" marginheight="0" scrolling="no" allowfullscreen mozallowfullscreen="true" webkitallowfullscreen="true" onmousewheel="" style="visibility:hidden;" tabindex="-1" onload="this.style.visibility=\'visible\';"></iframe>';
+ }
+ $this->_content = $res;
+ }
+ return $this->_content;
+ }
+}