function mythread_find_by_uid($uid, $page = 1, $pagesize = 20) { $mylist = mythread_find(array('uid' => $uid), array('tid' => -1), $page, $pagesize); if (empty($mylist)) { return array(); } $threadlist = array(); foreach ($mylist as &$mythread) { $threadlist[$mythread['tid']] = thread_read($mythread['tid']); } return $threadlist; }
function myagree_find_pids_by_uid($uid, $page = 1, $pagesize = 20) { $mylist = myagree_find(array('uid' => $uid), array('pid' => -1), $page, $pagesize); if (empty($mylist)) { return array(); } $threadlist = array(); foreach ($mylist as &$myagree) { $thread = thread_read($myagree['pid']); $thread['create_date_fmt'] = humandate($myagree['create_date']); $threadlist[$myagree['pid']] = $thread; } return $threadlist; }
} $arr and thread_update($tid, $arr) === FALSE and message(-1, '更新主题失败'); } $r = post_update($pid, array('message' => $message)); $r === FALSE and message(-1, '更新帖子失败'); message(0, array('pid' => $pid, 'subject' => $subject, 'message' => $message)); } } elseif ($action == 'delete') { $pid = param(2, 0); if ($method != 'POST') { message(-1, '方法不对'); } $post = post_read($pid); empty($post) and message(-1, '帖子不存在:' . $pid); $tid = $post['tid']; $thread = thread_read($tid); empty($thread) and message(-1, '主题不存在:' . $tid); $fid = $thread['fid']; $forum = forum_read($fid); empty($forum) and message(-1, '板块不存在:' . $fid); $isfirst = $post['isfirst']; !forum_access_user($fid, $gid, 'allowpost') and message(-1, '您(' . $user['groupname'] . ')无权限在此版块回帖'); $allowdelete = forum_access_mod($fid, $gid, 'allowdelete'); !$allowdelete and !$post['allowdelete'] and message(-1, '无权删除该帖'); if ($isfirst) { // 清除所有的回复。喜欢。还有相关资源 thread_delete($tid); } else { post_delete($pid); post_list_cache_delete($tid); }
function thread_read_by_seo_url($url) { $url = addslashes($url); $tid = thread_url_read_by_url($url); $thread = $tid ? thread_read($tid) : array(); return $thread; }
function sphinx_search($keyword) { $fid = 0; $daterange = 0; $orderby = 'match'; $page = 1; $pagesize = 60; global $conf, $time; $cl = new SphinxClient(); $cl->SetServer($conf['sphinx_host'], $conf['sphinx_port']); $cl->SetConnectTimeout(3); $cl->SetArrayResult(TRUE); $cl->SetWeights(array(100, 1, 5)); // 标题权重100,内容权重1,作者权重10 $fid && $cl->SetFilter('fid', array($fid)); $daterange && $cl->setFilterRange('dateline', $time - $daterange * 86400, $time); $cl->SetMatchMode(SPH_MATCH_ALL); if ($orderby == 'match') { $cl->SetSortMode(SPH_SORT_RELEVANCE); // 如果不设置,默认按照权重排序!但是TMD是正序! } elseif ($orderby == 'timeasc') { $cl->SetSortMode(SPH_SORT_ATTR_ASC, 'tid'); } elseif ($orderby == 'timedesc') { $cl->SetSortMode(SPH_SORT_ATTR_DESC, 'tid'); } //$cl->SetSortMode (SPH_SORT_ATTR_DESC, 'tid'); // 如果不设置,默认按照权重排序!但是TMD是正序! /* $cl->SetMatchMode ( SPH_MATCH_EXTENDED ); //设置模式 $cl->SetRankingMode ( SPH_RANK_PROXIMITY ); //设置评分模式 $cl->SetFieldWeights (array('subject'=>100,'message'=>10,'username'=>1));//设置字段的权重,如果area命中,那么权重算2 $cl->SetSortMode ('SPH_SORT_EXPR','@weight'); //按照权重排序 */ // --------------> 优先搜索增量索引 $newlist = array(); $forums = array(); if ($page == 1) { $cl->SetLimits(0, $pagesize, 1000); // 最大结果集 $res = $cl->Query($keyword, $conf['sphinx_deltasrc']); // * 为所有的索引 if (!empty($cl->_error)) { return xn_error(-1, 'Sphinx 错误:' . $cl->_error); } if (!empty($res) && !empty($res['total'])) { $deltamatch = $res['matches']; } $res['matches'] && arrlist_change_key($res['matches'], 'id'); $newlist = array(); $forums = array(); foreach ((array) $res['matches'] as $v) { if (empty($v['attrs'])) { continue; } if (empty($v['attrs']['fid'])) { continue; } $fid = $v['attrs']['fid']; $thread = thread_read($v['attrs']['tid']); if (empty($thread)) { continue; } if (stripos($thread['subject'], $keyword) === FALSE) { continue; } $thread['subject'] = str_replace($keyword, '<span class="red">' . $keyword . '</span>', $thread['subject']); $newlist[] = $thread; } } // --------------> 再搜索主索引 $start = ($page - 1) * $pagesize; $cl->SetLimits($start, $pagesize, 1000); // 最大结果集 $res = $cl->Query($keyword, $conf['sphinx_datasrc']); if (!empty($cl->_error)) { return xn_error(-1, 'Sphinx 错误:' . $cl->_error); } if (empty($res) || empty($res['total'])) { $res['matches'] = $deltamatch; } else { arrlist_change_key($res['matches'], 'id'); } $threadlist = array(); foreach ((array) $res['matches'] as $v) { if (empty($v['attrs'])) { continue; } if (empty($v['attrs']['fid'])) { continue; } $fid = $v['attrs']['fid']; $thread = thread_read($v['attrs']['tid']); if (empty($thread)) { continue; } $thread['subject'] = str_replace($keyword, '<span class="red">' . $keyword . '</span>', $thread['subject']); $threadlist[] = $thread; } $arrlist = $newlist + $threadlist; return $arrlist; }