function list_by_qid($qid, $ordertype = 1, $rownum = 0, $start = 0, $limit = 10) { $answerlist = array(); $already = 0; if (1 == $ordertype) { $timeorder = 'ASC'; $floor = $start + 1; } else { $timeorder = 'DESC'; $floor = $start ? $rownum - $start : $rownum; } $query = $this->db->query("SELECT * FROM " . DB_TABLEPRE . "answer WHERE qid={$qid} AND status>0 AND adopttime =0 ORDER BY supports DESC,time {$timeorder} LIMIT {$start},{$limit}"); while ($answer = $this->db->fetch_array($query)) { if ($answer['authorid'] == $this->base->user['uid']) { $already = 1; } $answer['floor'] = $floor; $answer['time'] = tdate($answer['time']); $answer['ip'] = formatip($answer['ip']); $answer['author_avartar'] = get_avatar_dir($answer['authorid']); $answer['appends'] = $this->get_appends($answer['id']); $answerlist[] = $answer; if (1 == $floor) { $floor++; } else { $floor--; } } return array($answerlist, $already); }
function get_by_cid($cid, $start = 0, $limit = 10) { $expertlist = array(); $query = $cid == 'all' ? $this->db->query("SELECT * FROM " . DB_TABLEPRE . "user WHERE uid IN (SELECT uid FROM " . DB_TABLEPRE . "expert) ORDER BY answers DESC LIMIT {$start},{$limit}") : $this->db->query("SELECT * FROM " . DB_TABLEPRE . "user WHERE uid IN (SELECT uid FROM " . DB_TABLEPRE . "expert WHERE cid={$cid}) ORDER BY answers DESC LIMIT {$start},{$limit}"); while ($expert = $this->db->fetch_array($query)) { $expert['avatar'] = get_avatar_dir($expert['uid']); $expertlist[] = $expert; } return $expertlist; }
function get_by_aid($aid, $start = 0, $limit = 10) { $commentlist = array(); $query = $this->db->query("SELECT * FROM `" . DB_TABLEPRE . "answer_comment` WHERE aid={$aid} ORDER BY `time` DESC limit {$start},{$limit}"); while ($comment = $this->db->fetch_array($query)) { $comment['avatar'] = get_avatar_dir($comment['authorid']); $comment['format_time'] = tdate($comment['time']); $commentlist[] = $comment; } return $commentlist; }
function get_by_noteid($noteid, $start = 0, $limit = 10) { $commentlist = array(); $query = $this->db->query("SELECT * FROM " . DB_TABLEPRE . "note_comment WHERE noteid='{$noteid}' ORDER BY `time` DESC LIMIT {$start},{$limit}"); while ($comment = $this->db->fetch_array($query)) { $comment['avatar'] = get_avatar_dir($comment['authorid']); $comment['format_time'] = tdate($comment['time']); $commentlist[] = $comment; } return $commentlist; }
function get_list($answersize = 3, $start = 0, $limit = 3) { $famouslist = array(); $query = $this->db->query("SELECT u.uid,u.username,u.questions,u.answers,u.signature,u.credit1,u.credit2,u.credit3,f.id,f.reason,f.time FROM " . DB_TABLEPRE . "famous as f," . DB_TABLEPRE . "user as u WHERE f.uid=u.uid ORDER BY f.id DESC LIMIT {$start} ,{$limit}"); while ($famous = $this->db->fetch_array($query)) { $famous['avatar'] = get_avatar_dir($famous['uid']); $famous['time'] = tdate($famous['time']); $famous['bestanswer'] = $this->get_solve_answer($famous['uid'], 0, $answersize); $famouslist[] = $famous; } return $famouslist; }
function list_by_fromuid($fromuid, $start = 0, $limit = 10) { $messagelist = array(); $sql = "SELECT * FROM " . DB_TABLEPRE . "message WHERE fromuid<>touid AND ((fromuid={$fromuid} AND touid=" . $this->base->user['uid'] . ") AND status IN (0,1)) OR ((fromuid=" . $this->base->user['uid'] . " AND touid=" . $fromuid . ") AND status IN (0,2)) ORDER BY time DESC LIMIT {$start},{$limit}"; $query = $this->db->query($sql); while ($message = $this->db->fetch_array($query)) { $message['format_time'] = tdate($message['time']); $message['from_avatar'] = get_avatar_dir($message['fromuid']); $message['touser'] = $this->db->result_first("SELECT username FROM " . DB_TABLEPRE . "user WHERE uid=" . $message['touid']); $messagelist[] = $message; } return $messagelist; }
/** * 推荐关注用户 */ function recommend_user($limit = 6) { $this->base->load("user"); $userlist = array(); $usercount = $this->db->fetch_total("user", " 1=1"); if ($usercount > 100) { $usercount = 101; } $start = rand(0, $usercount - 1); $loginuid = $this->base->user['uid']; $query = $this->db->query("SELECT * FROM " . DB_TABLEPRE . "user WHERE uid<>{$loginuid} AND uid NOT IN (SELECT uid FROM " . DB_TABLEPRE . "user_attention WHERE followerid={$loginuid}) ORDER BY followers DESC,answers DESC,regtime DESC LIMIT {$start},{$limit} "); while ($user = $this->db->fetch_array($query)) { $user['avatar'] = get_avatar_dir($user['uid']); $user['category'] = $_ENV['user']->get_category($user['uid']); $userlist[] = $user; } return $userlist; }
function get_attention($followerid, $start = 0, $limit = 20) { $attentionlist = array(); $query = $this->db->query("SELECT u.uid,u.username FROM " . DB_TABLEPRE . "user_attention AS ua," . DB_TABLEPRE . "user AS u WHERE ua.uid=u.uid AND ua.followerid={$followerid} ORDER BY ua.time DESC LIMIT {$start},{$limit}"); while ($attention = $this->db->fetch_array($query)) { $attention['avatar'] = get_avatar_dir($attention['uid']); $attentionlist[] = $attention; } return $attentionlist; }
function get_follower($qid, $start = 0, $limit = 16) { $followerlist = array(); $query = $this->db->query("SELECT * FROM " . DB_TABLEPRE . "question_attention WHERE qid={$qid} ORDER BY `time` DESC LIMIT {$start},{$limit}"); while ($follower = $this->db->fetch_array($query)) { $follower['avatar'] = get_avatar_dir($follower['followerid']); $followerlist[] = $follower; } return $followerlist; }
function init_user() { @($sid = tcookie('sid')); @($auth = tcookie('auth')); $user = array(); @(list($uid, $password) = empty($auth) ? array(0, 0) : taddslashes(explode("\t", authcode($auth, 'DECODE')), 1)); if (!$sid) { $sid = substr(md5(time() . $this->ip . random(6)), 16, 16); tcookie('sid', $sid, 31536000); } $this->load('user'); if ($uid && $password) { $user = $_ENV['user']->get_by_uid($uid, 0); $password != $user['password'] && ($user = array()); } if (!$user) { $user['uid'] = 0; $user['groupid'] = 6; } $_ENV['user']->refresh_session_time($sid, $user['uid']); $user['sid'] = $sid; $user['ip'] = $this->ip; $user['uid'] && ($user['loginuser'] = $user['username']); $user['uid'] && ($user['avatar'] = get_avatar_dir($user['uid'])); $this->user = array_merge($user, $this->usergroup[$user['groupid']]); }