$start_limit = ($page - 1) * $_G['tpp'];
     $index = C::t('common_searchindex')->fetch_by_searchid_srchmod($searchid, $srchmod);
     if (!$index) {
         showmessage('search_id_invalid');
     }
     $keyword = dhtmlspecialchars($index['keywords']);
     $keyword = $keyword != '' ? str_replace('+', ' ', $keyword) : '';
     $index['keywords'] = rawurlencode($index['keywords']);
     require_once libfile('function/discuzcode');
     $collectionlist = array();
     $maxcollection = $nowcollection = 0;
     $query = C::t('forum_collection')->fetch_all(explode(',', $index['ids']), $orderby, $ascdesc, $start_limit, $_G['tpp']);
     foreach ($query as $value) {
         $value['lastupdate'] = dgmdate($value['lastupdate']);
         $value['shortdesc'] = cutstr(strip_tags(discuzcode($value['desc'])), 50);
         $value['name'] = bat_highlight($value['name'], $keyword);
         $collectionlist[$value['ctid']] = $value;
     }
     $multipage = multi($index['num'], $_G['tpp'], $page, "search.php?mod=collection&searchid={$searchid}&orderby={$orderby}&ascdesc={$ascdesc}&searchsubmit=yes");
     $url_forward = 'search.php?mod=collection&' . $_SERVER['QUERY_STRING'];
     include template('search/collection');
 } else {
     $searchstring = 'collection|title|' . addslashes($srchtxt);
     $searchindex = array('id' => 0, 'dateline' => '0');
     foreach (C::t('common_searchindex')->fetch_all_search($_G['setting']['search']['collection']['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']) {
             showmessage('search_ctrl', 'search.php?mod=collection', array('searchctrl' => $_G['setting']['search']['collection']['searchctrl']));
         }
Example #2
0
     $page = max(1, intval($_G['gp_page']));
     $start_limit = ($page - 1) * $_G['tpp'];
     $index = DB::fetch_first("SELECT searchstring, keywords, num, ids FROM " . DB::table('common_searchindex') . " WHERE searchid='{$searchid}' AND srchmod='{$srchmod}'");
     if (!$index) {
         showmessage('search_id_invalid');
     }
     $keyword = htmlspecialchars($index['keywords']);
     $keyword = $keyword != '' ? str_replace('+', ' ', $keyword) : '';
     $index['keywords'] = rawurlencode($index['keywords']);
     $articlelist = array();
     $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 at.aid IN ({$index['ids']}) ORDER BY {$orderby} {$ascdesc} LIMIT {$start_limit}, {$_G['tpp']}");
     while ($article = DB::fetch($query)) {
         $article['dateline'] = dgmdate($article['dateline']);
         $article['pic'] = pic_get($article['pic'], 'portal', $article['thumb'], $article['remote']);
         $article['title'] = bat_highlight($article['title'], $keyword);
         $article['summary'] = bat_highlight($article['summary'], $keyword);
         $articlelist[] = $article;
     }
     $multipage = multi($index['num'], $_G['tpp'], $page, "search.php?mod=portal&searchid={$searchid}&orderby={$orderby}&ascdesc={$ascdesc}&searchsubmit=yes");
     $url_forward = 'search.php?mod=portal&' . $_SERVER['QUERY_STRING'];
     include template('search/portal');
 } else {
     !($_G['group']['exempt'] & 2) && checklowerlimit('search');
     $searchstring = 'portal|title|' . addslashes($srchtxt);
     $searchindex = array('id' => 0, 'dateline' => '0');
     $query = DB::query("SELECT searchid, dateline,\r\n\t\t\t('" . $_G['setting']['search']['portal']['searchctrl'] . "'<>'0' AND " . (empty($_G['uid']) ? "useip='{$_G['clientip']}'" : "uid='{$_G['uid']}'") . " AND {$_G['timestamp']}-dateline<'" . $_G['setting']['search']['portal']['searchctrl'] . "') AS flood,\r\n\t\t\t(searchstring='{$searchstring}' AND expiration>'{$_G['timestamp']}') AS indexvalid\r\n\t\t\tFROM " . DB::table('common_searchindex') . "\r\n\t\t\tWHERE srchmod='{$srchmod}' AND ('" . $_G['setting']['search']['portal']['searchctrl'] . "'<>'0' AND " . (empty($_G['uid']) ? "useip='{$_G['clientip']}'" : "uid='{$_G['uid']}'") . " AND {$_G['timestamp']}-dateline<" . $_G['setting']['search']['portal']['searchctrl'] . ") OR (searchstring='{$searchstring}' AND expiration>'{$_G['timestamp']}')\r\n\t\t\tORDER BY flood");
     while ($index = DB::fetch($query)) {
         if ($index['indexvalid'] && $index['dateline'] > $searchindex['dateline']) {
             $searchindex = array('id' => $index['searchid'], 'dateline' => $index['dateline']);
             break;
         } elseif ($_G['adminid'] != '1' && $index['flood']) {
Example #3
0
             }
         }
     }
     $threadlist = $posttables = array();
     $query = DB::query("SELECT * FROM " . DB::table('forum_thread') . " WHERE tid IN ({$index['ids']}) AND displayorder>='0' ORDER BY {$orderby} {$ascdesc} LIMIT {$start_limit}, {$_G['tpp']}");
     while ($thread = DB::fetch($query)) {
         $thread['subject'] = bat_highlight($thread['subject'], $keyword);
         $thread['realtid'] = $thread['isgroup'] == 1 ? $thread['closed'] : $thread['tid'];
         $threadlist[$thread['tid']] = procthread($thread, 'dt');
         $posttables[$thread['posttableid']][] = $thread['tid'];
     }
     if ($threadlist) {
         foreach ($posttables as $tableid => $tids) {
             $query = DB::query("SELECT tid, message FROM " . DB::table(getposttable($tableid)) . " WHERE tid IN (" . dimplode($tids) . ") AND first='1'");
             while ($post = DB::fetch($query)) {
                 $threadlist[$post['tid']]['message'] = bat_highlight(messagecutstr($post['message'], 200), $keyword);
             }
         }
     }
     $multipage = multi($index['num'], $_G['tpp'], $page, "search.php?mod=forum&searchid={$searchid}&orderby={$orderby}&ascdesc={$ascdesc}&searchsubmit=yes");
     $url_forward = 'search.php?mod=forum&' . $_SERVER['QUERY_STRING'];
     $fulltextchecked = $searchstring[1] == 'fulltext' ? 'checked="checked"' : '';
     include template('search/forum');
 } else {
     if ($_G['group']['allowsearch'] & 32 && $srchtype == 'fulltext') {
         periodscheck('searchbanperiods');
     } elseif ($srchtype != 'title') {
         $srchtype = 'title';
     }
     $forumsarray = array();
     if (!empty($srchfid)) {
Example #4
0
     }
     $keyword = htmlspecialchars($index['keywords']);
     $keyword = $keyword != '' ? str_replace('+', ' ', $keyword) : '';
     $index['keywords'] = rawurlencode($index['keywords']);
     $bloglist = array();
     $pricount = 0;
     $query = DB::query("SELECT b.*,bf.pic, bf.message FROM " . DB::table('home_blog') . " b LEFT JOIN " . DB::table('home_blogfield') . " bf ON bf.blogid=b.blogid WHERE b.blogid IN({$index['ids']}) ORDER BY b.blogid DESC LIMIT {$start_limit}, {$_G['tpp']}");
     while ($value = DB::fetch($query)) {
         if (ckfriend($value['uid'], $value['friend'], $value['target_ids']) && ($value['status'] == 0 || $value['uid'] == $_G['uid'] || $_G['adminid'] == 1)) {
             if ($value['friend'] == 4) {
                 $value['message'] = $value['pic'] = '';
             } else {
                 $value['message'] = bat_highlight($value['message'], $keyword);
                 $value['message'] = getstr($value['message'], 255, 0, 0, 0, -1);
             }
             $value['subject'] = bat_highlight($value['subject'], $keyword);
             $value['dateline'] = dgmdate($value['dateline']);
             $value['pic'] = pic_cover_get($value['pic'], $value['picflag']);
             $bloglist[] = $value;
         } else {
             $pricount++;
         }
     }
     $multipage = multi($index['num'], $_G['tpp'], $page, "search.php?mod=blog&searchid={$searchid}&orderby={$orderby}&ascdesc={$ascdesc}&searchsubmit=yes");
     $url_forward = 'search.php?mod=blog&' . $_SERVER['QUERY_STRING'];
     include template('search/blog');
 } else {
     $searchstring = 'blog|title|' . addslashes($srchtxt);
     $searchindex = array('id' => 0, 'dateline' => '0');
     $query = DB::query("SELECT searchid, dateline,\r\n\t\t\t('" . $_G['setting']['search']['blog']['searchctrl'] . "'<>'0' AND " . (empty($_G['uid']) ? "useip='{$_G['clientip']}'" : "uid='{$_G['uid']}'") . " AND {$_G['timestamp']}-dateline<'" . $_G['setting']['search']['blog']['searchctrl'] . "') AS flood,\r\n\t\t\t(searchstring='{$searchstring}' AND expiration>'{$_G['timestamp']}') AS indexvalid\r\n\t\t\tFROM " . DB::table('common_searchindex') . "\r\n\t\t\tWHERE srchmod='{$srchmod}' AND ('" . $_G['setting']['search']['blog']['searchctrl'] . "'<>'0' AND " . (empty($_G['uid']) ? "useip='{$_G['clientip']}'" : "uid='{$_G['uid']}'") . " AND {$_G['timestamp']}-dateline<" . $_G['setting']['search']['blog']['searchctrl'] . ") OR (searchstring='{$searchstring}' AND expiration>'{$_G['timestamp']}')\r\n\t\t\tORDER BY flood");
     while ($index = DB::fetch($query)) {
Example #5
0
                 while ($post = DB::fetch($query)) {
                     $threadlist[$post['tid']]['message'] = bat_highlight(messagecutstr($post['message'], 200), $keyword);
                 }
             }
         }
     }
     $groupnum = !empty($index['ids']['group']) ? count(explode(',', $index['ids']['group'])) - 1 : 0;
     if ($index['ids']['group'] && ($viewgroup || empty($searchstring[2]))) {
         if (empty($viewgroup)) {
             $index['ids']['group'] = implode(',', array_slice(explode(',', $index['ids']['group']), 0, 9));
         }
         $query = DB::query("SELECT f.*, ff.description, ff.membernum, ff.icon, ff.gviewperm, ff.jointype, ff.dateline FROM " . DB::table('forum_forum') . " f LEFT JOIN " . DB::table('forum_forumfield') . " ff ON f.fid=ff.fid WHERE f.fid IN ({$index[ids][group]}) AND f.status='3' AND `type`='sub'" . ($viewgroup ? " LIMIT {$start_limit}, {$_G['tpp']}" : ''));
         while ($group = DB::fetch($query)) {
             $group['icon'] = get_groupimg($group['icon'], 'icon');
             $group['name'] = bat_highlight($group['name'], $keyword);
             $group['description'] = bat_highlight($group['description'], $keyword);
             $group['dateline'] = dgmdate($group['dateline'], 'u');
             $grouplist[] = $group;
         }
     }
     if (empty($viewgroup)) {
         $multipage = multi($index['num'], $_G['tpp'], $page, "search.php?mod=group&searchid={$searchid}&orderby={$orderby}&ascdesc={$ascdesc}&searchsubmit=yes" . ($viewgroup ? '&viewgroup=1' : ''));
     } else {
         $multipage = multi($groupnum, $_G['tpp'], $page, "search.php?mod=group&searchid={$searchid}&orderby={$orderby}&ascdesc={$ascdesc}&searchsubmit=yes" . ($viewgroup ? '&viewgroup=1' : ''));
     }
     $url_forward = 'search.php?mod=group&' . $_SERVER['QUERY_STRING'];
     include template('search/group');
 } else {
     $srchuname = isset($_G['gp_srchuname']) ? trim($_G['gp_srchuname']) : '';
     $searchstring = 'group|title|' . $srchfid . '|' . addslashes($srchtxt);
     $searchindex = array('id' => 0, 'dateline' => '0');
Example #6
0
            if ($_G['adminid'] == 3 && !C::t('forum_moderator')->fetch_uid_by_fid_uid($modfid, $_G['uid'])) {
                $modfid = 0;
            }
        }
    }
    $todaytime = strtotime(dgmdate(TIMESTAMP, 'Ymd'));
    $threadlist = array();
    $tids = explode(',', $index['ids']);
    $threads = C::t('forum_thread')->fetch_all_by_tid($tids, $start_limit, $_G['tpp']);
    //tids是有序的,但是查出来的threads是无序的。
    foreach ($tids as $tid) {
        foreach ($threads as $thread) {
            if ($thread['tid'] != $tid) {
                continue;
            }
            $thread['subject'] = bat_highlight($thread['subject'], $keyword);
            $thread['realtid'] = $thread['isgroup'] == 1 ? $thread['closed'] : $thread['tid'];
            $thread['allreplies'] = $thread['replies'] + $thread['comments'];
            $threadlist[] = procthread($thread, 'dt');
            break;
        }
    }
    $multipage = multi($index['num'], $_G['tpp'], $page, "source/plugin/ngpt/search.php?" . "mod=seed&" . "searchid={$searchid}&" . "orderby={$orderby}&" . "ascdesc={$ascdesc}&" . "searchsubmit=yes&" . "kw=" . urlencode($keyword) . "&author={$author}&" . "oblue={$onlyblue}&" . "nodead={$nodead}");
    $url_forward = 'search.php?mod=forum&' . $_SERVER['QUERY_STRING'];
    $fulltextchecked = $searchstring[1] == 'fulltext' ? 'checked="checked"' : '';
    $_G['forum_threadlist'] = $threadlist;
    $_G['forum_threadcount'] = count($threadlist);
    include template('search/seed-main');
} else {
    $orderby = in_array($_GET['orderby'], array('dateline', 'replies', 'views')) ? $_GET['orderby'] : 'lastpost';
    $ascdesc = isset($_GET['ascdesc']) && $_GET['ascdesc'] == 'asc' ? 'asc' : 'desc';
 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;
 }