From 97a1474d28247aee7ec78434179bd4cdac32102e Mon Sep 17 00:00:00 2001 From: "vincent@cubedesigners.com" Date: Tue, 23 Nov 2021 15:08:56 +0000 Subject: [PATCH] wip #4367 @3 --- inc/ws/Controlleur/class.ws.services.php | 6 +- inc/ws/Metier/class.ws.document.php | 32 ++++++++++- inc/ws/Util/class.ws.util.php | 34 ++++++++---- .../html5/master/class.ws.html5.compiler.php | 55 ++++++++++++++++--- 4 files changed, 104 insertions(+), 23 deletions(-) diff --git a/inc/ws/Controlleur/class.ws.services.php b/inc/ws/Controlleur/class.ws.services.php index a265b45e6..29594c689 100644 --- a/inc/ws/Controlleur/class.ws.services.php +++ b/inc/ws/Controlleur/class.ws.services.php @@ -204,7 +204,6 @@ class wsServices extends cubeFlashGateway //die($limit . ':' . $book->changedate . '//' . filemtime($cover)); if (isset($_GET['force']) || !file_exists($cover) || filemtime($cover) < $limit || filesize($cover) < $minsize) { - $lock = WS_BOOKS . '/locks/' . $id . '.social_screenshot'; if (!file_exists($lock) || filemtime($lock) < time() - 3600) { touch($lock); @@ -237,6 +236,11 @@ class wsServices extends cubeFlashGateway } } + $sizeFile = WS_FILES . '/social_image/' . $id . '.size'; + if (!file_exists($sizeFile) || filemtime($sizeFile) < filemtime($cover)) { + file_put_contents($sizeFile, json_encode(CubeIT_Image::getimagesize($cover))); + } + cubeHTTP::relayFile($cover); exit; } diff --git a/inc/ws/Metier/class.ws.document.php b/inc/ws/Metier/class.ws.document.php index a6a3f007a..4e637c18d 100644 --- a/inc/ws/Metier/class.ws.document.php +++ b/inc/ws/Metier/class.ws.document.php @@ -42,6 +42,7 @@ class wsDocument extends cubeMetier protected $infos; protected $cropped; protected $rgb; + protected $filesdata = null; protected static $_docsDir; @@ -414,7 +415,30 @@ class wsDocument extends cubeMetier return false; } + public function getFilesData() + { + if ($this->filesdata === null) { + $f = $this->out . '/filesdata.json'; + if (file_exists($f)) { + $this->filesdata = json_decode(file_get_contents($f), true); + } else { + $this->filesdata = []; + } + } + return $this->filesdata; + } + public function getFile($page, $format = 'jpg', $resolution = 150, $withText = true, $withGraphics = true, $version = 'html', $force = false) + { + $this->getFilesData(); + $cacheKey = $page . '_' . $format . '_' . $resolution . '_' . ($withText ? '1' : '0') . '_' . ($withGraphics ? '1' : '0') . '_' . $version; + if (!isset($this->filesdata[$cacheKey]) || $force) { + $this->filesdata[$cacheKey] = $this->_getFile($page, $format, $resolution, $withText, $withGraphics, $version, $force); + } + return $this->filesdata[$cacheKey]; + } + + public function _getFile($page, $format = 'jpg', $resolution = 150, $withText = true, $withGraphics = true, $version = 'html', $force = false) { if ($format === 'jpeg') { $format = 'jpg'; @@ -500,8 +524,8 @@ class wsDocument extends cubeMetier if (count($e) > 1) { $resolution = $e[0]; $quality = $e[1]; - }else{ - $quality=85; + } else { + $quality = 85; } if ($resolution === 'thumb') { @@ -705,7 +729,9 @@ class wsDocument extends cubeMetier public function __destruct() { - + if (null !== $this->filesdata) { + file_put_contents($this->out . '/filesdata.json', json_encode($this->filesdata)); + } } public static function getDir($id) diff --git a/inc/ws/Util/class.ws.util.php b/inc/ws/Util/class.ws.util.php index 06f27ded0..e89aa300d 100644 --- a/inc/ws/Util/class.ws.util.php +++ b/inc/ws/Util/class.ws.util.php @@ -142,7 +142,6 @@ class wsUtil } - $res = []; foreach ($worksheet as $i => $line) { if ($i === 0) { @@ -254,7 +253,7 @@ class wsUtil /** * @param $book wsBook */ - public static function compilePDF($book, $pages = null) + public static function compilePDF($book, $pages = null, $log = null) { global $core; @@ -291,21 +290,34 @@ class wsUtil foreach ($pages as $i => $infos) { $doc = wsDocument::getDir($infos['document_id']) . 'crop.pdf'; if (file_exists($doc) && filemtime($doc) > $fmtime) { + if (null !== $log) { + $log->log('PDF File invalide : one most recent ' . $infos['document_id']); + } $invalid = true; + break; } } } else { + if (null !== $log) { + $log->log('PDF File invalide : recent composition change'); + } $invalid = true; } } else { + if (null !== $log) { + $log->log('PDF File invalide : original not exists'); + } $invalid = true; } + if (null !== $log) { + $log->log('PDF File invalide : ' . $invalid); + } if ($invalid) { if (file_exists($originalPDF)) { - self::copy($originalPDF, $cacheDir . '/original.' . TIME . '.pdf'); + self::copy($originalPDF, $cacheDir . '/original.' . TIME . '.pdf', false); } $pdfList = array(); @@ -337,7 +349,7 @@ class wsUtil } if ($original) { - self::copy(wsDocument::getDir($firstDoc) . 'crop.pdf', $originalPDF); + self::copy(wsDocument::getDir($firstDoc) . 'crop.pdf', $originalPDF, false); } else { $args = ''; foreach ($pdfList as $doc => $index) { @@ -402,13 +414,13 @@ class wsUtil $cached = WS_BOOKS . '/pdf/' . $hash . '.pdf'; if (file_exists($cached) && filesize($cached) > 0) { - self::copy($cached, $originalPDF); + self::copy($cached, $originalPDF, false); } else { $pdftk = new cubeCommandLine('pdftk'); $pdftk->setPath(CONVERTER_PATH); $pdftk->setManualArg($args); $pdftk->execute(); - self::copy($normalPDF, $cached); + self::copy($normalPDF, $cached, false); } } } @@ -418,11 +430,11 @@ class wsUtil $replace = $book->getAssetDir() . $book->parametres->pdfReplace; if (file_exists($replace) && filesize($replace) > 0) { if (!file_exists($normalPDF) || filemtime($normalPDF) < filemtime($replace) || filesize($normalPDF) != filesize($replace)) { - self::copy($replace, $normalPDF); + self::copy($replace, $normalPDF, false); } } } else { - self::copy($originalPDF, $normalPDF); + self::copy($originalPDF, $normalPDF, false); } if ($book->parametres->pdfCompress) { @@ -447,11 +459,13 @@ class wsUtil return $normalPDF; } - public static function copy($source, $dest) + public static function copy($source, $dest, $sourceTouch = true) { if (file_exists($source)) { copy($source, $dest); - touch($dest, filemtime($source)); + if ($sourceTouch) { + touch($dest, filemtime($source)); + } } } } \ No newline at end of file diff --git a/inc/ws/Util/html5/master/class.ws.html5.compiler.php b/inc/ws/Util/html5/master/class.ws.html5.compiler.php index 62fcfb0ec..e093785d5 100644 --- a/inc/ws/Util/html5/master/class.ws.html5.compiler.php +++ b/inc/ws/Util/html5/master/class.ws.html5.compiler.php @@ -225,6 +225,8 @@ class wsHTML5Compiler public $accessibleTexts = []; protected $_svgSymbols = []; + protected $_docDimensions = []; + public $_signature; /** * @var wsHTML5Seo @@ -1317,6 +1319,8 @@ height="0" width="0" style="display:none;visibility:hidden"> } $style = implode("\n\t\t", $style); + $this->log('Got index vars 1'); + $pagesContents = ''; $cache = ''; @@ -1347,13 +1351,27 @@ height="0" width="0" style="display:none;visibility:hidden"> } $script .= $iscript; + $this->log('Got index vars 2'); + $socialTitle = html::escapeHTML($this->book->parametres->facebook_title ? $this->book->parametres->facebook_title : $titre); $socialDescription = html::escapeHTML($this->book->parametres->facebook_description ? $this->book->parametres->facebook_description : $this->book->parametres->seoDescription); - $socialImage = 'https://workshop.fluidbook.com/services/facebook_thumbnail?cid=' . $this->book->cid . '&j=' . TIME; - $dim = CubeIT_Image::getimagesize($socialImage); + + $socialImage = 'https://workshop.fluidbook.com/services/facebook_thumbnail?cid=' . $this->book->cid; + $sizeFile = WS_FILES . '/social_image/' . $this->book->book_id . '.size'; + if (!file_exists($sizeFile)) { + $dim = CubeIT_Image::getimagesize($socialImage); + file_put_contents($sizeFile, json_encode($dim)); + $this->log('Got index vars (measure social image)'); + } else { + $dim = json_decode(file_get_contents($sizeFile), true); + } + $socialImageWidth = $dim[0]; $socialImageHeight = $dim[1]; + $this->log('Got index vars 2.5'); + + $titre = $this->book->parametres->title; $description = ''; @@ -1369,6 +1387,8 @@ height="0" width="0" style="display:none;visibility:hidden"> '; + $this->log('Got index vars 3'); + $favicon = ''; $hasIos = false; //if ($iosico = $this->checkThemeImage($this->theme->parametres->iosicon)) { @@ -1409,6 +1429,8 @@ height="0" width="0" style="display:none;visibility:hidden"> $print = $this->writePrint(); $message = sprintf($this->__('Your browser is not up to date and is not able to run this publication. %sLearn more%s'), ''); + $this->log('Got index vars 4'); + $splash = ''; $splashstyles = ''; $img = $this->book->parametres->splashImage; @@ -1431,6 +1453,8 @@ height="0" width="0" style="display:none;visibility:hidden"> $csp = "securityPolicyWhitelist)) . "; img-src * data:\">"; } $lang = $this->book->lang; + + $this->log('Got index vars 5'); $vars = array('lang', 'titre', 'credits', 'style', 'script', 'pagesContents', 'print', 'hiddenContents', 'splash', 'splashstyles', 'cache', 'bgcolor', 'message', 'favicon', 'svg', 'beginbody', 'csp', 'opengraph', 'twittercard', 'description'); $res = []; @@ -1442,6 +1466,7 @@ height="0" width="0" style="display:none;visibility:hidden"> } } $this->_indexVars = $res; + $this->log('Got index vars 6'); } return $this->_indexVars; } @@ -1605,10 +1630,11 @@ height="0" width="0" style="display:none;visibility:hidden"> return; } - $res = wsUtil::compilePDF($this->book, $this->pages); + $res = wsUtil::compilePDF($this->book, $this->pages, $this); if ($res !== false) { $this->vdir->copy($res, 'data/' . $this->book->parametres->pdfName); } + $this->log('Print written'); return ''; } @@ -1872,7 +1898,7 @@ height="0" width="0" style="display:none;visibility:hidden"> $dupData['image'] = ''; $dupData['animation'] = ''; $dupData['to'] = $linkData['image']; - $dupData['image_rollover'] =''; + $dupData['image_rollover'] = ''; $dupData['type'] = 15; $dupData['uid'] = 'i_' . $linkData['uid']; if (wsHTML5Link::isScorm($linkData)) { @@ -2373,7 +2399,7 @@ height="0" width="0" style="display:none;visibility:hidden"> protected function writeImages() { global $core; - $daoDoc = new wsDAODocument($core->con); + switch ($this->book->parametres->mobileVersion) { case 'html5-desktop': @@ -2408,10 +2434,8 @@ height="0" width="0" style="display:none;visibility:hidden"> foreach ($this->getResolutions() as $r) { foreach ($thisbackgroundPrefix as $backgroundsPrefix) { $source = $this->book->getFile($page, $this->imageFormat, $r, $backgroundsPrefix, true, $imdir); - if ($r == $this->maxRes && file_exists($source)) { - $firstDoc = $daoDoc->selectById($infos['document_id']); - $d = $firstDoc->generalInfos['page'][$infos['document_page']]['size']; - $this->config->pagesDimensions[$page] = array($this->cssWidth, $d[1] * ($this->cssWidth / $d[0])); + if ($r === $this->maxRes) { + $this->getPageDimension($infos, $page); } $this->vdir->copy($source, 'data/background/' . $r . '/' . ($backgroundsPrefix ? 't' : 'p') . $page . '.' . $this->imageFormat); } @@ -2433,6 +2457,19 @@ height="0" width="0" style="display:none;visibility:hidden"> $this->log('Made images'); } + + protected function getPageDimension($infos, $page) + { + global $core; + if (!isset($this->_docDimensions[$infos['document_id']])) { + $daoDoc = new wsDAODocument($core->con); + $firstDoc = $daoDoc->selectById($infos['document_id']); + $this->_docDimensions[$infos['document_id']] = $firstDoc->generalInfos['page']; + } + $d = $this->_docDimensions[$infos['document_id']][$infos['document_page']]['size']; + $this->config->pagesDimensions[$page] = array($this->cssWidth, $d[1] * ($this->cssWidth / $d[0])); + } + protected function _makeCover($orig) { $size = CubeIT_Image::getimagesize($orig); -- 2.39.5