inc_news.php 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. <?php
  2. function get_root_channel()
  3. {
  4. global $db;
  5. global $db_mymps;
  6. $query = $db->query('SELECT catid,catname FROM `' . $db_mymps . 'channel` WHERE parentid = \'0\' AND if_view = \'2\' ORDER BY catorder ASC');
  7. while ($queryrow = $db->fetchRow($query)) {
  8. $_array['catid'] = $queryrow['catid'];
  9. $_array['catname'] = $queryrow['catname'];
  10. $_array['uri_m'] = mRewrite('news', array('catid' => $queryrow['catid']));
  11. $channel[] = $_array;
  12. }
  13. return $channel;
  14. }
  15. CURSCRIPT != 'wap' && exit('FORBIDDEN');
  16. $id = isset($id) ? intval($id) : '';
  17. $catid = isset($catid) ? intval($catid) : '';
  18. $page = isset($page) ? intval($page) : 1;
  19. if ($id) {
  20. if (!$id) {
  21. errormsg('新闻ID不能为空!');
  22. }
  23. if (!($news = $db->getRow('SELECT * FROM ' . $db_mymps . 'news WHERE id = \'' . $id . '\''))) {
  24. errormsg('当前新闻不存在或者已经被删除!');
  25. }
  26. $db->query('UPDATE `' . $db_mymps . 'news` SET hit = hit +1 WHERE id = \'' . $id . '\';');
  27. $news['catname'] = $db->getOne('SELECT catname FROM `' . $db_mymps . 'channel` WHERE catid = \'' . $news['catid'] . '\'');
  28. $news['caturi'] = mRewrite('news', array('catid' => $news['catid']));
  29. $loc = get_location_m('channel', $news[catid], $news[title]);
  30. $page_title = $loc['page_title'];
  31. $news['keywords'] = $news['keywords'] ? $news['keywords'] : $news['title'];
  32. $news['description'] = cutstr(clear_html($news['content']), 250);
  33. $shareIcon = strstr($news['imgpath'], 'http') ? $news['imgpath'] : $mymps_global['SiteUrl'] . $news['imgpath'];
  34. include mymps_tpl('news');
  35. }
  36. else if ($catid) {
  37. $cat = get_cat_info($catid, 'channel');
  38. if (!$cat) {
  39. errormsg('您所指定的新闻栏目不存在或者已经删除!');
  40. }
  41. $rootchannel = get_categories_tree($catid, 'channel');
  42. $cat_children = get_channel_children($catid);
  43. $perpage = $mayimobile['mobiletopicperpage'] ? $mayimobile['mobiletopicperpage'] : 10;
  44. $param = setparams(array('mod', 'catid'));
  45. $rows_num = $db->getOne('SELECT COUNT(*) FROM `' . $db_mymps . 'news` AS a WHERE ' . $cat_children);
  46. $totalpage = ceil($rows_num / $perpage);
  47. $num = intval($page - 1) * $perpage;
  48. $page1 = page1('SELECT * FROM ' . $db_mymps . 'news WHERE ' . $cat_children . ' ORDER BY id DESC', $perpage);
  49. foreach ($page1 as $kr => $r) {
  50. $arr['begintime'] = $r['begintime'];
  51. $arr['begintimej'] = GetTime($r['begintime'], 'm-d');
  52. $arr['hit'] = $r['hit'];
  53. $arr['title'] = $r['title'];
  54. $arr['titlej'] = $charset == 'gbk' ? iconv('gb2312', 'utf-8', $r['title']) : $r['title'];
  55. $arr['iscommend'] = $r['iscommend'];
  56. $arr['content'] = clear_html($r['content']);
  57. $arr['contentj'] = $charset == 'gbk' ? iconv('gb2312', 'utf-8', cutstr($arr['content'], 60)) : cutstr($arr['content'], 60);
  58. $arr['uri_m'] = $r['isjump'] ? $r['redirect_url'] : mRewrite('news', array('id' => $r['id']));
  59. $arr['uri_ma'] = $r['isjump'] ? $r['redirect_url'] : 'index.php?mod=news&id=' . $r['id'];
  60. $arr['imgpath'] = $r['imgpath'] ? (!strstr($r['imgpath'], 'http') ? $mymps_global[SiteUrl] . $r['imgpath'] : $r['imgpath']) : '';
  61. $news[] = $arr;
  62. }
  63. if ($mayi) {
  64. $news = 5.4000000000000004 <= PHP_VERSION ? json_encode($news, JSON_UNESCAPED_SLASHES) : str_replace('\\/', '/', json_encode($news));
  65. echo $news;
  66. exit();
  67. }
  68. $parentcats = get_parent_cats('channel', $catid);
  69. $parentcats = is_array($parentcats) ? array_reverse($parentcats) : '';
  70. $loc = get_location_m('channel', $catid);
  71. $page_title = $loc['page_title'];
  72. $channel = $cat;
  73. include mymps_tpl('news_list');
  74. }
  75. else {
  76. !ifplugin('news') && exit('管理员已禁用或未安装资讯插件...');
  77. $rootchannel = get_root_channel();
  78. $perpage = $mayimobile['mobiletopicperpage'] ? $mayimobile['mobiletopicperpage'] : 10;
  79. $param = setparams(array('mod'));
  80. $rows_num = $db->getOne('SELECT COUNT(*) FROM `' . $db_mymps . 'news` AS a ORDER BY id DESC');
  81. $totalpage = ceil($rows_num / $perpage);
  82. $num = intval($page - 1) * $perpage;
  83. $page1 = page1('SELECT * FROM ' . $db_mymps . 'news ORDER BY id DESC', $perpage);
  84. foreach ($page1 as $kr => $r) {
  85. $arr['begintime'] = $r['begintime'];
  86. $arr['begintimej'] = GetTime($r['begintime'], 'm-d');
  87. $arr['hit'] = $r['hit'];
  88. $arr['title'] = $r['title'];
  89. $arr['titlej'] = $charset == 'gbk' ? iconv('gb2312', 'utf-8', $r['title']) : $r['title'];
  90. $arr['iscommend'] = $r['iscommend'];
  91. $arr['content'] = clear_html($r['content']);
  92. $arr['contentj'] = $charset == 'gbk' ? iconv('gb2312', 'utf-8', cutstr($arr['content'], 60)) : cutstr($arr['content'], 60);
  93. $arr['uri_m'] = $r['isjump'] ? $r['redirect_url'] : mRewrite('news', array('id' => $r['id']));
  94. $arr['uri_ma'] = $r['isjump'] ? $r['redirect_url'] : 'index.php?mod=news&id=' . $r['id'];
  95. $arr['imgpath'] = $r['imgpath'] ? (!strstr($r['imgpath'], 'http') ? $mymps_global[SiteUrl] . $r['imgpath'] : $r['imgpath']) : '';
  96. $news[] = $arr;
  97. }
  98. if ($mayi) {
  99. $news = 5.4000000000000004 <= PHP_VERSION ? json_encode($news, JSON_UNESCAPED_SLASHES) : str_replace('\\/', '/', json_encode($news));
  100. echo $news;
  101. exit();
  102. }
  103. $loc = get_location_m('news', 0, '热点资讯');
  104. $page_title = $loc['page_title'];
  105. $s = array();
  106. $s['keywords'] = $pluginsettings['news']['seokeywords'];
  107. $s['description'] = $pluginsettings['news']['seodescription'];
  108. include mymps_tpl('news_index');
  109. }
  110. ?>