/upload/app/article.app.php

https://github.com/bluelovers/ECMall · PHP · 230 lines · 199 code · 14 blank · 17 comment · 19 complexity · 5dbaf77f47e4c61f89730cc9a4570c2a MD5 · raw file

  1. <?php
  2. class ArticleApp extends MallbaseApp
  3. {
  4. var $_article_mod;
  5. var $_acategory_mod;
  6. var $_ACC; //系统文章cate_id数据
  7. var $_cate_ids; //当前分类及子孙分类cate_id
  8. function __construct()
  9. {
  10. $this->ArticleApp();
  11. }
  12. function ArticleApp()
  13. {
  14. parent::__construct();
  15. $this->_article_mod = &m('article');
  16. $this->_acategory_mod = &m('acategory');
  17. /* 获得系统分类cate_id数据 */
  18. $this->_ACC = $this->_acategory_mod->get_ACC();
  19. }
  20. function index()
  21. {
  22. /* 取得导航 */
  23. $this->assign('navs', $this->_get_navs());
  24. /* 处理cate_id */
  25. $cate_id = !empty($_GET['cate_id'])? intval($_GET['cate_id']) : $this->_ACC[ACC_NOTICE]; //如果cate_id为空则默认显示商城快讯
  26. isset($_GET['code']) && isset($this->_ACC[trim($_GET['code'])]) && $cate_id = $this->_ACC[trim($_GET['code'])]; //如果有code
  27. /* 取得当前分类及子孙分类cate_id */
  28. $cate_ids = array();
  29. if ($cate_id > 0 && $cate_id != $this->_ACC[ACC_SYSTEM]) //排除系统内置分类
  30. {
  31. $cate_ids = $this->_acategory_mod->get_descendant($cate_id);
  32. if (!$cate_ids)
  33. {
  34. $this->show_warning('no_such_acategory');
  35. return;
  36. }
  37. }
  38. else
  39. {
  40. $this->show_warning('no_such_acategory');
  41. return;
  42. }
  43. $this->_cate_ids = $cate_ids;
  44. /* 当前位置 */
  45. $curlocal = $this->_get_article_curlocal($cate_id);
  46. unset($curlocal[count($curlocal)-1]['url']);
  47. $this->_curlocal($curlocal);
  48. /* 文章分类 */
  49. $acategories = $this->_get_acategory($cate_id);
  50. /* 分类下的所有文章 */
  51. $all = $this->_get_article('all');
  52. $articles = $all['articles'];
  53. $page = $all['page'];
  54. /* 新文章 */
  55. $new = $this->_get_article('new');
  56. $new_articles = $new['articles'];
  57. // 页面标题
  58. $category = $this->_acategory_mod->get_info($cate_id);
  59. $this->_config_seo('title', $category['cate_name'] . ' - ' . Conf::get('site_title'));
  60. $this->assign('articles', $articles);
  61. $this->assign('new_articles', $new_articles);
  62. $this->_format_page($page);
  63. $this->assign('page_info', $page);
  64. $this->assign('acategories', $acategories);
  65. $this->display('article.index.html');
  66. }
  67. function view()
  68. {
  69. $article_id = empty($_GET['article_id']) ? 0 : intval($_GET['article_id']);
  70. $cate_ids = array();
  71. if ($article_id>0)
  72. {
  73. $article = $this->_article_mod->get('article_id=' . $article_id . ' AND code = "" AND if_show=1 AND store_id=0');
  74. if (!$article)
  75. {
  76. $this->show_warning('no_such_article');
  77. return;
  78. }
  79. if ($article['link']){ //外链文章跳转
  80. header("HTTP/1.1 301 Moved Permanently");
  81. header('location:'.$article['link']);
  82. return;
  83. }
  84. /* 上一篇下一篇 */
  85. $pre_article = $this->_article_mod->get('article_id<' . $article_id . ' AND code = "" AND if_show=1 AND store_id=0 ORDER BY article_id DESC limit 1');
  86. $pre_article && $pre_article['target'] = $pre_article['link'] ? '_blank' : '_self';
  87. $next_article = $this->_article_mod->get('article_id>' . $article_id . ' AND code = "" AND if_show=1 AND store_id=0 ORDER BY article_id ASC limit 1');
  88. $next_article && $next_article['target'] = $next_article['link'] ? '_blank' : '_self';
  89. if ($article)
  90. {
  91. $cate_id = $article['cate_id'];
  92. /* 取得当前分类及子孙分类cate_id */
  93. $cate_ids = $this->_acategory_mod->get_descendant($cate_id);
  94. }
  95. else
  96. {
  97. $this->show_warning('no_such_article');
  98. return;
  99. }
  100. }
  101. else
  102. {
  103. $this->show_warning('no_such_article');
  104. return;
  105. }
  106. $this->_cate_ids = $cate_ids;
  107. /* 当前位置 */
  108. $curlocal = $this->_get_article_curlocal($cate_id);
  109. $curlocal[] =array('text' => Lang::get('content'));
  110. $this->_curlocal($curlocal);
  111. /*文章分类*/
  112. $acategories = $this->_get_acategory($cate_id);
  113. /* 新文章 */
  114. $new = $this->_get_article('new');
  115. $new_articles = $new['articles'];
  116. $this->assign('article', $article);
  117. $this->assign('pre_article', $pre_article);
  118. $this->assign('next_article', $next_article);
  119. $this->assign('new_articles', $new_articles);
  120. $this->assign('acategories', $acategories);
  121. $this->_config_seo('title', $article['title'] . ' - ' . Conf::get('site_title'));
  122. $this->display('article.view.html');
  123. }
  124. function system()
  125. {
  126. $code = empty($_GET['code']) ? '' : trim($_GET['code']);
  127. if (!$code)
  128. {
  129. $this->show_warning('no_such_article');
  130. return;
  131. }
  132. $article = $this->_article_mod->get("code='" . $code . "'");
  133. if (!$article)
  134. {
  135. $this->show_warning('no_such_article');
  136. return;
  137. }
  138. if ($article['link']){ //外链文章跳转
  139. header("HTTP/1.1 301 Moved Permanently");
  140. header('location:'.$article['link']);
  141. return;
  142. }
  143. /*当前位置*/
  144. $curlocal[] =array('text' => $article['title']);
  145. $this->_curlocal($curlocal);
  146. /*文章分类*/
  147. $acategories = $this->_get_acategory('');
  148. /* 新文章 */
  149. $new = $this->_get_article('new');
  150. $new_articles = $new['articles'];
  151. $this->assign('acategories', $acategories);
  152. $this->assign('new_articles', $new_articles);
  153. $this->assign('article', $article);
  154. $this->_config_seo('title', $article['title'] . ' - ' . Conf::get('site_title'));
  155. $this->display('article.view.html');
  156. }
  157. function _get_article_curlocal($cate_id)
  158. {
  159. $parents = array();
  160. if ($cate_id)
  161. {
  162. $acategory_mod = &m('acategory');
  163. $acategory_mod->get_parents($parents, $cate_id);
  164. }
  165. foreach ($parents as $category)
  166. {
  167. $curlocal[] = array('text' => $category['cate_name'], 'ACC' => $category['code'], 'url' => 'index.php?app=article&amp;cate_id=' . $category['cate_id']);
  168. }
  169. return $curlocal;
  170. }
  171. function _get_acategory($cate_id)
  172. {
  173. $acategories = $this->_acategory_mod->get_list($cate_id);
  174. if ($acategories){
  175. unset($acategories[$this->_ACC[ACC_SYSTEM]]);
  176. return $acategories;
  177. }
  178. else
  179. {
  180. $parent = $this->_acategory_mod->get($cate_id);
  181. if (isset($parent['parent_id']))
  182. {
  183. return $this->_get_acategory($parent['parent_id']);
  184. }
  185. }
  186. }
  187. function _get_article($type='')
  188. {
  189. $conditions = '';
  190. $per = '';
  191. switch ($type)
  192. {
  193. case 'new' : $sort_order = 'add_time DESC,sort_order ASC';
  194. $per=5;
  195. break;
  196. case 'all' : $sort_order = 'sort_order ASC,add_time DESC';
  197. $per=10;
  198. break;
  199. }
  200. $page = $this->_get_page($per); //获取分页信息
  201. !empty($this->_cate_ids)&& $conditions = ' AND cate_id ' . db_create_in($this->_cate_ids);
  202. $articles = $this->_article_mod->find(array(
  203. 'conditions' => 'if_show=1 AND store_id=0 AND code = ""' . $conditions,
  204. 'limit' => $page['limit'],
  205. 'order' => $sort_order,
  206. 'count' => true //允许统计
  207. )); //找出所有符合条件的文章
  208. $page['item_count'] = $this->_article_mod->getCount();
  209. foreach ($articles as $key => $article)
  210. {
  211. $articles[$key]['target'] = $article[link] ? '_blank' : '_self';
  212. }
  213. return array('page'=>$page, 'articles'=>$articles);
  214. }
  215. }
  216. ?>