|
|
@ -76,7 +76,7 @@ Class DirScanner { |
|
|
|
|
|
|
|
|
|
|
|
//解析描述文件内容 |
|
|
|
//解析描述文件内容 |
|
|
|
//snapshot相对路径完善,支持secure_link |
|
|
|
//snapshot相对路径完善,支持secure_link |
|
|
|
private function parseDescriptionFiles($realpath, $dirLevel) { |
|
|
|
private function parseDescriptionFiles($realpath) { |
|
|
|
$pathinfo = pathinfo($realpath); |
|
|
|
$pathinfo = pathinfo($realpath); |
|
|
|
$field = preg_replace('/^.+_/', '', $pathinfo['filename']); |
|
|
|
$field = preg_replace('/^.+_/', '', $pathinfo['filename']); |
|
|
|
$content = file_get_contents($realpath); |
|
|
|
$content = file_get_contents($realpath); |
|
|
@ -92,7 +92,7 @@ Class DirScanner { |
|
|
|
fclose($fp); |
|
|
|
fclose($fp); |
|
|
|
$img_pathinfo = pathinfo($img_realpath); |
|
|
|
$img_pathinfo = pathinfo($img_realpath); |
|
|
|
$extension = strtolower($img_pathinfo['extension']); |
|
|
|
$extension = strtolower($img_pathinfo['extension']); |
|
|
|
$content = $this->getFilePath( $id, $this->getDirectoryName($img_pathinfo['dirname'], $dirLevel), $img_pathinfo['filename'], $extension, $fstat['mtime'] ); |
|
|
|
$content = $this->getFilePath( $id, $this->getRelativeDirname($img_pathinfo['dirname']), $img_pathinfo['filename'], $extension, $fstat['mtime'] ); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
@ -168,7 +168,7 @@ Class DirScanner { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
//根据路径生成文件数组,兼容URL文件 |
|
|
|
//根据路径生成文件数组,兼容URL文件 |
|
|
|
private function getFileData($realpath, $dirLevel) { |
|
|
|
private function getFileData($realpath) { |
|
|
|
$id = $this->getId($realpath); |
|
|
|
$id = $this->getId($realpath); |
|
|
|
$fp = fopen($realpath, 'r'); |
|
|
|
$fp = fopen($realpath, 'r'); |
|
|
|
$fstat = fstat($fp); |
|
|
|
$fstat = fstat($fp); |
|
|
@ -186,7 +186,7 @@ Class DirScanner { |
|
|
|
'ctime' => $fstat['ctime'], |
|
|
|
'ctime' => $fstat['ctime'], |
|
|
|
], |
|
|
|
], |
|
|
|
'realpath' => $realpath, |
|
|
|
'realpath' => $realpath, |
|
|
|
'path' => $this->getFilePath( $id, $this->getDirectoryName($pathinfo['dirname'], $dirLevel), $pathinfo['filename'], $extension, $fstat['mtime'] ), |
|
|
|
'path' => $this->getFilePath( $id, $this->getRelativeDirname($pathinfo['dirname']), $pathinfo['filename'], $extension, $fstat['mtime'] ), |
|
|
|
]; |
|
|
|
]; |
|
|
|
|
|
|
|
|
|
|
|
if ($extension == 'url') { |
|
|
|
if ($extension == 'url') { |
|
|
@ -212,19 +212,14 @@ Class DirScanner { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
//根据路径和当前扫描深度获取目录名 |
|
|
|
//根据路径和当前扫描深度获取目录名 |
|
|
|
private function getDirectoryName($dirname, $dirLevel) { |
|
|
|
private function getRelativeDirname($dirname) { |
|
|
|
if ($dirLevel <= 0) {return basename($dirname);} |
|
|
|
return str_replace($this->rootDir, '', $dirname); |
|
|
|
$dirname = preg_replace('/\/$/', '', $dirname); |
|
|
|
|
|
|
|
$dirname = preg_replace('/^\//', '', $dirname); |
|
|
|
|
|
|
|
$names = explode('/', $dirname); |
|
|
|
|
|
|
|
if ($dirLevel >= count($names)) {return $dirname;} |
|
|
|
|
|
|
|
return implode('/', array_splice($names, -$dirLevel)); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
//合并描述文件内容到md文件或者目录数据 |
|
|
|
//合并描述文件内容到md文件或者目录数据 |
|
|
|
private function mergeDescriptionData($realpath, $dirLevel) { |
|
|
|
private function mergeDescriptionData($realpath) { |
|
|
|
$data = []; |
|
|
|
$data = []; |
|
|
|
$ext = $this->parseDescriptionFiles($realpath, $dirLevel); |
|
|
|
$ext = $this->parseDescriptionFiles($realpath); |
|
|
|
|
|
|
|
|
|
|
|
//try to find the md file |
|
|
|
//try to find the md file |
|
|
|
$targetFile = preg_replace('/_?[a-z0-9]+\.txt$/iU', '.md', $realpath); |
|
|
|
$targetFile = preg_replace('/_?[a-z0-9]+\.txt$/iU', '.md', $realpath); |
|
|
@ -494,10 +489,10 @@ Class DirScanner { |
|
|
|
$extension = strtolower($pathinfo['extension']); |
|
|
|
$extension = strtolower($pathinfo['extension']); |
|
|
|
if ( in_array($extension, $this->supportFileExtensions) ) { |
|
|
|
if ( in_array($extension, $this->supportFileExtensions) ) { |
|
|
|
if ($extension != 'txt') { |
|
|
|
if ($extension != 'txt') { |
|
|
|
$branch = $this->getFileData($realpath, $this->scanningDirLevel); |
|
|
|
$branch = $this->getFileData($realpath); |
|
|
|
}else { |
|
|
|
}else { |
|
|
|
//把描述文件内容合并到被描述的目录或md文件数据中 |
|
|
|
//把描述文件内容合并到被描述的目录或md文件数据中 |
|
|
|
$branch = $this->mergeDescriptionData($realpath, $this->scanningDirLevel); |
|
|
|
$branch = $this->mergeDescriptionData($realpath); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
@ -583,4 +578,33 @@ Class DirScanner { |
|
|
|
return $titles; |
|
|
|
return $titles; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//替换.md文件解析之后的HTML中的静态文件URL为相对路径path |
|
|
|
|
|
|
|
public function fixMDUrls($realpath, $html) { |
|
|
|
|
|
|
|
$reg_urls = '/src="([^"]+)"/i'; |
|
|
|
|
|
|
|
preg_match_all($reg_urls, $html, $matches); |
|
|
|
|
|
|
|
if (empty($matches[1])) { |
|
|
|
|
|
|
|
return $html; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$pathinfo = pathinfo($realpath); |
|
|
|
|
|
|
|
foreach ($matches[1] as $url) { |
|
|
|
|
|
|
|
if (preg_match('/^http(s)?:\/\//i', $url)) {continue;} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$img_realpath = "{$pathinfo['dirname']}/{$url}"; |
|
|
|
|
|
|
|
if (file_exists($img_realpath)) { |
|
|
|
|
|
|
|
$id = $this->getId($img_realpath); |
|
|
|
|
|
|
|
$fp = fopen($img_realpath, 'r'); |
|
|
|
|
|
|
|
$fstat = fstat($fp); |
|
|
|
|
|
|
|
fclose($fp); |
|
|
|
|
|
|
|
$img_pathinfo = pathinfo($img_realpath); |
|
|
|
|
|
|
|
$extension = strtolower($img_pathinfo['extension']); |
|
|
|
|
|
|
|
$img_path = $this->getFilePath( $id, $this->getRelativeDirname($img_pathinfo['dirname']), $img_pathinfo['filename'], $extension, $fstat['mtime'] ); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$html = str_replace($url, $img_path, $html); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return $html; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|