]> _ Git - cubeextranet.git/commitdiff
WIP #3734 @8
authorstephen@cubedesigners.com <stephen@cubedesigners.com@f5622870-0f3c-0410-866d-9cb505b7a8ef>
Wed, 1 Jul 2020 17:02:39 +0000 (17:02 +0000)
committerstephen@cubedesigners.com <stephen@cubedesigners.com@f5622870-0f3c-0410-866d-9cb505b7a8ef>
Wed, 1 Jul 2020 17:02:39 +0000 (17:02 +0000)
inc/ws/Util/html5/slideshow/class.ws.html5.links.php [new file with mode: 0644]

diff --git a/inc/ws/Util/html5/slideshow/class.ws.html5.links.php b/inc/ws/Util/html5/slideshow/class.ws.html5.links.php
new file mode 100644 (file)
index 0000000..1ca6ed5
--- /dev/null
@@ -0,0 +1,2298 @@
+<?php
+
+class wsHTML5Link
+{
+
+    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 $rollover;
+    public $inline;
+    public $in_popup = false;
+    public $display_area;
+    public $read_mode;
+    public $group;
+    public $infobulle;
+    public $extra;
+    public $id;
+    public $rot;
+    public $class;
+    public $uid;
+    public $scorm;
+    public $hidden = false;
+    public $zindex = 4;
+    public $rightClone = false;
+    public $iframeType = "none";
+
+    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:
+                if ($init['inline']) {
+                    return new videoLink($id, $init, $compiler);
+                } else {
+                    return new videoPopupLink($id, $init, $compiler);
+                }
+            case 7:
+                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);
+                    default :
+                        return customLink::getCustomInstance($id, $init, $compiler);
+                }
+                break;
+            case 8:
+            case 9:
+                return null;
+            case 10:
+                if ($init['inline']) {
+                    return new webVideoLink($id, $init, $compiler);
+                } else {
+                    return new webVideoPopupLink($id, $init, $compiler);
+                }
+            case 11:
+                return new actionLink($id, $init, $compiler);
+            case 12:
+                if ($compiler->book->parametres->product_zoom_references !== '') {
+                    return new zoomProductLink($id, $init, $compiler);
+                }
+                switch ($compiler->book->parametres->basketManager) {
+                    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);
+                } else {
+                    return new imageLink($id, $init, $compiler);
+                }
+            case 16:
+                return new fileLink($id, $init, $compiler);
+            case 17:
+                if ($init['inline']) {
+                    return new audioLink($id, $init, $compiler);
+                } else {
+                    return new audioPopupLink($id, $init, $compiler);
+                }
+            case 18:
+                if ($init['inline']) {
+                    return new tooltipLink($id, $init, $compiler);
+                } else {
+                    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:
+                $compiler->addPageLabel($init['page'], $init['to']);
+                break;
+            case 27:
+                return new eventOverlayLink($id, $init, $compiler);
+                break;
+            case 29:
+                return new facebookLikeLink($id, $init, $compiler);
+                break;
+            case 30:
+                return new slideshowLink($id, $init, $compiler);
+                break;
+            case 31:
+                if ($init['inline']) {
+                    return new iframeLink($id, $init, $compiler);
+                } else {
+                    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);
+                break;
+            case 36:
+                return new articleLink($id, $init, $compiler);
+                break;
+            case 37:
+                return new downloadPortionLink($id, $init, $compiler);
+            default:
+                return null;
+        }
+    }
+
+    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;
+        }
+
+        $ext = mb_strtolower(files::getExtension($init['alternative']));
+
+        if (in_array($ext, array('oam', 'zip', 'html')) || substr($init['alternative'], 0, 4) == 'http') {
+            if ($init['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']) {
+                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']) || (stristr($linkData['to'], 'scorm') || (isset($linkData['alternative']) && stristr($linkData['alternative'], '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 (stristr($v, '=')) {
+                    $vv = $v;
+                    $v = [];
+                    parse_str($vv, $v);
+                    $v = CubeIT_Util_Object::asObject($v);
+                }
+            }
+            $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->wdir = WS_BOOKS . '/working/' . $compiler->book_id . '/';
+        $this->id = $id;
+        $this->compiler = $compiler;
+        $this->init();
+    }
+
+    public function overlapDoublePage()
+    {
+        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()
+    {
+        return '<div class="' . $this->getHTMLContainerClass() . '" data-hidden="' . $this->hidden . '" data-scorm="' . $this->scorm . '" data-id="' . $this->uid . '" id="l_' . $this->id . '"' . $this->getAdditionnalContent() . '>' . $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()
+    {
+        return '';
+
+    }
+
+    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->zindex + 1) * 1000) - min(999, round(($this->width * $this->height) / 300));
+        return 'z-index:' . $zindex . ';';
+    }
+
+    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->extra->skewX)) {
+            $css .= wsHTML5::writeCSSUA('transform', 'skewX(' . $this->extra->skewX . 'deg)');
+            $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;
+    }
+
+}
+
+class normalLink extends wsHTML5Link
+{
+
+    public function getHTMLContent()
+    {
+        $class = $this->getClasses();
+        if ($this->display_area) {
+            $class[] = 'displayArea';
+        }
+        $attrs = '';
+        if (count($class)) {
+            $attrs .= ' class="' . implode(' ', $class) . '"';
+        }
+        $t = $this->getTooltip();
+        if ($t !== false) {
+            $attrs .= ' data-tooltip="' . htmlentities($t, ENT_QUOTES) . '"';
+        }
+        if (isset($this->extra->blinkdelay)) {
+            $attrs .= ' data-blinkdelay="' . intval($this->extra->blinkdelay) . '"';
+        }
+        return '<a href="' . $this->getURL() . '" data-type="' . $this->type . '" target="' . $this->getTarget() . '"' . $attrs . $this->getAdditionnalContent() . $this->getTrack() . '></a>';
+    }
+
+    public function getTrack()
+    {
+        return '';
+    }
+
+    public function getURL()
+    {
+        return '#';
+    }
+
+    public function getTarget()
+    {
+        return '_self';
+    }
+
+
+}
+
+class showLinkLink extends normalLink
+{
+    public function getURL()
+    {
+        return '#';
+    }
+
+    public function getClasses()
+    {
+        $res = parent::getClasses();
+        $res[] = 'showlink';
+    }
+
+    public function getAdditionnalContent()
+    {
+        $res = parent::getAdditionnalContent();
+        if (!$this->video_service) {
+            $this->video_service = 'none';
+        }
+        $res .= ' data-showmode="' . $this->target . '" data-showclose="' . $this->video_service . '" data-showid="' . $this->to . '"';
+        return $res;
+    }
+}
+
+class tooltipLink extends normalLink
+{
+    public function getClasses()
+    {
+        return array_merge(array('lazy'), parent::getClasses());
+    }
+
+    public function getAdditionnalContent()
+    {
+        $res = parent::getAdditionnalContent();
+        $res .= ' data-tooltip-maxwidth="' . $this->compiler->book->parametres->linkTooltipMaxWidth . '" ';
+        $res .= ' data-tooltip-touch="1" ';
+        return $res;
+    }
+
+    public function getURL()
+    {
+        return '#';
+    }
+}
+
+class textPopupLink extends normalLink
+{
+    public function getClasses()
+    {
+        return array_merge(array('lazy', 'textpopup'), parent::getClasses());
+    }
+
+    public function getAdditionnalContent()
+    {
+        $res = parent::getAdditionnalContent();
+        $res .= ' data-text="' . htmlspecialchars($this->infobulle, ENT_QUOTES) . '" ';
+        return $res;
+    }
+
+    public function getURL()
+    {
+        return '#';
+    }
+
+    public function getTooltip()
+    {
+        return '';
+    }
+}
+
+class htmlMultimediaImage extends wsHTML5Link
+{
+    public $zindex = 2;
+
+    public function getHTMLContainerClass()
+    {
+        return parent::getHTMLContainerClass() . ' multimedia notinteractive';
+    }
+
+    public function getHTMLContent()
+    {
+        $w = $this->width;
+        $h = $this->height;
+        $this->copyExternalFile($this->alternative);
+        $alt = '<img class="multimediaimage" data-width="' . $w . '" data-height="' . $h . '" src="' . wsHTML5Link::getUniversalLocation($this->alternative) . '" width="' . $w . '" height="' . $h . '" />';
+        return $alt;
+    }
+
+}
+
+class htmlMultimediaPopupLink extends htmlMultimediaPopupImage
+{
+
+    public function getAdditionnalContent()
+    {
+        $i = $this->_init;
+        $i['inline'] = true;
+        $i['in_popup'] = true;
+        $i['width'] = $i['video_width'];
+        $i['height'] = $i['video_height'];
+
+        $l = self::getMultimediaInstance($this->id . '_content', $i, $this->compiler);
+        $markup = $l->getHTMLContainer();
+        return ' data-multimedia="' . rawurlencode($markup) . '" ';
+    }
+}
+
+class zoomhdLink extends normalLink
+{
+    public function init()
+    {
+        $this->compiler->addJsLib('fluidbook-zoomhd', 'js/libs/fluidbook/links/fluidbook.links.zoomhd.js');
+        $this->compiler->writeLinksData = true;
+    }
+
+    public function getURL()
+    {
+        $this->copyExternalFile($this->to);
+        return '#/zoomhd/' . $this->uid;
+    }
+
+    public function getAdditionnalContent()
+    {
+        $res = parent::getAdditionnalContent();
+        $res .= ' data-image="' . $this->to . '" ';
+        return $res;
+    }
+
+    public function getDefaultTooltip()
+    {
+        return 'zoom in';
+    }
+}
+
+class htmlMultimediaPopupImage extends normalLink
+{
+
+    public function getURL()
+    {
+        $this->copyExternalFile($this->alternative);
+        $read = ($this->read_mode) ? 'r_' : '';
+        return '#/multimedia/' . $read . md5($this->alternative);
+    }
+
+
+    public function getAdditionnalContent()
+    {
+        $res = parent::getAdditionnalContent();
+        $dim = getimagesize($this->wdir . '/' . $this->alternative);
+
+        $markup = '<div class="multimediaContainer "><img data-width="' . $dim[0] . '" data-height="' . $dim[1] . '" src="' . wsHTML5Link::getUniversalLocation($this->alternative) . '" width="' . $dim[0] . '" height="' . $dim[1] . '" class="multimedia" /></div>';
+        $read = '';
+        if ($this->read_mode) {
+            $read = ' data-readmode="1"';
+        }
+        return $res . ' ' . $read . ' data-multimedia="' . rawurlencode($markup) . '" ';
+    }
+
+    public function keep()
+    {
+        return true;
+    }
+
+}
+
+class contentLink extends wsHTML5Link
+{
+    public $zindex = 0;
+
+    public function getHTMLContainerClass()
+    {
+        return parent::getHTMLContainerClass() . ' contentLink';
+    }
+
+    public function getAdditionnalContent()
+    {
+        $res = parent::getAdditionnalContent();
+        $variables = self::parseAnimation($this->image_rollover);
+
+        if (!isset($variables['type']) || !$variables['type']) {
+            $variables['type'] = 'none';
+        }
+        if (isset($variables['zindex'])) {
+            $this->zindex = $variables['zindex'];
+        }
+        $res .= ' data-animation-type="' . $variables['type'] . '" data-animation="' . htmlspecialchars(json_encode($variables), ENT_QUOTES) . '" ';
+
+
+        return $res;
+    }
+
+    public static function parseAnimation($animation)
+    {
+        $animation = trim($animation);
+        $variables = [];
+        if ($animation != '') {
+            $lines = CubeIT_Text::splitLines($animation);
+            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];
+                }
+                $variables[trim($e[0])] = $v;
+            }
+            if (!isset($variables['direction'])) {
+                $variables['direction'] = 'right';
+            }
+            if ($variables['direction'] == 'top') {
+                $variables['direction'] = 'up';
+            }
+            if ($variables['direction'] == 'bottom') {
+                $variables['direction'] = 'down';
+            }
+        }
+        return $variables;
+    }
+
+    public function getCSSZIndex()
+    {
+        if ($this->zindex === 0) {
+            return '';
+        }
+        return 'z-index:' . ($this->zindex + 500) . ';';
+    }
+}
+
+class eventOverlayLink extends wsHTML5Link
+{
+    public $zindex = 3;
+
+    public function getHTMLContainerClass()
+    {
+        return parent::getHTMLContainerClass() . ' eventOverlayLink';
+    }
+
+    public function getHTMLContent()
+    {
+        return '<div></div>';
+    }
+}
+
+class webLink extends normalLink
+{
+    public function getURL()
+    {
+        $res = str_replace('"', '\'', wsHTML5Link::getUniversalLocation($this->to));
+        return $res;
+    }
+
+    public function getTarget()
+    {
+        if (strpos($this->getURL(), 'javascript:') === 0) {
+            return '_self';
+        }
+        return $this->target;
+    }
+
+    public function getTrack()
+    {
+        return ' data-track="' . $this->getURL() . '"';
+    }
+
+    public function getCSS()
+    {
+
+    }
+
+    public function getDefaultTooltip()
+    {
+        return 'click to open the link';
+    }
+
+}
+
+class mailLink extends normalLink
+{
+
+    public function getURL()
+    {
+        return 'mailto:' . $this->to;
+    }
+
+    public function getTrack()
+    {
+        return ' data-track="' . $this->to . '"';
+    }
+
+    public function getTarget()
+    {
+        return '_self';
+    }
+
+    public function getDefaultTooltip()
+    {
+        return 'click to send an e-mail';
+    }
+
+}
+
+class phoneLink extends mailLink
+{
+
+    public function getURL()
+    {
+        return 'tel:' . $this->to;
+    }
+
+    public function getTarget()
+    {
+        return '_blank';
+    }
+
+    public function getDefaultTooltip()
+    {
+        return 'click to call this number';
+    }
+
+}
+
+class internalLink extends normalLink
+{
+
+    public function getURL()
+    {
+        return '#/page/' . $this->getPage();
+    }
+
+    public function getPage()
+    {
+        if ($this->numerotation == 'physical') {
+            return $this->to;
+        } else {
+            return $this->compiler->virtualToPhysical($this->to);
+        }
+    }
+
+    public function getDefaultTooltip()
+    {
+        return 'go to page';
+    }
+
+}
+
+class videoLink extends wsHTML5Link
+{
+    public $zindex = 2;
+
+    public static function addVideoJS($compiler)
+    {
+        $compiler->addVideoJs();
+    }
+
+    public function getClasses()
+    {
+        return array_merge(['videoLink'], parent::getClasses());
+    }
+
+    public function getHTMLContent()
+    {
+
+
+        $this->copyExternalFile($this->to, true);
+
+        $w = round($this->width * $this->getCssScale());
+        $h = round($this->height * $this->getCssScale());
+
+        // Note: width and height for the video is normally measured from the
+        // preview frame for local files or set to 1280 x 720 for web videos.
+        // The $w and $h variables here seem to be null generally...
+
+        return $this->makeVideoTag($this, $w, $h, $this->compiler);
+    }
+
+    public static function makeVideoTag($linkDatas, $w = null, $h = null, $compiler = null)
+    {
+        static::addVideoJS($compiler);
+
+        $attributes = static::getVideoAttributes($linkDatas, $w, $h, $compiler);
+
+        $res = '<div class="videoContainer"';
+        foreach ($attributes as $name => $value) {
+            $res .= " data-{$name}='{$value}'";
+        }
+        $res .= '></div>';
+
+        return $res;
+    }
+
+    public static function getVideoAttributes($data, $w = null, $h = null, $compiler = null)
+    {
+
+        $file = $data->to;
+        $e = explode('.', $file);
+        $ext = array_pop($e);
+        $basename = implode('.', $e);
+
+        $attr['name'] = $basename;
+        $attr['id'] = 'video_' . $data->id;
+        $attr['autoplay'] = ($data->video_auto_start ? '1' : '0');
+        $attr['controls'] = ($data->video_controls ? '1' : '0');
+        $attr['loop'] = ($data->video_loop ? '1' : '0');
+        $attr['sound'] = ($data->video_sound_on ? '1' : '0');
+        $attr['link-id'] = $data->uid;
+
+        if (!is_null($w) && !is_null($h)) {
+            $attr['width'] = $w;
+            $attr['height'] = $h;
+        } else if (!is_null($compiler)) {
+            // Get video dimensions from thumbnail if possible (locally uploaded files)
+//            $path = WS_BOOKS . '/working/' . $compiler->book_id . '/' . $basename . '.jpg';
+//            $dim = getimagesize($path);
+//            $attr['width'] = $dim[0];
+//            $attr['height'] = $dim[1];
+            $path = WS_BOOKS . '/working/' . $compiler->book_id . '/' . $file;
+            $e = explode(',', `ffprobe -v error -select_streams v:0 -show_entries stream=width,height -of csv=p=0 $path`);
+            $attr['width'] = $e[0];
+            $attr['height'] = $e[1];
+        }
+
+        return $attr;
+    }
+
+}
+
+class videoPopupLink extends normalLink
+{
+
+    public function getURL()
+    {
+        $this->copyExternalFile($this->to, true);
+        $file = $this->to;
+        $e = explode('.', $file);
+        $ext = array_pop($e);
+        $basename = implode('.', $e);
+
+        return '#/video/' . $basename;
+    }
+
+    public function getAdditionnalContent()
+    {
+        $this->video_auto_start = true; // Videos should always autoplay
+        return ' data-video="' . rawurlencode(videoLink::makeVideoTag($this, null, null, $this->compiler)) . '" ';
+    }
+
+    public function keep()
+    {
+        return true;
+    }
+
+    public function getDefaultTooltip()
+    {
+        return 'click to play the video';
+    }
+
+}
+
+class audioPopupLink extends normalLink
+{
+
+    public function getURL()
+    {
+        $this->copyExternalFile($this->to, false);
+        $file = $this->to;
+        $e = explode('.', $file);
+        $ext = array_pop($e);
+        $basename = implode('.', $e);
+
+        return '#/audio/' . $basename;
+    }
+
+    public function getAdditionnalContent()
+    {
+        return ' data-audio="' . rawurlencode(audioLink::makeAudioTag($this, null, null, $this->compiler)) . '" ';
+    }
+
+    public function keep()
+    {
+        return true;
+    }
+
+    public function getDefaultTooltip()
+    {
+        return 'click to play the audio';
+    }
+
+}
+
+class webVideoLink extends videoLink
+{
+
+    public static function getVideoAttributes($data, $w = null, $h = null, $compiler = null)
+    {
+        $attributes = parent::getVideoAttributes($data, $w, $h, $compiler);
+
+        // Since the admin interface doesn't offer options for setting controls or sound, we will set some defaults here
+        $attributes['controls'] = '1';
+        $attributes['sound'] = '1';
+
+        $attributes['setup'] = static::getVideoSetup($data, $compiler);
+
+        return $attributes;
+    }
+
+    public static function getVideoSetup($data, $compiler)
+    {
+
+        static::addVideoJS($compiler); // Ensure videoJS core is included first
+
+        switch ($data->video_service) {
+            case 0: // YouTube
+                $compiler->addJsLib('videojs-youtube', 'js/libs/videojs/Youtube.js');
+                //                $compiler->addJs('https://rawgit.com/videojs/videojs-youtube/master/dist/Youtube.js');
+                $setup = [
+                    'techOrder' => ['youtube'],
+                    'sources' => [
+                        [
+                            'type' => 'video/youtube',
+                            'src' => 'https://www.youtube.com/watch?v=' . $data->to
+                        ]
+                    ]
+                ];
+                break;
+            case 1: // Dailymotion
+                // Todo: add local version of script...
+                // Note: this plugin doesn't seem to work currently so it is not included
+                //$compiler->addJs('https://rawgit.com/benjipott/video.js-dailymotion/master/dist-test/videojs-dailymotion.js');
+                $setup = [
+                    //                    'techOrder' => ['dailymotion'],
+                    //                    'sources' => [
+                    //                        [
+                    //                            'src' => 'http://www.dailymotion.com/video/' . $data->to
+                    //                        ]
+                    //                    ]
+                ];
+                break;
+            case 2: // Vimeo
+                // Todo: add local version of script...
+                // Note: Vimeo plugin doesn't seem to be working currently - might need updates to work with latest VideoJS module
+                //$compiler->addJs('https://rawgit.com/videojs/videojs-vimeo/master/dist/videojs-vimeo.min.js');
+                $setup = [
+                    //                    'techOrder' => ['vimeo'],
+                    //                    'sources' => [
+                    //                        [
+                    //                            'type' => 'vimeo/vimeo',
+                    //                            'src' => 'https://www.vimeo.com/' . $data->to
+                    //                        ]
+                    //                    ]
+                ];
+                break;
+            default:
+                $setup = [];
+        }
+
+        return json_encode($setup, JSON_UNESCAPED_SLASHES);
+
+    }
+
+    public function getHTMLContent()
+    {
+
+        if ($this->video_service !== 0) {
+            return $this->getEmbed();
+        }
+
+        $w = round($this->width * $this->getCssScale());
+        $h = round($this->height * $this->getCssScale());
+
+        return $this->makeVideoTag($this, $w, $h, $this->compiler);
+    }
+
+    public function getEmbed()
+    {
+        return '<iframe width="' . $this->width . '" height="' . $this->height . '" src="' . $this->getEmbedURL() . '" frameborder="0" allowfullscreen></iframe>';
+    }
+
+    public function getEmbedURL()
+    {
+        if ($this->video_service == 0) {
+            $url = 'https://www.youtube.com/embed/' . $this->to . '?html5=1';
+        } elseif ($this->video_service == 1) {
+            $url = 'https://www.dailymotion.com/embed/video/' . $this->to;
+        } elseif ($this->video_service == 2) {
+            $url = 'https://player.vimeo.com/video/' . $this->to;
+        } elseif ($this->video_service == 3) {
+            list($playerId, $videoId) = explode('|', $this->to);
+            $url = 'https://link.brightcove.com/services/player/bcpid' . $playerId . '?bctid=' . $videoId . '&autoStart=false&width=100%25&height=100%25';
+        }
+        return $url;
+    }
+
+}
+
+class actionLink extends internalLink
+{
+    protected $_share = array('facebook', 'twitter', 'googleplus', 'linkedin', 'viadeo');
+
+    public function getURL()
+    {
+        return '#';
+    }
+
+    public function getClasses()
+    {
+        if (in_array($this->to, $this->_share)) {
+            return array_merge(array('share'), parent::getClasses());
+        } else {
+            return parent::getClasses();
+        }
+    }
+
+    public function getAdditionnalContent()
+    {
+        $res = parent::getAdditionnalContent();
+        if (is_object($this->extra) || is_array($this->extra)) {
+            $extra = json_encode($this->extra);
+        } else {
+            $extra = $this->extra;
+        }
+        if ($extra) {
+            $res .= ' data-extra="' . htmlspecialchars($extra, ENT_QUOTES) . '"';
+        }
+
+        if (in_array($this->to, $this->_share)) {
+            $res .= ' data-service="' . $this->to . '" ';
+        } else {
+            $res .= /*parent::getClasses()*/
+                ' data-action="' . $this->to . '" ';
+        }
+        return $res;
+    }
+
+    public function getDefaultTooltip()
+    {
+        return false;
+    }
+
+
+}
+
+class cartLink extends normalLink
+{
+
+    public function getURL()
+    {
+        return '#';
+    }
+
+    public function getDefaultTooltip()
+    {
+        return 'add to cart';
+    }
+
+    public function getAdditionnalContent()
+    {
+        $res = parent::getAdditionnalContent();
+        $e = explode("|", $this->to);
+        $ref = $e[0];
+        $qty = isset($e[1]) ? $e[1] : '1';
+
+        $res .= 'data-cart-ref="' . $ref . '" data-cart-qty="' . $qty . '" ';
+        return $res;
+    }
+}
+
+class remarkableCartLink extends cartLink
+{
+
+}
+
+class colorLink extends contentLink
+{
+    public function getCSS()
+    {
+        return 'background-color:' . wsHTML5::colorToCSS($this->to, 1) . ';';
+    }
+
+    public function getAdditionnalContent()
+    {
+        $res = parent::getAdditionnalContent();
+        $res .= ' data-color="' . wsHTML5::colorToCSS($this->to, 1) . '"';
+        return $res;
+    }
+}
+
+class textLink extends contentLink
+{
+    public function getCSS()
+    {
+        $font = $this->compiler->addFont($this->image);
+        if (!$font['capHeight']) {
+            $font['capHeight'] = 1;
+        }
+        $fz = $this->height * $this->getCssScale();
+        $fz = round($fz / $font['capHeight'], 2);
+        return 'line-height:' . $font['capHeight'] . ';font-size:' . $fz . 'px;font-family:' . $font['family'] . ';color:' . wsHTML5::colorToCSS($this->extra, 1) . ';';
+    }
+
+    public function getHTMLContainerClass()
+    {
+        return parent::getHTMLContainerClass() . ' textLink';
+    }
+
+
+    public function getAdditionnalContent()
+    {
+        $res = parent::getAdditionnalContent();
+        return $res;
+    }
+
+    public function getHTMLContent()
+    {
+        return $this->to;
+    }
+}
+
+class imageLink extends contentLink
+{
+
+    public function getCSS()
+    {
+        $this->copyExternalFile($this->to);
+        return 'background-image:url(' . wsHTML5Link::getUniversalLocation($this->to, true) . ');background-size:100% 100%;background-repeat:no-repeat;';
+    }
+
+    public function getAdditionnalContent()
+    {
+        $res = parent::getAdditionnalContent();
+        $res .= ' data-rollover="' . $this->rollover . '"';
+        return $res;
+    }
+
+}
+
+class inlineSlideshowLink extends contentLink
+{
+    public function getHTMLContent()
+    {
+        $d = $this->unzipFile($this->to, false);
+        $this->compiler->vdir->copyDirectory($d['dir'], $d['fdir']);
+
+        $iterator = CubeIT_Files::getRecursiveDirectoryIterator($d['dir']);
+
+        $files = array();
+        foreach ($iterator as $f) {
+            /* @var $f SplFileInfo */
+            $files[] = $f->getFilename();
+        }
+        sort($files);
+        $f = htmlspecialchars(json_encode($files), ENT_QUOTES);
+
+        return '<div class="inlineslideshow" data-dir="' . str_replace('.', '_', $this->to) . '" data-images="' . $f . '"></div>';
+    }
+}
+
+class fileLink extends normalLink
+{
+
+    public function getURL()
+    {
+        if ($this->compiler->book->parametres->linkFilePrefix && !CubeIT_Util_Url::isDistant($this->to)) {
+            return $this->compiler->book->parametres->linkFilePrefix . $this->to;
+        }
+        $this->copyExternalFile($this->to);
+        return wsHTML5Link::getUniversalLocation($this->to);
+    }
+
+    public function getTarget()
+    {
+        return '_blank';
+    }
+
+    public function getDefaultTooltip()
+    {
+        return 'click to open the file';
+    }
+
+}
+
+class downloadPortionLink extends fileLink
+{
+    public function getURL()
+    {
+        zoomLink::generateImage($this->getZoomAttributes(), $this->compiler, 'downloadportion', 'downloadportion');
+        return 'data/links/downloadportion_' . $this->id . '.jpg';
+    }
+
+    public function getZoomAttributes()
+    {
+        $pdf = $this->compiler->book->parametres->downloadPortionPDF;
+        if ($pdf !== '') {
+            $pdf = $this->compiler->wdir . '/' . $this->compiler->book->parametres->downloadPortionPDF;
+        }
+
+        $res = [
+            'id' => $this->id,
+            'page' => $this->page,
+            'maxzoom' => $this->compiler->book->parametres->downloadPortionZoom,
+            'group' => '',
+            'group-count' => 0,
+            'width' => round($this->width),
+            'height' => round($this->height),
+            'x' => round($this->left),
+            'y' => round($this->top),
+            'pdf' => $pdf,
+        ];
+        return $res;
+    }
+
+    public function getAdditionnalContent()
+    {
+        $file = $this->to;
+        if (!$file) {
+            $file = 'p' . $this->page;
+        }
+        if (!preg_match('/\.jpe?g$/', $file, $matches)) {
+            $file .= '.jpg';
+        }
+        $file = htmlspecialchars($file);
+
+        return parent::getAdditionnalContent() . ' download="' . $file . '" ';
+    }
+
+    public function getDefaultTooltip()
+    {
+        return 'click to download the image';
+    }
+}
+
+class facebookLikeLink extends wsHTML5Link
+{
+    public function getHTMLContent()
+    {
+        $this->compiler->addFacebookSDK();
+        return '<div class="fb-like" data-href="' . $this->to . '" data-layout="button_count" data-action="like" data-size="large" data-show-faces="false" data-share="false"></div>';
+    }
+}
+
+class htmlMultimediaLink extends wsHTML5Link
+{
+
+    protected $_config = null;
+    protected $_content = '';
+    protected $_url;
+    protected $_externalIframe = false;
+    public $zindex = 2;
+
+    public function getHTMLContent()
+    {
+        if ($this->_content == '') {
+            $ext = files::getExtension($this->alternative);
+
+            if ($ext == 'oam') {
+                $d = $this->unzipFile($this->alternative, true);
+                $this->_config = $this->getConfigOAM($d['dir']);
+                $this->copyExternalDir($d['dir'], $d['fdir']);
+            } elseif ($ext == 'zip') {
+                $d = $this->unzipFile($this->alternative, 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->vdir->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->vdir->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 (substr($this->alternative, 0, 4) == 'http') {
+                $this->_url = $this->_externalIframe = $this->alternative;
+                $this->_config = array('html' => false, 'width' => $this->width, 'height' => $this->height);
+            }
+
+            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'];
+
+                $ld = ' ';
+                if (isset($this->_config['lowDef'])) {
+                    $ld = ' data-ld="' . str_replace('index.html', $this->_config['lowDef'], $this->_url) . '" ';
+                }
+
+                $res = '<iframe' . $ld . '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;" onload="this.style.visibility=\'visible\';"></iframe>';
+            }
+            if ($this->_externalIframe !== false) {
+                $iw = $this->_config['width'] * $s;
+                $ih = $this->_config['height'] * $s;
+                $res = '<iframe data-scale="' . $s . '" data-width="' . $iw . '" data-height="' . $ih . '"  width="' . $iw . '" height="' . $ih . '" src="' . $this->_externalIframe . '" frameborder="0" marginwidth="0" marginheight="0" scrolling="no" allowfullscreen mozallowfullscreen="true" webkitallowfullscreen="true" onmousewheel="" style="visibility:hidden;" onload="this.style.visibility=\'visible\';"></iframe>';
+            }
+
+            foreach ($this->_config['inject'] as $i) {
+                $infos = ['path' => 'data/links/' . str_replace('.', '_', $this->alternative)];
+                $i = str_replace('$id', '"#l_' . $this->id . '"', $i);
+                $i = str_replace('$path', '"' . $infos['path'] . '"', $i);
+                $i = str_replace('$init', CubeIT_Util_Json::encode($infos), $i);
+                $this->compiler->htmlmultimedia[] = $i;
+            }
+
+            if (isset($this->_config['injectcss'])) {
+                foreach ($this->_config['injectcss'] as $i) {
+
+                }
+            }
+
+            if (isset($this->_config['injectjs'])) {
+                foreach ($this->_config['injectjs'] as $i) {
+                    $this->compiler->pluginJs[] = $d['fdir'] . '/' . $i;
+                }
+            }
+
+
+            $this->_content = $res;
+        }
+        return $this->_content;
+    }
+
+    public function getHTMLContainerClass()
+    {
+        $res = parent::getHTMLContainerClass() . ' multimedia';
+        if (!$this->interactive) {
+            $res .= ' notinteractive';
+        }
+
+        return $res;
+    }
+
+
+    protected function _correctFiles($dir)
+    {
+        $files = CubeIT_Files::getRecursiveDirectoryIterator($dir);
+        foreach ($files as $f) {
+            /* @var $f SplFileInfo */
+            if ($f->getExtension() == 'js') {
+                $this->_correctFile($f);
+            }
+        }
+    }
+
+    public function getCSSContainer()
+    {
+        if ($this->moveOnEvenPage()) {
+            $this->page--;
+            $this->left += $this->compiler->width;
+        }
+
+        $css = '#l_' . $this->id . '{';
+        $css .= 'left:' . $this->left * $this->getCssScale() . 'px;top:' . $this->top * $this->getCssScale() . 'px;';
+        $css .= 'width:' . $this->_config['width'] . 'px;height:' . $this->_config['height'] . 'px;';
+        $css .= $this->getCSSZIndex();
+        $css .= $this->getCSS();
+        $css .= '}';
+        if ($this->_externalIframe !== false && $this->in_popup) {
+            $css .= '#l_' . $this->id . '>iframe{' . wsHTML5::writeCSSUA('transform', 'scale(' . $this->getCssScale() . ')') . '}';
+        }
+
+        if ($this->_config['type'] === 'oam') {
+            $sx = ($this->width / ($this->_config['width'])) * $this->getCssScale();
+            $sy = ($this->height / ($this->_config['height'])) * $this->getCssScale();
+            if ($this->compiler->book->parametres->OAMChromeFactor != 1) {
+                $css .= '.chrome #l_' . $this->id . '{';
+                $css .= 'width:' . ($this->_config['width'] * $this->compiler->book->parametres->OAMChromeFactor) . 'px;height:' . ($this->_config['height'] * $this->compiler->book->parametres->OAMChromeFactor) . 'px;';
+                $css .= wsHTML5::writeCSSUA('transform', 'scale(' . ($sx / $this->compiler->book->parametres->OAMChromeFactor) . ',' . ($sy / $this->compiler->book->parametres->OAMChromeFactor) . ')');
+                $css .= '}';
+            }
+            if ($this->compiler->book->parametres->OAMIEFactor != 1) {
+                $css .= '.msie #l_' . $this->id . '{';
+                $css .= 'width:' . ($this->_config['width'] * $this->compiler->book->parametres->OAMIEFactor) . 'px;height:' . ($this->_config['height'] * $this->compiler->book->parametres->OAMIEFactor) . 'px;';
+                $css .= wsHTML5::writeCSSUA('transform', 'scale(' . ($sx / $this->compiler->book->parametres->OAMIEFactor) . ',' . ($sy / $this->compiler->book->parametres->OAMIEFactor) . ')');
+                $css .= '}';
+            }
+
+        }
+
+
+        return $css;
+    }
+
+    public function getCSS()
+    {
+        $sx = ($this->width / ($this->_config['width'])) * $this->getCssScale();
+        $sy = ($this->height / ($this->_config['height'])) * $this->getCssScale();
+
+        $res = wsHTML5::writeCSSUA('transform', 'scale(' . $sx . ',' . $sy . ')');
+        $res .= wsHTML5::writeCSSUA('transform-origin', '0% 0%');
+
+        if (!$this->_config['html']) {
+            return '';
+        }
+        return $res;
+    }
+
+
+}
+
+class webVideoPopupLink extends videoPopupLink
+{
+
+    // public function getURL() {
+    //         if ($this->video_service == 0) {
+    //                 $service = 'youtube';
+    //         } elseif ($this->video_service == 1) {
+    //                 $service = 'dailymotion';
+    //         } elseif ($this->video_service == 2) {
+    //                 $service = 'vimeo';
+    //         } elseif ($this->video_service == 3) {
+    //                 $service = 'brightcove';
+    //         }
+    //         return '#/webvideo/' . $service . '/' . $this->to;
+    // }
+
+    public function getURL()
+    {
+
+        switch ($this->video_service) {
+            case 1: // Dailymotion
+                return '#/webvideo/dailymotion/' . $this->to;
+                break;
+            case 2: // Vimeo
+                return '#/webvideo/vimeo/' . $this->to;
+                break;
+            default:
+                return '#/video/' . $this->to;
+        }
+    }
+
+    public function getAdditionnalContent()
+    {
+        $this->video_auto_start = true; // Videos should always autoplay
+        return ' data-video="' . rawurlencode(webVideoLink::makeVideoTag($this, 1280, 720, $this->compiler)) . '" ';
+    }
+
+}
+
+class audioLink extends wsHTML5Link
+{
+
+    public function getHTMLContent()
+    {
+        $this->copyExternalFile($this->to);
+
+        $w = round($this->width * $this->getCssScale());
+        $h = round($this->height * $this->getCssScale());
+
+        return self::makeAudioTag($this, $w, $h, $this->compiler);
+    }
+
+    public function getCSSContainer()
+    {
+        $css = parent::getCSSContainer();
+        $css .= '#l_' . $this->id . ' audio{';
+        $css .= 'width:' . round($this->width * $this->getCssScale()) . 'px;';
+        $css .= 'height:' . round($this->height * $this->getCssScale()) . 'px;';
+        $css .= 'display:block;';
+        $css .= '}';
+        return $css;
+    }
+
+    public static function makeAudioTag($linkDatas, $w = null, $h = null, $compiler = null)
+    {
+        $res = '<audio controls ';
+        if ($linkDatas->video_loop) {
+            $res .= 'loop ';
+        }
+        if ($linkDatas->video_auto_start) {
+            $res .= 'autoplay ';
+        }
+        $res .= ' src="' . wsHTML5Link::getUniversalLocation($linkDatas->to) . '"';
+        $res .= '></audio>';
+        return $res;
+    }
+
+}
+
+class wescoLink extends normalLink
+{
+    public static function _getURL($to)
+    {
+        return self::_getURLOfType('wesco', $to);
+    }
+
+    public function getURL()
+    {
+        return self::_getURL($this->to);
+    }
+
+    protected static function _getURLOfType($type, $ref)
+    {
+        global $core;
+        $r = $core->con->select("SELECT * FROM wsref WHERE ref='" . $core->con->escape($ref) . "' AND type='" . $core->con->escape($type) . "'");
+        if ($r->count()) {
+            return $r->url;
+        }
+        return 'https://workshop.fluidbook.com/services/wsref?ref=' . urlencode($type . '|' . $ref);
+    }
+
+
+    public function getTarget()
+    {
+        return '_blank';
+    }
+
+    public function getDefaultTooltip()
+    {
+        return 'click to open the link';
+    }
+
+}
+
+class pierronLink extends normalLink
+{
+
+    public function getURL()
+    {
+        return 'https://workshop.fluidbook.com/services/pierronRef?ref=' . $this->to;
+    }
+
+    public function getTarget()
+    {
+        return '_blank';
+    }
+
+}
+
+class wescoSalesLink extends normalLink
+{
+    public function __construct($id, $init, $compiler)
+    {
+        $e = explode(':', $init['to']);
+        if (count($e) > 1) {
+            $init['to'] = $e[1];
+        }
+        parent::__construct($id, $init, $compiler);
+    }
+
+    public function getUrl()
+    {
+        return '#';
+    }
+
+    public function getAdditionnalContent()
+    {
+        $e = explode(':', $this->to);
+        if (count($e) > 1) {
+            $this->to = $e[1];
+        }
+        return parent::getAdditionnalContent() . ' data-wescosales-ref="' . $this->to . '" ';
+    }
+
+    public function getTooltip()
+    {
+        return 'Consulter les ventes de ce produit';
+    }
+}
+
+class atlanticDownloadLink extends normalLink
+{
+    public function getUrl()
+    {
+        return '#';
+    }
+
+    public function getAdditionnalContent()
+    {
+        return parent::getAdditionnalContent() . ' data-atlanticdownload-ref="' . $this->to . '" ';
+    }
+
+    public function getTooltip()
+    {
+        return 'Télécharger les documents';
+    }
+}
+
+class inpesPopinLink extends htmlMultimediaLink
+{
+
+    public function getHTMLContent()
+    {
+        $this->alternative = $this->to;
+        $c = parent::getHTMLContent();
+
+        $class = $this->getClasses();
+        if ($this->display_area) {
+            $class[] = 'displayArea';
+        }
+        $c = '';
+        if (count($class)) {
+            $c = ' class="' . implode(' ', $class) . '"';
+        }
+        $tooltip = '';
+        $t = $this->getTooltip();
+        if ($t !== false) {
+            $tooltip = ' data-tooltip="' . htmlspecialchars($t, ENT_QUOTES) . '"';
+        }
+        return '<a href="#" ' . $tooltip . $c . $this->getAdditionnalContent() . '></a>';
+    }
+
+    public function getCSSContainer()
+    {
+        if ($this->moveOnEvenPage()) {
+            $this->page--;
+            $this->left += $this->compiler->width;
+        }
+
+        $css = '#l_' . $this->id . '{';
+        $css .= 'left:' . $this->left * $this->getCssScale() . 'px;top:' . $this->top * $this->getCssScale() . 'px;';
+        $css .= 'width:' . $this->width * $this->getCssScale() . 'px;height:' . $this->height * $this->getCssScale() . 'px;';
+        $css .= $this->getCSSZIndex();
+        if ($this->rot) {
+            $css .= wsHTML5::writeCSSUA('transform', 'rotate(' . $this->rot . 'deg)');
+            $css .= wsHTML5::writeCSSUA('transform-origin', '0% 0%');
+        }
+        $css .= $this->getCSS();
+        $css .= '}';
+        return $css;
+    }
+
+    public function getCSS()
+    {
+        return "";
+    }
+
+    public function getClasses()
+    {
+        $res = parent::getClasses();
+        $res[] = 'popin';
+        return $res;
+    }
+
+    public function getAdditionnalContent()
+    {
+        $res = parent::getAdditionnalContent();
+        $res .= ' data-src="' . $this->_url . '" data-width="900" data-height="650"';
+        return $res;
+    }
+
+}
+
+class statsTagLink extends wsHTML5Link
+{
+    public function __construct($id, $init, &$compiler)
+    {
+        parent::__construct($id, $init, $compiler);
+        $this->width = 1;
+        $this->height = 1;
+    }
+
+    public function getHTMLContent()
+    {
+        return str_replace('%tag%', $this->to, $this->compiler->book->parametres->xiti_page);
+    }
+}
+
+class flfLink extends wescoLink
+{
+
+    public function getURL()
+    {
+        return 'https://workshop.fluidbook.com/services/flfRef?ref=' . $this->to;
+    }
+
+    public function getTarget()
+    {
+        return '_blank';
+    }
+
+    public function getTooltip()
+    {
+        return 'Accéder à la fiche du stage sur notre site flf.fr';
+    }
+
+}
+
+class haguenauManifLink extends internalLink
+{
+
+    public function getPage()
+    {
+        $fiches = array(
+            "1" => 7, "2" => 8, "3" => 14, "4" => 16, "5" => 17, "6" => 18, "7" => 19, "8" => 20, "9" => 22, "10" => 23, "11" => 24, "12" => 27
+        , "13" => 29, "14" => 32, "15" => 34, "16" => 37, "17" => 38, "18" => 41, "19" => 43,
+            "20" => 45, "21" => 46, "22" => 52, "23" => 53, "24" => 54, "25" => 56, "26" => 59, "27" => 60
+        );
+        return $fiches[$this->to];
+    }
+
+}
+
+class customLink extends wescoLink
+{
+    public static function getCustomInstance($id, $init, &$compiler)
+    {
+        $e = explode(':', $init['to']);
+        if ($e[0] == '10doigts') {
+            $init['to'] = self::_getURL($init['to']);
+            $init['iframeType'] = '10doigts';
+            $init['infobulle'] = 'Voir le produit';
+            return new iframePopupLink($id, $init, $compiler);
+        }
+        return new customLink($id, $init, $compiler);
+    }
+
+    public static function _getURL($to)
+    {
+        global $core;
+        $e = explode(':', $to, 2);
+        if (!count($e) == 1) {
+            return 'https://workshop.fluidbook.com/services/wsref?ref=' . urlencode($to);
+        }
+        $type = trim($e[0]);
+        $ref = trim($e[1]);
+        return self::_getURLOfType($type, $ref);
+    }
+
+    public function getDefaultTooltip()
+    {
+        return 'click to open the link';
+    }
+}
+
+class zoomLink extends normalLink
+{
+    protected $maxzoom_default = 2;
+    protected $_groups = null;
+
+    public function getGroups()
+    {
+        if (null === $this->_groups) {
+            $this->_groups = [];
+            $groups = explode(',', $this->group);
+            foreach ($groups as $group) {
+                $this->_groups[] = CubeIT_Text::str2URL(trim($group));
+            }
+        }
+        return $this->_groups;
+    }
+
+    public function init()
+    {
+        $this->compiler->addJsLib('fluidbook-zoom', 'js/libs/fluidbook/links/fluidbook.links.zoom.js');
+        parent::init();
+    }
+
+    public function getHTMLContainerClass()
+    {
+        $class = ' zoomarea';
+
+        $groups = $this->getGroups();
+
+        // If there's more than one group assigned, this link shouldn't be clickable (disabled via CSS)
+        // This needs to be set here (parent element) instead of on the actual link so we don't end up with a dead zone
+        if (count($groups) > 1) {
+            $class .= ' pointer-events-none';
+        }
+
+        return parent::getHTMLContainerClass() . $class;
+    }
+
+    public function getDefaultTooltip()
+    {
+        return 'zoom in';
+    }
+
+    public function getAdditionnalContent()
+    {
+        $res = parent::getAdditionnalContent();
+
+        $res .= ' id="' . $this->uid . '"';
+
+        // Data attributes
+        $attributes = $this->getZoomAttributes();
+
+        // Set data attributes
+        foreach ($attributes as $key => $val) {
+            $res .= ' data-' . $key . '="' . htmlspecialchars($val, ENT_QUOTES) . '"';
+        }
+
+        self::generateImage($this->getZoomAttributes(), $this->compiler, 'zoomarea', 'zoom');
+
+        return $res;
+    }
+
+    public function getZoomAttributes()
+    {
+        return [
+            'id' => $this->id,
+            'page' => $this->page,
+            'maxzoom' => empty($this->to) ? $this->maxzoom_default : $this->to,
+            'group' => implode(',', $this->getGroups()),
+            'group-count' => empty($this->group) ? 0 : count($this->getGroups()),
+            'width' => round($this->width),
+            'height' => round($this->height),
+            'x' => round($this->left),
+            'y' => round($this->top)
+        ];
+    }
+
+    public static function generateImage($attributes, $compiler, $cachedir, $save)
+    {
+
+        $maxzoom = $attributes['maxzoom']; // Max zoom level might not always be set in the link editor
+        $maxzoom = max(2, min($maxzoom, 4.166666667));
+        if (!$maxzoom) {
+            $maxzoom = 2;
+        }
+
+        // TODO: Consider generating higher-res images (eg. 2x) for HiDPI screens. Maybe some extra optimisations can be done on the larger images...
+
+        $extractOptions = [
+            // The Poppler::extractArea function accepts a resolution setting and uses that to determine the
+            // scale factor on the extracted images. It does so by dividing by 72, so we can pass our own scale
+            // factor by setting the resolution to 72 * $maxzoom
+            'resolution' => 72 * $maxzoom
+        ];
+
+        // Round all link co-ordinates because there seems to be a problem with the the Workshop link editor
+        // where link "left" values (and maybe others) change fractionally upon saves. This causes problems later when
+        // extracting the zoom images from the PDF because it causes a cache-miss and the images are regenerated again.
+        $x = $attributes['x'];
+        $y = $attributes['y'];
+        $w = $attributes['width'];
+        $h = $attributes['height'];
+        $bookwidth = round($compiler->book->parametres->width);
+
+        //error_log("--- Book Width: $bookwidth ---");
+
+        if (!isset($attributes['pdf']) || !$attributes['pdf']) {
+            $p = wsDAOBook::getDocumentPage($compiler->book_id, $attributes['page']);
+            $pdfpath = wsDocument::getDir($p['document_id']) . '/pdf/p' . $p['document_page'] . '.pdf';
+            $extractPage = 1;
+        } else {
+            $pdfpath = $attributes['pdf'];
+            $extractPage = $attributes['page'];
+        }
+
+        $left = CubeIT_Files::tempnam();
+        $leftfile = CubeIT_CommandLine_Poppler::extractArea($pdfpath,
+            $extractPage,
+            array('x' => $x, 'y' => $y, 'width' => $w, 'height' => $h),
+            $left, $extractOptions, WS_CACHE . '/' . $cachedir . '/' . $compiler->book_id . '/');
+
+        if (($x + $w) > $bookwidth) {
+            if (!isset($attributes['pdf']) || !$attributes['pdf']) {
+                $p = wsDAOBook::getDocumentPage($compiler->book_id, $attributes['page'] + 1);
+                $pdfpath = wsDocument::getDir($p['document_id']) . '/pdf/p' . $p['document_page'] . '.pdf';
+                $extractPage = 1;
+            } else {
+                $pdfpath = $attributes['pdf'];
+                $extractPage = $attributes['page'] + 1;
+            }
+
+            $diff = ($w + $x) - $bookwidth;
+            $right = CubeIT_Files::tempnam();
+            $rightfile = CubeIT_CommandLine_Poppler::extractArea($pdfpath,
+                $extractPage,
+                array('x' => 0, 'y' => $y, 'width' => $diff, 'height' => $h),
+                $right, $extractOptions, WS_CACHE . '/' . $cachedir . '/' . $compiler->book_id . '/');
+
+            $both = CubeIT_Files::tempnam() . '.jpg';
+            CubeIT_CommandLine_Imagemagick::append(array($leftfile, $rightfile), $both, 'horizontal');
+        } else {
+            $both = $leftfile;
+        }
+
+        $compiler->simpleCopyLinkFile($both, 'data/links/' . $save . '_' . $attributes['id'] . '.jpg');
+
+        // Perform tidy up and delete temporary files if they exist
+        $files_to_delete = ['left', 'leftfile', 'right', 'rightfile', 'both'];
+        foreach ($files_to_delete as $file) {
+            if (isset($$file)) {
+                $compiler->vdir->addTemp($$file);
+            }
+        }
+    }
+
+
+    public function getClasses()
+    {
+        // Assign CSS classes for all groups so we can match and group them via JS
+        $groups = $this->getGroups();
+        $group_classes = [];
+
+        foreach ($groups as $group) {
+            if (empty($group)) continue;
+
+            $group_classes[] = 'zoom-group-' . trim(CubeIT_Text::str2URL($group));
+        }
+
+        return array_merge($group_classes, ['zoomPopup'], parent::getClasses());
+    }
+}
+
+class zoomProductLink extends zoomLink
+{
+    protected $maxzoom_default = 2.5;
+
+    public function __construct($id, $init, &$compiler)
+    {
+        $init['group'] = $init['to'];
+        parent::__construct($id, $init, $compiler);
+    }
+
+    public function getZoomAttributes()
+    {
+        $url = isset($this->compiler->config->product_zoom_references[$this->to]) ? $this->compiler->config->product_zoom_references[$this->to] : '';
+
+        $res = parent::getZoomAttributes();
+        $res['maxzoom'] = $this->maxzoom_default;
+        $res['ref'] = $this->to;
+        if ($url) {
+            $res['shareurl'] = $url[0];
+            $n = count($url);
+            for ($i = 0; $i < $n; $i++) {
+                if (isset($url[$i]) && $url[$i]) {
+                    $res['d-' . $i] = $url[$i];
+                }
+            }
+        }
+
+        return $res;
+    }
+
+}
+
+
+class slideshowLink extends normalLink
+{
+
+    protected $path;
+    protected $path_absolute;
+
+    public function getURL()
+    {
+
+        if (empty($this->to)) {
+            return '';
+        }
+
+        $d = $this->unzipFile($this->to, false);
+        $this->copyExternalDir($d['dir'], $d['fdir']);
+
+        $this->path = $d['fdir'];
+        $this->path_absolute = $this->compiler->vdir->path($d['fdir']);
+
+        return '#/slideshow/' . $this->uid;
+    }
+
+    public function getAdditionnalContent()
+    {
+        return 'data-slideshow="' . rawurlencode($this->generateSlideshow()) . '" ';
+    }
+
+//    public function keep() {
+//        return true;
+//    }
+
+    public function getDefaultTooltip()
+    {
+        return 'view slideshow';
+    }
+
+    public function generateSlideshow()
+    {
+
+//        $this->compiler->addJsLib('slick', 'js/libs/slick/slick.min.js');
+//        $this->compiler->addLess('slick/slick-bundle');
+        $this->compiler->addJsLib('splide', 'js/libs/splide/splide.js');
+        $this->compiler->addLess('fluidbook.slideshow');
+
+        $extensions = ['jpg', 'png', 'jpeg', 'gif'];
+
+        $slideshowID = 'slideshow_' . $this->uid;
+        $XML_path = $this->path_absolute . '/slideshow.xml'; // Optional file so it may not exist
+
+        $this->getURL();
+
+        $slides = [];
+
+        // If the zip file contained a slideshow.xml file, use that for fetching images and their captions
+        if (file_exists($XML_path)) {
+            $slideshow_XML = simplexml_load_string(file_get_contents($XML_path));
+            $slideshowData = CubeIT_Util_Xml::toObject($slideshow_XML);
+            $images = [];
+            if (is_array($slideshowData->image)) {
+                $images = $slideshowData->image;
+            } else if (is_object($slideshowData->image)) {
+                $images = [$slideshowData->image];
+            }
+            foreach ($images as $img) {
+                $full_path = $this->path_absolute . '/' . $img->_name;
+                $slides[] = ['caption' => $img->_caption, 'path' => $full_path];
+            }
+            $thumbnails = $slideshowData->_thumbnails !== 'false' && $slideshowData->_thumbnails;
+        } else {
+            // Or by default, just get all the images that were in the zip file...
+
+            // Previously this was getting all files recursively but it caused problems
+            // when there was a __MACOSX sub directory inside the zip file containing
+            // resource forks for the JPGs. There's no need to support nested directories
+            // in the zip so we only look at the zip's root directory...
+            $afiles = CubeIT_Files::getDirectoryIterator($this->path_absolute);
+
+            foreach ($afiles as $afile) {
+                /** @var SplFileInfo $afile */
+                if (!$afile->isFile()) {
+                    continue;
+                }
+                $ext = mb_strtolower($afile->getExtension());
+                if (!in_array($ext, $extensions)) {
+                    continue;
+                }
+                $slides[] = ['path' => $afile->getPathname(), 'caption' => null];
+                uasort($slides, [$this, '_orderSlidesByFilename']);
+            }
+
+            $thumbnails = (count($slides) > 1);
+        }
+
+        // Main slider
+        $res = '<div class="fb-slideshow splide" id="' . $slideshowID . '" data-open-index="' . $this->extra . '" data-thumbnails="' . ($thumbnails ? '1' : '0') . '">' . $this->_slides($slides) . '</div>';
+
+        // Thumbnails slider
+        if ($thumbnails) {
+            $res .= '<div class="fb-slideshow-thumbnails splide" id="' . $slideshowID . '_thumbnails">' . $this->_slides($slides, false) . '</div>';
+        }
+
+        $res .= '<script>';
+        $res .= 'fluidbook.slideshow.initSlideshow("' . $slideshowID . '");';
+        $res .= '</script>';
+
+        return $res;
+    }
+
+    protected function _slides($slides, $show_captions = true) {
+
+        $res  = '<div class="splide__track">';
+        $res .= '<ul class="splide__list">';
+
+        foreach ($slides as $slide) {
+            $image_path_relative = $this->compiler->vdir->relativePath($slide['path']);
+            $image_info = getimagesize($slide['path']);
+            $image_info_json = ($image_info) ? json_encode(['width' => $image_info[0], 'height' => $image_info[1]]) : '';
+            $image_dimensions = ($image_info) ? $image_info[3] : '';
+
+            $res .= '<li class="fb-slideshow-slide splide__slide">';
+            $res .= '<div class="splide__slide__container">';
+            $res .= '<img class="fb-slideshow-slide-image" src="' . $image_path_relative . '" data-meta="'. htmlspecialchars($image_info_json, ENT_QUOTES) .'" '. $image_dimensions .'>';
+            $res .= '</div>'; // .splide__slide__container
+
+            if ($show_captions && null !== $slide['caption']) {
+                $res .= '<p class="fb-slideshow-slide-caption">' . $slide['caption'] . '</p>';
+            }
+
+            $res .= '</li>'; // .fb-slideshow-slide
+        }
+
+        $res .= '</ul>'; // .splide__list
+        $res .= '</div>'; // .splide__track
+
+        return $res;
+    }
+
+
+    protected function _orderSlidesByFilename($a, $b)
+    {
+        return strcmp($a['path'], $b['path']);
+    }
+}
+
+class iframeLink extends wsHTML5Link
+{
+    protected $_defaultTooltip;
+
+    function getHTMLContainerClass()
+    {
+        return parent::getHTMLContainerClass() . ' iframe';
+    }
+
+    function getHTMLContent()
+    {
+        return '<iframe src="' . self::_handleFile($this) . '" width="100%" height="100%" frameborder="0" marginwidth="0" marginheight="0" scrolling="auto" allowfullscreen mozallowfullscreen="true" webkitallowfullscreen="true" onmousewheel=""></iframe>';
+    }
+
+    /**
+     * @param $link wsHTML5Link
+     */
+    public static function _handleFile($link)
+    {
+        if (!CubeIT_Util_Url::isDistant($link->to)) {
+            $e = explode('.', $link->to);
+            $ext = array_pop($e);
+            if ($ext === 'oam' || $ext === 'zip') {
+                if ($ext === 'oam') {
+                    $d = $link->unzipFile($link->to, true);
+                    $config = $link->getConfigOAM($d['dir']);
+                    $link->copyExternalDir($d['dir'], $d['fdir']);
+                } else if ($ext === 'zip') {
+                    $d = $link->unzipFile($link->to, false);
+                    $config = $link->getConfigZip($d['dir']);
+                    $link->copyExternalDir($d['dir'], $d['fdir']);
+                }
+                if ($config['html']) {
+                    return $d['fdir'] . '/' . $config['html'];
+                }
+            } else {
+                $link->_defaultTooltip = 'click to open the file';
+                $link->copyExternalFile($link->to);
+                return wsHTML5Link::getUniversalLocation($link->to);
+            }
+        }
+
+        return $link->to;
+    }
+}
+
+class articleLink extends normalLink
+{
+    protected $article;
+
+    public function init()
+    {
+        parent::init();
+        $this->compiler->config->articlesList[$this->to]['page'] = $this->page;
+        $this->article = $this->compiler->config->articlesList[$this->to];
+    }
+
+    public function getURL()
+    {
+        return '#/article/' . $this->article['url'];
+    }
+}
+
+class iframePopupLink extends normalLink
+{
+    public function getURL()
+    {
+        return '#/iframe/' . md5($this->to);
+    }
+
+    public function getTrack()
+    {
+        return ' data-track="' . $this->to . '"';
+    }
+
+    public function getAdditionnalContent()
+    {
+        $res = parent::getAdditionnalContent();
+        $markup = '<div class="iframeContainer" data-type="' . $this->iframeType . '">';
+        $markup .= '<iframe src="' . iframeLink::_handleFile($this) . '" width="100%" height="100%" frameborder="0" marginwidth="0" marginheight="0" scrolling="auto" allowfullscreen mozallowfullscreen="true" webkitallowfullscreen="true" onmousewheel=""></iframe>';
+        $markup .= '</div>';
+        return $res . ' data-iframe="' . rawurlencode($markup) . '" ';
+    }
+
+    public function keep()
+    {
+        return false;
+    }
+
+}