From f8d93b231a9ca73dff774f545c4ecad1afdd2546 Mon Sep 17 00:00:00 2001 From: "vincent@cubedesigners.com" Date: Mon, 15 Aug 2011 20:48:48 +0000 Subject: [PATCH] --- .htaccess | 6 ++ images/ws/html5bug.png | Bin 0 -> 1551 bytes inc/ws/Controlleur/class.ws.url.php | 56 +++++++++- inc/ws/DAO/class.ws.dao.book.php | 26 ++++- inc/ws/Util/html5/class.ws.html5.compiler.php | 99 +++++++++++------- inc/ws/Util/html5/class.ws.html5.links.php | 16 +-- inc/ws/Util/packager/class.ws.packager.php | 2 - inc/ws/_common.php | 4 +- 8 files changed, 156 insertions(+), 53 deletions(-) create mode 100644 images/ws/html5bug.png diff --git a/.htaccess b/.htaccess index b74df29d9..2f639c659 100644 --- a/.htaccess +++ b/.htaccess @@ -50,4 +50,10 @@ AddCharset UTF-8 log RewriteRule ^viewerp/([0-9]+)_([0-9a-fA-F]+)_([0-9]+)/index.swf$ fluidbook/compile/_standalone/player.swf [L] RewriteRule ^viewerp/([0-9]+)_([0-9a-fA-F]+)_([0-9]+)/fluidbook.js$ fluidbook/compile/fluidbook.js [L] RewriteRule ^viewerp/([0-9]+)_([0-9a-fA-F]+)_([0-9]+)/(.+)$ fluidbook/books/final/$1/$4 [L] + + RewriteRule ^viewerh/([0-9]+)_([0-9a-fA-F]+)_([0-9]+)/(.+)$ fluidbook/books/html5/$1/$4 [L] + + RewriteRule ^viewerhu/([0-9]+)_([0-9a-fA-F]+)_([0-9]+)/js/(.+)$ fluidbook/compile/_html5/js/$4 [L] + RewriteRule ^viewerhu/([0-9]+)_([0-9a-fA-F]+)_([0-9]+)/(.+)$ fluidbook/books/html5/$1/$4 [L] + \ No newline at end of file diff --git a/images/ws/html5bug.png b/images/ws/html5bug.png new file mode 100644 index 0000000000000000000000000000000000000000..5a8ba358f116b944e82f063bf257748f74a971e4 GIT binary patch literal 1551 zcmeAS@N?(olHy`uVBq!ia0vp^0wB!61|;P_|4#%`k|nMYCBgY=CFO}lsSJ)O`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a/inc/ws/Controlleur/class.ws.url.php b/inc/ws/Controlleur/class.ws.url.php index 9771d7719..4bdcc0a72 100644 --- a/inc/ws/Controlleur/class.ws.url.php +++ b/inc/ws/Controlleur/class.ws.url.php @@ -167,9 +167,6 @@ class wsUrl { $versions['win-ins'] = array('title' => __('Version offline') . ' - ' . __('Installeur Auto-executable Windows'), 'icon' => cubeMedia::silk('application_view_tile.png')); $versions['mac-exe'] = array('title' => __('Version offline') . ' - ' . __('Exécutable Mac OS X'), 'icon' => cubeMedia::image(IMG . '/macos.png')); $versions['win-cd'] = array('title' => __('Version offline') . ' - ' . __('CD-ROM') . ' / ' . __('Clé USB'), 'icon' => cubeMedia::silk('cd.png')); - if (wsDroits::admin()) { - $versions['html5'] = array('title' => __('Version HTML5 (α)'), 'icon' => cubeMedia::image(IMG . '/html5.png')); - } $res = '
'; $res .= '
    '; @@ -208,8 +205,9 @@ class wsUrl { if (wsDroits::admin()) { $viewers = array('viewer' => array('title' => __('Version Flash'), 'icon' => cubeMedia::image(IMG . '/flash.png')), + 'viewerh' => array('title' => __('Version HTML5'), 'icon' => cubeMedia::image(IMG . '/html5.png')), 'vieweru' => array('title' => __('Version Flash') . ' (' . __('debuggage') . ')', 'icon' => cubeMedia::image(IMG . '/flashbug.png')), - 'viewerh' => array('title' => __('Version HTML5'), 'icon' => cubeMedia::image(IMG . '/html5.png'))); + 'viewerhu' => array('title' => __('Version HTML5') . ' (' . __('debuggage') . ')', 'icon' => cubeMedia::image(IMG . '/html5bug.png'))); } $res = '
    '; @@ -592,6 +590,56 @@ html{height:100%}' . "\n"; echo self::commonViewer($book_id, $e[1], false, 'default', true); } + public static function viewerh($args) { + $args = cubePage::getArgs($args); + + $e = explode('_', $args[0]); + if (count($e) == 2 || $e[2] < TIME - 10) { + $e[2] = TIME; + http::redirect(SITE_PATH . 'viewerh/' . implode('_', $e) . '/'); + exit; + } + + $book_id = $e[0]; + $hash = $e[1]; + self::commonHTML5Viewer($book_id, $hash); + } + + public static function viewerhu($args) { + commonDroits::min(5); + $args = cubePage::getArgs($args); + + $e = explode('_', $args[0]); + if (count($e) == 2 || $e[2] < TIME - 10) { + $e[2] = TIME; + http::redirect(SITE_PATH . 'viewerhu/' . implode('_', $e) . '/'); + exit; + } + + $book_id = $e[0]; + $hash = $e[1]; + self::commonHTML5Viewer($book_id, $hash, 'u'); + } + + public static function commonHTML5Viewer($book_id, $hash, $version='') { + global $core; + self::checkDocumentVersionOfBook($book_id); + + $dao = new wsDAOBook($core->con); + + $book = $dao->selectById($book_id); + if ($hash != 'bcf26f9cf4a795ec00b9a44f42750d58' && $book->hash != $hash) { + commonDroits::error(); + } + + if (!$dao->isUpToDate($book_id)) { + $dao->compile($book_id); + $dao->touchCompile($book_id); + } + echo file_get_contents(WS_BOOKS . '/html5/' . $book_id . '/index' . $version . '.html'); + exit; + } + public static function viewer($args) { $args = cubePage::getArgs($args); diff --git a/inc/ws/DAO/class.ws.dao.book.php b/inc/ws/DAO/class.ws.dao.book.php index b23d97023..bd80334f7 100644 --- a/inc/ws/DAO/class.ws.dao.book.php +++ b/inc/ws/DAO/class.ws.dao.book.php @@ -530,9 +530,25 @@ class wsDAOBook extends commonDAO { $c->update('WHERE book_id=\'' . $this->con->escape($book_id) . '\''); } - public function isUpToDate($book_id) { + public function isUpToDate($book_id, $html=false) { $r = $this->con->select('SELECT changedate,compiledate FROM books WHERE book_id=\'' . $this->con->escape($book_id) . '\''); - return $r->compiledate > $r->changedate; + if ($r->compiledate < $r->changedate) { + return false; + } + + $checks = array($r->changedate, filemtime(WS_COMPILE_ASSETS . '/_html5')); + $reffile = WS_BOOKS . '/html5/' . $book_id; + + if (!file_exists($reffile)) { + return false; + } + $reftime = filemtime($reffile); + foreach ($checks as $check) { + if ($check > $reftime) { + return false; + } + } + return true; } public function setComposition($book_id, $pages) { @@ -880,10 +896,16 @@ class wsDAOBook extends commonDAO { $this->compilePDF($book, $pages); $this->indexPDF($book, $pages); $this->touchCompile($book_id); + $this->compileHTML5($book_id); return $res; } + protected function compileHTML5($book_id) { + $htmlCompiler = new wsHTML5Compiler($book_id); + $htmlCompiler->compile(); + } + public function indexPDF($book, $pages) { $indexPath = WS_BOOKS . '/search/' . $book->book_id; diff --git a/inc/ws/Util/html5/class.ws.html5.compiler.php b/inc/ws/Util/html5/class.ws.html5.compiler.php index 44ef16167..abed44590 100644 --- a/inc/ws/Util/html5/class.ws.html5.compiler.php +++ b/inc/ws/Util/html5/class.ws.html5.compiler.php @@ -2,6 +2,24 @@ class wsHTML5Compiler { + protected static $resolutions = array(36, 72, 150); + protected static $uaPrefixes = array('-moz-', '-webkit-', '-o-', '-ms-', ''); + protected static $jsFiles = 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'); protected $layouts = array(); protected $cssSize = array(); protected $cssColor = array(); @@ -17,8 +35,6 @@ class wsHTML5Compiler { protected $multiply; protected $div = array(); protected $numerotation; - protected static $resolutions = array(36, 72, 150); - protected static $uaPrefixes = array('-moz-', '-webkit-', '-o-', '-ms-', ''); protected $fontDocs = array(); protected $dir; protected $vdir; @@ -29,12 +45,21 @@ class wsHTML5Compiler { protected $book_id; protected $themeRoot; protected $daoBook; + protected $needToRecompileContents = true; + protected $needToRecompileSettings = true; function __construct($book_id) { + global $core; + + if (trim($book_id) == '') { + return; + } $this->book_id = $book_id; $this->vdir = $this->dir = WS_BOOKS . '/html5/' . $book_id . '/'; + // Clean the folder + `rm -rf $this->vdir`; if (!file_exists($this->dir)) { mkdir($this->dir, 0777, true); } @@ -59,8 +84,6 @@ class wsHTML5Compiler { $this->scale = 4; $this->multiply = $this->pdf2htmlRatio * $this->scale; $this->numerotation = explode(',', $this->book->numerotation); - - $this->createHTML(); } public function virtualToPhysical($virtual) { @@ -79,7 +102,7 @@ class wsHTML5Compiler { } } - protected function createHTML() { + public function compile() { foreach ($this->layouts as $page => $layout) { $this->div[$page] = array(); $document_id = $this->pages[$page]['document_id']; @@ -93,14 +116,15 @@ class wsHTML5Compiler { $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); + + $dirsToCreate = array('data/images', 'data/contents', 'data/background', 'data/thumbnails', 'data/style', 'data/links/pages', 'data/l10n', 'swf'); + + foreach ($dirsToCreate as $dir) { + $d = $this->vdir . '/' . $dir; + if (!file_exists($d)) { + mkdir($d, 0777, true); + } + } // Copy style folder $from = WS_COMPILE_ASSETS . '/_html5/style'; @@ -128,6 +152,7 @@ class wsHTML5Compiler { protected function writeIndex($numCSS) { $html = file_get_contents(WS_COMPILE_ASSETS . '/_html5/_index.html'); + $uhtml = $html; $titre = $this->book->parametres->title; $credits = ''; @@ -147,11 +172,27 @@ class wsHTML5Compiler { } $style = implode("\n\t\t", $style); - $vars = array('titre', 'credits', 'ga', 'style'); + $script = ''; + + $vars = array('titre', 'credits', 'ga', 'style', 'script'); foreach ($vars as $v) { $html = str_replace('', $$v, $html); } + + $scripts = array(); + foreach (self::$jsFiles as $js) { + $scripts[] = ''; + } + $scripts[] = ''; + $script = implode("\n\t\t", $scripts); + + $vars = array('titre', 'credits', 'ga', 'style', 'script'); + foreach ($vars as $v) { + $uhtml = str_replace('', $$v, $uhtml); + } + file_put_contents($this->vdir . '/index.html', $html); + file_put_contents($this->vdir . '/indexu.html', $uhtml); } protected function writeLangs() { @@ -200,22 +241,7 @@ class wsHTML5Compiler { } 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'; @@ -223,7 +249,7 @@ class wsHTML5Compiler { $mintime = filemtime($minimized); } $reminimize = false; - foreach ($files as $file) { + foreach (self::$jsFiles as $file) { if (filemtime(WS_COMPILE_ASSETS . '/_html5/' . $file) > $mintime) { $reminimize = true; break; @@ -232,7 +258,7 @@ class wsHTML5Compiler { if ($reminimize) { $js = ''; - foreach ($files as $file) { + foreach (self::$jsFiles as $file) { $js.=file_get_contents(WS_COMPILE_ASSETS . '/_html5/' . $file); $js.="\n\n"; } @@ -249,8 +275,9 @@ class wsHTML5Compiler { $compressor->execute(); } - $js = $this->writeConfig(); - $js.=file_get_contents($minimized); + $config = $this->writeConfig(); + $js=$config.file_get_contents($minimized); + file_put_contents($this->vdir.'/data/datas.js',$config); file_put_contents($this->vdir . '/data/fluidbook.js', $js); } @@ -302,7 +329,7 @@ class wsHTML5Compiler { protected function writeImages() { foreach (self::$resolutions as $r) { - mkdir($this->vdir . '/data/background/' . $r, 0777); + mkdir($this->vdir . '/data/background/' . $r, 0777, true); } foreach ($this->pages as $page => $infos) { foreach (self::$resolutions as $r) { @@ -838,7 +865,6 @@ class wsHTML5Compiler { $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); @@ -912,4 +938,5 @@ class wsHTML5Compiler { } } + ?> \ No newline at end of file diff --git a/inc/ws/Util/html5/class.ws.html5.links.php b/inc/ws/Util/html5/class.ws.html5.links.php index b0bf8cb3b..d2eee02ab 100644 --- a/inc/ws/Util/html5/class.ws.html5.links.php +++ b/inc/ws/Util/html5/class.ws.html5.links.php @@ -149,7 +149,7 @@ class contentLink extends wsHTML5Link { class webLink extends normalLink { public function getURL() { - return wsPackagerHTML5Link::getUniversalLocation($this->to); + return wsHTML5Link::getUniversalLocation($this->to); } public function getTarget() { @@ -224,10 +224,10 @@ class videoLink extends wsHTML5Link { if ($type != '') { $type = " type='" . $type . "'"; } - $res.=''; + $res.=''; } - $flashvars = array('video' => wsPackagerHTML5Link::getUniversalLocation($basename . '.mp4'), - 'poster' => wsPackagerHTML5Link::getUniversalLocation($basename . '.jpg'), + $flashvars = array('video' => wsHTML5Link::getUniversalLocation($basename . '.mp4'), + 'poster' => wsHTML5Link::getUniversalLocation($basename . '.jpg'), 'controls' => $this->video_controls == '1', 'autoPlay' => $this->video_auto_start == '1', 'loop' => $this->video_loop); @@ -274,7 +274,7 @@ class basketLink extends wsHTML5Link { class colorLink extends contentLink { public function getCSS() { - return 'background-color:' . wsPackagerHTML5::colorToCSS($this->to) . ';'; + return 'background-color:' . wsHTML5Compiler::colorToCSS($this->to) . ';'; } } @@ -283,7 +283,7 @@ 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;'; + return 'background-image:url(' . wsHTML5Link::getUniversalLocation($this->to, true) . ');background-size:100% 100%;background-repeat:no-repeat;'; } } @@ -292,7 +292,7 @@ class fileLink extends normalLink { public function getURL() { $this->copyExternalFile($this->to); - return wsPackagerHTML5Link::getUniversalLocation($this->to); + return wsHTML5Link::getUniversalLocation($this->to); } public function getTarget() { @@ -304,7 +304,7 @@ class fileLink extends normalLink { class multimediaLink extends wsHTML5Link { public function getHTMLContent() { - return cubeMedia::flashObject(wsPackagerHTML5Link::getUniversalLocation($this->to), $this->width, $this->height, array(), '', '', 9, '#ffffff', '', 'true', 'noscale', 'transparent'); + return cubeMedia::flashObject(wsHTML5Link::getUniversalLocation($this->to), $this->width, $this->height, array(), '', '', 9, '#ffffff', '', 'true', 'noscale', 'transparent'); } } diff --git a/inc/ws/Util/packager/class.ws.packager.php b/inc/ws/Util/packager/class.ws.packager.php index 78702703e..564e37987 100644 --- a/inc/ws/Util/packager/class.ws.packager.php +++ b/inc/ws/Util/packager/class.ws.packager.php @@ -24,8 +24,6 @@ class wsPackager { $packager = new wsPackagerWinINST($book_id); } elseif ($version == 'mac-exe') { $packager = new wsPackagerMacEXE($book_id); - } elseif ($version == 'html5') { - $packager = new wsPackagerHTML5($book_id); } return $packager->makePackage(); diff --git a/inc/ws/_common.php b/inc/ws/_common.php index e803a9127..18585940b 100644 --- a/inc/ws/_common.php +++ b/inc/ws/_common.php @@ -1,4 +1,5 @@ url->register('restoreLinks', 'restoreLinks', '^restoreLinks/(.*)$', arra $core->url->register('viewer', 'viewer', '^viewer/(.*)$', array('wsUrl', 'viewer')); $core->url->register('vieweru', 'vieweru', '^vieweru/(.*)$', array('wsUrl', 'vieweru')); $core->url->register('viewerp', 'viewerp', '^viewerp/(.*)$', array('wsUrl', 'viewerp')); +$core->url->register('viewerh', 'viewerh', '^viewerh/(.*)$', array('wsUrl', 'viewerh')); +$core->url->register('viewerhu', 'viewerhu', '^viewerhu/(.*)$', array('wsUrl', 'viewerhu')); if (DEV) { $tools = ROOT . '/../inc/tools/'; @@ -23,5 +26,4 @@ if (DEV) { cubePHP::appendEnv('PATH', $tools . 'gs8.70/lib/'); cubePHP::setEnv('GS_FONTPATH', FONT_PATH); } - ?> \ No newline at end of file -- 2.39.5