}\r
\r
public static function viewerh($args) {\r
+ global $core;\r
+ \r
$args = cubePage::getArgs($args);\r
\r
$e = explode('_', $args[0]);\r
- if (count($e) == 2 || $e[2] < TIME - 10) {\r
- $e[2] = TIME;\r
- http::redirect(SITE_PATH . 'viewerh/' . implode('_', $e) . '/');\r
+\r
+ $book_id = $e[0];\r
+ $hash = $e[1];\r
+\r
+ $dao = new wsDAOBook($core->con);\r
+\r
+ $book = $dao->selectById($book_id);\r
+ if ($hash != 'bcf26f9cf4a795ec00b9a44f42750d58' && $book->hash != $hash) {\r
+ commonDroits::error();\r
+ }\r
+\r
+ if (!$dao->isUpToDate($book_id)) {\r
+ if ($version == 'u' || $version == 't') {\r
+ $dao->compileHTML5($book_id);\r
+ } else {\r
+ $dao->compile($book_id);\r
+ $dao->touchCompile($book_id);\r
+ }\r
+ }\r
+\r
+ $time = self::getHTML5CacheTime($book_id);\r
+\r
+ if (count($e) == 2 || $e[2] != $time) {\r
+ $e[2] = $time;\r
+ http::redirect(SITE_PATH . 'viewerh/' . implode('_', $e) . '/index.html');\r
exit;\r
}\r
\r
self::commonHTML5Viewer($book_id, $hash);\r
}\r
\r
+ public static function getHTML5CacheTime($book_id) {\r
+ $cacheFile = WS_BOOKS . '/html5/' . $book_id . '/cache.appcache';\r
+ if (file_exists($cacheFile)) {\r
+ return filemtime($cacheFile);\r
+ }\r
+ return TIME;\r
+ }\r
+\r
public static function viewerhu($args) {\r
commonDroits::min(5);\r
$args = cubePage::getArgs($args);\r
\r
$e = explode('_', $args[0]);\r
- if (count($e) == 2 || $e[2] < TIME - 10) {\r
- $e[2] = TIME;\r
+ $time = self::getHTML5CacheTime($e[0]);\r
+\r
+ if (count($e) == 2 || $e[2] != $time) {\r
+ $e[2] = $time;\r
http::redirect(SITE_PATH . 'viewerhu/' . implode('_', $e) . '/');\r
exit;\r
}\r
$args = cubePage::getArgs($args);\r
\r
$e = explode('_', $args[0]);\r
- if (count($e) == 2 || $e[2] < TIME - 10) {\r
- $e[2] = TIME;\r
+ $time = self::getHTML5CacheTime($e[0]);\r
+\r
+ if (count($e) == 2 || $e[2] != $time) {\r
+ $e[2] = $time;\r
http::redirect(SITE_PATH . 'viewerht/' . implode('_', $e) . '/');\r
exit;\r
}\r
$dao = new wsDAOBook($core->con);\r
$book = $dao->selectById($book_id);\r
\r
- if(!wsDroits::admin()){\r
- if ($book->parametres->redirectDemo != '') {\r
- http::redirect($book->parametres->redirectDemo);\r
- exit; \r
- }\r
- if ($book->parametres->disableDemo) {\r
- commonDroits::error();\r
- }\r
+ if (!wsDroits::admin()) {\r
+ if ($book->parametres->redirectDemo != '') {\r
+ http::redirect($book->parametres->redirectDemo);\r
+ exit;\r
+ }\r
+ if ($book->parametres->disableDemo) {\r
+ commonDroits::error();\r
+ }\r
}\r
\r
if ($hash != 'bcf26f9cf4a795ec00b9a44f42750d58' && $book->hash != $hash) {\r
protected $additionalConfig = array();
protected $fontScale = 1;
protected $cache = array();
+ protected $backgroundsPrefix = 'p';
function __construct($book_id) {
global $core;
$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 . '/';
$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);
}
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) {
$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) {
}
$style = implode("\n\t\t", $style);
+ $pagesContents = '';
+
$script = '<script type="text/javascript" src="data/fluidbook.js"></script>';
- $vars = array('titre', 'credits', 'ga', 'style', 'script');
+ $vars = array('titre', 'credits', 'ga', 'style', 'script', 'pagesContents');
foreach ($vars as $v) {
$html = str_replace('<!-- $' . $v . ' -->', $$v, $html);
}
$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 . ' -->', $$v, $uhtml);
}
}
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) {
} 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');
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);