国内流行的内容管理系统(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.

201 lines
8.4KB

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