Browse Source

Theme GoogleImage v1.0 released

master
filesite 3 years ago
parent
commit
f49159c212
  1. 2
      conf/app.php
  2. 19
      lib/DirScanner.php
  3. 29
      themes/googleimage/controller/ListController.php
  4. 6
      themes/googleimage/views/layout/main.php
  5. 32
      themes/googleimage/views/site/index.php
  6. 2
      www/content/Class_DirScanner.md
  7. 3
      www/content/Manual.md
  8. 1
      www/css/googleimage.css

2
conf/app.php

@ -22,6 +22,6 @@ return array(
//for themes //for themes
'googleimage' => [ 'googleimage' => [
'imageHeight' => 180, //图片高度,单位:px 'imageHeight' => 180, //图片高度,单位:px
'contact' => 'FileSite图片网站订制联系:<a href="https://filesite.io" target="_blank">FileSite.io</a>',
], ],
); );

19
lib/DirScanner.php

@ -513,12 +513,24 @@ Class DirScanner {
} }
$branch = $this->getDirData($realpath, $files); $branch = $this->getDirData($realpath, $files);
//add parent directory's id
$pid = $this->getId(realpath($dir));
if (!empty($pid)) {
$branch = array_merge(['pid' => $pid], $branch);
}
}else { }else {
$pathinfo = pathinfo($realpath); $pathinfo = pathinfo($realpath);
$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); $branch = $this->getFileData($realpath);
//add parent directory's id
$pid = $this->getId(realpath($dir));
if (!empty($pid)) {
$branch = array_merge(['pid' => $pid], $branch);
}
}else { }else {
//把描述文件内容合并到被描述的目录或md文件数据中 //把描述文件内容合并到被描述的目录或md文件数据中
$branch = $this->mergeDescriptionData($realpath); $branch = $this->mergeDescriptionData($realpath);
@ -569,10 +581,13 @@ Class DirScanner {
if (!empty($item['description'])) { if (!empty($item['description'])) {
$dir['description'] = $item['description']; $dir['description'] = $item['description'];
} }
if (!empty($item['pid'])) {
$dir['pid'] = $item['pid'];
}
} }
if (!empty($item['files'])) { if (!empty($item['directories'])) {
$dirs = $this->getMenus($item['files']); $dirs = $this->getMenus($item['directories']);
if (!empty($dirs)) { if (!empty($dirs)) {
$dir['directories'] = $dirs; $dir['directories'] = $dirs;
} }

29
themes/googleimage/controller/ListController.php

@ -30,13 +30,36 @@ Class ListController extends Controller {
$html = $scanner->fixMDUrls($readmeFile['realpath'], $html); $html = $scanner->fixMDUrls($readmeFile['realpath'], $html);
} }
//TODO: 获取父目录,生成面包屑 //获取目录面包屑
$subcate = $scanResults[$cateId];
$breadcrumbs = $this->getBreadcrumbs($menus, $subcate);
$pageTitle = !empty($titles) ? $titles[0]['name'] : "FileSite.io - 无数据库、基于文件和目录的Markdown文档、网址导航、图书、图片、视频网站PHP开源系统"; $pageTitle = !empty($titles) ? $titles[0]['name'] : "FileSite.io - 无数据库、基于文件和目录的Markdown文档、网址导航、图书、图片、视频网站PHP开源系统";
$viewName = '//site/index'; //共享视图 $viewName = '//site/index'; //共享视图
$params = compact('cateId', 'dirTree', 'scanResults', 'menus', 'html'); $params = compact('cateId', 'dirTree', 'scanResults', 'menus', 'html', 'breadcrumbs');
return $this->render($viewName, $params, $pageTitle); return $this->render($viewName, $params, $pageTitle);
} }
//根据目录结构以及当前目录获取面包屑
protected function getBreadcrumbs($menus, $subcate) {
$breads = [];
array_push($breads, [
'id' => $subcate['id'],
'name' => $subcate['directory'],
'url' => $subcate['path'],
]);
$foundKey = array_search($subcate['pid'], array_column($menus, 'id'));
if ($foundKey !== false) {
array_unshift($breads, [
'id' => $menus[$foundKey]['id'],
'name' => $menus[$foundKey]['directory'],
'url' => $menus[$foundKey]['path'],
]);
}
return $breads;
}
} }

6
themes/googleimage/views/layout/main.php

@ -41,6 +41,12 @@ if (!empty($viewFile) && file_exists($viewFile)) {
<br> <br>
<?php } ?> <?php } ?>
&copy;FSC 2022 - execute time: {page_time_cost} ms &copy;FSC 2022 - execute time: {page_time_cost} ms
<?php if (!empty(FSC::$app['config']['googleimage']['contact'])) {
$contactInfo = FSC::$app['config']['googleimage']['contact'];
echo <<<eof
<p>{$contactInfo}</p>
eof;
} ?>
</div> </div>
<!-- The Gallery as lightbox dialog, should be a document body child element --> <!-- The Gallery as lightbox dialog, should be a document body child element -->

32
themes/googleimage/views/site/index.php

@ -1,9 +1,10 @@
<div class="menu"> <div class="menu">
<?php <?php
$selectedId = $viewData['cateId']; $selectedId = $viewData['cateId'];
if (!empty($viewData['menus'])) { $breadcrumbs = $viewData['breadcrumbs'];
if (!empty($viewData['menus'])) { //只显示第一级目录
foreach($viewData['menus'] as $index => $item) { foreach($viewData['menus'] as $index => $item) {
$selected = $item['id'] == $selectedId ? 'selected' : ''; $selected = $item['id'] == $selectedId || (!empty($breadcrumbs) && $item['id'] == $breadcrumbs[0]['id']) ? 'selected' : '';
echo <<<eof echo <<<eof
<a href="/?id={$item['id']}" class="{$selected}">{$item['directory']}</a> <a href="/?id={$item['id']}" class="{$selected}">{$item['directory']}</a>
eof; eof;
@ -14,7 +15,32 @@ eof;
<div class="hr"></div> <div class="hr"></div>
<div class="content markdown-body"> <?php
if (!empty($breadcrumbs)) {
echo <<<eof
<div class="breadcrumbs">
<small>当前位置:</small>
eof;
foreach($breadcrumbs as $bread) {
if ($bread['id'] != $selectedId) {
echo <<<eof
<a href="{$bread['url']}">{$bread['name']}</a> /
eof;
}else {
echo <<<eof
<strong>{$bread['name']}</strong>
eof;
}
}
echo <<<eof
</div>
eof;
}
?>
<div class="content">
<?php <?php
$imgExts = ['jpg', 'jpeg', 'png', 'gif']; $imgExts = ['jpg', 'jpeg', 'png', 'gif'];
$category = $viewData['scanResults'][$selectedId]; $category = $viewData['scanResults'][$selectedId];

2
www/content/Class_DirScanner.md

@ -66,7 +66,7 @@
* isSecureOn: 获取是否开启防盗链 * isSecureOn: 获取是否开启防盗链
* scan: 扫描目录获取目录和文件列表,支持指定目录扫描深度(目录级数) * scan: 扫描目录获取目录和文件列表,支持指定目录扫描深度(目录级数)
* getScanResults: 获取扫描结果 * getScanResults: 获取扫描结果
* getMenus: 获取扫描结果中的目录结构 * getMenus: 获取扫描结果中的目录结构,其中pid指向父目录
* getMDTitles: 获取.md文件中的h1-h6标题 * getMDTitles: 获取.md文件中的h1-h6标题
* fixMDUrls: 替换.md文件解析之后的HTML中的静态文件URL为相对路径path * fixMDUrls: 替换.md文件解析之后的HTML中的静态文件URL为相对路径path
* getDefaultReadme: 获取名称为README.md的文件 * getDefaultReadme: 获取名称为README.md的文件

3
www/content/Manual.md

@ -59,6 +59,7 @@
``` ```
[ [
'id' => '根据完整路径生成的唯一编号', 'id' => '根据完整路径生成的唯一编号',
'pid' => '父目录id', //如果有父目录的话
'directory' => '倚天屠龙记', 'directory' => '倚天屠龙记',
'realpath' => '/www/webroot/content/倚天屠龙记/', 'realpath' => '/www/webroot/content/倚天屠龙记/',
'path' => '/list/?id={id}', 'path' => '/list/?id={id}',
@ -73,6 +74,7 @@
``` ```
[ [
'id' => '根据完整路径生成的唯一编号', 'id' => '根据完整路径生成的唯一编号',
'pid' => '父目录id', //如果有父目录的话
'filename' => '第一章', 'filename' => '第一章',
'realpath' => '/www/webroot/content/倚天屠龙记/第一章.md', 'realpath' => '/www/webroot/content/倚天屠龙记/第一章.md',
'path' => '/view/?id={id}', 'path' => '/view/?id={id}',
@ -110,6 +112,7 @@
``` ```
[ [
'id' => '根据完整路径生成的唯一编号', 'id' => '根据完整路径生成的唯一编号',
'pid' => '父目录id', //如果有父目录的话
'filename' => 'filesite.io', 'filename' => 'filesite.io',
'realpath' => '/www/webroot/content/网址导航/filesite.io.url', 'realpath' => '/www/webroot/content/网址导航/filesite.io.url',
'path' => '/link/?id={id}', 'path' => '/link/?id={id}',

1
www/css/googleimage.css

@ -19,6 +19,7 @@ a{color: #aaadb2;text-decoration: none}
.modal-about .btn-close svg{fill: currentColor;flex-shrink: 0;} .modal-about .btn-close svg{fill: currentColor;flex-shrink: 0;}
.modal-body{padding: 10px;background-color: inherit;} .modal-body{padding: 10px;background-color: inherit;}
.modal-about .modal-body h1{display: none;} .modal-about .modal-body h1{display: none;}
.breadcrumbs{padding-left: 1.5em;padding-bottom: 10px;}
.content{padding: 20px 10px} .content{padding: 20px 10px}
.img-item{display: inline-block;margin-left: 10px;margin-right: 10px;margin-bottom: 20px;cursor: pointer;} .img-item{display: inline-block;margin-left: 10px;margin-right: 10px;margin-bottom: 20px;cursor: pointer;}
.img-item img{height: 180px;object-fit: cover;} .img-item img{height: 180px;object-fit: cover;}

Loading…
Cancel
Save