function getdata($style, $parameter) { global $_G; $parameter = $this->cookparameter($parameter); loadcache('grouptype'); $typeids = array(); if (!empty($parameter['gtids'])) { if ($parameter['gtids'][0] == '0') { unset($parameter['gtids'][0]); } $typeids = $parameter['gtids']; } $tids = !empty($parameter['tids']) ? explode(',', $parameter['tids']) : array(); $fids = !empty($parameter['fids']) ? explode(',', $parameter['fids']) : array(); $uids = !empty($parameter['uids']) ? explode(',', $parameter['uids']) : array(); $startrow = isset($parameter['startrow']) ? intval($parameter['startrow']) : 0; $items = isset($parameter['items']) ? intval($parameter['items']) : 10; $digest = isset($parameter['digest']) ? $parameter['digest'] : 0; $stick = isset($parameter['stick']) ? $parameter['stick'] : 0; $orderby = isset($parameter['orderby']) ? in_array($parameter['orderby'], array('dateline', 'todayhots', 'weekhots', 'monthhots')) ? $parameter['orderby'] : 'dateline' : 'dateline'; $titlelength = !empty($parameter['titlelength']) ? intval($parameter['titlelength']) : 40; $summarylength = !empty($parameter['summarylength']) ? intval($parameter['summarylength']) : 80; $recommend = !empty($parameter['recommend']) ? 1 : 0; $keyword = !empty($parameter['keyword']) ? $parameter['keyword'] : ''; $highlight = !empty($parameter['highlight']) ? 1 : 0; $bannedids = !empty($parameter['bannedids']) ? explode(',', $parameter['bannedids']) : array(); $gviewperm = isset($parameter['gviewperm']) ? intval($parameter['gviewperm']) : -1; $gviewwhere = $gviewperm == -1 ? '' : " AND ff.gviewperm='{$gviewperm}'"; $groups = array(); if (empty($fids) && $typeids) { $query = DB::query('SELECT f.fid, f.name, ff.description FROM ' . DB::table('forum_forum') . " f LEFT JOIN " . DB::table('forum_forumfield') . " ff ON f.fid = ff.fid WHERE f.fup IN (" . dimplode($typeids) . ") AND threads > 0{$gviewwhere}"); while ($value = DB::fetch($query)) { $groups[$value['fid']] = $value; $fids[] = intval($value['fid']); } if (empty($fids)) { return array('html' => '', 'data' => ''); } } require_once libfile('function/post'); require_once libfile('function/search'); $datalist = $list = $listpids = $threadpids = $aid2pid = $attachtables = array(); $keyword = $keyword ? searchkey($keyword, "tr.subject LIKE '%{text}%'") : ''; $sql = ($fids ? ' AND t.fid IN (' . dimplode($fids) . ')' : '') . ($tids ? ' AND t.tid IN (' . dimplode($tids) . ')' : '') . ($digest ? ' AND t.digest IN (' . dimplode($digest) . ')' : '') . ($stick ? ' AND t.displayorder IN (' . dimplode($stick) . ')' : ''); if (empty($fids)) { $sql .= " AND t.isgroup='1'"; if ($gviewwhere) { $sql .= $gviewwhere; } } $where = ''; if (in_array($orderby, array('todayhots', 'weekhots', 'monthhots'))) { $historytime = 0; switch ($orderby) { case 'todayhots': $historytime = mktime(0, 0, 0, date('m', TIMESTAMP), date('d', TIMESTAMP), date('Y', TIMESTAMP)); break; case 'weekhots': $week = dgmdate(TIMESTAMP, 'w', getglobal('setting/timeformat')) - 1; $week = $week != -1 ? $week : 6; $historytime = mktime(0, 0, 0, date('m', TIMESTAMP), date('d', TIMESTAMP) - $week, date('Y', TIMESTAMP)); break; case 'monthhots': $historytime = mktime(0, 0, 0, date('m', TIMESTAMP), 1, date('Y', TIMESTAMP)); break; } $where = ' AND tr.dateline>=' . $historytime; $orderby = 'totalitems'; } $where .= ($uids ? ' AND tr.sellerid IN (' . dimplode($uids) . ')' : '') . $keyword; $where .= $bannedids ? ' AND tr.pid NOT IN (' . dimplode($bannedids) . ')' : ''; $where = "{$sql} AND t.displayorder>='0' {$where}"; $sqlfrom = " INNER JOIN `" . DB::table('forum_thread') . "` t ON t.tid=tr.tid "; $joinmethod = empty($tids) ? 'INNER' : 'LEFT'; if ($recommend) { $sqlfrom .= " {$joinmethod} JOIN `" . DB::table('forum_forumrecommend') . "` fc ON fc.tid=tr.tid"; } $sqlfield = ''; if (empty($fids)) { $sqlfield = ', f.name groupname'; $sqlfrom .= ' LEFT JOIN ' . DB::table('forum_forum') . ' f ON t.fid=f.fid LEFT JOIN ' . DB::table('forum_forumfield') . ' ff ON f.fid = ff.fid'; } $sqlfield = $highlight ? ', t.highlight' : ''; $query = DB::query("SELECT tr.pid, tr.tid, tr.aid, tr.price, tr.credit, tr.subject, tr.totalitems, tr.seller, tr.sellerid{$sqlfield}\n\t\t\tFROM " . DB::table('forum_trade') . " tr {$sqlfrom}\n\t\t\tWHERE 1{$where}\n\t\t\tORDER BY tr.{$orderby} DESC\n\t\t\tLIMIT {$startrow},{$items};"); require_once libfile('block_thread', 'class/block/forum'); $bt = new block_thread(); while ($data = DB::fetch($query)) { if ($style['getsummary']) { $threadpids[$data['posttableid']][] = $data['pid']; } if ($data['aid']) { $aid2pid[$data['aid']] = $data['pid']; $attachtable = getattachtableid($data['tid']); $attachtables[$attachtable][] = $data['aid']; } $listpids[] = $data['pid']; $list[$data['pid']] = array('id' => $data['pid'], 'idtype' => 'pid', 'title' => cutstr(str_replace('\\\'', ''', addslashes($data['subject'])), $titlelength, ''), 'url' => 'forum.php?mod=viewthread&do=tradeinfo&tid=' . $data['tid'] . '&pid=' . $data['pid'], 'pic' => $data['aid'] ? '' : $_G['style']['imgdir'] . '/nophoto.gif', 'picflag' => '0', 'fields' => array('fulltitle' => str_replace('\\\'', ''', addslashes($data['subject'])), 'totalitems' => $data['totalitems'], 'author' => $data['seller'] ? $data['seller'] : $_G['setting']['anonymoustext'], 'authorid' => $data['sellerid'] ? $data['sellerid'] : 0, 'price' => ($data['price'] > 0 ? '¥ ' . $data['price'] : '') . ($data['credit'] > 0 ? ($data['price'] > 0 ? lang('block/grouptrade', 'grouptrade_price_add') : '') . $data['credit'] . ' ' . $_G['setting']['extcredits'][$_G['setting']['creditstransextra'][5]]['unit'] . $_G['setting']['extcredits'][$_G['setting']['creditstransextra'][5]]['title'] : ''))); if ($highlight && $data['highlight']) { $list[$data['tid']]['fields']['showstyle'] = $bt->getthreadstyle($data['highlight']); } } if (!empty($listpids)) { foreach ($threadpids as $key => $var) { $posttable = $key == 0 ? 'forum_post' : 'forum_post_' . $key; $query = DB::query("SELECT pid, message FROM " . DB::table($posttable) . " WHERE pid IN (" . dimplode($var) . ")"); while ($result = DB::fetch($query)) { $list[$result['pid']]['summary'] = messagecutstr($result['message'], $messagelength); } } foreach ($attachtables as $tableid => $taids) { $query = DB::query('SELECT aid, attachment, remote FROM ' . DB::table('forum_attachment_' . $tableid) . ' WHERE aid IN (' . dimplode($taids) . ')'); while ($avalue = DB::fetch($query)) { $list[$aid2pid[$avalue['aid']]]['pic'] = 'forum/' . $avalue['attachment']; $list[$aid2pid[$avalue['aid']]]['picflag'] = $avalue['remote'] ? '2' : '1'; } } foreach ($listpids as $key => $value) { $datalist[] = $list[$value]; } } return array('html' => '', 'data' => $datalist); }
} } if ($searchindex['id']) { $searchid = $searchindex['id']; } else { !($_G['group']['exempt'] & 2) && checklowerlimit('search'); if (!$srchtxt && !$srchuid && !$srchuname) { dheader('Location: search.php?mod=collection'); } if ($_G['adminid'] != '1' && $_G['setting']['search']['collection']['maxspm']) { if (C::t('common_searchindex')->count_by_dateline($_G['timestamp'], $srchmod) >= $_G['setting']['search']['collection']['maxspm']) { showmessage('search_toomany', 'search.php?mod=collection', array('maxspm' => $_G['setting']['search']['collection']['maxspm'])); } } $num = $ids = 0; $_G['setting']['search']['collection']['maxsearchresults'] = $_G['setting']['search']['collection']['maxsearchresults'] ? intval($_G['setting']['search']['collection']['maxsearchresults']) : 500; list($srchtxt, $srchtxtsql) = searchkey($keyword, "name LIKE '%{text}%' OR keyword LIKE '%{text}%'", true); $query = C::t('forum_collection')->fetch_ctid_by_searchkey($srchtxtsql, $_G['setting']['search']['collection']['maxsearchresults']); foreach ($query as $collection) { $ids .= ',' . $collection['ctid']; $num++; } unset($query); $keywords = str_replace('%', '+', $srchtxt); $expiration = TIMESTAMP + $cachelife_text; $searchid = C::t('common_searchindex')->insert(array('srchmod' => $srchmod, 'keywords' => $keywords, 'searchstring' => $searchstring, 'useip' => $_G['clientip'], 'uid' => $_G['uid'], 'dateline' => $_G['timestamp'], 'expiration' => $expiration, 'num' => $num, 'ids' => $ids), true); !($_G['group']['exempt'] & 2) && updatecreditbyaction('search'); } dheader("location: search.php?mod=collection&searchid={$searchid}&searchsubmit=yes&kw=" . urlencode($keyword)); } }
function getdata($style, $parameter) { global $_G; $parameter = $this->cookparameter($parameter); $aids = !empty($parameter['aids']) ? explode(',', $parameter['aids']) : array(); $uids = !empty($parameter['uids']) ? explode(',', $parameter['uids']) : array(); $keyword = !empty($parameter['keyword']) ? $parameter['keyword'] : ''; $tag = !empty($parameter['tag']) ? $parameter['tag'] : array(); $starttime = !empty($parameter['starttime']) ? strtotime($parameter['starttime']) : 0; $endtime = !empty($parameter['endtime']) ? strtotime($parameter['endtime']) : 0; $publishdateline = isset($parameter['publishdateline']) ? intval($parameter['publishdateline']) : 0; $startrow = isset($parameter['startrow']) ? intval($parameter['startrow']) : 0; $items = isset($parameter['items']) ? intval($parameter['items']) : 10; $titlelength = isset($parameter['titlelength']) ? intval($parameter['titlelength']) : 40; $summarylength = isset($parameter['summarylength']) ? intval($parameter['summarylength']) : 80; $clickarr = array('click1', 'click2', 'click3', 'click4', 'click5', 'click6', 'click7', 'click8'); $orderby = in_array($parameter['orderby'], array_merge(array('dateline', 'viewnum', 'commentnum'), $clickarr)) ? $parameter['orderby'] : 'dateline'; $catid = array(); if (!empty($parameter['catid'])) { if ($parameter['catid'][0] == '0') { unset($parameter['catid'][0]); } $catid = $parameter['catid']; } $picrequired = !empty($parameter['picrequired']) ? 1 : 0; $bannedids = !empty($parameter['bannedids']) ? explode(',', $parameter['bannedids']) : array(); loadcache('portalcategory'); $list = array(); $wheres = array(); if ($aids) { $wheres[] = 'at.aid IN (' . dimplode($aids) . ')'; } if ($uids) { $wheres[] = 'at.uid IN (' . dimplode($uids) . ')'; } if ($catid) { include_once libfile('function/portalcp'); $childids = array(); foreach ($catid as $id) { if ($_G['cache']['portalcategory'][$id]['disallowpublish']) { $childids = array_merge($childids, category_get_childids('portal', $id)); } } $catid = array_merge($catid, $childids); $catid = array_unique($catid); $wheres[] = 'at.catid IN (' . dimplode($catid) . ')'; } if (!$aids && !$catid && $_G['setting']['blockmaxaggregationitem']) { if (($maxid = $this->getmaxid() - $_G['setting']['blockmaxaggregationitem']) > 0) { $wheres[] = 'at.aid > ' . $maxid; } } if (empty($aids) && $picrequired) { $wheres[] = "at.pic != ''"; } if ($publishdateline) { $time = TIMESTAMP - $publishdateline; $wheres[] = "at.dateline >= '{$time}'"; } if ($starttime) { $wheres[] = "at.dateline >= '{$starttime}'"; } if ($endtime) { $wheres[] = "at.dateline <= '{$endtime}'"; } if ($bannedids) { $wheres[] = 'at.aid NOT IN (' . dimplode($bannedids) . ')'; } $wheres[] = "at.status='0'"; if (is_array($tag)) { $article_tags = array(); foreach ($tag as $k) { $article_tags[$k] = 1; } include_once libfile('function/portalcp'); $v = article_make_tag($article_tags); if ($v > 0) { $wheres[] = "(at.tag & {$v}) = {$v}"; } } if ($keyword) { require_once libfile('function/search'); $keyword = searchkey($keyword, "at.title LIKE '%{text}%'"); } $wheresql = $wheres ? implode(' AND ', $wheres) : '1'; if (in_array($orderby, $clickarr)) { $orderby = "at.{$orderby} DESC,at.dateline DESC"; } else { $orderby = $orderby == 'dateline' ? 'at.dateline DESC ' : "ac.{$orderby} DESC"; } $query = DB::query("SELECT at.*, ac.viewnum, ac.commentnum FROM " . DB::table('portal_article_title') . " at LEFT JOIN " . DB::table('portal_article_count') . " ac ON at.aid=ac.aid WHERE {$wheresql}{$keyword} ORDER BY {$orderby} LIMIT {$startrow}, {$items}"); while ($data = DB::fetch($query)) { if (empty($data['pic'])) { $data['pic'] = STATICURL . 'image/common/nophoto.gif'; $data['picflag'] = '0'; } else { $data['pic'] = $data['pic']; $data['picflag'] = $data['remote'] == '1' ? '2' : '1'; } $list[] = array('id' => $data['aid'], 'idtype' => 'aid', 'title' => cutstr($data['title'], $titlelength, ''), 'url' => 'portal.php?mod=view&aid=' . $data['aid'], 'pic' => $data['pic'], 'picflag' => $data['picflag'], 'summary' => cutstr(strip_tags($data['summary']), $summarylength, ''), 'fields' => array('uid' => $data['uid'], 'username' => $data['username'], 'avatar' => avatar($data['uid'], 'small', true, false, false, $_G['setting']['ucenterurl']), 'avatar_middle' => avatar($data['uid'], 'middle', true, false, false, $_G['setting']['ucenterurl']), 'avatar_big' => avatar($data['uid'], 'big', true, false, false, $_G['setting']['ucenterurl']), 'fulltitle' => $data['title'], 'dateline' => $data['dateline'], 'caturl' => $_G['cache']['portalcategory'][$data['catid']]['caturl'], 'catname' => $_G['cache']['portalcategory'][$data['catid']]['catname'], 'articles' => $_G['cache']['portalcategory'][$data['catid']]['articles'], 'viewnum' => intval($data['viewnum']), 'commentnum' => intval($data['commentnum']))); } return array('html' => '', 'data' => $list); }
function getdata($style, $parameter) { global $_G; $parameter = $this->cookparameter($parameter); loadcache('forums'); $tids = !empty($parameter['tids']) ? explode(',', $parameter['tids']) : array(); $uids = !empty($parameter['uids']) ? explode(',', $parameter['uids']) : array(); $startrow = !empty($parameter['startrow']) ? intval($parameter['startrow']) : 0; $items = !empty($parameter['items']) ? intval($parameter['items']) : 10; $digest = isset($parameter['digest']) ? $parameter['digest'] : 0; $stick = isset($parameter['stick']) ? $parameter['stick'] : 0; $orderby = isset($parameter['orderby']) ? in_array($parameter['orderby'], array('dateline', 'weekstart', 'monthstart', 'weekexp', 'monthexp', 'weekhot', 'monthhot', 'alltimehot')) ? $parameter['orderby'] : 'dateline' : 'dateline'; $titlelength = !empty($parameter['titlelength']) ? intval($parameter['titlelength']) : 40; $summarylength = !empty($parameter['summarylength']) ? intval($parameter['summarylength']) : 80; $recommend = !empty($parameter['recommend']) ? 1 : 0; $keyword = !empty($parameter['keyword']) ? $parameter['keyword'] : ''; $place = !empty($parameter['place']) ? $parameter['place'] : ''; $class = !empty($parameter['class']) ? trim($parameter['class']) : ''; $gender = !empty($parameter['gender']) ? intval($parameter['gender']) : ''; $viewmod = !empty($parameter['viewmod']) ? 1 : 0; $highlight = !empty($parameter['highlight']) ? 1 : 0; $fids = array(); if (!empty($parameter['fids'])) { if ($parameter['fids'][0] == '0') { unset($parameter['fids'][0]); } $fids = $parameter['fids']; } $bannedids = !empty($parameter['bannedids']) ? explode(',', $parameter['bannedids']) : array(); require_once libfile('function/post'); require_once libfile('function/search'); $datalist = $list = array(); $keyword = $keyword ? searchkey($keyword, "t.subject LIKE '%{text}%'") : ''; $sql = ($fids ? ' AND t.fid IN (' . dimplode($fids) . ')' : '') . $keyword . ($tids ? ' AND t.tid IN (' . dimplode($tids) . ')' : '') . ($bannedids ? ' AND t.tid NOT IN (' . dimplode($bannedids) . ')' : '') . ($digest ? ' AND t.digest IN (' . dimplode($digest) . ')' : '') . ($stick ? ' AND t.displayorder IN (' . dimplode($stick) . ')' : '') . " AND t.isgroup='0'"; $where = ''; if (in_array($orderby, array('weekstart', 'monthstart'))) { $historytime = 0; switch ($orderby) { case 'weekstart': $historytime = TIMESTAMP + 86400 * 7; break; case 'monthstart': $historytime = TIMESTAMP + 86400 * 30; break; } $where = ' WHERE a.starttimefrom>=' . TIMESTAMP . ' AND a.starttimefrom<=' . $historytime; $orderby = 'a.starttimefrom ASC'; } elseif (in_array($orderby, array('weekexp', 'monthexp'))) { $historytime = 0; switch ($orderby) { case 'weekexp': $historytime = TIMESTAMP + 86400 * 7; break; case 'monthexp': $historytime = TIMESTAMP + 86400 * 30; break; } $where = ' WHERE a.expiration>=' . TIMESTAMP . ' AND a.expiration<=' . $historytime; $orderby = 'a.expiration ASC'; } elseif (in_array($orderby, array('weekhot', 'monthhot'))) { $historytime = 0; switch ($orderby) { case 'weekhot': $historytime = TIMESTAMP + 86400 * 7; break; case 'monthhot': $historytime = TIMESTAMP + 86400 * 30; break; } $where = ' WHERE a.expiration>=' . TIMESTAMP . ' AND a.expiration<=' . $historytime; $orderby = 'a.applynumber DESC'; } elseif ($orderby == 'alltimehot') { $where = ' WHERE (a.expiration>=' . TIMESTAMP . " OR a.expiration='0')"; $orderby = 'a.applynumber DESC'; } else { $orderby = 't.dateline DESC'; } $where .= $uids ? ' AND t.authorid IN (' . dimplode($uids) . ')' : ''; if ($gender) { $where .= " AND a.gender='{$gender}'"; } if ($class) { $where .= " AND a.class='{$class}'"; } $sqlfrom = " INNER JOIN `" . DB::table('forum_thread') . "` t ON t.tid=a.tid {$sql} AND t.displayorder>='0'"; $joinmethod = empty($tids) ? 'INNER' : 'LEFT'; if ($recommend) { $sqlfrom .= " {$joinmethod} JOIN `" . DB::table('forum_forumrecommend') . "` fc ON fc.tid=tr.tid"; } $sqlfield = $highlight ? ', t.highlight' : ''; $query = DB::query("SELECT a.*, t.tid, t.subject, t.authorid, t.author{$sqlfield}\n\t\t\tFROM " . DB::table('forum_activity') . " a {$sqlfrom} {$where}\n\t\t\tORDER BY {$orderby}\n\t\t\tLIMIT {$startrow},{$items};"); require_once libfile('block_thread', 'class/block/forum'); $bt = new block_thread(); $listtids = $threadtids = $threads = $aid2tid = $attachtables = array(); while ($data = DB::fetch($query)) { $data['time'] = dgmdate($data['starttimefrom']); if ($data['starttimeto']) { $data['time'] .= ' - ' . dgmdate($data['starttimeto']); } if ($style['getsummary']) { $threadtids[$data['posttableid']][] = $data['tid']; } if ($data['aid']) { $aid2tid[$data['aid']] = $data['tid']; $attachtable = getattachtableid($data['tid']); $attachtables[$attachtable][] = $data['aid']; } $listtids[] = $data['tid']; $list[$data['tid']] = array('id' => $data['tid'], 'idtype' => 'tid', 'title' => cutstr(str_replace('\\\'', ''', $data['subject']), $titlelength, ''), 'url' => 'forum.php?mod=viewthread&tid=' . $data['tid'] . ($viewmod ? '&from=portal' : ''), 'pic' => $data['aid'] ? '' : $_G['style']['imgdir'] . '/nophoto.gif', 'picflag' => '0', 'fields' => array('fulltitle' => str_replace('\\\'', ''', addslashes($data['subject'])), 'time' => $data['time'], 'expiration' => $data['expiration'] ? dgmdate($data['expiration']) : 'N/A', 'author' => $data['author'] ? $data['author'] : $_G['setting']['anonymoustext'], 'authorid' => $data['authorid'] ? $data['authorid'] : 0, 'cost' => $data['cost'], 'place' => $data['place'], 'class' => $data['class'], 'gender' => $data['gender'], 'number' => $data['number'], 'applynumber' => $data['applynumber'])); if ($highlight && $data['highlight']) { $list[$data['tid']]['fields']['showstyle'] = $bt->getthreadstyle($data['highlight']); } } if (!empty($listtids)) { $query = DB::query("SELECT tid,COUNT(*) as sum FROM " . DB::table('forum_activityapply') . " WHERE tid IN(" . dimplode($listtids) . ") GROUP BY tid"); while ($value = DB::fetch($query)) { $list[$value['tid']]['fields']['applynumber'] = $value['sum']; } $threads = $bt->getthread($threadtids, $summarylength, true); if ($threads) { foreach ($threads as $tid => $var) { $list[$tid]['summary'] = $var; } } foreach ($attachtables as $tableid => $taids) { $query = DB::query('SELECT aid, attachment, remote FROM ' . DB::table('forum_attachment_' . $tableid) . ' WHERE aid IN (' . dimplode($taids) . ')'); while ($avalue = DB::fetch($query)) { $list[$aid2tid[$avalue['aid']]]['pic'] = 'forum/' . $avalue['attachment']; $list[$aid2tid[$avalue['aid']]]['picflag'] = $avalue['remote'] ? '2' : '1'; } } foreach ($listtids as $key => $value) { $datalist[] = $list[$value]; } } return array('html' => '', 'data' => $datalist); }
if ($srchuname) { $srchuid = $comma = ''; $srchuname = str_replace('*', '%', addcslashes($srchuname, '%_')); $query = DB::query("SELECT uid FROM " . DB::table('common_member') . " WHERE username LIKE '" . str_replace('_', '\\_', $srchuname) . "' LIMIT 50"); while ($member = DB::fetch($query)) { $srchuid .= "{$comma}'{$member['uid']}'"; $comma = ', '; } if (!$srchuid) { $sqlsrch .= ' AND 0'; } } elseif ($srchuid) { $srchuid = "'{$srchuid}'"; } if ($srchtxt) { $srcharr = $srchtype == 'fulltext' ? searchkey($keyword, "(p.message LIKE '%{text}%' OR p.subject LIKE '%{text}%')", true) : searchkey($keyword, "t.subject LIKE '%{text}%'", true); $srchtxt = $srcharr[0]; $sqlsrch .= $srcharr[1]; } if ($srchuid) { $sqlsrch .= ' AND ' . ($srchtype == 'fulltext' ? 'p' : 't') . ".authorid IN ({$srchuid})"; } if (!empty($srchfrom)) { $searchfrom = ($before ? '<=' : '>=') . (TIMESTAMP - $srchfrom); $sqlsrch .= " AND t.lastpost{$searchfrom}"; } if (!empty($specials)) { $sqlsrch .= " AND special IN (" . dimplode($special) . ")"; } $keywords = str_replace('%', '+', $srchtxt); $expiration = TIMESTAMP + $cachelife_text;
function getdata($style, $parameter) { global $_G; $parameter = $this->cookparameter($parameter); loadcache('grouptype'); $typeids = array(); if (!empty($parameter['gtids'])) { if ($parameter['gtids'][0] == '0') { unset($parameter['gtids'][0]); } $typeids = $parameter['gtids']; } $tids = !empty($parameter['tids']) ? explode(',', $parameter['tids']) : array(); $fids = !empty($parameter['fids']) ? explode(',', $parameter['fids']) : array(); $uids = !empty($parameter['uids']) ? explode(',', $parameter['uids']) : array(); $keyword = !empty($parameter['keyword']) ? $parameter['keyword'] : ''; $startrow = isset($parameter['startrow']) ? intval($parameter['startrow']) : 0; $items = isset($parameter['items']) ? intval($parameter['items']) : 10; $special = isset($parameter['special']) ? $parameter['special'] : array(); $lastpost = isset($parameter['lastpost']) ? intval($parameter['lastpost']) : 0; $postdateline = isset($parameter['postdateline']) ? intval($parameter['postdateline']) : 0; $rewardstatus = isset($parameter['rewardstatus']) ? intval($parameter['rewardstatus']) : 0; $titlelength = !empty($parameter['titlelength']) ? intval($parameter['titlelength']) : 40; $summarylength = !empty($parameter['summarylength']) ? intval($parameter['summarylength']) : 80; $orderby = in_array($parameter['orderby'], array('dateline', 'replies', 'views', 'threads', 'heats', 'recommends')) ? $parameter['orderby'] : 'lastpost'; $picrequired = !empty($parameter['picrequired']) ? 1 : 0; $gviewperm = isset($parameter['gviewperm']) ? intval($parameter['gviewperm']) : -1; $highlight = !empty($parameter['highlight']) ? 1 : 0; $bannedids = !empty($parameter['bannedids']) ? explode(',', $parameter['bannedids']) : array(); $gviewwhere = $gviewperm == -1 ? '' : " AND ff.gviewperm='{$gviewperm}'"; $groups = array(); if (empty($fids) && $typeids) { $query = DB::query('SELECT f.fid, f.name, ff.description FROM ' . DB::table('forum_forum') . " f LEFT JOIN " . DB::table('forum_forumfield') . " ff ON f.fid = ff.fid WHERE f.fup IN (" . dimplode($typeids) . ") AND threads > 0{$gviewwhere}"); while ($value = DB::fetch($query)) { $groups[$value['fid']] = $value; $fids[] = intval($value['fid']); } if (empty($fids)) { return array('html' => '', 'data' => ''); } } require_once libfile('function/post'); require_once libfile('function/search'); $datalist = $list = $listtids = $pictids = $pics = $threadtids = $threads = array(); $threadtypeids = array(); $keyword = $keyword ? searchkey($keyword, "t.subject LIKE '%{text}%'") : ''; $sql = ($fids ? ' AND t.fid IN (' . dimplode($fids) . ')' : '') . ($tids ? ' AND t.tid IN (' . dimplode($tids) . ')' : '') . ($bannedids ? ' AND t.tid NOT IN (' . dimplode($bannedids) . ')' : '') . ($uids ? ' AND t.authorid IN (' . dimplode($uids) . ')' : '') . ($special ? ' AND t.special IN (' . dimplode($special) . ')' : '') . (in_array(3, $special) && $rewardstatus ? $rewardstatus == 1 ? ' AND t.price < 0' : ' AND t.price > 0' : '') . $keyword; if (empty($fids)) { $sql .= " AND t.isgroup='1'"; if ($gviewwhere) { $sql .= $gviewwhere; } } if ($postdateline) { $time = TIMESTAMP - $postdateline; $sql .= " AND t.dateline >= '{$time}'"; } if ($lastpost) { $time = TIMESTAMP - $lastpost; $sql .= " AND t.lastpost >= '{$time}'"; } if ($orderby == 'heats') { $sql .= " AND t.heats>'0'"; } $sqlfrom = $sqlfield = $joinmethodpic = ''; if ($picrequired) { $joinmethodpic = 'INNER'; } else { if ($style['getpic']) { $joinmethodpic = 'LEFT'; } } if ($joinmethodpic) { /*vot*/ $sqlfrom .= " {$joinmethodpic} JOIN `" . DB::table('forum_threadimage') . "` ti ON (t.tid=ti.tid AND ti.tid>0)"; $sqlfield = ', ti.attachment as attachmenturl, ti.remote'; } if (empty($fids)) { $sqlfield .= ', f.name groupname'; /*vot*/ $sqlfrom .= ' LEFT JOIN ' . DB::table('forum_forum') . ' f ON (t.fid=f.fid) LEFT JOIN ' . DB::table('forum_forumfield') . ' ff ON (f.fid = ff.fid)'; } $query = DB::query("SELECT t.* {$sqlfield}\r\n\t\t\tFROM `" . DB::table('forum_thread') . "` t\r\n\t\t\t{$sqlfrom} WHERE t.readperm='0'\r\n\t\t\t{$sql}\r\n\t\t\tAND t.displayorder>='0'\r\n\t\t\tORDER BY t.{$orderby} DESC\r\n\t\t\tLIMIT {$startrow},{$items};"); require_once libfile('block_thread', 'class/block/forum'); $bt = new block_thread(); while ($data = DB::fetch($query)) { if ($data['closed'] > 1 && $data['closed'] < $data['tid']) { continue; } $_G['block_thread'][$data['tid']] = $data; if ($style['getsummary']) { $threadtids[$data['posttableid']][] = $data['tid']; } $listtids[] = $data['tid']; $list[$data['tid']] = array('id' => $data['tid'], 'idtype' => 'tid', 'title' => cutstr(str_replace('\\\'', ''', $data['subject']), $titlelength, ''), 'url' => 'forum.php?mod=viewthread&tid=' . $data['tid'], 'pic' => $data['attachmenturl'] ? 'forum/' . $data['attachmenturl'] : STATICURL . 'image/common/nophoto.gif', 'picflag' => $data['attachmenturl'] ? $data['remote'] ? '2' : '1' : '0', 'fields' => array('fulltitle' => str_replace('\\\'', ''', addslashes($data['subject'])), 'icon' => 'forum/' . $data['icon'], 'author' => $data['author'] ? $data['author'] : $_G['setting']['anonymoustext'], 'authorid' => $data['author'] ? $data['authorid'] : 0, 'avatar' => avatar($data['author'] ? $data['authorid'] : 0, 'small', true, false, false, $_G['setting']['ucenterurl']), 'avatar_middle' => avatar($data['author'] ? $data['authorid'] : 0, 'middle', true, false, false, $_G['setting']['ucenterurl']), 'avatar_big' => avatar($data['author'] ? $data['authorid'] : 0, 'big', true, false, false, $_G['setting']['ucenterurl']), 'dateline' => $data['dateline'], 'lastpost' => $data['lastpost'], 'posts' => $data['posts'], 'todayposts' => $data['todayposts'], 'replies' => $data['replies'], 'views' => $data['views'], 'heats' => $data['heats'], 'recommends' => $data['recommends'], 'groupname' => empty($groups[$data['fid']]['name']) ? $data['groupname'] : $groups[$data['fid']]['name'], 'groupurl' => 'forum.php?mod=group&fid=' . $data['fid'])); if ($highlight && $data['highlight']) { $list[$data['tid']]['fields']['showstyle'] = $bt->getthreadstyle($data['highlight']); } } $threads = $bt->getthread($threadtids, $summarylength); if ($threads) { foreach ($threads as $tid => $var) { $list[$tid]['summary'] = $var; } } if ($listtids) { foreach ($listtids as $key => $value) { $datalist[] = $list[$value]; } } return array('html' => '', 'data' => $datalist); }
} if ($searchindex['id']) { $searchid = $searchindex['id']; } else { !($_G['group']['exempt'] & 2) && checklowerlimit('search'); if (!$srchtxt && !$srchuid && !$srchuname) { dheader('Location: search.php?mod=blog'); } if ($_G['adminid'] != '1' && $_G['setting']['search']['blog']['maxspm']) { if (DB::result_first("SELECT COUNT(*) FROM " . DB::table('common_searchindex') . " WHERE srchmod='{$srchmod}' AND dateline>'{$_G['timestamp']}'-60") >= $_G['setting']['search']['blog']['maxspm']) { showmessage('search_toomany', 'search.php?mod=blog', array('maxspm' => $_G['setting']['search']['blog']['maxspm'])); } } $num = $ids = 0; $_G['setting']['search']['blog']['maxsearchresults'] = $_G['setting']['search']['blog']['maxsearchresults'] ? intval($_G['setting']['search']['blog']['maxsearchresults']) : 500; list($srchtxt, $srchtxtsql) = searchkey($keyword, "subject LIKE '%{text}%'", true); $query = DB::query("SELECT blogid FROM " . DB::table('home_blog') . " WHERE 1 {$srchtxtsql} ORDER BY blogid DESC LIMIT " . $_G['setting']['search']['blog']['maxsearchresults']); while ($blog = DB::fetch($query)) { $ids .= ',' . $blog['blogid']; $num++; } DB::free_result($query); $keywords = str_replace('%', '+', $srchtxt); $expiration = TIMESTAMP + $cachelife_text; DB::query("INSERT INTO " . DB::table('common_searchindex') . " (srchmod, keywords, searchstring, useip, uid, dateline, expiration, num, ids)\r\n\t\t\t\t\tVALUES ('{$srchmod}', '{$keywords}', '{$searchstring}', '{$_G['clientip']}', '{$_G['uid']}', '{$_G['timestamp']}', '{$expiration}', '{$num}', '{$ids}')"); $searchid = DB::insert_id(); !($_G['group']['exempt'] & 2) && updatecreditbyaction('search'); } dheader("location: search.php?mod=blog&searchid={$searchid}&searchsubmit=yes&kw=" . urlencode($keyword)); } }
} } if ($searchindex['id']) { $searchid = $searchindex['id']; } else { if (!$srchtxt) { dheader('Location: search.php?mod=portal'); } if ($_G['adminid'] != '1' && $_G['setting']['search']['portal']['maxspm']) { if (DB::result_first("SELECT COUNT(*) FROM " . DB::table('common_searchindex') . " WHERE srchmod='{$srchmod}' AND dateline>'{$_G['timestamp']}'-60") >= $_G['setting']['search']['portal']['maxspm']) { showmessage('search_toomany', 'search.php?mod=portal', array('maxspm' => $_G['setting']['search']['portal']['maxspm'])); } } $num = $ids = 0; $_G['setting']['search']['portal']['maxsearchresults'] = $_G['setting']['search']['portal']['maxsearchresults'] ? intval($_G['setting']['search']['portal']['maxsearchresults']) : 500; list($srchtxt, $srchtxtsql) = searchkey($keyword, "title LIKE '%{text}%'", true); $query = DB::query("SELECT aid FROM " . DB::table('portal_article_title') . " WHERE 1 {$srchtxtsql} ORDER BY aid DESC LIMIT " . $_G['setting']['search']['portal']['maxsearchresults']); while ($article = DB::fetch($query)) { $ids .= ',' . $article['aid']; $num++; } DB::free_result($query); $keywords = str_replace('%', '+', $srchtxt); $expiration = TIMESTAMP + $cachelife_text; DB::query("INSERT INTO " . DB::table('common_searchindex') . " (srchmod, keywords, searchstring, useip, uid, dateline, expiration, num, ids)\r\n\t\t\t\t\tVALUES ('{$srchmod}', '{$keywords}', '{$searchstring}', '{$_G['clientip']}', '{$_G['uid']}', '{$_G['timestamp']}', '{$expiration}', '{$num}', '{$ids}')"); $searchid = DB::insert_id(); !($_G['portal']['exempt'] & 2) && updatecreditbyaction('search'); } dheader("location: search.php?mod=portal&searchid={$searchid}&searchsubmit=yes&kw=" . urlencode($keyword)); } }
$i = 0; foreach ($cfriend as $key => $uid) { if (isset($friend[$uid])) { $list[] = array('uid' => $friend[$uid]['fuid'], 'username' => $friend[$uid]['fusername']); $i++; if ($i >= 15) { break; } } } } } } elseif ($op == 'getinviteuser') { require_once libfile('function/search'); $perpage = 20; $username = empty($_GET['username']) ? '' : searchkey($_GET['username'], "f.fusername LIKE '{text}%'"); $page = empty($_GET['page']) ? 0 : intval($_GET['page']); $gid = isset($_GET['gid']) ? intval($_GET['gid']) : -1; if ($page < 1) { $page = 1; } $start = ($page - 1) * $perpage; $json = array(); $wheresql = ''; if ($gid > -1) { $wheresql .= " AND f.gid='{$gid}'"; } if (!empty($username)) { $wheresql .= $username; } $count = $count_at = $singlenum = 0;
$srchuid .= "{$comma}'{$member['uid']}'"; $comma = ', '; } if (!$srchuid) { $sqlsrch .= ' AND 0'; } } elseif ($srchuid) { $srchuid = "'{$srchuid}'"; } if ($srchtypeid) { $srchtypeid = intval($srchtypeid); $sqlsrch .= " AND tr.typeid='{$srchtypeid}'"; } if ($srchtxt) { require_once libfile('function/search'); $srcharr = searchkey($srchtxt, "tr.subject LIKE '%{text}%'", true); $srchtxt = $srcharr[0]; $sqlsrch .= $srcharr[1]; } if ($srchuid) { $sqlsrch .= " AND tr.sellerid IN ({$srchuid})"; } if (!empty($srchfrom)) { $searchfrom = ($before ? '<=' : '>=') . (TIMESTAMP - $srchfrom); $sqlsrch .= " AND tr.dateline{$searchfrom}"; } $keywords = str_replace('%', '+', $srchtxt) . (trim($srchuname) ? '+' . str_replace('%', '+', $srchuname) : ''); $expiration = TIMESTAMP + $cachelife_text; } $threads = $tids = 0; $query = DB::query("SELECT tr.tid, tr.pid, t.closed {$sqlsrch} ORDER BY tr.pid DESC LIMIT " . $_G['setting']['maxsearchresults']);
function getdata($style, $parameter) { global $_G; $returndata = array('html' => '', 'data' => ''); $parameter = $this->cookparameter($parameter); loadcache('forums', 'stamps'); $tids = !empty($parameter['tids']) ? explode(',', $parameter['tids']) : array(); $uids = !empty($parameter['uids']) ? explode(',', $parameter['uids']) : array(); $startrow = isset($parameter['startrow']) ? intval($parameter['startrow']) : 0; $items = !empty($parameter['items']) ? intval($parameter['items']) : 10; $digest = isset($parameter['digest']) ? $parameter['digest'] : 0; $stick = isset($parameter['stick']) ? $parameter['stick'] : 0; $orderby = isset($parameter['orderby']) ? in_array($parameter['orderby'], array('lastpost', 'dateline', 'replies', 'views', 'heats', 'recommends')) ? $parameter['orderby'] : 'lastpost' : 'lastpost'; $lastpost = isset($parameter['lastpost']) ? intval($parameter['lastpost']) : 0; $postdateline = isset($parameter['postdateline']) ? intval($parameter['postdateline']) : 0; $titlelength = !empty($parameter['titlelength']) ? intval($parameter['titlelength']) : 40; $summarylength = !empty($parameter['summarylength']) ? intval($parameter['summarylength']) : 80; $recommend = !empty($parameter['recommend']) ? 1 : 0; $keyword = !empty($parameter['keyword']) ? $parameter['keyword'] : ''; $tagkeyword = !empty($parameter['tagkeyword']) ? $parameter['tagkeyword'] : ''; $typeids = !empty($parameter['typeids']) ? explode(',', $parameter['typeids']) : array(); $sortids = !empty($parameter['sortids']) && !in_array(0, (array) $parameter['sortids']) ? $parameter['sortids'] : array(); $special = !empty($parameter['special']) ? $parameter['special'] : array(); $rewardstatus = !empty($parameter['rewardstatus']) ? intval($parameter['rewardstatus']) : 0; $picrequired = !empty($parameter['picrequired']) ? 1 : 0; $viewmod = !empty($parameter['viewmod']) ? 1 : 0; $highlight = !empty($parameter['highlight']) ? 1 : 0; $fids = array(); if (!empty($parameter['fids'])) { if (isset($parameter['fids'][0]) && $parameter['fids'][0] == '0') { unset($parameter['fids'][0]); } $fids = $parameter['fids']; } $bannedids = !empty($parameter['bannedids']) ? explode(',', $parameter['bannedids']) : array(); require_once libfile('function/post'); require_once libfile('function/search'); $datalist = $list = $listtids = $pictids = $pics = $threadtids = $threadtypeids = $tagids = array(); $keyword = $keyword ? searchkey($keyword, "t.subject LIKE '%{text}%'") : ''; if ($tagkeyword) { if (!($tagids = DB::fetch_all('SELECT tagid FROM ' . DB::table('common_tag') . ' WHERE 1' . searchkey($tagkeyword, "tagname LIKE '%{text}%'"), '', 'tagid'))) { return array('data' => ''); } } $threadsorts = $threadtypes = array(); $querytmp = DB::query("SELECT typeid, name, special FROM " . DB::table('forum_threadtype') . " WHERE special>'0'"); while ($value = DB::fetch($querytmp)) { $threadsorts[$value['typeid']] = $value; } $querytmp = DB::query("SELECT * FROM " . DB::table('forum_threadclass')); foreach (C::t('forum_threadclass')->range() as $value) { $threadtypes[$value['typeid']] = $value; } $sql = ($fids ? ' AND t.fid IN (' . dimplode($fids) . ')' : '') . ($tids ? ' AND t.tid IN (' . dimplode($tids) . ')' : '') . ($uids ? ' AND t.authorid IN (' . dimplode($uids) . ')' : '') . ($typeids ? ' AND t.typeid IN (' . dimplode($typeids) . ')' : '') . ($sortids ? ' AND t.sortid IN (' . dimplode($sortids) . ')' : '') . ($special ? ' AND t.special IN (' . dimplode($special) . ')' : '') . (in_array(3, $special) && $rewardstatus ? $rewardstatus == 1 ? ' AND t.price < 0' : ' AND t.price > 0' : '') . ($digest ? ' AND t.digest IN (' . dimplode($digest) . ')' : '') . ($stick ? ' AND t.displayorder IN (' . dimplode($stick) . ')' : '') . ($bannedids ? ' AND t.tid NOT IN (' . dimplode($bannedids) . ')' : '') . $keyword . " AND t.isgroup='0'"; if ($postdateline) { $time = TIMESTAMP - $postdateline; $sql .= " AND t.dateline >= '{$time}'"; } if ($lastpost) { $time = TIMESTAMP - $lastpost; $sql .= " AND t.lastpost >= '{$time}'"; } if ($orderby == 'heats') { $sql .= " AND t.heats>'0'"; } $sqlfrom = $sqlfield = $joinmethodpic = ''; if ($picrequired) { $joinmethodpic = 'INNER'; } else { if ($style['getpic']) { $joinmethodpic = 'LEFT'; } } if ($joinmethodpic) { $sqlfrom .= " {$joinmethodpic} JOIN `" . DB::table('forum_threadimage') . "` ti ON t.tid=ti.tid"; $sqlfield = ', ti.attachment as attachmenturl, ti.remote'; } $joinmethod = empty($tids) ? 'INNER' : 'LEFT'; if ($recommend) { $sqlfrom .= " {$joinmethod} JOIN `" . DB::table('forum_forumrecommend') . "` fc ON fc.tid=t.tid"; } if ($tagids) { $sqlfrom .= " {$joinmethod} JOIN `" . DB::table('common_tagitem') . "` tim ON tim.tagid IN (" . dimplode(array_keys($tagids)) . ") AND tim.itemid=t.tid AND tim.idtype='tid' "; } $maxwhere = ''; if (!$tids && !$fids && !$digest && !$stick && $_G['setting']['blockmaxaggregationitem']) { $maxwhere = ($maxid = $this->getmaxid() - $_G['setting']['blockmaxaggregationitem']) > 0 ? 't.tid > ' . $maxid . ' AND ' : ''; } $query = DB::query("SELECT DISTINCT t.*{$sqlfield}\n\t\t\tFROM `" . DB::table('forum_thread') . "` t\n\t\t\t{$sqlfrom} WHERE {$maxwhere}t.readperm='0'\n\t\t\t{$sql}\n\t\t\tAND t.displayorder>='0'\n\t\t\tORDER BY t.{$orderby} DESC\n\t\t\tLIMIT {$startrow},{$items};"); while ($data = DB::fetch($query)) { $_G['block_thread'][$data['tid']] = $data; if ($style['getsummary']) { $threadtids[$data['posttableid']][] = $data['tid']; } $listtids[] = $data['tid']; $list[$data['tid']] = array('id' => $data['tid'], 'idtype' => 'tid', 'title' => cutstr(str_replace('\\\'', ''', addslashes($data['subject'])), $titlelength, ''), 'url' => 'forum.php?mod=viewthread&tid=' . $data['tid'] . ($viewmod ? '&from=portal' : ''), 'pic' => $data['attachmenturl'] ? 'forum/' . $data['attachmenturl'] : STATICURL . 'image/common/nophoto.gif', 'picflag' => $data['attachmenturl'] ? $data['remote'] ? '2' : '1' : '0', 'fields' => array('fulltitle' => str_replace('\\\'', ''', addslashes($data['subject'])), 'threads' => $data['threads'], 'author' => $data['author'] ? $data['author'] : $_G['setting']['anonymoustext'], 'authorid' => $data['author'] ? $data['authorid'] : 0, 'avatar' => avatar($data['author'] ? $data['authorid'] : 0, 'small', true, false, false, $_G['setting']['ucenterurl']), 'avatar_middle' => avatar($data['author'] ? $data['authorid'] : 0, 'middle', true, false, false, $_G['setting']['ucenterurl']), 'avatar_big' => avatar($data['author'] ? $data['authorid'] : 0, 'big', true, false, false, $_G['setting']['ucenterurl']), 'posts' => $data['posts'], 'todayposts' => $data['todayposts'], 'lastpost' => $data['lastpost'], 'dateline' => $data['dateline'], 'replies' => $data['replies'], 'icon' => $data['icon'] > 0 ? STATICURL . 'image/stamp/' . $_G['cache']['stamps'][$data['icon']]['url'] : '', 'forumurl' => 'forum.php?mod=forumdisplay&fid=' . $data['fid'], 'forumname' => $_G['cache']['forums'][$data['fid']]['name'], 'typename' => $threadtypes[$data['typeid']]['name'], 'typeicon' => $threadtypes[$data['typeid']]['icon'], 'typeurl' => 'forum.php?mod=forumdisplay&fid=' . $data['fid'] . '&filter=typeid&typeid=' . $data['typeid'], 'sortname' => $threadsorts[$data['sortid']]['name'], 'sorturl' => 'forum.php?mod=forumdisplay&fid=' . $data['fid'] . '&filter=sortid&sortid=' . $data['sortid'], 'views' => $data['views'], 'heats' => $data['heats'], 'recommends' => $data['recommends'], 'hourviews' => $data['views'], 'todayviews' => $data['views'], 'weekviews' => $data['views'], 'monthviews' => $data['views'])); if ($highlight && $data['highlight']) { $list[$data['tid']]['fields']['showstyle'] = $this->getthreadstyle($data['highlight']); } } if ($listtids) { $threads = $this->getthread($threadtids, $summarylength); if ($threads) { foreach ($threads as $tid => $var) { $list[$tid]['summary'] = $var; } } foreach ($listtids as $key => $value) { $datalist[] = $list[$value]; } } $returndata['data'] = $datalist; return $returndata; }
private function _searchData($kw, $page, $pagesize, $res, $searchid) { global $_G; $srchtype = 'title'; $orderby = 'lastpost'; $ascdesc = 'desc'; $srchtxt = $kw; $keyword = WebUtils::t(dhtmlspecialchars(trim($kw))); $_G['setting']['search']['forum']['searchctrl'] = intval($_G['setting']['search']['forum']['searchctrl']); require_once libfile('function/forumlist'); require_once libfile('function/forum'); require_once libfile('function/search'); require_once libfile('function/misc'); require_once libfile('function/post'); loadcache(array('forums', 'posttable_info')); $srchmod = 2; $cachelife_time = 300; $cachelife_text = 3600; $seltableid = 0; if (empty($searchid)) { //searchid 为空的时候就要通过拼接一个字符串来进行查找搜索缓存表了 if ($_G['group']['allowsearch'] & 32 && $srchtype == 'fulltext') { //全文搜索 //时间段设置检测 periodscheck('searchban0periods'); } elseif ($srchtype != 'title') { $srchtype = 'title'; } $forumsarray = array(); if (!empty($srchfid)) { foreach (is_array($srchfid) ? $srchfid : explode('_', $srchfid) as $forum) { if ($forum = intval(trim($forum))) { $forumsarray[] = $forum; } } } //取出板块的fid $fids = $comma = ''; foreach ($_G['cache']['forums'] as $fid => $forum) { if ($forum['type'] != 'group' && (!$forum['viewperm'] && $_G['group']['readaccess']) || $forum['viewperm'] && forumperm($forum['viewperm'])) { if (!$forumsarray || in_array($fid, $forumsarray)) { $fids .= "{$comma}'{$fid}'"; $comma = ','; } } } if ($_G['setting']['threadplugins'] && $specialplugin) { $specialpluginstr = implode("','", $specialplugin); $special[] = 127; } else { $specialpluginstr = ''; } $special = ''; $specials = $special ? implode(',', $special) : ''; $srchfilter = 'all'; //所有板块 //搜索缓存表 查找字符串 $srchuid = $srchuname = $srchfrom = $before = ''; $searchstring = 'forum|' . $srchtype . '|' . base64_encode($srchtxt) . '|' . intval($srchuid) . '|' . $srchuname . '|' . addslashes($fids) . '|' . intval($srchfrom) . '|' . intval($before) . '|' . $srchfilter . '|' . $specials . '|' . $specialpluginstr . '|' . $se0; $searchindex = array('id' => 0, 'dateline' => '0'); foreach (C::t('common_searchindex')->fetch_all_search($_G['setting']['search']['forum']['searchctrl'], $_G['clientip'], $_G['uid'], $_G['timestamp'], $searchstring, $srchmod) as $index) { if ($index['indexvalid'] && $index['dateline'] > $searchindex['dateline']) { $searchindex = array('id' => $index['searchid'], 'dateline' => $index['dateline']); break; } elseif ($_G['adminid'] != '1' && $index['flood']) { //抱歉,您在 秒内只能进行一次搜索 return WebUtils::makeErrorInfo_oldVersion($res, 'search_ctrl', array('searchctrl' => $_G['setting']['search']['forum']['searchctrl'])); } } if ($searchindex['id']) { $searchid = $searchindex['id']; } else { if ($_G['adminid'] != '1' && $_G['setting']['search']['forum']['maxspm']) { if (C::t('common_searchindex')->count_by_dateline($_G['timestamp'], $srchmod) >= $_G['setting']['search']['forum']['maxspm']) { //抱歉,站点设置每分钟系统最多响应搜索请求 {maxspm} 次,请稍候再试 return WebUtils::makeErrorInfo_oldVersion($res, 'search_toomany', array('maxspm' => $_G['setting']['search']['forum']['maxspm'])); } } $digestltd = $srchfilter == 'digest' ? "t.digest>'0' AND" : ''; $topltd = $srchfilter == 'top' ? "AND t.displayorder>'0'" : "AND t.displayorder>='0'"; $sqlsrch = $srchtype == 'fulltext' ? "FROM " . DB::table(getposttable($seltableid)) . " p, " . DB::table('forum_thread') . " t WHERE {$digestltd} t.fid IN ({$fids}) {$topltd} AND p.tid=t.tid AND p.invisible='0'" : "FROM " . DB::table('forum_thread') . " t WHERE {$digestltd} t.fid IN ({$fids}) {$topltd}"; if ($srchtxt) { $srcharr = $srchtype == 'fulltext' ? searchkey($keyword, "(p.message LIKE '%{text}%' OR p.subject LIKE '%{text}%')", true) : searchkey($keyword, "t.subject LIKE '%{text}%'", true); $srchtxt = $srcharr[0]; $sqlsrch .= $srcharr[1]; } $keywords = str_replace('%', '+', $srchtxt); $expiration = TIMESTAMP + $cachelife_text; $num = $ids = 0; $_G['setting']['search']['forum']['maxsearchresults'] = $_G['setting']['search']['forum']['maxsearchresults'] ? intval($_G['setting']['search']['forum']['maxsearchresults']) : 500; $query = DB::query("SELECT " . ($srchtype == 'fulltext' ? 'DISTINCT' : '') . " t.tid, t.closed, t.author, t.authorid {$sqlsrch} ORDER BY tid DESC LIMIT " . $_G['setting']['search']['forum']['maxsearchresults']); while ($thread = DB::fetch($query)) { $ids .= ',' . $thread['tid']; $num++; } DB::free_result($query); $idsArr = explode(',', $ids); $idCount = count($idsArr); if ($idCount == 1) { return WebUtils::makeErrorInfo_oldVersion($res, 'search_no_results'); } $searchid = C::t('common_searchindex')->insert(array('srchmod' => $srchmod, 'keywords' => $keywords, 'searchstring' => $searchstring, 'useip' => $_G['clientip'], 'uid' => $_G['uid'], 'dateline' => $_G['timestamp'], 'expiration' => $expiration, 'num' => $num, 'ids' => $ids), true); !($_G['group']['exempt'] & 2) && updatecreditbyaction('search'); } } //这个分支要把数据取出来,并且返回正确的数据结构 $start_limit = ($page - 1) * $pagesize; $index = C::t('common_searchindex')->fetch_by_searchid_srchmod($searchid, $srchmod); if (!$index) { //showmessage('search_id_invalid');//指定的搜索不存在或已过期 return WebUtils::makeErrorInfo_oldVersion($res, 'search_id_invalid'); } $keyword = dhtmlspecialchars($index['keywords']); $keyword = $keyword != '' ? str_replace('+', ' ', $keyword) : ''; $index['keywords'] = rawurlencode($index['keywords']); $searchstring = explode('|', $index['searchstring']); $index['searchtype'] = $searchstring[0]; $searchstring[2] = base64_decode($searchstring[2]); $srchuname = $searchstring[3]; $modfid = 0; if ($keyword) { $modkeyword = str_replace(' ', ',', $keyword); $fids = explode(',', str_replace('\'', '', $searchstring[5])); if (count($fids) == 1 && in_array($_G['adminid'], array(1, 2, 3))) { $modfid = $fids[0]; if ($_G['adminid'] == 3 && !C::t('forum_moderator')->fetch_uid_by_fid_uid($modfid, $_G['uid'])) { $modfid = 0; } } } $threadlist = $posttables = array(); foreach (C::t('forum_thread')->fetch_all_by_tid_fid_displayorder(explode(',', $index['ids']), null, 0, $orderby, $start_limit, $pagesize, '>=', $ascdesc, 0) as $thread) { $thread['subject'] = bat_highlight($thread['subject'], $keyword); $thread['realtid'] = $thread['isgroup'] == 1 ? $thread['closed'] : $thread['tid']; $tempLastPost = $thread['lastpost']; $tempDateLine = $thread['dateline']; $threadlist[$thread['tid']] = procthread($thread, 'dt'); $threadlist[$thread['tid']]['lastpost'] = $tempLastPost; $threadlist[$thread['tid']]['dateline'] = $tempDateLine; $posttables[$thread['posttableid']][] = $thread['tid']; } if ($threadlist) { foreach ($posttables as $tableid => $tids) { foreach (C::t('forum_post')->fetch_all_by_tid($tableid, $tids, true, '', 0, 0, 1) as $post) { $threadlist[$post['tid']]['message'] = bat_highlight(messagecutstr($post['message'], 200), $keyword); } } } $pageInfo = $row = $rows = array(); $rows = $this->_fieldInfo($threadlist); $pageInfo = WebUtils::getWebApiArrayWithPage_oldVersion($page, $pagesize, $index['num']); $res = array_merge($res, $pageInfo); $res['searchid'] = (int) $searchid; $res['list'] = $rows; return $res; }