]> _ Git - cubeextranet.git/commitdiff
wait #3892 @2
authorvincent@cubedesigners.com <vincent@cubedesigners.com@f5622870-0f3c-0410-866d-9cb505b7a8ef>
Thu, 17 Sep 2020 15:33:48 +0000 (15:33 +0000)
committervincent@cubedesigners.com <vincent@cubedesigners.com@f5622870-0f3c-0410-866d-9cb505b7a8ef>
Thu, 17 Sep 2020 15:33:48 +0000 (15:33 +0000)
inc/ws/Util/class.ws.articles.php

index 067dfa497142dfbee4961e2ef9abccfba5780571..968f12879d20cd47c56fd4adcd2594d474faa400 100644 (file)
@@ -28,6 +28,11 @@ class wsArticles
      */\r
     protected $_outzip;\r
 \r
+    /**\r
+     * @var array\r
+     */\r
+    protected $_ids = [];\r
+\r
     public function __construct($file, $format)\r
     {\r
         $this->setFile($file);\r
@@ -92,11 +97,22 @@ class wsArticles
         $assets = [];\r
         $xmls = [];\r
 \r
-        for ($i = 0; $i <= $this->_zip->numFiles; $i++) {\r
+        $orderedIndexes = [];\r
+\r
+        for ($i = 0; $i < $this->_zip->numFiles; $i++) {\r
             $fname = $this->_zip->getNameIndex($i);\r
             if (stristr($fname, '__MACOSX') || stristr($fname, 'ds_store')) {\r
                 continue;\r
             }\r
+            if (preg_match('/page(\d+)/u', $fname, $matches)) {\r
+                $order = $matches[1] * 1000 + $i;\r
+                $orderedIndexes[$order] = $i;\r
+            }\r
+        }\r
+        ksort($orderedIndexes);\r
+\r
+        foreach ($orderedIndexes as $i) {\r
+            $fname = $this->_zip->getNameIndex($i);\r
             if (!preg_match('/\.xml$/', $fname)) {\r
                 $c = $this->_zip->getFromIndex($i);\r
                 if (!$c) {\r
@@ -107,7 +123,8 @@ class wsArticles
                 $dir = implode('/', $e);\r
                 $fname = $this->_normalizeAssetName($fname, false);\r
                 $final = $i . '-' . $fname;\r
-                $assets[$fname] = ['index' => $i, 'dir' => $dir, 'final' => $final];\r
+\r
+                $assets[$this->_woext($fname)] = ['index' => $i, 'dir' => $dir, 'final' => $final];\r
                 file_put_contents($this->_wdir . '/' . $final, $c);\r
             } else {\r
                 $xmls[$fname] = $i;\r
@@ -170,7 +187,11 @@ class wsArticles
                     } else {\r
                         $id = 'article-' . $index . '-' . $k;\r
                     }\r
+                    if (in_array($id, $this->_ids, true)) {\r
+                        $id .= '-' . $k;\r
+                    }\r
                     $url = $id . '.html';\r
+                    $this->_ids[] = $id;\r
                     $clone->setAttribute('id', $id);\r
                     $clone->setAttribute('url', $url);\r
 \r
@@ -183,6 +204,20 @@ class wsArticles
         $resdom->encoding = 'UTF-8';\r
         $xml = tidy_repair_string($resdom->saveXML(), ['input-xml' => 1, 'indent' => 1, 'wrap' => 0], 'UTF-8');\r
         file_put_contents($file, $xml);\r
+\r
+        file_put_contents($this->_wdir . '/id.txt', implode("\r\n", $this->_ids));\r
+    }\r
+\r
+    protected function _woext($f)\r
+    {\r
+        $images = ['jpeg', 'jpg', 'webp', 'gif', 'png'];\r
+        $e = explode('.', $f);\r
+\r
+        $ext = array_pop($e);\r
+        if (in_array($ext, $images)) {\r
+            return implode('.', $e);\r
+        }\r
+        return $f;\r
     }\r
 \r
     /**\r
@@ -259,10 +294,20 @@ class wsArticles
 \r
     protected function _normalizeAssetNameInXML($xml, $assets)\r
     {\r
-        return preg_replace_callback('/file:\/\/\/[^\"]*/um', function ($matches) use ($assets) {\r
-            $aname = $this->_normalizeAssetName($matches[0], false);\r
+        $xml = preg_replace_callback('/file:\/\/\/[^\"]*/um', function ($matches) use ($assets) {\r
+            $aname = $this->_woext($this->_normalizeAssetName($matches[0], false));\r
             return $assets[$aname]['final'];\r
         }, $xml);\r
+\r
+        $xml = preg_replace_callback('/href=\"([^\"]+)\"/um', function ($matches) use ($assets) {\r
+            if (strpos($matches[1], 'http') === 0) {\r
+                return 'href="' . $matches[1] . '"';\r
+            }\r
+            $aname = $this->_woext($this->_normalizeAssetName($matches[1], false));\r
+            return 'href="' . $assets[$aname]['final'] . '"';\r
+        }, $xml);\r
+\r
+        return $xml;\r
     }\r
 \r
     protected function _normalizeAssetName($fname, $withDir = false)\r
@@ -272,7 +317,7 @@ class wsArticles
             $fname = array_pop($e);\r
         }\r
         $fname = rawurldecode($fname);\r
-        $fname = str_replace('_opt.', '.', $fname);\r
+        $fname = str_replace('_opt', '', $fname);\r
         $fname = CubeIT_Text::removeAccents($fname, true);\r
         $fname = str_replace('é', 'e', $fname);\r
         $fname = str_replace('ç', 'c', $fname);\r