From 227ee877bc87d71421c03522ccf6084edf6e9894 Mon Sep 17 00:00:00 2001 From: "vincent@cubedesigners.com" Date: Wed, 24 Jul 2013 09:08:44 +0000 Subject: [PATCH] --- inc/commons/class.common.tools.php | 3 - inc/ws/Controlleur/class.ws.ajax.php | 11 ++- inc/ws/Controlleur/class.ws.services.php | 99 ++++++++++++++----- inc/ws/Util/class.ws.tools.php | 6 +- inc/ws/Util/html5/class.ws.html5.compiler.php | 28 +++++- 5 files changed, 113 insertions(+), 34 deletions(-) diff --git a/inc/commons/class.common.tools.php b/inc/commons/class.common.tools.php index c4474dea1..d73854e67 100644 --- a/inc/commons/class.common.tools.php +++ b/inc/commons/class.common.tools.php @@ -553,9 +553,6 @@ class commonTools { $uglify->execute(); ob_end_clean(); - fb($uglify->commande); - fb($uglify->output); - header('Content-type: text/javascript'); if (file_exists($res)) { echo file_get_contents($res); diff --git a/inc/ws/Controlleur/class.ws.ajax.php b/inc/ws/Controlleur/class.ws.ajax.php index bc5a7354f..67cf9bbec 100644 --- a/inc/ws/Controlleur/class.ws.ajax.php +++ b/inc/ws/Controlleur/class.ws.ajax.php @@ -1081,8 +1081,6 @@ class wsAjax extends cubeAjax { file_put_contents(WS_COLLECTIONS . '/versions/' . $id . '/' . $time . '/composition.json', json_encode($compiler->collection->datas)); - - $c = $core->con->openCursor('book_collection_compile'); $c->collection_id = $id; $c->compile_date = $time; @@ -1110,9 +1108,12 @@ class wsAjax extends cubeAjax { $c->online = 1; $c->update('WHERE collection_id=\'' . $core->con->escape($id) . '\' AND compile_date=\'' . $core->con->escape($date) . '\''); - $cache = WS_COLLECTIONS . '/ws/' . $id . '.json'; - if (file_exists($cache)) { - unlink($cache); + $caches = array(WS_COLLECTIONS . '/ws/' . $id . '.ios.json', WS_COLLECTIONS . '/ws/' . $id . '.android.json'); + + foreach ($caches as $cache) { + if (file_exists($cache)) { + unlink($cache); + } } $x->addReload(); diff --git a/inc/ws/Controlleur/class.ws.services.php b/inc/ws/Controlleur/class.ws.services.php index be3181b3a..1341f638f 100644 --- a/inc/ws/Controlleur/class.ws.services.php +++ b/inc/ws/Controlleur/class.ws.services.php @@ -586,13 +586,14 @@ class wsServices extends cubeFlashGateway { foreach ($composition as $k => $g) { foreach ($g->publications as $l => $p) { $root = WS_COLLECTIONS . '/versions/' . $id . '/' . $version . '/' . $os . '/' . $p->id; - $couv = $root . '/data/background/36/t1.jpg'; + $couv = $root . '/cover.jpg'; $couvertures[$p->id] = base64_encode(file_get_contents($couv)); $publications[] = $p->id; } } - $d = array('id' => $id, 'time' => $version, 'manifest' => $this->_getManifest($publications, '/fluidbook/collections/versions/' . $id . '/' . $version . '/' . $os), 'datas' => $composition, 'couvertures' => $couvertures); + $d = array('id' => $id, 'time' => $version, 'datas' => $composition, 'couvertures' => $couvertures); + $d = array_merge($d, $this->_getManifest($publications, '/fluidbook/collections/versions/' . $id . '/' . $version . '/' . $os)); $dao = new wsDAOCollection($core->con); $col = $dao->selectById($id); @@ -609,50 +610,104 @@ class wsServices extends cubeFlashGateway { } protected function _getManifest($publications, $dir) { + global $core; + $res = array(); + $res['manifest'] = array('assetRoot' => 'http://workshop.fluidbook.com' . $dir . '/', 'autoDownload' => true); + $res['manifestPub'] = array(); - - $res = array('assetRoot' => 'http://workshop.fluidbook.com' . $dir . '/', 'autoDownload' => false); $bundles = array(); $removeFromRelative = realpath(ROOT . '/' . $dir) . '/'; + foreach ($publications as $p) { - $c = array(); - $c1 = array(); + $res['manifestPub'][$p] = array('assetRoot' => 'http://workshop.fluidbook.com' . $dir . '/', 'autoDownload' => true); + $r = $p . '/'; $iterator = CubeIT_Files::getRecursiveDirectoryIterator(ROOT . $dir . '/' . $p); + + $daoBook = new wsDAOBook($core->con); + $book = $daoBook->selectById($p); + $daoTheme = new wsDAOTheme($core->con); + $theme = $daoTheme->selectById($book->theme); + $orders = $this->_getBundles($book); + $reg = $this->_getRegExpManifest($r, $book, $theme); + + $b = array(); + foreach ($iterator as $k => $f) { if ($f->isDir()) { continue; } $path = str_replace($removeFromRelative, '', $k); - $order = $this->_inFirstManifest($path, $r); - if ($order === 0) { - $c1[] = $path; - } elseif ($order === 1) { - $c[] = $path; + $order = $this->_inFirstManifest($path, $orders, $reg); + + if (!isset($b[$order])) { + $b[$order] = array(); } + + $b[$order][] = $path; } - //shuffle($c); - $bundles[] = array('name' => 'p_' . $p, 'contents' => $c1); - $bundles[] = array('name' => 'p_' . $p . '_', 'contents' => $c); + + + $bundles[] = array('name' => 'p_' . $p, 'contents' => $b['loading']); + + $res['manifestPub'][$p]['bundles'] = array(); + + foreach ($b as $name => $contents) { + if ($name == 'loading') { + continue; + } + $k = array_search($name, $orders); + $res['manifestPub'][$p]['bundles'][$k] = array('name' => $name, 'contents' => $contents); + } + ksort($res['manifestPub'][$p]['bundles']); + $res['manifestPub'][$p]['bundles'] = array_values($res['manifestPub'][$p]['bundles']); } - $res['bundles'] = $bundles; + $res['manifest']['bundles'] = $bundles; return $res; } - protected function _inFirstManifest($p, $r) { + protected function _getRegExpManifest($r, $book, $theme) { + $reg = array(); + $reg['loading'] = array('^' . $r . 'style/(.*).css$', '^' . $r . 'index.html$', '^' . $r . 'data/style/(.*)$', '^' . $r . 'data/(.*).js$', '^' . $r . 'data/images/' . $theme->parametres->logoLoader . '$'); + $reg['extras'] = array('^' . $r . 'data/links/(.*)$', '^' . $r . 'data/(.*).pdf$', '^' . $r . 'cover.jpg$'); + $reg['thumbnails'] = array('^' . $r . 'data/thumbnails/p(\d+).jpg$'); + for ($i = 1; $i <= $book->parametres->pages; $i++) { + $var = 'content_' . $i; + $reg[$var] = array('^' . $r . 'data/background/150/t' . $i . '.jpg$', '^' . $r . 'data/contents/p' . $i . '.svg$'); + } + $reg['urgents'] = array('^' . $r . 'images/(.*)$', '^' . $r . 'data/images/(.*)$', '^' . $r . 'style/fonts/(.*).ttf$'); + return $reg; + } + + protected function _inFirstManifest($p, $orders, $reg) { - $ok = array('^' . $r . 'style/(.*)$', '^' . $r . 'index.html$', '^' . $r . 'images/(.*)$', '^' . $r . 'data/images/(.*)$', '^' . $r . 'data/style/(.*)$', '^' . $r . 'data/(.*).js$'); - foreach ($ok as $v) { - if (preg_match('|' . $v . '|i', $p)) { - fb('ok : ' . $v, $p); - return 0; + + foreach ($orders as $list) { + foreach ($reg[$list] as $v) { + if (preg_match('|' . $v . '|', $p)) { + fb($p); + if ($p == '11461/data/background/150/t25.jpg') { + fb($reg[$list]); + fb($v); + } + return $list; + } } } - return 1; + return $list; + } + + protected function _getBundles($book) { + $res = array(0 => 'loading', 200001 => 'extras', 20000 => 'thumbnails', 1 => 'urgents'); + for ($i = 1; $i <= $book->parametres->pages; $i++) { + $k = 2 + $i; + $res[$k] = 'content_' . $i; + } + return $res; } public function collectionPushRegister() { diff --git a/inc/ws/Util/class.ws.tools.php b/inc/ws/Util/class.ws.tools.php index c5260e483..5f3b94ed3 100644 --- a/inc/ws/Util/class.ws.tools.php +++ b/inc/ws/Util/class.ws.tools.php @@ -22,7 +22,7 @@ class wsTools { $webvideo->execute(); } - public static function colorizeAndRasterizeIcon($iconSet, $icon, $colors, $dest, $scale, &$w, &$h) { + public static function colorizeAndRasterizeIcon($iconSet, $icon, $colors, $dest, $scale, &$w, &$h, $makepng = true) { // Init directory if (is_string($colors)) { $colors = array('colorize' => $colors); @@ -102,7 +102,9 @@ class wsTools { $w = $dim[0] / $scale; $h = $dim[1] / $scale; - self::copy($png, $dest . '/' . $icon . '.png'); + if ($makepng) { + self::copy($png, $dest . '/' . $icon . '.png'); + } } public static function copy($source, $dest) { diff --git a/inc/ws/Util/html5/class.ws.html5.compiler.php b/inc/ws/Util/html5/class.ws.html5.compiler.php index 9c9176c9b..997287f68 100644 --- a/inc/ws/Util/html5/class.ws.html5.compiler.php +++ b/inc/ws/Util/html5/class.ws.html5.compiler.php @@ -17,7 +17,7 @@ class wsHTML5Compiler { } } - protected static $resolutions = array(150, 36); + protected static $resolutions = array(150); protected static $uaPrefixes = array('-moz-', '-webkit-', '-o-', '-ms-', ''); public $jsFiles = array( 'js/libs/fix/ios-orientation.js', @@ -37,6 +37,8 @@ class wsHTML5Compiler { 'js/libs/jquery/jquery.localscroll.js', 'js/libs/gsap/TweenMax.js', 'js/libs/gsap/jquery.gsap.js', + 'js/libs/gal/gal.js', + 'js/libs/gal/gal.filesystem.js', 'js/libs/fluidbook/fluidbook.utils.js', 'js/libs/fluidbook/fluidbook.support.js', 'js/libs/fluidbook/fluidbook.video.js', @@ -789,6 +791,16 @@ class wsHTML5Compiler { file_put_contents($this->vdir . '/data/search.js', $js); } + public function supportSVG() { + if (!$this->phonegap) { + return false; + } else if ($this->phonegap == 'ios') { + return true; + } else { + return false; + } + } + protected function writeConfig() { $this->config->numerotation = explode(',', $this->book->numerotation); $this->config->id = $this->book->book_id; @@ -826,9 +838,16 @@ class wsHTML5Compiler { $this->config->navOrder = $navOrder; $this->config->standalone = $this->standalone; + if ($this->config->phonegap) { + $this->config->manifest = $this->writeManifest(); + } return 'var DATAS=' . json_encode($this->config) . ';' . "\n"; } + protected function writeManifest() { + $res=array(); + } + protected function writeIcons() { $res = array(); // Get the colors used to colorize graphics @@ -857,8 +876,9 @@ class wsHTML5Compiler { ); $this->config->iconsDimensions = array(); + $makepng = !$this->supportSVG(); foreach ($icons as $icon => $color) { - wsTools::colorizeAndRasterizeIcon($this->theme->parametres->iconSet, $icon, $color, $this->vdir . '/data/images/', 4, $w, $h); + wsTools::colorizeAndRasterizeIcon($this->theme->parametres->iconSet, $icon, $color, $this->vdir . '/data/images/', 4, $w, $h, $makepng); $this->config->iconsDimensions[$icon] = array($w, $h); } return $res; @@ -888,6 +908,10 @@ class wsHTML5Compiler { $this->copy(WS_DOCS . '/' . $infos['document_id'] . '/html/' . $srcPrefix . $r . '-' . $infos['document_page'] . '.jpg', $this->vdir . '/data/background/' . $r . '/' . $this->backgroundsPrefix . $page . '.jpg'); } $this->copy(WS_DOCS . '/' . $infos['document_id'] . '/p' . $infos['document_page'] . '.jpg', $this->vdir . '/data/thumbnails/p' . $page . '.jpg'); + + if ($page == 1) { + $this->copy(WS_DOCS . '/' . $infos['document_id'] . '/html/t36-' . $infos['document_page'] . '.jpg', $this->vdir . '/cover.jpg'); + } } } -- 2.39.5