PageRenderTime 43ms CodeModel.GetById 13ms RepoModel.GetById 1ms app.codeStats 0ms

/web raovat.vn php/az24/source/module/search/search_blog.php

https://gitlab.com/phamngsinh/baitaplon_sinhvien
PHP | 158 lines | 111 code | 41 blank | 6 comment | 39 complexity | ee76cd01c816c1bd605d4117a954e24c MD5 | raw file
  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_blog.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']['blog']['status']) {
  14. showmessage('search_blog_closed');
  15. }
  16. if($_G['adminid'] != 1 && !($_G['group']['allowsearch'] & 4)) {
  17. showmessage('group_nopermission', NULL, array('grouptitle' => $_G['group']['grouptitle']), array('login' => 1));
  18. }
  19. $_G['setting']['search']['blog']['searchctrl'] = intval($_G['setting']['search']['blog']['searchctrl']);
  20. $srchmod = 3;
  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/blog');
  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. $bloglist = array();
  43. $pricount = 0;
  44. $blogidarray = explode(',', $index['ids']);
  45. $data_blog = C::t('home_blog')->fetch_all($blogidarray, 'dateline', 'DESC', $start_limit, $_G['tpp']);
  46. $data_blogfield = C::t('home_blogfield')->fetch_all($blogidarray);
  47. foreach($data_blog as $curblogid => $value) {
  48. $result = array_merge($result, (array)$data_blogfield[$curblogid]);
  49. if(ckfriend($value['uid'], $value['friend'], $value['target_ids']) && ($value['status'] == 0 || $value['uid'] == $_G['uid'] || $_G['adminid'] == 1)) {
  50. if($value['friend'] == 4) {
  51. $value['message'] = $value['pic'] = '';
  52. } else {
  53. $value['message'] = bat_highlight($value['message'], $keyword);
  54. $value['message'] = getstr($value['message'], 255, 0, 0, 0, -1);
  55. }
  56. $value['subject'] = bat_highlight($value['subject'], $keyword);
  57. $value['dateline'] = dgmdate($value['dateline']);
  58. $value['pic'] = pic_cover_get($value['pic'], $value['picflag']);
  59. $bloglist[] = $value;
  60. } else {
  61. $pricount++;
  62. }
  63. }
  64. $multipage = multi($index['num'], $_G['tpp'], $page, "search.php?mod=blog&searchid=$searchid&orderby=$orderby&ascdesc=$ascdesc&searchsubmit=yes");
  65. $url_forward = 'search.php?mod=blog&'.$_SERVER['QUERY_STRING'];
  66. include template('search/blog');
  67. } else {
  68. $searchstring = 'blog|title|'.addslashes($srchtxt);
  69. $searchindex = array('id' => 0, 'dateline' => '0');
  70. foreach(C::t('common_searchindex')->fetch_all_search($_G['setting']['search']['blog']['searchctrl'], $_G['clientip'], $_G['uid'], $_G['timestamp'], $searchstring, $srchmod) as $index) {
  71. if($index['indexvalid'] && $index['dateline'] > $searchindex['dateline']) {
  72. $searchindex = array('id' => $index['searchid'], 'dateline' => $index['dateline']);
  73. break;
  74. } elseif($_G['adminid'] != '1' && $index['flood']) {
  75. showmessage('search_ctrl', 'search.php?mod=blog', array('searchctrl' => $_G['setting']['search']['blog']['searchctrl']));
  76. }
  77. }
  78. if($searchindex['id']) {
  79. $searchid = $searchindex['id'];
  80. } else {
  81. !($_G['group']['exempt'] & 2) && checklowerlimit('search');
  82. if(!$srchtxt && !$srchuid && !$srchuname) {
  83. dheader('Location: search.php?mod=blog');
  84. }
  85. if($_G['adminid'] != '1' && $_G['setting']['search']['blog']['maxspm']) {
  86. if(C::t('common_searchindex')->count_by_dateline($_G['timestamp'], $srchmod) >= $_G['setting']['search']['blog']['maxspm']) {
  87. showmessage('search_toomany', 'search.php?mod=blog', array('maxspm' => $_G['setting']['search']['blog']['maxspm']));
  88. }
  89. }
  90. $num = $ids = 0;
  91. $_G['setting']['search']['blog']['maxsearchresults'] = $_G['setting']['search']['blog']['maxsearchresults'] ? intval($_G['setting']['search']['blog']['maxsearchresults']) : 500;
  92. list($srchtxt, $srchtxtsql) = searchkey($keyword, "subject LIKE '%{text}%'", true);
  93. $query = C::t('home_blog')->fetch_blogid_by_subject($keyword, $_G['setting']['search']['blog']['maxsearchresults']);
  94. foreach($query as $blog) {
  95. $ids .= ','.$blog['blogid'];
  96. $num++;
  97. }
  98. unset($query);
  99. $keywords = str_replace('%', '+', $srchtxt);
  100. $expiration = TIMESTAMP + $cachelife_text;
  101. $searchid = C::t('common_searchindex')->insert(array(
  102. 'srchmod' => $srchmod,
  103. 'keywords' => $keywords,
  104. 'searchstring' => $searchstring,
  105. 'useip' => $_G['clientip'],
  106. 'uid' => $_G['uid'],
  107. 'dateline' => $_G['timestamp'],
  108. 'expiration' => $expiration,
  109. 'num' => $num,
  110. 'ids' => $ids
  111. ), true);
  112. !($_G['group']['exempt'] & 2) && updatecreditbyaction('search');
  113. }
  114. dheader("location: search.php?mod=blog&searchid=$searchid&searchsubmit=yes&kw=".urlencode($keyword));
  115. }
  116. }
  117. ?>