Browse Source

api update

master
filesite 1 year ago
parent
commit
ba2064d131
  1. 12
      themes/tajian/controller/ApiController.php
  2. 10
      themes/tajian/controller/SiteController.php
  3. 4
      themes/tajian/views/site/index.php

12
themes/tajian/controller/ApiController.php

@ -9,6 +9,13 @@ require_once __DIR__ . '/SiteController.php';
Class ApiController extends SiteController { Class ApiController extends SiteController {
public function actionIndex() { public function actionIndex() {
$code = 0;
$err = 'Not allowed';
return $this->renderJson(compact('code', 'err'));
}
public function actionTags() {
//获取数据 //获取数据
$menus = array(); //菜单,一级目录 $menus = array(); //菜单,一级目录
$htmlReadme = ''; //Readme.md 内容,底部网站详细介绍 $htmlReadme = ''; //Readme.md 内容,底部网站详细介绍
@ -18,16 +25,15 @@ Class ApiController extends SiteController {
$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);
//$scanResults = $scanner->getScanResults();
$code = 1; $code = 1;
$msg = ''; $msg = '';
$err = ''; $err = '';
//获取tags分类 //获取tags分类
$data = $this->getTags($dirTree); $noFiles = true;
$data = $this->getTags($dirTree, $noFiles);
return $this->renderJson(compact('code', 'msg', 'err', 'data')); return $this->renderJson(compact('code', 'msg', 'err', 'data'));
} }

10
themes/tajian/controller/SiteController.php

@ -76,7 +76,7 @@ Class SiteController extends Controller {
} }
//获取tag分类 //获取tag分类
protected function getTags($dirTree) { protected function getTags($dirTree, $noFiles = false) {
$tags = array(); $tags = array();
$tagDir = null; $tagDir = null;
@ -91,7 +91,7 @@ Class SiteController extends Controller {
if (!empty($tagDir) && !empty($tagDir['files'])) { if (!empty($tagDir) && !empty($tagDir['files'])) {
foreach($tagDir['files'] as $id => $item) { foreach($tagDir['files'] as $id => $item) {
if (empty($item['realpath'])) { //如果是txt描述文件 if (empty($item['realpath'])) { //如果是txt描述文件
$tag = $this->getTagItem($item); $tag = $this->getTagItem($item, $noFiles);
$tags[$tag['id']] = $tag; $tags[$tag['id']] = $tag;
} }
} }
@ -100,7 +100,7 @@ Class SiteController extends Controller {
return $tags; return $tags;
} }
protected function getTagItem($tagFile) { protected function getTagItem($tagFile, $noFiles = false) {
$tag = array(); $tag = array();
foreach($tagFile as $name => $item) { foreach($tagFile as $name => $item) {
@ -108,7 +108,9 @@ Class SiteController extends Controller {
$tag['id'] = $item; $tag['id'] = $item;
}else { }else {
$tag['name'] = $name; $tag['name'] = $name;
$tag['files'] = explode("\n", $item); if ($noFiles == false) {
$tag['files'] = explode("\n", $item);
}
} }
} }

4
themes/tajian/views/site/index.php

@ -9,8 +9,9 @@ $selectedId = $viewData['cateId'];
$breadcrumbs = !empty($viewData['breadcrumbs']) ? $viewData['breadcrumbs'] : []; $breadcrumbs = !empty($viewData['breadcrumbs']) ? $viewData['breadcrumbs'] : [];
if (!empty($viewData['tags'])) { //显示tags分类 if (!empty($viewData['tags'])) { //显示tags分类
foreach($viewData['tags'] as $id => $item) { foreach($viewData['tags'] as $id => $item) {
$selected = $item['id'] == $selectedId || (!empty($breadcrumbs) && $item['id'] == $breadcrumbs[0]['id']) ? 'selected' : '';
echo <<<eof echo <<<eof
<a href="/list/?id={$item['id']}">{$item['name']}</a> <a href="/list/?id={$item['id']}" class="{$selected}">{$item['name']}</a>
eof; eof;
} }
} }
@ -49,6 +50,7 @@ eof;
$imgExts = array('jpg', 'jpeg', 'png', 'gif'); $imgExts = array('jpg', 'jpeg', 'png', 'gif');
$videoExts = array('url'); $videoExts = array('url');
$category = $viewData['scanResults'][$selectedId]; $category = $viewData['scanResults'][$selectedId];
//TODO: 兼容按tag分类显示数据
//当前目录的描述介绍 //当前目录的描述介绍
if (!empty($category['description'])) { if (!empty($category['description'])) {

Loading…
Cancel
Save