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'; @@ -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,15 +25,14 @@ Class ApiController extends SiteController { @@ -18,15 +25,14 @@ 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'));
}

10
themes/tajian/controller/SiteController.php

@ -76,7 +76,7 @@ Class SiteController extends Controller { @@ -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 { @@ -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 { @@ -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 { @@ -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);
}
}
}

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

@ -9,8 +9,9 @@ $selectedId = $viewData['cateId']; @@ -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 <<<eof
<a href="/list/?id={$item['id']}">{$item['name']}</a>
<a href="/list/?id={$item['id']}" class="{$selected}">{$item['name']}</a>
eof;
}
}
@ -49,6 +50,7 @@ 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'])) {

Loading…
Cancel
Save