search.php 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405
  1. <?php
  2. define('IN_SMT', true);
  3. define('CURSCRIPT', 'search');
  4. define('IN_MYMPS', true);
  5. require_once dirname(__FILE__) . '/include/global.php';
  6. require_once dirname(__FILE__) . '/data/config.php';
  7. require_once MYMPS_DATA . '/config.db.php';
  8. require_once MYMPS_INC . '/db.class.php';
  9. ifsiteopen();
  10. $catid = isset($catid) ? intval($catid) : '';
  11. $areaid = isset($areaid) ? intval($areaid) : '';
  12. $posttime = isset($posttime) ? intval($posttime) : '';
  13. $tel = isset($tel) ? checkhtml($tel) : '';
  14. $keywords = checkhtml($keywords);
  15. if (preg_match('/from|script|or|invalid/i', $keywords)) {
  16. $keywords = '';
  17. }
  18. $keywords = str_replace(array('/', '?'), array(' ', ' '), $keywords);
  19. $keywords = isset($keywords) ? trim(preg_replace('/(\\s+)/', ' ', $keywords)) : '';
  20. $mod = isset($mod) ? trim($mod) : '';
  21. if ($keywords == '请输入关键词搜索') {
  22. $keywords = $_GET['keywords'] = '';
  23. }
  24. if ($mod == 'corp') {
  25. $mod = 'store';
  26. }
  27. !in_array($mod, array('information', 'store', 'coupon', 'group', 'news', 'goods')) && ($mod = 'information');
  28. $pluginsettings = read_static_cache('plugin');
  29. $allowplugin = array();
  30. if (is_array($pluginsettings)) {
  31. foreach ($pluginsettings as $k => $v) {
  32. if ($v['disable'] != 1) {
  33. $allowplugin[$k]['flag'] = $v['flag'];
  34. $allowplugin[$k]['name'] = $v['name'];
  35. }
  36. }
  37. }
  38. $sql = $search = $where = $cat_children = $allow_identifier = '';
  39. switch ($mod) {
  40. case 'information':
  41. $search['page_title'] = ($keywords != '' ? $keywords . ' - ' : '') . '信息搜索 - ' . $mymps_global['SiteName'];
  42. if ($keywords != '' || $tel != '') {
  43. require MYMPS_DATA . '/info_posttime.php';
  44. if ($catid) {
  45. $modid = $db->getOne('SELECT modid FROM `' . $db_mymps . 'category` WHERE catid = \'' . $catid . '\'');
  46. $cat_children = get_children($catid);
  47. $allow_identifier = allow_identifier();
  48. $allow_identifier = $allow_identifier[$modid]['identifier'];
  49. $mymps_extra_model = mod_identifier();
  50. $extra_model = $mymps_extra_model[$modid];
  51. $sq = $s = '';
  52. if (1 < $modid && is_array($allow_identifier)) {
  53. $s = 'LEFT JOIN `' . $db_mymps . 'information_' . $modid . '` AS g ON a.id = g.id';
  54. foreach (${$_request} as $key => $val) {
  55. if (in_array($key, $allow_identifier) && !empty(${$key})) {
  56. $val = intval($val);
  57. $where .= ' AND g.`' . $key . '` = \'' . $val . '\' ';
  58. }
  59. }
  60. }
  61. }
  62. if (is_array($keyword = explode(' ', $keywords))) {
  63. $or = '';
  64. $sqlkeywords = '';
  65. foreach ($keyword as $k => $v) {
  66. $sqlkeywords .= ' ' . $or . ' a.title LIKE \'%' . $v . '%\'';
  67. $or = 'OR';
  68. }
  69. $where .= ' AND (' . $sqlkeywords . ')';
  70. }
  71. $where .= $areaid != '' ? ' AND a.areaid = \'' . $areaid . '\'' : '';
  72. $where .= $tel != '' ? ' AND a.tel LIKE \'%' . $tel . '%\'' : '';
  73. $where .= $catid != '' ? ' AND ' . $cat_children : '';
  74. $where .= $posttime != '' ? 'AND a.begintime >= (' . $timestamp . '-' . $posttime . '*3600*24)' : '';
  75. $where .= 'AND (a.info_level = \'1\' OR a.info_level = \'2\')';
  76. $search['rows_num'] = $rows_num = $db->getOne('SELECT COUNT(a.id) FROM `' . $db_mymps . 'information` AS a LEFT JOIN `' . $db_mymps . 'category` AS c ON a.catid = c.catid ' . $s . ' WHERE 1 ' . $where);
  77. $param = $catid != '' && is_array($allow_identifier) ? setParam(array_merge(array('part', 'keywords', 'catid', 'areaid', 'posttime', 'tel'), $allow_identifier)) : setParam(array('mod', 'keywords', 'catid', 'areaid', 'posttime', 'tel'));
  78. $searchresult = page1('SELECT a.id,a.areaid,a.begintime,a.title,a.content,a.ismember,a.contact_who,a.begintime,a.catid,c.catname,a.dir_typename FROM `' . $db_mymps . 'information` AS a LEFT JOIN `' . $db_mymps . 'category` AS c ON a.catid = c.catid ' . $s . ' WHERE 1 ' . $where . ' ORDER BY a.id DESC');
  79. $ids = '';
  80. foreach ($searchresult as $k => $val) {
  81. $result['id'] = $val['id'];
  82. $result['uri'] = Rewrite('info', array('id' => $val['id'], 'dir_typename' => $val['dir_typename']));
  83. $result['begintime'] = $val['begintime'];
  84. $result['title'] = HighLight($val['title'], $keywords);
  85. $result['content'] = HighLight(cutstr(clear_html($val['content']), 180), $keywords);
  86. $result['poster'] = $val['ismember'] == 1 ? '<a target="black" href=' . Rewrite('space', array('userid' => $val['userid'])) . $val['userid'] . '</a>' : $val['contact_who'] ? $val['contact_who'] : '游客';
  87. $result['catname'] = HighLight($val['catname'], $keywords);
  88. $result['caturi'] = Rewrite('category', array('catid' => $val['catid'], 'dir_typename' => $val['dir_typename']));
  89. $search['result'][$val['id']] = $result;
  90. $ids .= $val['id'] . ',';
  91. }
  92. if ($idin = substr($ids, 0, -1)) {
  93. $idin = $idin = $idin ? ' AND a.id IN (' . $idin . ') ' : '';
  94. }
  95. $search['pagination'] = page2();
  96. if ($search['result'] && $catid && $idin && is_array($allow_identifier)) {
  97. $des = get_info_option_array();
  98. $extra = $db->getAll('SELECT a.* FROM `' . $db_mymps . 'information_' . $modid . '` AS a WHERE 1 ' . $idin);
  99. foreach ($extra as $k => $v) {
  100. unset($v['iid']);
  101. unset($v['content']);
  102. foreach ($v as $u => $w) {
  103. $g = get_info_option_titval($des[$u], $w);
  104. if ($u != 'id' && !is_numeric($u)) {
  105. $search['result'][$v[id]]['extra'][$u] = $g['value'];
  106. }
  107. }
  108. }
  109. }
  110. $posttime_select = GetInfoPostTime($posttime);
  111. $catoption = get_categories_tree(0, 'category');
  112. $select_where_option = cat_list('area', 0, $areaid);
  113. }
  114. break;
  115. case 'store':
  116. $search['page_title'] = ($keywords != '' ? $keywords . ' - ' : '') . '商家搜索 - ' . $mymps_global['SiteName'];
  117. if ($keywords != '') {
  118. $document_domain = str_replace('http://www.', '', $mymps_global['SiteUrl']);
  119. if ($keywords != '') {
  120. if (is_array($keyword = explode(' ', $keywords))) {
  121. $or = '';
  122. $sqlkeywords = '';
  123. foreach ($keyword as $k => $v) {
  124. $sqlkeywords .= ' ' . $or . ' a.tname LIKE \'%' . $v . '%\' OR a.introduce LIKE \'%' . $v . '%\' OR a.userid LIKE \'%' . $v . '%\'';
  125. $or = 'OR';
  126. }
  127. $where .= ' AND (' . $sqlkeywords . ')';
  128. }
  129. $where .= !empty($catid) ? ' AND b.catid IN(' . get_corp_children($catid) . ') ' : '';
  130. $where .= !empty($areaid) ? ' AND a.areaid = \'' . $areaid . '\' ' : '';
  131. $where .= ' AND a.if_corp = \'1\'';
  132. $sql = empty($catid) ? 'SELECT a.* FROM `' . $db_mymps . 'member` AS a WHERE 1 ' . $where . ' ORDER BY a.jointime DESC' : 'SELECT a.* FROM `' . $db_mymps . 'member` AS a LEFT JOIN `' . $db_mymps . 'member_category` AS b ON a.userid = b.userid WHERE 1 ' . $where . ' ORDER BY a.jointime DESC';
  133. $count_sql = empty($catid) ? 'SELECT COUNT(a.id) FROM `' . $db_mymps . 'member` AS a WHERE 1 ' . $where : 'SELECT COUNT(b.id) FROM `' . $db_mymps . 'member` AS a LEFT JOIN ' . $db_mymps . 'member_category AS b ON a.userid = b.userid WHERE 1 ' . $where;
  134. $search['rows_num'] = $rows_num = $db->getOne($count_sql);
  135. $param = setParam(array('mod', 'catid', 'areaid', 'keywords'));
  136. if (is_array($res = page1($sql))) {
  137. foreach ($res as $key => $val) {
  138. $arr['userid'] = $val['userid'];
  139. $arr['tel'] = $val['tel'] ? $val['tel'] : '尚未填写电话信息';
  140. $arr['address'] = $val['address'] ? $val['address'] : '尚未填写地址信息';
  141. $arr['tname'] = $val['tname'] ? $val['tname'] : $val['userid'];
  142. $arr['prelogo'] = $val['prelogo'] ? $val['prelogo'] : '/images/nophoto.jpg';
  143. $arr['tname'] = HighLight($val['tname'] ? $val['tname'] : $val['userid'], $keyword ? $keyword : $keywords);
  144. $arr['uri'] = Rewrite('store', array('uid' => $val['id']));
  145. $arr['uri_aboutus'] = Rewrite('store', array('uid' => $val['id'], 'part' => 'about'));
  146. $arr['uri_comment'] = Rewrite('store', array('uid' => $val['id'], 'part' => 'comment'));
  147. $arr['uri_album'] = Rewrite('store', array('uid' => $val['id'], 'part' => 'album'));
  148. $search['result'][] = $arr;
  149. }
  150. }
  151. $search['pagination'] = page2();
  152. }
  153. $catoption = get_corp_tree(0, 'corp');
  154. $select_where_option = cat_list('area', 0, $areaid);
  155. }
  156. break;
  157. case 'news':
  158. if ($keywords != '') {
  159. !ifplugin('news') && exit('管理员已禁用或未安装新闻插件...');
  160. $catoption = cat_list('channel', 0, 0, false, 1);
  161. $area_list = cat_list('area', 0, $areaid);
  162. if ($keywords != '') {
  163. if (is_array($keyword = explode(' ', $keywords))) {
  164. $or = '';
  165. $sqlkeywords = '';
  166. foreach ($keyword as $k => $v) {
  167. $sqlkeywords .= ' ' . $or . ' n.title LIKE \'%' . $v . '%\' OR n.content LIKE \'%' . $v . '%\'';
  168. $or = 'OR';
  169. }
  170. $where .= ' AND (' . $sqlkeywords . ')';
  171. }
  172. $where .= !empty($catid) ? ' AND n.catid IN (' . get_cat_children($catid, 'channel') . ')' : '';
  173. $sql = 'SELECT n.*,c.catname,c.html_dir FROM `' . $db_mymps . 'news` AS n LEFT JOIN `' . $db_mymps . 'channel` AS c ON n.catid = c.catid WHERE 1 ' . $where . ' ORDER BY n.id DESC';
  174. $search['rows_num'] = $rows_num = $db->getOne('SELECT COUNT(n.id) FROM `' . $db_mymps . 'news` AS n WHERE 1 ' . $where);
  175. $param = setParam(array('mod', 'catid', 'keywords'));
  176. $searchresult = page1($sql);
  177. foreach ($searchresult as $k => $val) {
  178. $result['id'] = $val['id'];
  179. $result['hit'] = $val['hit'];
  180. $result['uri'] = Rewrite('news', array('id' => $val['id'], 'html_path' => $val['html_path']));
  181. $result['begintime'] = $val['begintime'];
  182. $result['title'] = HighLight($val['title'], $keyword ? $keyword : $keywords);
  183. $result['content'] = HighLight(cutstr(clear_html($val['content']), 300), $keyword ? $keyword : $keywords);
  184. $result['catname'] = $val['catname'];
  185. $result['caturi'] = Rewrite('news', array('catid' => $val['catid'], 'html_dir' => $val['html_dir']));
  186. $search['result'][] = $result;
  187. }
  188. $search['pagination'] = page2();
  189. }
  190. }
  191. $search['page_title'] = ($keywords != '' ? $keywords . ' - ' : '') . '网站新闻搜索 - ' . $mymps_global['SiteName'];
  192. break;
  193. case 'group':
  194. if ($keywords != '') {
  195. require_once MYMPS_ROOT . '/plugin/group/include/functions.php';
  196. $group_class = get_group_class();
  197. $catoption = $group_class;
  198. $select_where_option = cat_list('area', 0, $areaid);
  199. require_once MYMPS_DATA . '/grouplevel.inc.php';
  200. if ($keywords != '') {
  201. $where = 'WHERE glevel > \'0\'';
  202. if (is_array($keyword = explode(' ', $keywords))) {
  203. $or = '';
  204. $sqlkeywords = '';
  205. foreach ($keyword as $k => $v) {
  206. $sqlkeywords .= ' ' . $or . ' gname LIKE \'%' . $v . '%\'';
  207. $or = 'OR';
  208. }
  209. $where .= ' AND (' . $sqlkeywords . ')';
  210. }
  211. if ($cate_id) {
  212. $where .= ' AND cate_id = \'' . $cate_id . '\'';
  213. }
  214. if ($areaid) {
  215. $where .= ' AND areaid = \'' . $areaid . '\'';
  216. }
  217. $search['rows_num'] = $rows_num = $db->getOne('SELECT COUNT(groupid) FROM `' . $db_mymps . 'group` ' . $where);
  218. $param = setParam(array('mod', 'cate_id', 'areaid', 'keywords'));
  219. $group = page1('SELECT * FROM `' . $db_mymps . 'group` ' . $where . ' ORDER BY displayorder DESC');
  220. foreach ($group as $k => $v) {
  221. $result['groupid'] = $v['groupid'];
  222. $result['gname'] = $v['gname'];
  223. $result['des'] = clear_html($v['des']);
  224. $result['enddate'] = $v['enddate'];
  225. $result['meetdate'] = $v['meetdate'];
  226. $result['gaddress'] = $v['gaddress'];
  227. $result['glevel'] = $v['glevel'];
  228. $result['signintotal'] = $v['signintotal'];
  229. $result['commenturl'] = $v['commenturl'];
  230. $result['pre_picture'] = $v['pre_picture'];
  231. $result['uri'] = plugin_url('group', array('id' => $v['groupid']));
  232. $search['result'][] = $result;
  233. }
  234. $search['pagination'] = page2();
  235. }
  236. }
  237. $search['page_title'] = ($keywords != '' ? $keywords . ' - ' : '') . '团购活动搜索 - ' . $mymps_global['SiteName'];
  238. break;
  239. case 'coupon':
  240. if ($keywords != '') {
  241. require_once MYMPS_ROOT . '/plugin/coupon/include/functions.php';
  242. $coupon_class = get_coupon_class();
  243. $catoption = $coupon_class;
  244. $select_where_option = cat_list('area', 0, $areaid);
  245. if ($keywords != '') {
  246. $where = 'WHERE status = \'1\' AND grade > \'0\'';
  247. if (is_array($keyword = explode(' ', $keywords))) {
  248. $or = '';
  249. $sqlkeywords = '';
  250. foreach ($keyword as $k => $v) {
  251. $sqlkeywords .= ' ' . $or . ' title LIKE \'%' . $v . '%\'';
  252. $or = 'OR';
  253. }
  254. $where .= ' AND (' . $sqlkeywords . ')';
  255. }
  256. if ($cate_id) {
  257. $where .= ' AND cate_id = \'' . $cate_id . '\'';
  258. }
  259. if ($areaid) {
  260. $where .= ' AND areaid = \'' . $areaid . '\'';
  261. }
  262. $search['rows_num'] = $rows_num = $db->getOne('SELECT count(id) FROM ' . $db_mymps . 'coupon ' . $where);
  263. $param = setParam(array('mod', 'cate_id', 'areaid', 'keywords'));
  264. $coupon = page1('SELECT * FROM `' . $db_mymps . 'coupon` ' . $where . ' ORDER BY begindate DESC');
  265. foreach ($coupon as $k => $v) {
  266. $result['id'] = $v['id'];
  267. $result['title'] = $v['title'];
  268. $result['des'] = $v['des'];
  269. $result['enddate'] = $v['enddate'];
  270. $result['begindate'] = $v['begindate'];
  271. $result['prints'] = $v['prints'];
  272. $result['pre_picture'] = $v['pre_picture'];
  273. $result['sup'] = $v['sup'];
  274. $result['uri'] = plugin_url('coupon', array('id' => $v['id']));
  275. $search['result'][] = $result;
  276. }
  277. $search['pagination'] = page2();
  278. }
  279. }
  280. $search['page_title'] = ($keywords != '' ? $keywords . ' - ' : '') . '优惠券搜索 - ' . $mymps_global['SiteName'];
  281. break;
  282. case 'goods':
  283. if ($keywords != '') {
  284. require_once MYMPS_ROOT . '/plugin/goods/include/functions.php';
  285. $goods_class = goods_category_tree(0);
  286. $catoption = $goods_class;
  287. $area_list = cat_list('area', 0, $areaid);
  288. if ($keywords != '') {
  289. $where = 'WHERE onsale = \'1\'';
  290. if (is_array($keyword = explode(' ', $keywords))) {
  291. $or = '';
  292. $sqlkeywords = '';
  293. foreach ($keyword as $k => $v) {
  294. $sqlkeywords .= ' ' . $or . ' goodsname LIKE \'%' . $v . '%\'';
  295. $or = 'OR';
  296. }
  297. $where .= ' AND (' . $sqlkeywords . ')';
  298. }
  299. if ($catid) {
  300. $where .= ' AND catid IN (' . mymps_get_goods_children($catid) . ')';
  301. }
  302. if ($areaid) {
  303. $where .= ' AND areaid = \'' . $areaid . '\'';
  304. }
  305. $search['rows_num'] = $rows_num = $db->getOne('SELECT COUNT(goodsid) FROM `' . $db_mymps . 'goods` ' . $where);
  306. $param = setParam(array('mod', 'cate_id', 'areaid', 'keywords'));
  307. $goods = page1('SELECT * FROM `' . $db_mymps . 'goods` ' . $where . ' ORDER BY dateline DESC', 16);
  308. foreach ($goods as $k => $v) {
  309. $result['goodsid'] = $v['goodsid'];
  310. $result['goodsname'] = $v['goodsname'];
  311. $result['nowprice'] = $v['nowprice'];
  312. $result['pre_picture'] = $v['pre_picture'] ? $v['pre_picture'] : $mymps_global['SiteUrl'] . '/images/nophoto.gif';
  313. $result['uri'] = plugin_url('goods', array('id' => $v['goodsid']));
  314. $search['result'][] = $result;
  315. }
  316. $search['pagination'] = page2();
  317. }
  318. }
  319. $search['page_title'] = ($keywords != '' ? $keywords . ' - ' : '') . '商品搜索 - ' . $mymps_global['SiteName'];
  320. break;
  321. }
  322. $mtime = explode(' ', microtime());
  323. $totaltime = number_format($mtime[1] + $mtime[0] - $mymps_starttime, 6);
  324. $sitedebug = 'Processed in ' . $totaltime . ' second(s) , ' . $db->query_num . ' queries';
  325. $search['keywords'] = $keywords;
  326. $search['tel'] = $tel;
  327. include $keywords || $tel ? mymps_tpl(CURSCRIPT . '_' . $mod) : mymps_tpl('search_index');
  328. is_object($db) && $db->Close();
  329. ?>