|
|
@ -580,27 +580,41 @@ Class DirScanner { |
|
|
|
|
|
|
|
|
|
|
|
//替换.md文件解析之后的HTML中的静态文件URL为相对路径path |
|
|
|
//替换.md文件解析之后的HTML中的静态文件URL为相对路径path |
|
|
|
public function fixMDUrls($realpath, $html) { |
|
|
|
public function fixMDUrls($realpath, $html) { |
|
|
|
$reg_urls = '/src="([^"]+)"/i'; |
|
|
|
$pathinfo = pathinfo($realpath); |
|
|
|
preg_match_all($reg_urls, $html, $matches); |
|
|
|
|
|
|
|
if (empty($matches[1])) { |
|
|
|
$matches = []; |
|
|
|
return $html; |
|
|
|
|
|
|
|
|
|
|
|
//匹配图片地址 |
|
|
|
|
|
|
|
$reg_imgs = '/src="([^"]+)"/i'; |
|
|
|
|
|
|
|
preg_match_all($reg_imgs, $html, $img_matches); |
|
|
|
|
|
|
|
if (!empty($img_matches[1])) { |
|
|
|
|
|
|
|
$matches = $img_matches[1]; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
$pathinfo = pathinfo($realpath); |
|
|
|
//匹配a链接 |
|
|
|
foreach ($matches[1] as $url) { |
|
|
|
$reg_links = '/href="([^"]+)"/i'; |
|
|
|
if (preg_match('/^http(s)?:\/\//i', $url)) {continue;} |
|
|
|
preg_match_all($reg_links, $html, $link_matches); |
|
|
|
|
|
|
|
if (!empty($link_matches[1])) { |
|
|
|
$img_realpath = "{$pathinfo['dirname']}/{$url}"; |
|
|
|
$matches = array_merge($matches, $link_matches[1]); |
|
|
|
if (file_exists($img_realpath)) { |
|
|
|
} |
|
|
|
$id = $this->getId($img_realpath); |
|
|
|
|
|
|
|
$fp = fopen($img_realpath, 'r'); |
|
|
|
if (!empty($matches)) { |
|
|
|
$fstat = fstat($fp); |
|
|
|
foreach ($matches as $url) { |
|
|
|
fclose($fp); |
|
|
|
if (preg_match('/^http(s)?:\/\//i', $url)) {continue;} |
|
|
|
$img_pathinfo = pathinfo($img_realpath); |
|
|
|
|
|
|
|
$extension = strtolower($img_pathinfo['extension']); |
|
|
|
$src_realpath = "{$pathinfo['dirname']}/{$url}"; |
|
|
|
$img_path = $this->getFilePath( $id, $this->getRelativeDirname($img_pathinfo['dirname']), $img_pathinfo['filename'], $extension, $fstat['mtime'] ); |
|
|
|
if (file_exists($src_realpath)) { |
|
|
|
|
|
|
|
$id = $this->getId($src_realpath); |
|
|
|
$html = str_replace($url, $img_path, $html); |
|
|
|
$fp = fopen($src_realpath, 'r'); |
|
|
|
|
|
|
|
$fstat = fstat($fp); |
|
|
|
|
|
|
|
fclose($fp); |
|
|
|
|
|
|
|
$src_pathinfo = pathinfo($src_realpath); |
|
|
|
|
|
|
|
$extension = strtolower($src_pathinfo['extension']); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$src_path = $this->getFilePath( $id, $this->getRelativeDirname($src_pathinfo['dirname']), $src_pathinfo['filename'], $extension, $fstat['mtime'] ); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$html = str_replace("\"{$url}\"", "\"{$src_path}\"", $html); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|