From 95b086f4007d124ac6117508eeb61a227a64c9be Mon Sep 17 00:00:00 2001 From: "vincent@cubedesigners.com" Date: Tue, 27 Apr 2021 11:16:41 +0000 Subject: [PATCH] wait #4426 @2 --- inc/ws/Controlleur/class.ws.flash.php | 10 +- inc/ws/Controlleur/class.ws.services.php | 158 +----------------- inc/ws/DAO/class.ws.dao.book.php | 10 +- inc/ws/Metier/class.ws.book.parametres.php | 18 +- inc/ws/Metier/class.ws.book.php | 25 ++- .../html5/master/class.ws.html5.compiler.php | 4 +- .../html5/master/class.ws.html5.links.php | 16 +- inc/ws/Util/packager/class.ws.packager.php | 2 +- 8 files changed, 69 insertions(+), 174 deletions(-) diff --git a/inc/ws/Controlleur/class.ws.flash.php b/inc/ws/Controlleur/class.ws.flash.php index f26656af1..da40f93fd 100644 --- a/inc/ws/Controlleur/class.ws.flash.php +++ b/inc/ws/Controlleur/class.ws.flash.php @@ -257,6 +257,10 @@ class wsFlash extends cubeFlashGateway public function uploadLinkContent() { + global $core; + $daoBook=new wsDAOBook($core->con); + $book=$daoBook->selectById($this->args['book_id'] ); + foreach ($_FILES as $varname => $infos) { if ($infos['error']) { continue; @@ -273,7 +277,7 @@ class wsFlash extends cubeFlashGateway } $fname = cubeFiles::tidyName($infos['name']); - $dir = WS_BOOKS . '/working/' . $this->args['book_id'] . '/' . $dir; + $dir = $book->getAssetDir($dir); if (!file_exists($dir)) { mkdir($dir, 0777, true); } @@ -677,9 +681,9 @@ class wsFlash extends cubeFlashGateway $dim = CubeIT_Image::getimagesize($themeRoot . $p->$param); $url = 'https://' . $_SERVER['HTTP_HOST'] . WEBROOT . '/fluidbook/themes/' . $theme->theme_id . '/' . $p->$param; } else { - $bookRoot = WS_BOOKS . '/working/' . $book->book_id . '/'; + $bookRoot = $book->getAssetDir(); $dim = CubeIT_Image::getimagesize($bookRoot . $p->$param); - $url = 'https://' . $_SERVER['HTTP_HOST'] . WEBROOT . '/fluidbook/books/working/' . $book->book_id . '/' . $p->$param; + $url = 'https://' . $_SERVER['HTTP_HOST'] . WEBROOT . '/fluidbook/books/working/' . $book->getAssetDirId() . '/' . $p->$param; } if ($this->json) { diff --git a/inc/ws/Controlleur/class.ws.services.php b/inc/ws/Controlleur/class.ws.services.php index b96b95567..6515221b4 100644 --- a/inc/ws/Controlleur/class.ws.services.php +++ b/inc/ws/Controlleur/class.ws.services.php @@ -183,12 +183,13 @@ class wsServices extends cubeFlashGateway } $id = $book->book_id; + $wid=$book->getAssetDir(); if (isset($this->args['image'])) { - $cover = WS_BOOKS . '/working/' . $id . '/' . $this->args['image']; + $cover = $wid . $this->args['image']; } else { if (isset($book->parametres->facebook_image) && $book->parametres->facebook_image != '') { - $c = WS_BOOKS . '/working/' . $id . '/' . $book->parametres->facebook_image; + $c =$wid. $book->parametres->facebook_image; if (file_exists($c)) { $cover = $c; } @@ -447,12 +448,13 @@ class wsServices extends cubeFlashGateway { global $core; $mode = $force ? $force : $book->parametres->bookmarkUsePDF; + $wid=$book->getAssetDir(); switch ($mode) { case 'download': - $res = WS_BOOKS . '/working/' . $book->book_id . '/' . $book->parametres->pdfReplace; + $res = $wid . $book->parametres->pdfReplace; break; case 'thumbnails': - $res = WS_BOOKS . '/working/' . $book->book_id . '/' . $book->parametres->pdfThumbnails; + $res = $wid . $book->parametres->pdfThumbnails; break; case 'pages': default: @@ -646,154 +648,6 @@ class wsServices extends cubeFlashGateway $mail->send(); } - public function grdfCoupon2015() - { - $id = $this->args['id']; - - $this->outputXML = false; - $couponsRoot = WS_BOOKS . '/working/' . $id . '/commerce/'; - - $xml = simplexml_load_file($couponsRoot . 'references.xml'); - // Check hash - $hash = md5('ae' . $_GET['nom'] . '25' . $_GET['ref']); - if ($hash != $_GET['h']) { - exit; - } - $refs = explode(',', $_GET['ref']); - - $tmp = cubeFiles::tempnam(); - $pdftk = new CubeIT_CommandLine('pdftk'); - $pdftk->setPath(CONVERTER_PATH); - foreach ($refs as $ref) { - $file = $couponsRoot . $ref . '.pdf'; - $pdftk->setArg(null, $file); - } - $pdftk->setArg(null, 'output'); - $pdftk->setArg(null, $tmp); - $pdftk->execute(); - - header('Content-Type: application/pdf'); - header('Content-Disposition: inline; filename="CouponChequier.pdf"'); - - readfile($tmp); - unlink($tmp); - exit; - } - - public function grdfCoupon() - { - - $id = $this->args['id']; - - if ($id == 13372) { - return $this->grdfCoupon2015(); - } - - $this->outputXML = false; - $couponsRoot = WS_BOOKS . '/working/' . $id . '/commerce/'; - - $xml = simplexml_load_file($couponsRoot . 'references.xml'); - // Check hash - $hash = md5('ae' . $_GET['nom'] . '25' . $_GET['ref']); - if ($hash != $_GET['h']) { - exit; - } - $refs = explode(',', $_GET['ref']); - $pdf = new FPDI(); - foreach ($refs as $ref) { - - foreach ($xml->xpath('//item[@reference=\'' . $ref . '\']') as $item) { - $code = (string)$item['code']; - } - - $file = $couponsRoot . $ref . '.pdf'; - - $pdf->setSourceFile($file); - $idx = $pdf->importPage(1); - $pdf->AddPage(); - $pdf->useTemplate($idx); - $pdf->SetXY(11, 12); - $pdf->SetFont('Helvetica', '', 12); - $pdf->SetTextColor(0, 0, 0); - $pdf->Cell(180, 10, utf8_decode(trim($_GET['civilite'] . ' ' . $_GET['prenom'] . ' ' . $_GET['nom']) . ',')); - $pdf->SetXY(135, 203); - $pdf->SetFont('Helvetica', 'B', 16); - $pdf->Cell(50, 15, $code, 0, 1, "C"); - } - $pdf->Output('coupon.pdf', 'I'); - } - - public function grdfExcel12568() - { - global $core; - $this->outputXML = false; - - if (!isset($_GET['annee'])) { - $_GET['annee'] = 2014; - } - $annee = $_GET['annee']; - - if ($annee == 2013) { - $id = 11222; - } elseif ($annee == 2014) { - $id = 12779; - } - - - $couponsRoot = WS_BOOKS . '/working/' . $id . '/commerce/'; - - $xml = simplexml_load_file($couponsRoot . 'references.xml'); - - $cols = array('Date' => 'date', 'Civilité' => 'civilite', 'Prénom' => 'prenom', 'Nom' => 'nom', - 'E-mail' => 'email', 'Adresse' => 'adresse', 'Code postal' => 'codepostal', 'Ville' => 'ville', - 'Téléphone' => 'telephone', 'Connu par' => 'connu', 'Energie' => 'energie', 'Type de logement' => 'logement', - 'Echéance travaux' => 'echeance', - 'Optin' => 'optin', 'Optin partenaires' => 'optin_partenaires'); - $refs = array(); - foreach ($xml->xpath('//item') as $i) { - $refs[(string)$i['reference']] = $i['name']; - } - - // - $h = ''; - $h .= ''; - foreach ($cols as $l => $k) { - $h .= ''; - } - foreach ($refs as $k => $l) { - $h .= ''; - } - $h .= ''; - - $r = $core->con->select('SELECT * FROM grdf' . $annee); - while ($r->fetch()) { - $d = json_decode($r->datas); - $rl = explode(',', $d->reflist); - $h .= ''; - foreach ($cols as $l => $k) { - $v = $d->$k; - if ($k == 'date') { - $v = date('Y-m-d H:i', $v); - } - $h .= ''; - } - foreach ($refs as $k => $l) { - $v = in_array($k, $rl) ? '1' : '0'; - $h .= ''; - } - $h .= ''; - } - - $h .= '
' . utf8_decode($l) . '' . utf8_decode($l) . '
' . utf8_decode($v) . '' . utf8_decode($v) . '
'; - - if (!file_exists(ROOT . '/cache/12568/')) { - mkdir(ROOT . '/cache/12568/', 0777, true); - } - file_put_contents(ROOT . '/cache/12568/chequieravantage.xls', $h); - http::redirect('/cache/12568/chequieravantage.xls'); - exit; - } - public function proxy() { ob_end_clean(); diff --git a/inc/ws/DAO/class.ws.dao.book.php b/inc/ws/DAO/class.ws.dao.book.php index 8759df48b..5cbc58506 100644 --- a/inc/ws/DAO/class.ws.dao.book.php +++ b/inc/ws/DAO/class.ws.dao.book.php @@ -847,6 +847,11 @@ class wsDAOBook extends commonDAO $c->update('WHERE book_id=\'' . $this->con->escape($book_id) . '\''); } + /** + * @param $book wsBook + * @param $version + * @return bool + */ public function isUpToDate($book, $version) { $version = (string)$version; @@ -868,7 +873,7 @@ class wsDAOBook extends commonDAO } else if ($version == 'html5') { return false; // HTML5 - $checks = array($book->changedate, cubeFiles::filemtimeRecursive(WS_BOOKS . '/working/' . $book->book_id), cubeFiles::filemtimeRecursive(WS_COMPILE_ASSETS . '/_html5'), cubeFiles::filemtimeRecursive(ROOT . '/inc/ws/Util/html5')); + $checks = array($book->changedate, cubeFiles::filemtimeRecursive($book->getAssetDir()), cubeFiles::filemtimeRecursive(WS_COMPILE_ASSETS . '/_html5'), cubeFiles::filemtimeRecursive(ROOT . '/inc/ws/Util/html5')); foreach ($checks as $check) { if ($check > $book->compilehtml5date) { return false; @@ -1226,8 +1231,7 @@ class wsDAOBook extends commonDAO return $path; } - $workingDir = WS_BOOKS . '/working/' . $book_id . '/'; - return $workingDir . trim($dir, '/') . '/' . $path; + return wsBook::getAssetDirOfBook($book_id, $dir) . $path; } public function compileHTML5($book_id, $book, $dev = false, $delete = true) diff --git a/inc/ws/Metier/class.ws.book.parametres.php b/inc/ws/Metier/class.ws.book.parametres.php index ca2e45117..ea207076d 100644 --- a/inc/ws/Metier/class.ws.book.parametres.php +++ b/inc/ws/Metier/class.ws.book.parametres.php @@ -110,6 +110,7 @@ class wsBookParametres extends wsParametres ); // Deprecated + $this->fields['version'] = array('type' => 'combo', 'default' => '2', 'editable' => true, 'label' => __('Version'), 'datas' => array('1' => '1', '2' => '2'), 'grade' => 3); $this->fields['email_editable'] = array('type' => 'boolean', 'default' => true, 'editable' => false, 'label' => __("Permettre au lecteur de modifier le corps de l'email")); $this->fields['askAcknowledge'] = array('type' => 'boolean', 'default' => false, 'editable' => false, 'label' => __("Demander au destinataire un accusé de réception"), 'grade' => 3); $this->fields['sendasfluidbook'] = array('type' => 'boolean', 'default' => false, 'editable' => false, 'label' => __("Envoyer le mail comme Fluidbook"), 'grade' => 3, 'hint' => __("L'expéditeur apparaîtra en reply-to")); @@ -201,15 +202,24 @@ class wsBookParametres extends wsParametres __('PDF') => 'pdf')); /** **/ - $this->fields['version'] = array('type' => 'combo', 'default' => '2', 'editable' => true, 'label' => __('Version'), 'datas' => array('1' => '1', '2' => '2'), 'grade' => 3); + $this->fields['title'] = array('type' => 'text', 'default' => '', 'editable' => true, 'label' => __("Titre de la publication"), 'embed' => false); $this->fields['url_link'] = array('type' => 'text', 'default' => 'http://', 'editable' => true, 'label' => __("URL du lien de retour au site")); $this->fields['signature'] = array('type' => 'combo', 'default' => '1', 'editable' => true, 'label' => __('Signature'), 'grade' => 3, 'datas' => wsDroits::getSignatures()); $this->forms['important'] = array('label' => __('Description de la publication'), - 'fieldsnames' => array('version', 'mobileLVersion', 'mobileVersion', 'title', 'url_link', 'signature')); + 'fieldsnames' => array('mobileLVersion', 'mobileVersion', 'title', 'url_link', 'signature')); // . // . + $this->fields['assetsDir'] = ['type' => 'text', 'label' => __('Utiliser le dossier d\'assets du fluidbook'), 'default' => '', 'editable' => true, 'grade' => 5]; + $this->fields['linksAssets'] = ['type' => 'freefile', 'label' => __('Charger ou remplacer des fichiers de liens'), 'default' => '', 'editable' => true, 'grade' => 3, 'multiple' => true]; + + $this->forms['assets'] = [ + 'label' => __('Assets'), + 'fieldsnames' => ['assetsDir', 'linksAssets'] + ]; + /** * */ + $this->fields['email_title'] = array('type' => 'text', 'default' => '', 'editable' => true, 'label' => __("Titre de l'email") . ' "' . __('Envoyer à un ami') . '"', 'hint' => __('Laisser vide pour utiliser la valeur par défaut')); $this->fields['email_body'] = array('type' => 'textarea', 'default' => '', 'editable' => true, 'label' => __("Corps de l'email") . ' "' . __('Envoyer à un ami') . '"', 'hint' => __('Laisser vide pour utiliser la valeur par défaut')); @@ -493,7 +503,7 @@ class wsBookParametres extends wsParametres 'fieldsnames' => ['tabsHTML5', 'tabsPages', 'tabsSections', 'tabsPagesNumbers', '|', 'tabsSide', 'tabsMargin', '|', 'tabsHideOnPages', 'tabsHideOnCover', 'tabsHideOnLastPage', 'tabsHideEdges', '|', 'tabsPriority', 'tabsLinkWidth', 'tabsHideWhenOverlapingArrows', 'tabsHideOnPortrait', 'tabsHideOnZoom']]; /*** **/ - $this->fields['linksAssets'] = ['type' => 'freefile', 'label' => __('Charger ou remplacer des fichiers de liens'), 'default' => '', 'editable' => true, 'grade' => 3, 'multiple' => true]; + $this->fields['customLinkClass'] = array('type' => 'text', 'default' => '', 'editable' => true, 'label' => __('Classe pour les liens personnalisés'), 'grade' => 5); $this->fields['ignoreLinksTypes'] = array('type' => 'text', 'default' => '', 'editable' => true, 'label' => __('Ignorer les liens de type'), 'hint' => __('Liste des numéros séparés par des virgules'), 'grade' => 5); $this->fields['mobileLinksRevealAnim'] = array('type' => 'boolean', 'default' => true, 'editable' => true, 'label' => __("Animer les liens après un changement de page"), 'grade' => 3); @@ -507,7 +517,7 @@ class wsBookParametres extends wsParametres $this->fields['mobileIgnoreBackgroundLinks'] = array('type' => 'boolean', 'default' => false, 'editable' => true, 'label' => __('Ignorer les liens de background')); $this->forms['links'] = array('label' => __('Liens'), - 'fieldsnames' => array('linksAssets', '|', 'permanentLinks', 'mobileLinksRevealAnim', 'linkBlinkTime', 'linkBlinkRepetition', '|', 'openLinkAtStartup', '|', 'customLinkClass', 'ignoreLinksTypes', 'mobileIgnoreBackgroundLinks', 'linkTooltipManager', 'linkCornerSize', 'linkTooltipMaxWidth', '|', 'linkTracker', 'linkTrackerRegexp', '|', 'linkFilePrefix')); + 'fieldsnames' => array('permanentLinks', 'mobileLinksRevealAnim', 'linkBlinkTime', 'linkBlinkRepetition', '|', 'openLinkAtStartup', '|', 'customLinkClass', 'ignoreLinksTypes', 'mobileIgnoreBackgroundLinks', 'linkTooltipManager', 'linkCornerSize', 'linkTooltipMaxWidth', '|', 'linkTracker', 'linkTrackerRegexp', '|', 'linkFilePrefix')); //. $this->fields['textPopupStylesheet'] = ['type' => 'freefile', 'default' => '', 'editable' => true, 'label' => __('Feuille de style des popups de texte'), 'fileFilter' => $cssFilter]; diff --git a/inc/ws/Metier/class.ws.book.php b/inc/ws/Metier/class.ws.book.php index 8f3d9f6f3..7e4fd5a86 100644 --- a/inc/ws/Metier/class.ws.book.php +++ b/inc/ws/Metier/class.ws.book.php @@ -84,7 +84,7 @@ class wsBook extends cubeMetier return $this->$varname; } - public function getFile($page, $format = 'jpg', $resolution = 150, $withText = true, $withGraphics = true, $version = 'html',$force=false) + public function getFile($page, $format = 'jpg', $resolution = 150, $withText = true, $withGraphics = true, $version = 'html', $force = false) { $p = wsDAOBook::getDocumentPage($this->book_id, $page); if (!isset($this->_docs[$p['document_id']])) { @@ -93,15 +93,34 @@ class wsBook extends cubeMetier $this->_docs[$p['document_id']] = $dao->selectById($p['document_id']); } $doc = $this->_docs[$p['document_id']]; - return $doc->getFile($p['document_page'], $format, $resolution, $withText, $withGraphics, $version,$force); + return $doc->getFile($p['document_page'], $format, $resolution, $withText, $withGraphics, $version, $force); } public function getThumbFile($page, $format) { - $thumbpdf = WS_BOOKS . '/working/' . $this->book_id . '/' . $this->parametres->pdfThumbnails; + $thumbpdf = $this->getAssetDir(). $this->parametres->pdfThumbnails; if ($this->parametres->pdfThumbnails && file_exists($thumbpdf)) { return wsPDFConvert::getThumbFromPDF($thumbpdf, $page, $format); } return $this->getFile($page, $format, 'thumb'); } + + public function getAssetDir($sub = '') + { + return rtrim(WS_BOOKS . '/working/' . $this->getAssetDirId() . '/' . trim($sub, '/'), '/') . '/'; + } + + public function getAssetDirId() + { + return $this->parametres->assetsDir === '' ? $this->book_id : trim($this->parametres->assetsDir); + } + + public static function getAssetDirOfBook($book_id, $sub = '') + { + global $core; + $dao = new wsDAOBook($core->con); + $book = $dao->selectById($book_id); + + return $book->getAssetDir($sub); + } } \ 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 fe98025ea..c8048cb36 100644 --- a/inc/ws/Util/html5/master/class.ws.html5.compiler.php +++ b/inc/ws/Util/html5/master/class.ws.html5.compiler.php @@ -271,7 +271,7 @@ class wsHTML5Compiler $this->dir = $dir; } $this->vdir = new CubeIT_Files_VirtualDirectory($this->dir); - $this->wdir = WS_BOOKS . '/working/' . $this->book_id . '/'; + $this->daoBook = new wsDAOBook($core->con); if (null === $book) { @@ -280,6 +280,8 @@ class wsHTML5Compiler $this->book = $book; } + $this->wdir = $this->book->getAssetDir(); + $this->widget = !$this->phonegap && $this->book->parametres->widget; $this->pages = $this->daoBook->getPagesOfBook($book_id); 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 7637b0964..7149cab3d 100644 --- a/inc/ws/Util/html5/master/class.ws.html5.links.php +++ b/inc/ws/Util/html5/master/class.ws.html5.links.php @@ -369,7 +369,7 @@ class wsHTML5Link if ($this->target == '') { $this->target = '_blank'; } - $this->wdir = WS_BOOKS . '/working/' . $compiler->book_id . '/'; + $this->wdir = $this->compiler->wdir; $this->id = $id; $this->compiler = $compiler; $this->init(); @@ -678,6 +678,7 @@ class anchorLink extends wsHTML5Link public function getHTMLContainer() { + $this->to = self::normalizeAnchor($this->to); $this->compiler->addPageLabel($this->page, $this->to); return '
getAdditionnalContent() . '>' . $this->getHTMLContent() . '
'; } @@ -686,6 +687,11 @@ class anchorLink extends wsHTML5Link { return ''; } + + public static function normalizeAnchor($anchor) + { + return mb_strtolower(CubeIT_Text::str2URL($anchor)); + } } class triggerLink extends normalLink @@ -1045,7 +1051,7 @@ class internalLink extends normalLink $anchor = trim($e[1], '# '); } if ($anchor) { - $res = $anchor; + $res = anchorLink::normalizeAnchor($anchor); } else if ($this->numerotation === 'physical') { $res = $p; } else { @@ -1164,11 +1170,7 @@ class videoLink extends wsHTML5Link $attr['height'] = $h; } else if (!is_null($compiler) && CubeIT_Util_Url::isLocal($data->to)) { // Get video dimensions from thumbnail if possible (locally uploaded files) -// $path = WS_BOOKS . '/working/' . $compiler->book_id . '/' . $basename . '.jpg'; -// $dim = getimagesize($path); -// $attr['width'] = $dim[0]; -// $attr['height'] = $dim[1]; - $path = WS_BOOKS . '/working/' . $compiler->book_id . '/' . $data->to; + $path = $compiler->wdir . '/' . $data->to; $e = explode(',', `ffprobe -v error -select_streams v:0 -show_entries stream=width,height -of csv=p=0 $path`); $attr['width'] = $e[0]; $attr['height'] = $e[1]; diff --git a/inc/ws/Util/packager/class.ws.packager.php b/inc/ws/Util/packager/class.ws.packager.php index 89a971ad4..10b8d02fe 100644 --- a/inc/ws/Util/packager/class.ws.packager.php +++ b/inc/ws/Util/packager/class.ws.packager.php @@ -71,7 +71,7 @@ class wsPackager $this->theme = $daoTheme->getThemeOfBook($book_id, true); $this->themeRoot = WS_THEMES . '/' . $this->theme->theme_id . '/'; - $this->workingDir = WS_BOOKS . '/working/' . $book_id . '/'; + $this->workingDir = $this->book->getAssetDir(); $this->compile(); } -- 2.39.5