search_album.php 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  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_album.php 29236 2012-03-30 05:34:47Z 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']['album']['status']) {
  14. showmessage('search_album_closed');
  15. }
  16. if($_G['adminid'] != 1 && !($_G['group']['allowsearch'] & 8)) {
  17. showmessage('group_nopermission', NULL, array('grouptitle' => $_G['group']['grouptitle']), array('login' => 1));
  18. }
  19. $_G['setting']['search']['album']['searchctrl'] = intval($_G['setting']['search']['album']['searchctrl']);
  20. $srchmod = 4;
  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/album');
  29. } else {
  30. $orderby = in_array($_GET['orderby'], array('dateline', 'replies', 'views')) ? $_GET['orderby'] : 'lastpost';
  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. $albumlist = array();
  43. $maxalbum = $nowalbum = 0;
  44. $query = C::t('home_album')->fetch_all(explode(',', $index['ids']), 'updatetime', $start_limit, $_G['tpp']);
  45. foreach($query as $value) {
  46. if($value['friend'] != 4 && ckfriend($value['uid'], $value['friend'], $value['target_ids'])) {
  47. $value['pic'] = pic_cover_get($value['pic'], $value['picflag']);
  48. } elseif ($value['picnum']) {
  49. $value['pic'] = STATICURL.'image/common/nopublish.jpg';
  50. } else {
  51. $value['pic'] = '';
  52. }
  53. $value['albumname'] = bat_highlight($value['albumname'], $keyword);
  54. $albumlist[$value['albumid']] = $value;
  55. }
  56. $multipage = multi($index['num'], $_G['tpp'], $page, "search.php?mod=album&searchid=$searchid&orderby=$orderby&ascdesc=$ascdesc&searchsubmit=yes");
  57. $url_forward = 'search.php?mod=album&'.$_SERVER['QUERY_STRING'];
  58. include template('search/album');
  59. } else {
  60. $searchstring = 'album|title|'.addslashes($srchtxt);
  61. $searchindex = array('id' => 0, 'dateline' => '0');
  62. foreach(C::t('common_searchindex')->fetch_all_search($_G['setting']['search']['album']['searchctrl'], $_G['clientip'], $_G['uid'], $_G['timestamp'], $searchstring, $srchmod) as $index) {
  63. if($index['indexvalid'] && $index['dateline'] > $searchindex['dateline']) {
  64. $searchindex = array('id' => $index['searchid'], 'dateline' => $index['dateline']);
  65. break;
  66. } elseif($_G['adminid'] != '1' && $index['flood']) {
  67. showmessage('search_ctrl', 'search.php?mod=album', array('searchctrl' => $_G['setting']['search']['album']['searchctrl']));
  68. }
  69. }
  70. if($searchindex['id']) {
  71. $searchid = $searchindex['id'];
  72. } else {
  73. !($_G['group']['exempt'] & 2) && checklowerlimit('search');
  74. if(!$srchtxt && !$srchuid && !$srchuname) {
  75. dheader('Location: search.php?mod=album');
  76. }
  77. if($_G['adminid'] != '1' && $_G['setting']['search']['album']['maxspm']) {
  78. if(C::t('common_searchindex')->count_by_dateline($_G['timestamp'], $srchmod) >= $_G['setting']['search']['album']['maxspm']) {
  79. showmessage('search_toomany', 'search.php?mod=album', array('maxspm' => $_G['setting']['search']['album']['maxspm']));
  80. }
  81. }
  82. $num = $ids = 0;
  83. $_G['setting']['search']['album']['maxsearchresults'] = $_G['setting']['search']['album']['maxsearchresults'] ? intval($_G['setting']['search']['album']['maxsearchresults']) : 500;
  84. list($srchtxt, $srchtxtsql) = searchkey($keyword, "albumname LIKE '%{text}%'", true);
  85. $query = C::t('home_album')->fetch_albumid_by_searchkey($srchtxtsql, $_G['setting']['search']['album']['maxsearchresults']);
  86. foreach($query as $album) {
  87. $ids .= ','.$album['albumid'];
  88. $num++;
  89. }
  90. unset($query);
  91. $keywords = str_replace('%', '+', $srchtxt);
  92. $expiration = TIMESTAMP + $cachelife_text;
  93. $searchid = C::t('common_searchindex')->insert(array(
  94. 'srchmod' => $srchmod,
  95. 'keywords' => $keywords,
  96. 'searchstring' => $searchstring,
  97. 'useip' => $_G['clientip'],
  98. 'uid' => $_G['uid'],
  99. 'dateline' => $_G['timestamp'],
  100. 'expiration' => $expiration,
  101. 'num' => $num,
  102. 'ids' => $ids
  103. ), true);
  104. !($_G['group']['exempt'] & 2) && updatecreditbyaction('search');
  105. }
  106. dheader("location: search.php?mod=album&searchid=$searchid&searchsubmit=yes&kw=".urlencode($keyword));
  107. }
  108. }
  109. ?>