--- /dev/null
+<?php
+
+namespace Fluidbook\Tools\Links;
+
+class Link
+{
+
+ public $left;
+ public $top;
+ public $width;
+ public $height;
+ public $page;
+ public $type;
+ public $to;
+ public $image;
+ public $numerotation;
+ public $target;
+ public $interactive;
+ public $video_loop;
+ public $video_sound_on;
+ public $video_controls;
+ public $video_auto_start;
+ public $video_height;
+ public $video_width;
+ public $video_service;
+ public $hidelinksonplay;
+ public $rollover;
+ public $inline;
+ public $in_popup = false;
+ public $display_area;
+ public $read_mode;
+ public $group;
+ public $infobulle;
+ public $blendmode = "normal";
+ public $extra;
+ public $id;
+ public $rot;
+ public $class;
+ public $uid;
+ public $scorm;
+ public $hidden = false;
+ public $defaultZIndex = 70;
+ public $zindex = -1;
+ public $addzindex = 0;
+ public $rightClone = false;
+ public $iframeType = "none";
+ public $border = 0;
+ public $borderColor = '#ffffff';
+ public $maxWidth = 0;
+ public $wdir;
+ public $initialOrder = 0;
+ public $gamifyCoins = 0;
+ public $tooltipColor = null;
+ public $tooltipBackgroundColor = null;
+ protected $role = 'button';
+
+ protected $_init;
+
+ /**
+ *
+ * @var wsHTML5Compiler
+ */
+ public $compiler;
+
+ /**
+ *
+ * @param integer $id
+ * @param stdClass $init
+ * @param wsHTML5Compiler $compiler
+ * @return wsHTML5Link
+ */
+ public static function getInstance($id, $init, &$compiler)
+ {
+ $init = wsLinks::decryptLink($init);
+ $init = CubeIT_Util_Array::asArray($init);
+
+ $init['scorm'] = self::isScorm($init);
+ $init['to'] = self::replaceCustomURL($init['to']);
+
+ switch ($init['type']) {
+ case 1:
+ case 2:
+ return new webLink($id, $init, $compiler);
+ case 3:
+ return new mailLink($id, $init, $compiler);
+ case 5:
+ return new internalLink($id, $init, $compiler);
+ case 4:
+
+ $init['inline'] = self::normalizeInlineIntegration($init['inline']);
+ if ($init['inline'] === 'inline') {
+ $init['inline'] = 'inline';
+ return new videoLink($id, $init, $compiler);
+ } else if ($init['inline'] === 'popup') {
+ $init['inline'] = 'popup';
+ return new videoPopupLink($id, $init, $compiler);
+ } else if ($init['inline'] === 'background_texts') {
+ $init['inline'] = 'background_texts';
+ return new videoBackgroundLink($id, $init, $compiler);
+ }
+
+ case 7:
+ if ($compiler->book->parametres->basketManager === 'Puma') {
+ return new pumaCartLink($id, $init, $compiler);
+ }
+ if ($compiler->book->parametres->basketManager === 'MIF') {
+ return new cartLink($id, $init, $compiler);
+ }
+ switch ($compiler->book->parametres->customLinkClass) {
+ case 'WescoLink':
+ return new wescoLink($id, $init, $compiler);
+ case 'HaguenauManifLink':
+ return new haguenauManifLink($id, $init, $compiler);
+ case 'FLFLink':
+ return new flfLink($id, $init, $compiler);
+ case 'InpesPopinLink':
+ return new inpesPopinLink($id, $init, $compiler);
+ case 'PierronLink':
+ return new pierronLink($id, $init, $compiler);
+ case 'WescoSalesLink':
+ return new wescoSalesLink($id, $init, $compiler);
+ case 'AtlanticDownloadLink':
+ return new atlanticDownloadLink($id, $init, $compiler);
+ case 'MiraklEaster2021':
+ return new miraklEaster2021Link($id, $init, $compiler);
+ default :
+ return customLink::getCustomInstance($id, $init, $compiler);
+ }
+ case 8:
+ case 9:
+ return null;
+ case 10:
+ $init['inline'] = self::normalizeInlineIntegration($init['inline']);
+ if ($init['inline'] === 'popup') {
+ return new webVideoPopupLink($id, $init, $compiler);
+ }
+ return new webVideoLink($id, $init, $compiler);
+ case 11:
+ return new actionLink($id, $init, $compiler);
+ case 12:
+ if ($compiler->book->parametres->basketManager === 'Puma' || $compiler->book->parametres->basketManager === 'MIF' || $compiler->book->parametres->basketManager === 'Flexipan') {
+ return new zoomProductLink($id, $init, $compiler);
+ }
+ if ($compiler->book->parametres->product_zoom_references !== '') {
+ return new zoomProductLink($id, $init, $compiler);
+ }
+ switch ($compiler->book->parametres->basketManager) {
+ case 'GrandVision':
+ return new grandVisionCartLink($id, $init, $compiler);
+ case 'JoueclubWishlist':
+ return new JoueclubWishlistLink($id, $init, $compiler);
+ case 'Remarkable':
+ return new remarkableCartLink($id, $init, $compiler);
+ case 'ZoomProductLink':
+ return new zoomProductLink($id, $init, $compiler);
+ default :
+ return new cartLink($id, $init, $compiler);
+ }
+ case 13: // zoom area
+ return new zoomLink($id, $init, $compiler);
+ case 14:
+ return new colorLink($id, $init, $compiler);
+ case 15:
+ if (stristr($init['to'], '.zip')) {
+ return new inlineSlideshowLink($id, $init, $compiler);
+ }
+ return new imageLink($id, $init, $compiler);
+ case 16:
+ return new fileLink($id, $init, $compiler);
+ case 17:
+
+ $init['inline'] = self::normalizeInlineIntegration($init['inline']);
+ if ($init['inline'] === 'inline') {
+ return new audioLink($id, $init, $compiler);
+ }
+ return new audioPopupLink($id, $init, $compiler);
+ case 18:
+ $init['inline'] = self::normalizeInlineIntegration($init['inline']);
+ if ($init['inline'] === 'inline') {
+ return new tooltipLink($id, $init, $compiler);
+ }
+ return new textPopupLink($id, $init, $compiler);
+ case 19:
+ break;
+ case 20:
+ $compiler->addBookmarkGroup($init);
+ break;
+ case 21:
+ case 6:
+ return self::getMultimediaInstance($id, $init, $compiler);
+ case 23:
+ return new statsTagLink($id, $init, $compiler);
+ case 24:
+ return new phoneLink($id, $init, $compiler);
+ case 25:
+ $compiler->addAudiodescription($init);
+ break;
+ case 26:
+ case 40:
+ return new anchorLink($id, $init, $compiler);
+ case 27:
+ return new eventOverlayLink($id, $init, $compiler);
+ case 29:
+ return new facebookLikeLink($id, $init, $compiler);
+ case 30:
+ return new slideshowLink($id, $init, $compiler);
+ case 31:
+ $init['inline'] = self::normalizeInlineIntegration($init['inline']);
+ if ($init['inline'] === 'inline') {
+ return new iframeLink($id, $init, $compiler);
+ }
+ return new iframePopupLink($id, $init, $compiler);
+ case 32:
+ return new showLinkLink($id, $init, $compiler);
+ case 33:
+ return new zoomhdLink($id, $init, $compiler);
+ case 34:
+ $compiler->addContentLock($init['page'], $init['to']);
+ break;
+ case 35:
+ return new textLink($id, $init, $compiler);
+ case 36:
+ return new articleLink($id, $init, $compiler);
+ case 37:
+ return new downloadPortionLink($id, $init, $compiler);
+ case 38:
+ if ($init['target'] != 'click') {
+ $compiler->addTriggersLink($init['page'], $init['to']);
+ } else {
+ return new triggerLink($id, $init, $compiler);
+ }
+ break;
+ case 39:
+ return new layerLink($id, $init, $compiler);
+ default:
+ return null;
+ }
+
+
+ }
+
+ public function getSurface()
+ {
+ return $this->width * $this->height;
+ }
+
+ public static function normalizeInlineIntegration($inline)
+ {
+ if ($inline == '1' || $inline === 'true') {
+ return 'inline';
+
+ } else if (!$inline || $inline === 'false') {
+ return 'popup';
+ }
+ return $inline;
+ }
+
+ public static function parseExtras($extras, $normalizeKey = false)
+ {
+ $extras = trim($extras);
+ if ($extras === '') {
+ return [];
+ }
+ $res = [];
+ $lines = CubeIT_Text::splitLines($extras);
+ foreach ($lines as $line) {
+ $e = explode('=', $line);
+ if (count($e) < 2) {
+ continue;
+ }
+ $v = trim($e[1]);
+ // Handle values surronded by quotes
+ if (preg_match('|^\"([^\"]+)\"$|', $v, $matches)) {
+ $v = $matches[1];
+ }
+ $k = trim($e[0]);
+ if ($normalizeKey) {
+ $k = mb_strtolower($k);
+ }
+ $res[$k] = $v;
+ }
+
+ return $res;
+ }
+
+ public static function parseAnimations($animations)
+ {
+ $anims = explode('---', $animations);
+ $res = [];
+
+ foreach ($anims as $animation) {
+ $animation = trim($animation);
+ if (!$animation) {
+ continue;
+ }
+ $extras = self::parseExtras($animation, true);
+ if (count($extras) > 0) {
+ if (!isset($extras['direction'])) {
+ $extras['direction'] = 'right';
+ }
+ if ($extras['direction'] === 'top') {
+ $extras['direction'] = 'up';
+ }
+ if ($extras['direction'] === 'bottom') {
+ $extras['direction'] = 'down';
+ }
+ }
+ $res[] = $extras;
+ }
+ return $res;
+ }
+
+ public static function replaceCustomURL($url)
+ {
+ $url = trim($url);
+ if (strpos($url, 'custom:') === 0) {
+ $e = explode(':', $url, 2);
+ return customLink::_getURL($e[1]);
+ }
+
+ return $url;
+ }
+
+ public static function getMultimediaInstance($id, $init, &$compiler)
+ {
+ if ($init['alternative'] == '') {
+ return null;
+ }
+ $init['inline'] = self::normalizeInlineIntegration($init['inline']);
+
+ $ext = mb_strtolower(files::getExtension($init['alternative']));
+
+ if (in_array($ext, array('oam', 'zip', 'html')) || substr($init['alternative'], 0, 4) == 'http') {
+ if ($init['inline'] === 'inline') {
+ return new htmlMultimediaLink($id, $init, $compiler);
+ } else {
+ return new htmlMultimediaPopupLink($id, $init, $compiler);
+ }
+ } else if (in_array($ext, array('gif', 'jpeg', 'jpg', 'png', 'svg'))) {
+ if ($init['inline'] === 'inline') {
+ return new htmlMultimediaImage($id, $init, $compiler);
+ } else {
+ return new htmlMultimediaPopupImage($id, $init, $compiler);
+ }
+ }
+ return null;
+ }
+
+ public static function isScorm($linkData)
+ {
+ return (isset($linkData['scorm']) && $linkData['scorm']) || (self::_isScormLink($linkData['to']) || (isset($linkData['alternative']) && self::_isScormLink($linkData['alternative'])));
+ }
+
+ protected static function _isScormLink($url)
+ {
+ if (strpos($url, 'http://') >= 0 || strpos($url, 'https://') > 0) {
+ return false;
+ }
+ return stristr($url, 'scorm');
+ }
+
+ public function __construct($id, $init, &$compiler)
+ {
+ $this->_init = $init;
+ foreach ($init as $k => $v) {
+ if ($k == 'extra') {
+ if (CubeIT_Util_Json::isJson($v)) {
+ $v = CubeIT_Util_Json::decode($v);
+ } else if (strpos($v, '=') !== false && strpos($v, '&') !== false) {
+ $vv = $v;
+ $v = [];
+ parse_str($vv, $v);
+ $v = CubeIT_Util_Object::asObject($v);
+ } else if (strpos($v, '=') !== false) {
+ $extras = self::parseExtras($v);
+ foreach ($extras as $extrak => $extrav) {
+ $this->$extrak = $extrav;
+ }
+ continue;
+ }
+ }
+ $this->$k = $v;
+ }
+ if (!$this->video_width) {
+ $this->video_width = $this->width;
+ }
+ if (!$this->video_height) {
+ $this->video_height = $this->height;
+ }
+ if ($this->target == '') {
+ $this->target = '_blank';
+ }
+
+ $this->id = $id;
+ $this->compiler = $compiler;
+ $this->wdir = $this->compiler->wdir;
+ $this->init();
+ }
+
+ /**
+ * @param int $initialOrder
+ */
+ public function setInitialOrder(int $initialOrder): void
+ {
+ $this->initialOrder = $initialOrder;
+ }
+
+ /**
+ * @return int
+ */
+ public function getInitialOrder(): int
+ {
+ return $this->initialOrder;
+ }
+
+ public function getDepth()
+ {
+ if ($this->zindex == -1 || null === $this->zindex || !$this->zindex) {
+ return $this->defaultZIndex;
+ }
+ if ($this->zindex < 10) {
+ return $this->zindex + $this->defaultZIndex;
+ }
+ return $this->zindex;
+ }
+
+ public function getTooltipAttribute($t = null)
+ {
+ if (null === $t) {
+ $t = $this->getTooltip();
+ }
+ if ($t !== false) {
+ $escaped = htmlspecialchars($t, ENT_QUOTES);
+ $tooltip = ' data-tooltip="' . $escaped . '"';
+ $tooltip .= ' aria-label="' . $escaped . '"';
+ return $tooltip;
+ } else {
+ return '';
+ }
+ }
+
+ public function overlapDoublePage()
+ {
+ // $this->page is normally an integer but it can also be a string (eg. background / aftersearch)
+ if (!is_int($this->page)) return false;
+
+ return ($this->page % 2 == 0 && $this->left + $this->width > $this->compiler->width);
+ }
+
+ public function getRightClone()
+ {
+ $res = clone $this;
+ $res->page++;
+ $res->left -= $this->compiler->width;
+ $res->rightClone = true;
+ $res->id .= '_c';
+ $res->init();
+ return $res;
+ }
+
+ public function init()
+ {
+
+ }
+
+ public function getDefaultTooltip()
+ {
+ return false;
+ }
+
+ public function getTooltip()
+ {
+ if ($this->infobulle === null || !$this->infobulle) {
+ if ($this->getDefaultTooltip() === false) {
+ return;
+ }
+ return '~' . $this->getDefaultTooltip();
+ }
+ return $this->infobulle;
+ }
+
+ public function getHTMLContainer()
+ {
+ $addContent = $this->getAdditionnalContent();
+ return '<div class="' . $this->getHTMLContainerClass() . '" data-blendmode="' . $this->blendmode . '" data-hidden="' . $this->hidden . '" data-scorm="' . $this->scorm . '" data-id="' . $this->uid . '" id="l_' . $this->id . '"' . $addContent . '>' . $this->getHTMLContent() . '</div>';
+ }
+
+ public function getHTMLContainerClass()
+ {
+ $res = trim('link ' . $this->class);
+ if ((int)$this->page % 2 == 1) {
+ $res .= ' odd';
+ }
+ if ($this->rightClone) {
+ $res .= ' rightclone';
+ }
+
+ return $res;
+ }
+
+ public function getHTMLContent()
+ {
+ return '';
+ }
+
+ public function getAdditionnalContent()
+ {
+ $res = '';
+ if ($this->role !== '') {
+ $res .= ' role="' . $this->role . '"';
+ }
+ if ($this->maxWidth > 0) {
+ $res .= ' data-max-width="' . $this->maxWidth . '"';
+ }
+ if (!isset($this->popupClose)) {
+ $this->popupClose = 1;
+ }
+ $res .= ' data-popup-close="' . $this->popupClose . '"';
+ if ($this->tooltipBackgroundColor) {
+ $res .= 'data-tooltip-background="' . $this->tooltipBackgroundColor . '" ';
+ }
+ if ($this->tooltipColor) {
+ $res .= 'data-tooltip-color="' . $this->tooltipColor . '" ';
+ }
+
+ return $res;
+
+ }
+
+ public function getClasses()
+ {
+
+ $res = array();
+ if (isset($this->image_rollover) && $this->image_rollover != 'none') {
+ $res[] = 'image_rollover';
+ }
+ return $res;
+ }
+
+ public function copyExternalFile($file, $video = false)
+ {
+ $this->compiler->copyLinkFile($file, 'data/links/', $video);
+ }
+
+ public function copyExternalDir($dir, $dest = 'data/links')
+ {
+ $this->compiler->copyLinkDir($dir, $dest);
+ }
+
+ public function unzipFile($file, $moveAssets = false)
+ {
+ return $this->compiler->unzipFile($file, $moveAssets);
+ }
+
+ public function getCssScale()
+ {
+ if (is_int($this->page)) {
+ return $this->compiler->getLinkScale();
+ } else {
+ return 1;
+ }
+ }
+
+ 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()
+ {
+ return $this->addzindex;
+ }
+
+ public function moveOnEvenPage()
+ {
+ return false;
+ }
+
+ public function getCSSContainer()
+ {
+ if ($this->moveOnEvenPage()) {
+ $this->page--;
+ $this->left += $this->compiler->width;
+ }
+
+ $css = '#l_' . $this->id . '{';
+ $css .= 'left:' . round($this->left * $this->getCssScale()) . 'px;top:' . round($this->top * $this->getCssScale()) . 'px;';
+ $css .= 'width:' . round($this->width * $this->getCssScale()) . 'px;height:' . round($this->height * $this->getCssScale()) . 'px;';
+ $css .= $this->getCSSZIndex();
+ $origin = false;
+ if ($this->rot) {
+ $css .= wsHTML5::writeCSSUA('transform', 'rotate(' . $this->rot . 'deg)');
+ $origin = true;
+ }
+ if (isset($this->skewX)) {
+ $css .= wsHTML5::writeCSSUA('transform', 'skewX(' . $this->skewX . 'deg)');
+ $origin = true;
+ }
+ if (isset($this->skew)) {
+ $css .= wsHTML5::writeCSSUA('transform', 'skew(' . $this->skew . ')');
+ $origin = true;
+ }
+
+ $css .= $this->getCSS();
+ $css .= '}';
+ return $css;
+ }
+
+ public function getCSS()
+ {
+ return '';
+ }
+
+ public function keep()
+ {
+ return false;
+ }
+
+ public static function getUniversalLocation($loc, $css = false)
+ {
+ $datas = parse_url($loc);
+
+ if ((isset($datas['scheme']) && !is_null($datas['scheme'])) || strpos($loc, '#') === 0) {
+
+ return $loc;
+ } else {
+ if ($css) {
+ return '../links/' . $loc;
+ } else {
+ return 'data/links/' . $loc;
+ }
+ }
+ }
+
+ public function getConfigZIP($d)
+ {
+ return $this->compiler->getConfigZIP($d);
+ }
+
+ public function getConfigHTML($d, $html)
+ {
+ $res = array('width' => $this->video_width, 'height' => $this->video_height);
+ $r = array('type' => 'html', 'html' => $html, 'inject' => array(), 'injectcss' => array(), 'injectjs' => array());
+
+ return array_merge($res, $r);
+ }
+
+ 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);
+ $x = simplexml_load_string(file_get_contents($config), 'SimpleXMLElement', LIBXML_NOCDATA);
+ $c = CubeIT_Util_Xml::toObject($x);
+
+ $props = array('default-width' => 'width', 'default-height' => 'height', 'html-page' => 'html');
+
+
+ $res = array('type' => 'oam', 'inject' => array(), 'injectcss' => array(), 'injectjs' => array(), 'content' => trim($c->content), 'name' => $c->_name, 'assets' => array());
+ foreach ($c->properties->property as $p) {
+ if (isset($props[$p->_name])) {
+ $res[$props[$p->_name]] = $p->_defaultValue;
+ }
+ }
+ foreach ($c->require as $r) {
+ if ($r->_type == 'folder') {
+ continue;
+ }
+ $res['assets'][] = $r->_src;
+ }
+ return $res;
+ }
+
+}