protected $infos;
protected $cropped;
protected $rgb;
+ protected $filesdata = null;
protected static $_docsDir;
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';
if (count($e) > 1) {
$resolution = $e[0];
$quality = $e[1];
- }else{
- $quality=85;
+ } else {
+ $quality = 85;
}
if ($resolution === 'thumb') {
public function __destruct()
{
-
+ if (null !== $this->filesdata) {
+ file_put_contents($this->out . '/filesdata.json', json_encode($this->filesdata));
+ }
}
public static function getDir($id)
}\r
\r
\r
-\r
$res = [];\r
foreach ($worksheet as $i => $line) {\r
if ($i === 0) {\r
/**\r
* @param $book wsBook\r
*/\r
- public static function compilePDF($book, $pages = null)\r
+ public static function compilePDF($book, $pages = null, $log = null)\r
{\r
global $core;\r
\r
foreach ($pages as $i => $infos) {\r
$doc = wsDocument::getDir($infos['document_id']) . 'crop.pdf';\r
if (file_exists($doc) && filemtime($doc) > $fmtime) {\r
+ if (null !== $log) {\r
+ $log->log('PDF File invalide : one most recent ' . $infos['document_id']);\r
+ }\r
$invalid = true;\r
+ break;\r
}\r
}\r
} else {\r
+ if (null !== $log) {\r
+ $log->log('PDF File invalide : recent composition change');\r
+ }\r
$invalid = true;\r
}\r
} else {\r
+ if (null !== $log) {\r
+ $log->log('PDF File invalide : original not exists');\r
+ }\r
$invalid = true;\r
}\r
\r
+ if (null !== $log) {\r
+ $log->log('PDF File invalide : ' . $invalid);\r
+ }\r
\r
if ($invalid) {\r
\r
if (file_exists($originalPDF)) {\r
- self::copy($originalPDF, $cacheDir . '/original.' . TIME . '.pdf');\r
+ self::copy($originalPDF, $cacheDir . '/original.' . TIME . '.pdf', false);\r
}\r
\r
$pdfList = array();\r
}\r
\r
if ($original) {\r
- self::copy(wsDocument::getDir($firstDoc) . 'crop.pdf', $originalPDF);\r
+ self::copy(wsDocument::getDir($firstDoc) . 'crop.pdf', $originalPDF, false);\r
} else {\r
$args = '';\r
foreach ($pdfList as $doc => $index) {\r
$cached = WS_BOOKS . '/pdf/' . $hash . '.pdf';\r
\r
if (file_exists($cached) && filesize($cached) > 0) {\r
- self::copy($cached, $originalPDF);\r
+ self::copy($cached, $originalPDF, false);\r
} else {\r
$pdftk = new cubeCommandLine('pdftk');\r
$pdftk->setPath(CONVERTER_PATH);\r
$pdftk->setManualArg($args);\r
$pdftk->execute();\r
- self::copy($normalPDF, $cached);\r
+ self::copy($normalPDF, $cached, false);\r
}\r
}\r
}\r
$replace = $book->getAssetDir() . $book->parametres->pdfReplace;\r
if (file_exists($replace) && filesize($replace) > 0) {\r
if (!file_exists($normalPDF) || filemtime($normalPDF) < filemtime($replace) || filesize($normalPDF) != filesize($replace)) {\r
- self::copy($replace, $normalPDF);\r
+ self::copy($replace, $normalPDF, false);\r
}\r
}\r
} else {\r
- self::copy($originalPDF, $normalPDF);\r
+ self::copy($originalPDF, $normalPDF, false);\r
}\r
\r
if ($book->parametres->pdfCompress) {\r
return $normalPDF;\r
}\r
\r
- public static function copy($source, $dest)\r
+ public static function copy($source, $dest, $sourceTouch = true)\r
{\r
if (file_exists($source)) {\r
copy($source, $dest);\r
- touch($dest, filemtime($source));\r
+ if ($sourceTouch) {\r
+ touch($dest, filemtime($source));\r
+ }\r
}\r
}\r
}
\ No newline at end of file
public $accessibleTexts = [];
protected $_svgSymbols = [];
+ protected $_docDimensions = [];
+
public $_signature;
/**
* @var wsHTML5Seo
}
$style = implode("\n\t\t", $style);
+ $this->log('Got index vars 1');
+
$pagesContents = '';
$cache = '';
}
$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 = '<meta name="description" content="' . $this->seo->pages[1]->description . '">';
<meta property="og:image:width" content="' . $socialImageWidth . '"/>
<meta property="og:image:height" content="' . $socialImageHeight . '"/>';
+ $this->log('Got index vars 3');
+
$favicon = '';
$hasIos = false;
//if ($iosico = $this->checkThemeImage($this->theme->parametres->iosicon)) {
$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;
$csp = "<meta http-equiv=\"Content-Security-Policy\" content=\"default-src 'self' data: gap: 'unsafe-inline' *; style-src 'self' 'unsafe-inline'; font-src 'self' data:; script-src 'self' 'unsafe-inline' 'unsafe-eval' " . implode(' ', array_unique($this->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 = [];
}
}
$this->_indexVars = $res;
+ $this->log('Got index vars 6');
}
return $this->_indexVars;
}
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 '';
}
$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)) {
protected function writeImages()
{
global $core;
- $daoDoc = new wsDAODocument($core->con);
+
switch ($this->book->parametres->mobileVersion) {
case 'html5-desktop':
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);
}
$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);