123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216 |
- <?php
- namespace app\home\controller;
- use think\facade\View;
- use think\facade\Lang;
- /**
-
- *
-
- *
- * ----------------------------------------------------------------------------
- *
-
- * 控制器
- */
- class Article extends BaseMall
- {
- public function initialize()
- {
- parent::initialize(); // TODO: Change the autogenerated stub
- Lang::load(base_path() . 'home/lang/' . config('lang.default_lang') . '/article.lang.php');
- }
- /**
- * 文章列表显示页面
- */
- public function index()
- {
- $ac_id = intval(input('param.ac_id'));
- if (empty($ac_id)) {
- $this->error(lang('param_error')); //'缺少参数:文章类别编号'
- }
- /**
- * 得到导航ID
- */
- $nav_id = intval(input('param.nav_id'));
- View::assign('index_sign', $nav_id);
- /**
- * 根据类别编号获取文章类别信息
- */
- $articleclass_model = model('articleclass');
- $article_class = $articleclass_model->getOneArticleclass($ac_id);
- View::assign('class_name', $article_class['ac_name']);
- if (empty($article_class) || !is_array($article_class)) {
- $this->error(lang('article_article_class_not_exists')); //'该文章分类并不存在'
- }
- $default_count = 5; //定义最新文章列表显示文章的数量
- /**
- * 分类导航
- */
- $nav_link = array(
- array(
- 'title' => lang('homepage'), 'link' => HOME_SITE_URL
- ), array(
- 'title' => $article_class['ac_name']
- )
- );
- View::assign('nav_link_list', $nav_link);
- /**
- * 左侧分类导航
- */
- $articleclass_list = $articleclass_model->getArticleclassList(array());
- $tree = new \mall\Tree();
- $tree->setTree($articleclass_list, 'ac_id', 'ac_parent_id', 'ac_name');
- View::assign('sub_class_list', $tree->getArrayList());
- /**
- * 文章列表
- */
- $child_class_list = $articleclass_model->getChildClass($ac_id);
- $ac_ids = array();
- if (!empty($child_class_list) && is_array($child_class_list)) {
- foreach ($child_class_list as $v) {
- $ac_ids[] = $v['ac_id'];
- }
- }
- $ac_ids = implode(',', $ac_ids);
- $article_model = model('article');
- $condition = array();
- $condition[] = array('ac_id', 'in', $ac_ids);
- $condition[] = array('article_show', '=', '1');
- $article_list = $article_model->getArticleList($condition, 12);
- View::assign('article', $article_list);
- View::assign('show_page', $article_model->page_info->render());
- /**
- * 最新文章列表
- */
- $count = count($article_list);
- $new_article_list = array();
- if (!empty($article_list) && is_array($article_list)) {
- for ($i = 0; $i < ($count > $default_count ? $default_count : $count); $i++) {
- $new_article_list[] = $article_list[$i];
- }
- }
- View::assign('new_article_list', $new_article_list);
- //SEO 设置
- $seo = model('seo')->type('article')->param(array('article_class' => $article_class['ac_name']))->show();
- $this->_assign_seo($seo);
- return View::fetch($this->template_dir . 'article_list');
- }
- /**
- * 单篇文章显示页面
- */
- public function show()
- {
- $article_id = intval(input('param.article_id'));
- if (empty($article_id)) {
- $this->error(lang('param_error')); //'缺少参数:文章编号'
- }
- /**
- * 根据文章编号获取文章信息
- */
- $article_model = model('article');
- $condition = array();
- $condition[] = array('article_id', '=', $article_id);
- $article = $article_model->getOneArticle($condition);
- if (empty($article) || !is_array($article) || $article['article_show'] == '0') {
- $this->error(lang('article_show_not_exists')); //'该文章并不存在'
- }
- View::assign('article', $article);
- /**
- * 根据类别编号获取文章类别信息
- */
- $articleclass_model = model('articleclass');
- $article_class = $articleclass_model->getOneArticleclass($article['ac_id']);
- if (empty($article_class) || !is_array($article_class)) {
- $this->error(lang('article_show_delete')); //'该文章已随所属类别被删除'
- }
- $default_count = 5; //定义最新文章列表显示文章的数量
- /**
- * 分类导航
- */
- $nav_link = array(
- array(
- 'title' => lang('homepage'), 'link' => HOME_SITE_URL
- ), array(
- 'title' => $article_class['ac_name'],
- 'link' => (string)url('Article/index', array('ac_id' => $article_class['ac_id']))
- ), array(
- 'title' => lang('article_show_article_content')
- )
- );
- View::assign('nav_link_list', $nav_link);
- /**
- * 左侧分类导航
- */
- $articleclass_list = $articleclass_model->getArticleclassList(array());
- $tree = new \mall\Tree();
- $tree->setTree($articleclass_list, 'ac_id', 'ac_parent_id', 'ac_name');
- View::assign('sub_class_list', $tree->getArrayList());
- /**
- * 文章列表
- */
- $child_class_list = $articleclass_model->getChildClass($article_class['ac_id']);
- $ac_ids = array();
- if (!empty($child_class_list) && is_array($child_class_list)) {
- foreach ($child_class_list as $v) {
- $ac_ids[] = $v['ac_id'];
- }
- }
- $ac_ids = implode(',', $ac_ids);
- $article_model = model('article');
- $condition = array();
- $condition[] = array('ac_id', 'in', $ac_ids);
- $condition[] = array('article_show', '=', '1');
- $article_list = $article_model->getArticleList($condition);
- /**
- * 寻找上一篇与下一篇
- */
- $pre_article = $next_article = array();
- if (!empty($article_list) && is_array($article_list)) {
- $pos = 0;
- foreach ($article_list as $k => $v) {
- if ($v['article_id'] == $article['article_id']) {
- $pos = $k;
- break;
- }
- }
- if ($pos > 0 && is_array($article_list[$pos - 1])) {
- $pre_article = $article_list[$pos - 1];
- }
- if ($pos < count($article_list) - 1 and is_array($article_list[$pos + 1])) {
- $next_article = $article_list[$pos + 1];
- }
- }
- View::assign('pre_article', $pre_article);
- View::assign('next_article', $next_article);
- /**
- * 最新文章列表
- */
- $count = count($article_list);
- $new_article_list = array();
- if (!empty($article_list) && is_array($article_list)) {
- for ($i = 0; $i < ($count > $default_count ? $default_count : $count); $i++) {
- $new_article_list[] = $article_list[$i];
- }
- }
- View::assign('new_article_list', $new_article_list);
- $seo_param = array();
- $seo_param['name'] = $article['article_title'];
- $seo_param['article_class'] = $article_class['ac_name'];
- $seo_param['description'] = ds_substing(htmlspecialchars_decode($article['article_content']));
- //SEO 设置
- $seo = model('seo')->type('article_content')->param($seo_param)->show();
- $this->_assign_seo($seo);
- return View::fetch($this->template_dir . 'article_show');
- }
- }
|