From: vincent@cubedesigners.com Date: Thu, 17 Sep 2020 15:33:48 +0000 (+0000) Subject: wait #3892 @2 X-Git-Url: http://git.cubedesigners.com/?a=commitdiff_plain;h=9b017a55fec1417cd3b08d7a699bfe8c2300c3ea;p=cubeextranet.git wait #3892 @2 --- diff --git a/inc/ws/Util/class.ws.articles.php b/inc/ws/Util/class.ws.articles.php index 067dfa497..968f12879 100644 --- a/inc/ws/Util/class.ws.articles.php +++ b/inc/ws/Util/class.ws.articles.php @@ -28,6 +28,11 @@ class wsArticles */ protected $_outzip; + /** + * @var array + */ + protected $_ids = []; + public function __construct($file, $format) { $this->setFile($file); @@ -92,11 +97,22 @@ class wsArticles $assets = []; $xmls = []; - for ($i = 0; $i <= $this->_zip->numFiles; $i++) { + $orderedIndexes = []; + + for ($i = 0; $i < $this->_zip->numFiles; $i++) { $fname = $this->_zip->getNameIndex($i); if (stristr($fname, '__MACOSX') || stristr($fname, 'ds_store')) { continue; } + if (preg_match('/page(\d+)/u', $fname, $matches)) { + $order = $matches[1] * 1000 + $i; + $orderedIndexes[$order] = $i; + } + } + ksort($orderedIndexes); + + foreach ($orderedIndexes as $i) { + $fname = $this->_zip->getNameIndex($i); if (!preg_match('/\.xml$/', $fname)) { $c = $this->_zip->getFromIndex($i); if (!$c) { @@ -107,7 +123,8 @@ class wsArticles $dir = implode('/', $e); $fname = $this->_normalizeAssetName($fname, false); $final = $i . '-' . $fname; - $assets[$fname] = ['index' => $i, 'dir' => $dir, 'final' => $final]; + + $assets[$this->_woext($fname)] = ['index' => $i, 'dir' => $dir, 'final' => $final]; file_put_contents($this->_wdir . '/' . $final, $c); } else { $xmls[$fname] = $i; @@ -170,7 +187,11 @@ class wsArticles } else { $id = 'article-' . $index . '-' . $k; } + if (in_array($id, $this->_ids, true)) { + $id .= '-' . $k; + } $url = $id . '.html'; + $this->_ids[] = $id; $clone->setAttribute('id', $id); $clone->setAttribute('url', $url); @@ -183,6 +204,20 @@ class wsArticles $resdom->encoding = 'UTF-8'; $xml = tidy_repair_string($resdom->saveXML(), ['input-xml' => 1, 'indent' => 1, 'wrap' => 0], 'UTF-8'); file_put_contents($file, $xml); + + file_put_contents($this->_wdir . '/id.txt', implode("\r\n", $this->_ids)); + } + + protected function _woext($f) + { + $images = ['jpeg', 'jpg', 'webp', 'gif', 'png']; + $e = explode('.', $f); + + $ext = array_pop($e); + if (in_array($ext, $images)) { + return implode('.', $e); + } + return $f; } /** @@ -259,10 +294,20 @@ class wsArticles protected function _normalizeAssetNameInXML($xml, $assets) { - return preg_replace_callback('/file:\/\/\/[^\"]*/um', function ($matches) use ($assets) { - $aname = $this->_normalizeAssetName($matches[0], false); + $xml = preg_replace_callback('/file:\/\/\/[^\"]*/um', function ($matches) use ($assets) { + $aname = $this->_woext($this->_normalizeAssetName($matches[0], false)); return $assets[$aname]['final']; }, $xml); + + $xml = preg_replace_callback('/href=\"([^\"]+)\"/um', function ($matches) use ($assets) { + if (strpos($matches[1], 'http') === 0) { + return 'href="' . $matches[1] . '"'; + } + $aname = $this->_woext($this->_normalizeAssetName($matches[1], false)); + return 'href="' . $assets[$aname]['final'] . '"'; + }, $xml); + + return $xml; } protected function _normalizeAssetName($fname, $withDir = false) @@ -272,7 +317,7 @@ class wsArticles $fname = array_pop($e); } $fname = rawurldecode($fname); - $fname = str_replace('_opt.', '.', $fname); + $fname = str_replace('_opt', '', $fname); $fname = CubeIT_Text::removeAccents($fname, true); $fname = str_replace('é', 'e', $fname); $fname = str_replace('ç', 'c', $fname);