From 14f8144a679d8aa0f647440ad0593dd804ac1147 Mon Sep 17 00:00:00 2001 From: "vincent@cubedesigners.com" Date: Tue, 23 Jun 2020 14:23:38 +0000 Subject: [PATCH] wip #3497 @2 --- inc/ws/Metier/class.ws.book.parametres.php | 7 +- .../html5/master/class.ws.html5.links.php | 76 +++++++++++++++---- 2 files changed, 68 insertions(+), 15 deletions(-) diff --git a/inc/ws/Metier/class.ws.book.parametres.php b/inc/ws/Metier/class.ws.book.parametres.php index a0f47a76c..c050ddc93 100644 --- a/inc/ws/Metier/class.ws.book.parametres.php +++ b/inc/ws/Metier/class.ws.book.parametres.php @@ -429,8 +429,13 @@ class wsBookParametres extends wsParametres $this->fields['OAMChromeFactor'] = ['type' => 'float', 'default' => '1', 'editable' => true, 'label' => __('Facteur OAM Chrome')]; $this->fields['OAMIEFactor'] = ['type' => 'float', 'default' => '1', 'editable' => true, 'label' => __('Facteur OAM IE11')]; $this->forms['multimedia'] = array('label' => __('Liens et multimédia'), - 'fieldsnames' => array('permanentLinks', 'linkBlinkTime', 'linkBlinkRepetition', '|', 'customLinkClass', 'ignoreLinksTypes', 'linkTooltipManager', 'linkCornerSize', 'linkTooltipMaxWidth', '|', 'linkTracker', 'linkTrackerRegexp', '|', 'linkFilePrefix', '|', 'linkMultimediaPerformanceMode', 'linkMultimediaQuality', '|', 'inlineSlideshowTransitionDuration', 'inlineSlideshowDuration', '|', 'videoReset', 'videoBigPlay', '|', 'brightcovePlayerId', 'brightcovePlayerSecret', '|', 'textPopupStylesheet', 'textPopupWidth', '|', 'iframePopupMaxWidth','|','OAMChromeFactor','OAMIEFactor')); + 'fieldsnames' => array('permanentLinks', 'linkBlinkTime', 'linkBlinkRepetition', '|', 'customLinkClass', 'ignoreLinksTypes', 'linkTooltipManager', 'linkCornerSize', 'linkTooltipMaxWidth', '|', 'linkTracker', 'linkTrackerRegexp', '|', 'linkFilePrefix', '|', 'linkMultimediaPerformanceMode', 'linkMultimediaQuality', '|', 'inlineSlideshowTransitionDuration', 'inlineSlideshowDuration', '|', 'videoReset', 'videoBigPlay', '|', 'brightcovePlayerId', 'brightcovePlayerSecret', '|', 'textPopupStylesheet', 'textPopupWidth', '|', 'iframePopupMaxWidth', '|', 'OAMChromeFactor', 'OAMIEFactor')); //. + $this->fields['downloadPortionPDF'] = ['type' => 'freefile', 'default' => '', 'editable' => true, 'label' => 'PDF utilisé pour le téléchargement des extraits']; + $this->fields['downloadPortionZoom'] = ['type' => 'integer', 'default' => 8, 'editable' => false, 'editable' => true, 'label' => __('Zoom des images extraites')]; + $this->forms['downloadportion'] = array('label' => __('Téléchargement d\'extraits'), + 'fieldsnames' => ['downloadPortionPDF', 'downloadPortionZoom']); + $this->fields['product_zoom_references'] = array('type' => 'freefile', 'default' => '', 'editable' => true, 'label' => __('Références produits'), 'grade' => 3, 'fileFilter' => $basketFilter, 'hint' => __('Fichier contenant les références produits'), 'dir' => 'commerce'); 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 5665199c9..45cc713da 100644 --- a/inc/ws/Util/html5/master/class.ws.html5.links.php +++ b/inc/ws/Util/html5/master/class.ws.html5.links.php @@ -190,6 +190,8 @@ class wsHTML5Link case 36: return new articleLink($id, $init, $compiler); break; + case 37: + return new downloadPortionLink($id, $init, $compiler); default: return null; } @@ -1293,6 +1295,50 @@ class fileLink extends normalLink } +class downloadPortionLink extends fileLink +{ + public function getURL() + { + zoomLink::generateImage($this->getZoomAttributes(), $this->compiler, 'downloadportion', 'downloadportion'); + return 'data/links/downloadportion_' . $this->id . '.jpg'; + } + + public function getZoomAttributes() + { + return [ + 'id' => $this->id, + 'page' => $this->page, + 'maxzoom' => $this->compiler->book->parametres->downloadPortionZoom, + 'group' => '', + 'group-count' => 0, + 'width' => round($this->width), + 'height' => round($this->height), + 'x' => round($this->left), + 'y' => round($this->top) + ]; + } + + + public function getAdditionnalContent() + { + $file = $this->to; + if (!$file) { + $file = 'p' . $this->page; + } + if (!preg_match('/\.jpe?g$/', $file, $matches)) { + $file .= '.jpg'; + } + $file = htmlspecialchars($file); + + return parent::getAdditionnalContent() . ' download="' . $file . '" '; + } + + public function getDefaultTooltip() + { + return 'click to download the image'; + } +} + class facebookLikeLink extends wsHTML5Link { public function getHTMLContent() @@ -1862,7 +1908,7 @@ class zoomLink extends normalLink $res .= ' data-' . $key . '="' . htmlspecialchars($val, ENT_QUOTES) . '"'; } - $this->generateImage(); + self::generateImage($this->getZoomAttributes(), $this->compiler, 'zoomarea', 'zoom'); return $res; } @@ -1870,6 +1916,8 @@ class zoomLink extends normalLink public function getZoomAttributes() { return [ + 'id' => $this->id, + 'page' => $this->page, 'maxzoom' => empty($this->to) ? $this->maxzoom_default : $this->to, 'group' => implode(',', $this->getGroups()), 'group-count' => empty($this->group) ? 0 : count($this->getGroups()), @@ -1880,10 +1928,10 @@ class zoomLink extends normalLink ]; } - public function generateImage() + public static function generateImage($attributes, $compiler, $cachedir, $save) { - $maxzoom = $this->getZoomAttributes()['maxzoom']; // Max zoom level might not always be set in the link editor + $maxzoom = $attributes['maxzoom']; // Max zoom level might not always be set in the link editor $maxzoom = max(2, min($maxzoom, 4.166666667)); if (!$maxzoom) { $maxzoom = 2; @@ -1901,32 +1949,32 @@ class zoomLink extends normalLink // Round all link co-ordinates because there seems to be a problem with the the Workshop link editor // where link "left" values (and maybe others) change fractionally upon saves. This causes problems later when // extracting the zoom images from the PDF because it causes a cache-miss and the images are regenerated again. - $x = round($this->left); - $y = round($this->top); - $w = round($this->width); - $h = round($this->height); - $bookwidth = round($this->compiler->book->parametres->width); + $x = $attributes['x']; + $y = $attributes['y']; + $w = $attributes['width']; + $h = $attributes['height']; + $bookwidth = round($compiler->book->parametres->width); //error_log("--- Book Width: $bookwidth ---"); - $p = wsDAOBook::getDocumentPage($this->compiler->book_id, $this->page); + $p = wsDAOBook::getDocumentPage($compiler->book_id, $attributes['page']); $pdfpath = wsDocument::getDir($p['document_id']) . '/pdf/p' . $p['document_page'] . '.pdf'; $left = CubeIT_Files::tempnam(); $leftfile = CubeIT_CommandLine_Poppler::extractArea($pdfpath, 1, array('x' => $x, 'y' => $y, 'width' => $w, 'height' => $h), - $left, $extractOptions, WS_CACHE . '/zoomarea/' . $this->compiler->book_id . '/'); + $left, $extractOptions, WS_CACHE . '/' . $cachedir . '/' . $compiler->book_id . '/'); if (($x + $w) > $bookwidth) { - $p = wsDAOBook::getDocumentPage($this->compiler->book_id, $this->page + 1); + $p = wsDAOBook::getDocumentPage($compiler->book_id, $attributes['page'] + 1); $pdfpath = wsDocument::getDir($p['document_id']) . '/pdf/p' . $p['document_page'] . '.pdf'; $diff = ($w + $x) - $bookwidth; $right = CubeIT_Files::tempnam(); $rightfile = CubeIT_CommandLine_Poppler::extractArea($pdfpath, 1, array('x' => 0, 'y' => $y, 'width' => $diff, 'height' => $h), - $right, $extractOptions, WS_CACHE . '/zoomarea/' . $this->compiler->book_id . '/'); + $right, $extractOptions, WS_CACHE . '/' . $cachedir . '/' . $compiler->book_id . '/'); $both = CubeIT_Files::tempnam() . '.jpg'; CubeIT_CommandLine_Imagemagick::append(array($leftfile, $rightfile), $both, 'horizontal'); @@ -1934,13 +1982,13 @@ class zoomLink extends normalLink $both = $leftfile; } - $this->compiler->simpleCopyLinkFile($both, 'data/links/zoom_' . $this->id . '.jpg'); + $compiler->simpleCopyLinkFile($both, 'data/links/' . $save . '_' . $attributes['id'] . '.jpg'); // Perform tidy up and delete temporary files if they exist $files_to_delete = ['left', 'leftfile', 'right', 'rightfile', 'both']; foreach ($files_to_delete as $file) { if (isset($$file)) { - $this->compiler->vdir->addTemp($$file); + $compiler->vdir->addTemp($$file); } } } -- 2.39.5