Article.php 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217
  1. <?php
  2. namespace app\home\controller;
  3. use think\facade\View;
  4. use think\facade\Lang;
  5. /**
  6. * ============================================================================
  7. *
  8. * ============================================================================
  9. * 版权所有 2014-2028 浙江惠利玛产业互联网有限公司,并保留所有权利。
  10. * 网站地址: https://www.valimart.net/
  11. * ----------------------------------------------------------------------------
  12. *
  13. * ============================================================================
  14. * 控制器
  15. */
  16. class Article extends BaseMall
  17. {
  18. public function initialize()
  19. {
  20. parent::initialize(); // TODO: Change the autogenerated stub
  21. Lang::load(base_path().'home/lang/'.config('lang.default_lang').'/article.lang.php');
  22. }
  23. /**
  24. * 文章列表显示页面
  25. */
  26. public function index()
  27. {
  28. $ac_id=intval(input('param.ac_id'));
  29. if (empty($ac_id)) {
  30. $this->error(lang('param_error'));//'缺少参数:文章类别编号'
  31. }
  32. /**
  33. * 得到导航ID
  34. */
  35. $nav_id = intval(input('param.nav_id'));
  36. View::assign('index_sign', $nav_id);
  37. /**
  38. * 根据类别编号获取文章类别信息
  39. */
  40. $articleclass_model = model('articleclass');
  41. $article_class = $articleclass_model->getOneArticleclass($ac_id);
  42. View::assign('class_name', $article_class['ac_name']);
  43. if (empty($article_class) || !is_array($article_class)) {
  44. $this->error(lang('article_article_class_not_exists'));//'该文章分类并不存在'
  45. }
  46. $default_count = 5;//定义最新文章列表显示文章的数量
  47. /**
  48. * 分类导航
  49. */
  50. $nav_link = array(
  51. array(
  52. 'title' => lang('homepage'), 'link' => HOME_SITE_URL
  53. ), array(
  54. 'title' => $article_class['ac_name']
  55. )
  56. );
  57. View::assign('nav_link_list', $nav_link);
  58. /**
  59. * 左侧分类导航
  60. */
  61. $articleclass_list = $articleclass_model->getArticleclassList(array());
  62. $tree = new \mall\Tree();
  63. $tree->setTree($articleclass_list, 'ac_id', 'ac_parent_id', 'ac_name');
  64. View::assign('sub_class_list', $tree->getArrayList());
  65. /**
  66. * 文章列表
  67. */
  68. $child_class_list = $articleclass_model->getChildClass($ac_id);
  69. $ac_ids = array();
  70. if (!empty($child_class_list) && is_array($child_class_list)) {
  71. foreach ($child_class_list as $v) {
  72. $ac_ids[] = $v['ac_id'];
  73. }
  74. }
  75. $ac_ids = implode(',', $ac_ids);
  76. $article_model = model('article');
  77. $condition = array();
  78. $condition[]=array('ac_id','in',$ac_ids);
  79. $condition[]=array('article_show','=','1');
  80. $article_list = $article_model->getArticleList($condition, 12);
  81. View::assign('article', $article_list);
  82. View::assign('show_page', $article_model->page_info->render());
  83. /**
  84. * 最新文章列表
  85. */
  86. $count = count($article_list);
  87. $new_article_list = array();
  88. if (!empty($article_list) && is_array($article_list)) {
  89. for ($i = 0; $i < ($count > $default_count ? $default_count : $count); $i++) {
  90. $new_article_list[] = $article_list[$i];
  91. }
  92. }
  93. View::assign('new_article_list', $new_article_list);
  94. //SEO 设置
  95. $seo = model('seo')->type('article')->param(array('article_class' => $article_class['ac_name']))->show();
  96. $this->_assign_seo($seo);
  97. return View::fetch($this->template_dir.'article_list');
  98. }
  99. /**
  100. * 单篇文章显示页面
  101. */
  102. public function show()
  103. {
  104. $article_id=intval(input('param.article_id'));
  105. if (empty($article_id)) {
  106. $this->error(lang('param_error'));//'缺少参数:文章编号'
  107. }
  108. /**
  109. * 根据文章编号获取文章信息
  110. */
  111. $article_model = model('article');
  112. $condition = array();
  113. $condition[] = array('article_id','=',$article_id);
  114. $article = $article_model->getOneArticle($condition);
  115. if (empty($article) || !is_array($article) || $article['article_show'] == '0') {
  116. $this->error(lang('article_show_not_exists'));//'该文章并不存在'
  117. }
  118. View::assign('article', $article);
  119. /**
  120. * 根据类别编号获取文章类别信息
  121. */
  122. $articleclass_model = model('articleclass');
  123. $article_class = $articleclass_model->getOneArticleclass($article['ac_id']);
  124. if (empty($article_class) || !is_array($article_class)) {
  125. $this->error(lang('article_show_delete'));//'该文章已随所属类别被删除'
  126. }
  127. $default_count = 5;//定义最新文章列表显示文章的数量
  128. /**
  129. * 分类导航
  130. */
  131. $nav_link = array(
  132. array(
  133. 'title' => lang('homepage'), 'link' => HOME_SITE_URL
  134. ), array(
  135. 'title' => $article_class['ac_name'],
  136. 'link' => (string)url('Article/index', array('ac_id' => $article_class['ac_id']))
  137. ), array(
  138. 'title' => lang('article_show_article_content')
  139. )
  140. );
  141. View::assign('nav_link_list', $nav_link);
  142. /**
  143. * 左侧分类导航
  144. */
  145. $articleclass_list = $articleclass_model->getArticleclassList(array());
  146. $tree = new \mall\Tree();
  147. $tree->setTree($articleclass_list, 'ac_id', 'ac_parent_id', 'ac_name');
  148. View::assign('sub_class_list', $tree->getArrayList());
  149. /**
  150. * 文章列表
  151. */
  152. $child_class_list = $articleclass_model->getChildClass($article_class['ac_id']);
  153. $ac_ids = array();
  154. if (!empty($child_class_list) && is_array($child_class_list)) {
  155. foreach ($child_class_list as $v) {
  156. $ac_ids[] = $v['ac_id'];
  157. }
  158. }
  159. $ac_ids = implode(',', $ac_ids);
  160. $article_model = model('article');
  161. $condition = array();
  162. $condition[]=array('ac_id','in',$ac_ids);
  163. $condition[]=array('article_show','=','1');
  164. $article_list = $article_model->getArticleList($condition);
  165. /**
  166. * 寻找上一篇与下一篇
  167. */
  168. $pre_article = $next_article = array();
  169. if (!empty($article_list) && is_array($article_list)) {
  170. $pos = 0;
  171. foreach ($article_list as $k => $v) {
  172. if ($v['article_id'] == $article['article_id']) {
  173. $pos = $k;
  174. break;
  175. }
  176. }
  177. if ($pos > 0 && is_array($article_list[$pos - 1])) {
  178. $pre_article = $article_list[$pos - 1];
  179. }
  180. if ($pos < count($article_list) - 1 and is_array($article_list[$pos + 1])) {
  181. $next_article = $article_list[$pos + 1];
  182. }
  183. }
  184. View::assign('pre_article', $pre_article);
  185. View::assign('next_article', $next_article);
  186. /**
  187. * 最新文章列表
  188. */
  189. $count = count($article_list);
  190. $new_article_list = array();
  191. if (!empty($article_list) && is_array($article_list)) {
  192. for ($i = 0; $i < ($count > $default_count ? $default_count : $count); $i++) {
  193. $new_article_list[] = $article_list[$i];
  194. }
  195. }
  196. View::assign('new_article_list', $new_article_list);
  197. $seo_param = array();
  198. $seo_param['name'] = $article['article_title'];
  199. $seo_param['article_class'] = $article_class['ac_name'];
  200. $seo_param['description'] = ds_substing(htmlspecialchars_decode($article['article_content']));
  201. //SEO 设置
  202. $seo = model('seo')->type('article_content')->param($seo_param)->show();
  203. $this->_assign_seo($seo);
  204. return View::fetch($this->template_dir.'article_show');
  205. }
  206. }