From 7cbec2e9d00af9584e9f086b8ebe385ce9f12b10 Mon Sep 17 00:00:00 2001 From: "vincent@cubedesigners.com" Date: Sat, 17 Mar 2012 23:50:06 +0000 Subject: [PATCH] --- .../Controlleur/class.extranet.url.php | 5 +- inc/ws/Controlleur/class.ws.url.php | 66 ++++++++--- inc/ws/Util/html5/class.ws.html5.compiler.php | 111 ++++++++++++++---- .../Util/packager/class.ws.packager.html.php | 33 ------ 4 files changed, 143 insertions(+), 72 deletions(-) diff --git a/inc/extranet/Controlleur/class.extranet.url.php b/inc/extranet/Controlleur/class.extranet.url.php index 0cd27a218..4301d05d6 100644 --- a/inc/extranet/Controlleur/class.extranet.url.php +++ b/inc/extranet/Controlleur/class.extranet.url.php @@ -620,13 +620,12 @@ class extranetUrl { global $core; commonDroits::min(1); $settings = $core->user->getSettings('timereport'); + $res = ''; if (!isset($_GET['light'])) { $filtres = array(); $filtres[] = new commonFiltre(__('Participants'), 'equipier_participe', $settings['filtres']); - $res = commonPage::barre($filtres, 'filtreTimereport', 'timereport', null); - + $res .= commonPage::barre($filtres, 'filtreTimereport', 'timereport', null); $res .= commonPage::tMain(); - $res .= commonPage::bh(); } $res .= '
'; diff --git a/inc/ws/Controlleur/class.ws.url.php b/inc/ws/Controlleur/class.ws.url.php index 5a97c0e33..5ad564c33 100644 --- a/inc/ws/Controlleur/class.ws.url.php +++ b/inc/ws/Controlleur/class.ws.url.php @@ -627,12 +627,36 @@ html{height:100%}' . "\n"; } public static function viewerh($args) { + global $core; + $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) . '/'); + + $book_id = $e[0]; + $hash = $e[1]; + + $dao = new wsDAOBook($core->con); + + $book = $dao->selectById($book_id); + if ($hash != 'bcf26f9cf4a795ec00b9a44f42750d58' && $book->hash != $hash) { + commonDroits::error(); + } + + if (!$dao->isUpToDate($book_id)) { + if ($version == 'u' || $version == 't') { + $dao->compileHTML5($book_id); + } else { + $dao->compile($book_id); + $dao->touchCompile($book_id); + } + } + + $time = self::getHTML5CacheTime($book_id); + + if (count($e) == 2 || $e[2] != $time) { + $e[2] = $time; + http::redirect(SITE_PATH . 'viewerh/' . implode('_', $e) . '/index.html'); exit; } @@ -641,13 +665,23 @@ html{height:100%}' . "\n"; self::commonHTML5Viewer($book_id, $hash); } + public static function getHTML5CacheTime($book_id) { + $cacheFile = WS_BOOKS . '/html5/' . $book_id . '/cache.appcache'; + if (file_exists($cacheFile)) { + return filemtime($cacheFile); + } + return TIME; + } + 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; + $time = self::getHTML5CacheTime($e[0]); + + if (count($e) == 2 || $e[2] != $time) { + $e[2] = $time; http::redirect(SITE_PATH . 'viewerhu/' . implode('_', $e) . '/'); exit; } @@ -662,8 +696,10 @@ html{height:100%}' . "\n"; $args = cubePage::getArgs($args); $e = explode('_', $args[0]); - if (count($e) == 2 || $e[2] < TIME - 10) { - $e[2] = TIME; + $time = self::getHTML5CacheTime($e[0]); + + if (count($e) == 2 || $e[2] != $time) { + $e[2] = $time; http::redirect(SITE_PATH . 'viewerht/' . implode('_', $e) . '/'); exit; } @@ -770,14 +806,14 @@ html{height:100%}' . "\n"; $dao = new wsDAOBook($core->con); $book = $dao->selectById($book_id); - if(!wsDroits::admin()){ - if ($book->parametres->redirectDemo != '') { - http::redirect($book->parametres->redirectDemo); - exit; - } - if ($book->parametres->disableDemo) { - commonDroits::error(); - } + if (!wsDroits::admin()) { + if ($book->parametres->redirectDemo != '') { + http::redirect($book->parametres->redirectDemo); + exit; + } + if ($book->parametres->disableDemo) { + commonDroits::error(); + } } if ($hash != 'bcf26f9cf4a795ec00b9a44f42750d58' && $book->hash != $hash) { diff --git a/inc/ws/Util/html5/class.ws.html5.compiler.php b/inc/ws/Util/html5/class.ws.html5.compiler.php index ddb1fa39b..951f1596d 100644 --- a/inc/ws/Util/html5/class.ws.html5.compiler.php +++ b/inc/ws/Util/html5/class.ws.html5.compiler.php @@ -62,6 +62,7 @@ class wsHTML5Compiler { protected $additionalConfig = array(); protected $fontScale = 1; protected $cache = array(); + protected $backgroundsPrefix = 'p'; function __construct($book_id) { global $core; @@ -85,6 +86,10 @@ class wsHTML5Compiler { $this->book = $this->daoBook->selectById($book_id); $this->pages = $this->daoBook->getPagesOfBook($book_id); + if ($this->book->parametres->mobileVersion == 'html5-images') { + $this->backgroundsPrefix = 't'; + } + $daoTheme = new wsDAOTheme($core->con); $this->theme = $daoTheme->getThemeOfBook($book_id, true); $this->themeRoot = WS_THEMES . '/' . $this->theme->theme_id . '/'; @@ -98,7 +103,7 @@ class wsHTML5Compiler { $imagesize = getimagesize(WS_DOCS . '/' . $this->pages[1]['document_id'] . '/html/h150-' . $this->pages[1]['document_page'] . '.jpg'); - $this->pdf2htmlRatio = round(($imagesize[0]*0.48) / $this->width, 2); + $this->pdf2htmlRatio = round(($imagesize[0] * 0.48) / $this->width, 2); $this->cssScale = min($this->optimalWidth / $this->width, $this->optimalHeight / $this->height); $this->cssOneScale = min(($this->optimalWidth * 2) / $this->width, $this->optimalHeight / $this->height); @@ -131,15 +136,6 @@ class wsHTML5Compiler { } public function compile() { - foreach ($this->layouts as $page => $layout) { - $lines = $this->sortPage($layout); - $document_id = $this->pages[$page]['document_id']; - $this->div[$page] = array(); - foreach ($lines as $line) { - $this->div[$page][] = $this->addLine($line, $document_id); - } - } - $dirsToCreate = array('data/images', 'data/contents', 'data/background', 'data/thumbnails', 'data/style', 'data/links/pages', 'data/l10n', 'swf'); foreach ($dirsToCreate as $dir) { @@ -167,6 +163,77 @@ class wsHTML5Compiler { $this->writeLangs(); $this->writeIndex($numCSS); $this->writeJs(); + $this->writeCache(); + } + + protected function writeCache() { + $ignore = array('data/l10n/([a-z-]{2,5}).json', '(.*).ogv', '(.*).flv', '(.*).mp4', '(.*).webm'); + + $cacheFile = $this->vdir . '/cache.appcache'; + + if (file_exists($cacheFile)) { + unlink($cacheFile); + } + + $dest = realpath($this->vdir); + $lines = array(); + + $network = array('NETWORK:','*'); + + $lines[] = 'CACHE MANIFEST'; + $lines[] = '# ' . date('Y-m-d H:i:s'); + $lines[] = ''; + $lines[] = 'index.html'; + $lines[] = ''; + $lines[] = 'FALLBACK:'; + $lines[] = '/ index.html'; + $lines[] = 'index.html* index.html'; + $lines[] = ''; + $lines[] = 'CACHE:'; + //$lines[] = 'index.html'; + $assets = array('images', 'style', 'swf', 'data/l10n', 'data/style', 'data/images', 'data/fluidbook.js'); + + $pages = $this->book->parametres->pages + 1; + + for ($i = 0; $i <= $pages; $i++) { + + $assets[] = 'data/background/150/' . $this->backgroundsPrefix . $i . '.jpg'; + $assets[] = 'data/links/pages/p' . $i . '.html'; + $assets[] = 'data/contents/p' . $i . '.svg'; + } + $assets[] = 'data/thumbnails'; + $assets[] = 'data/links'; + + foreach ($assets as $a) { + $ap = $dest . '/' . $a; + + if (!file_exists($ap)) { + continue; + } + if (is_file($ap)) { + $lines[] = str_replace($dest . '/', '', $ap); + } else if (is_dir($ap)) { + $iterator = new RecursiveDirectoryIterator($ap); + foreach ($iterator as $path) { + if (!$path->isFile()) { + continue; + } + $p = str_replace($dest . '/', '', $path); + foreach ($ignore as $i) { + if (preg_match('|' . $i . '|i', $p, $matches)) { + $network[] = $p; + continue 2; + } + } + $lines[] = $p; + } + } + } + + $lines[] = ''; + $lines = array_merge($lines, $network); + + file_put_contents($cacheFile, implode("\n", $lines)); } protected function writeIndex($numCSS) { @@ -191,9 +258,11 @@ class wsHTML5Compiler { } $style = implode("\n\t\t", $style); + $pagesContents = ''; + $script = ''; - $vars = array('titre', 'credits', 'ga', 'style', 'script'); + $vars = array('titre', 'credits', 'ga', 'style', 'script', 'pagesContents'); foreach ($vars as $v) { $html = str_replace('', $$v, $html); } @@ -214,7 +283,7 @@ class wsHTML5Compiler { $thtml = $uhtml; - $vars = array('titre', 'credits', 'ga', 'style', 'script'); + $vars = array('titre', 'credits', 'ga', 'style', 'script', 'pagesContents'); foreach ($vars as $v) { $uhtml = str_replace('', $$v, $uhtml); } @@ -358,22 +427,21 @@ class wsHTML5Compiler { } foreach ($this->pages as $page => $infos) { foreach (self::$resolutions as $r) { - $this->copy(WS_DOCS . '/' . $infos['document_id'] . '/html/h' . $r . '-' . $infos['document_page'] . '.jpg', $this->vdir . '/data/background/' . $r . '/p' . $page . '.jpg'); - $this->copy(WS_DOCS . '/' . $infos['document_id'] . '/html/t' . $r . '-' . $infos['document_page'] . '.jpg', $this->vdir . '/data/background/' . $r . '/t' . $page . '.jpg'); + $this->copy(WS_DOCS . '/' . $infos['document_id'] . '/html/' . $this->backgroundsPrefix . $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'); } } - - protected function copy($s,$t){ - if(!file_exists($s)){ + + protected function copy($s, $t) { + if (!file_exists($s)) { return; } - if(file_exists($t) && filemtime($t)>=filemtime($s) && filesize($s)==filesize($t)){ + if (file_exists($t) && filemtime($t) >= filemtime($s) && filesize($s) == filesize($t)) { return; } - - copy($s,$t); + + copy($s, $t); } protected function writeCSS($file, $links) { @@ -572,6 +640,7 @@ class wsHTML5Compiler { } while ($val > 0); return $str; } + public function copyLinkFile($source, $dest, $video = false) { $origDir = WS_BOOKS . '/working/' . $this->book_id . '/'; $types = array('flv', 'mp4', 'ogv', 'webm', 'jpg'); @@ -597,7 +666,7 @@ class wsHTML5Compiler { if (!file_exists(dirname($d))) { mkdir(dirname($d), 0777, true); } - if(file_exists($d) && filemtime($d)>=filemtime($s) && filesize($d)==filesize($s)){ + if (file_exists($d) && filemtime($d) >= filemtime($s) && filesize($d) == filesize($s)) { continue; } copy($s, $d); diff --git a/inc/ws/Util/packager/class.ws.packager.html.php b/inc/ws/Util/packager/class.ws.packager.html.php index f2f6614d7..1548366ba 100644 --- a/inc/ws/Util/packager/class.ws.packager.html.php +++ b/inc/ws/Util/packager/class.ws.packager.html.php @@ -190,39 +190,6 @@ class wsPackagerHTML extends wsPackager { $rm->setArg(null, $dest . '/' . $f); } $rm->execute(); - - $this->writeHTML5Cache($dest); - } - - public function writeHTML5Cache($dest) { - $ignore = array('data/l10n/([a-z-]{2,5}).json'); - - $dest = realpath($dest); - $lines = array(); - $lines[] = 'CACHE MANIFEST'; - $lines[] = '# ' . date('Y-m-d H:i:s'); - $lines[] = ''; - $lines[] = 'CACHE:'; - $lines[] = 'index.html'; - $dir = array('images', 'data', 'style'); - foreach ($dir as $d) { - $directory = $dest . '/' . $d; - - $iterator = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($directory), RecursiveIteratorIterator::CHILD_FIRST); - foreach ($iterator as $path) { - if (!$path->isFile()) { - continue; - } - $p = str_replace($dest . '/', '', $path); - foreach ($ignore as $i) { - if (preg_match('|' . $i . '|i', $p, $matches)) { - continue 2; - } - } - $lines[] = $p; - } - } - file_put_contents($dest . '/cache.appcache', implode("\n", $lines)); } public function makePackage($zip) { -- 2.39.5