From d98369d7fd38b2bb25621517b77d0bac76aa9446 Mon Sep 17 00:00:00 2001 From: gongfuxiang Date: Tue, 9 Nov 2021 22:50:35 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=87=E7=AB=A0=E4=BC=98=E5=8C=96=E3=80=81?= =?UTF-8?q?=E6=94=AF=E6=8C=81=E5=88=86=E7=B1=BB=E3=80=81=E6=94=AF=E6=8C=81?= =?UTF-8?q?=E5=B0=8F=E7=A8=8B=E5=BA=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/api/controller/Article.php | 148 ++++++++++++++++ app/index/controller/Article.php | 121 +++++++++++-- app/index/view/default/article/category.html | 165 +++++++++++++++++ app/index/view/default/article/index.html | 72 +++++--- app/index/view/default/index/index.html | 10 +- app/index/view/default/safety/index.html | 2 +- app/route/route.config | 1 + app/service/ArticleService.php | 175 +++++++++++++++---- public/static/index/default/css/article.css | 123 ++++++++++--- public/static/index/default/css/index.css | 2 +- 10 files changed, 707 insertions(+), 112 deletions(-) create mode 100644 app/api/controller/Article.php create mode 100644 app/index/view/default/article/category.html diff --git a/app/api/controller/Article.php b/app/api/controller/Article.php new file mode 100644 index 000000000..925f0f386 --- /dev/null +++ b/app/api/controller/Article.php @@ -0,0 +1,148 @@ + $article_category['data'], + ]; + return ApiService::ApiDataReturn(SystemBaseService::DataReturn($result)); + } + + /** + * 分类文章列表 + * @author Devil + * @blog http://gong.gg/ + * @version 1.0.0 + * @date 2021-11-08 + * @desc description + */ + public function DataList() + { + // 参数 + $params = $this->data_post; + + // 分页 + $number = 10; + $page = max(1, isset($this->data_post['page']) ? intval($this->data_post['page']) : 1); + + // 条件 + $where = ArticleService::ArticleWhere($params); + + // 获取总数 + $total = ArticleService::ArticleTotal($where); + $page_total = ceil($total/$number); + $start = intval(($page-1)*$number); + + // 获取列表 + $data_params = [ + 'm' => $start, + 'n' => $number, + 'where' => $where, + ]; + $data = ArticleService::ArticleList($data_params); + + // 返回数据 + $result = [ + 'total' => $total, + 'page_total' => $page_total, + 'data' => $data['data'], + ]; + return ApiService::ApiDataReturn(SystemBaseService::DataReturn($result)); + } + + /** + * 文章详情 + * @author Devil + * @blog http://gong.gg/ + * @version 1.0.0 + * @date 2021-11-08 + * @desc description + */ + public function Detail() + { + // 获取文章 + if(!empty($this->data_request['id'])) + { + // 获取数据 + $id = intval($this->data_request['id']); + $params = [ + 'where' => [ + 'is_enable' => 1, + 'id' => $id, + ], + 'field' => 'id,title,title_color,jump_url,content,access_count,article_category_id,seo_title,seo_keywords,seo_desc,add_time', + 'm' => 0, + 'n' => 1, + ]; + $data = ArticleService::ArticleList($params); + if(!empty($data['data'][0])) + { + // 访问统计 + ArticleService::ArticleAccessCountInc(['id'=>$id]); + + // 返回数据 + $result = [ + 'data' => $data['data'][0], + 'category_list' => $article_category['data'], + ]; + $ret = SystemBaseService::DataReturn($result); + } else { + $ret = DataReturn('文章不存在或已删除', -1); + } + } else { + $ret = DataReturn('文章ID有误', -1); + } + return ApiService::ApiDataReturn($ret); + } +} +?> \ No newline at end of file diff --git a/app/index/controller/Article.php b/app/index/controller/Article.php index 9b812449c..1976121aa 100755 --- a/app/index/controller/Article.php +++ b/app/index/controller/Article.php @@ -36,11 +36,12 @@ class Article extends Common } /** - * [Index 文章详情] - * @author Devil - * @blog http://gong.gg/ - * @version 0.0.1 - * @datetime 2016-12-06T21:31:53+0800 + * 文章详情 + * @author Devil + * @blog http://gong.gg/ + * @version 1.0.0 + * @date 2021-11-08 + * @desc description */ public function Index() { @@ -77,8 +78,11 @@ class Article extends Common } // 获取分类 - $article_category_content = ArticleService::ArticleCategoryListContent(); - MyViewAssign('category_list', $article_category_content['data']); + $article_category = ArticleService::ArticleCategoryList(); + MyViewAssign('category_list', $article_category['data']); + + // 上一篇、下一篇 + MyViewAssign('last_next_data', ArticleService::ArticleLastNextData($id)); // seo $seo_title = empty($article['seo_title']) ? $article['title'] : $article['seo_title']; @@ -93,7 +97,7 @@ class Article extends Common } // 钩子 - $this->PluginsHook($id, $article); + $this->PluginsContentHook($id, $article); MyViewAssign('article', $article); return MyView(); @@ -105,7 +109,104 @@ class Article extends Common } /** - * 钩子处理 + * 文章分类 + * @author Devil + * @blog http://gong.gg/ + * @version 1.0.0 + * @date 2021-11-08 + * @desc description + */ + public function Category() + { + // 条件 + $where = ArticleService::ArticleWhere($this->data_request); + + // 总数 + $total = ArticleService::ArticleTotal($where); + + // 分页 + $page_params = [ + 'number' => $this->page_size, + 'total' => $total, + 'where' => $this->data_request, + 'page' => $this->page, + 'url' => MyUrl('index/article/category'), + ]; + $page = new \base\Page($page_params); + + // 获取列表 + $data_params = [ + 'm' => $page->GetPageStarNumber(), + 'n' => $this->page_size, + 'where' => $where, + ]; + $ret = ArticleService::ArticleList($data_params); + + // 获取分类 + $article_category = ArticleService::ArticleCategoryList(); + MyViewAssign('category_list', $article_category['data']); + + // 分类信息 + $category_info = ArticleService::ArticleCategoryInfo($this->data_request, $article_category['data']); + MyViewAssign('category_info', $category_info); + + // 浏览器名称 + MyViewAssign('home_seo_site_title', SeoService::BrowserSeoTitle(empty($category_info) ? '所有文章' : $category_info['name'], 1)); + + // 基础参数赋值 + MyViewAssign('page_html', $page->GetPageHtml()); + MyViewAssign('data_list', $ret['data']); + MyViewAssign('params', $this->data_request); + + // 钩子 + $this->PluginsCategoryHook($ret['data'], $this->data_request); + return MyView(); + } + + /** + * 分类钩子处理 + * @author whats + * @version 1.0.0 + * @date 2019-04-22 + * @desc description + * @param [array] $data [文章内容] + * @param [array] $params [输入参数] + */ + private function PluginsCategoryHook(&$data, $params = []) + { + $hook_arr = [ + // 分类内容顶部钩子 + 'plugins_view_article_category_top', + + // 分类底部钩子 + 'plugins_view_article_category_bottom', + + // 分类内容顶部钩子 + 'plugins_view_article_category_content_top', + + // 分类内容底部钩子 + 'plugins_view_article_category_content_botton', + + // 分类左侧内部顶部钩子 + 'plugins_view_article_category_left_inside_top', + + // 分类左侧内部底部钩子 + 'plugins_view_article_category_left_inside_botton', + ]; + foreach($hook_arr as $hook_name) + { + MyViewAssign($hook_name.'_data', MyEventTrigger($hook_name, + [ + 'hook_name' => $hook_name, + 'is_backend' => false, + 'data' => &$data, + 'params' => $params, + ])); + } + } + + /** + * 内容钩子处理 * @author whats * @version 1.0.0 * @date 2019-04-22 @@ -113,7 +214,7 @@ class Article extends Common * @param [int] $article_id [文章id] * @param [array] $article [文章内容] */ - private function PluginsHook($article_id, &$article) + private function PluginsContentHook($article_id, &$article) { $hook_arr = [ // 文章内容顶部钩子 diff --git a/app/index/view/default/article/category.html b/app/index/view/default/article/category.html new file mode 100644 index 000000000..3ae192eae --- /dev/null +++ b/app/index/view/default/article/category.html @@ -0,0 +1,165 @@ +{{include file="public/header" /}} + + +{{include file="public/header_top_nav" /}} + + +{{include file="public/nav_search" /}} + + +{{include file="public/header_nav" /}} + + +{{include file="public/goods_category" /}} + + +{{if isset($shopxo_is_develop) and $shopxo_is_develop eq true}} +
+ plugins_view_article_category_top +
+{{/if}} +{{if !empty($plugins_view_article_category_top_data) and is_array($plugins_view_article_category_top_data)}} + {{foreach $plugins_view_article_category_top_data as $hook}} + {{if is_string($hook) or is_int($hook)}} + {{$hook|raw}} + {{/if}} + {{/foreach}} +{{/if}} + + +
+ +
+ {{if !empty($category_info)}} +
+

{{$category_info.name}}

+
+
+ {{/if}} + + + {{if isset($shopxo_is_develop) and $shopxo_is_develop eq true}} +
+ plugins_view_article_category_content_top +
+ {{/if}} + {{if !empty($plugins_view_article_category_content_top_data) and is_array($plugins_view_article_category_content_top_data)}} + {{foreach $plugins_view_article_category_content_top_data as $hook}} + {{if is_string($hook) or is_int($hook)}} + {{$hook|raw}} + {{/if}} + {{/foreach}} + {{/if}} + + + {{if !empty($data_list)}} +
+
+
    + {{foreach $data_list as $v}} +
  • + {{$v.title}} + {{$v.add_time}} +
  • + {{/foreach}} +
+
+
+ + +
{{$page_html|raw}}
+ {{else /}} + {{include file="public/not_data" /}} + {{/if}} + + + {{if isset($shopxo_is_develop) and $shopxo_is_develop eq true}} +
+ plugins_view_article_category_content_botton +
+ {{/if}} + {{if !empty($plugins_view_article_category_content_botton_data) and is_array($plugins_view_article_category_content_botton_data)}} + {{foreach $plugins_view_article_category_content_botton_data as $hook}} + {{if is_string($hook) or is_int($hook)}} + {{$hook|raw}} + {{/if}} + {{/foreach}} + {{/if}} +
+ + + + + 侧栏导航 + +
+ + + +{{if isset($shopxo_is_develop) and $shopxo_is_develop eq true}} +
+ plugins_view_article_category_bottom +
+{{/if}} +{{if !empty($plugins_view_article_category_bottom_data) and is_array($plugins_view_article_category_bottom_data)}} + {{foreach $plugins_view_article_category_bottom_data as $hook}} + {{if is_string($hook) or is_int($hook)}} + {{$hook|raw}} + {{/if}} + {{/foreach}} +{{/if}} + + +{{include file="public/footer" /}} + \ No newline at end of file diff --git a/app/index/view/default/article/index.html b/app/index/view/default/article/index.html index d4d8be9ae..ec839b91d 100755 --- a/app/index/view/default/article/index.html +++ b/app/index/view/default/article/index.html @@ -27,10 +27,10 @@ {{/if}} -
+
-
+

{{$article.title}}

{{$article.content|raw}}
+ +
+
+
+
+ 上一篇: + {{if !empty($last_next_data['last'])}} + {{$last_next_data.last.title}} + {{$last_next_data.last.add_time}} + {{else /}} + 没有符合条件的文章 + {{/if}} +
+
+ 下一篇: + {{if !empty($last_next_data['next'])}} + {{$last_next_data.next.title}} + {{$last_next_data.next.add_time}} + {{else /}} + 没有符合条件的文章 + {{/if}} +
+
+
+ {{if isset($shopxo_is_develop) and $shopxo_is_develop eq true}}
@@ -72,10 +97,10 @@
-