vr-shopxo-source/app/index/controller/Article.php

131 lines
4.0 KiB
PHP
Raw Normal View History

2018-12-28 10:58:37 +00:00
<?php
// +----------------------------------------------------------------------
// | ShopXO 国内领先企业级B2C免费开源电商系统
// +----------------------------------------------------------------------
2021-03-16 02:34:52 +00:00
// | Copyright (c) 2011~2099 http://shopxo.net All rights reserved.
2018-12-28 10:58:37 +00:00
// +----------------------------------------------------------------------
2021-03-16 02:34:52 +00:00
// | Licensed ( https://opensource.org/licenses/mit-license.php )
2018-12-28 10:58:37 +00:00
// +----------------------------------------------------------------------
// | Author: Devil
// +----------------------------------------------------------------------
namespace app\index\controller;
use app\service\ArticleService;
2019-03-11 09:57:15 +00:00
use app\service\SeoService;
2018-12-28 10:58:37 +00:00
/**
* 文章详情
* @author Devil
* @blog http://gong.gg/
* @version 0.0.1
* @datetime 2016-12-01T21:51:08+0800
*/
class Article extends Common
{
/**
* 构造方法
* @author Devil
* @blog http://gong.gg/
* @version 1.0.0
* @date 2018-11-30
* @desc description
*/
public function __construct()
{
parent::__construct();
}
/**
* [Index 文章详情]
* @author Devil
* @blog http://gong.gg/
* @version 0.0.1
* @datetime 2016-12-06T21:31:53+0800
*/
public function Index()
{
// 获取文章
2020-06-16 15:27:12 +00:00
if(empty($this->data_request['id']))
{
2021-07-18 15:42:10 +00:00
MyViewAssign('msg', '文章ID有误');
return MyView('public/tips_error');
2020-06-16 15:27:12 +00:00
}
// 获取数据
$id = intval($this->data_request['id']);
2018-12-28 10:58:37 +00:00
$params = [
2020-06-16 15:27:12 +00:00
'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,
2018-12-28 10:58:37 +00:00
];
2020-06-16 15:27:12 +00:00
$ret = ArticleService::ArticleList($params);
if(!empty($ret['data'][0]))
2018-12-28 10:58:37 +00:00
{
// 访问统计
ArticleService::ArticleAccessCountInc(['id'=>$id]);
// 是否外部链接
2020-06-16 15:27:12 +00:00
if(!empty($ret['data'][0]['jump_url']))
2018-12-28 10:58:37 +00:00
{
2021-07-18 15:42:10 +00:00
return MyRedirect($ret['data'][0]['jump_url']);
2018-12-28 10:58:37 +00:00
}
2020-06-16 15:27:12 +00:00
// 获取分类
2018-12-28 10:58:37 +00:00
$article_category_content = ArticleService::ArticleCategoryListContent();
2021-07-18 15:42:10 +00:00
MyViewAssign('category_list', $article_category_content['data']);
2018-12-28 10:58:37 +00:00
2019-06-02 13:45:10 +00:00
// seo
2020-06-16 15:27:12 +00:00
$seo_title = empty($ret['data'][0]['seo_title']) ? $ret['data'][0]['title'] : $ret['data'][0]['seo_title'];
2021-07-18 15:42:10 +00:00
MyViewAssign('home_seo_site_title', SeoService::BrowserSeoTitle($seo_title, 2));
2020-06-16 15:27:12 +00:00
if(!empty($ret['data'][0]['seo_keywords']))
2019-06-02 13:45:10 +00:00
{
2021-07-18 15:42:10 +00:00
MyViewAssign('home_seo_site_keywords', $ret['data'][0]['seo_keywords']);
2019-06-02 13:45:10 +00:00
}
2020-06-16 15:27:12 +00:00
if(!empty($ret['data'][0]['seo_desc']))
2019-06-02 13:45:10 +00:00
{
2021-07-18 15:42:10 +00:00
MyViewAssign('home_seo_site_description', $ret['data'][0]['seo_desc']);
2019-06-02 13:45:10 +00:00
}
2021-08-24 02:38:28 +00:00
$article = $ret['data'][0];
$this->PluginsHook($id, $article);
MyViewAssign('article', $article);
2021-07-18 15:42:10 +00:00
return MyView();
2018-12-28 10:58:37 +00:00
}
2020-06-16 15:27:12 +00:00
// 无数据
2021-07-18 15:42:10 +00:00
MyViewAssign('msg', '文章不存在或已删除');
return MyView('public/tips_error');
2018-12-28 10:58:37 +00:00
}
2021-08-24 02:38:28 +00:00
/**
* 钩子处理
* @author whats
* @blog
* @version 1.0.0
* @date 2019-04-22
* @desc description
* @param [int] $article_id [文章id]
* @param [array] $params [输入参数]
*/
private function PluginsHook($article_id, &$article)
{
$hook_arr = [
//文章内容内部钩子
'plugins_view_article_detail_content_within',
];
foreach($hook_arr as $hook_name)
{
MyViewAssign($hook_name.'_data', MyEventTrigger($hook_name,
[
'hook_name' => $hook_name,
'is_backend' => false,
'article_id' => $article_id,
'article' => &$article,
]));
}
}
2018-12-28 10:58:37 +00:00
}
?>