From 27c3f704f6f7f6e3d984f939d056a0bb0e6968af Mon Sep 17 00:00:00 2001 From: "vincent@cubedesigners.com" Date: Fri, 22 Sep 2017 17:12:52 +0000 Subject: [PATCH] wip #1694 @4 --- inc/ws/DAO/class.ws.dao.book.php | 12 +++++--- inc/ws/Util/class.ws.util.php | 30 ++++++++++++++++++- .../html5/master/class.ws.html5.compiler.php | 3 ++ 3 files changed, 40 insertions(+), 5 deletions(-) diff --git a/inc/ws/DAO/class.ws.dao.book.php b/inc/ws/DAO/class.ws.dao.book.php index 4c1c0cf98..734d3191e 100644 --- a/inc/ws/DAO/class.ws.dao.book.php +++ b/inc/ws/DAO/class.ws.dao.book.php @@ -952,7 +952,7 @@ class wsDAOBook extends commonDAO { foreach ($words as $w) { $word = $w->word; $word = trim($word, "\0"); - if($word==''){ + if ($word == '') { continue; } unset($w->word); @@ -1149,7 +1149,7 @@ class wsDAOBook extends commonDAO { $flexLight = new cubeFlexCompiler('FluidbookDatasLight', $compilerDir, 'flash.display.Sprite', explode(';', AS3_SOURCES), MXMLC_PATH, 10, 30, 800, 600, $debug); $filesToCopy = array(); - $this->compileFlex($book_id, $complete, $compilerDir, $finalDir, $filesToCopy, $book, $pages, $flex, $flexLight); + $this->compileFlex($book_id, $complete, $compilerDir, $finalDir, $filesToCopy, $book, $pages, $flex, $flexLight, $finalDir); $res .= $flex->compile() . "\n\n-------------------\n\n"; $flexLight->addVariable('datasSize', filesize($compilerDir . '/FluidbookDatas.swf')); @@ -1236,7 +1236,7 @@ class wsDAOBook extends commonDAO { return $res; } - public function compileFlex($book_id, $complete, $compilerDir, $finalDir, &$filesToCopy, $book, $pages, $flex, $flexLight) { + public function compileFlex($book_id, $complete, $compilerDir, $finalDir, &$filesToCopy, $book, $pages, $flex, $flexLight, $finalDir) { cubePHP::neverStop(); /* @var $flex cubeFlexCompiler */ @@ -1545,7 +1545,11 @@ class wsDAOBook extends commonDAO { $i++; } } elseif ($ext == 'xlsx') { - $flex->addVariable('basketReferences', wsUtil::excelToArray($referencesFile), false, true, "OrderedObject"); + $references = wsUtil::excelToArray($referencesFile); + if ($book->parametres->customLinkClass == 'AtlanticDownloadLink') { + $references = wsUtil::atlanticReferences($this->config->basketReferences, $finalDir . '/local/'); + } + $flex->addVariable('basketReferences', $references, false, true, "OrderedObject"); } } if (isset($xml)) { diff --git a/inc/ws/Util/class.ws.util.php b/inc/ws/Util/class.ws.util.php index 0e5198063..1d36bd512 100644 --- a/inc/ws/Util/class.ws.util.php +++ b/inc/ws/Util/class.ws.util.php @@ -23,7 +23,7 @@ class wsUtil { $cacheFile = WS_CACHE . '/xlsx2array/' . sha1($excelFile . '/' . filemtime($excelFile)); if (file_exists($cacheFile)) { - $worksheets = json_decode(file_get_contents($cacheFile)); + $worksheets = json_decode(file_get_contents($cacheFile), true); } else { set_time_limit(0); include_once ROOT . '/inc/ZendFramework/PHPExcel/PHPExcel.php'; @@ -46,4 +46,32 @@ class wsUtil { return $worksheets; } + + public static function atlanticReferences($references, $dir) { + 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)) { + copy($url, $cache); + } + copy($cache, $dir . '/' . $matches[1]); + $references[$i][$j][$k] = 'local/' . $matches[1]; + } + } + } + } + + return $references; + } } \ 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 862e68e25..c74a8baeb 100644 --- a/inc/ws/Util/html5/master/class.ws.html5.compiler.php +++ b/inc/ws/Util/html5/master/class.ws.html5.compiler.php @@ -1050,6 +1050,9 @@ class wsHTML5Compiler { $ext = CubeIT_Files::getExtension($referencesFile); if ($ext == 'xlsx') { $this->config->basketReferences = wsUtil::excelToArray($referencesFile); + if ($this->book->parametres->customLinkClass == 'AtlanticDownloadLink') { + $this->config->basketReferences = wsUtil::atlanticReferences($this->config->basketReferences,$this->vdir.'/local/'); + } } } } -- 2.39.5