Browse Source

get tags done, api for tags ready

master
filesite 1 year ago
parent
commit
527a37984b
  1. 34
      themes/tajian/controller/ApiController.php
  2. 11
      themes/tajian/controller/ListController.php
  3. 46
      themes/tajian/controller/SiteController.php
  4. 21
      themes/tajian/views/site/index.php

34
themes/tajian/controller/ApiController.php

@ -0,0 +1,34 @@
<?php
/**
* List Controller
*/
require_once __DIR__ . '/../../../lib/DirScanner.php';
require_once __DIR__ . '/../../../plugins/Parsedown.php';
require_once __DIR__ . '/SiteController.php';
Class ApiController extends SiteController {
public function actionIndex() {
//获取数据
$menus = array(); //菜单,一级目录
$htmlReadme = ''; //Readme.md 内容,底部网站详细介绍
$htmlCateReadme = ''; //当前目录下的Readme.md 内容
$menus_sorted = array(); //Readme_sort.txt 说明文件内容,一级目录菜单从上到下的排序
$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);
return $this->renderJson(compact('code', 'msg', 'err', 'data'));
}
}

11
themes/tajian/controller/ListController.php

@ -4,8 +4,9 @@
*/ */
require_once __DIR__ . '/../../../lib/DirScanner.php'; require_once __DIR__ . '/../../../lib/DirScanner.php';
require_once __DIR__ . '/../../../plugins/Parsedown.php'; require_once __DIR__ . '/../../../plugins/Parsedown.php';
require_once __DIR__ . '/SiteController.php';
Class ListController extends Controller { Class ListController extends SiteController {
public function actionIndex() { public function actionIndex() {
//获取数据 //获取数据
@ -58,6 +59,12 @@ Class ListController extends Controller {
$htmlCateReadme = $scanner->fixMDUrls($cateReadmeFile['realpath'], $htmlCateReadme); $htmlCateReadme = $scanner->fixMDUrls($cateReadmeFile['realpath'], $htmlCateReadme);
} }
//获取tags分类
$tags = $this->getTags($dirTree);
//TODO: 根据tag获取相关数据,并传给视图;调整视图兼容tag的数据结构
$pageTitle = $defaultTitle = !empty($titles) ? $titles[0]['name'] : FSC::$app['config']['site_name']; $pageTitle = $defaultTitle = !empty($titles) ? $titles[0]['name'] : FSC::$app['config']['site_name'];
if (!empty($subcate)) { if (!empty($subcate)) {
$pageTitle = "{$subcate['directory']}相关视频,来自{$defaultTitle}"; $pageTitle = "{$subcate['directory']}相关视频,来自{$defaultTitle}";
@ -66,7 +73,7 @@ Class ListController extends Controller {
} }
} }
$viewName = '//site/index'; //共享视图 $viewName = '//site/index'; //共享视图
$params = compact('cateId', 'dirTree', 'scanResults', 'menus', 'htmlReadme', 'breadcrumbs', 'htmlCateReadme'); $params = compact('cateId', 'dirTree', 'scanResults', 'menus', 'htmlReadme', 'breadcrumbs', 'htmlCateReadme', 'tags');
return $this->render($viewName, $params, $pageTitle); return $this->render($viewName, $params, $pageTitle);
} }

46
themes/tajian/controller/SiteController.php

@ -58,6 +58,10 @@ Class SiteController extends Controller {
$htmlCateReadme = $scanner->fixMDUrls($cateReadmeFile['realpath'], $htmlCateReadme); $htmlCateReadme = $scanner->fixMDUrls($cateReadmeFile['realpath'], $htmlCateReadme);
} }
//获取tags分类
$tags = $this->getTags($dirTree);
$pageTitle = $defaultTitle = !empty($titles) ? $titles[0]['name'] : FSC::$app['config']['site_name']; $pageTitle = $defaultTitle = !empty($titles) ? $titles[0]['name'] : FSC::$app['config']['site_name'];
if (!empty($subcate)) { if (!empty($subcate)) {
$pageTitle = "{$subcate['directory']},来自{$defaultTitle}"; $pageTitle = "{$subcate['directory']},来自{$defaultTitle}";
@ -67,8 +71,48 @@ Class SiteController extends Controller {
} }
$viewName = 'index'; $viewName = 'index';
$params = compact('cateId', 'dirTree', 'scanResults', 'menus', 'htmlReadme', 'htmlCateReadme'); $params = compact('cateId', 'dirTree', 'scanResults', 'menus', 'htmlReadme', 'htmlCateReadme', 'tags');
return $this->render($viewName, $params, $pageTitle); return $this->render($viewName, $params, $pageTitle);
} }
//获取tag分类
protected function getTags($dirTree) {
$tags = array();
$tagDir = null;
$tagSaveDirName = str_replace('/', '', FSC::$app['config']['tajian']['tag_dir']);
foreach($dirTree as $id => $item) {
if (!empty($item['directory']) && $item['directory'] == $tagSaveDirName) {
$tagDir = $item;
break;
}
}
if (!empty($tagDir) && !empty($tagDir['files'])) {
foreach($tagDir['files'] as $id => $item) {
if (empty($item['realpath'])) { //如果是txt描述文件
$tag = $this->getTagItem($item);
$tags[$tag['id']] = $tag;
}
}
}
return $tags;
}
protected function getTagItem($tagFile) {
$tag = array();
foreach($tagFile as $name => $item) {
if ($name == 'id') {
$tag['id'] = $item;
}else {
$tag['name'] = $name;
$tag['files'] = explode("\n", $item);
}
}
return $tag;
}
} }

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

@ -7,11 +7,10 @@ $imgPreffix = FSC::$app['config']['content_directory'] . FSC::$app['config']['ta
<?php <?php
$selectedId = $viewData['cateId']; $selectedId = $viewData['cateId'];
$breadcrumbs = !empty($viewData['breadcrumbs']) ? $viewData['breadcrumbs'] : []; $breadcrumbs = !empty($viewData['breadcrumbs']) ? $viewData['breadcrumbs'] : [];
if (!empty($viewData['menus'])) { //只显示第一级目录 if (!empty($viewData['tags'])) { //显示tags分类
foreach($viewData['menus'] as $index => $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="/?id={$item['id']}" class="{$selected}">{$item['directory']}</a> <a href="/list/?id={$item['id']}">{$item['name']}</a>
eof; eof;
} }
} }
@ -58,13 +57,6 @@ eof;
eof; eof;
} }
//当前目录的readme详细介绍
if (!empty($viewData['htmlCateReadme'])) {
echo <<<eof
<div class="cateinfo markdown-body">{$viewData['htmlCateReadme']}</div>
eof;
}
if (!empty($category['files'])) { //一级目录支持,目录下直接存放视频文件 if (!empty($category['files'])) { //一级目录支持,目录下直接存放视频文件
foreach($category['files'] as $file) { foreach($category['files'] as $file) {
@ -93,5 +85,12 @@ eof;
eof; eof;
} }
} }
//当前目录的readme详细介绍
if (!empty($viewData['htmlCateReadme'])) {
echo <<<eof
<div class="cateinfo markdown-body">{$viewData['htmlCateReadme']}</div>
eof;
}
?> ?>
</div> </div>

Loading…
Cancel
Save