]> _ Git - cubeextranet.git/commitdiff
wip #4367 @3
authorvincent@cubedesigners.com <vincent@cubedesigners.com@f5622870-0f3c-0410-866d-9cb505b7a8ef>
Tue, 23 Nov 2021 15:08:56 +0000 (15:08 +0000)
committervincent@cubedesigners.com <vincent@cubedesigners.com@f5622870-0f3c-0410-866d-9cb505b7a8ef>
Tue, 23 Nov 2021 15:08:56 +0000 (15:08 +0000)
inc/ws/Controlleur/class.ws.services.php
inc/ws/Metier/class.ws.document.php
inc/ws/Util/class.ws.util.php
inc/ws/Util/html5/master/class.ws.html5.compiler.php

index a265b45e69986860ee2fa8b9a9f63ce37c5110e8..29594c6893c9eeb4fe6806df49a3997d61ab9102 100644 (file)
@@ -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;
     }
index a6a3f007ab4e9aa70655d1463fdcfd78eb20786c..4e637c18df3b6d93da35b0105c4f9c7cf410ac78 100644 (file)
@@ -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)
index 06f27ded0412cf0489c14b8153dc67f3e2115e2e..e89aa300db08e19a19cf4e02da1132ea11edfd55 100644 (file)
@@ -142,7 +142,6 @@ class wsUtil
         }\r
 \r
 \r
-\r
         $res = [];\r
         foreach ($worksheet as $i => $line) {\r
             if ($i === 0) {\r
@@ -254,7 +253,7 @@ class wsUtil
     /**\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
@@ -291,21 +290,34 @@ class wsUtil
                 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
@@ -337,7 +349,7 @@ class wsUtil
             }\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
@@ -402,13 +414,13 @@ class wsUtil
                 $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
@@ -418,11 +430,11 @@ class wsUtil
             $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
@@ -447,11 +459,13 @@ class wsUtil
         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
index 62fcfb0ec5c781070b382a0b4155a754370af826..e093785d55df143361c119016f66fcabec864043 100644 (file)
@@ -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"></iframe></noscript>
             }
             $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"></iframe></noscript>
             }
             $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 . '">';
@@ -1369,6 +1387,8 @@ height="0" width="0" style="display:none;visibility:hidden"></iframe></noscript>
        <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)) {
@@ -1409,6 +1429,8 @@ height="0" width="0" style="display:none;visibility:hidden"></iframe></noscript>
             $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"></iframe></noscript>
                 $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 = [];
@@ -1442,6 +1466,7 @@ height="0" width="0" style="display:none;visibility:hidden"></iframe></noscript>
                 }
             }
             $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"></iframe></noscript>
             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"></iframe></noscript>
                 $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"></iframe></noscript>
     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"></iframe></noscript>
             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"></iframe></noscript>
         $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);