From e50da51c7b787144f77a42ac1af119d4d1bbe406 Mon Sep 17 00:00:00 2001 From: "vincent@cubedesigners.com" Date: Mon, 20 Jan 2014 13:14:31 +0000 Subject: [PATCH] --- inc/ws/DAO/class.ws.dao.book.php | 3 - .../Util/packager/class.ws.packager.html.php | 748 +++++++++--------- 2 files changed, 374 insertions(+), 377 deletions(-) diff --git a/inc/ws/DAO/class.ws.dao.book.php b/inc/ws/DAO/class.ws.dao.book.php index bd263961d..5cd60abcf 100644 --- a/inc/ws/DAO/class.ws.dao.book.php +++ b/inc/ws/DAO/class.ws.dao.book.php @@ -1476,9 +1476,6 @@ class wsDAOBook extends commonDAO { $originalPDF = $cacheDir . '/original.pdf'; $compressedPDF = $cacheDir . '/compressed.pdf'; - - - if (file_exists($originalPDF)) { $fmtime = filemtime($originalPDF); if ($fmtime >= $book->composition_update) { diff --git a/inc/ws/Util/packager/class.ws.packager.html.php b/inc/ws/Util/packager/class.ws.packager.html.php index f741d3a6c..36084f9c8 100644 --- a/inc/ws/Util/packager/class.ws.packager.html.php +++ b/inc/ws/Util/packager/class.ws.packager.html.php @@ -1,375 +1,375 @@ -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->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); - } - - $facebook = ''; - if ($this->book->parametres->facebook) { - if ($this->book->parametres->facebook_title != '') { - $facebook .= ''; - } else { - $facebook .= ''; - } - if ($this->book->parametres->facebook_description != '') { - $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->seoRobot)) { - $seoRobot = $this->book->parametres->seoRobot; - } - - $robots = ''; - if (!$seoRobot) { - $robots = ''; - } - - $description = ''; - if ($this->book->parametres->seoDescription) { - $description = ''; - } - $keywords = ''; - if ($this->book->parametres->seoKeywords) { - $keywords = ''; - } - - $alwaysHTML5 = $this->book->parametres->alwaysHTML5; - if (is_null($alwaysHTML5) || !$alwaysHTML5) { - $alwaysHTML5 = 'false'; - } - - // Stuffs to replace in html - $toReplace = array('lang' => strtolower($this->book->lang), - 'ga' => $ga, - 'facebook' => $facebook, - 'bgcolor' => $this->theme->parametres->loadingBackColor, - 'redirectMobile' => $redirectMobile, - 'redirectPDF' => $redirectPDF, - 'junk' => TIME, - 'description' => $description, - 'robots' => $robots, - 'favicon' => $favicon, - 'flashversion' => $this->getMinFlashVersion(), - 'fv' => json_encode($this->getFlashvars()), - 'alwaysHTML5' => $alwaysHTML5, - 'keywords' => $keywords); - - - - $this->origHTML = file_get_contents($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.html'; - $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)) . '.html'; - $pathToIndex = '../index.swf'; - $pathToGetflash = '../getflash.gif'; - $sp = '../'; - $redirectScript = ''; - } - $alt = ''; - - $htmlfile = WS_DOCS . '/' . $infos['document_id'] . '/h' . $infos['document_page'] . '.txt'; - - if ($seoVersion && file_exists($htmlfile)) { - $html = file_get_contents($htmlfile); - $alt .= "\n" . $html . "\n"; - - - if ($page == 1) { - $alt .= $nav1; - } else { - $alt .= $nav; - } - } - - - $alt .= $footer; - - $data = str_replace('$alt', $alt, $this->origHTML); - $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); - - 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'); - - $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'; - } - $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->vdir; - } - - 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) { - return htmlentities($txt, ENT_COMPAT, 'UTF-8'); - } - - 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('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); - } - -} - +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->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); + } + + $facebook = ''; + if ($this->book->parametres->facebook) { + if ($this->book->parametres->facebook_title != '') { + $facebook .= ''; + } else { + $facebook .= ''; + } + if ($this->book->parametres->facebook_description != '') { + $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->seoRobot)) { + $seoRobot = $this->book->parametres->seoRobot; + } + + $robots = ''; + if (!$seoRobot) { + $robots = ''; + } + + $description = ''; + if ($this->book->parametres->seoDescription) { + $description = ''; + } + $keywords = ''; + if ($this->book->parametres->seoKeywords) { + $keywords = ''; + } + + $alwaysHTML5 = $this->book->parametres->alwaysHTML5; + if (is_null($alwaysHTML5) || !$alwaysHTML5) { + $alwaysHTML5 = 'false'; + } + + // Stuffs to replace in html + $toReplace = array('lang' => strtolower($this->book->lang), + 'ga' => $ga, + 'facebook' => $facebook, + 'bgcolor' => $this->theme->parametres->loadingBackColor, + 'redirectMobile' => $redirectMobile, + 'redirectPDF' => $redirectPDF, + 'junk' => TIME, + 'description' => $description, + 'robots' => $robots, + 'favicon' => $favicon, + 'flashversion' => $this->getMinFlashVersion(), + 'fv' => json_encode($this->getFlashvars()), + 'alwaysHTML5' => $alwaysHTML5, + 'keywords' => $keywords); + + + + $this->origHTML = file_get_contents($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.html'; + $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)) . '.html'; + $pathToIndex = '../index.swf'; + $pathToGetflash = '../getflash.gif'; + $sp = '../'; + $redirectScript = ''; + } + $alt = ''; + + $htmlfile = WS_DOCS . '/' . $infos['document_id'] . '/h' . $infos['document_page'] . '.txt'; + + if ($seoVersion && file_exists($htmlfile)) { + $html = file_get_contents($htmlfile); + $alt .= "\n" . $html . "\n"; + + + if ($page == 1) { + $alt .= $nav1; + } else { + $alt .= $nav; + } + } + + + $alt .= $footer; + + $data = str_replace('$alt', $alt, $this->origHTML); + $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); + + 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'); + + $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'; + } + $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->vdir; + } + + 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) { + return htmlentities($txt, ENT_COMPAT, 'UTF-8'); + } + + 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('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); + } + +} + ?> \ No newline at end of file -- 2.39.5