From ba2064d131cb1cac48f9d3c310f5c3e667461f59 Mon Sep 17 00:00:00 2001 From: filesite Date: Sun, 17 Sep 2023 15:53:10 +0800 Subject: [PATCH] api update --- themes/tajian/controller/ApiController.php | 12 +++++++++--- themes/tajian/controller/SiteController.php | 10 ++++++---- themes/tajian/views/site/index.php | 4 +++- 3 files changed, 18 insertions(+), 8 deletions(-) diff --git a/themes/tajian/controller/ApiController.php b/themes/tajian/controller/ApiController.php index 583f9e0..71f1006 100644 --- a/themes/tajian/controller/ApiController.php +++ b/themes/tajian/controller/ApiController.php @@ -9,6 +9,13 @@ require_once __DIR__ . '/SiteController.php'; Class ApiController extends SiteController { public function actionIndex() { + $code = 0; + $err = 'Not allowed'; + + return $this->renderJson(compact('code', 'err')); + } + + public function actionTags() { //获取数据 $menus = array(); //菜单,一级目录 $htmlReadme = ''; //Readme.md 内容,底部网站详细介绍 @@ -18,16 +25,15 @@ Class ApiController extends SiteController { $scanner = new DirScanner(); $scanner->setWebRoot(FSC::$app['config']['content_directory']); $dirTree = $scanner->scan(__DIR__ . '/../../../www/' . FSC::$app['config']['content_directory'], 3); - //$scanResults = $scanner->getScanResults(); $code = 1; $msg = ''; $err = ''; //获取tags分类 - $data = $this->getTags($dirTree); + $noFiles = true; + $data = $this->getTags($dirTree, $noFiles); - return $this->renderJson(compact('code', 'msg', 'err', 'data')); } diff --git a/themes/tajian/controller/SiteController.php b/themes/tajian/controller/SiteController.php index 9bdd772..99e4c97 100644 --- a/themes/tajian/controller/SiteController.php +++ b/themes/tajian/controller/SiteController.php @@ -76,7 +76,7 @@ Class SiteController extends Controller { } //获取tag分类 - protected function getTags($dirTree) { + protected function getTags($dirTree, $noFiles = false) { $tags = array(); $tagDir = null; @@ -91,7 +91,7 @@ Class SiteController extends Controller { if (!empty($tagDir) && !empty($tagDir['files'])) { foreach($tagDir['files'] as $id => $item) { if (empty($item['realpath'])) { //如果是txt描述文件 - $tag = $this->getTagItem($item); + $tag = $this->getTagItem($item, $noFiles); $tags[$tag['id']] = $tag; } } @@ -100,7 +100,7 @@ Class SiteController extends Controller { return $tags; } - protected function getTagItem($tagFile) { + protected function getTagItem($tagFile, $noFiles = false) { $tag = array(); foreach($tagFile as $name => $item) { @@ -108,7 +108,9 @@ Class SiteController extends Controller { $tag['id'] = $item; }else { $tag['name'] = $name; - $tag['files'] = explode("\n", $item); + if ($noFiles == false) { + $tag['files'] = explode("\n", $item); + } } } diff --git a/themes/tajian/views/site/index.php b/themes/tajian/views/site/index.php index 9082ff1..36b8e18 100644 --- a/themes/tajian/views/site/index.php +++ b/themes/tajian/views/site/index.php @@ -9,8 +9,9 @@ $selectedId = $viewData['cateId']; $breadcrumbs = !empty($viewData['breadcrumbs']) ? $viewData['breadcrumbs'] : []; if (!empty($viewData['tags'])) { //显示tags分类 foreach($viewData['tags'] as $id => $item) { + $selected = $item['id'] == $selectedId || (!empty($breadcrumbs) && $item['id'] == $breadcrumbs[0]['id']) ? 'selected' : ''; echo <<{$item['name']} + {$item['name']} eof; } } @@ -49,6 +50,7 @@ eof; $imgExts = array('jpg', 'jpeg', 'png', 'gif'); $videoExts = array('url'); $category = $viewData['scanResults'][$selectedId]; + //TODO: 兼容按tag分类显示数据 //当前目录的描述介绍 if (!empty($category['description'])) {