国内流行的内容管理系统(CMS)多端全媒体解决方案 https://www.dedebiz.com
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

213 lines
8.5KB

  1. <?php
  2. /**
  3. *
  4. * 高级搜索
  5. *
  6. * @version $Id: advancedsearch.php 1 15:38 2010年7月8日Z tianya $
  7. * @package DedeBIZ.Site
  8. * @copyright Copyright (c) 2022, DedeBIZ.COM
  9. * @license https://www.dedebiz.com/license
  10. * @link https://www.dedebiz.com
  11. */
  12. require_once(dirname(__FILE__)."/../include/common.inc.php");
  13. require_once(DEDEINC."/datalistcp.class.php");
  14. $timestamp = time();
  15. @session_start();
  16. //限制同时搜索数量
  17. $timelock = '../data/time.lock';
  18. if ($cfg_allsearch_limit < 1) {
  19. $cfg_allsearch_limit = 1;
  20. }
  21. if (file_exists($timelock)) {
  22. if ($timestamp - filemtime($timelock) < $cfg_allsearch_limit) {
  23. showmsg('服务器忙,请稍后搜索', '-1');
  24. exit();
  25. }
  26. }
  27. @touch($timelock, $timestamp);
  28. $mid = isset($mid) && is_numeric($mid) ? $mid : 0;
  29. $sqlhash = isset($sqlhash) && preg_match("/^[A-Za-z0-9]+$/", $sqlhash) ? $sqlhash : '';
  30. if ($mid == 0) {
  31. showmsg('参数不正确,高级自定义搜索必须指定模型id', 'javascript');
  32. exit();
  33. }
  34. $query = "SELECT maintable, mainfields, addontable, addonfields, template FROM #@__advancedsearch WHERE mid='$mid'";
  35. $searchinfo = $dsql->GetOne($query);
  36. if (!is_array($searchinfo)) {
  37. showmsg('自定义搜索模型不存在', '-1');
  38. exit();
  39. }
  40. $template = $searchinfo['template'] != '' ? $searchinfo['template'] : 'advancedsearch.htm';
  41. $sql = empty($_SESSION[$sqlhash]) ? '' : $_SESSION[$sqlhash];
  42. if (empty($sql)) {
  43. //主表字段处理
  44. $q = stripslashes($q);
  45. $q = preg_replace("#[\|\"\r\n\t%\*\?\(\)\$;,'%<>]#", " ", trim($q));
  46. if (($cfg_notallowstr != '' && preg_match("#".$cfg_notallowstr."#i", $q)) || ($cfg_replacestr != '' && preg_match("#".$cfg_replacestr."#i", $q))) {
  47. echo "您的信息中存在非法内容,被系统禁止<a href='javascript:history.go(-1)'>[返回]</a>";
  48. exit();
  49. }
  50. $q = addslashes($q);
  51. $iscommend = isset($iscommend) && is_numeric($iscommend) ? $iscommend : 0;
  52. $typeid = isset($typeid) && is_numeric($typeid) ? $typeid : 0;
  53. $typeid = max($typeid, 0);
  54. $includesons = isset($includesons) ? 1 : 0;
  55. $writer = isset($writer) ? trim($writer) : '';
  56. $source = isset($source) ? trim($source) : '';
  57. $startdate = isset($startdate) ? trim($startdate) : '';
  58. $enddate = isset($enddate) ? trim($enddate) : '';
  59. if ($startdate != '') $starttime = strtotime($startdate);
  60. else $starttime = 0;
  61. if ($enddate != '') $endtime = strtotime($enddate);
  62. else $endtime = 0;
  63. $where = ' WHERE main.arcrank>-1 ';
  64. if ($q != '') $where .= " AND main.title LIKE '%$q%' ";
  65. if ($iscommend == 1) $where .= " AND FIND_IN_SET('c', main.flag)>0 ";
  66. if (!empty($typeid)) {
  67. if ($includesons == 1) {
  68. $tids = TypeGetSunID($typeid, $dsql, '', $mid, TRUE);
  69. $where .= " AND main.typeid IN ($tids) ";
  70. } else {
  71. $where .= " AND main.typeid=$typeid ";
  72. }
  73. } else {
  74. $where .= " AND main.channel = $mid ";
  75. }
  76. if ($writer != '') {
  77. $writer = stripslashes($writer);
  78. $writer = preg_replace("#[\|\"\r\n\t%\*\?\(\)\$;,'%<>]#", "", trim($writer));
  79. $writer = addslashes($writer);
  80. $where .= " AND main.writer='$writer' ";
  81. }
  82. if ($source != '') {
  83. $source = stripslashes($source);
  84. $source = preg_replace("#[\|\"\r\n\t%\*\?\(\)\$;,'%<>]#", "", trim($source));
  85. $source = addslashes($source);
  86. $where .= " AND main.source='$source' ";
  87. }
  88. if ($starttime > 0) $where .= " AND main.senddate>$starttime ";
  89. if ($endtime > 0) $where .= " AND main.senddate<$endtime";
  90. $maintable = $searchinfo['maintable'];
  91. $addontable = $searchinfo['addontable'];
  92. $mainfields = $searchinfo['mainfields'];
  93. $addonfields = $searchinfo['addonfields'];
  94. $mainfieldsarr = explode(',', $mainfields);
  95. $addonfieldsarr = explode(',', $addonfields);
  96. array_pop($addonfieldsarr); //弹出
  97. $intarr = array('int', 'float');
  98. $textarr = array('textdata', 'textchar', 'text', 'htmltext', 'multitext');
  99. foreach ($addonfieldsarr as $addonfield) {
  100. $addonfieldarr = explode(':', $addonfield);
  101. $var = $addonfieldarr[0];
  102. $type = $addonfieldarr[1];
  103. if (in_array($type, $intarr)) {
  104. if (isset(${'start'.$var}) && trim(${'start'.$var}) != '') {
  105. ${'start'.$var} = trim(${'start'.$var});
  106. ${'start'.$var} = intval(${'start'.$var});
  107. $where .= " AND addon.$var>${'start' .$var} ";
  108. }
  109. if (isset(${'end'.$var}) && trim(${'end'.$var}) != '') {
  110. ${'end'.$var} = trim(${'end'.$var});
  111. ${'end'.$var} = intval(${'end'.$var});
  112. $where .= " AND addon.$var<${'end' .$var} ";
  113. }
  114. } elseif (in_array($type, $textarr)) {
  115. if (isset(${$var}) && trim(${$var}) != '') {
  116. ${$var} = stripslashes(${$var});
  117. ${$var} = preg_replace("#[\|\"\r\n\t%\*\?\(\)\$;,'%<>]#", "", trim(${$var}));
  118. ${$var} = addslashes(${$var});
  119. $where .= " AND addon.$var LIKE '%${$var}%'";
  120. }
  121. } elseif ($type == 'select') {
  122. ${$var} = stripslashes(${$var});
  123. ${$var} = preg_replace("#[\|\"\r\n\t%\*\?\(\)\$;,'%<>]#", "", trim(${$var}));
  124. ${$var} = addslashes(${$var});
  125. if (${$var} != '') {
  126. $where .= " AND addon.$var LIKE '${$var}'";
  127. }
  128. } elseif ($type == 'radio') {
  129. ${$var} = stripslashes(${$var});
  130. ${$var} = preg_replace("#[\|\"\r\n\t%\*\?\(\)\$;,'%<>]#", "", trim(${$var}));
  131. ${$var} = addslashes(${$var});
  132. if (${$var} != '') {
  133. $where .= " AND addon.$var LIKE '${$var}'";
  134. }
  135. } elseif ($type == 'checkbox') {
  136. if (is_array(${$var}) && !empty(${$var})) {
  137. foreach (${$var} as $tmpvar) {
  138. $tmpvar = trim($tmpvar);
  139. if ($tmpvar != '') {
  140. $tmpvar = stripslashes($tmpvar);
  141. $tmpvar = preg_replace("#[\|\"\r\n\t%\*\?\(\)\$;,'%<>]#", "", trim($tmpvar));
  142. $tmpvar = addslashes($tmpvar);
  143. $where .= " AND CONCAT(',',addon.$var, ',') LIKE '%,$tmpvar,%' ";
  144. }
  145. }
  146. }
  147. } elseif ($type == 'datetime') {
  148. ${'start'.$var} = trim(${'start'.$var});
  149. if (${'start'.$var} != '') {
  150. ${'start'.$var} = strtotime(${'start'.$var});
  151. } else {
  152. ${'start'.$var} = 0;
  153. }
  154. ${'end'.$var} = trim(${'end'.$var});
  155. if (${'end'.$var} != '') {
  156. ${'end'.$var} = strtotime(${'end'.$var});
  157. } else {
  158. ${'end'.$var} = 0;
  159. }
  160. }
  161. }
  162. $orderby = ' order by main.senddate desc ';
  163. if ($mid < -1) {
  164. $where = str_replace('main.', 'addon.', $where);
  165. $orderby = str_replace('main.', 'addon.', $orderby);
  166. $query = "SELECT addon.*, arctype.* FROM $addontable addon
  167. LEFT JOIN #@__arctype arctype ON arctype.id = addon.typeid
  168. $where $orderby";
  169. } else {
  170. $query = "SELECT main.id AS aid,main.*,main.description AS description1, type.*
  171. FROM $maintable main
  172. LEFT JOIN #@__arctype type ON type.id = main.typeid
  173. LEFT JOIN $addontable addon ON addon.aid = main.id
  174. $where $orderby";
  175. }
  176. $sql = $query;
  177. } else {
  178. $sql = urldecode($sql);
  179. $query = $sql;
  180. }
  181. $sql = urlencode($sql);
  182. //生成sql的唯一序列化字符串,并将sql语句记录到session中去
  183. $sqlhash = md5($sql);
  184. $_SESSION[$sqlhash] = $sql;
  185. $dlist = new DataListCP();
  186. $dlist->pageSize = 20;
  187. $dlist->SetParameter("hash", $sqlhash);
  188. $dlist->SetParameter("mid", $mid);
  189. if (file_exists(DEDEROOT."/templets/default/$template")) {
  190. $templatefile = DEDEROOT."/templets/default/$template";
  191. } else {
  192. $templatefile = DEDEROOT."/templets/default/advancedsearch.htm";
  193. }
  194. $dlist->SetTemplate($templatefile);
  195. $dlist->SetSource($query);
  196. require_once(DEDEINC."/channelunit.class.php");
  197. //获得一个指定档案的链接
  198. function GetArcUrl($aid, $typeid, $timetag, $title, $ismake = 0, $rank = 0, $namerule = '', $artdir = '', $money = 0)
  199. {
  200. return GetFileUrl($aid, $typeid, $timetag, $title, $ismake, $rank, $namerule, $artdir, $money);
  201. }
  202. $dlist->Display();