*/\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
$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
$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
} 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
$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
\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
$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