From: vincent@cubedesigners.com Date: Tue, 24 Sep 2019 15:18:34 +0000 (+0000) Subject: wip #3054 @2 X-Git-Url: http://git.cubedesigners.com/?a=commitdiff_plain;h=665a5223be95a35c34dbf0ca59d13ffdab3a1854;p=cubeextranet.git wip #3054 @2 --- diff --git a/inc/ws/Util/class.ws.util.php b/inc/ws/Util/class.ws.util.php index 7e4b267be..4c5dffda8 100644 --- a/inc/ws/Util/class.ws.util.php +++ b/inc/ws/Util/class.ws.util.php @@ -2,317 +2,330 @@ class wsUtil { - public static function excelToArray($excelFile, $assoc = false) - { - $worksheets = array(); - - if ($assoc) { - $cacheBase = WS_CACHE . '/xlsx2assocarray/'; - } else { - $cacheBase = WS_CACHE . '/xlsx2array/'; - } - if (!file_exists($cacheBase)) { - mkdir($cacheBase, 0777, true); - } - - if (CubeIT_Util_Url::isDistant($excelFile)) { - $tmp = CubeIT_Files::tempnam(); - copy($excelFile, $tmp); - - $hash = hash_file('sha256', $tmp); - $dest = $cacheBase . $hash . '.xlsx'; - - if (!file_exists($dest)) { - copy($tmp, $dest); - } - $excelFile = $dest; - } - if (!file_exists($excelFile)) { - return array(); - } - - $cacheFile = $cacheBase . sha1($excelFile . '/' . filemtime($excelFile)); - - if (file_exists($cacheFile) && !$assoc) { - $worksheets = json_decode(file_get_contents($cacheFile), true); - } else { - set_time_limit(0); - include_once ROOT . '/inc/ZendFramework/PHPExcel/PHPExcel.php'; - $objReader = PHPExcel_IOFactory::createReader('Excel2007'); - $objPHPExcel = $objReader->load($excelFile); - - foreach ($objPHPExcel->getWorksheetIterator() as $worksheet) { - if ($worksheet->getSheetState() != PHPExcel_Worksheet::SHEETSTATE_VISIBLE) { - continue; - } - $title = $worksheet->getTitle(); - if (strlen($title) == 2 && cubeCountry::getCountry($title)) { - $title = cubeCountry::getCountry($title); - } - - if ($assoc) { - $worksheets[$title] = self::_assocSheet($worksheet->toArray(null, true, true)); - } else { - $worksheets[$title] = $worksheet->toArray(null, true, true); - } - } - file_put_contents($cacheFile, json_encode($worksheets)); - } - - return $worksheets; - } - - protected static function _assocSheet($s) - { - $res = []; - $colslabels = []; - foreach ($s[0] as $j => $collabel) { - if (trim($collabel) == '') { - continue; - } - $colslabels[$j] = $collabel; - } - for ($i = 1; $i < count($s); $i++) { - $r = []; - foreach ($colslabels as $j => $collabel) { - $r[$collabel] = $s[$i][$j]; - } - $res[] = $r; - } - - return $res; - } - - - public static function atlanticReferences($references, $dir, $log = null, $copy = 'copy') - { - if (!file_exists($dir)) { - mkdir($dir, 0777, true); - } - foreach ($references as $i => $sheet) { - foreach ($sheet as $j => $line) { - foreach ($line as $k => $v) { - if (preg_match('|^http:\/\/atlantic-international-book-com\.com\/files\/(.*)$|', $v, $matches)) { - $local = $dir . '/' . $matches[1]; - $ldir = dirname($local); - if (!file_exists($ldir)) { - mkdir($ldir, 0777, true); - } - $url = str_replace(' ', '%20', $v); - $cache = WS_CACHE . '/atlantic/' . md5($url); - if (!file_exists($cache) || filemtime($url) > filemtime($cache)) { - copy($url, $cache); - $copylog = ' (copy) '; - } else { - $copylog = ' '; - } - call_user_func($copy, $cache, $dir . '/' . $matches[1]); - $references[$i][$j][$k] = 'local/' . $matches[1]; - if (null !== $log) { - call_user_func($log, 'Done' . $copylog . $matches[1]); - } - } - } - } - } - - return $references; - } - - /** - * @param $book wsBook - */ - public static function compilePDF($book, $pages = null) - { - global $core; - - if (null === $pages) { - $dao = new wsDAOBook($core->con); - $pages = $dao->getPagesOfBook($book->book_id); - } - - if (substr($book->parametres->pdfName, 0, 4) == 'http') { - return false; - } - - $cacheDir = WS_BOOKS . '/pdf/' . $book->book_id; - if (!file_exists($cacheDir)) { - mkdir($cacheDir, 0777, true); - } - - $normalPDF = $cacheDir . '/normal.pdf'; - $originalPDF = $cacheDir . '/original.pdf'; - $compressedPDF = $cacheDir . '/compressed.pdf'; - - $files = [$normalPDF, $originalPDF, $compressedPDF]; - - foreach ($files as $file) { - if (file_exists($file) && filesize($file) == 0) { - unlink($file); - } - } - - if (file_exists($originalPDF)) { - $fmtime = filemtime($originalPDF); - if ($fmtime >= $book->composition_update) { - $invalid = false; - foreach ($pages as $i => $infos) { - $doc = wsDocument::getDir($infos['document_id']) . 'crop.pdf'; - if (file_exists($doc) && filemtime($doc) > $fmtime) { - $invalid = true; - } - } - } else { - $invalid = true; - } - } else { - $invalid = true; - } - - - if ($invalid) { - $pdfList = array(); - $pagesList = array(); - $nb_pages = array(); - $j = 0; - $k = 0; - $original = true; - - foreach ($pages as $i => $infos) { - if (!isset($firstDoc)) { - $firstDoc = $infos['document_id']; - } - - $doc = wsDocument::getDir($infos['document_id']) . 'crop.pdf'; - if (!isset($pdfList[$doc])) { - $pdfList[$doc] = $j; - $nb_pages[$doc] = $infos['nb_pages']; - $k = $j; - $j++; - } else { - $k = $pdfList[$doc]; - } - $pagesList[$i] = array($k, $infos['document_page']); - - if ($i != $infos['document_page'] || $infos['document_id'] != $firstDoc) { - $original = false; - } - } - - if ($original) { - self::copy(wsDocument::getDir($firstDoc) . 'crop.pdf', $originalPDF); - } else { - $args = ''; - foreach ($pdfList as $doc => $index) { - $lettre = cubeMath::toPDFLetter($index, true); - $args .= $lettre . '=' . $doc . ' '; - } - - $args .= ' cat '; - - $ranges = array(); - $currentRange = null; - - foreach ($pagesList as $p) { - $lettre = cubeMath::toPDFLetter($p[0], true); - $page = $p[1]; - - // Initialise l'intervale - if (is_null($currentRange)) { - $currentRange = array('lettre' => $lettre, 'start' => $page, 'end' => $page); - continue; - } - - // Poursuit le remplissage si la lettre est identique et si la page suivante est bien la page suivante dans le document - if ($currentRange['lettre'] == $lettre && $currentRange['end'] + 1 == $page) { - $currentRange['end'] = $page; - continue; - } - - // Ajoute l'intervale à la liste finale - $ranges[] = $currentRange; - - // Réinitialise l'intervale suivant - $currentRange = array('lettre' => $lettre, 'start' => $page, 'end' => $page); - } - - // Ajoute la dernière - if (!is_null($currentRange)) { - $ranges[] = $currentRange; - } - // Si le pdf final est constitué du document complet d'un document - if (count($ranges) == 1 && $ranges[0]['start'] == 1) { - $alldocs = array_keys($pdfList); - $doc = array_pop($alldocs); - if ($nb_pages[$doc] == $ranges[0]['end']) { - self::copy($doc, $originalPDF); - return; - } - } - - foreach ($ranges as $range) { - $args .= ' ' . $range['lettre'] . $range['start']; - if ($range['start'] == $range['end']) { - continue; - } - $args .= '-' . $range['end']; - } - - $hash = sha1($args); - - $args .= ' output ' . $originalPDF; - - $cached = WS_BOOKS . '/pdf/' . $hash . '.pdf'; - - if (file_exists($cached) && filesize($cached) > 0) { - self::copy($cached, $originalPDF); - } else { - $pdftk = new cubeCommandLine('pdftk'); - $pdftk->setPath(CONVERTER_PATH); - $pdftk->setManualArg($args); - $pdftk->execute(); - self::copy($normalPDF, $cached); - } - } - } - - - if ($book->parametres->pdfReplace) { - $replace = WS_BOOKS . '/working/' . $book->book_id . '/' . $book->parametres->pdfReplace; - if (file_exists($replace) && filesize($replace) > 0) { - if (!file_exists($normalPDF) || filemtime($normalPDF) < filemtime($replace) || filesize($normalPDF) != filesize($replace)) { - self::copy($replace, $normalPDF); - } - } - } else { - self::copy($originalPDF, $normalPDF); - } - - if ($book->parametres->pdfCompress) { - if (!file_exists($compressedPDF) || filemtime($compressedPDF) < filemtime($normalPDF)) { - $gs = new cubeCommandLine('gs', null, true); - $gs->setPath(CONVERTER_PATH); - $gs->setEnv('GS_FONTPATH', '/home/ws/fonts'); - $gs->setArg('-dBATCH'); - $gs->setArg('-dNOPAUSE'); - $gs->setArg('-dNOPROMPT'); - $gs->setArg('-sOutputFile=' . $compressedPDF); - $gs->setArg('-sDEVICE=pdfwrite'); - $gs->setArg('-dPDFSETTINGS=/ebook'); - $gs->setArg('-dColorImageResolution=72'); - $gs->setArg('-dAutoRotatePages=/None'); - $gs->setArg('-dColorConversionStrategy=/LeaveColorUnchanged'); - $gs->setArg(null, $normalPDF); - $gs->execute(); - } - return $compressedPDF; - } - return $normalPDF; - } - - public static function copy($source, $dest) - { - copy($source, $dest); - touch($dest, filemtime($source)); - } + public static function excelToArray($excelFile, $assoc = false) + { + $worksheets = array(); + + if ($assoc) { + $cacheBase = WS_CACHE . '/xlsx2assocarray/'; + } else { + $cacheBase = WS_CACHE . '/xlsx2array/'; + } + if (!file_exists($cacheBase)) { + mkdir($cacheBase, 0777, true); + } + + if (CubeIT_Util_Url::isDistant($excelFile)) { + $tmp = CubeIT_Files::tempnam(); + copy($excelFile, $tmp); + + $hash = hash_file('sha256', $tmp); + $dest = $cacheBase . $hash . '.xlsx'; + + if (!file_exists($dest)) { + copy($tmp, $dest); + } + $excelFile = $dest; + } + if (!file_exists($excelFile)) { + return array(); + } + + $cacheFile = $cacheBase . sha1($excelFile . '/' . filemtime($excelFile)); + + if (file_exists($cacheFile) && !$assoc) { + $worksheets = json_decode(file_get_contents($cacheFile), true); + } else { + set_time_limit(0); + include_once ROOT . '/inc/ZendFramework/PHPExcel/PHPExcel.php'; + $objReader = PHPExcel_IOFactory::createReader('Excel2007'); + $objPHPExcel = $objReader->load($excelFile); + + foreach ($objPHPExcel->getWorksheetIterator() as $worksheet) { + if ($worksheet->getSheetState() != PHPExcel_Worksheet::SHEETSTATE_VISIBLE) { + continue; + } + $title = $worksheet->getTitle(); + if (strlen($title) == 2 && cubeCountry::getCountry($title)) { + $title = cubeCountry::getCountry($title); + } + + if ($assoc) { + $worksheets[$title] = self::_assocSheet($worksheet->toArray(null, true, true)); + } else { + $worksheets[$title] = $worksheet->toArray(null, true, true); + } + } + file_put_contents($cacheFile, json_encode($worksheets)); + } + + return $worksheets; + } + + public static function excelToArrayKeyVal($excelFile) + { + $worksheets = self::excelToArray($excelFile); + $res = []; + foreach ($worksheets as $worksheet) { + foreach ($worksheet as $line) { + $res[trim($line[0])] = trim($line[1]); + } + break; + } + return $res; + } + + protected static function _assocSheet($s) + { + $res = []; + $colslabels = []; + foreach ($s[0] as $j => $collabel) { + if (trim($collabel) == '') { + continue; + } + $colslabels[$j] = $collabel; + } + for ($i = 1; $i < count($s); $i++) { + $r = []; + foreach ($colslabels as $j => $collabel) { + $r[$collabel] = $s[$i][$j]; + } + $res[] = $r; + } + + return $res; + } + + + public static function atlanticReferences($references, $dir, $log = null, $copy = 'copy') + { + if (!file_exists($dir)) { + mkdir($dir, 0777, true); + } + foreach ($references as $i => $sheet) { + foreach ($sheet as $j => $line) { + foreach ($line as $k => $v) { + if (preg_match('|^http:\/\/atlantic-international-book-com\.com\/files\/(.*)$|', $v, $matches)) { + $local = $dir . '/' . $matches[1]; + $ldir = dirname($local); + if (!file_exists($ldir)) { + mkdir($ldir, 0777, true); + } + $url = str_replace(' ', '%20', $v); + $cache = WS_CACHE . '/atlantic/' . md5($url); + if (!file_exists($cache) || filemtime($url) > filemtime($cache)) { + copy($url, $cache); + $copylog = ' (copy) '; + } else { + $copylog = ' '; + } + call_user_func($copy, $cache, $dir . '/' . $matches[1]); + $references[$i][$j][$k] = 'local/' . $matches[1]; + if (null !== $log) { + call_user_func($log, 'Done' . $copylog . $matches[1]); + } + } + } + } + } + + return $references; + } + + /** + * @param $book wsBook + */ + public static function compilePDF($book, $pages = null) + { + global $core; + + if (null === $pages) { + $dao = new wsDAOBook($core->con); + $pages = $dao->getPagesOfBook($book->book_id); + } + + if (substr($book->parametres->pdfName, 0, 4) == 'http') { + return false; + } + + $cacheDir = WS_BOOKS . '/pdf/' . $book->book_id; + if (!file_exists($cacheDir)) { + mkdir($cacheDir, 0777, true); + } + + $normalPDF = $cacheDir . '/normal.pdf'; + $originalPDF = $cacheDir . '/original.pdf'; + $compressedPDF = $cacheDir . '/compressed.pdf'; + + $files = [$normalPDF, $originalPDF, $compressedPDF]; + + foreach ($files as $file) { + if (file_exists($file) && filesize($file) == 0) { + unlink($file); + } + } + + if (file_exists($originalPDF)) { + $fmtime = filemtime($originalPDF); + if ($fmtime >= $book->composition_update) { + $invalid = false; + foreach ($pages as $i => $infos) { + $doc = wsDocument::getDir($infos['document_id']) . 'crop.pdf'; + if (file_exists($doc) && filemtime($doc) > $fmtime) { + $invalid = true; + } + } + } else { + $invalid = true; + } + } else { + $invalid = true; + } + + + if ($invalid) { + $pdfList = array(); + $pagesList = array(); + $nb_pages = array(); + $j = 0; + $k = 0; + $original = true; + + foreach ($pages as $i => $infos) { + if (!isset($firstDoc)) { + $firstDoc = $infos['document_id']; + } + + $doc = wsDocument::getDir($infos['document_id']) . 'crop.pdf'; + if (!isset($pdfList[$doc])) { + $pdfList[$doc] = $j; + $nb_pages[$doc] = $infos['nb_pages']; + $k = $j; + $j++; + } else { + $k = $pdfList[$doc]; + } + $pagesList[$i] = array($k, $infos['document_page']); + + if ($i != $infos['document_page'] || $infos['document_id'] != $firstDoc) { + $original = false; + } + } + + if ($original) { + self::copy(wsDocument::getDir($firstDoc) . 'crop.pdf', $originalPDF); + } else { + $args = ''; + foreach ($pdfList as $doc => $index) { + $lettre = cubeMath::toPDFLetter($index, true); + $args .= $lettre . '=' . $doc . ' '; + } + + $args .= ' cat '; + + $ranges = array(); + $currentRange = null; + + foreach ($pagesList as $p) { + $lettre = cubeMath::toPDFLetter($p[0], true); + $page = $p[1]; + + // Initialise l'intervale + if (is_null($currentRange)) { + $currentRange = array('lettre' => $lettre, 'start' => $page, 'end' => $page); + continue; + } + + // Poursuit le remplissage si la lettre est identique et si la page suivante est bien la page suivante dans le document + if ($currentRange['lettre'] == $lettre && $currentRange['end'] + 1 == $page) { + $currentRange['end'] = $page; + continue; + } + + // Ajoute l'intervale à la liste finale + $ranges[] = $currentRange; + + // Réinitialise l'intervale suivant + $currentRange = array('lettre' => $lettre, 'start' => $page, 'end' => $page); + } + + // Ajoute la dernière + if (!is_null($currentRange)) { + $ranges[] = $currentRange; + } + // Si le pdf final est constitué du document complet d'un document + if (count($ranges) == 1 && $ranges[0]['start'] == 1) { + $alldocs = array_keys($pdfList); + $doc = array_pop($alldocs); + if ($nb_pages[$doc] == $ranges[0]['end']) { + self::copy($doc, $originalPDF); + return; + } + } + + foreach ($ranges as $range) { + $args .= ' ' . $range['lettre'] . $range['start']; + if ($range['start'] == $range['end']) { + continue; + } + $args .= '-' . $range['end']; + } + + $hash = sha1($args); + + $args .= ' output ' . $originalPDF; + + $cached = WS_BOOKS . '/pdf/' . $hash . '.pdf'; + + if (file_exists($cached) && filesize($cached) > 0) { + self::copy($cached, $originalPDF); + } else { + $pdftk = new cubeCommandLine('pdftk'); + $pdftk->setPath(CONVERTER_PATH); + $pdftk->setManualArg($args); + $pdftk->execute(); + self::copy($normalPDF, $cached); + } + } + } + + + if ($book->parametres->pdfReplace) { + $replace = WS_BOOKS . '/working/' . $book->book_id . '/' . $book->parametres->pdfReplace; + if (file_exists($replace) && filesize($replace) > 0) { + if (!file_exists($normalPDF) || filemtime($normalPDF) < filemtime($replace) || filesize($normalPDF) != filesize($replace)) { + self::copy($replace, $normalPDF); + } + } + } else { + self::copy($originalPDF, $normalPDF); + } + + if ($book->parametres->pdfCompress) { + if (!file_exists($compressedPDF) || filemtime($compressedPDF) < filemtime($normalPDF)) { + $gs = new cubeCommandLine('gs', null, true); + $gs->setPath(CONVERTER_PATH); + $gs->setEnv('GS_FONTPATH', '/home/ws/fonts'); + $gs->setArg('-dBATCH'); + $gs->setArg('-dNOPAUSE'); + $gs->setArg('-dNOPROMPT'); + $gs->setArg('-sOutputFile=' . $compressedPDF); + $gs->setArg('-sDEVICE=pdfwrite'); + $gs->setArg('-dPDFSETTINGS=/ebook'); + $gs->setArg('-dColorImageResolution=72'); + $gs->setArg('-dAutoRotatePages=/None'); + $gs->setArg('-dColorConversionStrategy=/LeaveColorUnchanged'); + $gs->setArg(null, $normalPDF); + $gs->execute(); + } + return $compressedPDF; + } + return $normalPDF; + } + + public static function copy($source, $dest) + { + copy($source, $dest); + touch($dest, filemtime($source)); + } } \ 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 b107d2b63..823a2b44a 100644 --- a/inc/ws/Util/html5/master/class.ws.html5.compiler.php +++ b/inc/ws/Util/html5/master/class.ws.html5.compiler.php @@ -375,7 +375,10 @@ class wsHTML5Compiler $this->addLess('form/avery'); $this->writeCountries(); } + $this->config->seoArticles = $this->seoArticles; + } + public function writeCartConfig(){ if ($this->config->basket) { $this->addJsLib('cart', 'js/libs/fluidbook/fluidbook.cart.js'); switch ($this->config->basketManager) { @@ -387,7 +390,8 @@ class wsHTML5Compiler default: break; } - + } + if ($this->config->basketReferences) { if (file_exists($this->config->basketReferences) || CubeIT_Util_Url::isDistant($this->config->basketReferences)) { $referencesFile = $this->config->basketReferences; } else { @@ -397,7 +401,12 @@ class wsHTML5Compiler if (file_exists($referencesFile) || CubeIT_Util_Url::isDistant($referencesFile)) { $ext = CubeIT_Files::getExtension($referencesFile); if ($ext == 'xlsx') { - $this->config->basketReferences = wsUtil::excelToArray($referencesFile); + if($this->config->basketManager=="ZoomProductLink"){ + $function='excelToArrayKeyVal'; + }else{ + $function='excelToArray'; + } + $this->config->basketReferences = wsUtil::$function($referencesFile); if ($this->book->parametres->customLinkClass == 'AtlanticDownloadLink') { $this->config->basketReferences = wsUtil::atlanticReferences($this->config->basketReferences, 'local/', array($this, 'log'), array($this->vdir, "copy")); } @@ -405,7 +414,6 @@ class wsHTML5Compiler $this->log("Done cart references"); } } - $this->config->seoArticles = $this->seoArticles; } public function writeGPUDatabase() @@ -521,6 +529,7 @@ class wsHTML5Compiler $this->log('Plugins loaded'); $this->writeImages(); $this->log('Images written'); + $this->writeCartConfig(); $linksCSS = $this->writeLinks(); $this->log('Links written'); $this->writeLangs(); @@ -1107,8 +1116,8 @@ class wsHTML5Compiler $e = explode("\n", $ml); $m = array(); foreach ($e as $l1) { - $l1=trim($l1); - if($l1==''){ + $l1 = trim($l1); + if ($l1 == '') { continue; } $l = explode(',', $l1); @@ -1943,9 +1952,6 @@ class wsHTML5Compiler $res[] = '@font-face{font-family: "' . $hash . '";src:url("../../data/fonts/' . $hash . '.woff") format("woff");}'; } - # ZoomPopup close button background - $res[] = '.zoomPopupClose {background-color:' . wsHTML5::colorToCSS($this->theme->parametres->couleurB) . ';}'; - if ($this->book->parametres->textPopupStylesheet) { $res[] = file_get_contents($this->wdir . '/' . $this->book->parametres->textPopupStylesheet); } 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 958a49a5b..af7b04050 100644 --- a/inc/ws/Util/html5/master/class.ws.html5.links.php +++ b/inc/ws/Util/html5/master/class.ws.html5.links.php @@ -1722,6 +1722,12 @@ class zoomLink extends normalLink { protected $maxzoom_default = 2; + public function init() + { + $this->compiler->addJsLib('fluidbook-zoomhd', 'js/libs/fluidbook/links/fluidbook.links.zoom.js'); + parent::init(); + } + public function getHTMLContainerClass() { $class = ' zoomarea'; @@ -1857,18 +1863,25 @@ class zoomProductLink extends zoomLink { public function __construct($id, $init, &$compiler) { + + $init['to'] = trim($init['to']); $init['group'] = $init['to']; parent::__construct($id, $init, $compiler); } public function getZoomAttributes() { - // $cart = $this->compiler->getCartData(); - $url = ''; + $url = isset($this->compiler->config->basketReferences[$this->to]) ? $this->compiler->config->basketReferences[$this->to] : ''; - return array_merge(parent::getZoomAttributes(), - ['maxzoom' => $this->maxzoom_default, 'ref' => $this->to, 'shareurl' => $url, 'producturl' => $url] + $res = array_merge(parent::getZoomAttributes(), + ['maxzoom' => $this->maxzoom_default, 'ref' => $this->to] ); + if ($url) { + $res['shareurl'] = $url; + $res['producturl'] = $url; + } + + return $res; } }