Article.php 8.4 KB

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