| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405 |
- <?php
- define('IN_SMT', true);
- define('CURSCRIPT', 'search');
- define('IN_MYMPS', true);
- require_once dirname(__FILE__) . '/include/global.php';
- require_once dirname(__FILE__) . '/data/config.php';
- require_once MYMPS_DATA . '/config.db.php';
- require_once MYMPS_INC . '/db.class.php';
- ifsiteopen();
- $catid = isset($catid) ? intval($catid) : '';
- $areaid = isset($areaid) ? intval($areaid) : '';
- $posttime = isset($posttime) ? intval($posttime) : '';
- $tel = isset($tel) ? checkhtml($tel) : '';
- $keywords = checkhtml($keywords);
- if (preg_match('/from|script|or|invalid/i', $keywords)) {
- $keywords = '';
- }
- $keywords = str_replace(array('/', '?'), array(' ', ' '), $keywords);
- $keywords = isset($keywords) ? trim(preg_replace('/(\\s+)/', ' ', $keywords)) : '';
- $mod = isset($mod) ? trim($mod) : '';
- if ($keywords == '请输入关键词搜索') {
- $keywords = $_GET['keywords'] = '';
- }
- if ($mod == 'corp') {
- $mod = 'store';
- }
- !in_array($mod, array('information', 'store', 'coupon', 'group', 'news', 'goods')) && ($mod = 'information');
- $pluginsettings = read_static_cache('plugin');
- $allowplugin = array();
- if (is_array($pluginsettings)) {
- foreach ($pluginsettings as $k => $v) {
- if ($v['disable'] != 1) {
- $allowplugin[$k]['flag'] = $v['flag'];
- $allowplugin[$k]['name'] = $v['name'];
- }
- }
- }
- $sql = $search = $where = $cat_children = $allow_identifier = '';
- switch ($mod) {
- case 'information':
- $search['page_title'] = ($keywords != '' ? $keywords . ' - ' : '') . '信息搜索 - ' . $mymps_global['SiteName'];
- if ($keywords != '' || $tel != '') {
- require MYMPS_DATA . '/info_posttime.php';
- if ($catid) {
- $modid = $db->getOne('SELECT modid FROM `' . $db_mymps . 'category` WHERE catid = \'' . $catid . '\'');
- $cat_children = get_children($catid);
- $allow_identifier = allow_identifier();
- $allow_identifier = $allow_identifier[$modid]['identifier'];
- $mymps_extra_model = mod_identifier();
- $extra_model = $mymps_extra_model[$modid];
- $sq = $s = '';
- if (1 < $modid && is_array($allow_identifier)) {
- $s = 'LEFT JOIN `' . $db_mymps . 'information_' . $modid . '` AS g ON a.id = g.id';
- foreach (${$_request} as $key => $val) {
- if (in_array($key, $allow_identifier) && !empty(${$key})) {
- $val = intval($val);
- $where .= ' AND g.`' . $key . '` = \'' . $val . '\' ';
- }
- }
- }
- }
- if (is_array($keyword = explode(' ', $keywords))) {
- $or = '';
- $sqlkeywords = '';
- foreach ($keyword as $k => $v) {
- $sqlkeywords .= ' ' . $or . ' a.title LIKE \'%' . $v . '%\'';
- $or = 'OR';
- }
- $where .= ' AND (' . $sqlkeywords . ')';
- }
- $where .= $areaid != '' ? ' AND a.areaid = \'' . $areaid . '\'' : '';
- $where .= $tel != '' ? ' AND a.tel LIKE \'%' . $tel . '%\'' : '';
- $where .= $catid != '' ? ' AND ' . $cat_children : '';
- $where .= $posttime != '' ? 'AND a.begintime >= (' . $timestamp . '-' . $posttime . '*3600*24)' : '';
- $where .= 'AND (a.info_level = \'1\' OR a.info_level = \'2\')';
- $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);
- $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'));
- $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');
- $ids = '';
- foreach ($searchresult as $k => $val) {
- $result['id'] = $val['id'];
- $result['uri'] = Rewrite('info', array('id' => $val['id'], 'dir_typename' => $val['dir_typename']));
- $result['begintime'] = $val['begintime'];
- $result['title'] = HighLight($val['title'], $keywords);
- $result['content'] = HighLight(cutstr(clear_html($val['content']), 180), $keywords);
- $result['poster'] = $val['ismember'] == 1 ? '<a target="black" href=' . Rewrite('space', array('userid' => $val['userid'])) . $val['userid'] . '</a>' : $val['contact_who'] ? $val['contact_who'] : '游客';
- $result['catname'] = HighLight($val['catname'], $keywords);
- $result['caturi'] = Rewrite('category', array('catid' => $val['catid'], 'dir_typename' => $val['dir_typename']));
- $search['result'][$val['id']] = $result;
- $ids .= $val['id'] . ',';
- }
- if ($idin = substr($ids, 0, -1)) {
- $idin = $idin = $idin ? ' AND a.id IN (' . $idin . ') ' : '';
- }
- $search['pagination'] = page2();
- if ($search['result'] && $catid && $idin && is_array($allow_identifier)) {
- $des = get_info_option_array();
- $extra = $db->getAll('SELECT a.* FROM `' . $db_mymps . 'information_' . $modid . '` AS a WHERE 1 ' . $idin);
- foreach ($extra as $k => $v) {
- unset($v['iid']);
- unset($v['content']);
- foreach ($v as $u => $w) {
- $g = get_info_option_titval($des[$u], $w);
- if ($u != 'id' && !is_numeric($u)) {
- $search['result'][$v[id]]['extra'][$u] = $g['value'];
- }
- }
- }
- }
- $posttime_select = GetInfoPostTime($posttime);
- $catoption = get_categories_tree(0, 'category');
- $select_where_option = cat_list('area', 0, $areaid);
- }
- break;
- case 'store':
- $search['page_title'] = ($keywords != '' ? $keywords . ' - ' : '') . '商家搜索 - ' . $mymps_global['SiteName'];
- if ($keywords != '') {
- $document_domain = str_replace('http://www.', '', $mymps_global['SiteUrl']);
- if ($keywords != '') {
- if (is_array($keyword = explode(' ', $keywords))) {
- $or = '';
- $sqlkeywords = '';
- foreach ($keyword as $k => $v) {
- $sqlkeywords .= ' ' . $or . ' a.tname LIKE \'%' . $v . '%\' OR a.introduce LIKE \'%' . $v . '%\' OR a.userid LIKE \'%' . $v . '%\'';
- $or = 'OR';
- }
- $where .= ' AND (' . $sqlkeywords . ')';
- }
- $where .= !empty($catid) ? ' AND b.catid IN(' . get_corp_children($catid) . ') ' : '';
- $where .= !empty($areaid) ? ' AND a.areaid = \'' . $areaid . '\' ' : '';
- $where .= ' AND a.if_corp = \'1\'';
- $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';
- $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;
- $search['rows_num'] = $rows_num = $db->getOne($count_sql);
- $param = setParam(array('mod', 'catid', 'areaid', 'keywords'));
- if (is_array($res = page1($sql))) {
- foreach ($res as $key => $val) {
- $arr['userid'] = $val['userid'];
- $arr['tel'] = $val['tel'] ? $val['tel'] : '尚未填写电话信息';
- $arr['address'] = $val['address'] ? $val['address'] : '尚未填写地址信息';
- $arr['tname'] = $val['tname'] ? $val['tname'] : $val['userid'];
- $arr['prelogo'] = $val['prelogo'] ? $val['prelogo'] : '/images/nophoto.jpg';
- $arr['tname'] = HighLight($val['tname'] ? $val['tname'] : $val['userid'], $keyword ? $keyword : $keywords);
- $arr['uri'] = Rewrite('store', array('uid' => $val['id']));
- $arr['uri_aboutus'] = Rewrite('store', array('uid' => $val['id'], 'part' => 'about'));
- $arr['uri_comment'] = Rewrite('store', array('uid' => $val['id'], 'part' => 'comment'));
- $arr['uri_album'] = Rewrite('store', array('uid' => $val['id'], 'part' => 'album'));
- $search['result'][] = $arr;
- }
- }
- $search['pagination'] = page2();
- }
- $catoption = get_corp_tree(0, 'corp');
- $select_where_option = cat_list('area', 0, $areaid);
- }
- break;
- case 'news':
- if ($keywords != '') {
- !ifplugin('news') && exit('管理员已禁用或未安装新闻插件...');
- $catoption = cat_list('channel', 0, 0, false, 1);
- $area_list = cat_list('area', 0, $areaid);
- if ($keywords != '') {
- if (is_array($keyword = explode(' ', $keywords))) {
- $or = '';
- $sqlkeywords = '';
- foreach ($keyword as $k => $v) {
- $sqlkeywords .= ' ' . $or . ' n.title LIKE \'%' . $v . '%\' OR n.content LIKE \'%' . $v . '%\'';
- $or = 'OR';
- }
- $where .= ' AND (' . $sqlkeywords . ')';
- }
- $where .= !empty($catid) ? ' AND n.catid IN (' . get_cat_children($catid, 'channel') . ')' : '';
- $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';
- $search['rows_num'] = $rows_num = $db->getOne('SELECT COUNT(n.id) FROM `' . $db_mymps . 'news` AS n WHERE 1 ' . $where);
- $param = setParam(array('mod', 'catid', 'keywords'));
- $searchresult = page1($sql);
- foreach ($searchresult as $k => $val) {
- $result['id'] = $val['id'];
- $result['hit'] = $val['hit'];
- $result['uri'] = Rewrite('news', array('id' => $val['id'], 'html_path' => $val['html_path']));
- $result['begintime'] = $val['begintime'];
- $result['title'] = HighLight($val['title'], $keyword ? $keyword : $keywords);
- $result['content'] = HighLight(cutstr(clear_html($val['content']), 300), $keyword ? $keyword : $keywords);
- $result['catname'] = $val['catname'];
- $result['caturi'] = Rewrite('news', array('catid' => $val['catid'], 'html_dir' => $val['html_dir']));
- $search['result'][] = $result;
- }
- $search['pagination'] = page2();
- }
- }
- $search['page_title'] = ($keywords != '' ? $keywords . ' - ' : '') . '网站新闻搜索 - ' . $mymps_global['SiteName'];
- break;
- case 'group':
- if ($keywords != '') {
- require_once MYMPS_ROOT . '/plugin/group/include/functions.php';
- $group_class = get_group_class();
- $catoption = $group_class;
- $select_where_option = cat_list('area', 0, $areaid);
- require_once MYMPS_DATA . '/grouplevel.inc.php';
- if ($keywords != '') {
- $where = 'WHERE glevel > \'0\'';
- if (is_array($keyword = explode(' ', $keywords))) {
- $or = '';
- $sqlkeywords = '';
- foreach ($keyword as $k => $v) {
- $sqlkeywords .= ' ' . $or . ' gname LIKE \'%' . $v . '%\'';
- $or = 'OR';
- }
- $where .= ' AND (' . $sqlkeywords . ')';
- }
- if ($cate_id) {
- $where .= ' AND cate_id = \'' . $cate_id . '\'';
- }
- if ($areaid) {
- $where .= ' AND areaid = \'' . $areaid . '\'';
- }
- $search['rows_num'] = $rows_num = $db->getOne('SELECT COUNT(groupid) FROM `' . $db_mymps . 'group` ' . $where);
- $param = setParam(array('mod', 'cate_id', 'areaid', 'keywords'));
- $group = page1('SELECT * FROM `' . $db_mymps . 'group` ' . $where . ' ORDER BY displayorder DESC');
- foreach ($group as $k => $v) {
- $result['groupid'] = $v['groupid'];
- $result['gname'] = $v['gname'];
- $result['des'] = clear_html($v['des']);
- $result['enddate'] = $v['enddate'];
- $result['meetdate'] = $v['meetdate'];
- $result['gaddress'] = $v['gaddress'];
- $result['glevel'] = $v['glevel'];
- $result['signintotal'] = $v['signintotal'];
- $result['commenturl'] = $v['commenturl'];
- $result['pre_picture'] = $v['pre_picture'];
- $result['uri'] = plugin_url('group', array('id' => $v['groupid']));
- $search['result'][] = $result;
- }
- $search['pagination'] = page2();
- }
- }
- $search['page_title'] = ($keywords != '' ? $keywords . ' - ' : '') . '团购活动搜索 - ' . $mymps_global['SiteName'];
- break;
- case 'coupon':
- if ($keywords != '') {
- require_once MYMPS_ROOT . '/plugin/coupon/include/functions.php';
- $coupon_class = get_coupon_class();
- $catoption = $coupon_class;
- $select_where_option = cat_list('area', 0, $areaid);
- if ($keywords != '') {
- $where = 'WHERE status = \'1\' AND grade > \'0\'';
- if (is_array($keyword = explode(' ', $keywords))) {
- $or = '';
- $sqlkeywords = '';
- foreach ($keyword as $k => $v) {
- $sqlkeywords .= ' ' . $or . ' title LIKE \'%' . $v . '%\'';
- $or = 'OR';
- }
- $where .= ' AND (' . $sqlkeywords . ')';
- }
- if ($cate_id) {
- $where .= ' AND cate_id = \'' . $cate_id . '\'';
- }
- if ($areaid) {
- $where .= ' AND areaid = \'' . $areaid . '\'';
- }
- $search['rows_num'] = $rows_num = $db->getOne('SELECT count(id) FROM ' . $db_mymps . 'coupon ' . $where);
- $param = setParam(array('mod', 'cate_id', 'areaid', 'keywords'));
- $coupon = page1('SELECT * FROM `' . $db_mymps . 'coupon` ' . $where . ' ORDER BY begindate DESC');
- foreach ($coupon as $k => $v) {
- $result['id'] = $v['id'];
- $result['title'] = $v['title'];
- $result['des'] = $v['des'];
- $result['enddate'] = $v['enddate'];
- $result['begindate'] = $v['begindate'];
- $result['prints'] = $v['prints'];
- $result['pre_picture'] = $v['pre_picture'];
- $result['sup'] = $v['sup'];
- $result['uri'] = plugin_url('coupon', array('id' => $v['id']));
- $search['result'][] = $result;
- }
- $search['pagination'] = page2();
- }
- }
- $search['page_title'] = ($keywords != '' ? $keywords . ' - ' : '') . '优惠券搜索 - ' . $mymps_global['SiteName'];
- break;
- case 'goods':
- if ($keywords != '') {
- require_once MYMPS_ROOT . '/plugin/goods/include/functions.php';
- $goods_class = goods_category_tree(0);
- $catoption = $goods_class;
- $area_list = cat_list('area', 0, $areaid);
- if ($keywords != '') {
- $where = 'WHERE onsale = \'1\'';
- if (is_array($keyword = explode(' ', $keywords))) {
- $or = '';
- $sqlkeywords = '';
- foreach ($keyword as $k => $v) {
- $sqlkeywords .= ' ' . $or . ' goodsname LIKE \'%' . $v . '%\'';
- $or = 'OR';
- }
- $where .= ' AND (' . $sqlkeywords . ')';
- }
- if ($catid) {
- $where .= ' AND catid IN (' . mymps_get_goods_children($catid) . ')';
- }
- if ($areaid) {
- $where .= ' AND areaid = \'' . $areaid . '\'';
- }
- $search['rows_num'] = $rows_num = $db->getOne('SELECT COUNT(goodsid) FROM `' . $db_mymps . 'goods` ' . $where);
- $param = setParam(array('mod', 'cate_id', 'areaid', 'keywords'));
- $goods = page1('SELECT * FROM `' . $db_mymps . 'goods` ' . $where . ' ORDER BY dateline DESC', 16);
- foreach ($goods as $k => $v) {
- $result['goodsid'] = $v['goodsid'];
- $result['goodsname'] = $v['goodsname'];
- $result['nowprice'] = $v['nowprice'];
- $result['pre_picture'] = $v['pre_picture'] ? $v['pre_picture'] : $mymps_global['SiteUrl'] . '/images/nophoto.gif';
- $result['uri'] = plugin_url('goods', array('id' => $v['goodsid']));
- $search['result'][] = $result;
- }
- $search['pagination'] = page2();
- }
- }
- $search['page_title'] = ($keywords != '' ? $keywords . ' - ' : '') . '商品搜索 - ' . $mymps_global['SiteName'];
- break;
- }
- $mtime = explode(' ', microtime());
- $totaltime = number_format($mtime[1] + $mtime[0] - $mymps_starttime, 6);
- $sitedebug = 'Processed in ' . $totaltime . ' second(s) , ' . $db->query_num . ' queries';
- $search['keywords'] = $keywords;
- $search['tel'] = $tel;
- include $keywords || $tel ? mymps_tpl(CURSCRIPT . '_' . $mod) : mymps_tpl('search_index');
- is_object($db) && $db->Close();
- ?>
|