"require": {\r
"php": ">=7.2",\r
"php-mime-mail-parser/php-mime-mail-parser": "2.11.1",\r
- "jaybizzle/crawler-detect": "^1.2"\r
+ "jaybizzle/crawler-detect": "^1.2",\r
+ "ext-mbstring": "*"\r
}\r
}\r
. 'FROM themes t '\r
. 'LEFT JOIN themes_books_nb b ON t.theme_id=b.theme '\r
. 'LEFT JOIN utilisateurs_entreprise e ON t.proprietaire=e.utilisateur_id');\r
+ $this->views->createView('ws3_themes_vue','SELECT t.*, b.nb as nbBooks, CONCAT(e.prenom,\' \',e.nom,\' (\',e.rs,\')\') AS proprietaire_nom '\r
+ . 'FROM ws3_themes t '\r
+ . 'LEFT JOIN themes_books_nb b ON t.theme_id=b.theme '\r
+ . 'LEFT JOIN utilisateurs_entreprise e ON t.proprietaire=e.utilisateur_id');\r
$this->views->createView('demandes_vue', 'SELECT d.*, CONCAT(c.rs,\' (\',c.prenom,\' \',c.nom,\')\') AS utilisateur_nom, CONCAT(r.rs,\' (\',r.prenom,\' \',r.nom,\')\') AS revendeur_nom, c.entreprise AS entreprise, a.prenom AS administrateur_nom, c.ws_count AS fluidbooks, IF(d.gclid=\'\',\'Organic\',\'Paid\') AS origin '\r
. 'FROM demandes d '\r
. 'LEFT JOIN utilisateurs_entreprise r ON d.revendeur=r.utilisateur_id '\r
$book_id = $e[0];
$hash = $e[1];
+
self::commonHTML5Viewer($book_id, $hash);
}
public static function loadingCompile($url, $book, $theme)
{
- global $core;
+ global $core;
$tcolor = $theme->parametres->couleurL;
if ($tcolor == $theme->parametres->backgroundColor) {
$tcolor = $theme->parametres->loadingSecColor;
$html = '';
if (file_exists($htmlFile)) {
$html = file_get_contents($htmlFile);
+ } else {
+ $dao->compile($book_id, 'html5', false, false, false, $book, false);
+ $html = file_get_contents($htmlFile);
}
foreach ($replace as $from => $to) {
$html = str_replace($from, $to, $html);
}
+
echo $html;
exit;
}
protected function singleton($r)\r
{\r
$theme = new wsTheme();\r
- $theme->theme_id = $r->theme_id;\r
- $theme->nom = $r->nom;\r
- $theme->date = $r->date;\r
- $theme->proprietaire = $r->proprietaire;\r
- if ($r->exists('nbBooks')) {\r
- $theme->nbBooks = $r->nbBooks;\r
- }\r
- if ($r->exists('proprietaire_nom')) {\r
- $theme->proprietaire_nom = $r->proprietaire_nom;\r
- }\r
- $theme->signature = $r->signature;\r
- $theme->icones = $r->icones;\r
- $p = unserialize($r->parametres);\r
- if (!$p) {\r
- $p = new wsThemeParametres($theme);\r
+ if ($r->exists('id')) {\r
+ $theme->theme_id = $r->id;\r
+ $theme->nom = $r->name;\r
+ $theme->date = strtotime($r->created_at);\r
+ $theme->proprietaire = $r->owner;\r
+ $theme->signature = 0;\r
+ $theme->icones = 15;\r
+ $theme->parametres = new wsThemeParametres($theme);\r
+ $theme->parametres->initFromWS3Data($r);\r
} else {\r
- $p->setParent($theme);\r
+ $theme->theme_id = $r->theme_id;\r
+ $theme->nom = $r->nom;\r
+ $theme->date = $r->date;\r
+ $theme->proprietaire = $r->proprietaire;\r
+ if ($r->exists('nbBooks')) {\r
+ $theme->nbBooks = $r->nbBooks;\r
+ }\r
+ if ($r->exists('proprietaire_nom')) {\r
+ $theme->proprietaire_nom = $r->proprietaire_nom;\r
+ }\r
+ $theme->signature = $r->signature;\r
+ $theme->icones = $r->icones;\r
+ if(CubeIT_Util_Json::isJson($r->parametres)){\r
+ $p = new wsThemeParametres($theme);\r
+ $p->importFromJson($r->parametres);\r
+ }else {\r
+ $p = unserialize($r->parametres);\r
+ }\r
+ if (!$p) {\r
+ $p = new wsThemeParametres($theme);\r
+ } else {\r
+ $p->setParent($theme);\r
+ }\r
+ $theme->parametres = $p;\r
}\r
- $theme->parametres = $p;\r
\r
return $theme;\r
}\r
\r
+ protected function _table($table)\r
+ {\r
+ global $core;\r
+\r
+ if (false && $core->user->utilisateur_id == 5) {\r
+ if ($table === 'themes_vue') {\r
+ return 'ws3_theme_vue';\r
+ } else if ($table === 'themes') {\r
+ return 'ws3_theme';\r
+ }\r
+ } else {\r
+ return $table;\r
+ }\r
+ }\r
+\r
public function selectById($theme_id, $table = 'themes_vue')\r
{\r
- $r = $this->con->select('SELECT * FROM ' . $table . ' WHERE theme_id=\'' . $this->con->escape($theme_id) . '\' LIMIT 1');\r
+ $r = $this->con->select('SELECT * FROM ' . $this->_table($table) . ' WHERE theme_id=\'' . $this->con->escape($theme_id) . '\' LIMIT 1');\r
return $this->singleton($r);\r
}\r
\r
} else {\r
$table = 'themes_vue';\r
}\r
- $r = $this->con->select('SELECT * FROM ' . $table . ' WHERE theme_id IN (SELECT theme FROM books WHERE book_id=\'' . $this->con->escape($book_id) . '\') LIMIT 1');\r
+ $r = $this->con->select('SELECT * FROM ' . $this->_table($table) . ' WHERE theme_id IN (SELECT theme FROM books WHERE book_id=\'' . $this->con->escape($book_id) . '\') LIMIT 1');\r
return $this->singleton($r);\r
}\r
\r
public function getAllThemes($user, $order = '', $demos = null)\r
{\r
if (wsDroits::admin(false)) {\r
- $sql = 'SELECT * FROM themes_vue';\r
+ $sql = 'SELECT * FROM '.$this->_table('themes_vue');\r
} else {\r
$or = '';\r
if (wsDroits::revendeur()) {\r
}\r
$or .= ') OR ( proprietaire IN(' . $user->ws_rights . ') ';\r
}\r
- $sql = 'SELECT * FROM themes_vue WHERE theme_id IN (SELECT theme FROM books WHERE proprietaire IN(' . $user->ws_rights . ') ' . $or . ')';\r
+ $sql = 'SELECT * FROM '.$this->_table('themes_vue').' WHERE theme_id IN (SELECT theme FROM books WHERE proprietaire IN(' . $user->ws_rights . ') ' . $or . ')';\r
}\r
$sql .= ' ' . $order;\r
\r
$this->setDefaultValues();\r
}\r
\r
+\r
+ public function initFromWS3Data($r)\r
+ {\r
+ print_r($r->columns);\r
+ exit;\r
+ $this->datas = $r->columns();\r
+ }\r
+\r
public function importFromJson($jsonString)\r
{\r
$this->datas = json_decode($jsonString, true);\r
$this->fields['backgroundImage'] = array('type' => 'file', 'default' => 'backgroundImg.jpg', 'editable' => true,\r
'label' => __('Image de fond'),\r
'path' => $themeRoot,\r
- 'uploadURL' => $uploadThemeURL);\r
+ 'uploadURL' => $uploadThemeURL . '&fieldname=backgroundImage');\r
$this->fields['repeat'] = array('type' => 'combo',\r
'datas' => array(__('Etirer') => wsTheme::STRETCH,\r
__('Etirer le fond en conservant les proportions') => wsTheme::RATIO,\r
$this->fields['menuImage'] = array('type' => 'file', 'default' => 'menu_back.png', 'editable' => true,\r
'label' => __('Image de fond'),\r
'path' => $themeRoot,\r
- 'uploadURL' => $uploadThemeURL);\r
+ 'uploadURL' => $uploadThemeURL . '&fieldname=menuImage');\r
$this->fields['invertMenuPosition'] = array('type' => 'boolean', 'default' => false, 'editable' => true,\r
'label' => __("Intervertir le menu et le logo"));\r
\r
$this->fields['topBar'] = array('type' => 'file', 'default' => '', 'editable' => true,\r
'label' => __('Top Bar'),\r
'path' => $themeRoot,\r
- 'uploadURL' => $uploadThemeURL);\r
+ 'uploadURL' => $uploadThemeURL . '&fieldname=topBar');\r
$this->fields['topBarAlign'] = array('type' => 'combo',\r
'datas' => array(__('Centré') => wsTheme::CENTER,\r
__('Gauche') => wsTheme::LEFT,\r
$this->fields['afterSearch'] = array('type' => 'file', 'default' => '', 'editable' => true,\r
'label' => __('Image supplémentaire'),\r
'path' => $themeRoot,\r
- 'uploadURL' => $uploadThemeURL,\r
+ 'uploadURL' => $uploadThemeURL . '&fieldname=afterSearch',\r
'hint' => __('Image disposée à droite du champ de recherche')\r
);\r
\r
$this->fields['logo'] = array('type' => 'file', 'default' => 'menu_clientLogo.png', 'editable' => true,\r
'label' => __('Logo'),\r
'path' => $themeRoot,\r
- 'uploadURL' => $uploadThemeURL);\r
+ 'uploadURL' => $uploadThemeURL . '&fieldname=logo');\r
$this->fields['logoHideWhenOverriden'] = array('type' => 'boolean', 'default' => false, 'editable' => true,\r
'label' => __("Cacher le logo lorsqu'il est partiellement masqué par la publication"));\r
$this->fields['favicon'] = array('type' => 'file', 'default' => '', 'editable' => true,\r
'label' => __('Icone (pour favicon et CD-ROM)'),\r
'path' => $themeRoot,\r
'fileFilter' => $imageFilter,\r
- 'uploadURL' => $uploadThemeURL . '&type=favicon',\r
+ 'uploadURL' => $uploadThemeURL . '&type=favicon&fieldname=favicon',\r
'hint' => __('Image PNG de 256x256'));\r
$this->fields['iosicon'] = array('type' => 'file', 'default' => '', 'editable' => true,\r
'label' => __('Icone (pour application iOS)'),\r
'path' => $themeRoot,\r
'fileFilter' => $imageFilter,\r
- 'uploadURL' => $uploadThemeURL . '&type=iosicon',\r
+ 'uploadURL' => $uploadThemeURL . '&type=iosicon' . '&fieldname=iosicon',\r
'hint' => __('Image PNG de 1024x1024'));\r
$this->fields['androidicon'] = array('type' => 'file', 'default' => '', 'editable' => true,\r
'label' => __('Icone (pour application Android)'),\r
'hint' => __('Image PNG de 1024x1024'));\r
\r
$this->forms['logo'] = array('label' => __('Personnalisation du logo'),\r
- 'fieldsnames' => array('logo', 'logoHideWhenOverriden', '|', 'favicon', 'iosicon', 'androidicon'));\r
+ 'fieldsnames' => array('logo', 'logoHideWhenOverriden', '|', 'favicon'));\r
/* Loader */\r
$this->fields['logoLoader'] = array('type' => 'file', 'default' => 'logoLoader.png', 'editable' => true,\r
'label' => __('Logo affiché au chargement'),\r
'path' => $themeRoot,\r
- 'uploadURL' => $uploadThemeURL);\r
+ 'uploadURL' => $uploadThemeURL . '&fieldname=logoLoader');\r
$this->fields['couleurL'] = array('type' => 'couleur', 'default' => '', 'editable' => true,\r
'label' => __("Couleur principale de la barre de chargement"));\r
$this->fields['loadingSecColor'] = array('type' => 'couleur', 'default' => 'ffffff', 'editable' => true,\r
// '//svg:defs/svg:pattern',\r
'//svg:defs/svg:g[starts-with(@id, "surface")]//svg:path',\r
'//svg:defs/svg:g[starts-with(@id, "surface")]//svg:rect',\r
+ '//svg:defs/svg:g[starts-with(@id, "surface")]//svg:use[starts-with(@xlink:href, "#image")]',\r
'/svg:svg/svg:g[@id="surface1"]//svg:path',\r
'/svg:svg/svg:g[@id="surface1"]//svg:rect',\r
'/svg:svg/svg:g[@id="surface1"]//svg:filter',\r
'/svg:svg/svg:g[@id="surface1"]//svg:use[starts-with(@xlink:href, "#image")]',\r
- '//svg:image',\r
+ '//svg:svg/svg:g[@id="surface1"]//svg:use[starts-with(@xlink:href, "#image")]',\r
+ //'//svg:image',\r
);\r
\r
//global $svglog;\r
return $this->restDelete('/api/fluidbook-theme/' . $themeId, ['api_token' => $core->user->api_token]);\r
}\r
\r
+ public function uploadThemeFile($themeId, $field, $path)\r
+ {\r
+ global $core;\r
+ return $this->restPut('/api/fluidbook-theme/' . $themeId . '/uploadfile/' . $field, ['api_token' => $core->user->api_token, 'path' => $path]);\r
+ }\r
+\r
/**\r
* @param wsTheme $theme\r
*/\r
+++ /dev/null
-<?php
-
-class wsHTML5Compiler
-{
- public static $resolutions = array(150, 300);
- public $maxRes = 300;
-
- public $jsLibs = [
- 'cube' =>
- ['js/libs/cube/util.js',
- 'js/libs/cube/fb.js',],
- 'modernizr' =>
- ['js/libs/modernizr/modernizr.min.js',
- 'js/libs/modernizr/tests.js',],
- 'modifier' => ['js/libs/threejs/modifier.min.js'],
- 'threejs' =>
- ['js/libs/threejs/legacy/three.min.js',
- 'js/libs/threejs/legacy/Projector.js',
- 'js/libs/threejs/legacy/CanvasRenderer.js',
- ],
-// 'threejs-latest' =>
-// ['js/libs/threejs/latest/three.min.js',
-// ],
- 'jquery' =>
- ['js/libs/jquery/jquery.min.js',
- ],
-
- 'jquery-extras' => ['js/libs/jquery/jquery.transform.js',
- 'js/libs/jquery/jquery.form.min.js',
- 'js/libs/jquery/jquery.mousewheel.min.js',
- 'js/libs/jquery/jquery.hashchange.min.js'],
- 'aria' => ['js/libs/aria/radio.js',],
- 'bluebird' => ['js/libs/bluebird.min.js'],
- 'screenfull' => ['js/libs/screenfull.min.js'],
- 'storage' => ['js/libs/storage.js',],
- 'hotkeys' => ['js/libs/hotkeys.min.js',],
- 'forge' => ['js/libs/forge/forge-sha256.min.js',],
- 'perfectscrollbar' => ['js/libs/perfect-scrollbar/perfect-scrollbar.js',
- 'js/libs/perfect-scrollbar/perfect-scrollbar.jquery.js'],
- 'confirm' => ['js/libs/jquery/jquery.confirm.min.js'],
- 'mmenu' =>
- ['js/libs/mmenu/jquery.mmenu.all.js'],
- 'tweenmax' =>
- ['js/libs/gsap/TweenMax.min.js',
- 'js/libs/gsap/jquery.gsap.min.js',
- 'js/libs/gsap/plugins/ScrollToPlugin.min.js',
- 'js/libs/threejs/Tweenmax.threejs.js',],
- 'hammer' => ['js/libs/hammer.min.js',],
- 'interactjs' => ['js/libs/interact.min.js'],
- 'gal' =>
- ['js/libs/gal/gal.js',
- 'js/libs/gal/gal.filesystem.js',],
- 'raphael' =>
- ['js/libs/raphael/raphael.min.js',
- 'js/libs/gsap/plugins/RaphaelPlugin.min.js'],
- 'countup' =>
- ['js/libs/countup/countup.min.js'],
- 'clipboard' => ['js/libs/clipboard.min.js'],
- 'fluidbook' =>
- ['js/libs/fluidbook/fluidbook.utils.js',
- 'js/libs/fluidbook/fluidbook.networkcontrol.js',
- 'js/libs/fluidbook/fluidbook.splash.js',
- 'js/libs/fluidbook/fluidbook.links.js',
- 'js/libs/fluidbook/fluidbook.support.js',
- 'js/libs/fluidbook/fluidbook.video.js',
- 'js/libs/fluidbook/fluidbook.viewport.js',
- 'js/libs/fluidbook/fluidbook.desktop.js',
- 'js/libs/fluidbook/fluidbook.service.js',
- 'js/libs/fluidbook/fluidbook.share.js',
- 'js/libs/fluidbook/fluidbook.l10n.js',
- 'js/libs/fluidbook/fluidbook.slider.js',
- 'js/libs/fluidbook/fluidbook.pagetransitions.js',
- 'js/libs/fluidbook/fluidbook.nav.js',
- 'js/libs/fluidbook/fluidbook.interface.js',
- 'js/libs/fluidbook/fluidbook.input.js',
- 'js/libs/fluidbook/fluidbook.touch.js',
- 'js/libs/fluidbook/fluidbook.loader.js',
- 'js/libs/fluidbook/fluidbook.search.js',
- 'js/libs/fluidbook/fluidbook.help.js',
- 'js/libs/fluidbook/fluidbook.resize.js',
- 'js/libs/fluidbook/fluidbook.stats.js',
- 'js/libs/fluidbook/fluidbook.cache.js',
- 'js/libs/fluidbook/fluidbook.tooltip.js',
- 'js/libs/fluidbook/fluidbook.bookmarks.js',
- 'js/libs/fluidbook/fluidbook.background.js',
- 'js/libs/fluidbook/fluidbook.pad.js',
- 'js/libs/fluidbook/fluidbook.audiodescription.js',
- 'js/libs/fluidbook/fluidbook.audioplayer.js',
- 'js/libs/fluidbook/fluidbook.accessibility.js',
- 'js/libs/fluidbook/fluidbook.privacy.js',
- 'js/libs/fluidbook/fluidbook.zoom.js',
- 'js/libs/fluidbook/fluidbook.menu.js',
- 'js/libs/fluidbook/fluidbook.sound.js',
- 'js/libs/fluidbook/fluidbook.contentlock.js',
- 'js/libs/fluidbook/fluidbook.scorm.js',
- 'js/libs/fluidbook/fluidbook.3dflip.js',
- 'js/libs/fluidbook/menu/fluidbook.chapters.js',
- 'js/libs/fluidbook/menu/fluidbook.index.js',
- 'js/libs/fluidbook/fluidbook.landingpage.js',
- 'js/libs/fluidbook/fluidbook.print.js',
- 'js/libs/fluidbook/fluidbook.secure.js',
- 'js/libs/fluidbook/fluidbook.tabs.js',
- 'js/libs/fluidbook/fluidbook.articles.js',
- 'js/libs/fluidbook/fluidbook.widget.js',
- 'js/libs/fluidbook/fluidbook.keyboard.js',
- 'js/libs/fluidbook/fluidbook.posad.js',
- 'js/libs/fluidbook/fluidbook.notes.js',
- 'js/libs/fluidbook/fluidbook.gamify.js',
- 'js/libs/fluidbook/fluidbook.js',
- 'js/main.js'],
- 'mobilefirst' => [
- 'js/libs/fluidbook/fluidbook.mobilefirst.js',
- 'js/libs/fluidbook/mobilefirst/fluidbook.mobilefirst.slider.js',
- ],
- ];
-
- public $specialJsFiles = array();
-
- public $debugJsFiles = array(
- 'js/libs/Three.js',
- 'data/search.index.js',
- );
- public $testJsFiles = array(
- 'js/libs/cube/fb.js',
- 'js/libs/modernizr/modernizr.min.js',
- 'js/libs/modernizr/tests.js',
- 'js/libs/jquery/jquery.min.js',
- 'js/libs/jquery/jquery.transform.min.js',
- 'js/libs/jquery/jquery.mousewheel.min.js',
- 'js/libs/jquery/jquery.hashchange.min.js',
- 'js/tester.js'
- );
- public $widgetJsFiles = array(
- 'js/libs/cube/fb.js',
- 'js/libs/modernizr/modernizr.min.js',
- 'js/libs/modernizr/tests.js',
- 'js/libs/jquery/jquery.min.js',
- 'js/libs/jquery/jquery.transit.js',
- 'js/widget.js'
- );
-
-
- public $jsFiles = [];
-
- // Collection of LESS files to be compiled
- // Filename with no extension, relative to the /style directory in the player build folder
- public $lessFiles = ['fluidbook'];
-
- public $specialCSS = array();
- public $phonegapStandardPlugins = array('ios' => array('ExternalFileUtil'),
- 'android' => array('webintent'));
- public $pluginCSS = array();
- public $pluginJs = array();
- public $htmlmultimedia = array();
- public $cssX = array();
- public $cssY = array();
- public $cssWidths = array();
- public $pdf2htmlRatio;
- public $scale;
- public $multiply;
- public $div = array();
- public $numerotation;
- public $fontDocs = array();
- public $dir;
- public $z = 3;
- public $vdir;
- public $wdir;
- protected $_lottieIDByHash = [];
-
- /**
- *
- * @var wsBook
- */
- public $book;
- public $pages;
- public $theme;
- public $version;
- public $book_id;
- public $themeRoot;
-
- /**
- *
- * @var wsDAOBook
- */
- public $daoBook;
- public $needToRecompileContents = true;
- public $needToRecompileSettings = true;
- public $width;
- public $height;
- public $cssWidth;
- public $cssHeight;
- public $cssOneWidth;
- public $cssOneHeight;
- public $cssScale;
- public $linkScale;
- public $cssSVGScale;
- public $optimalWidth = 567;
- public $optimalHeight = 709;
- public $additionalConfig = array();
- public $fontScale = 1;
- public $cache = array();
- public $backgroundsPrefix = array();
- public $svg = true;
- public $config = array();
- public $assets = '';
- public $phonegap = false;
- public $phonegapVersion;
- public $standalone = false;
- public $hiddenContents = array();
- public $appcache;
- public $home;
- public $widget = true;
- public $multiApp = false;
- public $pageLabels = array();
- public $stylesheets = array();
- public $logfp = null;
- public $logtime = null;
- public $beginBody = array();
- public $seoArticles = [];
- public $securityPolicyWhitelist = ['*.google-analytics.com', '*.youtube.com', '*.ytimg.com', '*.googletagmanager.com'];
- public $writeLinksData = false;
- public $content_lock = [];
- public $cssfont = [];
- public $lessVariables = ["import-cart-styles" => 'none'];
- protected $_indexVars = null;
- public $accessibleTexts = [];
- protected $_svgSymbols = [];
-
- public $_signature;
- /**
- * @var wsHTML5Seo
- */
- public $seo = null;
-
-
- function __construct($book_id, $version = 'stable', $phonegap = false, $phonegapVersion = 'latest', $dir = null, $standalone = false, $appcache = false, $home = false, $book = null)
- {
- global $core;
-
- $this->phonegapVersion = wsHTML5::getPhonegapVersion($phonegapVersion);
- $this->appcache = $appcache;
- $this->multiApp = $this->home = $home;
- $this->version = $version;
-
-
- if ($version == 'stable') {
- $this->assets = WS_COMPILE_ASSETS . '/player/branches/master';
- } else if ($version == 'dev') {
- $this->assets = WS_COMPILE_ASSETS . '/player/local/master';
- } else {
- list($branch, $location) = explode('|', $version);
- $this->assets = WS_COMPILE_ASSETS . '/player/' . ($location == 'git' ? 'branches' : $location) . '/' . $branch;
- }
-
- $this->phonegap = $phonegap;
- $this->standalone = $standalone || $this->phonegap;
- $this->appcache = $appcache;
- $this->widget = !$this->phonegap;
-
- cubePHP::set_memory('12G');
-
- if (trim($book_id) == '') {
- return;
- }
- $this->book_id = $book_id;
- $this->log('Start compilation');
-
- if (is_null($dir)) {
- $this->dir = WS_BOOKS . '/html5/' . $book_id . '/';
- } else {
- $this->dir = $dir;
- }
- $this->vdir = new CubeIT_Files_VirtualDirectory($this->dir);
-
-
- $this->daoBook = new wsDAOBook($core->con);
- if (null === $book) {
- $this->book = $this->daoBook->selectById($book_id);
- } else {
- $this->book = $book;
- }
-
- $this->wdir = $this->book->getAssetDir();
-
- $this->widget = !$this->phonegap && $this->book->parametres->widget;
-
- $this->pages = $this->daoBook->getPagesOfBook($book_id);
- $this->maxRes = min(300, $this->book->parametres->maxResolution);
-
- $daoTheme = new wsDAOTheme($core->con);
- $this->theme = $daoTheme->getThemeOfBook($book_id, true);
- $this->themeRoot = WS_THEMES . '/' . $this->theme->theme_id . '/';
-
- $daoDoc = new wsDAODocument($core->con);
- $firstDoc = $daoDoc->selectById($this->pages[1]['document_id']);
- $firstDoc->checkInfos();
- $size = $firstDoc->generalInfos['page'][$this->pages[1]['document_page']]['size'];
-
- $this->log('Got data from database');
-
- $this->width = round($size[0], 8);
- $this->height = round($size[1], 8);
-
- $this->imageFormat = $this->book->parametres->imageFormat;
-
- $imagesize = CubeIT_Image::getimagesize($this->book->getFile(1, 'jpg', 150));
- $this->pdf2htmlRatio = round(($imagesize[0] * 0.48) / $this->width, 12);
-
- $this->linkScale = $this->cssScale = $this->z * min($this->optimalWidth / $this->width, $this->optimalHeight / $this->height);
- $this->cssOneScale = $this->z * min(($this->optimalWidth * 2) / $this->width, $this->optimalHeight / $this->height);
-
- $this->cssWidth = $this->width * $this->cssScale;
- $this->cssHeight = $this->height * $this->cssScale;
-
- $this->cssOneWidth = $this->width * $this->cssOneScale;
- $this->cssOneHeight = $this->height * $this->cssOneScale;
-
- $this->cssSVGScale = 1;
-
- $this->scale = 1;
-
- $this->numerotation = explode(',', $this->book->numerotation);
-
- if ($this->isMobileFirst()) {
- $this->cssScale = $this->cssOneScale = 480 / $this->width;
- $this->linkScale = $this->cssScale;
- $this->cssOneWidth = $this->cssWidth = $this->width * $this->cssScale;
- $this->cssOneHeight = $this->cssHeight = $this->height * $this->cssScale;
- $this->initMobileFirst();
- }
-
- $this->svgfiles = array($this->assets . '/images/symbols/interface.svg',
- WS_ICONS . '/' . $this->theme->parametres->iconSet . '/interface.svg');
-
- if ($this->book->parametres->zoomMode == 1 || $this->isMobileFirst()) {
- $this->multiply = $this->pdf2htmlRatio * $this->scale * $this->cssOneScale;
- } else {
- $this->multiply = $this->pdf2htmlRatio * $this->scale * $this->cssScale;
- }
-
- $this->initConfig();
- $this->log('Defined dimensions');
- }
-
- public function isMobileFirst()
- {
- return $this->book->parametres->mobileNavigationType === 'mobilefirst';
- }
-
- public function initMobileFirst()
- {
- $this->theme->parametres->usePageEdges = false;
- }
-
- public function initConfig()
- {
- $this->config = cubeObject::merge($this->book->parametres->toStandardObject(), $this->theme->parametres->toStandardObject());
- $this->config->bookmarkDisablePages = cubeArray::parseRange($this->config->bookmarkDisablePages);
- $this->config->rasterizePages = cubeArray::parseRange($this->config->rasterizePages);
- $this->config->vectorPages = array_diff(cubeArray::parseRange($this->config->vectorPages), $this->config->rasterizePages);
- $this->config->tabsHideOnPages = cubeArray::parseRange($this->config->tabsHideOnPages);
- if ($this->config->tabsHideOnCover) {
- $this->config->tabsHideOnPages[] = 0;
- $this->config->tabsHideOnPages[] = 1;
- }
- if ($this->config->tabsHideOnLastPage) {
- $this->config->tabsHideOnPages[] = count($this->pages);
- }
- $this->config->triggersLinks = [];
- $this->config->hasContentLock = false;
- }
-
- protected function populateConfig()
- {
- $this->config->numerotation = explode(',', $this->book->numerotation);
- $this->config->id = $this->book->book_id;
- $this->config->cid = $this->book->cid;
- $this->config->cacheDate = TIME;
- $this->config->width = $this->cssWidth;
- $this->config->height = $this->cssHeight;
- $this->config->optimalWidth = $this->optimalWidth;
- $this->config->optimalHeight = $this->optimalHeight;
- $this->config->chapters = $this->book->chapters;
- $this->config->videoFormats = $this->getVideosFormats(false);
- $this->config->htmlmultimedia = $this->htmlmultimedia;
- $this->config->phonegap = $this->phonegap;
- $this->config->retinaResolution = min($this->book->parametres->maxResolution, $this->maxRes);
- $this->config->pageLabels = $this->pageLabels;
- $this->config->pageZoomFactor = $this->z;
- $this->config->multiply = $this->multiply;
- $this->config->cssScale = $this->cssScale;
- $this->config->pdfZoomFactor = $this->pdf2htmlRatio;
- if ($this->home) {
- $this->config->home = 'http://home';
- }
- $this->config->multiApp = $this->multiApp;
- foreach ($this->additionalConfig as $k => $v) {
- $this->config->$k = $v;
- }
- if ($this->phonegap && ($this->book->parametres->offlineLink == '' || $this->book->parametres->offlineLink == 'http://')) {
- $this->config->share = false;
- }
- if ($this->config->maxPages > 0) {
- $this->addContentLock($this->config->maxPages);
- }
-
- // We need to be able to reference both navOrder and navOrderH so convert both to arrays
- // We also make sure there are no empty items in the arrays (see: http://php.net/manual/en/function.array-filter.php#111091)
- $this->config->navOrder = array_filter(array_map('trim', explode(',', $this->config->navOrder)), 'strlen');
- $this->config->navOrderH = array_filter(array_map('trim', explode(',', $this->config->navOrderH)), 'strlen');
-
- $this->config->standalone = $this->standalone;
- if ($this->config->phonegap) {
- $this->config->manifest = $this->writeManifest();
- }
-
- $this->writeGPUDatabase();
-
- if ($this->config->form == 'bulle') {
- $this->addJsLib('bulle', 'js/libs/fluidbook/forms/fluidbook.form.bulle.js');
- } else if ($this->config->form == 'bourbon') {
- $this->addJsLib('parsley', 'js/libs/parsley.min.js');
- $this->addJsLib('bourbon', 'js/libs/fluidbook/forms/fluidbook.form.bourbon.js');
- } else if ($this->config->form == 'avery') {
- $this->addJsLib('parsley', 'js/libs/parsley.min.js');
- $this->addJsLib('avery', 'js/libs/fluidbook/forms/fluidbook.form.avery.js');
- $this->addLess('form/avery');
- $this->writeCountries();
- }
- $this->config->seoArticles = $this->seoArticles;
- }
-
- public function writeGrandVisionCart()
- {
- $this->lessVariables['import-cart-styles'] = 'grandvision';
-
- $this->addJsLib('cookie', 'js/libs/jquery/jquery.cookie.js');
- $this->addJsLib('grandvision', 'js/libs/fluidbook/cart/fluidbook.cart.grandvision.js');
- $this->addJsLib('html2pdf', 'js/libs/html2pdf/html2pdf.min.js');
- $this->addJsLib('multiselect', 'js/libs/jquery/jquery.multi-select.js');
- $this->addJsLib('jqueryui', 'js/libs/jquery/jquery-ui.min.js');
- $this->svgfiles[] = $this->assets . '/images/symbols/grandvision.svg';
-
- $cdir = $this->wdir . '/commerce/';
- $file = $cdir . $this->book->parametres->basketReferences;
- $this->config->basketReferences = wsUtil::excelToArrayKeyVars($file, 'Excel2007', true);
-
- $odir = $cdir . '/opt/';
- if (!file_exists($odir)) {
- mkdir($odir, 0777, true);
- }
-
- $it = CubeIT_Files::getDirectoryIterator($cdir);
- $exts = ['png', 'jpg', 'tif', 'mp4'];
- foreach ($it as $file) {
-
- /** @var $file SplFileInfo */
- if ($file->isDir()) {
- continue;
- }
- $ext = $file->getExtension();
- if (!in_array($ext, $exts)) {
- continue;
- }
-
- $e = explode('-', $file->getFilename());
- $ean = $this->findEAN($e);
- if (!$ean) {
- continue;
- }
- if (!isset($this->config->basketReferences[$ean])) {
- continue;
- }
-
- $f = $file->getPathname();
-
- if ($ext === 'mp4') {
- $n = $ean . '-360.mp4';
- $this->config->basketReferences[$ean]['360'] = true;
- $opt = $odir . '/' . $n;
- if (!file_exists($opt) || !filesize($opt) || filemtime($opt) < filemtime($f)) {
- // Optimize original video
- `ffmpeg -i $f -filter:v scale=360:-2 -vcodec libx264 -an $opt`;
- touch($opt, filemtime($f));
- }
- } else {
- if (in_array('front', $e)) {
- $type = 'front';
- } else if (in_array('angle', $e)) {
- $type = 'angle';
- } else {
- continue;
- }
- $n = $ean . '-' . $type . '.jpg';
- $this->config->basketReferences[$ean][$type] = true;
- $opt = $odir . '/' . $n;
- if (!file_exists($opt) || !filesize($opt) || filemtime($opt) < filemtime($f)) {
- // Optimize original image
- $convert = new CubeIT_Image_Resizer_ImageMagick();
- $convert->loadImage($f);
- $convert->resize(1080, null, 'ratio', false, 'C', 'M', 'white');
- $convert->output('jpg', $opt, 75);
- touch($opt, filemtime($f));
- }
- }
- $this->vdir->copy($opt, 'data/commerce/' . $n);
- }
-
- }
-
- public function findEAN($array)
- {
- foreach ($array as $item) {
- if (strlen($item) === 13 && preg_match('/^\d{13}$/', $item)) {
- return $item;
- }
- }
- return false;
- }
-
- public function writeFlexipanCart()
- {
- $this->lessVariables['import-cart-styles'] = 'flexipan';
-
- $this->addJsLib('cookie', 'js/libs/jquery/jquery.cookie.js');
- $this->addJsLib('flexipan', 'js/libs/fluidbook/cart/fluidbook.cart.flexipan.js');
- $this->addJsLib('html2pdf', 'js/libs/html2pdf/html2pdf.min.js');
-
- $cdir = $this->wdir . '/commerce/';
-
-
- $file = $cdir . $this->book->parametres->basketReferences;
- $this->config->basketReferences = wsUtil::excelToArrayKeyVars($file);
-
- wsLinks::getLinksAndRulersFromFile($this->book_id, $links, $rulers);
-
- foreach ($links as $link) {
- if ($link['type'] == '12') {
-
- }
- }
-
- $this->config->product_zoom_references = [];
- foreach ($this->config->basketReferences as $ref => $data) {
- $this->config->product_zoom_references[$ref] = [$ref];
- }
- }
-
- public function writeMIFCart()
- {
- $this->lessVariables['import-cart-styles'] = 'mif';
-
- $this->addJsLib('cookie', 'js/libs/jquery/jquery.cookie.js');
- $this->addJsLib('mif', 'js/libs/fluidbook/cart/fluidbook.cart.mif.js');
- $this->addJsLib('html2pdf', 'js/libs/html2pdf/html2pdf.min.js');
-
- $cdir = $this->wdir . '/commerce/';
- $odir = $cdir . '/opt/';
- if (!file_exists($odir)) {
- mkdir($odir, 0777, true);
- }
-
- $file = $cdir . $this->book->parametres->basketReferences;
- $this->config->basketReferences = wsUtil::excelToArrayKeyVars($file);
-
- wsLinks::getLinksAndRulersFromFile($this->book_id, $links, $rulers);
-
- foreach ($this->config->basketReferences as $ref => $data) {
- $source = $cdir . '/' . $data['Image'];
- if (!file_exists($source)) {
- continue;
- }
- $d = CubeIT_Text::str2URL($ref) . '.jpg';
- $dest = $odir . '/' . $d;
- if (!file_exists($dest) || !filesize($dest) || filemtime($dest) < filemtime($source)) {
- $convert = new CubeIT_Image_Resizer_ImageMagick();
- $convert->loadImage($source);
- $convert->resize(500, 500, 'ratio', false, 'C', 'M', 'ffffff');
- $convert->output('jpg', $dest, 80);
- }
- $vdest = 'data/commerce/opt/' . $d;
- $this->vdir->copy($dest, $vdest);
- $this->config->basketReferences[$ref]['Image'] = $vdest;
- }
-
- foreach ($links as $link) {
- if ($link['type'] == '12') {
-
- }
- }
-
-// $this->config->product_zoom_references = [];
-// foreach ($this->config->basketReferences as $ref => $data) {
-// $r = [$data['Lien']];
-// $this->config->product_zoom_references[$ref] = $r;
-// }
- }
-
-
- public function writePumaCart()
- {
- $this->lessVariables['import-cart-styles'] = 'puma';
-
- $this->addJsLib('parsley', 'js/libs/parsley.min.js');
- $this->addJsLib('cookie', 'js/libs/jquery/jquery.cookie.js');
- $this->addJsLib('puma', 'js/libs/fluidbook/cart/fluidbook.cart.puma.js');
- $this->addJsLib('html2pdf', 'js/libs/html2pdf/html2pdf.min.js');
- $this->addJsLib('exceljs', 'js/libs/exceljs.min.js');
- $this->addVideoJs();
-
- $this->config->basketReferences = wsUtil::excelToArrayKeyVars($this->wdir . 'commerce/' . $this->book->parametres->basketReferences);
-
- wsLinks::getLinksAndRulersFromFile($this->book_id, $links, $rulers);
- foreach ($links as $link) {
- if ($link['type'] == '12' && isset($this->config->basketReferences[$link['to']])) {
- $this->config->basketReferences[$link['to']]['zoom_image'] = 'data/links/zoom_' . $link['uid'] . '.jpg';
- $this->config->basketReferences[$link['to']]['zoom_url'] = base64_encode(file_get_contents($this->dir . '/data/links/zoom_' . $link['uid'] . '.jpg'));
- $this->config->basketReferences[$link['to']]['zoom_image_ratio'] = $link['width'] / $link['height'];
- }
- }
-
- $this->config->product_zoom_references = [];
- $files = ['360°', 'Image supplémentaire', 'Fiche technique'];
- foreach ($this->config->basketReferences as $ref => $data) {
- $r = [];
- foreach ($files as $file) {
- $fname = trim($data[$file]);
- if ($fname !== '') {
- $fname = str_replace(' ', '-', $fname);
- $wfile = $this->wdir . 'commerce/' . $fname;
- if (file_exists($wfile)) {
- $fname = 'data/commerce/' . $fname;
- $this->vdir->copy($wfile, $fname);
- } else {
- $fname = '';
- }
- }
- $r[] = $fname;
- }
- $this->config->product_zoom_references[$ref] = $r;
- }
- }
-
- public function writeCartConfig()
- {
- if ($this->config->basket) {
- $this->addJsLib('cart', 'js/libs/fluidbook/fluidbook.cart.js');
- switch ($this->config->basketManager) {
- case 'Flexipan';
- return $this->writeFlexipanCart();
- case 'Puma':
- return $this->writePumaCart();
- case 'MIF':
- return $this->writeMIFCart();
- case 'GrandVision':
- return $this->writeGrandVisionCart();
- case 'Remarkable':
- $this->addJsLib('parsley', 'js/libs/parsley.min.js');
- $this->addJsLib('cookie', 'js/libs/jquery/jquery.cookie.js');
- $this->addJsLib('remarkable', 'js/libs/fluidbook/cart/fluidbook.cart.remarkable.js');
- break;
- case 'Mopec':
- $this->addJsLib('parsley', 'js/libs/parsley.min.js');
- $this->addJsLib('cookie', 'js/libs/jquery/jquery.cookie.js');
- $this->addJsLib('mopec', 'js/libs/fluidbook/cart/fluidbook.cart.mopec.js');
- break;
- default:
- break;
- }
- }
- if (!$this->config->product_zoom_references && $this->config->basketReferences && $this->config->basketManager == "ZoomProductLink") {
- $this->config->product_zoom_references = $this->config->basketReferences;
- $this->config->basketReferences = '';
- }
-
- if ($this->config->product_zoom_references) {
- if (file_exists($this->config->product_zoom_references) || CubeIT_Util_Url::isDistant($this->config->product_zoom_references)) {
- $referencesFile = $this->config->product_zoom_references;
- } else {
- $referencesFile = $this->wdir . '/commerce/' . $this->config->product_zoom_references;
- }
- if (file_exists($referencesFile) || CubeIT_Util_Url::isDistant($referencesFile)) {
- $function = 'excelToArrayKeyValMulti';
- $this->config->product_zoom_references = wsUtil::$function($referencesFile, 'Excel2007', true);
- }
- }
-
- if ($this->config->basketReferences) {
- if (file_exists($this->config->basketReferences) || CubeIT_Util_Url::isDistant($this->config->basketReferences)) {
- $referencesFile = $this->config->basketReferences;
- } else {
- $referencesFile = $this->wdir . '/commerce/' . $this->config->basketReferences;
- }
-
- if (file_exists($referencesFile) || CubeIT_Util_Url::isDistant($referencesFile)) {
- $ext = CubeIT_Files::getExtension($referencesFile);
- if ($ext == 'xlsx') {
- if ($this->config->basketManager == "ZoomProductLink") {
- $function = 'excelToArrayKeyVal';
- } else {
- $function = 'excelToArray';
- }
- $this->config->basketReferences = wsUtil::$function($referencesFile);
- if ($this->book->parametres->customLinkClass == 'AtlanticDownloadLink') {
- $this->config->basketReferences = wsUtil::atlanticReferences($this->config->basketReferences, 'local/', array($this, 'log'), array($this->vdir, "copy"));
- }
- }
- $this->log("Done cart references");
- }
- }
- }
-
- public function writeGPUDatabase()
- {
- global $core;
- $r = $core->con->select('SELECT gpu,rgpu,score FROM gpu');
- $gpu = [];
- while ($r->fetch()) {
- $gpu[$r->gpu] = $r->score;
- $gpu[$r->rgpu] = $r->score;
- }
- $this->config->gupsc = $gpu;
- $this->config->gupse = wsServices::gpuSeparators();
- }
-
- public function log($step)
- {
- $currenttime = microtime(true);
- if (null === $this->logfp) {
- $this->logfp = fopen('/var/log/extranet/htmlconversions/' . $this->book_id . '.log', 'w+');
- }
- if (null === $this->logtime) {
- $this->logtime = $currenttime;
- }
- $time = $currenttime - $this->logtime;
- $log = $step . ' | ' . round($time, 3) . 's' . "\n";
- fwrite($this->logfp, $log);
- fflush($this->logfp);
- $this->logtime = $currenttime;
- }
-
- public function addFacebookSDK()
- {
- $lang = str_replace('-', '_', $this->book->lang);
- $e = explode('_', $lang);
- if (count($e) > 1) {
- $e[1] = mb_strtoupper($lang);
- }
- $lang = implode('_', $e);
-
- $langsMap = ['fr' => 'fr_FR', 'en' => 'en_US'];
-
- if (isset($langsMap[$lang])) {
- $lang = $langsMap[$lang];
- }
-
- $this->beginBody[] = "<div id=\"fb-root\"></div>
-<script>(function(d, s, id) {
- var js, fjs = d.getElementsByTagName(s)[0];
- if (d.getElementById(id)) return;
- js = d.createElement(s); js.id = id;
- js.src = 'https://connect.facebook.net/" . $lang . "/sdk.js#xfbml=1&version=v2.11&appId=132006430233560';
- fjs.parentNode.insertBefore(js, fjs);
-}(document, 'script', 'facebook-jssdk'));</script>";
- $this->securityPolicyWhitelist[] = '*.facebook.net';
- $this->securityPolicyWhitelist[] = 'data:';
- }
-
- public function addPageLabel($page, $label)
- {
- $this->pageLabels[$label] = $page;
- }
-
- public function getResolutions()
- {
- $res = [];
- foreach (self::$resolutions as $r) {
- if ($r > $this->maxRes) {
- continue;
- }
- $res[] = $r;
- }
- if ($this->widget) {
- $res = array_merge(array(36), $res);
- }
- return $res;
- }
-
- public function getCssScale()
- {
- return $this->cssScale;
- }
-
- public function getLinkScale()
- {
- return $this->linkScale;
- }
-
- public function virtualToPhysical($virtual)
- {
- if (isset($this->pageLabels[$virtual])) {
- return $virtual;
- }
- if (!in_array($virtual, $this->numerotation)) {
- return $virtual;
- }
- $p = array_search($virtual, $this->numerotation);
- return $p + 1;
- }
-
- public function compile($delete = true)
- {
-
- $this->log('Start compile process');
-
- // Raw copy of some directories
- $directories = array('style/fonts/OpenSans', 'images', 'sound', 'video');
- foreach ($directories as $directory) {
- $from = $this->assets . '/' . $directory;
- $this->vdir->copyDirectory($from, $directory);
- }
-
- if ($this->book->parametres->scorm_enable) {
- $this->book->parametres->seoVersion = false;
- }
- $this->writeStats();
- $this->writeSecure();
- $this->log('Copied assets');
- $this->loadPlugins();
- $this->log('Plugins loaded');
- $this->writeImages();
- $this->log('Images written');
- $this->writeCartConfig();
- $this->writeArticles();
- $this->log('Articles written');
- $linksCSS = $this->writeLinks();
- $this->log('Links written');
- $this->writeLangs();
- $this->log('Langs written');
- $this->writeSEO();
- $this->log('SEO written');
- $this->writeWidget();
- $this->log('Widget written');
- $this->writeSounds();
- $this->log('Sound written');
- $this->writeTexts();
- $this->log('Texts written');
- $this->writeAccessibility();
- $this->log('Accessibility written');
- $this->writeExtras();
- $this->log('Extras written');
- $this->populateConfig();
- $this->writeCSS($linksCSS);
- $this->log('CSS written');
- $this->writeIndex();
- $this->log('Index written');
- if ($this->book->parametres->scorm_enable) {
- $this->writeScorm();
- $this->log('SCORM written');
- }
- $this->writeJs();
- $this->log('Js written');
- $this->vdir->sync($delete, $this);
- $this->log('Files Synced');
- }
-
- protected function writeStats()
- {
- if ($this->book->parametres->tagcommander_id) {
- $id = $this->book->parametres->tagcommander_id;
- if (!$this->book->parametres->tagcommander_prod) {
- $id .= '/uat';
- }
-
- $default = ['page_name' => '', 'page_cat1_name' => '', 'page_cat2_name' => '', 'page_cat3_name' => ''];
- $this->config->tagcommander_default_vars = array_merge($default, $this->parseVariables($this->book->parametres->tagcommander_default_vars));
- $this->config->tagcommander_default_vars['env_work'] = $this->book->parametres->tagcommander_prod ? 'prod' : 'pre-prod';
-
- $this->book->parametres->googleAnalyticsCustom .= '<script>window.tc_vars=' . json_encode($this->config->tagcommander_default_vars) . ';</script><script src="//cdn.tagcommander.com/' . $id . '/tc_Multisite_Head.js"></script>';
- $this->book->parametres->statsCustom .= '<script src="//cdn.tagcommander.com/' . $id . '/tc_Multisite_Analytics.js"></script>';
- $this->book->parametres->statsCustom .= '<script src="//cdn.tagcommander.com/' . $id . '/tc_Multisite_Medias.js"></script>';
-
-
- if ($this->book->parametres->tagcommander_plan) {
- $plan = wsUtil::excelToArrayKeyVars($this->wdir . '/' . $this->book->parametres->tagcommander_plan);
- $fixedplan = [];
- foreach ($plan as $k => $v) {
- $e = explode('#', $k);
- if (count($e) === 2) {
- $k = $e[1];
- }
-
- $fixedplan[trim($k, '#/')] = $v;
- }
- $this->config->tagcommander_plan = $fixedplan;
- }
- }
- if (isset($this->book->parametres->googleTagManager) && $this->book->parametres->googleTagManager) {
- $this->book->parametres->googleAnalyticsCustom .= "<!-- Google Tag Manager -->
-<script>(function(w,d,s,l,i){w[l]=w[l]||[];w[l].push({'gtm.start':
-new Date().getTime(),event:'gtm.js'});var f=d.getElementsByTagName(s)[0],
-j=d.createElement(s),dl=l!='dataLayer'?'&l='+l:'';j.async=true;j.src=
-'https://www.googletagmanager.com/gtm.js?id='+i+dl;f.parentNode.insertBefore(j,f);
-})(window,document,'script','dataLayer','" . $this->book->parametres->googleTagManager . "');</script>
-<!-- End Google Tag Manager -->
-";
- $this->book->parametres->statsCustom = '<!-- Google Tag Manager (noscript) -->
-<noscript><iframe src="https://www.googletagmanager.com/ns.html?id=' . $this->book->parametres->googleTagManager . '"
-height="0" width="0" style="display:none;visibility:hidden"></iframe></noscript>
-<!-- End Google Tag Manager (noscript) -->';
- }
- }
-
- protected function writeSecure()
- {
- if ($this->book->parametres->secureClientSidePassword !== '') {
- $credentials = CubeIT_Text::explodeNewLines($this->book->parametres->secureClientSidePasswordCredentials);
- $credentials[] = 'fluidbook:LatacaM4##*';
- $users = [];
- foreach ($credentials as $credential) {
- $salt = bin2hex(random_bytes(5));
- $e = explode(':', $credential);
- if (count($e) <= 1) {
- continue;
- }
- $usersalt = bin2hex(random_bytes(5));
- $user = hash("sha256", $usersalt . '+' . $e[0]);
- $users[$user] = ['salt' => $salt, 'usersalt' => $usersalt, 'hash' => hash("sha256", $salt . '-' . $e[1])];
- }
-
- $secure = file_get_contents($this->wdir . '/' . $this->book->parametres->secureClientSidePassword);
- $secure = str_replace('$CREDENTIALS', 'var CREDENTIALS=' . json_encode($users) . ';', $secure);
- $secure = str_replace('$TITLE', $this->book->parametres->title, $secure);
- $secure = str_replace('$CODE', '$(function () {
- $(\'form\').on(\'submit\', function () {
- var u = $("#username").val();
- var p = $("#password").val();
- var error = true;
- $.each(CREDENTIALS, function (user, data) {
- if (forge_sha256(data.usersalt + \'+\' + u) === user && forge_sha256(data.salt + \'-\' + p) === data.hash) {
- error = false;
- window.sessionStorage.setItem(\'secureUsername\', u);
- window.sessionStorage.setItem(\'securePassword\', p);
- window.location = \'index.html\';
- }
- });
- if (error) {
- $("#message").text(\'Wrong username or password\');
- }
- return false;
- });
- });', $secure);
- $this->vdir->file_put_contents('secure.html', $secure);
-
- $this->config->secureClientSidePasswordCredentials = $users;
- }
- }
-
- protected function loadPlugins()
- {
- $e = explode("\n", $this->book->parametres->mobilePlugins);
- $main = array_pop($this->jsFiles);
-
- $plugins = array();
-
- foreach ($e as $plugin) {
- $plugin = trim($plugin);
- if ($plugin == '') {
- continue;
- }
-
- $d = 'plugins/' . str_replace('.', '/', $plugin);
- $dir = $this->assets . '/' . $d;
- if (!file_exists($dir)) {
- continue;
- }
-
- $plugins[] = $plugin;
-
- if (file_exists($dir . '/plugin.js')) {
- $f = $d . '/plugin.js';
- $this->pluginJs[] = $f;
- $this->vdir->copy($dir . '/plugin.js', $f);
- }
- if (file_exists($dir . '/plugin.css')) {
- $f = $d . '/plugin.css';
- $this->pluginCSS[] = $f;
- $this->vdir->copy($dir . '/plugin.css', $f);
- }
- }
-
- $this->config->plugins = $plugins;
-
- array_push($this->jsFiles, $main);
- }
-
- public function getVideosFormats($poster = true)
- {
- $res = [];
- $res[] = 'mp4';
-
- if ($poster) {
- $res[] = 'jpg';
- }
- return $res;
- }
-
- /**
- * Helper function to add a unique script entry to the JS stack.
- * Normally this is a relative path but it can be an external URL.
- * External URLs are added to the pluginJs collection instead of jsFiles.
- * Duplicate paths are ignored.
- * @param $path
- */
- public function addJs($path, $collection = null)
- {
-
- if (null === $collection) {
- // If JS is external, it will be included via the pluginJs collection
- // Otherwise, it will be compiled into the main JS file
- $collection = (preg_match('#^https?://#i', $path) === 1) ? 'pluginJs' : 'jsFiles';
- }
-
- if (!in_array($path, $this->$collection)) {
- $this->{$collection}[] = $path;
- }
- }
-
- /**
- * Helper function to add a unique stylesheet entry to the LESS stack for compilation
- * Duplicate paths are ignored.
- * @param $path string The path of the file relative to the /style folder, without any extension
- */
- public function addLess($path)
- {
- if (!in_array($path, $this->lessFiles)) {
- $this->lessFiles[] = $path;
- }
- }
-
- protected function writeSounds()
- {
- if ($this->book->parametres->soundTheme == '') {
- return;
- }
- $this->config->simpleSoundTheme = file_exists(WS_SOUNDS . '/' . $this->book->parametres->soundTheme . '/flip.mp3');
- $this->vdir->copyDirectory(WS_SOUNDS . '/' . $this->book->parametres->soundTheme, 'data/sounds');
- }
-
- protected function writeAccessibility()
- {
- if (!$this->book->parametres->audiodescriptionTexts) {
- return;
- }
- $file = $this->wdir . '/' . $this->book->parametres->audiodescriptionTexts;
- new PHPExcel();
- $reader = new PHPExcel_Reader_Excel2007();
- $phpexcel = $reader->load($file);
-
- $sheet = $phpexcel->getActiveSheet();
- $maxRow = $sheet->getHighestRow(0);
-
- for ($i = 0; $i <= $maxRow; $i++) {
- $page = trim($sheet->getCellByColumnAndRow(0, $i)->getValue());
- $text = trim($sheet->getCellByColumnAndRow(1, $i)->getValue());
- if ($page == '' || $text == '') {
- continue;
- }
-
- $replace = ['`' => "'",
- '“' => '"',
- '”' => '"',
- '’' => "'",
- '—' => " - ",
- '‘' => "'",
- ];
-
- $text = str_replace(array_keys($replace), array_values($replace), $text);
-
- if ($this->book->parametres->audiodescriptionVoice) {
- $hash = hash('sha256', $this->book->parametres->audiodescriptionVoice . '_^_' . $text);
- $fname = $hash . '.mp3';
- $dir = WS_BOOKS . '/audiodescription/';
- if (!file_exists($dir)) {
- mkdir($dir, 0777, true);
- }
-
- $file = $dir . $fname;
- if (!file_exists($file)) {
- $e = explode(':', $this->book->parametres->audiodescriptionVoice);
-
- $engine = $e[0];
- $voice = $e[1];
-
- if ($engine == 'festival') {
- $tmp = CubeIT_Files::tempnam() . '.wav';
- $tmptext = CubeIT_Files::tempnam() . '.txt';
-
- file_put_contents($tmptext, $text);
- $cmd = "text2wave -o $tmp $tmptext -eval \"($voice)\"";
- `$cmd`;
-
- `lame $tmp $file`;
- unlink($tmp);
- unlink($tmptext);
- } else if ($engine == 'readspeaker') {
- $e = explode('/', $voice);
- $this->_readSpeaker($text, $e[1], $e[0], $file);
- }
- }
-
- $this->config->audiodescription[$page] = $fname;
- $this->vdir->copy($file, 'data/audiodescription/' . $fname);
- }
- $this->accessibleTexts[$page] = $text;
- }
-
-
- if (count($this->accessibleTexts) > 0) {
- $this->config->accessibleTexts = $this->accessibleTexts;
- }
- }
-
- protected function _readSpeaker($text, $language, $voice, $output)
- {
- $text_to_read = urlencode($text);
- // Your API key here
- $apikey = 'e9c321908f2dd016f6a0c34d2d786aff';
-
- // File path and file name
- $filepath = $output;
-
- // API URL of text-to-speech enabler
- $api_url = 'https://tts.readspeaker.com/a/speak';
-
- // Compose API call url
- $url = $api_url . '?key=' . $apikey . '&streaming=0&lang=' . $language . '&voice=' . $voice . '&text=' . $text_to_read;
-
- // Initiating curl
- $ch = curl_init($url);
-
- curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
- curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
-
- $data = curl_exec($ch);
-
- $status = curl_getinfo($ch, CURLINFO_HTTP_CODE);
-
- if ($status == 200 && !curl_errno($ch)) {
- // Everything is fine, close curl and save file
- curl_close($ch);
- file_put_contents($filepath, $data);
- } else {
- // Cannot translate text to speech because of text-to-speech API error
- error_log(__FILE__ . ': API error while text-to-speech. error code=' . $status);
- curl_close($ch);
- }
-
- }
-
- protected function _writeIndex($page)
- {
- if (!isset($this->seo->pages[$page])) {
- return;
- }
- $seo = $this->seo->pages[$page];
- $html = $seo->getHTML();
-
- if ($this->book->parametres->seoVersion) {
- $seo->writePage($html, $this->vdir);
- }
- if ($page == 1) {
- $seo->writePage($html, $this->vdir, 'index.html');
- }
- }
-
- public function getIndexVars()
- {
- if (null === $this->_indexVars) {
- global $core;
- $titre = $this->book->parametres->title;
-
-
- if (null === $this->_signature) {
- $daoSignature = new wsDAOSignature($core->con);
- $this->_signature = $daoSignature->selectById($this->book->parametres->signature);
- }
-
- $credits = $this->_signature->credits;
-
- $hiddenContents = implode("\n", $this->hiddenContents);
-
- $bgcolor = $this->theme->parametres->loadingBackColor;
-
- // Feuilles de style
- $sheets = array_merge($this->stylesheets, $this->specialCSS);
-
- $style = array();
- foreach ($sheets as $sheet) {
- $style[] = '<link type="text/css" rel="stylesheet" media="screen" href="' . $sheet . '?j=' . TIME . '">';
- }
- $style = implode("\n\t\t", $style);
-
- $pagesContents = '';
-
- $cache = '';
-
- $beginbody = implode("\n", array_unique($this->beginBody));
-
- $jstime = "?j=" . TIME;
-
- $iscript = '';
- if (count($this->htmlmultimedia)) {
- $iscript .= '<script type="text/javascript">' . "\n";
- $iscript .= implode("\n", $this->htmlmultimedia);
- $iscript .= '</script>' . "\n";
- }
-
- $script = '<script type="text/javascript" charset="utf-8" src="data/datas.js' . $jstime . '"></script>' . "\n";
- foreach ($this->jsLibs as $jsLib => $files) {
- $script .= "\t" . '<script type="text/javascript" charset="utf-8" src="data/' . $jsLib . '.js' . $jstime . '"></script>' . "\n";
- }
- if ($this->book->parametres->scorm_enable) {
- $script .= "\t" . '<script type="text/javascript" charset="utf-8" src="data/scorm.js' . $jstime . '"></script>' . "\n";
- }
- if (count($this->specialJsFiles)) {
- $script .= "\t" . '<script type="text/javascript" charset="utf-8" src="data/special.js' . $jstime . '"></script>' . "\n";
- }
- foreach ($this->pluginJs as $p) {
- $script .= "\t" . '<script type="text/javascript" charset="utf-8" src="' . $p . $jstime . '"></script>' . "\n";
- }
- $script .= $iscript;
-
- $socialTitle = html::escapeHTML($this->book->parametres->facebook_title ? $this->book->parametres->facebook_title : $titre);
- $socialDescription = html::escapeHTML($this->book->parametres->facebook_description ? $this->book->parametres->facebook_description : $this->book->parametres->seoDescription);
- $socialImage = 'https://workshop.fluidbook.com/services/facebook_thumbnail?cid=' . $this->book->cid . '&j=' . TIME;
- $dim = CubeIT_Image::getimagesize($socialImage);
- $socialImageWidth = $dim[0];
- $socialImageHeight = $dim[1];
-
- $titre = $this->book->parametres->title;
-
- $description = '<meta name="description" content="' . $this->seo->pages[1]->description . '">';
-
- $twittercard = '<meta name="twitter:title" content="' . $socialTitle . '">
- <meta name="twitter:description" content="' . $socialDescription . '">
- <meta name="twitter:image" content="' . $socialImage . '">
- <meta name="twitter:site" content="@Fluidbook">
- <meta name="twitter:card" content="summary_large_image">';
- $opengraph = '<meta property="og:title" content="' . $socialTitle . '"/>
- <meta property="og:description" content="' . $socialDescription . '"/>
- <meta property="og:image" content="' . $socialImage . '"/>
- <meta property="og:image:width" content="' . $socialImageWidth . '"/>
- <meta property="og:image:height" content="' . $socialImageHeight . '"/>';
-
- $favicon = '';
- $hasIos = false;
- if ($iosico = $this->checkThemeImage($this->theme->parametres->iosicon)) {
- $hasIos = true;
- $this->vdir->copy($iosico, 'data/apple-touch-icon.png');
- $favicon .= '<link rel="apple-touch-icon" href="data/apple-touch-icon.png" />' . "\n\t";
- }
- if ($this->theme->parametres->favicon != '') {
-
- $pngFile = $this->checkThemeImage($this->theme->parametres->favicon);
- $icoFile = $this->checkThemeImage('favicon.ico');
-
- if (!file_exists($icoFile) || filemtime($icoFile) < filemtime($pngFile) || filemtime(__FILE__) > filemtime($icoFile)) {
- $tmp = CubeIT_Files::tempnam() . '.png';
- $convert = "convert $pngFile -resize 64x64^ -gravity center $tmp";
- `$convert`;
-
- $icotool = new cubeCommandLine('icotool');
- $icotool->setArg('c');
- $icotool->setArg('o', $icoFile);
- $icotool->setArg(null, $tmp);
- $icotool->execute();
-
- unlink($tmp);
- }
-
- $this->vdir->copy($icoFile, 'data/favicon.ico');
- $this->vdir->copy($pngFile, 'data/favicon.png');
-
- $datapng = 'data:image/png;base64,' . base64_encode(file_get_contents($pngFile));
-
- $favicon .= '<link rel="icon" type="image/png" href="' . $datapng . '" />' . "\n\t";
- if (!$hasIos) {
- $favicon .= '<link rel="apple-touch-icon" href="data/favicon.png" />';
- }
- }
-
- $print = $this->writePrint();
- $message = sprintf($this->__('Your browser is not up to date and is not able to run this publication. %sLearn more%s'), '<br /><a href="http://www.whatbrowser.org/intl/' . $this->config->defaultLang . '/" target="_blank">', '</a>');
-
- $splash = '';
- $splashstyles = '';
- $img = $this->book->parametres->splashImage;
- if ($img) {
- $this->vdir->copy($this->wdir . '/' . $img, 'data/images/' . $img);
- $splashstyles = 'background-image:url(' . 'data/images/' . $img . ');background-size:contain;background-position:50% 50%;';
- if ($this->book->parametres->splashURL !== '') {
- $splash = '<a href="' . $this->book->parametres->splashURL . '" target="' . $this->book->parametres->splashTarget . '" style="display:block;position:absolute;top:0;left;0;width:100%;height:100%"></a>';
- }
- } else if ($ll = $this->checkThemeImage($this->theme->parametres->logoLoader)) {
- $dim = CubeIT_Image::getimagesize($ll);
- if ($dim !== false) {
- $this->vdir->copy($ll, 'data/images/' . $this->theme->parametres->logoLoader);
- $splash .= '<div class="logo"><img src="data/images/' . $this->theme->parametres->logoLoader . '" width="' . $dim[0] . '" height="' . $dim[1] . '" alt="" /></div>';
- }
- }
-
- if ($this->theme->parametres->iconSet < 15) {
- $this->theme->parametres->iconSet = 15;
- }
-
-
- $svg = '';
- foreach ($this->svgfiles as $svgfile) {
- if (file_exists($svgfile)) {
- $svg .= str_replace('$bookmark-color', wsHTML5::colorToCSS($this->theme->parametres->bookmarkBackgroundColor), file_get_contents($svgfile));
- } else {
- die($svgfile . ' does not exist');
- }
- }
- if (count($this->_svgSymbols)) {
- $svg .= '<svg xmlns="http://www.w3.org/2000/svg" style="display: none;">' . implode('', $this->_svgSymbols) . '</svg>' . "\n";
- }
-
- if ($this->phonegap) {
- $csp = "<meta http-equiv=\"Content-Security-Policy\" content=\"default-src 'self' data: gap: 'unsafe-inline' *; style-src 'self' 'unsafe-inline'; font-src 'self' data:; script-src 'self' 'unsafe-inline' 'unsafe-eval' " . implode(' ', array_unique($this->securityPolicyWhitelist)) . "; img-src * data:\">";
- }
- $lang = $this->book->lang;
- $vars = array('lang', 'titre', 'credits', 'style', 'script', 'pagesContents', 'print', 'hiddenContents', 'splash', 'splashstyles', 'cache', 'bgcolor', 'message', 'favicon', 'svg', 'beginbody', 'csp', 'opengraph', 'twittercard', 'description');
-
- $res = [];
- foreach ($vars as $v) {
- if (isset($$v)) {
- $res['<!-- $' . $v . ' -->'] = $$v;
- } else {
- $res['<!-- $' . $v . ' -->'] = '';
- }
- }
- $this->_indexVars = $res;
- }
- return $this->_indexVars;
- }
-
- protected function writeIndex()
- {
- $iv = $this->getIndexVars();
- foreach ($iv as $k => $v) {
- $this->seo->html = str_replace($k, $v, $this->seo->html);
- }
- if ($this->book->parametres->seoVersion) {
- foreach ($this->pages as $page => $infos) {
- $this->_writeIndex($page);
- }
- } else {
- $this->_writeIndex(1);
- }
- }
-
- protected function writeWidget()
- {
- // Write widget html
- if ($this->widget) {
- $whtml = file_get_contents($this->assets . '/widget.html');
- $script = '<script type="text/javascript" charset="utf-8" src="data/datas.js"></script>';
- $script .= '<script type="text/javascript" charset="utf-8" src="data/widget.js"></script>';
-
- $style = '<link type="text/css" rel="stylesheet" href="style/widget.css">';
- $vars = array('titre', 'style', 'script');
- foreach ($vars as $v) {
- if (isset($$v)) {
- $whtml = str_replace('<!-- $' . $v . ' -->', $$v, $whtml);
- } else {
- $whtml = str_replace('<!-- $' . $v . ' -->', '', $whtml);
- }
- }
- $this->vdir->file_put_contents('widget.html', $whtml);
- }
- }
-
- function writeSEO()
- {
- foreach ($this->seoArticles as $seoArticle) {
- $html = file_get_contents($this->assets . '/_seo.html');
- $a = $seoArticle;
- unset($a['image']);
- $a['imageurl'] = 'https://workshop.fluidbook.com/services/facebook_thumbnail?cid=' . $this->book->cid . '&j=' . TIME;
- if ($seoArticle['image']) {
- $a['imageurl'] .= '&image=' . $seoArticle['image'];
- }
- $dim = CubeIT_Image::getimagesize($a['imageurl']);
- $a['imagewidth'] = $dim[0];
- $a['imageheight'] = $dim[1];
- foreach ($a as $k => $v) {
- $html = str_replace('$' . $k, $v, $html);
- }
- $this->vdir->file_put_contents('p/' . $seoArticle['url'], $html);
- }
- $this->seo = new wsHTML5Seo($this);
- }
-
- public function addContentLock($page, $unlockConditions = '')
- {
- $this->config->hasContentLock = true;
- $unlockConditions = CubeIT_Text::explodeNewLines($unlockConditions);
- $conditions = [];
- foreach ($unlockConditions as $unlockCondition) {
- $e = explode(',', $unlockCondition);
- if (!isset($e[1])) {
- $e[1] = 'click';
- }
- $conditions[] = $e;
- }
- $page = max(1, $page);
- if (!isset($this->content_lock[$page])) {
- $this->content_lock[$page] = ['unlocked' => 0, 'conditions' => []];
- }
- $this->content_lock[$page]['conditions'] = array_merge($this->content_lock[$page]['conditions'], $conditions);
- }
-
- protected function writeScorm()
- {
- if ($this->book->parametres->scorm_version == '1.2') {
- $manifestfile = '_imsmanifest.12.xml';
- } elseif ($this->book->parametres->scorm_version == '2004') {
- $manifestfile = '_imsmanifest.2004.xml';
- }
-
- $manifest = file_get_contents($this->assets . '/' . $manifestfile);
- if (!$this->book->parametres->scorm_title) {
- $this->book->parametres->scorm_title = $this->book->parametres->title;
- }
- if (!$this->book->parametres->scorm_id || ($this->book->book_id > 16614 && $this->book->parametres->scorm_id === 'MFMCTE091mobile')) {
- $this->book->parametres->scorm_id = 'fb_' . $this->book->book_id;
- }
- if (!$this->book->parametres->scorm_org) {
- $this->book->parametres->scorm_org = 'Fluidbook';
- }
-
- $vars = array('scorm_id', 'scorm_org', 'scorm_title');
- foreach ($vars as $v) {
- $manifest = str_replace('$' . $v, htmlspecialchars($this->book->parametres->$v, ENT_QUOTES), $manifest);
- }
- $this->vdir->file_put_contents('imsmanifest.xml', $manifest);
-
-
- $this->config->scorm_variables = $this->book->parametres->scorm_variables = $this->parseVariables($this->book->parametres->scorm_variables);
- if ($this->book->parametres->scorm_quizdata) {
- $this->config->scorm_quizdata = wsUtil::excelToArray($this->wdir . '/' . $this->book->parametres->scorm_quizdata);
- }
- }
-
- protected function parseVariables($f)
- {
- $variables = [];
- $f = str_replace("\r", "\n", $f);
- $e = CubeIT_Text::explodeNewLines($f);
- foreach ($e as $item) {
- $item = trim($item);
- if ($item == '') {
- continue;
- }
- $f = explode('=', $item, 2);
- $variables[trim($f[0])] = trim($f[1]);
- }
- return $variables;
- }
-
- protected function writePrint()
- {
- if (!$this->book->parametres->print && !$this->book->parametres->pdf) {
- return;
- }
-
- $res = wsUtil::compilePDF($this->book, $this->pages);
- if ($res !== false) {
- $this->vdir->copy($res, 'data/' . $this->book->parametres->pdfName);
- }
- return '';
- }
-
- protected function addFilesInfos($key, $file)
- {
- if (!file_exists($file)) {
- return;
- }
- if (!isset($this->config->filesInfos)) {
- $this->config->filesInfos = array();
- }
- $infos = array('filesize' => filesize($file));
- $dim = CubeIT_Image::getimagesize($file);
- if ($dim !== false) {
- $infos['width'] = $dim[0];
- $infos['height'] = $dim[1];
- }
- $this->config->filesInfos[$key] = $infos;
- }
-
- protected function __($str)
- {
- if (!isset($this->config->l10n)) {
- $this->writeLangs();
- }
-
- if (isset($this->config->l10n['default']->$str)) {
- return $this->config->l10n['default']->$str;
- } else {
- return $str;
- }
- }
-
- protected function writeLangs()
- {
- global $core;
- $daoLang = new wsDAOLang($core->con);
- $lang = $daoLang->selectById($this->book->lang);
- $langs = $daoLang->selectAll();
-
- $t = CubeIT_Util_Object::toArray($this->book->traductions);
-
- $traductions = (!is_countable($t) || !count($t)) ? $lang->traductions : $t;
-
- $this->config->l10n = array();
- $this->config->l10n['default'] = $traductions;
- $this->config->defaultLang = $this->book->lang;
-
- foreach ($langs as $lang) {
- $this->config->l10n[$lang->lang_id] = $lang->traductions;
- }
- $iso = l10n::getISOcodes();
- if ($this->book->parametres->multilang != '') {
- $flagsDir = 'images/flags';
- if (!file_exists($flagsDir)) {
- mkdir($flagsDir);
- }
- $ml = str_replace("\r", "\n", $this->book->parametres->multilang);
- $ml = str_replace("\n\n", "\n", $ml);
- $e = explode("\n", $ml);
- $m = array();
- foreach ($e as $l1) {
- $l1 = trim($l1);
- if ($l1 == '') {
- continue;
- }
- $l = explode(',', $l1);
- $flag = $l[1];
-
- $ll = explode('-', $l[0]);
-
- $this->vdir->copy(cubeMedia::getFlagFile($flag), $flagsDir . '/' . $flag . '.png');
- $l[3] = cubeText::ucfirst($iso[$l[0]]);
- $l[4] = cubeCountry::getCountryName($flag, $ll[0]);
- $m[] = implode(',', $l);
- }
-
- $this->config->multilang = implode("\n", $m);
- }
- }
-
- protected function writeExtras()
- {
- if ($as = $this->checkThemeImage($this->theme->parametres->afterSearch)) {
- $this->vdir->copy($as, 'data/images/' . $this->theme->parametres->afterSearch);
- }
- if ($this->book->parametres->externalArchives != '') {
- $this->addFilesInfos('archives', $this->wdir . '/' . $this->book->parametres->externalArchives);
- $this->vdir->copy($this->wdir . '/' . $this->book->parametres->externalArchives, 'data/images/' . $this->book->parametres->externalArchives);
- }
-
- if ($this->book->parametres->navExtraImage != '') {
- $this->vdir->copy($this->wdir . '/' . $this->book->parametres->navExtraImage, 'data/images/' . $this->book->parametres->navExtraImage);
- }
-
- if ($this->book->parametres->navExtraImageMobile != '') {
- $this->vdir->copy($this->wdir . '/' . $this->book->parametres->navExtraImageMobile, 'data/images/' . $this->book->parametres->navExtraImageMobile);
- }
-
- for ($i = 1; $i <= 5; $i++) {
- $ic = $this->book->parametres->{'navExtraIcon' . $i};
- if ($ic != '') {
- if (stristr($ic, '.svg')) {
- $e = explode('.', $ic);
- $sname = 'external-' . $e[0];
- $this->addSVGSymbolFromFile($this->wdir . '/' . $ic, $sname);
- $this->config->{'navExtraIcon' . $i} = $sname;
- } else {
- $this->vdir->copy($this->wdir . '/' . $ic, 'data/images/' . $ic);
- }
- }
- }
- }
-
- protected function addSVGSymbolFromFile($svg, $symbolName)
- {
- $svg = wsTools::optimizeSVG($svg);
-
- $xml = simplexml_load_string(file_get_contents($svg));
- $viewBox = (string)$xml['viewBox'];
-
- $this->_svgSymbols[] = '<symbol id="' . $symbolName . '" viewBox="' . $viewBox . '">' . $this->SimpleXMLElement_innerXML($xml) . '</symbol>';
- }
-
- protected function writeLinks()
- {
- global $core;
-
- switch ($this->book->parametres->customLinkClass) {
- case 'WescoSalesLink':
- $this->specialJsFiles[] = 'js/libs/interact.min.js';
- $this->specialJsFiles[] = 'js/libs/fluidbook/special/wescosales.js';
- $this->specialCSS[] = 'wescosales';
- break;
- case 'AtlanticDownloadLink':
- $this->specialJsFiles[] = 'js/libs/fluidbook/special/atlanticdownload.js';
- $this->specialCSS[] = 'atlanticdownload';
- break;
- case 'MiraklEaster2021':
- $this->specialJsFiles[] = 'js/libs/fluidbook/special/mirakleaster2021.js';
- $this->specialCSS[] = 'mirakleaster2021';
- break;
- }
-
- $this->config->links = array();
- $this->config->clinks = array();
- $this->config->bookmarkGroups = array();
-
- $ignore = $this->book->parametres->ignoreLinksTypes;
- if (!$ignore) {
- $ignore = array();
- } else {
- $ignore = explode(',', $ignore);
- }
-
- if ($this->book->parametres->externalChaptersHTML != '') {
- $d = $this->unzipFile($this->book->parametres->externalChaptersHTML, false, 'data/chapters/');
- $meta = $this->getConfigZIP($d['dir']);
- $this->config->externalChaptersSize = new stdClass();
- $this->config->externalChaptersSize->width = $meta['width'];
- $this->config->externalChaptersSize->height = $meta['height'];
- $this->vdir->copyDirectory($d['dir'], $d['fdir']);
- }
-
- wsLinks::getLinksAndRulersFromFile($this->book_id, $links, $rulers);
-
- if ($this->book->parametres->basketManager === 'Puma') {
- foreach ($links as $k => $init) {
- if ($init['type'] == 12 && isset($this->config->product_zoom_references[$init['to']]) && count($this->config->product_zoom_references[$init['to']]) > 0 && implode('', $this->config->product_zoom_references[$init['to']]) != '') {
- $init['infobulle'] = 'Digital information';
- $init['animation'] = 'reflet-anim.html';
- $links[$k] = $init;
- }
- if ($init['type'] == 7) {
- $init['image'] = '';
- $init['display_area'] = false;
- $links[$k] = $init;
- }
- }
-
- }
-
- // Custom landing page content
- if ($this->book->parametres->landingPage != '') {
- $d = $this->unzipFile($this->book->parametres->landingPage, false, 'data/landing-page/');
- $this->vdir->copyDirectory($d['dir'], $d['fdir']);
- }
-
- if ($this->book->parametres->tabsHTML5 != '' && file_exists($this->wdir . '/' . $this->book->parametres->tabsHTML5)) {
- $ext = CubeIT_Files::getExtension($this->book->parametres->tabsHTML5);
- if ($ext === 'zip') {
- $links[] = [
- 'page' => 'background',
- 'top' => 0,
- 'left' => 0,
- 'width' => 100,
- 'height' => 100,
- 'type' => 6,
- 'to' => $this->book->parametres->tabsHTML5,
- 'alternative' => $this->book->parametres->tabsHTML5,
- 'image' => '',
- 'inline' => 1,
- 'interactive' => 1,
- 'class' => 'tabslink',
- 'uid' => 'tabs',
- ];
- } else if ($ext === 'svg') {
- $this->vdir->copy($this->wdir . '/' . $this->book->parametres->tabsHTML5, 'data/tabs.svg');
- $this->config->svgTabs = true;
- $pagesLists = ['tabsPages', 'tabsSections'];
- foreach ($pagesLists as $pagesList) {
- $e = explode(',', $this->book->parametres->$pagesList);
- $list = [];
- foreach ($e as $k => $v) {
- $v = trim($v);
- if ($v === '') {
- continue;
- }
- if ($v !== '-') {
- if ($this->book->parametres->tabsPagesNumbers === 'virtual') {
- $v = $this->virtualToPhysical($v);
- }
- }
- $list[] = $v;
- }
- $this->config->$pagesList = $list;
- }
- }
- }
-
- $pagesOfCustomLinks = [];
- $hiddenLinks = [];
-
- $linksCopy = $links;
-
- foreach ($linksCopy as $k => $linkData) {
- if ($linkData['type'] == 35 || $linkData['type'] == 15 || $linkData['type'] == 39) {
- $linkData = wsLinks::decryptLink($linkData);
- $animations = contentLink::parseAnimations($linkData['image_rollover']);
- foreach ($animations as $animation) {
- if (isset($animation['backgroundcolor']) && $animation['backgroundcolor'] != 'transparent') {
- $dupData = $linkData;
- $dupData['type'] = 14;
- $dupData['to'] = $animation['backgroundcolor'];
-
- $dupData['uid'] = 'b_' . $linkData['uid'];
- if (!isset($animation['zindex'])) {
- $animation['zindex'] = 0;
- }
- $z = intval($animation['zindex']) - 1;
- $dupData['image_rollover'] = 'zindex=' . $z;
- array_push($links, $dupData);
- array_push($links, $linkData);
- unset($links[$k]);
- }
- }
- }
- if (isset($linkData['image']) && $linkData['image'] && $linkData['type'] != 28 && $linkData['type'] != 35) {
- $dupData = $linkData;
- $dupData['image'] = '';
- $dupData['animation'] = '';
- $dupData['to'] = $linkData['image'];
- $dupData['rollover'] = $linkData['image_rollover'];
- $dupData['type'] = 15;
- $dupData['uid'] = 'i_' . $linkData['uid'];
- if (wsHTML5Link::isScorm($linkData)) {
- $dupData['scorm'] = true;
- }
- array_push($links, $dupData);
- }
- if (isset($linkData['animation']) && $linkData['animation']) {
- $dupData = $linkData;
- $dupData['image'] = '';
- $dupData['animation'] = '';
- $dupData['inline'] = true;
- $dupData['interactive'] = false;
- $dupData['alternative'] = $linkData['animation'];
- $dupData['type'] = 6;
- $dupData['uid'] = 'a_' . $linkData['uid'];
- $dupData['video_width'] = $dupData['video_height'] = 0;
- if (wsHTML5Link::isScorm($linkData)) {
- $dupData['scorm'] = true;
- }
- array_push($links, $dupData);
- }
- if ($linkData['type'] == 7) {
- $k = $linkData['to'];
- $e = explode(':', $k);
- if (count($e) > 1) {
- $k = $e[1];
- }
- if (!isset($pagesOfCustomLinks[$k])) {
- $pagesOfCustomLinks[$k] = [];
- }
- if (!in_array($linkData['page'], $pagesOfCustomLinks[$k])) {
- $pagesOfCustomLinks[$k][] = $linkData['page'];
- }
- }
- if ($linkData['type'] == 32) {
- $ids = explode(',', $linkData['to']);
- foreach ($ids as $id) {
- $id = trim($id);
- if ($id === 'tabs') {
- $this->config->tabsHiddenAtStartup = true;
- } else {
- $hiddenLinks[] = $id;
- $hiddenLinks[] = 'i_' . $id;
- }
- }
- }
- }
-
- $this->config->pagesOfCustomLinks = $pagesOfCustomLinks;
-
- $i = 1;
- $pages = array();
- $cpages = array();
- $ctpages = array();
- $css = array();
- $linkPages = [];
- $allLinksData = [];
- $gamifyCoins = [];
-
- usort($links, array($this, '_sortLinks'));
-
- foreach ($links as $linkData) {
- if (in_array($linkData['type'], $ignore)) {
- continue;
- }
-
- $linkData['hidden'] = in_array($linkData['uid'], $hiddenLinks);
- if ($linkData['type'] == 28) {
- $this->addSEOArticle('#/page/' . $linkData['page'], $linkData['to'], $linkData['extra'], $linkData['image']);
- continue;
- }
- $link = wsHTML5Link::getInstance($this->base62($i), $linkData, $this);
- if (is_null($link)) {
- continue;
- }
-
- $linksToAdd = [$link];
- if ($link->overlapDoublePage()) {
- $linksToAdd[] = $link->getRightClone();
- }
-
- foreach ($linksToAdd as $lta) {
-
- $css[] = $lta->getCSSContainer();
- if (!isset($pages[$lta->page])) {
- $pages[$lta->page] = [];
- $cpages[$lta->page] = [];
- $ctpages[$lta->page] = [];
- }
-
- $d = $lta->getDepth();
- if ($d < 30) {
- $v = 'ctpages';
- } else if ($d < 50) {
- $v = 'cpages';
- } else {
- $v = 'pages';
- }
-
- $lta->setInitialOrder($i);
- if (!isset($$v[$lta->page][$lta->blendmode])) {
- $$v[$lta->page][$lta->blendmode] = [];
- }
-
- array_push($$v[$lta->page][$lta->blendmode], $lta);
- $i++;
- }
- // Make old "aftersearch" link compatible with new "extra" menu option by extracting link URL
- if ($link->page == 'aftersearch') {
- $this->config->afterSearchLink = $link->to;
- $this->config->afterSearchTooltip = $link->infobulle;
- }
-
- if (strpos($link->page, 'link_') === 0) {
- $linkPages[$link->page] = true;
- }
-
- if ($link->gamifyCoins) {
- $gamifyCoins[$linkData['uid']] = (float)$link->gamifyCoins;
- }
-
- $allLinksData[$linkData['uid']] = $linkData;
-
- if ($link->keep()) {
- $this->hiddenContents[] = $link->getHTMLContainer();
- }
- }
-
- $allpages = range(0, $this->book->parametres->pages + 1);
- if ($this->book->parametres->themeEnableAfterSearch) {
- $allpages[] = 'aftersearch';
- }
- $allpages[] = 'background';
- $allpages[] = 'archives';
- foreach ($linkPages as $linkPage => $true) {
- $allpages[] = $linkPage;
- }
-
- foreach ($allpages as $i) {
- $this->config->links[$i] = $this->_htmlLinkList($pages[$i]['normal'] ?? []);
- $this->config->clinks[$i] = $this->_htmlLinkList($cpages[$i] ?? []);
- $this->config->ctlinks[$i] = $this->_htmlLinkList($ctpages[$i] ?? []);
- }
-
- if ($this->writeLinksData) {
- $this->config->linksData = $allLinksData;
- }
- $this->config->gamifyCoins = $gamifyCoins;
-
- return $css;
- }
-
- protected function _htmlLinkList($list)
- {
- if (!count($list)) {
- return '';
- }
- usort($list, [$this, '_sortLinksByDepth']);
- $res = '';
- foreach ($list as $item) {
- $res .= $item->getHTMLContainer();
- }
- return $res;
- }
-
- protected function _sortLinksByDepth($a, $b)
- {
- $c = $a->getDepth() - $b->getDepth();
- if ($c === 0) {
- return $a->getInitialOrder() - $b->getInitialOrder();
- }
- return $c;
- }
-
- public function addSlideshowLibrary($inline = true)
- {
- $l = ($inline ? $this->config->inlineSlideshowLibrary : $this->config->popupSlideshowLibrary);
- if ($l === 'splide') {
- $this->addJsLib('splide', 'js/libs/splide/splide.js');
- }
-
- $this->addJsLib('slideshow', ['js/libs/fluidbook/slideshow/fluidbook.slideshow.js',
- 'js/libs/fluidbook/slideshow/fluidbook.slideshow.' . $l . '.js']);
- $this->addLess('slideshow/' . $l);
- }
-
- public function addSEOArticle($page, $title, $intro, $image, $id = null, $url = null, $content = '')
- {
- if (null === $url) {
- $url = CubeIT_Text::str2URL($title) . '.html';
- }
- if (null === $id) {
- $id = $title;
- }
-
- $this->seoArticles[$id] = ['title' => $title, 'description' => $intro, 'image' => $image, 'content' => $content, 'page' => $page, 'url' => $url, 'id' => $id];
- }
-
- public function _sortLinks($a, $b)
- {
-
- $priorities = array(26 => -1, 35 => 1);
-
- $pa = isset($priorities[$a['type']]) ? -$priorities[$a['type']] : 0;
- $pb = isset($priorities[$b['type']]) ? -$priorities[$b['type']] : 0;
- return $pb - $pa;
- }
-
- public function addBookmarkGroup($link)
- {
- if ($link['left'] > $this->book->parametres->width) {
- //$link['page']++;
- }
- if ($link['page'] <= 0 || $link['page'] > $this->book->parametres->pages) {
- return;
- }
-
- $this->config->bookmarkGroups[] = array('page' => ($link['page']), 'nb' => $link['to'], 'name' => $link['extra']);
- }
-
- public function addTriggersLink($page, $link)
- {
- $this->config->triggersLinks[] = ['page' => $page, 'link' => $link];
- }
-
- public function addAudiodescription($link)
- {
- $this->config->audiodescription[$link['page']] = $link['to'];
- $this->copyLinkFile($link['to'], 'data/audiodescription/');
- }
-
- protected function beforeWriteConfig()
- {
- // Dynamic background
- $dbc = [];
- $p = $this->parseVariables($this->book->parametres->dynamicBackgroundColor);
- foreach ($p as $range => $color) {
- $e = explode(',', $color);
- $pages = cubeArray::parseRange($range);
- foreach ($pages as $page) {
- $dbc[$page] = $e;
- }
- }
- $this->config->dynamicBackgroundColor = $dbc;
-
- // Content locks
- uasort($this->content_lock, function ($a, $b) {
- return $a['page'] - $b['page'];
- });
-
- $this->config->content_lock = $this->content_lock;
- }
-
- protected function writeJs()
- {
- $this->beforeWriteConfig();
-
- $config = $this->writeConfig();
-
- $this->vdir->file_put_contents('data/datas.js', $config);
- $finals = $this->jsLibs;
- if ($this->book->parametres->scorm_enable) {
- $finals['scorm'] = array();
- $finals['scorm'][] = 'js/libs/scorm/apiwrapper.js';
- $finals['scorm'][] = 'js/libs/scorm/scorm.js';
- }
- if (count($this->specialJsFiles)) {
- $finals['special'] = $this->specialJsFiles;
- }
- if ($this->widget) {
- $finals['widget'] = $this->widgetJsFiles;
- }
-
- $dirminimized = $this->assets . '/js/min/';
- if (!file_exists($dirminimized)) {
- mkdir($dirminimized, 0777, true);
- }
-
- foreach ($finals as $jsfinal => $files) {
- $mintime = 0;
- $hash = hash('sha256', json_encode($files));
- $minimized = $dirminimized . $jsfinal . '-' . $hash . '-min.js';
- if (!file_exists(dirname($minimized))) {
- mkdir(dirname($minimized));
- }
- if (file_exists($minimized) && filesize($minimized) > 0) {
- $mintime = filemtime($minimized);
- $reminimize = false;
- } else {
- $mintime = 0;
- $reminimize = true;
- }
-
- if (!$reminimize) {
- foreach ($files as $file) {
- $f = $this->assets . '/' . $file;
- if (file_exists($f) && filemtime($f) > $mintime) {
- $reminimize = true;
- break;
- }
- }
- }
-
- if (!$reminimize) {
- if (filemtime(__FILE__) > $mintime || (file_exists(__DIR__ . '/class.ws.html5.links.php') && filemtime(__DIR__ . '/class.ws.html5.links.php') > $mintime)) {
- $reminimize = true;
- }
- }
-
- if ($reminimize) {
- $js = '';
- $hasNonMin = false;
- foreach ($files as $file) {
- $f = $this->assets . '/' . $file;
- if (!file_exists($f)) {
- continue;
- }
- if (strpos($f, '.min.') === false) {
- $hasNonMin = true;
- }
- $js .= file_get_contents($f);
- $js .= ";\n\n";
- }
- $tmp = cubeFiles::tempnam();
- file_put_contents($tmp, $js);
-
- if (file_exists($minimized)) {
- unlink($minimized);
- }
-
- if (file_exists($tmp) && filesize($tmp) > 0) {
- if ($hasNonMin) {
- $uglify = new CubeIT_CommandLine('/usr/local/bin/uglifyjs');
- $uglify->setArg('o', $minimized);
- $uglify->setArg(null, $tmp);
- $uglify->execute();
- $uglify->debug();
- } else {
- $uglify = null;
- copy($tmp, $minimized);
- }
-
- if (!file_exists($minimized) || filesize($minimized) == 0) {
- die('An error occured while uglifying ' . $hasNonMin . '? ' . $minimized . ': ' . ($uglify ? $uglify->commande : '') . ' :: ' . ($uglify ? $uglify->output : '') . '(' . implode(',', $files) . ')');
- }
- }
- }
- $dest = 'data/' . $jsfinal . '.js';
- $this->vdir->copy($minimized, $dest);
- }
-
-
- if ($this->phonegap) {
- $this->vdir->copy(WS_COMPILE_ASSETS . '/_html5/js/libs/phonegap/' . $this->phonegapVersion . '/cordova-' . $this->phonegap . '.js', 'data/cordova.js');
- }
- $this->vdir->copyDirectory($this->assets . '/js/libs/fluidbook/workers', 'js/libs/fluidbook/workers');
- $this->vdir->copyDirectory($this->assets . '/js/libs/stand', 'js/libs/stand');
- $this->vdir->copyDirectory($this->assets . '/js/libs/polyfills', 'js/libs/polyfills');
- }
-
- public function writeTexts()
- {
- $cache = sha1($this->book->parametres->highlightResults . '/--/' . $this->book->parametres->searchWordSelectionAlgorithm . '///' . $this->book->parametres->textExtraction . '|--|' . $this->book->parametres->ignoreSearchSeparators . '|||' . $this->book->composition_update . '()()()' . filemtime(WS_TOOLS . '/fwstk/out/artifacts/fwstk_jar/fwstk.jar'));
- $cacheDir = WS_BOOKS . '/index/' . $this->book_id . '/' . $cache . '/';
- if (!file_exists($cacheDir)) {
- mkdir($cacheDir, 0777, true);
-
- $this->daoBook->makeTextsIndexes($this->book, $this->pages, $index, $textes, true);
- file_put_contents($cacheDir . '/search.index.js', 'var INDEX=' . $index . ';' . "\r");
- if ($this->book->parametres->highlightResults) {
- file_put_contents($cacheDir . '/search.highlight.js', 'var HIGHLIGHTS=' . json_encode($this->daoBook->makeHighlightIndex($this->book, $this->pages)) . ";\r");
- }
- if ($this->book->parametres->searchWordSelectionAlgorithm == 'expression') {
- file_put_contents($cacheDir . '/search.texts.js', 'var TEXTS=' . $textes . ";\r");
- }
- }
-
- $this->vdir->copy($cacheDir . '/search.index.js', 'data/search.index.js');
- if ($this->book->parametres->highlightResults) {
- $this->vdir->copy($cacheDir . '/search.highlight.js', 'data/search.highlight.js');
- }
- if ($this->book->parametres->searchWordSelectionAlgorithm == 'expression') {
- $this->vdir->copy($cacheDir . '/search.texts.js', 'data/search.texts.js');
- }
- }
-
- public function supportSVG()
- {
- if (!$this->phonegap) {
- return false;
- } else if ($this->phonegap == 'ios') {
- return true;
- } else {
- return false;
- }
- }
-
- protected function writeConfig()
- {
- $c = json_encode($this->config);
- return 'var SETTINGS=' . $c . ';' . "\n";
- }
-
- protected function writeCountries()
- {
- $c = Zend_Locale::getTranslationList('Territory', $this->book->lang, 2);
- asort($c);
- $this->config->countries = $c;
- }
-
- protected function writeManifest()
- {
- $res = array();
- }
-
- protected function writeImages()
- {
- global $core;
- $daoDoc = new wsDAODocument($core->con);
-
- switch ($this->book->parametres->mobileVersion) {
- case 'html5-desktop':
- $this->backgroundsPrefix = array(true, false);
- $this->svg = true;
- break;
- case 'html5-images':
- $this->backgroundsPrefix = array(true);
- $this->svg = false;
- break;
- default:
- $this->backgroundsPrefix = array(false);
- $this->svg = true;
- break;
- }
-
- $rasterizePages = $this->config->rasterizePages;
- $this->config->pagesDimensions = [];
-
- if ($this->book->parametres->mobileNavigationType === 'mobilefirst') {
- $imdir = 'mf';
- } else {
- $imdir = 'html';
- }
-
- $thumbs = array();
- foreach ($this->pages as $page => $infos) {
- $thisrasterize = in_array($page, $rasterizePages);
- $thisimagesvg = !$thisrasterize && $this->svg;
- $thisbackgroundPrefix = $thisrasterize ? [true] : $this->backgroundsPrefix;
-
- foreach ($this->getResolutions() as $r) {
- foreach ($thisbackgroundPrefix as $backgroundsPrefix) {
- $source = $this->book->getFile($page, $this->imageFormat, $r, $backgroundsPrefix, true, $imdir);
- if ($r == 150 && file_exists($source)) {
- $firstDoc = $daoDoc->selectById($infos['document_id']);
- $d = $firstDoc->generalInfos['page'][$infos['document_page']]['size'];
- $this->config->pagesDimensions[$page] = array($this->cssWidth, $d[1] * ($this->cssWidth / $d[0]));
- }
- $this->vdir->copy($source, 'data/background/' . $r . '/' . ($backgroundsPrefix ? 't' : 'p') . $page . '.' . $this->imageFormat);
- }
- }
-
- if ($thisimagesvg) {
- $this->vdir->copy(
- $this->book->getFile($page, 'svg', 150, true,
- in_array($page, $this->config->vectorPages), 'html')
- , 'data/contents/p' . $page . '.svg');
- }
-
- $this->vdir->copy($this->book->getThumbFile($page, $this->imageFormat), 'data/thumbnails/p' . $page . '.' . $this->imageFormat);
- $this->log('Made image page ' . $page);
- }
-
- $this->_makeCover($this->book->getFile(1, 'jpg', 150, true, true));
-
- $this->log('Made images');
- }
-
- protected function _makeCover($orig)
- {
- $size = CubeIT_Image::getimagesize($orig);
- $w = $size[0];
- $h = $size[1];
-
- $tmp = cubeFiles::tempnam() . '.png';
-
- $c = new CubeIT_CommandLine('convert');
- $c->setArg(null, ROOT . '/images/ws/shade-cover-app.png');
- $c->setManualArg('-resize ' . round($w / 3) . 'x' . $h);
- $c->setArg(null, $tmp);
- $c->execute();
-
- $res = cubeFiles::tempnam() . '.jpg';
-
- $convert = new CubeIT_CommandLine('composite');
- $cmd = '-compose Multiply ';
- $cmd .= $tmp . ' ' . $orig . ' ';
- $cmd .= $res;
- $convert->setManualArg($cmd);
- $convert->execute();
-
- $this->vdir->copy($res, 'cover.jpg', true);
-
- unlink($tmp);
- }
-
- protected function _lessBoolean($val)
- {
- return $val ? 'true' : 'false';
- }
-
- protected function writeCSS($links)
- {
- $res = array();
-
- $this->addFontKit('OpenSans');
-
- $lessContents = '';
-
- $this->lessVariables['css-scale'] = $this->cssScale;
- $this->lessVariables['slider-display'] = $this->_lessBoolean($this->theme->parametres->pagesBar);
- $this->lessVariables['slider-thumb-background'] = wsHTML5::colorToCSS($this->theme->parametres->pageBarThumbBack);
- $this->lessVariables['pages-background'] = $this->book->parametres->forceWhiteBackground ? '#ffffff' : 'transparent';
-
- // General theme
- $cssWidth = $this->cssWidth;
- $cssHeight = $this->cssHeight;
- $cssScale = $this->cssScale;
- $w2 = ($cssWidth * 2) . 'px';
- $h = $cssHeight . 'px';
-
- $wm = ($this->width * $this->multiply) . 'px';
- $hm = ($this->height * $this->multiply) . 'px';
- $w = $cssWidth . 'px';
- $offsetLeft = round(($this->optimalWidth - $cssWidth) / 2, 3);
- $offsetLeft2 = $offsetLeft * 2;
- $offsetTop = round(($this->optimalHeight - $cssHeight) / 2, 3);
- $navTop = ($cssHeight - 40 - 100) / 2;
- $leftOfRightPage = (floor($cssWidth) - 1) . 'px';
-
- $this->lessVariables['z'] = $this->z;
- $this->lessVariables['book-page-width'] = $w;
-
- if ($this->book->parametres->correctCenter && !$this->isMobileFirst()) {
- $this->lessVariables['book-page-correct-width'] = ceil($w) + 1;
- $this->lessVariables['book-page-correct-height'] = ceil($h) + 1;
- } else {
- $this->lessVariables['book-page-correct-width'] = $w;
- $this->lessVariables['book-page-correct-height'] = $h;
- }
- $this->lessVariables['book-page-height'] = $h;
- $this->lessVariables['book-page-ratio'] = floatval($w) / floatval($h);
-
- $this->lessVariables['page-shade-opacity'] = min(1, $this->theme->parametres->shadeAlpha / 50);
- $this->lessVariables['shadow-opacity'] = wsHTML5::colorToArray($this->theme->parametres->bookShadeColor)['opacity'] * 1.2;
- $this->lessVariables['edges-display'] = $this->_lessBoolean($this->theme->parametres->usePageEdges);
- $this->lessVariables['edge-left-offset'] = $this->theme->parametres->pageEdgeLeftOffset;
- $this->lessVariables['edge-right-offset'] = $this->theme->parametres->pageEdgeRightOffset;
- $this->lessVariables['edges-opacity'] = $this->theme->parametres->pageEdgeOpacity / 100;
-
- $this->lessVariables['page-number-color'] = wsHTML5::colorToCSS($this->theme->parametres->colorPageNumber);
- $this->lessVariables['display-page-number'] = $this->_lessBoolean($this->theme->parametres->displayPageNumber);
- $this->lessVariables['page-transition-duration'] = $this->book->parametres->mobileTransitionDuration . 's';
-
- $corrText = $this->isMobileFirst() ? 0 : 4;
-
- if ($this->cssSVGScale != 1) {
- $texts = '.texts{' . wsHTML5::writeCSSUA('transform-origin', 'top left') . ';';
- $texts .= wsHTML5::writeCSSUA('transform', 'scale(' . round((1 / $this->multiply) * $cssScale * $this->cssSVGScale, 3) . ')') . ';';
- $texts .= 'width:' . ($wm / $this->cssSVGScale) . 'px; max-width:' . ($wm / $this->cssSVGScale) . 'px;';
- $texts .= 'height:' . ($hm / $this->cssSVGScale) . 'px; max-height:' . ($hm / $this->cssSVGScale) . 'px;';
- $texts .= '}';
- } else {
- $texts = '.texts{width:' . floor(floatval($w) + $corrText) . 'px;height:' . floor(floatval($h) + $corrText) . 'px;}';
- }
-
- $res[] = $texts;
-
- // Theme
- $shade = '.page .shade{';
- $shade .= 'opacity:' . min(($this->theme->parametres->shadeAlpha * 2) / 100, 1) . ';';
- $shade .= '}';
- $res[] = $shade;
-
- // SVG
- $res[] = 'svg .fill-c-menu-back{fill:' . wsHTML5::colorToCSS($this->theme->parametres->couleurB) . ';}';
- $res[] = 'svg .fill-c-menu-text{fill:' . wsHTML5::colorToCSS($this->theme->parametres->subTextColor) . ';}';
-
- // Background
- $res[] = $this->_cssBackground();
-
- // Archives
- // Header
- $header = 'header{';
- $header .= 'height:' . $this->theme->parametres->menuHeight . 'px;';
- if ($mi = $this->checkThemeImage($this->theme->parametres->menuImage)) {
- $this->vdir->copy($mi, 'data/images/' . $this->theme->parametres->menuImage);
- $header .= 'background-image:url(../images/' . $this->theme->parametres->menuImage . ');';
- $header .= 'background-repeat:no-repeat;';
- $header .= 'background-size:100% ' . $this->theme->parametres->menuHeight . 'px;';
- } else {
- // Force redo
- $header .= 'background-color:' . wsHTML5::colorToCSS($this->theme->parametres->menuColor) . ';';
- }
- $header .= '}';
- $res[] = $header;
-
- // Logo
- $logo = '#logo{';
- if ($l = $this->checkThemeImage($this->theme->parametres->logo)) {
- $this->vdir->copy($l, 'data/images/' . $this->theme->parametres->logo);
- $dim = CubeIT_Image::getimagesize($l);
- $logo .= 'background-image:url(../images/' . $this->theme->parametres->logo . ');width:' . $dim[0] . 'px;height:' . $dim[1] . 'px;';
- }
- $logo .= '}';
- $res[] = $logo;
-
- // Credits
- $res[] = 'footer,footer a{color:' . wsHTML5::colorToCSS($this->theme->parametres->creditsColor) . ';}';
-
- // Arrows
- $this->lessVariables['arrows-background'] = wsHTML5::colorToCSS($this->theme->parametres->couleurA);
- $this->lessVariables['arrows-color'] = wsHTML5::colorToCSS($this->theme->parametres->arrowsColor);
-
- // Loader
- $this->lessVariables['loader-background-color'] = wsHTML5::colorToCSS($this->theme->parametres->couleurL);
- $this->lessVariables['loader-foreground-color'] = wsHTML5::colorToCSS($this->theme->parametres->loadingSecColor);
-
- // Audio description buttons
- $this->lessVariables['audiodescription-background'] = wsHTML5::colorToCSS($this->theme->parametres->couleurA);
- $this->lessVariables['audiodescription-color'] = wsHTML5::colorToCSS($this->theme->parametres->couleurA);
-
- // Links Styles
- $this->lessVariables['links-color'] = wsHTML5::colorToCSS($this->theme->parametres->linksColor);
- $this->lessVariables['inlineslideshow-transition-time'] = (floatval($this->book->parametres->inlineSlideshowTransitionDuration) * 1000) . 'ms';
- $this->lessVariables['slideshow-caption-size'] = $this->book->parametres->slideshowCaptionSize ?: '16px';
-
- $res = array_merge($res, $links);
-
- // Bookmarks
- if (!isset($this->book->parametres->bookmarkCornerSize)) {
- $this->book->parametres->bookmarkCornerSize = 10;
- }
-
- $this->lessVariables['bookmark-star-disabled-color'] = wsHTML5::colorToCSS($this->theme->parametres->bookmarkStarDisabledColor);
- $this->lessVariables['bookmark-star-enabled-color'] = wsHTML5::colorToCSS($this->theme->parametres->bookmarkStarEnabledColor);
- $this->lessVariables['bookmark-color'] = wsHTML5::colorToCSS($this->theme->parametres->bookmarkBackgroundColor);
- $this->lessVariables['bookmark-corner-size'] = round($this->width * $this->book->parametres->bookmarkCornerSize * 0.0075 * $this->z) . 'px';
- $this->lessVariables['bookmark-corner-offset'] = $this->book->parametres->bookmarkOffset . 'px';
-
- // Menus
- $menuColor = new CubeIT_Graphics_Color($this->theme->parametres->couleurB);
- $menuColor->setAlpha(1);
- $menuTextColor = wsHTML5::colorToCSS($this->theme->parametres->subTextColor);
- $menuBreakpoint = empty($this->book->parametres->menuBreakpoint) ? '1023px' : $this->book->parametres->menuBreakpoint;
-
- $this->lessVariables['menu-breakpoint'] = $menuBreakpoint;
- $this->lessVariables['menu-background'] = $menuColor->toCSS();
- if ($this->theme->parametres->subSecondaryColor) {
- $this->lessVariables['menu-button-background'] = wsHTML5::colorToCSS($this->theme->parametres->subSecondaryColor);
- } else {
- $this->lessVariables['menu-background-green'] = 'max(45, min(255-45, green(@menu-background)))';
- $this->lessVariables['menu-background-red'] = 'max(45, min(255-45, red(@menu-background)))';
- $this->lessVariables['menu-background-blue'] = 'max(45, min(255-45, blue(@menu-background)))';
- $this->lessVariables['menu-button-background'] = 'overlay(rgb(@menu-background-red, @menu-background-green, @menu-background-blue), #c0c0c0)';
- }
-
- $this->lessVariables['menu-text'] = $menuTextColor;
- $this->lessVariables['menu-field-background'] = wsHTML5::colorToCSS($this->theme->parametres->subFieldColor);
- $this->lessVariables['menu-field-text'] = wsHTML5::colorToCSS($this->theme->parametres->subTextFieldColor);
- $this->lessVariables['menu-select-background'] = wsHTML5::colorToCSS($this->theme->parametres->subSelectColor);
- $this->lessVariables['menu-select-text'] = wsHTML5::colorToCSS($this->theme->parametres->subTextSelectColor);
- $this->lessVariables['icon-color'] = wsHTML5::colorToCSS($this->theme->parametres->couleurI);
- $this->lessVariables['menu-overlay'] = wsHTML5::colorToCSS($this->theme->parametres->popupVideoOverlay);
-
- // Chapters
- $this->lessVariables['menu-chapters-columns-count'] = max(1, min(6, $this->book->parametres->chaptersColumns));
- $this->lessVariables['menu-chapters-columns-width'] = $this->book->parametres->chaptersColMaxWidth;
- $this->lessVariables['menu-chapters-font-size'] = $this->book->parametres->chaptersFontSize;
-
- foreach ($this->book->chapters as $chapter) {
- if (substr($chapter->page, 0, 1) != '#') {
- continue;
- }
- if ($chapter->color == '') {
- continue;
- }
- $color = trim($chapter->color, '#');
- $lessContents .= '.mview.c_' . $color . '{.menu-color(#' . $color . ');}';
- }
-
- // Archives
- if ($this->book->parametres->externalArchivesBack) {
- $this->vdir->copy($this->wdir . '/' . $this->book->parametres->externalArchivesBack, 'data/images/' . $this->book->parametres->externalArchivesBack);
- $res[] = '.mview.archives{background-image:url("../images/' . $this->book->parametres->externalArchivesBack . '");}';
- }
-
- # Index
- $thumbw = $this->book->parametres->mobileNavigationType === 'portrait' ? 200 : 100;
- $this->lessVariables['thumb-width'] = $thumbw . 'px';
- $ratio = $this->width / $this->height;
- $thumbh = round($thumbw / $ratio);
- $this->config->thumbWidth = $thumbw;
- $this->config->thumbHeight = $thumbh;
-
- $this->lessVariables['thumb-height'] = $thumbh . 'px';
-
- #tooltip
- $this->lessVariables['tooltip-background'] = wsHTML5::colorToCSS($this->theme->parametres->tooltipBackColor);
- $this->lessVariables['tooltip-color'] = wsHTML5::colorToCSS($this->theme->parametres->tooltipTextColor);
- $this->lessVariables['tooltip-font-size'] = 14 * ($this->theme->parametres->tooltipTextSize / 100);
-
- #Videos
- if ($this->book->parametres->bigPlayImage) {
- $this->lessVariables['video-bigplay-image'] = '~"../data/links/' . $this->book->parametres->bigPlayImage . '"';
- $this->vdir->copy($this->wdir . '/' . $this->book->parametres->bigPlayImage, 'data/links/' . $this->book->parametres->bigPlayImage);
- } else {
- $this->lessVariables['video-bigplay-image'] = '~"data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHZpZXdCb3g9IjAgMCAxMTMuNCAxMTMuNCI+PHN0eWxlPi5zdDB7b3BhY2l0eTowLjg7fSAuc3Qxe2ZpbGw6I0ZGRkZGRjt9PC9zdHlsZT48cGF0aCBjbGFzcz0ic3QwIiBkPSJNMTEwLjUgMTEzLjRIMi45Yy0xLjYgMC0yLjktMS4zLTIuOS0yLjlWMi45QzAgMS4zIDEuMyAwIDIuOSAwaDEwNy42YzEuNiAwIDIuOSAxLjMgMi45IDIuOXYxMDcuNmMwIDEuNi0xLjMgMi45LTIuOSAyLjl6Ii8+PHBhdGggY2xhc3M9InN0MSIgZD0iTTQ1LjggMzcuOGwzMS41IDE3LjljLjguNS44IDEuNiAwIDIuMUw0NS44IDc1LjZjLS44LjUtMS44LS4xLTEuOC0xVjM4LjhjMC0uOSAxLTEuNSAxLjgtMXoiLz48L3N2Zz4="';
- }
-
- #fonts
- foreach ($this->cssfont as $hash => $item) {
- $res[] = '@font-face{font-family: "' . $hash . '";src:url("../../data/fonts/' . $hash . '.woff") format("woff");}';
- }
-
- if ($this->book->parametres->textPopupStylesheet) {
- $res[] = file_get_contents($this->wdir . '/' . $this->book->parametres->textPopupStylesheet);
- }
-
- $this->_writeLess($this->lessVariables, $lessContents);
- $this->stylesheets[] = 'data/style/style.css';
- $this->vdir->file_put_contents('data/style/style.css', implode("\n", $res));
- $this->log('Write CSS');
- }
-
- protected function checkThemeImage($path)
- {
- $path = trim($path);
- $path = trim($path, '/');
- if (!$path) {
- return false;
- }
- $p = $this->themeRoot . '/' . $path;
- if (file_exists($p)) {
- return $p;
- }
- $po = str_replace('.svg', '.o.svg', $p);
- if (file_exists($po)) {
- copy($po, $p);
- return $p;
- }
- return false;
- }
-
- protected function _writeLess($variables, $lessContents = '')
- {
- if ($this->widget) {
- $this->lessFiles[] = 'widget';
- }
- foreach ($this->specialCSS as $s) {
- $this->lessFiles[] = 'special/' . $s;
- }
-
- $tmp = CubeIT_Files::tmpdir();
-
- $from = $this->assets . '/style/*';
- `cp -r $from $tmp`;
-
- $bookVariables = array();
- foreach ($variables as $k => $v) {
- $bookVariables[] = '@' . trim($k) . ':' . $v . ';';
- }
- file_put_contents($tmp . '/book-variables.less', implode("\n", $bookVariables));
- file_put_contents($tmp . '/additional.less', $lessContents);
-
- foreach ($this->lessFiles as $f) {
- $source_less = $this->assets . '/style/' . $f . '.less';
- $destination_less = $tmp . '/' . $f . '.less';
- $destination_css = $tmp . '/' . $f . '.css';
-
- if (!file_exists($source_less)) {
- die($source_less);
- continue;
- }
-
- $dir = dirname($destination_css);
-
- if (file_exists($dir) && !is_dir($dir)) {
- unlink($dir);
- }
- // LESS file might be in a subfolder, so create if it doesn't exist
- if (!file_exists($dir)) {
- mkdir($dir, 0777, true);
- }
-
- // Less files must be copied to temporary directory so they'll
- // have access to the variables generated in book-variables.less
- copy($source_less, $destination_less);
- $less = new CubeIT_CommandLine('/usr/local/bin/lessc');
- $less->setArg(null, $destination_less);
- $less->setArg(null, $destination_css);
- $less->execute();
- $less->debug();
- if (!file_exists($destination_css)) {
- die($less->output);
- continue;
- }
- $this->vdir->copy($destination_css, 'style/' . $f . '.css');
- if ($f != 'widget') {
- $this->stylesheets[] = 'style/' . $f . '.css';
- }
- }
- }
-
- protected function _cssBackground()
- {
- $body = '';
-
- if ($this->theme->parametres->displayBackgroundDuringLoading) {
- $body .= '#background,#splash{background-color:#' . $this->theme->parametres->backgroundColor . ' !important;}';
- } else {
- $body .= '#background{transition:500ms opacity;visibility:hidden;opacity:0;background-color:#' . $this->theme->parametres->backgroundColor . ' !important;}';
- $body .= '#splash{background-color:' . $this->theme->parametres->loadingBackColor . ' !important;}';
- }
-
- $body .= '#background,#splash{';
-
- switch ($this->theme->parametres->repeat) {
- case wsTheme::REPEAT:
- $body .= 'background-repeat:repeat;';
- break;
- case wsTheme::NONE:
- $body .= 'background-repeat:no-repeat;';
- break;
- case wsTheme::RATIO:
- $body .= 'background-repeat:no-repeat;';
- $body .= 'background-size:cover;';
- break;
- case wsTheme::STRETCH:
- $body .= 'background-repeat:no-repeat;';
- $body .= 'background-size:100% 100%;';
- break;
- }
- if ($bi = $this->checkThemeImage($this->theme->parametres->backgroundImage)) {
-
- $dbi = CubeIT_Image::getimagesize($bi);
- $this->config->backgroundImageDimensions = array('width' => $dbi[0], 'height' => $dbi[1]);
-
-
- $this->vdir->copy($bi, 'data/images/' . $this->theme->parametres->backgroundImage);
- $body .= 'background-image:url(../images/' . $this->theme->parametres->backgroundImage . ');';
- $body .= 'background-position:';
-
- switch ($this->theme->parametres->backgroundVAlign) {
- case wsTheme::TOP:
- $body .= 'top';
- break;
- case wsTheme::MIDDLE:
- $body .= 'center';
- break;
- case wsTheme::BOTTOM:
- $body .= 'bottom';
- break;
- }
- $body .= ' ';
- switch ($this->theme->parametres->backgroundHAlign) {
- case wsTheme::LEFT:
- $body .= 'left';
- break;
- case wsTheme::CENTER:
- $body .= 'center';
- break;
- case wsTheme::RIGHT:
- $body .= 'right';
- break;
- }
- $body .= ';';
- }
-
- $body .= '}';
-
- return $body;
- }
-
- public static function writeCSSUA($property, $value)
- {
- $res = array();
- foreach (self::$uaPrefixes as $prefix) {
- $res[] = $prefix . $property . ':' . $value;
- }
- return implode(';', $res);
- }
-
- protected function base62($val)
- {
- $chars = '0123456789abcdefghijklmnopqrstuvwxyz';
- $base = strlen($chars);
- $str = '';
- do {
- $i = $val % $base;
- $str = $chars[$i] . $str;
- $val = ($val - $i) / $base;
- } while ($val > 0);
- return $str;
- }
-
- public function copyLinkDir($source, $dest)
- {
- $this->vdir->copyDirectory($source, $dest);
- }
-
- public function simpleCopyLinkFile($source, $dest, $addVdir = true)
- {
- if ($addVdir) {
- $dest = $dest;
- }
-
- $this->vdir->copy($source, $dest);
- }
-
- public function addVideoJs()
- {
- $locale = $this->book->lang;
- $map = ['pt' => 'pt-PT', 'pt-br' => 'pt-BR', 'zh' => 'zh-CN', 'es-pr' => 'es'];
- if (isset($map[$locale])) {
- $locale = $map[$locale];
- }
-
- $this->addJsLib('videojs', ['js/libs/videojs/video.withscalefix.js', 'js/libs/videojs/lang/' . $locale . '.js']);
- $this->addLess('videojs/videojs');
- }
-
- public function addLottie($animationData, $params, $hash)
- {
- if (isset($this->_lottieIDByHash[$hash])) {
- return $this->_lottieIDByHash[$hash];
- }
-
- $this->addJsLib('lottie', 'js/libs/lottie.min.js');
-
- if (!isset($this->config->lottieAnimations)) {
- $this->config->lottieAnimations = [];
- }
-
- $id = count($this->config->lottieAnimations);
- $this->config->lottieAnimations[] = [$params, $animationData];
- $this->_lottieIDByHash[$hash] = $id;
- return $id;
- }
-
- public function addFont($fontFile)
- {
- $f = $this->wdir . '/' . $fontFile;
- $e = explode('.', $f);
- $ext = array_pop($f);
- $hash = 'fb_' . substr(md5($fontFile), 0, 10);
- if (!isset($this->cssfont[$hash])) {
- $final = $hash . '.woff';
- $dest = $this->wdir . '/' . $final;
- if (!file_exists($dest) || filemtime($dest) < filemtime($f)) {
- $fontforge = new cubeCommandLine('convertrn.pe');
- $fontforge->setPath(CONVERTER_PATH);
- $fontforge->setArg(null, $f);
- $fontforge->setArg(null, $dest);
- $fontforge->execute();
- }
- $this->vdir->copy($dest, 'data/fonts/' . $hash . '.woff');
- $cmd = "font-line report $f";
- $fontline = `$cmd`;
- $report = explode("\n", $fontline);
-
- foreach ($report as $item) {
- $item = trim($item);
- list($k, $v) = explode(':', $item, 2);
- if ($k == '[head] Units per Em') {
- $fontHeight = trim($v);
- }
- if ($k == '[OS/2] CapHeight') {
- $fontCapHeight = trim($v);
- }
- if ($k == '[OS/2] TypoAscender') {
- $ascender = abs(trim($v));
- }
- if ($k == '[OS/2] TypoDescender') {
- $descender = abs(trim($v));
- }
- }
- $capHeight = 1;
- if (isset($fontCapHeight) && isset($fontHeight)) {
- $capHeight = $fontCapHeight / $fontHeight;
- }
- $font = ['family' => $hash, 'capHeight' => $capHeight, 'ascender' => $ascender / $fontHeight, 'descender' => $descender / $fontHeight];
- $this->cssfont[$hash] = $font;
- }
- return $this->cssfont[$hash];
- }
-
- public function addJsLib($name, $files)
- {
- if (!isset($this->jsLibs[$name])) {
- $this->jsLibs[$name] = [];
- }
- if (!is_array($files)) {
- $files = [$files];
- }
- $diff = array_diff($files, $this->jsLibs[$name]);
- if (count($diff)) {
- $this->jsLibs[$name] = array_merge($this->jsLibs[$name], $diff);
- }
- }
-
- public function copyLinkFile($source, $dest, $video = false)
- {
- if ($video && $this->book->parametres->mobileVideosPath != '') {
-
- }
- $origDir = $this->wdir;
- $types = $this->getVideosFormats();
- if ($video) {
- wsTools::encodeWebVideos($origDir . $source, null, true);
- $e = explode('.', $source);
- array_pop($e);
- $base = implode('.', $e);
- $source = array();
- foreach ($types as $type) {
- $source[] = $base . '.' . $type;
- }
- }
-
- if (!is_array($source)) {
- $source = array($source);
- }
-
- foreach ($source as $so) {
- $s = $origDir . $so;
- if (file_exists($s)) {
- $d = $dest . '/' . $so;
- $this->simpleCopyLinkFile($s, $d, false);
- }
- }
- }
-
- public function __destruct()
- {
-
- }
-
- public function unzipFile($file, $moveAssets = false, $baseDir = null)
- {
- $fdir = is_null($baseDir) ? 'data/links/' . str_replace('.', '_', $file) : $baseDir;
-
- $tmp = CubeIT_Files::tmpdir();
- $dir = $tmp . '/' . $fdir;
- if (file_exists($dir) && is_file($dir)) {
- unlink($dir);
- }
- if (!file_exists($dir)) {
- mkdir($dir, 0777, true);
- }
- $unzip = new cubeCommandLine('unzip');
- $unzip->setArg(null, $this->wdir . '/' . $file);
- $unzip->setArg('d', $dir);
- $unzip->execute();
-
- if ($moveAssets) {
- `mv $dir/Assets/* $dir`;
- rmdir($dir . '/Assets');
- }
-
- return array('dir' => $dir, 'fdir' => $fdir);
- }
-
- public function getConfigZIP($d)
- {
- $res = array('type' => 'zip', 'width' => 0, 'height' => 0);
- if (file_exists($d . '/index.html')) {
- $doc = new DOMDocument();
- @$doc->loadHTMLFile($d . '/index.html');
- $xpath = new DOMXPath($doc);
- $c = $xpath->query("//canvas");
- foreach ($c as $canvas) {
- /* @var $canvas DOMElement */
- $res['width'] = intval((string)$canvas->getAttribute('width'));
- $res['height'] = intval((string)$canvas->getAttribute('height'));
- }
-
- $m = $xpath->query('//meta[@name="width"]');
- foreach ($m as $meta) {
- $res['width'] = intval((string)$meta->getAttribute('content'));
- }
-
- $m = $xpath->query('//meta[@name="height"]');
- foreach ($m as $meta) {
- $res['height'] = intval((string)$meta->getAttribute('content'));
- }
-
- $r = array('html' => 'index.html', 'inject' => array(), 'injectcss' => array(), 'injectjs' => array());
- } else {
- $r = array('html' => false, 'inject' => array(file_get_contents($d . '/init.js')), 'injectcss' => array('multimedia.css'), 'injectjs' => array('multimedia.js'));
- }
- $res = array_merge($res, $r);
- return $res;
- }
-
- public function addFontKit($font)
- {
- if ($font === 'sans-serif') {
- return;
- }
-
- $path = 'style/fonts/' . $font;
- $css = $path . '/font.css';
- if (in_array($css, $this->stylesheets)) {
- return;
- }
- $this->stylesheets[] = $css;
- $this->vdir->copyDirectory($this->assets . '/' . $path, $path);
- return $path . '/font.css';
- }
-
-
- public function SimpleXMLElement_innerXML($xml)
- {
- $innerXML = '';
- foreach (dom_import_simplexml($xml)->childNodes as $child) {
- $innerXML .= $child->ownerDocument->saveXML($child);
- }
- return $innerXML;
- }
-
- public function writeArticles()
- {
- $mapFonts = ['OpenSans' => 'Open Sans'];
-
- $this->lessVariables['articles-title-color'] = '#000000';
- $this->lessVariables['articles-font'] = 'OpenSans';
-
- $list = [];
-
- $f = $this->book->parametres->articlesFile;
- if ($f === '') {
- $this->config->articlesList = $list;
- return;
- }
- $f = $this->wdir . '/' . $f;
- if (!file_exists($f)) {
- $this->config->articlesList = $list;
- return;
- }
-
- $this->addLess('articles');
- if ($this->book->parametres->articlesStyle !== 'default') {
- $this->lessVariables['articles-styles'] = $this->book->parametres->articlesStyle;
- }
-
- $this->lessVariables['articles-title-color'] = '#565657';
- $this->lessVariables['articles-font'] = $mapFonts[$this->book->parametres->articlesFont] ?? $this->book->parametres->articlesFont;
- $fontPath = $this->addFontKit($this->book->parametres->articlesFont);
-
- $svg = '<svg xmlns="http://www.w3.org/2000/svg" style="display: none;"><symbol id="nav-print" viewBox="0 0 512 512">
- <path d="m424 186l-39 0 0-114c0-9-6-15-14-15l-230 0c-8 0-14 6-14 15l0 114-39 0c-22 0-41 19-41 41l0 121c0 23 19 41 41 41l39 0 0 49c0 8 6 15 14 15l230 0c8 0 14-7 14-15l0-49 39 0c22 0 41-18 41-41l0-121c0-22-19-41-41-41z m-268-100l200 0 0 100-200 0z m200 340l-200 0 0-88 200 0z m80-76c0 6-6 12-12 12l-39 0 0-38c0-9-6-15-14-15l-230 0c-8 0-14 6-14 15l0 38-39 0c-6 0-12-6-12-12l0-121c0-6 6-12 12-12l336 0c6 0 12 6 12 12z m-278-96l-33 0c-8 0-14 6-14 14 0 8 6 15 14 15l35 0c8 0 14-7 14-15 0-8-8-14-16-14z m32 139l132 0c8 0 14-6 14-14 0-8-6-14-14-14l-132 0c-8 0-14 6-14 14 0 8 6 14 14 14z"/>
- </symbol></svg>';
-
-
- $x = simplexml_load_string(file_get_contents($f));
- $prevurl = '';
- foreach ($x->xpath('/articles/article') as $k => $a) {
- $dir = isset($a['dir']) ? (string)$a['dir'] : null;
- $url = (string)$a['url'];
- $id = (string)$a['id'];
- $color = (string)$a['color'];
- if (!$color) {
- $color = '#000';
- }
-
- $specificStyles = '## h3, ## figure figcaption{background-color:' . $color . '}';
- $specificStyles .= '## .chapo, ## blockquote, ## a{color:' . $color . ';}';
-
- $inner = '<article data-id="$id" class="menu-article" id="article_$id"';
- if (null !== $dir) {
- $inner .= ' dir="' . $dir . '"';
- }
- $inner .= '>';
- $inner .= '<style type="text/css">' . str_replace('##', '#article_$id', $specificStyles) . '</style>';
- $inner .= '<div class="actions">';
- if ($this->book->parametres->articlesShare && $this->book->parametres->share) {
- $inner .= '<a data-id="$id" data-url="$url" href="#" class="articlesShare"><svg viewBox="0 0 512 512" class="nav-share nav-icon svg-icon"><use xlink:href="#nav-share"></use></svg></a>';
- }
- $inner .= '<a href="#" class="articlesPrint"><svg viewBox="0 0 512 512" class="nav-print nav-icon svg-icon"><use xlink:href="#nav-print"></use></svg></a>';
- $inner .= '</div>';
-
- $inner .= '<div class="articleBody">';
-
- $title = '';
- $lead = '';
- $image = '';
-
- $first = true;
-
- foreach ($a->children() as $child) {
- if ($first) {
- $first = false;
- if ($child->getName() !== 'category') {
- $inner .= '<h3> </h3>';
- }
- }
- $inner .= $this->_articleToHTML($child, $title, $lead, $image, $dir);
- }
- $inner .= '</div></article>';
-
- if (!$title) {
- $title = 'Article sans titre ' . $k;
- }
-
- if (!$id) {
- $id = CubeIT_Text::str2URL($title);
- }
-
- if (!$url) {
- $url = $id . '.html';
- }
-
- $inner = str_replace(array('$id', '$url'), array($id, $url), $inner);
-
- $article = ['id' => $id,
- 'url' => $url,
- 'color' => $color,
- 'contents' => '',
- 'prev' => $prevurl,
- 'next' => ''];
-
- if ($prevurl !== '') {
- $list[count($list) - 1]['next'] = $url;
- } else {
- $firsturl = $url;
- }
-
- $prevurl = $url;
-
- $article['contents'] = $inner;
- $content = '<html><head>';
- $content .= '<link rel="stylesheet" type="text/css" href="' . $fontPath . '">';
- $content .= '<link rel="stylesheet" type="text/css" href="style/articles.css">';
- $content .= '<style type="text/css">';
- $content .= str_replace('## ', '', $specificStyles);
- $content .= '</style>';
- $content .= '<style type="text/css" media="screen">*{visibility:hidden}</style>';
- $content .= '</head><body>';
- $content .= $svg;
- $content .= $inner;
- $content .= '</body></html>';
- $article['print'] = $content;
- $list[] = $article;
-
- $this->addSEOArticle('#/article/' . $article['url'], $title, $lead, $image, $article['id'], $article['url'], $inner);
- }
- $list[0]['prev'] = $prevurl;
- $list[count($list) - 1]['next'] = $firsturl;
-
- $idlist = [];
- foreach ($list as $item) {
- $idlist[$item['id']] = $item;
- }
- $this->config->articlesList = $idlist;
- }
-
- /**
- * @param $child SimpleXMLElement
- * @param $title
- * @param $lead
- * @param $image
- * @return string|void
- * @throws Zend_Filter_Exception
- */
- protected function _articleToHTML($child, &$title, &$lead, &$image, $dir = null)
- {
- $markupMap = ['category' => 'h3',
- 'subtitle' => 'h2',
- 'legend' => 'figcaption',
- 'title' => 'h1',
- 'lead' => 'div.chapo',
- 'paragraph' => 'p',
- 'note' => 'div.note',
- 'quote' => 'blockquote',
- 'signature' => 'div.author',
- 'intertitle' => 'h2.inter',
- 'bigfont' => 'h2.bigfont',
- 'separator' => 'hr',
- 'link' => 'a'];
-
- $attrsmap = ['a' => ['link' => 'href']];
-
- $dirattr = '';
- if (isset($child['dir'])) {
- $d = (string)$child['dir'];
- if ($d !== $dir) {
- $dirattr = ' dir="' . $d . '"';
- $dir = $d;
- }
- }
-
- $res = '';
- $tag = $child->getName();
- if ($tag === 'encadre') {
- $res .= '<aside' . $dirattr . '>';
- foreach ($child->children() as $sub) {
- $res .= $this->_articleToHTML($sub, $a1, $a2, $a3, $dir);
- }
- $res .= '</aside>';
- } else if ($tag === 'youtube') {
- $filter = new CubeIT_Filter_WebVideo();
- $e = explode(':', $filter->filter((string)$child['link']));
- $res .= '<div class="youtube"><iframe width="800" height="450" src="https://www.youtube.com/embed/' . $e[1] . '" frameborder="0" allow="accelerometer; autoplay; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe></div>';
- } else if ($tag === 'image') {
- $srcattrs = ['href', 'src', 'file'];
- $file = '';
- foreach ($srcattrs as $srcattr) {
- if (isset($child[$srcattr])) {
- $file = (string)$child[$srcattr];
- break;
- }
- }
- if ($image === '') {
- $image = 'articles/' . $file;
- }
- $filepath = $this->wdir . '/articles/' . $file;
- $this->vdir->copy($filepath, 'data/articles/' . $file);
- $legend = (string)$child;
- $caption = $legend ? '<figcaption>' . $legend . '</figcaption>' : '';
- if (file_exists($filepath)) {
- $dim = getimagesize($filepath);
- } else {
- $dim = [0 => 1024, 1 => 10];
- }
- $res .= '<figure' . $dirattr . '><img src="data/articles/' . $file . '" alt="' . $legend . '" width="' . $dim[0] . '" height="' . $dim[1] . '">' . $caption . '</figure>';
- } else {
- $c = trim($this->SimpleXMLElement_innerXML($child));
- if (!$c) {
- return;
- }
- if ($title === '' && $tag === 'title') {
- $title = $c;
- }
- if ($lead === '' && $tag === 'lead') {
- $lead = $c;
- }
- $m = $markupMap[$tag] ?? $tag;
- $e = explode('.', $m);
- $markup = $e[0];
- $attrs = $dirattr;
- if (count($e) === 2) {
- $attrs .= ' class="' . $e[1] . '"';
- }
- if ($m === 'a') {
- $attrs .= ' target="_blank"';
- }
- foreach ($child->attributes() as $name => $v) {
- $n = $attrsmap[$m][$name] ?? $name;
- $attrs .= ' ' . $n . '="' . htmlspecialchars($v) . '"';
- }
- $res .= '<' . $markup . $attrs . '>' . $c . '</' . $markup . '>';
- }
- return $res;
- }
-
-}
-
-
-if (!function_exists('is_countable')) {
-
- function is_countable($c)
- {
- return is_array($c) || $c instanceof Countable;
- }
-
-}
-
-function shuffle_assoc(&$array)
-{
- $keys = array_keys($array);
-
- shuffle($keys);
-
- foreach ($keys as $key) {
- $new[$key] = $array[$key];
- }
-
- $array = $new;
-
- return true;
-}
+++ /dev/null
-<?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 $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 $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 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']) || (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 (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()
- {
- 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-blendmode="' . $this->blendmode . '" 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()
- {
- $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) * 1000) - min(999, round(($this->width * $this->height) / 300));
- return 'z-index:' . $zindex . ';';
- }
-
- public function getAddZIndex()
- {
- return 0;
- }
-
- 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;
- }
-
-}
-
-class normalLink extends wsHTML5Link
-{
- protected $role = 'link';
-
- public function getInnerContent()
- {
- return '';
- }
-
- public function getHTMLContent()
- {
- $class = $this->getClasses();
- if ($this->display_area) {
- $class[] = 'displayArea';
- }
- $attrs = '';
- if (count($class)) {
- $attrs .= ' class="' . implode(' ', $class) . '"';
- }
- $attrs .= $this->getTooltipAttribute();
- 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() . '>' . $this->getInnerContent() . '</a>';
- }
-
-
- public function getTrack()
- {
- return '';
- }
-
- public function getURL()
- {
- return '#';
- }
-
- public function getTarget()
- {
- return '_self';
- }
-
-
-}
-
-class anchorLink extends wsHTML5Link
-{
- protected $role = '';
-
- public function getHTMLContainer()
- {
- $this->to = self::normalizeAnchor($this->to);
- $this->compiler->addPageLabel($this->page, $this->to);
- return '<div aria-hidden="false" data-anchor="' . trim($this->to, '# ') . '" class="anchor ' . $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 getHTMLContent()
- {
- return '';
- }
-
- public static function normalizeAnchor($anchor)
- {
- return mb_strtolower(CubeIT_Text::str2URL($anchor));
- }
-}
-
-class triggerLink extends normalLink
-{
- public function getURL()
- {
- return '#';
- }
-
- public function getClasses()
- {
- $res = parent::getClasses();
- $res[] = 'triggerlink';
- return $res;
- }
-
- public function getAdditionnalContent()
- {
- $res = parent::getAdditionnalContent();
-
- $res .= ' data-trigger-event="' . $this->target . '" data-trigger-id="' . $this->to . '"';
- return $res;
- }
-}
-
-class showLinkLink extends normalLink
-{
- public function getURL()
- {
- return '#';
- }
-
- public function getClasses()
- {
- $res = parent::getClasses();
- $res[] = 'showlink';
- return $res;
- }
-
- 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();
- if ($this->backgroundColor) {
- $res .= 'data-tooltip-background="' . $this->backgroundColor . '" ';
- }
- if ($this->color) {
- $res .= 'data-tooltip-color="' . $this->color . '" ';
- }
- if ($this->tooltipMaxWidth) {
- $res .= ' data-tooltip-maxwidth="' . $this->tooltipMaxWidth . '" ';
- } else {
- $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 $defaultZIndex = 50;
-
- 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;
- }
-
- public function getAdditionnalContent()
- {
- return parent::getAdditionnalContent() . ' aria-hidden="true"';
- }
-
-}
-
-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 $clickToClose = 0;
-
- public function getURL()
- {
- $this->copyExternalFile($this->alternative);
- $read = ($this->read_mode) ? 'r_' : '';
- return '#/multimedia/' . $read . md5($this->alternative . '/' . $this->extra . '/' . $this->id);
- }
-
- public function getAdditionnalContent()
- {
- $res = parent::getAdditionnalContent();
- $dim = CubeIT_Image::getimagesize($this->wdir . '/' . $this->alternative);
-
- $markup = '<div class="multimediaContainer" data-click-to-close="' . $this->clickToClose . '"><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 $defaultZIndex = 30;
- public $animZindex = 0;
-
- public function getHTMLContainerClass()
- {
- return parent::getHTMLContainerClass() . ' contentLink';
- }
-
- public function getAdditionnalContent()
- {
- $res = parent::getAdditionnalContent();
- $animations = self::parseAnimations($this->image_rollover);
-
- foreach ($animations as $animation) {
- if (isset($animation['blendmode'])) {
- $this->blendmode = $animation['blendmode'];
- unset($animation['blendmode']);
- }
- if (isset($animation['zindex'])) {
- $this->animZindex = $animation['zindex'];
- }
- }
- $res .= ' data-animations="' . htmlspecialchars(json_encode($animations), ENT_QUOTES) . '" ';
- if ($this->_isHiddenFirst($animations)) {
- $res .= ' data-animation-hide ';
- }
- if ($this->_isFinallyHidden($animations)) {
- $res .= ' data-animation-hide-on-leave ';
- }
-
- return $res;
- }
-
- protected function _isFinallyHidden($animations)
- {
- $hiddenAnimations = ['fadeout', 'unmask'];
- foreach ($animations as $animation) {
- if (in_array($animation['type'], $hiddenAnimations)) {
- return true;
- }
- }
- return false;
- }
-
- protected function _isHiddenFirst($animations)
- {
- $hiddenAnimations = ['reveal', 'fadein', 'translatefrom'];
- foreach ($animations as $animation) {
- if (in_array($animation['type'], $hiddenAnimations)) {
- return true;
- }
- }
- return false;
- }
-
- public function getAddZIndex()
- {
- return parent::getAddZIndex() + $this->animZindex;
- }
-}
-
-class eventOverlayLink extends wsHTML5Link
-{
- public $defaultZIndex = 60;
-
- public function getHTMLContainerClass()
- {
- return parent::getHTMLContainerClass() . ' eventOverlayLink';
- }
-
- public function getHTMLContent()
- {
- return '<div></div>';
- }
-}
-
-class webLink extends normalLink
-{
- protected $role = 'link';
-
- 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
-{
- protected $role = 'link';
-
- 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
-{
- protected $role = 'link';
-
- 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()
- {
- $e = explode('#', $this->to, 2);
-
- $p = $e[0];
- $anchor = false;
- if (count($e) > 1) {
- $anchor = trim($e[1], '# ');
- }
- if ($anchor) {
- $res = anchorLink::normalizeAnchor($anchor);
- } else if ($this->numerotation === 'physical') {
- $res = $p;
- } else {
- $res = $this->compiler->virtualToPhysical($p);
- }
-
-
- return $res;
- }
-
- public function getAdditionnalContent()
- {
- return parent::getAdditionnalContent() . ' role="button"';
- }
-
- public function getDefaultTooltip()
- {
- return 'go to page';
- }
-}
-
-class videoBackgroundLink extends videoLink
-{
- public $defaultZIndex = 10;
-
- public function __construct($id, $init, &$compiler)
- {
- /*
- * public $video_loop;
- public $video_sound_on;
- public $video_controls;
- public $video_auto_start;
- public $video_height;
- public $video_width;
- */
- $init['video_loop'] = true;
- $init['video_controls'] = false;
- $init['video_auto_start'] = true;
- parent::__construct($id, $init, $compiler);
- }
-}
-
-class videoLink extends wsHTML5Link
-{
- public $defaultZIndex = 50;
- public $backgroundColor = '#000000';
-
-
- public static function addVideoJS($compiler)
- {
- $compiler->addVideoJs();
- }
-
- public function getClasses()
- {
- return array_merge(['videoLink'], parent::getClasses());
- }
-
- public function getCSS()
- {
- $res = parent::getCSS();
- $res .= 'background-color:' . $this->backgroundColor . ';';
- return $res;
- }
-
- public function getHTMLContent()
- {
- if (!CubeIT_Util_Url::isDistant($this->to)) {
- $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 self::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);
- $linkDatas->backgroundColor = $attributes['backgroundcolor'];
-
- $res = '<div class="videoContainer integration-' . $linkDatas->inline . '"';
- foreach ($attributes as $name => $value) {
- $res .= " data-{$name}='{$value}'";
- }
- $res .= '></div>';
-
- return $res;
- }
-
- public static function getVideoAttributes($data, $w = null, $h = null, $compiler = null)
- {
-
- $attr['name'] = videoPopupLink::getBasename($data->to);
- if (CubeIT_Util_Url::isDistant($data->to)) {
- $attr['url'] = $data->to;
- }
- $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['hidelinksonplay'] = $data->hidelinksonplay;
- $attr['link-id'] = $data->uid;
- $attr['backgroundcolor'] = isset($data->backgroundColor) ? $data->backgroundColor : '#000000';
-
- if (!is_null($w) && !is_null($h)) {
- $attr['width'] = $w;
- $attr['height'] = $h;
- } else if (!is_null($compiler) && CubeIT_Util_Url::isLocal($data->to)) {
- // Get video dimensions from thumbnail if possible (locally uploaded files)
- $path = $compiler->wdir . '/' . $data->to;
- $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 static function getBasename($f)
- {
- $prefix = '';
- if (CubeIT_Util_Url::isDistant($f)) {
- $prefix = mb_substr(sha1($f), 0, 10) . '-';
- $e = explode('/', $f);
- $f = array_pop($e);
- }
- $e = explode('.', $f);
- array_pop($e);
- return $prefix . implode('.', $e);
- }
-
- public function getURL()
- {
- if (!CubeIT_Util_Url::isDistant($this->to)) {
- $this->copyExternalFile($this->to, true);
- }
- return '#/video/' . self::getBasename($this->to);
- }
-
- public function getAdditionnalContent()
- {
- $this->video_auto_start = true; // Videos should always autoplay
- $this->video_sound_on = true;
- $this->video_controls = true;
- 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
- ]
- ],
- "youtube" => ["loop" => $data->video_loop, 'showinfo' => '0'],
- ];
- 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 self::getEmbed($this);
- }
-
- $w = round($this->width * $this->getCssScale());
- $h = round($this->height * $this->getCssScale());
-
- return self::makeVideoTag($this, $w, $h, $this->compiler);
- }
-
- public static function getEmbed($link, $width = null, $height = null)
- {
- if (null === $width) {
- $width = $link->width;
- }
- if (null === $height) {
- $height = $link->height;
- }
- return '<iframe width="' . $width . '" height="' . $height . '" src="' . self::getEmbedURL($link) . '" frameborder="0" allowfullscreen></iframe>';
- }
-
- public static function getEmbedURL($data)
- {
- switch ($data->video_service) {
- case 0:
- return 'https://www.youtube.com/embed/' . $data->to . '?html5=1';
- case 1:
- return 'https://www.dailymotion.com/embed/video/' . $data->to;
- case 2:
- return 'https://player.vimeo.com/video/' . $data->to;
- case 3:
- default:
- return $data->to;
- }
- }
-
- public static function makeVideoTag($link, $width, $height, $compiler)
- {
- if ($link->video_service == 0) {
- return parent::makeVideoTag($link, $width, $height, $compiler);
- }
- return self::getEmbed($link);
- }
-}
-
-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 pumaCartLink extends cartLink
-{
- public function getInnerContent()
- {
- return '<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px"
- viewBox="0 0 32 32" style="enable-background:new 0 0 32 32;" xml:space="preserve">
-<style type="text/css">
- .st0{fill:#B09474;}
- .st1{fill:#FFFFFF;}
- .st2{opacity:0.5;fill:#B09474;enable-background:new;}
-</style>
-<g class="on">
- <circle class="st0" cx="16" cy="16" r="14"/>
- <path class="st1" d="M16,23.2c-0.2,0-0.4-0.1-0.5-0.2L10,17.4c-1.2-1.2-1.5-3-0.7-4.4c1-1.9,3.4-2.7,5.3-1.7c0.4,0.2,0.7,0.4,1,0.7
- l0.4,0.4l0.4-0.4c1.5-1.5,4-1.5,5.6,0c0.3,0.3,0.6,0.6,0.7,1c0.8,1.5,0.5,3.3-0.7,4.5l-5.5,5.5C16.4,23.1,16.2,23.2,16,23.2z"/>
-</g>
-<g class="off">
- <circle class="st2" cx="16" cy="16" r="14"/>
- <path class="st1" d="M16,23.2c-0.2,0-0.4-0.1-0.5-0.2L10,17.4c-1.2-1.2-1.5-3-0.7-4.4c1-1.9,3.4-2.7,5.3-1.7c0.4,0.2,0.7,0.4,1,0.7
- l0.4,0.4l0.4-0.4c1.5-1.5,4-1.5,5.6,0c0.3,0.3,0.6,0.6,0.7,1c0.8,1.5,0.5,3.3-0.7,4.5l-5.5,5.5C16.4,23.1,16.2,23.2,16,23.2z
- M12.8,12.3c-0.9,0-1.8,0.5-2.3,1.4c-0.5,0.9-0.3,2.1,0.5,2.8l5,5l5-5c0.8-0.7,1-1.9,0.5-2.8c-0.1-0.2-0.3-0.4-0.5-0.6
- c-1-1-2.6-1-3.6,0l-0.9,0.9c-0.3,0.3-0.7,0.3-1,0L14.6,13c-0.2-0.2-0.4-0.3-0.7-0.5C13.6,12.3,13.2,12.3,12.8,12.3z"/>
-</g>
-</svg>';
- }
-
- public function getAdditionnalContent()
- {
- $res = parent::getAdditionnalContent();
- $res .= ' data-tooltip-conditional="' . htmlspecialchars(json_encode(['.active' => 'remove from cart'])) . '" ';
- return $res;
- }
-}
-
-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 layerLink extends imageLink
-{
- protected $maxzoom_default = 4;
- public $defaultZIndex = 31;
-
- public function getCSS()
- {
- $attributes = $this->getZoomAttributes();
- if (!$this->rightClone) {
- zoomLink::generateImage($attributes, $this->compiler, 'layerlink', 'layer');
- }
- return 'background-image:url(' . $this->getImageUrl() . ');background-size:' . $this->getBackgroundSize() . ';background-position:' . $this->getBackgroundPosition() . ';background-repeat:no-repeat;';
- }
-
- public function getImageUrl()
- {
- return '../links/layer_' . $this->uid . '.jpg';
- }
-
- public function getZoomAttributes()
- {
- return [
- 'id' => $this->uid,
- 'page' => $this->page,
- 'maxzoom' => $this->maxzoom_default,
- 'width' => round($this->width),
- 'height' => round($this->height),
- 'x' => round($this->left),
- 'y' => round($this->top),
- ];
- }
-}
-
-class colorLink extends contentLink
-{
- protected $role = '';
-
- public function getCSS()
- {
- $res = parent::getCSS();
- $res .= 'background-color:' . wsHTML5::colorToCSS($this->to, 1) . ';';
- return $res;
- }
-
- 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);
- $res = parent::getCSS();
- $res .= 'line-height:' . $font['capHeight'] . ';font-size:' . $fz . 'px;font-family:' . $font['family'] . ';color:' . wsHTML5::colorToCSS($this->extra, 1) . ';';
- return $res;
- }
-
- 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 getImageUrl()
- {
- return wsHTML5Link::getUniversalLocation($this->to, true);
- }
-
- public function getCSS()
- {
- $res = parent::getCSS();
- $this->copyExternalFile($this->to);
- $res .= 'background-image:url(' . $this->getImageUrl() . ');background-size:' . $this->getBackgroundSize() . ';background-position:' . $this->getBackgroundPosition() . ';background-repeat:no-repeat;';
- return $res;
- }
-
- public function getBackgroundPosition()
- {
- $animations = self::parseAnimations($this->image_rollover);
- foreach ($animations as $animation) {
- if (($animation['type'] === 'zoomout' || $animation['type'] === 'zoomin') && isset($animation['transformorigin'])) {
- return $animation['transformorigin'];
- }
- }
- return '50% 50%';
- }
-
- public function getBackgroundSize()
- {
-
- $size = '100%';
- $animations = self::parseAnimations($this->image_rollover);
- foreach ($animations as $animation) {
- if ($animation['type'] === 'zoomout') {
- $size = round($animation['scale'] * 100) . '%';
- }
- }
- return $size . ' ' . $size;
- }
-
- public function getAdditionnalContent()
- {
- $res = parent::getAdditionnalContent();
- $res .= ' data-image="' . $this->getImageUrl() . '"';
- $res .= ' data-rollover="' . $this->rollover . '"';
- return $res;
- }
-
-}
-
-class inlineSlideshowLink extends slideshowLink
-{
- public function getDepth()
- {
- if ($this->compiler->book->parametres->inlineSlideshowLibrary === 'dummy') {
- $this->defaultZIndex = 30;
- }
- return parent::getDepth();
- }
-
- public function getHTMLContent()
- {
- return $this->generateSlideshow('inline');
- }
-
- public function keep()
- {
- return false;
- }
-}
-
-class fileLink extends normalLink
-{
- protected $role = 'link';
-
- public function getURL()
- {
- $this->copyExternalFile($this->to);
-
- if ($this->compiler->book->parametres->linkFilePrefix && !CubeIT_Util_Url::isDistant($this->to)) {
- return $this->compiler->book->parametres->linkFilePrefix . $this->to;
- }
-
- return wsHTML5Link::getUniversalLocation($this->to);
- }
-
- public function getTarget()
- {
- return $this->target;
- }
-
- public function getDefaultTooltip()
- {
- return 'click to open the file';
- }
-
-}
-
-class downloadPortionLink extends fileLink
-{
- public function getURL()
- {
- $attributes = $this->getZoomAttributes();
- if (!$this->rightClone) {
- zoomLink::generateImage($attributes, $this->compiler, 'downloadportion', 'downloadportion');
- }
- return 'data/links/downloadportion_' . $attributes['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,
- 'border' => $this->border,
- 'borderColor' => $this->borderColor,
- ];
- 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
-{
- protected $role = '';
-
- 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 $role = '';
- protected $_config = null;
- protected $_content = '';
- protected $_url;
- protected $_externalIframe = false;
- public $defaultZIndex = 50;
-
- 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);
- $file = $this->compiler->wdir . '/' . $this->alternative;
- $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 = '<div class="mask"></div>';
- $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;" tabindex="-1" onload="this.style.visibility=\'visible\';"></iframe>';
- }
- if ($this->_externalIframe !== false) {
- $iw = $this->_config['width'] * $s;
- $ih = $this->_config['height'] * $s;
- $res = '<div class="mask"></div>';
- $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;" tabindex="-1" 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 getLottieContent($c, $width, $height)
-// {
-// $this->_config = ['width' => $this->width * $this->getCssScale(), 'height' => $this->height * $this->getCssScale()];
-// $parsedLottie = self::_parseLottieContent($c);
-//
-// $lottieID = $this->compiler->addLottie($parsedLottie['animation'], $parsedLottie['params'], $parsedLottie['hash']);
-// return '<div class="lottie" data-lottie-id="' . $lottieID . '"></div>';
-// }
-//
-// public static function _parseLottieContent($c)
-// {
-// $hash = hash('sha256', $c);
-// $start = mb_strpos($c, 'var animationData = {') + 20;
-// $end = mb_strpos($c, '};', $start) + 1;
-// $ad = mb_substr($c, $start, $end - $start);
-// $animationData = json_decode($ad);
-// preg_match('/var params = (\{.*\});/sU', $c, $matches);
-// $matches[1] = str_replace('container: document.getElementById(\'lottie\'),', '', $matches[1]);
-// $matches[1] = str_replace('animationData: animationData', '', $matches[1]);
-// $params = CJSON::decode($matches[1]);
-// return ['animation' => $animationData, 'params' => $params, 'hash' => $hash];
-// }
-
- 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;
- }
-
- $this->getHTMLContent();
-
- $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()
- {
- switch ($this->video_service) {
- case 0: // Dailymotion
- return '#/webvideo/youtube/' . $this->to;
- case 1: // Dailymotion
- return '#/webvideo/dailymotion/' . $this->to;
- case 2: // Vimeo
- return '#/webvideo/vimeo/' . $this->to;
- case 3: // Brightcove
- return '#/webvideo/brightcove/' . md5($this->to);
- 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)
- {
- $theme = $compiler->book->parametres->audioPlayerTheme;
- $controls = '';
- if ($theme === 'native') {
- $controls = 'controls ';
- }
-
- $res = '<audio class="' . $theme . '" ' . $controls;
- if ($linkDatas->video_loop) {
- $res .= 'loop ';
- }
- if ($linkDatas->video_auto_start) {
- $res .= 'autoplay ';
- }
- $res .= ' src="' . wsHTML5Link::getUniversalLocation($linkDatas->to) . '"';
- $res .= '></audio>';
- $res .= '<div class="visualPlayer"></div>';
- return $res;
- }
-
-}
-
-class grandVisionCartLink extends normalLink
-{
- public function getDefaultTooltip()
- {
- return 'More details';
- }
-
- public function getURL()
- {
- return '#/cart/details/' . $this->to;
- }
-}
-
-class JoueclubWishlistLink extends normalLink
-{
- protected $role = 'link';
-
- public function getURL()
- {
- return 'https://listedecadeau.joueclub.fr/scan?device_id=$uuid&id_from_asset_name=' . $this->to;
- }
-
- public function getTarget()
- {
- return '_popupiframe';
- }
-
- public function getDefaultTooltip()
- {
- return 'Ajouter à la wishlist';
- }
-}
-
-class wescoLink extends normalLink
-{
- protected $role = 'link';
-
- public static function _getURL($to)
- {
- return self::_getURLOfType('wesco', $to);
- }
-
- public function getURL()
- {
- return static::_getURL($this->to);
- }
-
- protected static function _getURLOfType($type, $ref)
- {
- global $core;
- $nospaceref = str_replace(' ', '', $ref);
- $r = $core->con->select("SELECT * FROM wsref WHERE (ref='" . $core->con->escape($ref) . "' OR ref='" . $core->con->escape($nospaceref) . "') 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';
- //return '_popupiframe';
- }
-
- public function getDefaultTooltip()
- {
- return 'click to open the link';
- }
-
-}
-
-class pierronLink extends normalLink
-{
- protected $role = 'link';
-
- 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 miraklEaster2021Link extends normalLink
-{
- public function getURL()
- {
- return '#';
- }
-
- public function getAdditionnalContent()
- {
- return parent::getAdditionnalContent() . ' data-answers="' . $this->to . '" ';
- }
-}
-
-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 = $this->getTooltipAttribute();
-
- 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
-{
- protected $role = 'link';
-
- 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
-{
- protected $role = 'link';
-
- 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)
- {
- $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) . '"';
- }
-
- if (!$this->rightClone) {
- self::generateImage($this->getZoomAttributes(), $this->compiler, 'zoomarea', 'zoom');
- }
-
- return $res;
- }
-
- public function getZoomAttributes()
- {
- return [
- 'id' => $this->uid,
- '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),
- 'border' => $this->border,
- 'borderColor' => $this->borderColor,
- ];
- }
-
- 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' => 150 * $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->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;
- }
-
- if (isset($attributes['border']) && $attributes['border'] > 0) {
- $tmp = CubeIT_Files::tempnam() . '.jpg';
- CubeIT_CommandLine_Imagemagick::addBorder($both, $tmp, $attributes['border'], $attributes['borderColor']);
- $compiler->vdir->addTemp($both);
- $both = $tmp;
- }
-
- $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;
- protected $allowed_extensions;
- protected $thumbnail_height = 80; // Height in px of thumbnail slider
-
- 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('popup')) . '" ';
- }
-
-// public function keep() {
-// return true;
-// }
-
- public function getDefaultTooltip()
- {
- return 'view slideshow';
- }
-
- public function generateSlideshow($context)
- {
- $this->compiler->addSlideshowLibrary($context === 'inline');
-
- $this->allowed_extensions = ['jpg', 'png', 'jpeg', 'gif', 'svg'];
-
- $slideshowID = 'slideshow_' . $this->uid;
- $XML_path = $this->path_absolute . '/slideshow.xml'; // Optional file so it may not exist
-
- // Default Slick settings (can be overridden by slideshow.xml)
- $slideshow_settings = [
- 'autoplay' => false,
- 'fade' => false,
- ];
-
- $this->getURL();
-
- $slides = [];
- $slides_options = [];
-
- // 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);
- $thumbnails = isset($slideshowData->_thumbnails) && $slideshowData->_thumbnails !== 'false';
-
- // Allow "fade" transition to be enabled
- if (isset($slideshowData->_effect) && $slideshowData->_effect == 'fade') {
- $slideshow_settings['type'] = 'fade';
- $slideshow_settings['rewind'] = true; // Loop infinitely
- }
-
- // Autoplay
- if (isset($slideshowData->_autoplay) && $slideshowData->_autoplay == 'true') {
- $slideshow_settings['autoplay'] = true;
- }
-
- // Allow caption font-size to be overridden from XML file
- $slides_options['caption_size'] = $slideshowData->_captionsize ?? null;
-
-
- if (isset($slideshowData->image)) {
- $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];
- }
- }
-
- // It's possible that images are not defined in the slideshow.xml structure.
- // In this case, we attempt to read the images from the directory...
- if (empty($slides)) {
- $slides = $this->_getSlidesFromDirectory($this->path_absolute);
- }
-
- } else {
- // Or by default, just get all the images that were in the zip file...
- $slides = $this->_getSlidesFromDirectory($this->path_absolute);
-
- $thumbnails = (count($slides) > 1);
- }
-
- // Main slider
- $res = '<div class="fb-slideshow splide" id="' . $slideshowID . '" data-open-index="' . $this->extra . '" data-thumbnails="' . ($thumbnails ? '1' : '0') . '" data-splide=\'' . json_encode($slideshow_settings) . '\'>' . $this->_slides($slides, $slides_options) . '</div>';
-
- // Thumbnails slider
- if ($thumbnails) {
- $res .= '<div class="fb-slideshow-thumbnails splide" id="' . $slideshowID . '_thumbnails">' . $this->_slides($slides, ['show_captions' => false, 'max_height' => $this->thumbnail_height]) . '</div>';
- }
-
- $lib = $context === 'popup' ? $this->compiler->book->parametres->popupSlideshowLibrary : $this->compiler->book->parametres->inlineSlideshowLibrary;
- $res = '<div class="fb-slideshow-wrapper ' . $lib . ' fb-slideshow-' . $context . '">' . $res . '</div>';
-
- return $res;
- }
-
- protected function _getSlidesFromDirectory($path)
- {
- // 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...
- $files = CubeIT_Files::getDirectoryIterator($path);
- $slides = [];
-
- foreach ($files as $file) {
- /** @var SplFileInfo $file */
- if (!$file->isFile()) {
- continue;
- }
- $ext = mb_strtolower($file->getExtension());
- if (!in_array($ext, $this->allowed_extensions)) {
- continue;
- }
- $slides[] = ['path' => $file->getPathname(), 'caption' => null];
- uasort($slides, [$this, '_orderSlidesByFilename']);
- }
-
- return $slides;
- }
-
- protected function _slides($slides, $options = [])
- {
- $default_options = [
- 'show_captions' => true,
- 'caption_size' => null,
- 'max_height' => null,
- ];
-
- $options = array_merge($default_options, $options);
-
- $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 = CubeIT_Image::getimagesize($slide['path']);
- $image_info_json = ($image_info) ? json_encode(['width' => $image_info[0], 'height' => $image_info[1], 'ratio' => round($image_info[0] / $image_info[1], 4)]) : '';
- $image_dimensions = ($image_info) ? $image_info[3] : '';
-
- // When displaying thumbnails, they are a fixed size, based on height
- // We set dimensions here to avoid extra work on the client side
- if ($options['max_height'] && $image_info) {
- $thumb_width = round($options['max_height'] / $image_info[1] * $image_info[0]); // max_height / image_height * image_width
- $image_dimensions = 'style="width:' . $thumb_width . 'px; height:' . $options['max_height'] . 'px"';
- }
-
- $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 ($options['show_captions'] && null !== $slide['caption']) {
-
- // Caption font size can be overridden if specified in XML
- $caption_style = $options['caption_size'] ? ' style="font-size:' . $options['caption_size'] . '"' : '';
-
- $res .= '<p class="fb-slideshow-slide-caption"' . $caption_style . '>' . $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']);
- }
-
- public function keep()
- {
- return true;
- }
-}
-
-class iframeLink extends wsHTML5Link
-{
- protected $_defaultTooltip;
- protected $scale = 'auto';
- protected $scrolling = 'auto';
-
- function getHTMLContainerClass()
- {
- return parent::getHTMLContainerClass() . ' iframe';
- }
-
- function getHTMLContent()
- {
- return '<iframe src="' . self::_handleFile($this) . '" width="100%" height="100%" frameborder="0" marginwidth="0" marginheight="0" data-scale="' . $this->scale . '" scrolling="' . $this->scrolling . '" allowfullscreen mozallowfullscreen="true" webkitallowfullscreen="true" onmousewheel=""></iframe>';
- }
-
- /**
- * @param $link wsHTML5Link
- */
- public static function _handleFile($link)
- {
- $to = preg_replace('/^data\/links\//', '', $link->to);
- if (!CubeIT_Util_Url::isDistant($to)) {
- $e = explode('.', $to);
- $ext = array_pop($e);
- if ($ext === 'oam' || $ext === 'zip') {
- if ($ext === 'oam') {
- $d = $link->unzipFile($to, true);
- $config = $link->getConfigOAM($d['dir']);
- $link->copyExternalDir($d['dir'], $d['fdir']);
- } else if ($ext === 'zip') {
- $d = $link->unzipFile($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($to);
- return wsHTML5Link::getUniversalLocation($to);
- }
- }
-
- return $to;
- }
-}
-
-class articleLink extends normalLink
-{
- protected $article;
-
- public function init()
- {
- parent::init();
- $this->article = $this->compiler->config->articlesList[$this->to];
- if (!isset($this->compiler->config->articlesList[$this->to]['page'])) {
- $this->compiler->config->articlesList[$this->to]['page'] = $this->page;
- }
- }
-
- 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;
- }
-
-}
-
-
-/**
- * JSON (JavaScript Object Notation) is a lightweight data-interchange
- * format. It is easy for humans to read and write. It is easy for machines
- * to parse and generate. It is based on a subset of the JavaScript
- * Programming Language, Standard ECMA-262 3rd Edition - December 1999.
- * This feature can also be found in Python. JSON is a text format that is
- * completely language independent but uses conventions that are familiar
- * to programmers of the C-family of languages, including C, C++, C#, Java,
- * JavaScript, Perl, TCL, and many others. These properties make JSON an
- * ideal data-interchange language.
- *
- * This package provides a simple encoder and decoder for JSON notation. It
- * is intended for use with client-side Javascript applications that make
- * use of HTTPRequest to perform server communication functions - data can
- * be encoded into JSON notation for use in a client-side javascript, or
- * decoded from incoming Javascript requests. JSON format is native to
- * Javascript, and can be directly eval()'ed with no further parsing
- * overhead
- *
- * All strings should be in ASCII or UTF-8 format!
- *
- * LICENSE: Redistribution and use in source and binary forms, with or
- * without modification, are permitted provided that the following
- * conditions are met: Redistributions of source code must retain the
- * above copyright notice, this list of conditions and the following
- * disclaimer. Redistributions in binary form must reproduce the above
- * copyright notice, this list of conditions and the following disclaimer
- * in the documentation and/or other materials provided with the
- * distribution.
- *
- * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED
- * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
- * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN
- * NO EVENT SHALL CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
- * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
- * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
- * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
- * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
- * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
- * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
- * DAMAGE.
- *
- * @author Michal Migurski <mike-json@teczno.com>
- * @author Matt Knapp <mdknapp[at]gmail[dot]com>
- * @author Brett Stimmerman <brettstimmerman[at]gmail[dot]com>
- * @copyright 2005 Michal Migurski
- * @license http://www.opensource.org/licenses/bsd-license.php
- * @link http://pear.php.net/pepr/pepr-proposal-show.php?id=198
- */
-
-/**
- * CJSON converts PHP data to and from JSON format.
- *
- * @author Michal Migurski <mike-json@teczno.com>
- * @author Matt Knapp <mdknapp[at]gmail[dot]com>
- * @author Brett Stimmerman <brettstimmerman[at]gmail[dot]com>
- * @package system.web.helpers
- * @since 1.0
- */
-class CJSON
-{
- /**
- * Marker constant for JSON::decode(), used to flag stack state
- */
- const JSON_SLICE = 1;
-
- /**
- * Marker constant for JSON::decode(), used to flag stack state
- */
- const JSON_IN_STR = 2;
-
- /**
- * Marker constant for JSON::decode(), used to flag stack state
- */
- const JSON_IN_ARR = 4;
-
- /**
- * Marker constant for JSON::decode(), used to flag stack state
- */
- const JSON_IN_OBJ = 8;
-
- /**
- * Marker constant for JSON::decode(), used to flag stack state
- */
- const JSON_IN_CMT = 16;
-
- /**
- * Encodes an arbitrary variable into JSON format
- *
- * @param mixed $var any number, boolean, string, array, or object to be encoded.
- * If var is a string, it will be converted to UTF-8 format first before being encoded.
- * @return string JSON string representation of input var
- */
- public static function encode($var)
- {
- switch (gettype($var)) {
- case 'boolean':
- return $var ? 'true' : 'false';
-
- case 'NULL':
- return 'null';
-
- case 'integer':
- return (int)$var;
-
- case 'double':
- case 'float':
- return str_replace(',', '.', (float)$var); // locale-independent representation
-
- case 'string':
- if (($enc = strtoupper(Yii::app()->charset)) !== 'UTF-8')
- $var = iconv($enc, 'UTF-8', $var);
-
- if (function_exists('json_encode'))
- return json_encode($var);
-
- // STRINGS ARE EXPECTED TO BE IN ASCII OR UTF-8 FORMAT
- $ascii = '';
- $strlen_var = strlen($var);
-
- /*
- * Iterate over every character in the string,
- * escaping with a slash or encoding to UTF-8 where necessary
- */
- for ($c = 0; $c < $strlen_var; ++$c) {
-
- $ord_var_c = ord($var{$c});
-
- switch (true) {
- case $ord_var_c == 0x08:
- $ascii .= '\b';
- break;
- case $ord_var_c == 0x09:
- $ascii .= '\t';
- break;
- case $ord_var_c == 0x0A:
- $ascii .= '\n';
- break;
- case $ord_var_c == 0x0C:
- $ascii .= '\f';
- break;
- case $ord_var_c == 0x0D:
- $ascii .= '\r';
- break;
-
- case $ord_var_c == 0x22:
- case $ord_var_c == 0x2F:
- case $ord_var_c == 0x5C:
- // double quote, slash, slosh
- $ascii .= '\\' . $var{$c};
- break;
-
- case (($ord_var_c >= 0x20) && ($ord_var_c <= 0x7F)):
- // characters U-00000000 - U-0000007F (same as ASCII)
- $ascii .= $var{$c};
- break;
-
- case (($ord_var_c & 0xE0) == 0xC0):
- // characters U-00000080 - U-000007FF, mask 110XXXXX
- // see http://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8
- $char = pack('C*', $ord_var_c, ord($var{$c + 1}));
- $c += 1;
- $utf16 = self::utf8ToUTF16BE($char);
- $ascii .= sprintf('\u%04s', bin2hex($utf16));
- break;
-
- case (($ord_var_c & 0xF0) == 0xE0):
- // characters U-00000800 - U-0000FFFF, mask 1110XXXX
- // see http://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8
- $char = pack('C*', $ord_var_c,
- ord($var{$c + 1}),
- ord($var{$c + 2}));
- $c += 2;
- $utf16 = self::utf8ToUTF16BE($char);
- $ascii .= sprintf('\u%04s', bin2hex($utf16));
- break;
-
- case (($ord_var_c & 0xF8) == 0xF0):
- // characters U-00010000 - U-001FFFFF, mask 11110XXX
- // see http://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8
- $char = pack('C*', $ord_var_c,
- ord($var{$c + 1}),
- ord($var{$c + 2}),
- ord($var{$c + 3}));
- $c += 3;
- $utf16 = self::utf8ToUTF16BE($char);
- $ascii .= sprintf('\u%04s', bin2hex($utf16));
- break;
-
- case (($ord_var_c & 0xFC) == 0xF8):
- // characters U-00200000 - U-03FFFFFF, mask 111110XX
- // see http://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8
- $char = pack('C*', $ord_var_c,
- ord($var{$c + 1}),
- ord($var{$c + 2}),
- ord($var{$c + 3}),
- ord($var{$c + 4}));
- $c += 4;
- $utf16 = self::utf8ToUTF16BE($char);
- $ascii .= sprintf('\u%04s', bin2hex($utf16));
- break;
-
- case (($ord_var_c & 0xFE) == 0xFC):
- // characters U-04000000 - U-7FFFFFFF, mask 1111110X
- // see http://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8
- $char = pack('C*', $ord_var_c,
- ord($var{$c + 1}),
- ord($var{$c + 2}),
- ord($var{$c + 3}),
- ord($var{$c + 4}),
- ord($var{$c + 5}));
- $c += 5;
- $utf16 = self::utf8ToUTF16BE($char);
- $ascii .= sprintf('\u%04s', bin2hex($utf16));
- break;
- }
- }
-
- return '"' . $ascii . '"';
-
- case 'array':
- /*
- * As per JSON spec if any array key is not an integer
- * we must treat the the whole array as an object. We
- * also try to catch a sparsely populated associative
- * array with numeric keys here because some JS engines
- * will create an array with empty indexes up to
- * max_index which can cause memory issues and because
- * the keys, which may be relevant, will be remapped
- * otherwise.
- *
- * As per the ECMA and JSON specification an object may
- * have any string as a property. Unfortunately due to
- * a hole in the ECMA specification if the key is a
- * ECMA reserved word or starts with a digit the
- * parameter is only accessible using ECMAScript's
- * bracket notation.
- */
-
- // treat as a JSON object
- if (is_array($var) && count($var) && (array_keys($var) !== range(0, sizeof($var) - 1))) {
- return '{' .
- join(',', array_map(array('CJSON', 'nameValue'),
- array_keys($var),
- array_values($var)))
- . '}';
- }
-
- // treat it like a regular array
- return '[' . join(',', array_map(array('CJSON', 'encode'), $var)) . ']';
-
- case 'object':
- if ($var instanceof Traversable) {
- $vars = array();
- foreach ($var as $k => $v)
- $vars[$k] = $v;
- } else
- $vars = get_object_vars($var);
- return '{' .
- join(',', array_map(array('CJSON', 'nameValue'),
- array_keys($vars),
- array_values($vars)))
- . '}';
-
- default:
- return '';
- }
- }
-
- /**
- * array-walking function for use in generating JSON-formatted name-value pairs
- *
- * @param string $name name of key to use
- * @param mixed $value reference to an array element to be encoded
- *
- * @return string JSON-formatted name-value pair, like '"name":value'
- * @access private
- */
- protected static function nameValue($name, $value)
- {
- return self::encode(strval($name)) . ':' . self::encode($value);
- }
-
- /**
- * reduce a string by removing leading and trailing comments and whitespace
- *
- * @param string $str string value to strip of comments and whitespace
- *
- * @return string string value stripped of comments and whitespace
- * @access private
- */
- protected static function reduceString($str)
- {
- $str = preg_replace(array(
-
- // eliminate single line comments in '// ...' form
- '#^\s*//(.+)$#m',
-
- // eliminate multi-line comments in '/* ... */' form, at start of string
- '#^\s*/\*(.+)\*/#Us',
-
- // eliminate multi-line comments in '/* ... */' form, at end of string
- '#/\*(.+)\*/\s*$#Us'
-
- ), '', $str);
-
- // eliminate extraneous space
- return trim($str);
- }
-
- /**
- * decodes a JSON string into appropriate variable
- *
- * @param string $str JSON-formatted string
- * @param boolean $useArray whether to use associative array to represent object data
- * @return mixed number, boolean, string, array, or object corresponding to given JSON input string.
- * Note that decode() always returns strings in ASCII or UTF-8 format!
- * @access public
- */
- public static function decode($str, $useArray = true)
- {
- if (function_exists('json_decode')) {
- $json = json_decode($str, $useArray);
-
- // based on investigation, native fails sometimes returning null.
- // see: http://gggeek.altervista.org/sw/article_20070425.html
- // As of PHP 5.3.6 it still fails on some valid JSON strings
- if ($json !== null)
- return $json;
- }
-
- $str = self::reduceString($str);
-
- switch (strtolower($str)) {
- case 'true':
- return true;
-
- case 'false':
- return false;
-
- case 'null':
- return null;
-
- default:
- if (is_numeric($str)) {
- // Lookie-loo, it's a number
-
- // This would work on its own, but I'm trying to be
- // good about returning integers where appropriate:
- // return (float)$str;
-
- // Return float or int, as appropriate
- return ((float)$str == (integer)$str)
- ? (integer)$str
- : (float)$str;
-
- } elseif (preg_match('/^("|\').+(\1)$/s', $str, $m) && $m[1] == $m[2]) {
- // STRINGS RETURNED IN UTF-8 FORMAT
- $delim = substr($str, 0, 1);
- $chrs = substr($str, 1, -1);
- $utf8 = '';
- $strlen_chrs = strlen($chrs);
-
- for ($c = 0; $c < $strlen_chrs; ++$c) {
-
- $substr_chrs_c_2 = substr($chrs, $c, 2);
- $ord_chrs_c = ord($chrs{$c});
-
- switch (true) {
- case $substr_chrs_c_2 == '\b':
- $utf8 .= chr(0x08);
- ++$c;
- break;
- case $substr_chrs_c_2 == '\t':
- $utf8 .= chr(0x09);
- ++$c;
- break;
- case $substr_chrs_c_2 == '\n':
- $utf8 .= chr(0x0A);
- ++$c;
- break;
- case $substr_chrs_c_2 == '\f':
- $utf8 .= chr(0x0C);
- ++$c;
- break;
- case $substr_chrs_c_2 == '\r':
- $utf8 .= chr(0x0D);
- ++$c;
- break;
-
- case $substr_chrs_c_2 == '\\"':
- case $substr_chrs_c_2 == '\\\'':
- case $substr_chrs_c_2 == '\\\\':
- case $substr_chrs_c_2 == '\\/':
- if (($delim == '"' && $substr_chrs_c_2 != '\\\'') ||
- ($delim == "'" && $substr_chrs_c_2 != '\\"')) {
- $utf8 .= $chrs{++$c};
- }
- break;
-
- case preg_match('/\\\u[0-9A-F]{4}/i', substr($chrs, $c, 6)):
- // single, escaped unicode character
- $utf16 = chr(hexdec(substr($chrs, ($c + 2), 2)))
- . chr(hexdec(substr($chrs, ($c + 4), 2)));
- $utf8 .= self::utf16beToUTF8($utf16);
- $c += 5;
- break;
-
- case ($ord_chrs_c >= 0x20) && ($ord_chrs_c <= 0x7F):
- $utf8 .= $chrs{$c};
- break;
-
- case ($ord_chrs_c & 0xE0) == 0xC0:
- // characters U-00000080 - U-000007FF, mask 110XXXXX
- //see http://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8
- $utf8 .= substr($chrs, $c, 2);
- ++$c;
- break;
-
- case ($ord_chrs_c & 0xF0) == 0xE0:
- // characters U-00000800 - U-0000FFFF, mask 1110XXXX
- // see http://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8
- $utf8 .= substr($chrs, $c, 3);
- $c += 2;
- break;
-
- case ($ord_chrs_c & 0xF8) == 0xF0:
- // characters U-00010000 - U-001FFFFF, mask 11110XXX
- // see http://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8
- $utf8 .= substr($chrs, $c, 4);
- $c += 3;
- break;
-
- case ($ord_chrs_c & 0xFC) == 0xF8:
- // characters U-00200000 - U-03FFFFFF, mask 111110XX
- // see http://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8
- $utf8 .= substr($chrs, $c, 5);
- $c += 4;
- break;
-
- case ($ord_chrs_c & 0xFE) == 0xFC:
- // characters U-04000000 - U-7FFFFFFF, mask 1111110X
- // see http://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8
- $utf8 .= substr($chrs, $c, 6);
- $c += 5;
- break;
-
- }
-
- }
-
- return $utf8;
-
- } elseif (preg_match('/^\[.*\]$/s', $str) || preg_match('/^\{.*\}$/s', $str)) {
- // array, or object notation
-
- if ($str{0} == '[') {
- $stk = array(self::JSON_IN_ARR);
- $arr = array();
- } else {
- if ($useArray) {
- $stk = array(self::JSON_IN_OBJ);
- $obj = array();
- } else {
- $stk = array(self::JSON_IN_OBJ);
- $obj = new stdClass();
- }
- }
-
- $stk[] = array('what' => self::JSON_SLICE, 'where' => 0, 'delim' => false);
-
- $chrs = substr($str, 1, -1);
- $chrs = self::reduceString($chrs);
-
- if ($chrs == '') {
- if (reset($stk) == self::JSON_IN_ARR) {
- return $arr;
-
- } else {
- return $obj;
-
- }
- }
-
- //print("\nparsing {$chrs}\n");
-
- $strlen_chrs = strlen($chrs);
-
- for ($c = 0; $c <= $strlen_chrs; ++$c) {
-
- $top = end($stk);
- $substr_chrs_c_2 = substr($chrs, $c, 2);
-
- if (($c == $strlen_chrs) || (($chrs{$c} == ',') && ($top['what'] == self::JSON_SLICE))) {
- // found a comma that is not inside a string, array, etc.,
- // OR we've reached the end of the character list
- $slice = substr($chrs, $top['where'], ($c - $top['where']));
- $stk[] = array('what' => self::JSON_SLICE, 'where' => ($c + 1), 'delim' => false);
- //print("Found split at {$c}: ".substr($chrs, $top['where'], (1 + $c - $top['where']))."\n");
-
- if (reset($stk) == self::JSON_IN_ARR) {
- // we are in an array, so just push an element onto the stack
- $arr[] = self::decode($slice, $useArray);
-
- } elseif (reset($stk) == self::JSON_IN_OBJ) {
- // we are in an object, so figure
- // out the property name and set an
- // element in an associative array,
- // for now
- if (preg_match('/^\s*(["\'].*[^\\\]["\'])\s*:\s*(\S.*),?$/Uis', $slice, $parts)) {
- // "name":value pair
- $key = self::decode($parts[1], $useArray);
- $val = self::decode($parts[2], $useArray);
-
- if ($useArray) {
- $obj[$key] = $val;
- } else {
- $obj->$key = $val;
- }
- } elseif (preg_match('/^\s*(\w+)\s*:\s*(\S.*),?$/Uis', $slice, $parts)) {
- // name:value pair, where name is unquoted
- $key = $parts[1];
- $val = self::decode($parts[2], $useArray);
-
- if ($useArray) {
- $obj[$key] = $val;
- } else {
- $obj->$key = $val;
- }
- }
-
- }
-
- } elseif ((($chrs{$c} == '"') || ($chrs{$c} == "'")) && ($top['what'] != self::JSON_IN_STR)) {
- // found a quote, and we are not inside a string
- $stk[] = array('what' => self::JSON_IN_STR, 'where' => $c, 'delim' => $chrs{$c});
- //print("Found start of string at {$c}\n");
-
- } elseif (($chrs{$c} == $top['delim']) &&
- ($top['what'] == self::JSON_IN_STR) &&
- (($chrs{$c - 1} != "\\") ||
- ($chrs{$c - 1} == "\\" && $chrs{$c - 2} == "\\"))) {
- // found a quote, we're in a string, and it's not escaped
- array_pop($stk);
- //print("Found end of string at {$c}: ".substr($chrs, $top['where'], (1 + 1 + $c - $top['where']))."\n");
-
- } elseif (($chrs{$c} == '[') &&
- in_array($top['what'], array(self::JSON_SLICE, self::JSON_IN_ARR, self::JSON_IN_OBJ))) {
- // found a left-bracket, and we are in an array, object, or slice
- $stk[] = array('what' => self::JSON_IN_ARR, 'where' => $c, 'delim' => false);
- //print("Found start of array at {$c}\n");
-
- } elseif (($chrs{$c} == ']') && ($top['what'] == self::JSON_IN_ARR)) {
- // found a right-bracket, and we're in an array
- array_pop($stk);
- //print("Found end of array at {$c}: ".substr($chrs, $top['where'], (1 + $c - $top['where']))."\n");
-
- } elseif (($chrs{$c} == '{') &&
- in_array($top['what'], array(self::JSON_SLICE, self::JSON_IN_ARR, self::JSON_IN_OBJ))) {
- // found a left-brace, and we are in an array, object, or slice
- $stk[] = array('what' => self::JSON_IN_OBJ, 'where' => $c, 'delim' => false);
- //print("Found start of object at {$c}\n");
-
- } elseif (($chrs{$c} == '}') && ($top['what'] == self::JSON_IN_OBJ)) {
- // found a right-brace, and we're in an object
- array_pop($stk);
- //print("Found end of object at {$c}: ".substr($chrs, $top['where'], (1 + $c - $top['where']))."\n");
-
- } elseif (($substr_chrs_c_2 == '/*') &&
- in_array($top['what'], array(self::JSON_SLICE, self::JSON_IN_ARR, self::JSON_IN_OBJ))) {
- // found a comment start, and we are in an array, object, or slice
- $stk[] = array('what' => self::JSON_IN_CMT, 'where' => $c, 'delim' => false);
- $c++;
- //print("Found start of comment at {$c}\n");
-
- } elseif (($substr_chrs_c_2 == '*/') && ($top['what'] == self::JSON_IN_CMT)) {
- // found a comment end, and we're in one now
- array_pop($stk);
- $c++;
-
- for ($i = $top['where']; $i <= $c; ++$i)
- $chrs = substr_replace($chrs, ' ', $i, 1);
-
- //print("Found end of comment at {$c}: ".substr($chrs, $top['where'], (1 + $c - $top['where']))."\n");
-
- }
-
- }
-
- if (reset($stk) == self::JSON_IN_ARR) {
- return $arr;
-
- } elseif (reset($stk) == self::JSON_IN_OBJ) {
- return $obj;
-
- }
-
- }
- }
- }
-
- /**
- * This function returns any UTF-8 encoded text as a list of
- * Unicode values:
- * @param string $str string to convert
- * @return string
- * @author Scott Michael Reynen <scott@randomchaos.com>
- * @link http://www.randomchaos.com/document.php?source=php_and_unicode
- * @see unicodeToUTF8()
- */
- protected static function utf8ToUnicode(&$str)
- {
- $unicode = array();
- $values = array();
- $lookingFor = 1;
-
- for ($i = 0; $i < strlen($str); $i++) {
- $thisValue = ord($str[$i]);
- if ($thisValue < 128)
- $unicode[] = $thisValue;
- else {
- if (count($values) == 0)
- $lookingFor = ($thisValue < 224) ? 2 : 3;
- $values[] = $thisValue;
- if (count($values) == $lookingFor) {
- $number = ($lookingFor == 3) ?
- (($values[0] % 16) * 4096) + (($values[1] % 64) * 64) + ($values[2] % 64) :
- (($values[0] % 32) * 64) + ($values[1] % 64);
- $unicode[] = $number;
- $values = array();
- $lookingFor = 1;
- }
- }
- }
- return $unicode;
- }
-
- /**
- * This function converts a Unicode array back to its UTF-8 representation
- * @param string $str string to convert
- * @return string
- * @author Scott Michael Reynen <scott@randomchaos.com>
- * @link http://www.randomchaos.com/document.php?source=php_and_unicode
- * @see utf8ToUnicode()
- */
- protected static function unicodeToUTF8(&$str)
- {
- $utf8 = '';
- foreach ($str as $unicode) {
- if ($unicode < 128) {
- $utf8 .= chr($unicode);
- } elseif ($unicode < 2048) {
- $utf8 .= chr(192 + (($unicode - ($unicode % 64)) / 64));
- $utf8 .= chr(128 + ($unicode % 64));
- } else {
- $utf8 .= chr(224 + (($unicode - ($unicode % 4096)) / 4096));
- $utf8 .= chr(128 + ((($unicode % 4096) - ($unicode % 64)) / 64));
- $utf8 .= chr(128 + ($unicode % 64));
- }
- }
- return $utf8;
- }
-
- /**
- * UTF-8 to UTF-16BE conversion.
- *
- * Maybe really UCS-2 without mb_string due to utf8ToUnicode limits
- * @param string $str string to convert
- * @param boolean $bom whether to output BOM header
- * @return string
- */
- protected static function utf8ToUTF16BE(&$str, $bom = false)
- {
- $out = $bom ? "\xFE\xFF" : '';
- if (function_exists('mb_convert_encoding'))
- return $out . mb_convert_encoding($str, 'UTF-16BE', 'UTF-8');
-
- $uni = self::utf8ToUnicode($str);
- foreach ($uni as $cp)
- $out .= pack('n', $cp);
- return $out;
- }
-
- /**
- * UTF-8 to UTF-16BE conversion.
- *
- * Maybe really UCS-2 without mb_string due to utf8ToUnicode limits
- * @param string $str string to convert
- * @return string
- */
- protected static function utf16beToUTF8(&$str)
- {
- $uni = unpack('n*', $str);
- return self::unicodeToUTF8($uni);
- }
-}
-