Browse Source

add menus and dir tree sort function

master
filesite 2 years ago
parent
commit
51d40d8ca4
  1. 40
      controller/Controller.php
  2. 20
      themes/googleimage/controller/ListController.php
  3. 20
      themes/googleimage/controller/SiteController.php
  4. 21
      themes/videoblog/controller/ListController.php
  5. 24
      themes/videoblog/controller/SiteController.php
  6. 37
      themes/webdirectory/controller/SiteController.php
  7. 4
      www/content/README.md

40
controller/Controller.php

@ -188,4 +188,44 @@ Class Controller {
setcookie($cookieKey, $val, $expires, $path); setcookie($cookieKey, $val, $expires, $path);
} }
//sort menus and dirTree
protected function sortMenusAndDirTree($menus_sorted, $menus, $dirTree) {
if (empty($menus_sorted) || empty($menus) || empty($dirTree)) {return false;}
//一级目录菜单排序
$menu_dirs = array_column($menus, 'directory');
$names = array_replace(array_flip($menus_sorted), array_flip($menu_dirs));
if (!empty($names)) {
$menus_sorted = array_keys($names);
$arr = [];
foreach($menus_sorted as $name) {
$index = array_search($name, $menu_dirs);
array_push($arr, $menus[$index]);
}
$menus = $arr;
}
//dirTree一级目录排序
$sorted_dirs = array_column($menus, 'directory');
$tree_dirs = array_column($dirTree, 'directory');
$names = array_replace(array_flip($sorted_dirs), array_flip($tree_dirs));
if (!empty($names)) {
$sorted_dirs = array_keys($names);
$arr = [];
foreach($sorted_dirs as $name) {
foreach($dirTree as $index => $item) {
if (!empty($item['directory']) && $item['directory'] == $name) {
array_push($arr, $item);
break;
}
}
}
$dirTree = $arr;
}
return compact('menus', 'dirTree');
}
} }

20
themes/googleimage/controller/ListController.php

@ -9,6 +9,11 @@ Class ListController extends Controller {
public function actionIndex() { public function actionIndex() {
//获取数据 //获取数据
$menus = []; //菜单,一级目录
$htmlReadme = ''; //Readme.md 内容,底部网站详细介绍
$htmlCateReadme = ''; //当前目录下的Readme.md 内容
$menus_sorted = []; //Readme_sort.txt 说明文件内容,一级目录菜单从上到下的排序
$scanner = new DirScanner(); $scanner = new DirScanner();
$scanner->setWebRoot(FSC::$app['config']['content_directory']); $scanner->setWebRoot(FSC::$app['config']['content_directory']);
$dirTree = $scanner->scan(__DIR__ . '/../../../www/' . FSC::$app['config']['content_directory'], 4); $dirTree = $scanner->scan(__DIR__ . '/../../../www/' . FSC::$app['config']['content_directory'], 4);
@ -16,12 +21,14 @@ Class ListController extends Controller {
//获取目录 //获取目录
$menus = $scanner->getMenus(); $menus = $scanner->getMenus();
$cateId = $this->get('id', $menus[0]['id']);
$titles = []; $titles = [];
$htmlReadme = '';
$readmeFile = $scanner->getDefaultReadme(); $readmeFile = $scanner->getDefaultReadme();
if (!empty($readmeFile)) { if (!empty($readmeFile)) {
if (!empty($readmeFile['sort'])) {
$menus_sorted = explode("\n", $readmeFile['sort']);
}
$titles = $scanner->getMDTitles($readmeFile['id']); $titles = $scanner->getMDTitles($readmeFile['id']);
$Parsedown = new Parsedown(); $Parsedown = new Parsedown();
@ -30,12 +37,19 @@ Class ListController extends Controller {
$htmlReadme = $scanner->fixMDUrls($readmeFile['realpath'], $htmlReadme); $htmlReadme = $scanner->fixMDUrls($readmeFile['realpath'], $htmlReadme);
} }
//排序
$sortedTree = $this->sortMenusAndDirTree($menus_sorted, $menus, $dirTree);
if (!empty($sortedTree)) {
$menus = $sortedTree['menus'];
$dirTree = $sortedTree['dirTree'];
}
//获取目录面包屑 //获取目录面包屑
$cateId = $this->get('id', $menus[0]['id']);
$subcate = $scanResults[$cateId]; $subcate = $scanResults[$cateId];
$breadcrumbs = $this->getBreadcrumbs($menus, $subcate); $breadcrumbs = $this->getBreadcrumbs($menus, $subcate);
//获取当前目录下的readme //获取当前目录下的readme
$htmlCateReadme = '';
$cateReadmeFile = $scanner->getDefaultReadme($cateId); $cateReadmeFile = $scanner->getDefaultReadme($cateId);
if (!empty($cateReadmeFile)) { if (!empty($cateReadmeFile)) {
$Parsedown = new Parsedown(); $Parsedown = new Parsedown();

20
themes/googleimage/controller/SiteController.php

@ -9,6 +9,11 @@ Class SiteController extends Controller {
public function actionIndex() { public function actionIndex() {
//获取数据 //获取数据
$menus = []; //菜单,一级目录
$htmlReadme = ''; //Readme.md 内容,底部网站详细介绍
$htmlCateReadme = ''; //当前目录下的Readme.md 内容
$menus_sorted = []; //Readme_sort.txt 说明文件内容,一级目录菜单从上到下的排序
$scanner = new DirScanner(); $scanner = new DirScanner();
$scanner->setWebRoot(FSC::$app['config']['content_directory']); $scanner->setWebRoot(FSC::$app['config']['content_directory']);
$dirTree = $scanner->scan(__DIR__ . '/../../../www/' . FSC::$app['config']['content_directory'], 4); $dirTree = $scanner->scan(__DIR__ . '/../../../www/' . FSC::$app['config']['content_directory'], 4);
@ -16,12 +21,14 @@ Class SiteController extends Controller {
//获取目录 //获取目录
$menus = $scanner->getMenus(); $menus = $scanner->getMenus();
$cateId = $this->get('id', $menus[0]['id']);
$titles = []; $titles = [];
$htmlReadme = '';
$readmeFile = $scanner->getDefaultReadme(); $readmeFile = $scanner->getDefaultReadme();
if (!empty($readmeFile)) { if (!empty($readmeFile)) {
if (!empty($readmeFile['sort'])) {
$menus_sorted = explode("\n", $readmeFile['sort']);
}
$titles = $scanner->getMDTitles($readmeFile['id']); $titles = $scanner->getMDTitles($readmeFile['id']);
$Parsedown = new Parsedown(); $Parsedown = new Parsedown();
@ -30,10 +37,17 @@ Class SiteController extends Controller {
$htmlReadme = $scanner->fixMDUrls($readmeFile['realpath'], $htmlReadme); $htmlReadme = $scanner->fixMDUrls($readmeFile['realpath'], $htmlReadme);
} }
//排序
$sortedTree = $this->sortMenusAndDirTree($menus_sorted, $menus, $dirTree);
if (!empty($sortedTree)) {
$menus = $sortedTree['menus'];
$dirTree = $sortedTree['dirTree'];
}
$cateId = $this->get('id', $menus[0]['id']);
$subcate = $scanResults[$cateId]; $subcate = $scanResults[$cateId];
//获取当前目录下的readme //获取当前目录下的readme
$htmlCateReadme = '';
$cateReadmeFile = $scanner->getDefaultReadme($cateId); $cateReadmeFile = $scanner->getDefaultReadme($cateId);
if (!empty($cateReadmeFile)) { if (!empty($cateReadmeFile)) {
$Parsedown = new Parsedown(); $Parsedown = new Parsedown();

21
themes/videoblog/controller/ListController.php

@ -9,6 +9,11 @@ Class ListController extends Controller {
public function actionIndex() { public function actionIndex() {
//获取数据 //获取数据
$menus = []; //菜单,一级目录
$htmlReadme = ''; //Readme.md 内容,底部网站详细介绍
$htmlCateReadme = ''; //当前目录下的Readme.md 内容
$menus_sorted = []; //Readme_sort.txt 说明文件内容,一级目录菜单从上到下的排序
$scanner = new DirScanner(); $scanner = new DirScanner();
$scanner->setWebRoot(FSC::$app['config']['content_directory']); $scanner->setWebRoot(FSC::$app['config']['content_directory']);
$dirTree = $scanner->scan(__DIR__ . '/../../../www/' . FSC::$app['config']['content_directory'], 3); $dirTree = $scanner->scan(__DIR__ . '/../../../www/' . FSC::$app['config']['content_directory'], 3);
@ -16,13 +21,14 @@ Class ListController extends Controller {
//获取目录 //获取目录
$menus = $scanner->getMenus(); $menus = $scanner->getMenus();
$cateId = $this->get('id', $menus[0]['id']);
//print_r($menus);exit;
$titles = []; $titles = [];
$htmlReadme = '';
$readmeFile = $scanner->getDefaultReadme(); $readmeFile = $scanner->getDefaultReadme();
if (!empty($readmeFile)) { if (!empty($readmeFile)) {
if (!empty($readmeFile['sort'])) {
$menus_sorted = explode("\n", $readmeFile['sort']);
}
$titles = $scanner->getMDTitles($readmeFile['id']); $titles = $scanner->getMDTitles($readmeFile['id']);
$Parsedown = new Parsedown(); $Parsedown = new Parsedown();
@ -31,12 +37,19 @@ Class ListController extends Controller {
$htmlReadme = $scanner->fixMDUrls($readmeFile['realpath'], $htmlReadme); $htmlReadme = $scanner->fixMDUrls($readmeFile['realpath'], $htmlReadme);
} }
//排序
$sortedTree = $this->sortMenusAndDirTree($menus_sorted, $menus, $dirTree);
if (!empty($sortedTree)) {
$menus = $sortedTree['menus'];
$dirTree = $sortedTree['dirTree'];
}
//获取目录面包屑 //获取目录面包屑
$cateId = $this->get('id', $menus[0]['id']);
$subcate = $scanResults[$cateId]; $subcate = $scanResults[$cateId];
$breadcrumbs = $this->getBreadcrumbs($scanResults, $subcate); $breadcrumbs = $this->getBreadcrumbs($scanResults, $subcate);
//获取当前目录下的readme //获取当前目录下的readme
$htmlCateReadme = '';
$cateReadmeFile = $scanner->getDefaultReadme($cateId); $cateReadmeFile = $scanner->getDefaultReadme($cateId);
if (!empty($cateReadmeFile)) { if (!empty($cateReadmeFile)) {
$Parsedown = new Parsedown(); $Parsedown = new Parsedown();

24
themes/videoblog/controller/SiteController.php

@ -9,6 +9,11 @@ Class SiteController extends Controller {
public function actionIndex() { public function actionIndex() {
//获取数据 //获取数据
$menus = []; //菜单,一级目录
$htmlReadme = ''; //Readme.md 内容,底部网站详细介绍
$htmlCateReadme = ''; //当前目录下的Readme.md 内容
$menus_sorted = []; //Readme_sort.txt 说明文件内容,一级目录菜单从上到下的排序
$scanner = new DirScanner(); $scanner = new DirScanner();
$scanner->setWebRoot(FSC::$app['config']['content_directory']); $scanner->setWebRoot(FSC::$app['config']['content_directory']);
$dirTree = $scanner->scan(__DIR__ . '/../../../www/' . FSC::$app['config']['content_directory'], 4); $dirTree = $scanner->scan(__DIR__ . '/../../../www/' . FSC::$app['config']['content_directory'], 4);
@ -16,12 +21,15 @@ Class SiteController extends Controller {
//获取目录 //获取目录
$menus = $scanner->getMenus(); $menus = $scanner->getMenus();
$cateId = $this->get('id', $menus[0]['id']);
$titles = []; $titles = [];
$htmlReadme = ''; $htmlReadme = '';
$readmeFile = $scanner->getDefaultReadme(); $readmeFile = $scanner->getDefaultReadme();
if (!empty($readmeFile)) { if (!empty($readmeFile)) {
if (!empty($readmeFile['sort'])) {
$menus_sorted = explode("\n", $readmeFile['sort']);
}
$titles = $scanner->getMDTitles($readmeFile['id']); $titles = $scanner->getMDTitles($readmeFile['id']);
$Parsedown = new Parsedown(); $Parsedown = new Parsedown();
@ -30,10 +38,18 @@ Class SiteController extends Controller {
$htmlReadme = $scanner->fixMDUrls($readmeFile['realpath'], $htmlReadme); $htmlReadme = $scanner->fixMDUrls($readmeFile['realpath'], $htmlReadme);
} }
//排序
$sortedTree = $this->sortMenusAndDirTree($menus_sorted, $menus, $dirTree);
if (!empty($sortedTree)) {
$menus = $sortedTree['menus'];
$dirTree = $sortedTree['dirTree'];
}
//默认显示的目录
$cateId = $this->get('id', $menus[0]['id']);
$subcate = $scanResults[$cateId]; $subcate = $scanResults[$cateId];
//获取当前目录下的readme //获取当前目录下的readme
$htmlCateReadme = '';
$cateReadmeFile = $scanner->getDefaultReadme($cateId); $cateReadmeFile = $scanner->getDefaultReadme($cateId);
if (!empty($cateReadmeFile)) { if (!empty($cateReadmeFile)) {
$Parsedown = new Parsedown(); $Parsedown = new Parsedown();
@ -42,6 +58,10 @@ Class SiteController extends Controller {
$htmlCateReadme = $scanner->fixMDUrls($cateReadmeFile['realpath'], $htmlCateReadme); $htmlCateReadme = $scanner->fixMDUrls($cateReadmeFile['realpath'], $htmlCateReadme);
} }
$pageTitle = !empty($titles) ? $titles[0]['name'] : "FileSite.io - 无数据库、基于文件和目录的Markdown文档、网址导航、图书、图片、视频网站PHP开源系统"; $pageTitle = !empty($titles) ? $titles[0]['name'] : "FileSite.io - 无数据库、基于文件和目录的Markdown文档、网址导航、图书、图片、视频网站PHP开源系统";
if (!empty($readmeFile['title'])) { if (!empty($readmeFile['title'])) {
$pageTitle = $readmeFile['title']; $pageTitle = $readmeFile['title'];

37
themes/webdirectory/controller/SiteController.php

@ -43,39 +43,10 @@ Class SiteController extends Controller {
} }
//排序 //排序
if (!empty($menus_sorted) && !empty($menus)) { $sortedTree = $this->sortMenusAndDirTree($menus_sorted, $menus, $dirTree);
//一级目录菜单排序 if (!empty($sortedTree)) {
$menu_dirs = array_column($menus, 'directory'); $menus = $sortedTree['menus'];
$names = array_replace(array_flip($menus_sorted), array_flip($menu_dirs)); $dirTree = $sortedTree['dirTree'];
if (!empty($names)) {
$menus_sorted = array_keys($names);
$arr = [];
foreach($menus_sorted as $name) {
$index = array_search($name, $menu_dirs);
array_push($arr, $menus[$index]);
}
$menus = $arr;
}
//dirTree一级目录排序
$sorted_dirs = array_column($menus, 'directory');
$tree_dirs = array_column($dirTree, 'directory');
$names = array_replace(array_flip($sorted_dirs), array_flip($tree_dirs));
if (!empty($names)) {
$sorted_dirs = array_keys($names);
$arr = [];
foreach($sorted_dirs as $name) {
foreach($dirTree as $index => $item) {
if (!empty($item['directory']) && $item['directory'] == $name) {
array_push($arr, $item);
break;
}
}
}
$dirTree = $arr;
}
} }

4
www/content/README.md

@ -81,7 +81,9 @@ https://git.filesite.io/filesite/machete/archive/master.zip
5. 视频站 5. 视频站
- | 名称 | 网址 |
| ---- | ---- |
| 在线学 | <a href="https://duan.filesite.io" target="_blank">Duan.Filesite.io</a> |
## 源码下载 ## 源码下载

Loading…
Cancel
Save