Browse Source

improve realpath of links and static files

master
filesite 3 years ago
parent
commit
4756237d34
  1. 5
      lib/DirScanner.php
  2. 20
      test/DirScannerTest.php
  3. 25
      test/init_test_files.sh

5
lib/DirScanner.php

@ -84,7 +84,7 @@ Class DirScanner {
if (in_array($field, ['title', 'snapshot'])) { if (in_array($field, ['title', 'snapshot'])) {
$content = preg_replace('/\s/', '', $content); $content = preg_replace('/\s/', '', $content);
if ($field == 'snapshot') { if ($field == 'snapshot') {
$img_realpath = "{$pathinfo['dirname']}/{$content}"; $img_realpath = realpath("{$pathinfo['dirname']}/{$content}");
if (file_exists($img_realpath)) { if (file_exists($img_realpath)) {
$id = $this->getId($img_realpath); $id = $this->getId($img_realpath);
$fp = fopen($img_realpath, 'r'); $fp = fopen($img_realpath, 'r');
@ -602,8 +602,7 @@ Class DirScanner {
foreach ($matches as $url) { foreach ($matches as $url) {
if (preg_match('/^http(s)?:\/\//i', $url) || preg_match('/^\//i', $url)) {continue;} if (preg_match('/^http(s)?:\/\//i', $url) || preg_match('/^\//i', $url)) {continue;}
$src_realpath = !preg_match('/^\.\//', $url) ? "{$pathinfo['dirname']}/{$url}" : "{$pathinfo['dirname']}/" . preg_replace('/^\.\//', '', $url); $src_realpath = realpath("{$pathinfo['dirname']}/{$url}");
if (file_exists($src_realpath)) { if (file_exists($src_realpath)) {
$id = $this->getId($src_realpath); $id = $this->getId($src_realpath);
$fp = fopen($src_realpath, 'r'); $fp = fopen($src_realpath, 'r');

20
test/DirScannerTest.php

@ -71,24 +71,24 @@ $dirTree = $scanner->scan(__DIR__ . '/content/', 4);
echo "Time cost: {$scanner->scanTimeCost} ms\n"; echo "Time cost: {$scanner->scanTimeCost} ms\n";
echo "\n"; echo "\n";
$readme_id = '6a8a2df95732bd046e20269707a70171'; $readme_id = 'cd3075de9c038921184388bbdd1f08c2';
$readme_titles = $scanner->getMDTitles($readme_id); $readme_titles = $scanner->getMDTitles($readme_id);
echo "Titles of MD file {$readme_id}:\n"; echo "Titles of MD file {$readme_id}:\n";
print_r($readme_titles); print_r($readme_titles);
echo "\n"; echo "\n";
echo "\n"; echo "\n";
$menus = $scanner->getMenus(); //$menus = $scanner->getMenus();
echo "Directories:\n"; //echo "Directories:\n";
print_r($menus); //print_r($menus);
echo "\n"; //echo "\n";
echo "\n"; //echo "\n";
echo "Directories and files' tree:\n"; //echo "Directories and files' tree:\n";
print_r($dirTree); //print_r($dirTree);
echo "\n"; //echo "\n";
echo "\n"; //echo "\n";
$scanResults = $scanner->getScanResults(); $scanResults = $scanner->getScanResults();

25
test/init_test_files.sh

@ -51,9 +51,34 @@ tee "Readme.md" <<EOF
<img src="小说/金庸小说/最爱金庸网站图标.ico" alt="金庸小说"> <img src="小说/金庸小说/最爱金庸网站图标.ico" alt="金庸小说">
<img src="./小说/古龙小说/最爱古龙网站图标.ico" alt="古龙小说"> <img src="./小说/古龙小说/最爱古龙网站图标.ico" alt="古龙小说">
<img src="../favs/小说/古龙小说/最爱古龙网站图标.ico" alt="古龙小说2">
## 其它
<a href="Others.md" title="其它">其它</a>
EOF
tee "Others.md" <<EOF
# 其它
补充说明。
## 注意事项
测试md文件相互连接。
## 参考文档
Google、Bing等。
<a href="Readme.md" title="首页">返回首页</a>
EOF EOF
mkdir -p "小说/金庸小说/" mkdir -p "小说/金庸小说/"
mkdir -p "小说/古龙小说/" mkdir -p "小说/古龙小说/"
mkdir -p "图片/图片搜索/" mkdir -p "图片/图片搜索/"

Loading…
Cancel
Save