From ec9fee1706adcff063e17c1a4ac1ddfcbd9aea35 Mon Sep 17 00:00:00 2001 From: filesite Date: Mon, 25 Apr 2022 11:02:43 +0800 Subject: [PATCH] improve page title and cate title --- lib/DirScanner.php | 13 +++++++++---- themes/googleimage/controller/ListController.php | 3 +++ themes/googleimage/controller/SiteController.php | 3 +++ themes/googleimage/views/site/index.php | 9 ++++++--- 4 files changed, 21 insertions(+), 7 deletions(-) diff --git a/lib/DirScanner.php b/lib/DirScanner.php index cad32fd..30102c2 100644 --- a/lib/DirScanner.php +++ b/lib/DirScanner.php @@ -87,11 +87,14 @@ Class DirScanner { //snapshot相对路径完善,支持secure_link private function parseDescriptionFiles($realpath) { $pathinfo = pathinfo($realpath); - $field = preg_replace('/^.+_/', '', $pathinfo['filename']); - $content = file_get_contents($realpath); + $tmp = explode('_', $pathinfo['filename']); + $field = array_pop($tmp); + $content = @file_get_contents($realpath); + if (empty($content)) {return [];} + $content = trim($content); + $data = []; if (in_array($field, ['title', 'snapshot'])) { - $content = preg_replace('/\s/', '', $content); if ($field == 'snapshot') { $img_realpath = realpath("{$pathinfo['dirname']}/{$content}"); if (file_exists($img_realpath)) { @@ -112,8 +115,9 @@ Class DirScanner { //解析快捷方式文件内容 private function parseShortCuts($realpath, $filename) { - $content = file_get_contents($realpath); + $content = @file_get_contents($realpath); if (empty($content) || !preg_match('/\[InternetShortcut\]/i', $content)) {return false;} + $content = trim($content); preg_match('/URL=(\S+)/i', $content, $matches); if (empty($matches) || empty($matches[1])) { @@ -608,6 +612,7 @@ Class DirScanner { $content = @file_get_contents($file['realpath']); if (empty($content)) {return [];} + $content = trim($content); # standardize line breaks $content = str_replace(array("\r\n", "\r"), "\n", $content); diff --git a/themes/googleimage/controller/ListController.php b/themes/googleimage/controller/ListController.php index d60e316..8819e16 100644 --- a/themes/googleimage/controller/ListController.php +++ b/themes/googleimage/controller/ListController.php @@ -47,6 +47,9 @@ Class ListController extends Controller { $pageTitle = !empty($titles) ? $titles[0]['name'] : "FileSite.io - 无数据库、基于文件和目录的Markdown文档、网址导航、图书、图片、视频网站PHP开源系统"; if (!empty($subcate)) { $pageTitle = "{$subcate['directory']}的照片,来自{$pageTitle}"; + if (!empty($subcate['title'])) { + $pageTitle = $subcate['title']; + } } $viewName = '//site/index'; //共享视图 $params = compact('cateId', 'dirTree', 'scanResults', 'menus', 'htmlReadme', 'breadcrumbs', 'htmlCateReadme'); diff --git a/themes/googleimage/controller/SiteController.php b/themes/googleimage/controller/SiteController.php index 0080a69..606349c 100644 --- a/themes/googleimage/controller/SiteController.php +++ b/themes/googleimage/controller/SiteController.php @@ -45,6 +45,9 @@ Class SiteController extends Controller { $pageTitle = !empty($titles) ? $titles[0]['name'] : "FileSite.io - 无数据库、基于文件和目录的Markdown文档、网址导航、图书、图片、视频网站PHP开源系统"; if (!empty($subcate)) { $pageTitle = "{$subcate['directory']}的照片,来自{$pageTitle}"; + if (!empty($readmeFile['title'])) { + $pageTitle = $readmeFile['title']; + } } $viewName = 'index'; $params = compact('cateId', 'dirTree', 'scanResults', 'menus', 'htmlReadme', 'htmlCateReadme'); diff --git a/themes/googleimage/views/site/index.php b/themes/googleimage/views/site/index.php index 7f64964..c543c98 100644 --- a/themes/googleimage/views/site/index.php +++ b/themes/googleimage/views/site/index.php @@ -87,18 +87,21 @@ eof; } } + $title = !empty($dir['title']) ? $dir['title'] : $dir['directory']; echo <<{$dir['directory']} + {$title} eof; } }else if (!empty($category['files'])) { //一级目录支持 foreach($category['files'] as $file) { if (!in_array($file['extension'], $imgExts)) {continue;} + + $title = !empty($file['title']) ? $file['title'] : $file['filename']; echo << {$file['filename']} - {$file['filename']} + {$title} eof; } @@ -109,7 +112,7 @@ eof;