public function search()
{
$k = t($_REQUEST['k']);
$this->setTitle('搜索' . $k);
$this->setKeywords('搜索' . $k);
$this->setDescription('搜索' . $k);
// //微吧推荐
// $this->_weiba_recommend(9,50,50);
// //微吧排行榜
// $this->_weibaOrder();
//微吧达人
$daren_arr = $this->_weiba_daren();
$this->assign('daren_arr', $daren_arr);
//帖子推荐
$post_recommend_list = $this->_post_list('recommend', 10);
$this->assign('post_recommend_list', $post_recommend_list);
$this->assign('nav', 'search');
if ($k == '') {
if ($_REQUEST['type'] == '1') {
$this->display('search_weiba');
} else {
$this->display('search_post');
}
exit;
}
$_POST['k'] && ($_SERVER['QUERY_STRING'] = $_SERVER['QUERY_STRING'] . '&k=' . $k);
$this->assign('searchkey', $k);
$map['is_del'] = 0;
$map['status'] = 1;
if ($_REQUEST['type'] == '1') {
//搜微吧
$map['weiba_name'] = array('like', '%' . $k . '%');
//$where['intro'] = array('like','%'.$k.'%');
//$where['_logic'] = 'or';
//$map['_complex'] = $where;
$weibaList = D('weiba')->where($map)->findPage(10);
if ($weibaList['data']) {
foreach ($weibaList['data'] as $k => $v) {
$weibaList['data'][$k]['logo'] = getImageUrlByAttachId($v['logo'], 100, 100);
}
$weiba_ids = getSubByKey($weibaList['data'], 'weiba_id');
$this->_assignFollowState($weiba_ids);
$this->assign('weibaList', $weibaList);
} else {
//微吧推荐
$this->_weiba_recommend(9, 50, 50);
}
$this->display('search_weiba');
} else {
//搜帖子
$map['weiba_id'] = array('in', getSubByKey(D('weiba')->where('is_del=0')->field('weiba_id')->findAll(), 'weiba_id'));
$map['title'] = array('like', '%' . $k . '%');
//$where['content'] = array('like','%'.$k.'%');
//$where['_logic'] = 'or';
//$map['_complex'] = $where;
$post_list = D('weiba_post')->where($map)->order('post_time desc')->findPage(20);
if ($post_list['data']) {
$weiba_ids = getSubByKey($post_list['data'], 'weiba_id');
$nameArr = $this->_getWeibaName($weiba_ids);
foreach ($post_list['data'] as $k => $v) {
$post_list['data'][$k]['weiba'] = $nameArr[$v['weiba_id']];
$post_list['data'][$k]['user'] = model('User')->getUserInfo($v['post_uid']);
$post_list['data'][$k]['replyuser'] = model('User')->getUserInfo($v['last_reply_uid']);
$images = matchImages($v['content']);
$images[0] && ($post_list['data'][$k]['image'] = array_slice($images, 0, 5));
/* 解析emoji */
$post_list['data'][$k]['title'] = formatEmoji(false, $v['title']);
$post_list['data'][$k]['content'] = formatEmoji(false, $v['content']);
}
$this->assign('post_list', $post_list);
} else {
//微吧推荐
$this->_weiba_recommend(9, 50, 50);
}
$this->display('search_post');
}
}