diff --git a/TODO.md b/TODO.md
new file mode 100644
index 0000000..e44dc7b
--- /dev/null
+++ b/TODO.md
@@ -0,0 +1,5 @@
+待完成功能列表
+- 完善euapi主题
+- 完善获取分类,分类下的数量列表,现在只实现当前分类,没有包含下钻分类
+- 完善用户发帖数量等字段
+- doc文档上输出
\ No newline at end of file
diff --git a/app/admin/common.php b/app/admin/common.php
index 146c35a..e8327ab 100644
--- a/app/admin/common.php
+++ b/app/admin/common.php
@@ -157,6 +157,9 @@ if (!function_exists('get_template_list')) {
{
$themeList = [];
$themeDir = public_path('template') . system_config('web_template') . '/pc/' . $type;
+ if (!file_exists($themeDir)){
+ return [];
+ }
if ($dh = opendir($themeDir)) {
while (($file = readdir($dh)) !== false) {
@@ -217,4 +220,4 @@ if (!function_exists('cross')) {
else $str .= "--";
return $str . " ";
}
-}
\ No newline at end of file
+}
diff --git a/app/admin/controller/Category.php b/app/admin/controller/Category.php
index 3f4ff67..e3bae87 100644
--- a/app/admin/controller/Category.php
+++ b/app/admin/controller/Category.php
@@ -105,14 +105,6 @@ class Category extends AuthController
*/
public function add(string $pid = ''): string
{
- $templatePath = system_config('web_template');
- $themeInfoFile = public_path('template' . DIRECTORY_SEPARATOR . $templatePath) . 'info.json';
- if (file_exists($themeInfoFile)) {
- $themeInfo = json_decode(file_get_contents($themeInfoFile), true);
- $themeList = $themeInfo['category_list'];
- } else {
- $themeList = [];
- }
$where = Util::postMore([
'name' => '',
'status' => '',
@@ -121,6 +113,10 @@ class Category extends AuthController
$category = get_tree_list($category);
$this->assign("category", $category);
$this->assign("pid", $pid);
+ $themeList = get_template_list(Data::DOCUMENT_CATEGORY);
+ if (empty($themeList)){
+ $this->error("模板文件不存在,请检查主题目录或主题配置");
+ }
$this->assign("template_list", $themeList);
return $this->fetch();
}
@@ -134,14 +130,6 @@ class Category extends AuthController
*/
public function edit(Request $request): string
{
- $templatePath = system_config('web_template');
- $themeInfoFile = public_path('template' . DIRECTORY_SEPARATOR . $templatePath) . 'info.json';
- if (file_exists($themeInfoFile)) {
- $themeInfo = json_decode(file_get_contents($themeInfoFile), true);
- $themeList = $themeInfo['category_list'];
- } else {
- $themeList = [];
- }
$where = Util::postMore([
'name' => '',
'status' => '',
@@ -151,6 +139,10 @@ class Category extends AuthController
$info = aModel::find($request->param(['id']));
$this->assign("category", $category);
$this->assign("info", $info);
+ $themeList = get_template_list(Data::DOCUMENT_CATEGORY);
+ if (empty($themeList)){
+ $this->error("模板文件不存在,请检查主题目录或主题配置");
+ }
$this->assign("template_list", $themeList);
return $this->fetch();
}
diff --git a/app/admin/controller/Page.php b/app/admin/controller/Page.php
index ca0a230..e219e7b 100644
--- a/app/admin/controller/Page.php
+++ b/app/admin/controller/Page.php
@@ -134,6 +134,9 @@ class Page extends AuthController
{
// 获取页面模板列表
$templateList = get_template_list(Data::DOCUMENT_TYPE_PAGE);
+ if (empty($themeList)){
+ $this->error("模板文件不存在,请检查主题目录或主题配置");
+ }
$this->assign("template_list", $templateList);
return $this->fetch();
}
@@ -157,6 +160,9 @@ class Page extends AuthController
}
// 获取页面模板列表
$templateList = get_template_list(Data::DOCUMENT_TYPE_PAGE);
+ if (empty($themeList)){
+ $this->error("模板文件不存在,请检查主题目录或主题配置");
+ }
$this->assign("template_list", $templateList);
$this->assign("info", $info);
return $this->fetch();
diff --git a/app/admin/controller/SystemConfig.php b/app/admin/controller/SystemConfig.php
index 4b90ccf..675d700 100644
--- a/app/admin/controller/SystemConfig.php
+++ b/app/admin/controller/SystemConfig.php
@@ -63,14 +63,14 @@ class SystemConfig extends AuthController
public function clearCache(Request $request)
{
if ($request->isPost()) {
-// $adminPath = config("cache.runtime") . "/admin/";
+ $adminPath = config("cache.runtime") . "/admin/temp";
$commonPath = config("cache.runtime") . "/cache/";
-// $indexPath = config("cache.runtime") . "/index/";
-// $apiPath = config("cache.runtime") . "/api/";
+ $indexPath = config("cache.runtime") . "/index/temp";
+ $apiPath = config("cache.runtime") . "/api/temp";
Cache::clear();
-// remove_cache($adminPath);
-// remove_cache($indexPath);
-// remove_cache($apiPath);
+ remove_cache($adminPath);
+ remove_cache($indexPath);
+ remove_cache($apiPath);
remove_cache($commonPath);
return app("json")->success("操作成功");
}
diff --git a/app/admin/controller/Theme.php b/app/admin/controller/Theme.php
index a434831..7768dc0 100644
--- a/app/admin/controller/Theme.php
+++ b/app/admin/controller/Theme.php
@@ -38,9 +38,9 @@ class Theme extends AuthController
}
$info = json_decode(file_get_contents($themeInfoFile), true);
unset($themeInfoFile);
- $info['root_dir'] = $themeDir . "/" . $file . '/';
+ $info['root_dir'] = $themeDir . "/" . $file ;
$info['dir_name'] = $file;
- $info['preview_file'] = file_cdn($themeDir . "/" . $file . '/' . $info['preview_file']);
+ $info['preview_file'] = file_cdn($themeDir ."/". $file . '/' . $info['preview_file']);
$info['is_default'] = $file == $defaultTheme ? 1 : 0;//检查是不是默认主题
$themeList[] = $info;
}
@@ -58,7 +58,7 @@ class Theme extends AuthController
* @author 木子的忧伤
* @date 2021-02-17 11:40
*/
- public function change_theme(): string
+ public function change_theme()
{
$data = Util::postMore([
['value', ''],
diff --git a/app/admin/view/category/add.html b/app/admin/view/category/add.html
index b79ac4c..5511109 100644
--- a/app/admin/view/category/add.html
+++ b/app/admin/view/category/add.html
@@ -41,7 +41,7 @@
diff --git a/app/admin/view/category/edit.html b/app/admin/view/category/edit.html
index 37ffebb..0bb21bf 100644
--- a/app/admin/view/category/edit.html
+++ b/app/admin/view/category/edit.html
@@ -42,7 +42,7 @@
diff --git a/app/common/taglib/Ape.php b/app/common/taglib/Ape.php
index c64ad1c..02fcb43 100644
--- a/app/common/taglib/Ape.php
+++ b/app/common/taglib/Ape.php
@@ -22,7 +22,7 @@ class Ape extends TagLib
'article' => ['attr' => 'id,void,model', 'close' => 1],
'comment' => ['attr' => 'typeId,void,type,pageSize,orderBy', 'close' => 1],
'relevant' => ['attr' => 'id,model,void,row', 'close' => 1],
- 'tags' => ['attr' => 'tags,void', 'close' => 1],
+ 'tags' => ['attr' => 'tags,void,row', 'close' => 1],
'archive' => ['attr' => 'type,format,void', 'close' => 1],
'nav' => ['attr' => 'type,typeId,row,void,where,orderBy,display', 'close' => 1],
'table' => ['attr' => 'name,where,orderby,row,pagesize,void', 'close' => 1]
@@ -265,14 +265,12 @@ class Ape extends TagLib
*/
public function tagTags($tag, $content)
{
- if (!isset($tag['tags'])) {
- return false;
- }
- $tags = $tag['tags'];
+ $row = $tag['row'] ?? 10;
+ $tags = $tag['tags']??"";
$void = $tag['void'] ?? 'field';
$parse = '';
$parse .= '{volist name="$__LIST__" id="' . $void . '"}';
$parse .= $content;
diff --git a/app/index/common.php b/app/index/common.php
index 04a7b57..c3ba85c 100644
--- a/app/index/common.php
+++ b/app/index/common.php
@@ -8,6 +8,7 @@ use app\common\model\Advert;
use app\common\model\FriendLink;
use app\common\model\Tag;
use app\common\model\Nav;
+use app\common\model\Tag as TagModel;
use think\App;
use think\Collection;
use think\db\exception\DataNotFoundException;
@@ -43,20 +44,55 @@ function get_document_category_list()
{
//缓存文章菜单
$documentCategory = cache(Data::DATA_DOCUMENT_CATEGORY_LIST);
+ $documentCategory = null;
+
if ($documentCategory === null) {
- $documentCategoryList = DocumentCategory::where('status', 1)->order('sort asc')->select()->toArray();
- //转换,让id作为数组的键
- $documentCategory = [];
- foreach ($documentCategoryList as $item) {
+ $documentCategory = DocumentCategory::where('status', 1)->order('sort asc')->select()->toArray();
+ $documentList = Document::where('display', 1)
+ ->where('status', 1)
+ ->where("category_id","in",array_column($documentCategory,"id"))
+ ->group("category_id")
+ ->column('count(*) as count', 'category_id');
+ //TODO 需要实现包含下级分类所有数据的逻辑 使用下面两个函数实现,暂未完成
+ ///转换,让id作为数组的键
+ foreach ($documentCategory as &$item) {
//根据栏目类型,生成栏目url
$item['url'] = make_category_url($item);
- $documentCategory[$item['id']] = $item;
+ $item['dc_count'] = $documentList[$item['id']] ?? 0;
}
cache(Data::DATA_DOCUMENT_CATEGORY_LIST, $documentCategory);
}
+
return $documentCategory;
}
+// 构建树形结构的函数
+function buildTree($list, $pid = 0) {
+ $tree = [];
+ foreach ($list as $item) {
+ if ($item['pid'] == $pid) {
+ $children = buildTree($list, $item['id']);
+ if ($children) {
+ $item['children'] = $children;
+ }
+ $item['count'] += array_sum(array_column($children,"count"));
+ $tree[] = $item;
+ }
+ }
+ return $tree;
+}
+
+// 生成映射数据的函数
+function generateMap($tree, &$map = []) {
+ foreach ($tree as $item) {
+ $map[$item['id']] = $item;
+ if (isset($item['children'])) {
+ generateMap($item['children'], $map);
+ }
+ }
+ return $map;
+}
+
/**
* 获取一个文章分类
*/
@@ -146,7 +182,7 @@ function tpl_get_channel($type, $typeId, $row = 100, $where = '', $orderby = '')
{
switch ($type) {
case "all":
- //获取顶级分类
+ //获取所有
return get_document_category_all();
break;
case 'top':
@@ -421,10 +457,18 @@ function tpl_get_list($orderBy, int $pageSize, $cid, $type, $table = 'article',
} else {
$documentListModel = $documentListModel->paginate($pageSize);
}
+ //获取评论数 跟在文章后面
+ if (!empty($item)){
+ $commentModel = (new Comment())->field('document_id as id,count(*) as comment')
+ ->where("id","in" ,array_column($documentListModel->toArray(),'id'))
+ ->group('id')
+ ->select();
+ }
$lists = [];
foreach ($documentListModel as $key => $item) {
//生成文章url
$item['url'] = make_detail_url($item);
+ $item['comment'] = $commentModel[$item['id']]['comment'] ?? 0;
$lists[$key] = $item;
}
$re = [
@@ -548,10 +592,18 @@ function tpl_get_article_list($cid, $row, $orderby, $table = 'article', $type =
}
$documentListModel = $documentListModel->order($orderby)->select();
+ //获取评论数 跟在文章后面
+ if (!empty($item)){
+ $commentModel = (new Comment())->field('document_id as id,count(*) as comment')
+ ->where("id","in" ,array_column($documentListModel->toArray(),'id'))
+ ->group('id')
+ ->select();
+ }
$lists = [];
foreach ($documentListModel as $key => $item) {
//生成文章url
$item['url'] = make_detail_url($item);
+ $item['comment'] = $commentModel[$item['id']]['comment'] ?? 0;
$lists[$key] = $item;
}
return $lists;
@@ -697,19 +749,18 @@ if (!function_exists('web_config')) {
* @date 2021-11-12 0:34
*/
if (!function_exists('tpl_get_tags_list')) {
- function tpl_get_tags_list($tags)
+ function tpl_get_tags_list($tag ='', $limit = 10)
{
- if (!$tags) {
- return false;
+ $where =[
+ 'name'=> $tag,
+ 'page'=> 1,
+ 'limit'=> $limit
+ ];
+ try {
+ return TagModel::getList($where);
+ } catch (DbException $e) {
+ return [];
}
- $tagArr = explode(',', $tags);
- $tagTemp = [];
- foreach ($tagArr as $item) {
- $data['title'] = $item;
- $data['url'] = url('/article/tag', ["t" => $item])->build();
- array_push($tagTemp, $data);
- }
- return $tagTemp;
}
}
@@ -1195,6 +1246,21 @@ function get_nav($x, $field = false)
}
}
+function tpl_get_admin($id,$field=""){
+ $info = cache("admin_{$id}");
+ if (is_null($info)){
+ try {
+ //TODO 这里考虑是否会泄露用户信息问题,并且是否会影响性能,后续需要完善发帖数量等等
+ $info = \app\common\model\User::where('id', $id)->field('nickname,avatar,email,ip,remark')->find();
+ } catch (DbException $e) {
+ return "";
+ }
+ cache("admin_{$id}", $info, 1*60*60);
+ }
+ return $info[$field] ?? '';
+
+}
+
/**
* 获取导航列表
*/
diff --git a/app/index/config/view.php b/app/index/config/view.php
index 03ad90a..6766532 100644
--- a/app/index/config/view.php
+++ b/app/index/config/view.php
@@ -5,9 +5,10 @@
//第一步判断选择的模板
$theme = system_config('web_template');
//检查主题目录是否存在,不存在则更新为默认目录
-if (file_exists(public_path("template/{$theme}"))) {
+if (!file_exists(public_path("template/{$theme}"))) {
$theme = 'default';
}
+
//检查是否切换模板
if (is_mobile() == "wap" && file_exists(public_path("template/{$theme}/mobile"))) {
$mode = "mobile";
diff --git a/public/template/default/info.json b/public/template/default/info.json
index a8e4588..521d527 100644
--- a/public/template/default/info.json
+++ b/public/template/default/info.json
@@ -1,33 +1,9 @@
{
"title":"默认主题",
"author":"木子的忧伤",
- "demo_url":"http://default.lcm.wang/",
- "category_list":[
- {
- "name": "默认列表",
- "template":"list_default.html"
- },
- {
- "name": "两排列表",
- "template":"list_double.html"
- }
- ],
- "article_list":[
- {
- "name": "普通文章",
- "template":"page.html"
- },
- {
- "name": "关于我们",
- "template":"page_about.html"
- },
- {
- "name": "产品文章",
- "template":"page_product.html"
- }
- ],
- "info_file":"全部都是可视化的 没什么可说明的",
- "update_url":"http://www.lcm.wang/",
+ "demo_url":"https://blog.apecloud.ltd/",
+ "description":"默认主题,精美响应式主题",
+ "update_url":"https://blog.apecloud.ltd/",
"preview_file":"preview.jpg",
"versions":"1.0"
}
\ No newline at end of file
diff --git a/public/template/default/pc/index/index.html b/public/template/default/pc/index/index.html
index 714a097..1a04f44 100644
--- a/public/template/default/pc/index/index.html
+++ b/public/template/default/pc/index/index.html
@@ -131,7 +131,7 @@
{$field['view']}
-
+ {$field['comment']}