|
|
@ -10,12 +10,12 @@ Class DirScanner { |
|
|
|
private $userIp = '127.0.0.1'; //用户IP地址 |
|
|
|
private $userIp = '127.0.0.1'; //用户IP地址 |
|
|
|
private $nginxSecureTimeout = 1800; //Nginx防盗链有效期,单位:秒 |
|
|
|
private $nginxSecureTimeout = 1800; //Nginx防盗链有效期,单位:秒 |
|
|
|
private $nginxSecureLinkMd5Pattern = '{secure_link_expires}{uri}{remote_addr} {secret}'; //Nginx防盗链MD5加密方式 |
|
|
|
private $nginxSecureLinkMd5Pattern = '{secure_link_expires}{uri}{remote_addr} {secret}'; //Nginx防盗链MD5加密方式 |
|
|
|
private $allowReadContentFileExtensions = [ //允许读取文件内容的文件类型 |
|
|
|
private $allowReadContentFileExtensions = array( //允许读取文件内容的文件类型 |
|
|
|
'txt', |
|
|
|
'txt', |
|
|
|
'md', |
|
|
|
'md', |
|
|
|
'url', |
|
|
|
'url', |
|
|
|
]; |
|
|
|
); |
|
|
|
private $fields = [ //私有属性字段名和说明 |
|
|
|
private $fields = array( //私有属性字段名和说明 |
|
|
|
'directory' => '目录名', |
|
|
|
'directory' => '目录名', |
|
|
|
'filename' => '文件名', |
|
|
|
'filename' => '文件名', |
|
|
|
'realpath' => '完整路径', |
|
|
|
'realpath' => '完整路径', |
|
|
@ -28,16 +28,16 @@ Class DirScanner { |
|
|
|
'description' => '描述', |
|
|
|
'description' => '描述', |
|
|
|
'keywords' => '关键词', |
|
|
|
'keywords' => '关键词', |
|
|
|
'snapshot' => '快照图片', |
|
|
|
'snapshot' => '快照图片', |
|
|
|
]; |
|
|
|
); |
|
|
|
private $rootDir; //当前扫描的根目录 |
|
|
|
private $rootDir; //当前扫描的根目录 |
|
|
|
private $webRoot = '/content/'; //网站静态文件相对路径的根目录 |
|
|
|
private $webRoot = '/content/'; //网站静态文件相对路径的根目录 |
|
|
|
private $scanningDirLevel = 0; //当前扫描的目录深度 |
|
|
|
private $scanningDirLevel = 0; //当前扫描的目录深度 |
|
|
|
private $scanStartTime = 0; //扫描开始时间,单位:秒 |
|
|
|
private $scanStartTime = 0; //扫描开始时间,单位:秒 |
|
|
|
private $scanResults = []; //目录扫描结果 |
|
|
|
private $scanResults = array(); //目录扫描结果 |
|
|
|
private $tree = []; //目录扫描树形结构 |
|
|
|
private $tree = array(); //目录扫描树形结构 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
protected $supportFileExtensions = [ //支持的文件类型 |
|
|
|
protected $supportFileExtensions = array( //支持的文件类型 |
|
|
|
'txt', //纯文本 |
|
|
|
'txt', //纯文本 |
|
|
|
'md', //纯文本 |
|
|
|
'md', //纯文本 |
|
|
|
'url', //快捷方式 |
|
|
|
'url', //快捷方式 |
|
|
@ -49,8 +49,8 @@ Class DirScanner { |
|
|
|
'mp4', //视频 |
|
|
|
'mp4', //视频 |
|
|
|
'ts', //视频 |
|
|
|
'ts', //视频 |
|
|
|
'm3u8', //视频 |
|
|
|
'm3u8', //视频 |
|
|
|
]; |
|
|
|
); |
|
|
|
protected $maxReadFilesize = [ //默认每种文件读取内容最大大小 |
|
|
|
protected $maxReadFilesize = array( //默认每种文件读取内容最大大小 |
|
|
|
'txt' => 100*1024, //纯文本 |
|
|
|
'txt' => 100*1024, //纯文本 |
|
|
|
'md' => 5*1024*1024, //纯文本 |
|
|
|
'md' => 5*1024*1024, //纯文本 |
|
|
|
'url' => 20*1024, //快捷方式 |
|
|
|
'url' => 20*1024, //快捷方式 |
|
|
@ -62,8 +62,8 @@ Class DirScanner { |
|
|
|
'mp4' => 100*1024*1024, //视频 |
|
|
|
'mp4' => 100*1024*1024, //视频 |
|
|
|
'ts' => 10*1024*1024, //视频 |
|
|
|
'ts' => 10*1024*1024, //视频 |
|
|
|
'm3u8' => 10*1024*1024, //视频 |
|
|
|
'm3u8' => 10*1024*1024, //视频 |
|
|
|
]; |
|
|
|
); |
|
|
|
protected $securedFileExtensions = [ //开启Nginx防盗链的文件类型 |
|
|
|
protected $securedFileExtensions = array( //开启Nginx防盗链的文件类型 |
|
|
|
'jpg', //图片 |
|
|
|
'jpg', //图片 |
|
|
|
'jpeg', //图片 |
|
|
|
'jpeg', //图片 |
|
|
|
'png', //图片 |
|
|
|
'png', //图片 |
|
|
@ -72,7 +72,7 @@ Class DirScanner { |
|
|
|
'mp4', //视频 |
|
|
|
'mp4', //视频 |
|
|
|
'ts', //视频 |
|
|
|
'ts', //视频 |
|
|
|
'm3u8', //视频 |
|
|
|
'm3u8', //视频 |
|
|
|
]; |
|
|
|
); |
|
|
|
|
|
|
|
|
|
|
|
public $scanTimeCost = 0; //上一次目录扫描耗时,单位:毫秒 |
|
|
|
public $scanTimeCost = 0; //上一次目录扫描耗时,单位:毫秒 |
|
|
|
|
|
|
|
|
|
|
@ -93,7 +93,7 @@ Class DirScanner { |
|
|
|
if (empty($content)) {return [];} |
|
|
|
if (empty($content)) {return [];} |
|
|
|
$content = trim($content); |
|
|
|
$content = trim($content); |
|
|
|
|
|
|
|
|
|
|
|
$data = []; |
|
|
|
$data = array(); |
|
|
|
if (in_array($field, ['title', 'snapshot'])) { |
|
|
|
if (in_array($field, ['title', 'snapshot'])) { |
|
|
|
if ($field == 'snapshot') { |
|
|
|
if ($field == 'snapshot') { |
|
|
|
$img_realpath = realpath("{$pathinfo['dirname']}/{$content}"); |
|
|
|
$img_realpath = realpath("{$pathinfo['dirname']}/{$content}"); |
|
|
@ -143,12 +143,12 @@ Class DirScanner { |
|
|
|
private function isNginxSecureLinkMd5PatternValid($pattern) { |
|
|
|
private function isNginxSecureLinkMd5PatternValid($pattern) { |
|
|
|
$valid = true; |
|
|
|
$valid = true; |
|
|
|
|
|
|
|
|
|
|
|
$fieldsNeeded = [ |
|
|
|
$fieldsNeeded = array( |
|
|
|
'{secure_link_expires}', |
|
|
|
'{secure_link_expires}', |
|
|
|
'{uri}', |
|
|
|
'{uri}', |
|
|
|
'{remote_addr}', |
|
|
|
'{remote_addr}', |
|
|
|
'{secret}', |
|
|
|
'{secret}', |
|
|
|
]; |
|
|
|
); |
|
|
|
foreach($fieldsNeeded as $needle) { |
|
|
|
foreach($fieldsNeeded as $needle) { |
|
|
|
if (strstr($pattern, $needle) === false) { |
|
|
|
if (strstr($pattern, $needle) === false) { |
|
|
|
$valid = false; |
|
|
|
$valid = false; |
|
|
@ -162,15 +162,15 @@ Class DirScanner { |
|
|
|
//根据路径生成目录数组 |
|
|
|
//根据路径生成目录数组 |
|
|
|
private function getDirData($realpath, $files) { |
|
|
|
private function getDirData($realpath, $files) { |
|
|
|
$id = $this->getId($realpath); |
|
|
|
$id = $this->getId($realpath); |
|
|
|
$data = [ |
|
|
|
$data = array( |
|
|
|
'id' => $id, |
|
|
|
'id' => $id, |
|
|
|
'directory' => basename($realpath), |
|
|
|
'directory' => basename($realpath), |
|
|
|
'realpath' => $realpath, |
|
|
|
'realpath' => $realpath, |
|
|
|
'path' => $this->getDirPath($id), |
|
|
|
'path' => $this->getDirPath($id), |
|
|
|
]; |
|
|
|
); |
|
|
|
|
|
|
|
|
|
|
|
$sub_dirs = []; |
|
|
|
$sub_dirs = array(); |
|
|
|
$sub_files = []; |
|
|
|
$sub_files = array(); |
|
|
|
|
|
|
|
|
|
|
|
//try to merge description data |
|
|
|
//try to merge description data |
|
|
|
if (!empty($files[$id])) { |
|
|
|
if (!empty($files[$id])) { |
|
|
@ -205,19 +205,19 @@ Class DirScanner { |
|
|
|
fclose($fp); |
|
|
|
fclose($fp); |
|
|
|
$pathinfo = pathinfo($realpath); |
|
|
|
$pathinfo = pathinfo($realpath); |
|
|
|
$extension = strtolower($pathinfo['extension']); |
|
|
|
$extension = strtolower($pathinfo['extension']); |
|
|
|
$data = [ |
|
|
|
$data = array( |
|
|
|
'id' => $id, |
|
|
|
'id' => $id, |
|
|
|
'filename' => $pathinfo['filename'], |
|
|
|
'filename' => $pathinfo['filename'], |
|
|
|
'extension' => $extension, |
|
|
|
'extension' => $extension, |
|
|
|
'fstat' => [ |
|
|
|
'fstat' => array( |
|
|
|
'size' => $fstat['size'], |
|
|
|
'size' => $fstat['size'], |
|
|
|
'atime' => $fstat['atime'], |
|
|
|
'atime' => $fstat['atime'], |
|
|
|
'mtime' => $fstat['mtime'], |
|
|
|
'mtime' => $fstat['mtime'], |
|
|
|
'ctime' => $fstat['ctime'], |
|
|
|
'ctime' => $fstat['ctime'], |
|
|
|
], |
|
|
|
), |
|
|
|
'realpath' => $realpath, |
|
|
|
'realpath' => $realpath, |
|
|
|
'path' => $this->getFilePath( $id, $this->getRelativeDirname($pathinfo['dirname']), $pathinfo['filename'], $extension, $fstat['mtime'] ), |
|
|
|
'path' => $this->getFilePath( $id, $this->getRelativeDirname($pathinfo['dirname']), $pathinfo['filename'], $extension, $fstat['mtime'] ), |
|
|
|
]; |
|
|
|
); |
|
|
|
|
|
|
|
|
|
|
|
if ($extension == 'url') { |
|
|
|
if ($extension == 'url') { |
|
|
|
$data['shortcut'] = $this->parseShortCuts($realpath, $pathinfo['filename']); |
|
|
|
$data['shortcut'] = $this->parseShortCuts($realpath, $pathinfo['filename']); |
|
|
@ -251,7 +251,7 @@ Class DirScanner { |
|
|
|
//合并描述文件内容到md文件或者目录数据 |
|
|
|
//合并描述文件内容到md文件或者目录数据 |
|
|
|
//增加视频文件:mp4, m3u8描述文件支持 |
|
|
|
//增加视频文件:mp4, m3u8描述文件支持 |
|
|
|
private function mergeDescriptionData($realpath) { |
|
|
|
private function mergeDescriptionData($realpath) { |
|
|
|
$data = []; |
|
|
|
$data = array(); |
|
|
|
$ext = $this->parseDescriptionFiles($realpath); |
|
|
|
$ext = $this->parseDescriptionFiles($realpath); |
|
|
|
|
|
|
|
|
|
|
|
//try to find the md file |
|
|
|
//try to find the md file |
|
|
@ -337,7 +337,7 @@ Class DirScanner { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
$webRoot = preg_replace('/\/$/', '', $this->webRoot); |
|
|
|
$webRoot = preg_replace('/\/$/', '', $this->webRoot); |
|
|
|
$extensionPathMap = [ //默认每种文件读取内容最大大小 |
|
|
|
$extensionPathMap = array( //默认每种文件读取内容最大大小 |
|
|
|
'txt' => '', |
|
|
|
'txt' => '', |
|
|
|
'md' => '/view/', |
|
|
|
'md' => '/view/', |
|
|
|
'url' => '/link/', |
|
|
|
'url' => '/link/', |
|
|
@ -349,7 +349,7 @@ Class DirScanner { |
|
|
|
'ico' => "{$webRoot}{$directory}{$filename}.{$extension}", |
|
|
|
'ico' => "{$webRoot}{$directory}{$filename}.{$extension}", |
|
|
|
'mp4' => "{$webRoot}{$directory}{$filename}.{$extension}", |
|
|
|
'mp4' => "{$webRoot}{$directory}{$filename}.{$extension}", |
|
|
|
'ts' => "{$webRoot}{$directory}{$filename}.{$extension}", |
|
|
|
'ts' => "{$webRoot}{$directory}{$filename}.{$extension}", |
|
|
|
]; |
|
|
|
); |
|
|
|
|
|
|
|
|
|
|
|
$path = isset($extensionPathMap[$extension]) ? $extensionPathMap[$extension] : ''; |
|
|
|
$path = isset($extensionPathMap[$extension]) ? $extensionPathMap[$extension] : ''; |
|
|
|
|
|
|
|
|
|
|
@ -515,10 +515,10 @@ Class DirScanner { |
|
|
|
foreach($files as $file) { |
|
|
|
foreach($files as $file) { |
|
|
|
if (in_array($file, $ignore_files) || !$this->isValid($file)) {continue;} |
|
|
|
if (in_array($file, $ignore_files) || !$this->isValid($file)) {continue;} |
|
|
|
|
|
|
|
|
|
|
|
$branch = []; |
|
|
|
$branch = array(); |
|
|
|
$realpath = realpath("{$dir}{$file}"); |
|
|
|
$realpath = realpath("{$dir}{$file}"); |
|
|
|
if (is_dir($realpath)) { |
|
|
|
if (is_dir($realpath)) { |
|
|
|
$files = []; |
|
|
|
$files = array(); |
|
|
|
if ($nextLevels >= 0) { |
|
|
|
if ($nextLevels >= 0) { |
|
|
|
$files = $this->scan($realpath, $levels); |
|
|
|
$files = $this->scan($realpath, $levels); |
|
|
|
if (!empty($files)) { |
|
|
|
if (!empty($files)) { |
|
|
@ -575,19 +575,19 @@ Class DirScanner { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
//获取菜单,扫描结果中的目录结构 |
|
|
|
//获取菜单,扫描结果中的目录结构 |
|
|
|
public function getMenus($tree = []) { |
|
|
|
public function getMenus($tree = array()) { |
|
|
|
$results = empty($tree) ? $this->tree : $tree; |
|
|
|
$results = empty($tree) ? $this->tree : $tree; |
|
|
|
$menus = []; |
|
|
|
$menus = array(); |
|
|
|
if (empty($results)) {return $menus;} |
|
|
|
if (empty($results)) {return $menus;} |
|
|
|
|
|
|
|
|
|
|
|
foreach ($results as $id => $item) { |
|
|
|
foreach ($results as $id => $item) { |
|
|
|
$dir = []; |
|
|
|
$dir = array(); |
|
|
|
if (!empty($item['directory'])) { |
|
|
|
if (!empty($item['directory'])) { |
|
|
|
$dir = [ |
|
|
|
$dir = array( |
|
|
|
'id' => $item['id'], |
|
|
|
'id' => $item['id'], |
|
|
|
'directory' => $item['directory'], |
|
|
|
'directory' => $item['directory'], |
|
|
|
'path' => $item['path'], |
|
|
|
'path' => $item['path'], |
|
|
|
]; |
|
|
|
); |
|
|
|
if (!empty($item['snapshot'])) { |
|
|
|
if (!empty($item['snapshot'])) { |
|
|
|
$dir['snapshot'] = $item['snapshot']; |
|
|
|
$dir['snapshot'] = $item['snapshot']; |
|
|
|
} |
|
|
|
} |
|
|
@ -633,17 +633,17 @@ Class DirScanner { |
|
|
|
# split text into lines |
|
|
|
# split text into lines |
|
|
|
$lines = explode("\n", $content); |
|
|
|
$lines = explode("\n", $content); |
|
|
|
|
|
|
|
|
|
|
|
$titles = []; |
|
|
|
$titles = array(); |
|
|
|
if (!empty($lines)) { |
|
|
|
if (!empty($lines)) { |
|
|
|
foreach($lines as $line) { |
|
|
|
foreach($lines as $line) { |
|
|
|
preg_match_all('/^#(.+)/u', $line, $matches); |
|
|
|
preg_match_all('/^#(.+)/u', $line, $matches); |
|
|
|
if (!empty($matches[1])) { |
|
|
|
if (!empty($matches[1])) { |
|
|
|
foreach($matches[1] as $title) { |
|
|
|
foreach($matches[1] as $title) { |
|
|
|
$num = substr_count($title, '#'); |
|
|
|
$num = substr_count($title, '#'); |
|
|
|
$titles[] = [ |
|
|
|
$titles[] = array( |
|
|
|
'name' => trim(str_replace('#', '', $title)), |
|
|
|
'name' => trim(str_replace('#', '', $title)), |
|
|
|
'heading' => 'h' . ($num+1), |
|
|
|
'heading' => 'h' . ($num+1), |
|
|
|
]; |
|
|
|
); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
@ -656,7 +656,7 @@ Class DirScanner { |
|
|
|
public function fixMDUrls($realpath, $html) { |
|
|
|
public function fixMDUrls($realpath, $html) { |
|
|
|
$pathinfo = pathinfo($realpath); |
|
|
|
$pathinfo = pathinfo($realpath); |
|
|
|
|
|
|
|
|
|
|
|
$matches = []; |
|
|
|
$matches = array(); |
|
|
|
|
|
|
|
|
|
|
|
//匹配图片地址 |
|
|
|
//匹配图片地址 |
|
|
|
$reg_imgs = '/src="([^"]+)"/i'; |
|
|
|
$reg_imgs = '/src="([^"]+)"/i'; |
|
|
|