portal_list.php 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223
  1. <?php
  2. /**
  3. * [Discuz!] (C)2001-2099 Comsenz Inc.
  4. * This is NOT a freeware, use is subject to license terms
  5. *
  6. * $Id: portal_list.php 33245 2013-05-09 02:02:59Z laoguozhang $
  7. */
  8. if(!defined('IN_DISCUZ')) {
  9. exit('Access Denied');
  10. }
  11. $_G['catid'] = $catid = max(0,intval($_GET['catid']));
  12. if(empty($catid)) {
  13. showmessage('list_choose_category', dreferer());
  14. }
  15. $portalcategory = &$_G['cache']['portalcategory'];
  16. $cat = $portalcategory[$catid];
  17. if(empty($cat)) {
  18. showmessage('list_category_noexist', dreferer());
  19. }
  20. require_once libfile('function/portalcp');
  21. $categoryperm = getallowcategory($_G['uid']);
  22. if($cat['closed'] && !$_G['group']['allowdiy'] && !$categoryperm[$catid]['allowmanage']) {
  23. showmessage('list_category_is_closed', dreferer());
  24. }
  25. if(!isset($_G['makehtml'])) {
  26. if(!empty($cat['url'])) dheader('location:'.$cat['url']);
  27. if(defined('SUB_DIR') && $_G['siteurl']. substr(SUB_DIR, 1) != $cat['caturl'] || !defined('SUB_DIR') && $_G['siteurl'] != substr($cat['caturl'], 0, strrpos($cat['caturl'], '/')+1)) {
  28. dheader('location:'.$cat['caturl'], '301');
  29. }
  30. }
  31. $cat = category_remake($catid);
  32. $navid = 'mn_P'.$cat['topid'];
  33. foreach ($_G['setting']['navs'] as $navsvalue) {
  34. if($navsvalue['navid'] == $navid && $navsvalue['available'] && $navsvalue['level'] == 0) {
  35. $_G['mnid'] = $navid;
  36. break;
  37. }
  38. }
  39. $page = max(1, intval($_GET['page']));
  40. foreach($cat['ups'] as $val) {
  41. $cats[] = $val['catname'];
  42. }
  43. $bodycss = array($cat['topid'] => 'pg_list_'.$cat['topid']);
  44. if($cat['upid']) {
  45. $bodycss[$cat['upid']] = 'pg_list_'.$cat['upid'];
  46. }
  47. $bodycss[$cat['catid']] = 'pg_list_'.$cat['catid'];
  48. $cat['bodycss'] = implode(' ', $bodycss);
  49. $catseoset = array(
  50. 'seotitle' => $cat['seotitle'],
  51. 'seokeywords' => $cat['keyword'],
  52. 'seodescription' => $cat['description']
  53. );
  54. $seodata = array('firstcat' => $cats[0], 'secondcat' => $cats[1], 'curcat' => $cat['catname'], 'page' => intval($_GET['page']));
  55. list($navtitle, $metadescription, $metakeywords) = get_seosetting('articlelist', $seodata, $catseoset);
  56. if(!$navtitle) {
  57. $navtitle = helper_seo::get_title_page($cat['catname'], $_G['page']);
  58. $nobbname = false;
  59. } else {
  60. $nobbname = true;
  61. }
  62. if(!$metakeywords) {
  63. $metakeywords = $cat['catname'];
  64. }
  65. if(!$metadescription) {
  66. $metadescription = $cat['catname'];
  67. }
  68. if(isset($_G['makehtml'])){
  69. helper_makehtml::portal_list($cat);
  70. }
  71. $file = 'portal/list:'.$catid;
  72. $tpldirectory = '';
  73. $primaltplname = $cat['primaltplname'];
  74. if(strpos($primaltplname, ':') !== false) {
  75. list($tpldirectory, $primaltplname) = explode(':', $primaltplname);
  76. }
  77. include template('diy:'.$file, NULL, $tpldirectory, NULL, $primaltplname);
  78. function category_get_wheresql($cat) {
  79. $wheresql = '';
  80. if(is_array($cat)) {
  81. $catid = $cat['catid'];
  82. if(!empty($cat['subs'])) {
  83. include_once libfile('function/portalcp');
  84. $subcatids = category_get_childids('portal', $catid);
  85. $subcatids[] = $catid;
  86. $wheresql = "at.catid IN (".dimplode($subcatids).")";
  87. } else {
  88. $wheresql = "at.catid='$catid'";
  89. }
  90. }
  91. $wheresql .= " AND at.status='0'";
  92. return $wheresql;
  93. }
  94. function category_get_list($cat, $wheresql, $page = 1, $perpage = 0) {
  95. global $_G;
  96. $cat['perpage'] = empty($cat['perpage']) ? 15 : $cat['perpage'];
  97. $cat['maxpages'] = empty($cat['maxpages']) ? 1000 : $cat['maxpages'];
  98. $perpage = intval($perpage);
  99. $page = intval($page);
  100. $perpage = empty($perpage) ? $cat['perpage'] : $perpage;
  101. $page = empty($page) ? 1 : min($page, $cat['maxpages']);
  102. $start = ($page-1)*$perpage;
  103. if($start<0) $start = 0;
  104. $list = array();
  105. $pricount = 0;
  106. $multi = '';
  107. $count = C::t('portal_article_title')->fetch_all_by_sql($wheresql, '', 0, 0, 1, 'at');
  108. if($count) {
  109. $query = C::t('portal_article_title')->fetch_all_by_sql($wheresql, 'ORDER BY at.dateline DESC', $start, $perpage, 0, 'at');
  110. foreach($query as $value) {
  111. $value['catname'] = $value['catid'] == $cat['catid'] ? $cat['catname'] : $_G['cache']['portalcategory'][$value['catid']]['catname'];
  112. $value['onerror'] = '';
  113. if($value['pic']) {
  114. $value['pic'] = pic_get($value['pic'], '', $value['thumb'], $value['remote'], 1, 1);
  115. }
  116. $value['dateline'] = dgmdate($value['dateline']);
  117. if($value['status'] == 0 || $value['uid'] == $_G['uid'] || $_G['adminid'] == 1) {
  118. $list[] = $value;
  119. } else {
  120. $pricount++;
  121. }
  122. }
  123. if(strpos($cat['caturl'], 'portal.php') === false) {
  124. $cat['caturl'] .= 'index.php';
  125. }
  126. $multi = multi($count, $perpage, $page, $cat['caturl'], $cat['maxpages']);
  127. }
  128. return $return = array('list'=>$list,'count'=>$count,'multi'=>$multi,'pricount'=>$pricount);
  129. }
  130. function category_get_list_more($cat, $wheresql, $hassub = true,$hasnew = true,$hashot = true) {
  131. global $_G;
  132. $data = array();
  133. $catid = $cat['catid'];
  134. $cachearr = array();
  135. if($hashot) $cachearr[] = 'portalhotarticle';
  136. if($hasnew) $cachearr[] = 'portalnewarticle';
  137. if($hassub) {
  138. foreach($cat['children'] as $childid) {
  139. $cachearr[] = 'subcate'.$childid;
  140. }
  141. }
  142. $allowmemory = memory('check');
  143. foreach ($cachearr as $key) {
  144. $cachekey = $key.$catid;
  145. $data[$key] = $allowmemory ? memory('get', $cachekey) : false;
  146. if($data[$key] === false) {
  147. $list = array();
  148. $sql = '';
  149. if($key == 'portalhotarticle') {
  150. $dateline = TIMESTAMP - 3600 * 24 * 90;
  151. $query = C::t('portal_article_count')->fetch_all_hotarticle($wheresql, $dateline);
  152. } elseif($key == 'portalnewarticle') {
  153. $query = C::t('portal_article_title')->fetch_all_by_sql($wheresql, 'ORDER BY at.dateline DESC', 0, 10, 0, 'at');
  154. } elseif(substr($key, 0, 7) == 'subcate') {
  155. $cacheid = intval(str_replace('subcate', '', $key));
  156. if(!empty($_G['cache']['portalcategory'][$cacheid])) {
  157. $where = '';
  158. if(!empty($_G['cache']['portalcategory'][$cacheid]['children']) && dimplode($_G['cache']['portalcategory'][$cacheid]['children'])) {
  159. $_G['cache']['portalcategory'][$cacheid]['children'][] = $cacheid;
  160. $where = 'at.catid IN ('.dimplode($_G['cache']['portalcategory'][$cacheid]['children']).')';
  161. } else {
  162. $where = 'at.catid='.$cacheid;
  163. }
  164. $where .= " AND at.status='0'";
  165. $query = C::t('portal_article_title')->fetch_all_by_sql($where, 'ORDER BY at.dateline DESC', 0, 10, 0, 'at');
  166. }
  167. }
  168. if($query) {
  169. foreach($query as $value) {
  170. $value['catname'] = $value['catid'] == $cat['catid'] ? $cat['catname'] : $_G['cache']['portalcategory'][$value['catid']]['catname'];
  171. if($value['pic']) $value['pic'] = pic_get($value['pic'], '', $value['thumb'], $value['remote'], 1, 1);
  172. $value['timestamp'] = $value['dateline'];
  173. $value['dateline'] = dgmdate($value['dateline']);
  174. $list[] = $value;
  175. }
  176. }
  177. $data[$key] = $list;
  178. if($allowmemory) {
  179. memory('set', $cachekey, $list, empty($list) ? 60 : 600);
  180. }
  181. }
  182. }
  183. return $data;
  184. }
  185. function article_title_style($value = array()) {
  186. $style = array();
  187. $highlight = '';
  188. if($value['highlight']) {
  189. $style = explode('|', $value['highlight']);
  190. $highlight = ' style="';
  191. $highlight .= $style[0] ? 'color: '.$style[0].';' : '';
  192. $highlight .= $style[1] ? 'font-weight: bold;' : '';
  193. $highlight .= $style[2] ? 'font-style: italic;' : '';
  194. $highlight .= $style[3] ? 'text-decoration: underline;' : '';
  195. $highlight .= '"';
  196. }
  197. return $highlight;
  198. }
  199. ?>