From 2759a915ca8a4e8ee999856341cdbf2318421e5d Mon Sep 17 00:00:00 2001 From: "vincent@cubedesigners.com" Date: Mon, 5 Jun 2023 13:46:20 +0000 Subject: [PATCH] wait #5993 @0.75 --- inc/ws/Controlleur/class.ws.maintenance.php | 2 +- inc/ws/Metier/class.ws.book.php | 17 ++-- inc/ws/Metier/class.ws.document.php | 86 ++++--------------- .../html5/master/class.ws.html5.links.php | 1 - 4 files changed, 24 insertions(+), 82 deletions(-) diff --git a/inc/ws/Controlleur/class.ws.maintenance.php b/inc/ws/Controlleur/class.ws.maintenance.php index 28649b6c4..afb830183 100644 --- a/inc/ws/Controlleur/class.ws.maintenance.php +++ b/inc/ws/Controlleur/class.ws.maintenance.php @@ -1761,7 +1761,7 @@ class wsMaintenance foreach ($files as $file) { echo '

' . json_encode($file) . '

'; - $path = $doc->getFile($page, $file[0], $file[1], $file[2], $file[3], $file[4], true); + $path = $doc->getFile($page, $file[0], $file[1],85, $file[2], $file[3], $file[4], true); echo '

' . $path . '

'; $path = str_replace('/data1/extranet/www/', 'https://workshop.fluidbook.com/', $path); $path = str_replace('/home/extranet/www/', 'https://workshop.fluidbook.com/', $path); diff --git a/inc/ws/Metier/class.ws.book.php b/inc/ws/Metier/class.ws.book.php index 4f8ed212b..df1157b2d 100644 --- a/inc/ws/Metier/class.ws.book.php +++ b/inc/ws/Metier/class.ws.book.php @@ -91,16 +91,13 @@ class wsBook extends cubeMetier $dao = new wsDAODocument($core->con); $this->_docs[$p['document_id']] = $dao->selectById($p['document_id']); } - if ($format === 'jpg') { - $q = $this->parametres->JPEGQuality ?? 85; - } else { - $q = 85; - } - if ($q != 85) { - $resolution .= '-' . $q; - } + $q = $this->parametres->JPEGQuality ?: 85; + + $doc = $this->_docs[$p['document_id']]; - return $doc->getFile($p['document_page'], $format, $resolution, $withText, $withGraphics, $version, $force); + $res= $doc->getFile($p['document_page'], $format, $resolution, $q, $withText, $withGraphics, $version, $force); + + return $res; } public function getThumbFile($page, $format) @@ -152,7 +149,7 @@ class wsBook extends cubeMetier public static function getDir($id, $dir, $addSlash = true, $onlyroot = false) { - $res = self::getRegionDir($id,false); + $res = self::getRegionDir($id, false); $res .= $dir . '/'; if (!$onlyroot) { $res .= $id . '/'; diff --git a/inc/ws/Metier/class.ws.document.php b/inc/ws/Metier/class.ws.document.php index 891db1d68..fec0cc9b5 100644 --- a/inc/ws/Metier/class.ws.document.php +++ b/inc/ws/Metier/class.ws.document.php @@ -435,12 +435,13 @@ class wsDocument extends cubeMetier return $this->filesdata; } - public function getFile($page, $format = 'jpg', $resolution = 150, $withText = true, $withGraphics = true, $version = 'html', $force = false) + public function getFile($page, $format = 'jpg', $resolution = 150, $quality = 85, $withText = true, $withGraphics = true, $version = 'html', $force = false) { $this->getFilesData(); - $cacheKey = md5($page . '||' . $format . '//' . $resolution . '""' . ($withText ? '1' : '0') . '---' . ($withGraphics ? '1' : '0') . '%%' . $version); + $cacheKey = md5($page . '||' . $format . '$$' . $quality . '//' . $resolution . '""' . ($withText ? '1' : '0') . '---' . ($withGraphics ? '1' : '0') . '%%' . $version); if ($force || !isset($this->filesdata[$cacheKey]) || !$this->filesdata[$cacheKey]) { - $this->filesdata[$cacheKey] = $this->_getFile($page, $format, $resolution, $withText, $withGraphics, $version, $force); + $res=$this->_getFile($page, $format, $resolution, $quality, $withText, $withGraphics, $version, $force); + $this->filesdata[$cacheKey] = $res; } return $this->filesdata[$cacheKey]; } @@ -506,12 +507,12 @@ class wsDocument extends cubeMetier return trim($response->getBody()); } - public function _getFileFarm($page, $format = 'jpg', $resolution = 150, $withText = true, $withGraphics = true, $version = 'html', $force = false) + public function _getFileFarm($page, $format = 'jpg', $resolution = 150, $quality = 85, $withText = true, $withGraphics = true, $version = 'html', $force = false) { $start = microtime(true); $farmer = self::pickOneFarmServer($this->region); - $params = ['page' => $page, 'format' => $format, 'resolution' => $resolution, 'withText' => $withText, 'withGraphics' => $withGraphics, 'version' => $version, 'force' => $force, 'out' => $this->out, 'resolutionRatio' => $this->getResolutionRatio(), 'mobileRatio' => $this->getMobileFirstRatio()]; + $params = ['page' => $page, 'format' => $format, 'resolution' => $resolution, 'quality' => $quality, 'withText' => $withText, 'withGraphics' => $withGraphics, 'version' => $version, 'force' => $force, 'out' => $this->out, 'resolutionRatio' => $this->getResolutionRatio(), 'mobileRatio' => $this->getMobileFirstRatio()]; try { $output = self::sendRequest($farmer, 'process.php', $params); if (preg_match('|/data1/extranet/www/[^\s]+|', $output, $matches)) { @@ -532,7 +533,7 @@ class wsDocument extends cubeMetier } $time = round(microtime(true) - $start, 4); - $log = '[' . $farmer['name'] . ']' . "\t" . date('Y-m-d H:i:s') . "\t\t\t\t" . $time . "\t\t\t\t$page|$format|$resolution|$withText|$withGraphics|$version\t\t\t\t$res\t\t\t\t$output\n"; + $log = '[' . $farmer['name'] . ']' . "\t" . date('Y-m-d H:i:s') . "\t\t\t\t" . $time . "\t\t\t\t$page|$format|$resolution|$quality|$withText|$withGraphics|$version\t\t\t\t$res\t\t\t\t$output\n"; $fp = fopen(wsDocument::getDir($this->document_id) . 'farm.log', 'a+'); fwrite($fp, $log); @@ -541,18 +542,7 @@ class wsDocument extends cubeMetier return $res; } - public static function isFarmUser() - { - global $core; - return true; - $farmTesters = [1, 2, 3, 5, 446, 4135]; - if (!$core->user) { - return false; - } - return in_array($core->user->utilisateur_id, $farmTesters); - } - - public function _getFile($page, $format = 'jpg', $resolution = 150, $withText = true, $withGraphics = true, $version = 'html', $force = false) + public function _getFile($page, $format = 'jpg', $resolution = 150, $quality = 85, $withText = true, $withGraphics = true, $version = 'html', $force = false) { global $core; @@ -571,7 +561,6 @@ class wsDocument extends cubeMetier $version = ''; } - $isFarmUser = self::isFarmUser(); $dir = rtrim($this->out . $version, '/') . '/'; $minsize = 1; @@ -582,18 +571,17 @@ class wsDocument extends cubeMetier $file .= '-' . $resolution; } $file .= '.svg'; - if ($isFarmUser) { - $reffile = $this->out . '/html/fp' . $page . '.svg'; - } else { - $reffile = $this->makeSVGFile($page, $force); - } + + $reffile = $this->out . '/html/fp' . $page . '.svg'; + $minsize = 100; } else if ($format === 'png' || $format === 'jpg') { + $q = ($format === 'jpg' && $quality != 85) ? $quality : ''; $prefix = $withText ? 't' : 'h'; if ($resolution === 'thumb') { $file = $dir . 'p' . $page . '.' . $format; } else { - $file = $dir . $prefix . $page . '-' . $resolution . '.' . $format; + $file = $dir . $prefix . $page . '-' . $resolution . $q . '.' . $format; } } else if ($format === 'swf') { $file = $dir . 'p' . $page . '.' . $format; @@ -613,11 +601,7 @@ class wsDocument extends cubeMetier if ($do || $force) { - if ($isFarmUser) { - return $this->_getFileFarm($page, $format, $resolution, $withText, $withGraphics, $version, $force); - } else { - $this->makeFile($file, $page, $format, $resolution, $withText, $withGraphics, $version); - } + return $this->_getFileFarm($page, $format, $resolution, $quality, $withText, $withGraphics, $version, $force); } else { touch($file); } @@ -625,44 +609,6 @@ class wsDocument extends cubeMetier return $file; } - public function makeFile($file, $page, $format = 'jpg', $resolution = 150, $withText = true, $withGraphics = true, $version = 'html') - { - $lock = $file . '.lock'; - if (file_exists($lock) && filemtime($lock) > time() - 300) { - sleep(10); - return $this->getFile($page, $format, $resolution, $withText, $withGraphics, $version); - } - touch($lock); - if ($format === 'jpeg') { - $format = 'jpg'; - } - if ($format === 'svg') { - if ($withGraphics) { - $this->makeOptimizedSVGFile($page, $resolution, $file); - } else { - $this->makeTextSVGFile($page, $file); - } - } else if ($format === 'png' || $format === 'jpg') { - $e = explode('-', $resolution); - if (count($e) > 1) { - $resolution = $e[0]; - $quality = $e[1]; - } else { - $quality = 85; - } - - if ($resolution === 'thumb') { - wsPDFConvert::makeMiniShot($this->getSplittedPDFPage($page), $file, 1, $format); - } else { - $rr = $version === 'html' ? $this->getResolutionRatio() : $this->getMobileFirstRatio(); - wsPDFConvert::makeShotPNM($this->getSplittedPDFPage($page), $file, 1, '', $resolution * $rr, $quality, 4, $withText, null, null, $format); - } - } else if ($format === 'swf') { - wsPDFConvert::makeSWF($this->getSplittedPDFPage($page), $file, 1, $resolution, 80); - } - unlink($lock); - } - public function cutDocument($mode) { $fwstk = new cubeCommandLine('fwstk.sh'); @@ -690,9 +636,9 @@ class wsDocument extends cubeMetier if ($force) { $this->addToLog('Processing page #' . $page); // Thumb for composition panel - $this->getFile($page, 'jpg', 'thumb', true, true, '', true); + $this->getFile($page, 'jpg', 'thumb', 85, true, true, '', true); // Image for link editor - $this->getFile($page, 'jpg', 150, true, true, 'html', true); + $this->getFile($page, 'jpg', 150, 85, true, true, 'html', true); // Make SVG base file $this->makeSVGFile($page, true); } diff --git a/inc/ws/Util/html5/master/class.ws.html5.links.php b/inc/ws/Util/html5/master/class.ws.html5.links.php index e49085461..84051ac89 100644 --- a/inc/ws/Util/html5/master/class.ws.html5.links.php +++ b/inc/ws/Util/html5/master/class.ws.html5.links.php @@ -2961,7 +2961,6 @@ class zoomLink extends normalLink if (!file_exists($leftfile)) { die('Error generating left part ' . $leftfile); } - if (($x + $w) > $bookwidth) { if (!isset($attributes['pdf']) || !$attributes['pdf']) { $p = wsDAOBook::getDocumentPage($compiler->book_id, $attributes['page'] + 1); -- 2.39.5