From: vincent@cubedesigners.com Date: Mon, 7 Oct 2019 17:03:51 +0000 (+0000) Subject: wip #3097 @4 X-Git-Url: http://git.cubedesigners.com/?a=commitdiff_plain;h=84bb5726b0f4ff345f1d9077b96cb69e6f0a6654;p=cubeextranet.git wip #3097 @4 --- diff --git a/inc/ws/Metier/class.ws.book.parametres.php b/inc/ws/Metier/class.ws.book.parametres.php index 4712d3aa2..fb5ecc6d1 100644 --- a/inc/ws/Metier/class.ws.book.parametres.php +++ b/inc/ws/Metier/class.ws.book.parametres.php @@ -515,9 +515,14 @@ class wsBookParametres extends wsParametres $this->fields['mobileIgnoreBackgroundLinks'] = array('type' => 'boolean', 'default' => false, 'editable' => true, 'label' => __('Ignorer les liens de background')); - $this->forms['mobile'] = array('label' => __('Version mobile'), + $this->forms['mobile'] = array('label' => __('Version HTML5'), 'fieldsnames' => array('alwaysHTML5', 'html5priority', 'flashBlockedWait', 'mobileNavigationType', '|', 'rasterizePages', 'vectorPages', '|', 'mobileNavScale', '|', 'mobileTransitionDuration', "mobileLinksRevealAnim", '|', 'menuBreakpoint', 'navOrderH', '|', 'mobileIconVector', 'mobileServerConfig', 'mobilePlugins', '|', 'mobileVideosPath', '|', 'mobileExtraXSpace', '|', 'mobileIgnoreBackgroundLinks')); + $this->fields['mobilefirstFluidbookId'] = ['type' => 'text', 'default' => '', 'editable' => true, 'label' => 'Identifiant du fluidbook "Mobile first"', 'grade' => 5]; + $this->fields['mobilefirstBreakpoint'] = ['type' => 'text', 'default' => '640', 'editable' => true, 'label' => 'Breakpoint du passage à la version "Mobile first" (en pixels)', 'grade' => 5]; + $this->forms['mobilefirst'] = ['label' => __('Mobile first'), + 'fieldsnames' => ['mobilefirstFluidbookId', 'mobilefirstBreakpoint']]; + $this->fields['phonegapId'] = array('type' => 'text', 'default' => 'com.fluidbook.phonegap.$id', 'editable' => true, 'label' => __("Identifiant de l'identifiant"), 'grade' => 5, 'hint' => __('De la forme') . ' com.fluidbook.phonegap.xxxxx'); $this->fields['phonegapVersion'] = array('type' => 'text', 'default' => '1.0.0', 'editable' => true, 'label' => __("Version de l'application"), 'grade' => 5, 'hint' => __('De la forme') . ' 1.2.3'); diff --git a/inc/ws/Util/packager/class.ws.packager.html.php b/inc/ws/Util/packager/class.ws.packager.html.php index 45fbc4ba0..6fa874117 100644 --- a/inc/ws/Util/packager/class.ws.packager.html.php +++ b/inc/ws/Util/packager/class.ws.packager.html.php @@ -3,186 +3,190 @@ class wsPackagerHTML extends wsPackager { - protected $origHTML; - protected $_labels = array(); - protected $_allowNeworking = 'all'; - protected $_ext = 'html'; - protected $_forceOnlyHtml = false; - protected $_disableScorm = true; - - public function __construct($book_id, $vdir = null, $whole = true) - { - parent::__construct($book_id, $vdir, $whole); - $this->version = 'html'; - } - - protected function getMinFlashVersion() - { - return '10.0.22'; - } - - protected function getSWFFiles() - { - return array('index.swf', 'player.swf'); - } - - protected function preparePackage() - { - parent::preparePackage(); - - if ($this->_forceOnlyHtml) { - $this->book->parametres->alwaysHTML5 = true; - } - if ($this->_disableScorm) { - $this->book->parametres->scorm_enable = false; - } - - $this->_ext = $this->book->parametres->htmlExtension; - - if ($this->book->parametres->offlineExport && $this->book->parametres->pdfComplex) { - $versions = array('win-ins' => 'exe', 'mac-exe' => 'zip'); - foreach ($versions as $v => $ext) { - $a = wsPackager::package($this->book_id, $v); - rename(ROOT . $a, $this->vdir . '/data/document.' . $ext); - } - } - - $this->copyFluidbookFiles(); - $this->mergeJavascript(); - - $others = array('fluidbook.js', 'getflash.gif', 'index.html', 'style.css'); - $others = array_merge($others, $this->getSWFFiles()); - - $this->copyOtherFiles($others); - - if (!file_exists($this->vdir . '/pages')) { - mkdir($this->vdir . '/pages/', 0777, true); - } - - $ga = ''; - if ($this->book->parametres->googleAnalyticsCustom) { - $ga = $this->book->parametres->googleAnalyticsCustom; - } elseif ($this->book->parametres->googleAnalytics != '') { - $variables = array('Language' => array('value' => 'getLang()', 'valueAsJS' => true, 'scope' => 2)); - $ga = cubePage::googleAnalytics(explode(',', $this->book->parametres->googleAnalytics), true, $variables); - } - - $statsfooter = ''; - if ($this->book->parametres->statsCustom != '') { - $statsfooter = $this->book->parametres->statsCustom; - } - - $facebook = ''; - if ($this->book->parametres->facebook) { - if ($this->book->parametres->facebook_title != '') { - $facebook .= ''; - } else { - $facebook .= ''; - } - if ($this->book->parametres->facebook_description != '') { - $facebook .= ''; - } - $t = 'https://workshop.fluidbook.com/services/facebook_thumbnail?id=' . $this->book->book_id . '&j=' . time(); - $dim = getimagesize($t); - $facebook .= ''; - $facebook .= ''; - $facebook .= ''; - } - - $favicon = ''; - - if ($this->theme->parametres->favicon != '') { - $favicon = ''; - } - - $redirectPDF = 'redirectPDF();'; - if ($this->book->parametres->mobileVersion == 'pdf') { - $redirectMobile = $redirectPDF; - } else { - $redirectMobile = 'redirectMobile();'; - $this->prepareHTML5(); - } - - $seoVersion = true; - if (isset($this->book->parametres->seoVersion)) { - $seoVersion = $this->book->parametres->seoVersion; - } - - $seoRobot = true; - if (isset($this->book->parametres->seoRobots)) { - $seoRobot = $this->book->parametres->seoRobots; - } - - $robots = ''; - if (!$seoRobot) { - $robots = ''; - } - - $keywords = ''; - if ($this->book->parametres->seoKeywords) { - $keywords = ''; - } - - $alwaysHTML5 = $this->book->parametres->alwaysHTML5; - if (is_null($alwaysHTML5) || !$alwaysHTML5) { - $alwaysHTML5 = 'false'; - } - - if (!isset($this->book->parametres->html5priority)) { - $this->book->parametres->html5priority = 'true'; - } - $html5priority = $this->book->parametres->html5priority; - - - // Stuffs to replace in html - $toReplace = array('lang' => strtolower($this->book->lang), - 'ga' => $ga, - 'statsfooter' => $statsfooter, - 'facebook' => $facebook, - 'bgcolor' => $this->theme->parametres->loadingBackColor, - 'redirectMobile' => $redirectMobile, - 'redirectPDF' => $redirectPDF, - 'junk' => TIME, - 'robots' => $robots, - 'favicon' => $favicon, - 'flashversion' => $this->getMinFlashVersion(), - 'fv' => json_encode($this->getFlashvars()), - 'alwaysHTML5' => $alwaysHTML5, - 'keywords' => $keywords, - 'allowNetworking' => $this->_allowNeworking, - 'redirectIfFlashNotInstalled' => in_array($html5priority, array('true', 'notinstalled')) ? 'true' : 'false', - 'redirectIfFlashBlocked' => $html5priority == 'true' ? 'true' : 'false', - 'flash_blocked_wait' => $this->book->parametres->flashBlockedWait, - ); - - $this->origHTML = $this->book->parametres->htmlPrepend . file_get_contents($this->vdir . '/index.html'); - unlink($this->vdir . '/index.html'); - $this->origHTML = $this->replaceHTML($toReplace); - - $nav1 = $this->makeHTMLNav(true); - $nav = $this->makeHTMLNav(false); - $footer = $this->makeHTMLFooter(); - - fb(time(), 'end prepare constant parts of seo'); - - foreach ($this->pages as $page => $infos) { - $pathToIndex = 'index.swf'; - $pathToGetflash = 'getflash.gif'; - $redirectScript = ''; - if ($page == 1) { - $dest = 'index.' . $this->_ext; - $title = $this->book->parametres->title; - $sp = ''; - } else { - $label = $this->_getLabelOfPage($page); - $title = $label . ' - ' . $this->book->parametres->title; - $dest = 'pages/' . $page . '-' . mb_strtolower(cubeText::str2URL($label)) . '.' . $this->_ext; - $pathToIndex = '../index.swf'; - $pathToGetflash = '../getflash.gif'; - $sp = '../'; - $redirectScript = ''; - } - $alt = ''; + protected $origHTML; + protected $_labels = array(); + protected $_allowNeworking = 'all'; + protected $_ext = 'html'; + protected $_forceOnlyHtml = false; + protected $_disableScorm = true; + + public function __construct($book_id, $vdir = null, $whole = true) + { + parent::__construct($book_id, $vdir, $whole); + $this->version = 'html'; + } + + protected function getMinFlashVersion() + { + return '10.0.22'; + } + + protected function getSWFFiles() + { + return array('index.swf', 'player.swf'); + } + + protected function preparePackage() + { + parent::preparePackage(); + + if ($this->_forceOnlyHtml) { + $this->book->parametres->alwaysHTML5 = true; + } + if ($this->_disableScorm) { + $this->book->parametres->scorm_enable = false; + } + + if ($this->book->parametres->mobilefirstFluidbookId != '') { + $this->book->parametres->alwaysHTML5 = true; + } + + $this->_ext = $this->book->parametres->htmlExtension; + + if ($this->book->parametres->offlineExport && $this->book->parametres->pdfComplex) { + $versions = array('win-ins' => 'exe', 'mac-exe' => 'zip'); + foreach ($versions as $v => $ext) { + $a = wsPackager::package($this->book_id, $v); + rename(ROOT . $a, $this->vdir . '/data/document.' . $ext); + } + } + + $this->copyFluidbookFiles(); + $this->mergeJavascript(); + + $others = array('fluidbook.js', 'getflash.gif', 'index.html', 'style.css'); + $others = array_merge($others, $this->getSWFFiles()); + + $this->copyOtherFiles($others); + + if (!file_exists($this->vdir . '/pages')) { + mkdir($this->vdir . '/pages/', 0777, true); + } + + $ga = ''; + if ($this->book->parametres->googleAnalyticsCustom) { + $ga = $this->book->parametres->googleAnalyticsCustom; + } elseif ($this->book->parametres->googleAnalytics != '') { + $variables = array('Language' => array('value' => 'getLang()', 'valueAsJS' => true, 'scope' => 2)); + $ga = cubePage::googleAnalytics(explode(',', $this->book->parametres->googleAnalytics), true, $variables); + } + + $statsfooter = ''; + if ($this->book->parametres->statsCustom != '') { + $statsfooter = $this->book->parametres->statsCustom; + } + + $facebook = ''; + if ($this->book->parametres->facebook) { + if ($this->book->parametres->facebook_title != '') { + $facebook .= ''; + } else { + $facebook .= ''; + } + if ($this->book->parametres->facebook_description != '') { + $facebook .= ''; + } + $t = 'https://workshop.fluidbook.com/services/facebook_thumbnail?id=' . $this->book->book_id . '&j=' . time(); + $dim = getimagesize($t); + $facebook .= ''; + $facebook .= ''; + $facebook .= ''; + } + + $favicon = ''; + + if ($this->theme->parametres->favicon != '') { + $favicon = ''; + } + + $redirectPDF = 'redirectPDF();'; + if ($this->book->parametres->mobileVersion == 'pdf') { + $redirectMobile = $redirectPDF; + } else { + $redirectMobile = 'redirectMobile();'; + $this->prepareHTML5(); + } + + $seoVersion = true; + if (isset($this->book->parametres->seoVersion)) { + $seoVersion = $this->book->parametres->seoVersion; + } + + $seoRobot = true; + if (isset($this->book->parametres->seoRobots)) { + $seoRobot = $this->book->parametres->seoRobots; + } + + $robots = ''; + if (!$seoRobot) { + $robots = ''; + } + + $keywords = ''; + if ($this->book->parametres->seoKeywords) { + $keywords = ''; + } + + $alwaysHTML5 = $this->book->parametres->alwaysHTML5; + if (is_null($alwaysHTML5) || !$alwaysHTML5) { + $alwaysHTML5 = 'false'; + } + + if (!isset($this->book->parametres->html5priority)) { + $this->book->parametres->html5priority = 'true'; + } + $html5priority = $this->book->parametres->html5priority; + + + // Stuffs to replace in html + $toReplace = array('lang' => strtolower($this->book->lang), + 'ga' => $ga, + 'statsfooter' => $statsfooter, + 'facebook' => $facebook, + 'bgcolor' => $this->theme->parametres->loadingBackColor, + 'redirectMobile' => $redirectMobile, + 'redirectPDF' => $redirectPDF, + 'junk' => TIME, + 'robots' => $robots, + 'favicon' => $favicon, + 'flashversion' => $this->getMinFlashVersion(), + 'fv' => json_encode($this->getFlashvars()), + 'alwaysHTML5' => $alwaysHTML5, + 'keywords' => $keywords, + 'allowNetworking' => $this->_allowNeworking, + 'redirectIfFlashNotInstalled' => in_array($html5priority, array('true', 'notinstalled')) ? 'true' : 'false', + 'redirectIfFlashBlocked' => $html5priority == 'true' ? 'true' : 'false', + 'flash_blocked_wait' => $this->book->parametres->flashBlockedWait, + ); + + $this->origHTML = $this->book->parametres->htmlPrepend . file_get_contents($this->vdir . '/index.html'); + unlink($this->vdir . '/index.html'); + $this->origHTML = $this->replaceHTML($toReplace); + + $nav1 = $this->makeHTMLNav(true); + $nav = $this->makeHTMLNav(false); + $footer = $this->makeHTMLFooter(); + + fb(time(), 'end prepare constant parts of seo'); + + foreach ($this->pages as $page => $infos) { + $pathToIndex = 'index.swf'; + $pathToGetflash = 'getflash.gif'; + $redirectScript = ''; + if ($page == 1) { + $dest = 'index.' . $this->_ext; + $title = $this->book->parametres->title; + $sp = ''; + } else { + $label = $this->_getLabelOfPage($page); + $title = $label . ' - ' . $this->book->parametres->title; + $dest = 'pages/' . $page . '-' . mb_strtolower(cubeText::str2URL($label)) . '.' . $this->_ext; + $pathToIndex = '../index.swf'; + $pathToGetflash = '../getflash.gif'; + $sp = '../'; + $redirectScript = ''; + } + $alt = ''; // if ($seoVersion && CubeIT_Util_Gzip::file_exists($htmlfile)) { // $html = CubeIT_Util_Gzip::file_get_contents($htmlfile); @@ -195,251 +199,268 @@ class wsPackagerHTML extends wsPackager // } // } - $alt .= $footer; - - $base = ''; - if ($this->book->parametres->baseUrl) { - $base = ''; - } - - if ($page == 1 && $this->book->parametres->seoDescription) { - $description = $this->book->parametres->seoDescription; - } else { - $textfile = wsDocument::getDir($infos['document_id']) . 'ph' . $infos['document_page'] . '.txt'; - if (file_exists($textfile)) { - $description = mb_substr(file_get_contents($textfile), 0, 150); - } else { - $description = ''; - } - } - - $data = str_replace('$alt', $alt, $this->origHTML); - $data = str_replace('$base', $base, $data); - $data = str_replace('$pathToIndex', $pathToIndex, $data); - $data = str_replace('$title', $this->escape($title), $data); - $data = str_replace('$pathToGetflash', $pathToGetflash, $data); - $data = str_replace('$redirectScript', $redirectScript, $data); - $data = str_replace('$sp', $sp, $data); - $data = str_replace('$index_ext', $this->_ext, $data); - $data = str_replace('$description', '', $data); - - file_put_contents($this->vdir . $dest, $data); - - if (!$seoVersion) { - break; - } - } - fb(time(), 'end prepare seo'); - } - - protected function getFlashvars() - { - return array(); - } - - public function prepareHTML5() - { - fb(time(), 'start prepare html5'); - if (!$this->whole) { - return; - } - $this->daoBook->compile($this->book_id, 'html5', false, $this->book->parametres->forceCompileOnDownload, false, $this->book); - - $dest = $this->vdir . 'm'; - if (!file_exists($dest)) { - mkdir($dest, 0777, true); - } - - $cp = new cubeCommandLine('cp'); - $cp->setPath(CONVERTER_PATH); - $cp->setArg('r'); - $cp->setArg('p'); - $cp->setArg(null, WS_BOOKS . '/html5/' . $this->book_id . '/*'); - $cp->setArg(null, $dest); - $cp->execute(); - - $filesToAdd = array(); - if ($this->book->parametres->mobileServerConfig) { - $filesToAdd = array('.htaccess', 'web.config'); - } - foreach ($filesToAdd as $f) { - $this->copy(WS_COMPILE_ASSETS . '/_html5/' . $f, $dest . '/' . $f); - } - - $filesToDelete = array('indext.html', 'indexu.html'); - // if ($this->book->parametres->mobileVersion == 'html5') { - // $filesToDelete[] = 'data/background/*/t*.jpg'; - // $filesToDelete[] = 'data/background/contents/p*.html'; - // } else { - // $filesToDelete[] = 'data/background/*/p*.jpg'; - // $filesToDelete[] = 'data/contents/p*.svg'; - // } - $htmlFiles = array('index', 'widget'); - - foreach ($htmlFiles as $name) { - $html = $this->book->parametres->htmlPrepend . file_get_contents($dest . '/' . $name . '.html'); - file_put_contents($dest . '/' . $name . '.' . $this->_ext, $html); - if ($this->_ext != 'html') { - $filesToDelete[] = $name . '.html'; - } - } - - $rm = new cubeCommandLine('rm'); - $rm->setPath(CONVERTER_PATH); - foreach ($filesToDelete as $f) { - $rm->setArg(null, $dest . '/' . $f); - } - $rm->execute(); - fb(time(), 'end prepare html5'); - } - - public function makePackage($zip) - { - parent::makePackage($zip); - if ($zip) { - return $this->zip(); - } - return $this->getFinalPackageDir(); - } - - protected function makeHTMLNav($root) - { - $res = ''; - return $res; - } - - protected function _getLabelOfPage($page) - { - if (!isset($this->_chapters)) { - $this->_chapters = $this->book->chapters; - } - - - if (isset($this->_labels[$page])) { - return $this->_labels[$page]; - } - - - if ($page == 1) { - $this->_labels[1] = $this->book->parametres->title; - - return $this->_labels[1]; - } - - - $virtual = $this->_getVirtualPage($page); - - $candidates = array(); - foreach ($this->_chapters as $c) { - if ($c->page == $virtual) { - $candidates[] = $c; - } - } - if (!count($candidates)) { - $this->_labels[$page] = $this->_getLabelOfPage($page - 1); - return $this->_labels[$page]; - } - - usort($candidates, array($this, '_sortCandidates')); - $c = array_shift($candidates); - - $this->_labels[$page] = $c->label; - return $this->_labels[$page]; - } - - protected function _sortCandidates($a, $b) - { - if ($a->level > $b->level) { - return 1; - } else if ($a->level < $b->level) { - return -1; - } else { - return 0; - } - } - - protected function _getVirtualPage($page) - { - $num = explode(',', $this->book->numerotation); - if (isset($num[$page - 1])) { - return $num[$page - 1]; - } - return 1; - } - - protected function escape($txt, $replaceNewLines = false) - { - $res = htmlentities($txt, ENT_COMPAT, 'UTF-8'); - if ($replaceNewLines) { - $res = str_replace("\n", ' ', $res); - $res = str_replace("\r", '', $res); - } - return $res; - } - - protected function makeHTMLFooter() - { - $res = ''; - return $res; - } - - protected function replaceHTML($toReplace) - { - return $this->replaceContents($this->origHTML, $toReplace); - } - - protected function mergeJavascript() - { - $dest = WS_COMPILE_ASSETS . '/fluidbook.js'; - $orig = WS_COMPILE_ASSETS . '/_js/'; - $files = array('log4js.js' => false, 'esapi.js' => false, 'resources/i18n/ESAPI_Standard_en_US.properties.js' => false, 'resources/Base.esapi.properties.js' => false, 'swfobject.js' => false, 'swfaddress.js' => true, 'fluidbook.js' => true); - - $refresh = false; - if (file_exists($dest)) { - $mtime = filemtime($dest); - foreach ($files as $file => $min) { - if (filemtime($orig . $file) > $mtime) { - $refresh = true; - break; - } - } - } else { - $refresh = true; - } - if (!$refresh) { - return; - } - - $minjs = "\n\n"; - foreach ($files as $file => $min) { - $c = file_get_contents($orig . $file); - if ($min) { - $c = JSMin::minify($c); - } - - $minjs .= $c . "\n\n"; - } - file_put_contents($dest, $minjs); - } + $alt .= $footer; + + $base = ''; + if ($this->book->parametres->baseUrl) { + $base = ''; + } + + if ($page == 1 && $this->book->parametres->seoDescription) { + $description = $this->book->parametres->seoDescription; + } else { + $textfile = wsDocument::getDir($infos['document_id']) . 'ph' . $infos['document_page'] . '.txt'; + if (file_exists($textfile)) { + $description = mb_substr(file_get_contents($textfile), 0, 150); + } else { + $description = ''; + } + } + + $data = str_replace('$alt', $alt, $this->origHTML); + $data = str_replace('$base', $base, $data); + $data = str_replace('$pathToIndex', $pathToIndex, $data); + $data = str_replace('$title', $this->escape($title), $data); + $data = str_replace('$pathToGetflash', $pathToGetflash, $data); + $data = str_replace('$redirectScript', $redirectScript, $data); + $data = str_replace('$sp', $sp, $data); + $data = str_replace('$index_ext', $this->_ext, $data); + $data = str_replace('$description', '', $data); + + file_put_contents($this->vdir . $dest, $data); + + if (!$seoVersion) { + break; + } + } + fb(time(), 'end prepare seo'); + } + + protected function getFlashvars() + { + return array(); + } + + public function prepareHTML5() + { + fb(time(), 'start prepare html5'); + if (!$this->whole) { + return; + } + $dest = $this->vdir . 'm'; + $this->_compileHTML5($this->book_id, $this->book, $dest); + + try { + $mfid = $this->book->parametres->mobilefirstFluidbookId; + if ($mfid != '' && (int)$mfid > 0) { + $mfbook = $this->daoBook->selectById($mfid); + $dest .= '/mf'; + $this->_compileHTML5($mfid, $mfbook, $dest); + } + } catch (Exception $e) { + die($e->getMessage()); + } + + fb(time(), 'end prepare html5'); + } + + protected function _compileHTML5($bookId, $book, $dest) + { + $this->daoBook->compile($bookId, 'html5', false, $book->parametres->forceCompileOnDownload, false, $book); + + if (!file_exists($dest)) { + mkdir($dest, 0777, true); + } + + $cp = new cubeCommandLine('cp'); + $cp->setPath(CONVERTER_PATH); + $cp->setArg('r'); + $cp->setArg('p'); + $cp->setArg(null, WS_BOOKS . '/html5/' . $bookId . '/*'); + $cp->setArg(null, $dest); + $cp->execute(); + + $filesToAdd = array(); + if ($book->parametres->mobileServerConfig) { + $filesToAdd = array('.htaccess', 'web.config'); + } + foreach ($filesToAdd as $f) { + $this->copy(WS_COMPILE_ASSETS . '/_html5/' . $f, $dest . '/' . $f); + } + + $filesToDelete = array('indext.html', 'indexu.html'); + // if ($book->parametres->mobileVersion == 'html5') { + // $filesToDelete[] = 'data/background/*/t*.jpg'; + // $filesToDelete[] = 'data/background/contents/p*.html'; + // } else { + // $filesToDelete[] = 'data/background/*/p*.jpg'; + // $filesToDelete[] = 'data/contents/p*.svg'; + // } + $htmlFiles = array('index', 'widget'); + + foreach ($htmlFiles as $name) { + $html = $book->parametres->htmlPrepend . file_get_contents($dest . '/' . $name . '.html'); + file_put_contents($dest . '/' . $name . '.' . $this->_ext, $html); + if ($this->_ext != 'html') { + $filesToDelete[] = $name . '.html'; + } + } + + $rm = new cubeCommandLine('rm'); + $rm->setPath(CONVERTER_PATH); + foreach ($filesToDelete as $f) { + $rm->setArg(null, $dest . '/' . $f); + } + $rm->execute(); + } + + public function makePackage($zip) + { + parent::makePackage($zip); + if ($zip) { + return $this->zip(); + } + return $this->getFinalPackageDir(); + } + + protected function makeHTMLNav($root) + { + $res = ''; + return $res; + } + + protected function _getLabelOfPage($page) + { + if (!isset($this->_chapters)) { + $this->_chapters = $this->book->chapters; + } + + + if (isset($this->_labels[$page])) { + return $this->_labels[$page]; + } + + + if ($page == 1) { + $this->_labels[1] = $this->book->parametres->title; + + return $this->_labels[1]; + } + + + $virtual = $this->_getVirtualPage($page); + + $candidates = array(); + foreach ($this->_chapters as $c) { + if ($c->page == $virtual) { + $candidates[] = $c; + } + } + if (!count($candidates)) { + $this->_labels[$page] = $this->_getLabelOfPage($page - 1); + return $this->_labels[$page]; + } + + usort($candidates, array($this, '_sortCandidates')); + $c = array_shift($candidates); + + $this->_labels[$page] = $c->label; + return $this->_labels[$page]; + } + + protected function _sortCandidates($a, $b) + { + if ($a->level > $b->level) { + return 1; + } else if ($a->level < $b->level) { + return -1; + } else { + return 0; + } + } + + protected function _getVirtualPage($page) + { + $num = explode(',', $this->book->numerotation); + if (isset($num[$page - 1])) { + return $num[$page - 1]; + } + return 1; + } + + protected function escape($txt, $replaceNewLines = false) + { + $res = htmlentities($txt, ENT_COMPAT, 'UTF-8'); + if ($replaceNewLines) { + $res = str_replace("\n", ' ', $res); + $res = str_replace("\r", '', $res); + } + return $res; + } + + protected function makeHTMLFooter() + { + $res = ''; + return $res; + } + + protected function replaceHTML($toReplace) + { + return $this->replaceContents($this->origHTML, $toReplace); + } + + protected function mergeJavascript() + { + $dest = WS_COMPILE_ASSETS . '/fluidbook.js'; + $orig = WS_COMPILE_ASSETS . '/_js/'; + $files = array('log4js.js' => false, 'esapi.js' => false, 'resources/i18n/ESAPI_Standard_en_US.properties.js' => false, 'resources/Base.esapi.properties.js' => false, 'swfobject.js' => false, 'swfaddress.js' => true, 'fluidbook.js' => true); + + $refresh = false; + if (file_exists($dest)) { + $mtime = filemtime($dest); + foreach ($files as $file => $min) { + if (filemtime($orig . $file) > $mtime) { + $refresh = true; + break; + } + } + } else { + $refresh = true; + } + if (!$refresh) { + return; + } + + $minjs = "\n\n"; + foreach ($files as $file => $min) { + $c = file_get_contents($orig . $file); + if ($min) { + $c = JSMin::minify($c); + } + + $minjs .= $c . "\n\n"; + } + file_put_contents($dest, $minjs); + } } diff --git a/inc/ws/Util/packager/class.ws.packager.html5.php b/inc/ws/Util/packager/class.ws.packager.html5.php deleted file mode 100644 index a2d62d711..000000000 --- a/inc/ws/Util/packager/class.ws.packager.html5.php +++ /dev/null @@ -1,577 +0,0 @@ -version = 'html5'; - } - - protected function preparePackage() { - parent::preparePackage(); - - foreach ($this->pages as $page => $infos) { - $file = wsDocument::getDir($infos['document_id']) . 'html/p' . $infos['document_page'] . '.layout'; - if (file_exists($file)) { - $this->layouts[$page] = simplexml_load_file($file, null, LIBXML_ERR_WARNING); - } - } - - $imagesize = getimagesize(wsDocument::getDir($this->pages[1]['document_id']) . 'html/h72-' . $this->pages[1]['document_page'] . '.jpg'); - $this->pdf2htmlRatio = $imagesize[0] / $this->layouts[1]['width']; - $this->scale = 4; - $this->multiply = $this->pdf2htmlRatio * $this->scale; - - $this->createHTML(); - } - - public function makePackage() { - parent::makePackage(); - return $this->zip(); - } - - protected function createHTML() { - foreach ($this->layouts as $page => $layout) { - $this->div[$page] = array(); - $document_id = $this->pages[$page]['document_id']; - foreach ($layout->l as $line) { - $this->div[$page][] = $this->addLine($line, $document_id); - } - } - mkdir($this->vdir . '/data/images', 0777, true); - mkdir($this->vdir . '/data/contents', 0777, true); - mkdir($this->vdir . '/data/background', 0777, true); - mkdir($this->vdir . '/data/style', 0777, true); - - foreach ($this->div as $n => $page) { - file_put_contents($this->vdir . '/data/contents/p' . $n . '.html', $this->writePage($page)); - } - $this->writeFonts(); - $this->writeImages(); - $this->writeLinks(); - $this->writeCSS($this->vdir . '/data/style/style_%d.css'); - - file_put_contents($this->vdir . '/data/datas.js', $this->writeConfig()); - } - - protected function writeLinks() { - global $core; - $daoDoc = new wsDAODocument($core->con); - $daoDoc->getLinksAndRulers($this->book_id, $links, $rulers); - - foreach ($links as $link) { - fb($link); - } - } - - protected function writeConfig() { - $config = cubeObject::merge($this->book->parametres->toStandardObject(), $this->theme->parametres->toStandardObject()); - $config->id = $this->book->book_id; - return 'DATAS=' . json_encode($config) . ';'; - } - - protected function writeFonts() { - $fext = array('ttf', 'eot', 'svg', 'svgz', 'woff'); - foreach ($this->cssFont as $font => $index) { - list($font, $document_id) = explode('//', $font); - foreach ($fext as $ext) { - copy(wsDocument::getDir($document_id) . "fonts/web/" . $font . '.' . $ext, $this->vdir . '/data/style/F' . $index . '.' . $ext); - } - } - } - - protected function writeIcons() { - $res = array(); - // Get the colors used to colorize graphics - if ($this->theme->parametres->colorizeIcons) { - $couleurI = '#' . $this->theme->parametres->couleurI; - } else { - $couleurI = '#FFFFFF'; - } - $arrowsColor = '#' . $this->theme->parametres->arrowsColor; - // Set the icon list with the color - $icons = array('nav-bookmark' => $couleurI, 'nav-friend' => $couleurI, 'nav-help' => $couleurI, 'nav-index' => $couleurI, 'nav-sommaire' => $couleurI, - 'next' => $arrowsColor, 'previous' => $arrowsColor, 'search' => $couleurI); - - foreach ($icons as $icon => $color) { - wsTools::colorizeAndRasterizeIcon($this->theme->parametres->iconSet, $icon, $color, $this->vdir . '/data/images/', $w, $h); - $res[] = '#icon-' . $icon . '{width:' . $w . 'px;height:' . $h . 'px;background-image:url(data/images/' . $icon . '.svg), url(data/images/' . $icon . '.png);background-repeat:no-repeat;background-size:' . $w . 'px ' . $h . 'px}'; - } - return $res; - } - - protected function writeImages() { - - foreach (self::$resolutions as $r) { - mkdir($this->vdir . '/data/background/' . $r, 0777); - } - foreach ($this->pages as $page => $infos) { - foreach (self::$resolutions as $r) { - copy(wsDocument::getDir($infos['document_id']) . 'html/h' . $r . '-' . $infos['document_page'] . '.jpg', $this->vdir . '/data/background/' . $r . '/p' . $page . '.jpg'); - } - } - } - - protected function writePage($page) { - $res = ''; - foreach ($page as $line) { - $res .= $this->writeLine($line); - } - return $res; - } - - protected function writeLine($line) { - $line['x'] = $this->getCSSX($line['x'] * $this->multiply); - $line['y'] = $this->getCSSY($line['y'] * $this->multiply); - - $class = array('l'); - if (!is_null($line['rotation'])) { - $class[] = 'r' . $line['rotation']; - } - if (!is_null($line['x'])) { - $class[] = 'x' . $line['x']; - } - if (!is_null($line['y'])) { - $class[] = 'y' . $line['y']; - } - $class = implode(' ', $class); - - - $res = '
'; - foreach ($line['groups'] as $group) { - $res .= $this->writeGroup($group); - } - $res .= '
'; - return $res; - } - - protected function writeGroup($group) { - if ($group === false) { - return ''; - } - - $group['y'] = $this->getCSSY($group['y'] * $this->multiply); - $group['x'] = $this->getCSSX($group['x'] * $this->multiply); - - $class = array('g'); - if (!is_null($group['color'])) { - $class[] = 'c' . $group['color']; - } - if (!is_null($group['size'])) { - $class[] = 's' . $group['size']; - } - if (!is_null($group['font'])) { - $class[] = 'f' . $group['font']; - } - if (!is_null($group['x'])) { - $class[] = 'x' . $group['x']; - } - if (!is_null($group['y'])) { - $class[] = 'y' . $group['y']; - } - if (!is_null($group['letterspacing'])) { - $class[] = 'l' . $group['letterspacing']; - } - if (!is_null($group['wordspacing'])) { - $class[] = 'w' . $group['wordspacing']; - } - $class = implode(' ', $class); - - $res = '
'; - foreach ($group['spans'] as $span) { - $res .= $this->writeSpan($span); - } - $res .= '
'; - return $res; - } - - protected function writeSpan($span) { - if ($span === false) { - return ''; - } - - return self::escapeHTML($span['text']); - } - - protected function writeCSS($file) { - $res = array(); - - // General theme - $h = $this->book->parametres->height . 'px'; - $w2 = ($this->book->parametres->width * 2) . 'px'; - $w = $this->book->parametres->width . 'px'; - $wm = ($this->book->parametres->width * $this->multiply) . 'px'; - $hm = ($this->book->parametres->height * $this->multiply) . 'px'; - - - $navTop = ($this->book->parametres->height - 40 - 100) / 2; - $res[] = '.portrait #pages,.portrait .doublePage.page,.page,.portrait #shadow,#shadow.single{width:' . $w . ';max-width:' . $w . ';height:' . $h . ';max-height:' . $h . '}'; - $res[] = '.background{' . $this->writeCSSUA('transform-origin', 'top left') . ';}'; - foreach (self::$resolutions as $r) { - $ratio = 72 / $r; - $wr = $this->book->parametres->width / $ratio; - $hr = $this->book->parametres->height / $ratio; - - $br = '.background.r' . $r . '{'; - if ($ratio != 1) { - $br .= $this->writeCSSUA('transform', 'scale(' . $ratio . ')') . ';'; - } - $br .= 'width:' . $wr . 'px;height:' . $hr . 'px;}'; - $res[] = $br; - } - $res[] = '.doublePage,#pages,.landscape #shadow.double{width:' . $w2 . ';max-width:' . $w2 . ';height:' . $h . ';max-height:' . $h . '}'; - $res[] = '.landscape #shadow.single.right{left: ' . $w . ';}'; - $res[] = '.landscape .page.right{left:' . $w . '}'; - $texts = '.texts{' . $this->writeCSSUA('transform-origin', 'top left') . ';'; - $texts .= $this->writeCSSUA('transform', 'scale(' . (1 / $this->multiply) . ')') . ';'; - $texts .= 'width:' . $wm . '; max-width:' . $wm . ';'; - $texts .= 'height:' . $hm . '; max-height:' . $hm . ';'; - $texts .= '}'; - $res[] = $texts; - - // Theme - // Background - $body = '#main{'; - $body .= 'background-color:#' . $this->theme->parametres->backgroundColor . ';'; - 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;'; - break; - case wsTheme::STRETCH: - $body .= 'background-repeat:no-repeat;'; - $body .= 'background-size:100% 100%;'; - break; - } - if ($this->theme->parametres->backgroundImage != '') { - copy($this->themeRoot . '/' . $this->theme->parametres->backgroundImage, $this->vdir . '/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 .= '}'; - $res[] = $body; - - // Header - $header = '#header{'; - $header .= 'height:' . $this->theme->parametres->menuHeight . 'px;'; - $header .= 'background-color:' . self::colorToCSS($this->theme->parametres->menuColor) . ';'; - if ($this->theme->parametres->menuImage != '') { - copy($this->themeRoot . '/' . $this->theme->parametres->menuImage, $this->vdir . '/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;'; - } - $header .= '}'; - $res[] = $header; - - //Icons - $res = array_merge($res, $this->writeIcons()); - - // Logo - $logo = '#logo{'; - if ($this->theme->parametres->logo) { - copy($this->themeRoot . '/' . $this->theme->parametres->logo, $this->vdir . '/data/images/' . $this->theme->parametres->logo); - $dim = getimagesize($this->vdir . '/data/images/' . $this->theme->parametres->logo); - $logo .= 'background-image:url(../images/' . $this->theme->parametres->logo . ');width:' . $dim[0] . 'px;height:' . $dim[1] . 'px;'; - } - $logo .= '}'; - $res[] = $logo; - - // Credits - $res[] = '#credits,#credits a{color:' . self::colorToCSS($this->theme->parametres->creditsColor) . ';}'; - - // Arrows - $res[] = '#next,#previous{background-color:' . self::colorToCSS($this->theme->parametres->couleurA) . ';}'; - // Book shadow - $shadowColor = self::colorToCSS($this->theme->parametres->bookShadeColor); - if ($shadowColor != 'transparent') { - $res[] = '#shadow{' . $this->writeCSSUA('box-shadow', '0 0 20px ' . $shadowColor) . '}'; - } - - // Pages styles - foreach ($this->cssColor as $color => $index) { - $res[] = '.c' . $index . '{color:#' . $color . '}'; - } - - foreach ($this->cssSize as $size => $index) { - $res[] = '.s' . $index . '{font-size:' . $size . 'px}'; - } - - foreach ($this->cssLetterSpacing as $letterspacing => $index) { - $res[] = '.l' . $index . '{letter-spacing:' . $letterspacing . 'em}'; - } - - foreach ($this->cssWordSpacing as $wordspacing => $index) { - $res[] = '.w' . $index . '{word-spacing:' . $wordspacing . 'em}'; - } - - foreach ($this->cssX as $x => $index) { - $res[] = '.x' . $index . '{left:' . $x . 'px}'; - } - - foreach ($this->cssY as $y => $index) { - $res[] = '.y' . $index . '{top:' . $y . 'px}'; - } - - foreach ($this->cssRotation as $rotation => $index) { - $rotation *= -1; - - - $to = 'transform-origin:left top;'; - - $css = '.r' . $index . '{'; - $css .= self::writeCSSUA('transform', 'rotate(' . $rotation . 'deg)') . ';'; - $css .= self::writeCSSUA('transform-origin', 'left top'); - $css .= '}'; - $res[] = $css; - } - - foreach ($this->cssFont as $font => $index) { - list($font, $document_id) = explode('//', $font); - $res[] = "@font-face{font-family:F" . $index . ";src:url('F" . $index . ".eot');src:url('F" . $index . ".eot?#iefix') format('eot'),url('F" . $index . ".ttf') format('truetype'),url('F" . $index . ".svgz#" . $font . "') format('svgz'),url('F" . $index . ".svg#" . $font . "') format('svg')}"; - $res[] = '.f' . $index . '{font-family:F' . $index . ',Arial,Helvetica}'; - } - - $res = array_chunk($res, 4000); - foreach ($res as $k => $css) { - file_put_contents(sprintf($file, $k), implode("\n", $css)); - } - } - - protected function writeCSSUA($property, $value) { - $res = array(); - foreach (self::$uaPrefixes as $prefix) { - $res[] = $prefix . $property . ':' . $value; - } - return implode(';', $res); - } - - protected function addLine($line, $document_id) { - $res = array(); - foreach ($line->a as $group) { - $res[] = $this->addGroup($group, $document_id); - } - return array('x' => $this->normalizeFloatValue($line['x']), - 'y' => $this->normalizeFloatValue($line['y']), - 'rotation' => $this->getCSSRotation($this->normalizeFloatValue($line['rotation'], 0)), - "groups" => $res); - } - - protected function addGroup($group, $document_id) { - $alpha = intval(substr($group['color'], 1, 2), 16); - if ($alpha == 0) { - return false; - } - - $res = array(); - - $first = true; - foreach ($group->s as $span) { - if ($first) { - $x = $span['x']; - $first = false; - } - $newSpan = $this->addSpan($span, $document_id); - - array_push($res, $newSpan); - } - - return array( - 'color' => $this->getCSSColor($group['color']), - 'size' => $this->getCSSSize($group['size']), - 'font' => $this->getCSSFont($group['font'], $document_id), - 'letterspacing' => $this->getCSSLetterSpacing($group['letterspacing']), - 'wordspacing' => $this->getCSSWordSpacing($group['wordspacing']), - 'y' => ($group['size']) / -1.2, - 'x' => $x, - 'spans' => $res); - } - - protected function addSpan($span, $document_id) { - - $text = (string)$span; - if ($text == '') { - return false; - } - return array('text' => $text); - } - - protected function getCSSSize(&$size) { - $size = $this->normalizeFloatValue($size * $this->multiply, 3); - $sizer = $size; - return $this->getIndex($sizer, $this->cssSize); - } - - protected function getCSSFont($font, $document_id) { - return $this->getIndex($font . "//" . $document_id, $this->cssFont); - } - - protected function getCSSColor($color) { - $color = trim($color, '#'); - if (strlen($color) > 6) { - $color = substr($color, 2, 6); - } - if ($color == '000000') { - return null; - } - return $this->getIndex($color, $this->cssColor); - } - - protected function getCSSLetterSpacing($letterspacing) { - - $letterspacing = $this->normalizeFloatValue($letterspacing, 5); - - if ($letterspacing == 0) { - return null; - } - return $this->getIndex($letterspacing, $this->cssLetterSpacing); - } - - protected function getCSSWordSpacing($wordspacing) { - $wordspacing = $this->normalizeFloatValue($wordspacing, 5); - - if ($wordspacing == 0) { - return null; - } - return $this->getIndex($wordspacing, $this->cssWordSpacing); - } - - protected function getCSSRotation($rotation) { - $rotation = $this->normalizeFloatValue($rotation, 0); - if ($rotation == 0) { - return null; - } - return $this->getIndex($rotation, $this->cssRotation); - } - - protected function getCSSX($x) { - $x = round($x); - if ($x == 0) { - return null; - } - return $this->getIndex($x, $this->cssX); - } - - protected function getCSSY($y) { - $y = round($y); - if ($y == 0) { - return null; - } - return $this->getIndex($y, $this->cssY); - } - - protected function getIndex($value, &$tab) { - $value = (string)$value; - if (isset($tab[$value])) { - return $tab[$value]; - } - $res = $this->base62(count($tab)); - $tab[$value] = $res; - return $res; - } - - protected function normalizeFloatValue($value, $round = 3) { - $value = str_replace(',', '.', $value); - $value = (float)$value; - $value = round($value, $round); - return $value; - } - - 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 static function escapeHTML($in) { - $in = htmlentities($in, ENT_NOQUOTES, "UTF-8"); - $in = str_replace(' ', '', $in); - - return $in; - } - - public function __destruct() { - - } - - public static function colorToCSS($color) { - if (strlen($color) == 6) { - return '#' . $color; - } else { - $alpha = substr($color, 0, 2); - $red = substr($color, 2, 2); - $green = substr($color, 4, 2); - $blue = substr($color, 6, 2); - - $components = array('alpha', 'red', 'green', 'blue'); - foreach ($components as $k => $name) { - $hex = substr($color, $k * 2, 2); - $$name = intval($hex, 16); - } - $alpha /= 255; - if ($alpha == 0) { - return 'transparent'; - } elseif ($alpha == 1) { - return '#' . substr($color, 2, 6); - } - return 'rgba(' . $red . ',' . $green . ',' . $blue . ',' . $alpha . ')'; - } - } - -} diff --git a/inc/ws/Util/packager/html5/class.ws.packager.html5.links.php b/inc/ws/Util/packager/html5/class.ws.packager.html5.links.php deleted file mode 100644 index 4aadb1087..000000000 --- a/inc/ws/Util/packager/html5/class.ws.packager.html5.links.php +++ /dev/null @@ -1,333 +0,0 @@ - $v) { - $this->$k = $v; - } - $this->id = $id; - $this->packager = $packager; - } - - public function getHTMLContainer() { - return ''; - } - - public function getHTMLContent() { - return ''; - } - - public function copyExternalFile($file, $video = false) { - $this->packager->copyLinkFile($file, 'data/links/', $video); - } - - public function getCSSContainer() { - $css = '#link' . $this->id . '{'; - $css .= 'left:' . $this->left . 'px;top:' . $this->top . 'px;'; - $css .= 'width:' . $this->width . 'px;height:' . $this->height . 'px;'; - $css .= $this->getCSS(); - $css .= '}'; - return $css; - } - - public function getCSS() { - return ''; - } - - public static function getUniversalLocation($loc, $css = false) { - $datas = parse_url($loc); - - if (isset($datas['scheme']) && !is_null($datas['scheme'])) { - return $loc; - } else { - if ($css) { - return '../links/' . $loc; - } else { - return 'data/links/' . $loc; - } - } - } - -} - -class normalLink extends wsPackagerHTML5Link { - - public function getHTMLContent() { - $class = array(); - if ($this->display_area) { - $class[] = 'displayArea'; - } - $c = ''; - if (count($class)) { - $c = ' class="' . implode(' ', $class) . '"'; - } - return ''; - } - - public function getURL() { - return '#'; - } - - public function getTarget() { - return '_self'; - } - -} - -class contentLink extends wsPackagerHTML5Link { - -} - -class webLink extends normalLink { - - public function getURL() { - return wsPackagerHTML5Link::getUniversalLocation($this->to); - } - - public function getTarget() { - return $this->target; - } - - public function getCSS() { - - } - -} - -class mailLink extends normalLink { - - public function getURL() { - return 'mailto:' . $this->to; - } - - public function getTarget() { - return '_self'; - } - -} - -class internalLink extends normalLink { - - public function getURL() { - return '#/page/' . $this->getPage(); - } - - public function getPage() { - if ($this->numerotation == 'physical') { - return $this->to; - } else { - return $this->packager->virtualToPhysical($this->to); - } - } - -} - -class videoLink extends wsPackagerHTML5Link { - - public function getHTMLContent() { - $file = $this->to; - $e = explode('.', $file); - $ext = array_pop($e); - $basename = implode('.', $e); - $w = round($this->width); - $h = round($this->height); - - $res = ''; - return $res; - } - -} - -class webVideoLink extends videoLink { - - public function getHTMLContent() { - return $this->getEmbed(); - } - - public function getEmbed() { - return ''; - } - - public function getEmbedURL() { - if ($this->video_service == 0) { - $url = 'https://www.youtube.com/embed/' . $this->to . '?html5=1'; - } else { - $url = 'https://www.dailymotion.com/embed/video/' . $this->to; - } - return $url; - } - -} - -class actionLink extends internalLink { - - public function getURL() { - return '#' . $to; - } - -} - -class basketLink extends wsPackagerHTML5Link { - -} - -class colorLink extends contentLink { - - public function getCSS() { - return 'background-color:' . wsPackagerHTML5::colorToCSS($this->to) . ';'; - } - -} - -class imageLink extends contentLink { - - public function getCSS() { - $this->copyExternalFile($this->to); - return 'background-image:url(' . wsPackagerHTML5Link::getUniversalLocation($this->to, true) . ');background-size:100% 100%;background-repeat:no-repeat;'; - } - -} - -class fileLink extends normalLink { - - public function getURL() { - $this->copyExternalFile($this->to); - return wsPackagerHTML5Link::getUniversalLocation($this->to); - } - - public function getTarget() { - return '_blank'; - } - -} - -class multimediaLink extends wsPackagerHTML5Link { - - public function getHTMLContent() { - return cubeMedia::flashObject(wsPackagerHTML5Link::getUniversalLocation($this->to), $this->width, $this->height, array(), '', '', 9, '#ffffff', '', 'true', 'noscale', 'transparent'); - } - -} - -class videoPopupLink extends normalLink { - - public function getURL() { - $this->copyExternalFile($this->to, true); - return '#/video/' . $this->to; - } - -} - -class webVideoPopupLink extends videoPopupLink { - - public function getURL() { - if ($this->video_service == 0) { - $service = 'youtube'; - } elseif ($this->video_service == 1) { - $service = 'dailymotion'; - } - return '#/webvideo/' . $service . '/' . $this->to; - } - -} - -?> diff --git a/inc/ws/Util/packager/html5/class.ws.packager.html5.php b/inc/ws/Util/packager/html5/class.ws.packager.html5.php deleted file mode 100644 index c0de0aafe..000000000 --- a/inc/ws/Util/packager/html5/class.ws.packager.html5.php +++ /dev/null @@ -1,903 +0,0 @@ -version = 'html5'; - } - - protected function preparePackage() { - parent::preparePackage(); - - foreach ($this->pages as $page => $infos) { - $file = wsDocument::getDir($infos['document_id']) . 'html/p' . $infos['document_page'] . '.layout'; - if (file_exists($file)) { - $this->layouts[$page] = simplexml_load_file($file, null, LIBXML_ERR_WARNING); - } - } - - $imagesize = getimagesize(wsDocument::getDir($this->pages[1]['document_id']) . 'html/h72-' . $this->pages[1]['document_page'] . '.jpg'); - $this->pdf2htmlRatio = round($imagesize[0] / $this->layouts[1]['width'], 2); - $this->scale = 4; - $this->multiply = $this->pdf2htmlRatio * $this->scale; - $this->numerotation = explode(',', $this->book->numerotation); - - $this->createHTML(); - } - - public function makePackage() { - parent::makePackage(); - return $this->zip(); - } - - public function virtualToPhysical($virtual) { - if (!in_array($virtual, $this->numerotation)) { - return 1; - } - $p = array_search($virtual, $this->numerotation); - return $p + 1; - } - - protected function compareLines($a, $b) { - if ((float)$a['y'] > (float)$b['y']) { - return 1; - } else { - return -1; - } - } - - protected function createHTML() { - foreach ($this->layouts as $page => $layout) { - $this->div[$page] = array(); - $document_id = $this->pages[$page]['document_id']; - $lines = array(); - foreach ($layout->l as $line) { - $lines[] = $line; - } - usort($lines, array($this, 'compareLines')); - - foreach ($lines as $line) { - $this->div[$page][] = $this->addLine($line, $document_id); - } - } - mkdir($this->vdir . '/data/images', 0777, true); - mkdir($this->vdir . '/data/contents', 0777, true); - mkdir($this->vdir . '/data/background', 0777, true); - mkdir($this->vdir . '/data/thumbnails', 0777, true); - mkdir($this->vdir . '/data/style', 0777, true); - mkdir($this->vdir . '/data/links/pages', 0777, true); - mkdir($this->vdir . '/data/l10n/', 0777, true); - mkdir($this->vdir . '/swf', 0777, true); - - // Copy style folder - $from = WS_COMPILE_ASSETS . '/_html5/style'; - $to = $this->vdir; - `cp -r $from $to`; - - // Copy images folder - $from = WS_COMPILE_ASSETS . '/_html5/images'; - `cp -r $from $to`; - - // Copy swf - copy(WS_COMPILE_ASSETS . '/_html5/swf/video.swf', $this->vdir . '/swf/video.swf'); - - foreach ($this->div as $n => $page) { - file_put_contents($this->vdir . '/data/contents/p' . $n . '.html', $this->writePage($page)); - } - $this->writeFonts(); - $this->writeImages(); - $linksCSS = $this->writeLinks(); - $numCSS = $this->writeCSS($this->vdir . '/data/style/style_%d.css', $linksCSS); - $this->writeLangs(); - $this->writeJs(); - $this->writeIndex($numCSS); - } - - protected function writeIndex($numCSS) { - $html = file_get_contents(WS_COMPILE_ASSETS . '/_html5/_index.html'); - - $titre = $this->book->parametres->title; - $credits = ''; - // Google analytics - $ga = ''; - if ($this->book->parametres->googleAnalytics != '') { - $ga = cubePage::googleAnalytics($this->book->parametres->googleAnalytics); - } - // Feuilles de style - $sheets = array('style/fluidbook.css'); - for ($i = 0; $i < $numCSS; $i++) { - $sheets[] = 'data/style/style_' . $i . '.css'; - } - $style = array(); - foreach ($sheets as $sheet) { - $style[] = ''; - } - $style = implode("\n\t\t", $style); - - $vars = array('titre', 'credits', 'ga', 'style'); - foreach ($vars as $v) { - $html = str_replace('', $$v, $html); - } - file_put_contents($this->vdir . '/index.html', $html); - } - - protected function writeLangs() { - global $core; - $daoLang = new wsDAOLang($core->con); - $lang = $daoLang->selectById($this->book->lang); - $langs = $daoLang->selectAll(); - - - $traductions = (!count($this->book->traductions)) ? $lang->traductions : $this->book->traductions; - file_put_contents($this->vdir . '/data/l10n/default.json', json_encode($traductions)); - foreach ($langs as $lang) { - file_put_contents($this->vdir . '/data/l10n/' . $lang->lang_id . '.json', json_encode($lang->traductions)); - } - } - - protected function writeLinks() { - global $core; - $daoDoc = new wsDAODocument($core->con); - $daoDoc->getLinksAndRulers($this->book_id, $links, $rulers); - - $i = 0; - $pages = array(); - $css = array(); - foreach ($links as $linkData) { - $link = wsPackagerHTML5Link::getInstance($this->base62($i), $linkData, $this); - if (is_null($link)) { - continue; - } - if (!isset($pages[$link->page])) { - $pages[$link->page] = ''; - } - $pages[$link->page] .= $link->getHTMLContainer(); - $css[] = $link->getCSSContainer(); - $i++; - } - - for ($i = 0; $i <= $this->book->parametres->pages + 1; $i++) { - $c = ''; - if (isset($pages[$i])) { - $c = $pages[$i]; - } - file_put_contents($this->vdir . 'data/links/pages/p' . $i . '.html', $c); - } - return $css; - } - - protected function writeJs() { - $files = array('js/libs/modernizr.js', - 'js/libs/jquery/jquery.js', - 'js/libs/jquery/jquery.transform.js', - 'js/libs/jquery/jquery.mousewheel.js', - 'js/libs/jquery/jquery.hashchange.js', - 'js/libs/fluidbook/fluidbook.utils.js', - 'js/libs/fluidbook/fluidbook.cache.js', - 'js/libs/fluidbook/fluidbook.support.js', - 'js/libs/fluidbook/fluidbook.viewport.js', - 'js/libs/fluidbook/fluidbook.desktop.js', - 'js/libs/fluidbook/fluidbook.service.js', - 'js/libs/fluidbook/fluidbook.loader.js', - 'js/libs/fluidbook/fluidbook.l10n.js', - 'js/libs/fluidbook/fluidbook.nav.js', - 'js/libs/fluidbook/fluidbook.js', - 'js/main.js'); - - $mintime = 0; - $minimized = WS_COMPILE_ASSETS . '/_html5/js/min.js'; - if (file_exists($minimized)) { - $mintime = filemtime($minimized); - } - $reminimize = false; - foreach ($files as $file) { - if (filemtime(WS_COMPILE_ASSETS . '/_html5/' . $file) > $mintime) { - $reminimize = true; - break; - } - } - - if ($reminimize) { - $js = ''; - foreach ($files as $file) { - $js .= file_get_contents(WS_COMPILE_ASSETS . '/_html5/' . $file); - $js .= "\n\n"; - } - $tmp = cubeFiles::tempnam(); - file_put_contents($tmp, $js); - - $compressor = new cubeCommandLine('yuicompressor'); - $compressor->setPath(CONVERTER_PATH); - $compressor->setArg('charset', 'UTF-8'); - $compressor->setArg('type', 'js'); - $compressor->setArg('line-break', 1024); - $compressor->setArg('o', $minimized); - $compressor->setArg(null, $tmp); - $compressor->execute(); - } - - $js = $this->writeConfig(); - $js .= file_get_contents($minimized); - file_put_contents($this->vdir . '/data/fluidbook.js', $js); - } - - protected function writeConfig() { - $config = cubeObject::merge($this->book->parametres->toStandardObject(), $this->theme->parametres->toStandardObject()); - $config->numerotation = explode(',', $this->book->numerotation); - $config->id = $this->book->book_id; - $config->cacheDate = TIME; - return 'var DATAS=' . json_encode($config) . ';' . "\n"; - } - - protected function writeFonts() { - $formats = array('ttf', 'woff', 'svg'); - - foreach ($this->cssFont as $font => $index) { - - foreach ($formats as $format) { - $fontforge = new cubeCommandLine('convert.pe'); - $fontforge->setPath(CONVERTER_PATH); - foreach ($this->fontDocs[$font] as $document_id => $dummy) { - $fontforge->setArg(null, wsDocument::getDir($document_id) . 'fonts/web/' . $font . '.ttf'); - } - $fontforge->setArg(null, $this->vdir . '/data/style/F' . $index . '.' . $format); - $fontforge->execute(); - } - } - } - - protected function writeIcons() { - $res = array(); - // Get the colors used to colorize graphics - if ($this->theme->parametres->colorizeIcons) { - $couleurI = '#' . $this->theme->parametres->couleurI; - } else { - $couleurI = '#FFFFFF'; - } - $arrowsColor = '#' . $this->theme->parametres->arrowsColor; - // Set the icon list with the color - $icons = array('nav-bookmark' => $couleurI, 'nav-friend' => $couleurI, 'nav-help' => $couleurI, 'nav-index' => $couleurI, 'nav-sommaire' => $couleurI, - 'next' => $arrowsColor, 'previous' => $arrowsColor, 'search' => $couleurI, 'nav-facebook' => $couleurI, 'nav-twitter' => $couleurI, - 'help-fingers' => $couleurI, 'help-mouse' => $couleurI); - - foreach ($icons as $icon => $color) { - wsTools::colorizeAndRasterizeIcon($this->theme->parametres->iconSet, $icon, $color, $this->vdir . '/data/images/', $w, $h); - } - return $res; - } - - protected function writeImages() { - - foreach (self::$resolutions as $r) { - mkdir($this->vdir . '/data/background/' . $r, 0777); - } - foreach ($this->pages as $page => $infos) { - foreach (self::$resolutions as $r) { - copy(wsDocument::getDir($infos['document_id']) . 'html/h' . $r . '-' . $infos['document_page'] . '.jpg', $this->vdir . '/data/background/' . $r . '/p' . $page . '.jpg'); - } - copy(wsDocument::getDir($infos['document_id']) . 'p' . $infos['document_page'] . '.jpg', $this->vdir . '/data/thumbnails/p' . $page . '.jpg'); - } - } - - protected function writePage($page) { - $res = ''; - foreach ($page as $line) { - $res .= $this->writeLine($line); - } - return $res; - } - - protected function writeLine($line) { - $res = ''; - foreach ($line['groups'] as $group) { - $res .= $this->writeGroup($group, $line); - } - return $res; - } - - protected function writeGroup($group, $line) { - if ($group === false) { - return ''; - } - - $group['y'] = $this->getCSSY(($group['y'] + $line['y']) * $this->multiply); - $group['x'] = $this->getCSSX(($group['x']) * $this->multiply); - - $class = array('g'); - if (!is_null($group['color'])) { - $class[] = 'c' . $group['color']; - } - if (!is_null($group['size'])) { - $class[] = 's' . $group['size']; - } - if (!is_null($group['font'])) { - $class[] = 'f' . $group['font']; - } - if (!is_null($group['x'])) { - $class[] = 'x' . $group['x']; - } - if (!is_null($group['y'])) { - $class[] = 'y' . $group['y']; - } - if (!is_null($line['rotation'])) { - $class[] = 'r' . $line['rotation']; - } - if (!is_null($group['letterspacing'])) { - $class[] = 'l' . $group['letterspacing']; - } - if (!is_null($group['wordspacing'])) { - $class[] = 'w' . $group['wordspacing']; - } - $class = implode(' ', $class); - - $res = '
'; - foreach ($group['spans'] as $span) { - $res .= $this->writeSpan($span); - } - $res .= '
'; - return $res; - } - - protected function writeSpan($span) { - if ($span === false) { - return ''; - } - - if ($span['space']) { - return $span['text']; - } else { - return self::escapeHTML($span['text']); - } - } - - protected function writeCSS($file, $links) { - $res = array(); - - // General theme - $h = $this->book->parametres->height . 'px'; - $w2 = ($this->book->parametres->width * 2) . 'px'; - $w = $this->book->parametres->width . 'px'; - $wm = ($this->book->parametres->width * $this->multiply) . 'px'; - $hm = ($this->book->parametres->height * $this->multiply) . 'px'; - - - $navTop = ($this->book->parametres->height - 40 - 100) / 2; - $res[] = '.portrait #pages,.portrait .doublePage.page,.page,.portrait #shadow,#shadow.single,.page .links{width:' . $w . ';max-width:' . $w . ';height:' . $h . ';max-height:' . $h . '}'; - $res[] = '.background{' . $this->writeCSSUA('transform-origin', 'top left') . ';}'; - foreach (self::$resolutions as $r) { - $ratio = round(72 / $r, 2); - $wr = $this->book->parametres->width / $ratio; - $hr = $this->book->parametres->height / $ratio; - - $br = '.background.r' . $r . '{'; - if ($ratio != 1) { - $br .= $this->writeCSSUA('transform', 'scale(' . $ratio . ')') . ';'; - } - $br .= 'width:' . $wr . 'px;height:' . $hr . 'px;}'; - $res[] = $br; - } - $res[] = '.doublePage,#pages,.landscape #shadow.double{width:' . $w2 . ';max-width:' . $w2 . ';height:' . $h . ';max-height:' . $h . '}'; - $res[] = '.landscape #shadow.single.right{left: ' . $w . ';}'; - $res[] = '.landscape .page.right{left:' . $w . '}'; - if ($this->theme->parametres->displayPageNumber) { - $res[] = '#pagesnumbers{top:' . $h . ';color:' . self::colorToCSS($this->theme->parametres->colorPageNumber) . '}'; - $res[] = '#pagesnumbers div{width:' . $w . '}'; - } else { - $res[] = '#pagesnumbers{display:none;}'; - } - - $texts = '.texts{' . $this->writeCSSUA('transform-origin', 'top left') . ';'; - $texts .= $this->writeCSSUA('transform', 'scale(' . round(1 / $this->multiply, 2) . ')') . ';'; - $texts .= 'width:' . $wm . '; max-width:' . $wm . ';'; - $texts .= 'height:' . $hm . '; max-height:' . $hm . ';'; - $texts .= '}'; - $res[] = $texts; - - // Theme - // Background - $body = '#deviceView{'; - $body .= 'background-color:#' . $this->theme->parametres->backgroundColor . ';'; - 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;'; - break; - case wsTheme::STRETCH: - $body .= 'background-repeat:no-repeat;'; - $body .= 'background-size:100% 100%;'; - break; - } - if ($this->theme->parametres->backgroundImage != '') { - copy($this->themeRoot . '/' . $this->theme->parametres->backgroundImage, $this->vdir . '/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 .= '}'; - $res[] = $body; - - // Header - $header = '#header{'; - $header .= 'height:' . $this->theme->parametres->menuHeight . 'px;'; - $header .= 'background-color:' . self::colorToCSS($this->theme->parametres->menuColor) . ';'; - if ($this->theme->parametres->menuImage != '') { - copy($this->themeRoot . '/' . $this->theme->parametres->menuImage, $this->vdir . '/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;'; - } - $header .= '}'; - $res[] = $header; - - //Icons - $res = array_merge($res, $this->writeIcons()); - - // Logo - $logo = '#logo{'; - if ($this->theme->parametres->logo) { - copy($this->themeRoot . '/' . $this->theme->parametres->logo, $this->vdir . '/data/images/' . $this->theme->parametres->logo); - $dim = getimagesize($this->vdir . '/data/images/' . $this->theme->parametres->logo); - $logo .= 'background-image:url(../images/' . $this->theme->parametres->logo . ');width:' . $dim[0] . 'px;height:' . $dim[1] . 'px;'; - } - $logo .= '}'; - $res[] = $logo; - - // Credits - $res[] = '#credits,#credits a{color:' . self::colorToCSS($this->theme->parametres->creditsColor) . ';}'; - - // Arrows - $res[] = '#next,#previous{background-color:' . self::colorToCSS($this->theme->parametres->couleurA) . ';}'; - // Book shadow - $shadowColor = self::colorToCSS($this->theme->parametres->bookShadeColor); - if ($shadowColor != 'transparent') { - $res[] = '#shadow{' . $this->writeCSSUA('box-shadow', '0 0 20px ' . $shadowColor) . '}'; - } - - // Links Styles - $res = array_merge($res, $links); - $res[] = '.link a.displayArea:hover,.link a.displayArea.animating{background-color:' . self::colorToCSS($this->theme->parametres->linksColor, 0.4) . ';}'; - - // Menus - # View - $res[] = '.portrait #view{width:' . $w . ';min-height:' . $h . '}'; - $res[] = '.landscape #view{width:' . $w2 . ';min-height:' . $h . '}'; - $res[] = '#view{background-color:' . self::colorToCSS($this->theme->parametres->couleurB) . ';color:' . self::colorToCSS($this->theme->parametres->subTextColor) . ';}'; - # Index - $ratio = $this->book->parametres->width / $this->book->parametres->height; - $thumbh = round(100 / $ratio); - $res[] = '#index .thumb img{width:100px;height:' . $thumbh . 'px;}'; - $res[] = '#index .doubleThumb{height:' . $thumbh . 'px;' . $this->writeCSSUA('box-shadow', '0 0 3px ' . $shadowColor) . '}'; - $res[] = '#index .doubleThumb .overlay{height:' . $thumbh . 'px;}'; - $res[] = '#index .doubleThumb .hits.yes{background-color:' . self::colorToCSS($this->theme->parametres->subSelectColor) . ';color:' . self::colorToCSS($this->theme->parametres->subTextSelectColor) . '}'; - - // Pages styles - foreach ($this->cssColor as $color => $index) { - $res[] = '.c' . $index . '{color:#' . $color . '}'; - } - - foreach ($this->cssSize as $size => $index) { - $res[] = '.s' . $index . '{font-size:' . $size . 'px}'; - } - - foreach ($this->cssLetterSpacing as $letterspacing => $index) { - $res[] = '.l' . $index . '{letter-spacing:' . $letterspacing . 'em}'; - } - - foreach ($this->cssWordSpacing as $wordspacing => $index) { - $res[] = '.w' . $index . '{word-spacing:' . $wordspacing . 'em}'; - } - - foreach ($this->cssX as $x => $index) { - $res[] = '.x' . $index . '{left:' . $x . 'px}'; - } - - foreach ($this->cssY as $y => $index) { - $res[] = '.y' . $index . '{top:' . $y . 'px}'; - } - - foreach ($this->cssRotation as $rotation => $index) { - $rotation *= -1; - - - $to = 'transform-origin:left top;'; - - $css = '.r' . $index . '{'; - $css .= self::writeCSSUA('transform', 'rotate(' . $rotation . 'deg)') . ';'; - $css .= self::writeCSSUA('transform-origin', 'left top') . ';'; - $css .= 'margin-top:' . round(cos(deg2rad($rotation)) * -1, 2) . 'em !important;'; - $css .= 'margin-left:' . round(sin(deg2rad($rotation)), 2) . 'em !important;'; - $css .= '}'; - $res[] = $css; - } - - foreach ($this->cssFont as $font => $index) { - $res[] = "@font-face{font-family:F" . $index . ";src:url('F" . $index . ".woff') format('woff'),url('F" . $index . ".ttf') format('truetype'),url('F" . $index . ".svg#" . $font . "') format('svg')}"; - $res[] = '.f' . $index . '{font-family:F' . $index . ',Arial,Helvetica}'; - } - - $res = array_chunk($res, 3500); - foreach ($res as $k => $css) { - file_put_contents(sprintf($file, $k), implode("\n", $css)); - } - return count($res); - } - - protected function writeCSSUA($property, $value) { - $res = array(); - foreach (self::$uaPrefixes as $prefix) { - $res[] = $prefix . $property . ':' . $value; - } - return implode(';', $res); - } - - protected function addLine($line, $document_id) { - $res = array(); - foreach ($line->a as $group) { - $res = array_merge($res, $this->addGroup($group, $document_id)); - } - return array( - 'y' => $this->normalizeFloatValue($line['y']), - 'rotation' => $this->getCSSRotation($this->normalizeFloatValue($line['rotation'], 0)), - "groups" => $res); - } - - protected function addGroup($group, $document_id) { - $alpha = intval(substr($group['color'], 1, 2), 16); - if ($alpha == 0) { - return false; - } - - $first = true; - $letterSpacing = 0; - $letterCount = 0; - $wordSpacing = 0; - $wordCount = 0; - - $res = array(); - $spans = array(); - - foreach ($group->s as $span) { - if ($first && trim((string)$span) == '') { - continue; - } - if ($first) { - $pos = $x = $span['x']; - $pos += $span['width']; - $first = false; - } else { - if ((float)$span['x'] < (float)$newSpan['x']) { - // On change de groupe - $ls = $ws = 0; - if ($letterCount > 0) { - $ls = $letterSpacing / $letterCount; - } - if ($wordCount > 0) { - $ws = $wordSpacing / $wordCount; - } - - $res[] = array( - 'color' => $this->getCSSColor($group['color']), - 'size' => $this->getCSSSize($group['size']), - 'font' => $this->getCSSFont((string)$group['font'], $document_id), - 'letterspacing' => $this->getCSSLetterSpacing($ls), - 'wordspacing' => $this->getCSSLetterSpacing($ws), - 'y' => 0, - 'x' => $x, - 'spans' => $spans); - - $spans = array(); - $pos = $x = $span['x']; - $pos += $span['width']; - } else { - - $diff = $span['x'] - $pos; - if ($diff > $group['size'] / 4) { - $space = round($diff / $group['size'], 4); - if ($space > 2) { - // On change de groupe - $ls = $ws = 0; - if ($letterCount > 0) { - $ls = $letterSpacing / $letterCount; - } - if ($wordCount > 0) { - $ws = $wordSpacing / $wordCount; - } - $res[] = array( - 'color' => $this->getCSSColor($group['color']), - 'size' => $this->getCSSSize($group['size']), - 'font' => $this->getCSSFont($group['font'], $document_id), - 'letterspacing' => $this->getCSSLetterSpacing($ls), - 'wordspacing' => $this->getCSSLetterSpacing($ws), - 'y' => 0, - 'x' => $x, - 'spans' => $spans); - - $spans = array(); - $pos = $x = $span['x']; - $pos += $span['width']; - } else { - - $newSpan = $this->addSpan(' ', true); - array_push($spans, $newSpan); - } - } - } - } - - - $newSpan = $this->addSpan($span); - $pos = $span['x'] + $span['width']; - - array_push($spans, $newSpan); - $copy = (string)$span; - $len = mb_strlen($copy); - str_replace(' ', '-', $copy, $w); - $l = $len - $w; - - $letterCount += $l; - $wordCount += $w; - - $letterSpacing += $l * (float)$span['letterspacing']; - $wordSpacing += $w * (float)$span['wordspacing']; - } - - if (count($spans)) { - $ls = $ws = 0; - if ($letterCount > 0) { - $ls = $letterSpacing / $letterCount; - } - if ($wordCount > 0) { - $ws = $wordSpacing / $wordCount; - } - - $res[] = array( - 'color' => $this->getCSSColor($group['color']), - 'size' => $this->getCSSSize($group['size']), - 'font' => $this->getCSSFont($group['font'], $document_id), - 'letterspacing' => $this->getCSSLetterSpacing($ls), - 'wordspacing' => $this->getCSSLetterSpacing($ws), - 'y' => 0, - 'x' => $x, - 'spans' => $spans); - } - - return $res; - } - - protected function addSpan($span, $space = false) { - $text = (string)$span; - return array('text' => $text, 'space' => $space, 'x' => $span['x']); - } - - protected function getCSSSize($size) { - $size = $this->normalizeFloatValue($size); - $size *= $this->multiply; - return $this->getIndex($size, $this->cssSize); - } - - protected function getCSSFont($font, $document_id) { - $font = (string)$font; - if (!isset($this->fontDocs[$font])) { - $this->fontDocs[$font] = array(); - } - $this->fontDocs[$font][$document_id] = true; - - return $this->getIndex($font, $this->cssFont); - } - - protected function getCSSColor($color) { - $color = trim($color, '#'); - if (strlen($color) > 6) { - $color = substr($color, 2, 6); - } - if ($color == '000000') { - return null; - } - return $this->getIndex($color, $this->cssColor); - } - - protected function getCSSLetterSpacing($letterspacing) { - - $letterspacing = $this->normalizeFloatValue($letterspacing, 4); - - if ($letterspacing == 0) { - return null; - } - return $this->getIndex($letterspacing, $this->cssLetterSpacing); - } - - protected function getCSSWordSpacing($wordspacing) { - $wordspacing = $this->normalizeFloatValue($wordspacing, 4); - - if ($wordspacing == 0) { - return null; - } - return $this->getIndex($wordspacing, $this->cssWordSpacing); - } - - protected function getCSSRotation($rotation) { - $rotation = $this->normalizeFloatValue($rotation, 0); - if ($rotation == 0) { - return null; - } - return $this->getIndex($rotation, $this->cssRotation); - } - - protected function getCSSX($x) { - $x = round($x); - if ($x == 0) { - return null; - } - return $this->getIndex($x, $this->cssX); - } - - protected function getCSSY($y) { - $y = round($y); - if ($y == 0) { - return null; - } - return $this->getIndex($y, $this->cssY); - } - - protected function getIndex($value, &$tab) { - $value = (string)$value; - if (isset($tab[$value])) { - return $tab[$value]; - } - $res = $this->base62(count($tab)); - $tab[$value] = $res; - return $res; - } - - protected function normalizeFloatValue($value, $round = 3) { - $value = str_replace(',', '.', $value); - $value = (float)$value; - $value = round($value, $round); - return $value; - } - - 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 copyLinkFile($source, $dest, $video = false) { - // TODO delete that return; - //return; - $origDir = WS_BOOKS . '/working/' . $this->book_id . '/'; - $types = array('mp4', 'ogv', 'webm', 'jpg'); - if ($video) { - return; - wsTools::encodeWebVideos($origDir . $source, null, false); - $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 = $this->vdir . '/' . $dest . '/' . $so; - if (!file_exists(dirname($d))) { - mkdir(dirname($d), 0777, true); - } - copy($s, $d); - } - } - } - - public static function escapeHTML($in) { - $in = htmlentities($in, ENT_NOQUOTES, "UTF-8"); - $in = str_replace(' ', '', $in); - - return $in; - } - - public function __destruct() { - - } - - public static function colorToCSS($color, $forceAlpha = null) { - - if (!is_null($forceAlpha)) { - $a = $forceAlpha * 255; - $a = base_convert($a, 10, 16); - if (strlen($color) == 6) { - $color = $a . $color; - } else { - $color = $a . substr($color, 2, 6); - } - } - - if (strlen($color) == 6) { - return '#' . $color; - } else { - $alpha = substr($color, 0, 2); - $red = substr($color, 2, 2); - $green = substr($color, 4, 2); - $blue = substr($color, 6, 2); - - $components = array('alpha', 'red', 'green', 'blue'); - foreach ($components as $k => $name) { - $hex = substr($color, $k * 2, 2); - $$name = intval($hex, 16); - } - $alpha /= 255; - if ($alpha == 0) { - return 'transparent'; - } elseif ($alpha == 1) { - return '#' . substr($color, 2, 6); - } - return 'rgba(' . $red . ',' . $green . ',' . $blue . ',' . $alpha . ')'; - } - } - -} - -?> \ No newline at end of file