search_collection.php 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  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: search_collection.php 31371 2012-08-21 01:51:24Z chenmengshu $
  7. */
  8. if(!defined('IN_DISCUZ')) {
  9. exit('Access Denied');
  10. }
  11. define('NOROBOT', TRUE);
  12. require_once libfile('function/home');
  13. if(!$_G['setting']['search']['collection']['status']) {
  14. showmessage('search_collection_closed');
  15. }
  16. if($_G['adminid'] != 1 && !($_G['group']['allowsearch'] & 64)) {
  17. showmessage('group_nopermission', NULL, array('grouptitle' => $_G['group']['grouptitle']), array('login' => 1));
  18. }
  19. $_G['setting']['search']['collection']['searchctrl'] = intval($_G['setting']['search']['collection']['searchctrl']);
  20. $srchmod = 7;
  21. $cachelife_time = 300; // Life span for cache of searching in specified range of time
  22. $cachelife_text = 3600; // Life span for cache of text searching
  23. $srchtype = empty($_GET['srchtype']) ? '' : trim($_GET['srchtype']);
  24. $searchid = isset($_GET['searchid']) ? intval($_GET['searchid']) : 0;
  25. $srchtxt = $_GET['srchtxt'];
  26. $keyword = isset($srchtxt) ? dhtmlspecialchars(trim($srchtxt)) : '';
  27. if(!submitcheck('searchsubmit', 1)) {
  28. include template('search/collection');
  29. } else {
  30. $orderby = in_array($_GET['orderby'], array('follownum', 'threadnum', 'commentnum', 'dateline')) ? $_GET['orderby'] : 'dateline';
  31. $ascdesc = isset($_GET['ascdesc']) && $_GET['ascdesc'] == 'asc' ? 'asc' : 'desc';
  32. if(!empty($searchid)) {
  33. $page = max(1, intval($_GET['page']));
  34. $start_limit = ($page - 1) * $_G['tpp'];
  35. $index = C::t('common_searchindex')->fetch_by_searchid_srchmod($searchid, $srchmod);
  36. if(!$index) {
  37. showmessage('search_id_invalid');
  38. }
  39. $keyword = dhtmlspecialchars($index['keywords']);
  40. $keyword = $keyword != '' ? str_replace('+', ' ', $keyword) : '';
  41. $index['keywords'] = rawurlencode($index['keywords']);
  42. require_once libfile('function/discuzcode');
  43. $collectionlist = array();
  44. $maxcollection = $nowcollection = 0;
  45. $query = C::t('forum_collection')->fetch_all(explode(',', $index['ids']), $orderby, $ascdesc, $start_limit, $_G['tpp']);
  46. foreach($query as $value) {
  47. $value['lastupdate'] = dgmdate($value['lastupdate']);
  48. $value['shortdesc'] = cutstr(strip_tags(discuzcode($value['desc'])), 50);
  49. $value['name'] = bat_highlight($value['name'], $keyword);
  50. $collectionlist[$value['ctid']] = $value;
  51. }
  52. $multipage = multi($index['num'], $_G['tpp'], $page, "search.php?mod=collection&searchid=$searchid&orderby=$orderby&ascdesc=$ascdesc&searchsubmit=yes");
  53. $url_forward = 'search.php?mod=collection&'.$_SERVER['QUERY_STRING'];
  54. include template('search/collection');
  55. } else {
  56. $searchstring = 'collection|title|'.addslashes($srchtxt);
  57. $searchindex = array('id' => 0, 'dateline' => '0');
  58. foreach(C::t('common_searchindex')->fetch_all_search($_G['setting']['search']['collection']['searchctrl'], $_G['clientip'], $_G['uid'], $_G['timestamp'], $searchstring, $srchmod) as $index) {
  59. if($index['indexvalid'] && $index['dateline'] > $searchindex['dateline']) {
  60. $searchindex = array('id' => $index['searchid'], 'dateline' => $index['dateline']);
  61. break;
  62. } elseif($_G['adminid'] != '1' && $index['flood']) {
  63. showmessage('search_ctrl', 'search.php?mod=collection', array('searchctrl' => $_G['setting']['search']['collection']['searchctrl']));
  64. }
  65. }
  66. if($searchindex['id']) {
  67. $searchid = $searchindex['id'];
  68. } else {
  69. !($_G['group']['exempt'] & 2) && checklowerlimit('search');
  70. if(!$srchtxt && !$srchuid && !$srchuname) {
  71. dheader('Location: search.php?mod=collection');
  72. }
  73. if($_G['adminid'] != '1' && $_G['setting']['search']['collection']['maxspm']) {
  74. if(C::t('common_searchindex')->count_by_dateline($_G['timestamp'], $srchmod) >= $_G['setting']['search']['collection']['maxspm']) {
  75. showmessage('search_toomany', 'search.php?mod=collection', array('maxspm' => $_G['setting']['search']['collection']['maxspm']));
  76. }
  77. }
  78. $num = $ids = 0;
  79. $_G['setting']['search']['collection']['maxsearchresults'] = $_G['setting']['search']['collection']['maxsearchresults'] ? intval($_G['setting']['search']['collection']['maxsearchresults']) : 500;
  80. list($srchtxt, $srchtxtsql) = searchkey($keyword, "name LIKE '%{text}%' OR keyword LIKE '%{text}%'", true);
  81. $query = C::t('forum_collection')->fetch_ctid_by_searchkey($srchtxtsql, $_G['setting']['search']['collection']['maxsearchresults']);
  82. foreach($query as $collection) {
  83. $ids .= ','.$collection['ctid'];
  84. $num++;
  85. }
  86. unset($query);
  87. $keywords = str_replace('%', '+', $srchtxt);
  88. $expiration = TIMESTAMP + $cachelife_text;
  89. $searchid = C::t('common_searchindex')->insert(array(
  90. 'srchmod' => $srchmod,
  91. 'keywords' => $keywords,
  92. 'searchstring' => $searchstring,
  93. 'useip' => $_G['clientip'],
  94. 'uid' => $_G['uid'],
  95. 'dateline' => $_G['timestamp'],
  96. 'expiration' => $expiration,
  97. 'num' => $num,
  98. 'ids' => $ids
  99. ), true);
  100. !($_G['group']['exempt'] & 2) && updatecreditbyaction('search');
  101. }
  102. dheader("location: search.php?mod=collection&searchid=$searchid&searchsubmit=yes&kw=".urlencode($keyword));
  103. }
  104. }
  105. ?>