/** * 根据用户ID获取回收站联系人列表 * @param int $user_id 用户ID * @param int $offset 开始记录数 * @param int $limit 获取记录数 * @return array */ public function get_recycled_list($user_id, $offset = 0, $limit = 5000) { $cols = Contact::get_list_fields(FALSE, TRUE); $table = $this->get_table($user_id, 'contacts_recycled'); $sql = sprintf("SELECT %s FROM %s WHERE uid = %d ORDER BY modified DESC LIMIT %d,%d", implode(',', Contact::get_list_fields(TRUE, TRUE)), $table, $user_id, $offset, $limit); $query = $this->db->query($sql); $result = array(); if ($query->count()) { //获取电话数据 $tels = $this->get_info_list($user_id, NULL, 'tels', FALSE, TRUE, array('recycled_id') + Contact::$allow_cols['tels']); $tels_data = array(); foreach ($tels as $tel) { $recycled_id = $tel['recycled_id']; unset($tel['recycled_id']); $tels_data[$recycled_id][] = $tel; } $rows = $query->result_array(FALSE); foreach ($rows as $row) { $data = array(); foreach ($cols as $col) { switch ($col) { case 'id': $data['id'] = (int) $row['recycled_id']; break; case 'modified_at': $data['modified_at'] = $row['modified'] ? (int) $row['modified'] : (int) $row['created']; break; case 'source': $data['source'] = is_numeric($row['source']) ? api::get_source_name($row['source']) : $row['source']; break; case 'tels': $data['tels'] = isset($tels_data[$row['recycled_id']]) ? $tels_data[$row['recycled_id']] : array(); break; default: $data[$col] = $row[$col]; break; } } $result[(int) $row['recycled_id']] = $data; } } return $result; }
/** * 获取来源名称 * @return string */ public function get_source_name() { static $source_name; if (empty($source_name)) { $source_name = $this->phone_model ? $this->phone_model : api::get_source_name($this->source); } return $source_name; }
public function client_from($id) { $id = is_numeric($id) ? $id : 0; return api::get_source_name($id); }
public function saveComment($status_id, $content, $feed_uid, $client_id = 0, $reply_commentid = 0, $uid = 0, $group_member = array()) { $this->at2id = array(); $comment_at = array(); $isall = 0; if (strpos($content, '@全部成员(0)') !== false) { $isall = 1; } $addfeed = new Feed_Model(); $doc = $addfeed->findFeed($status_id); $this->group_id = (int) $doc['group_id']; $content = preg_replace_callback('#\\b(https?)://[-A-Z0-9+&\\#/%?=~_|!:,.;]*[-A-Z0-9+&\\#/%=~_|]#i', array($this, 'bulid_hyperlinks'), $content); $content = preg_replace_callback('/@([^@]+?)\\(([0-9]*)\\)/', array($this, 'bulid_user_hyperlinks'), $content); $comment_at = $this->at2id; $time = time(); $typeid = 4; $feed_uid = $doc['owner_uid']; $uid = $uid == 0 ? $this->uid : $uid; $content_link = $addfeed->atLink($content, $this->at2id); $m = new MongoClient(Kohana::config('uap.mongodb')); $comment_id = md5($status_id . '_' . $feed_uid . '_' . microtime()); $addTime = microtime(true) * 10000; $col = $this->m->selectCollection('im_user'); //右侧聊天窗口start $arr = $col->find(array('feedid' => $status_id)); if (!empty($arr)) { $source_name = api::get_source_name($client_id); $immsg = array("kind" => "im", "data" => array("id" => $comment_id, "statuses_id" => $status_id, "owner_uid" => $feed_uid, "user" => array('id' => $uid, 'name' => sns::getrealname($uid), 'avatar' => sns::getavatar($uid)), "datetime" => $addTime, "created_at" => sns::gettime($time), "source_name" => $source_name == 'MOMO网站' ? '' : $source_name, "text" => $content_link)); $uid_string = ''; foreach ($arr as $v) { if ($v['uid'] == $uid) { continue; } if (strlen($uid_string) > 200) { $this->mq_send(json_encode($immsg), substr($uid_string, 0, -1)); $uid_string = ''; } $uid_string .= $v['uid'] . '.'; } $this->mq_send(json_encode($immsg), substr($uid_string, 0, -1)); } //右侧聊天窗口end $client_id = $client_id ? $client_id : 0; $realname = sns::getrealname($uid); $array = array('id' => $comment_id, 'feedid' => $status_id, 'content' => $content, 'at' => $this->at2id, 'addtime' => $addTime, 'uid' => intval($uid), 'realname' => $realname, 'client_id' => intval($client_id), 'owner' => intval($feed_uid)); $this->comment->insert($array); if ($doc) { } $typeid = $doc['typeid']; $sended_uid = array(); //回复某人 if ($reply_commentid) { $reply_comment = $this->comment->findOne(array('id' => $reply_commentid)); $is_reply = false; if ($reply_comment['uid'] && count($this->at2id) > 0) { foreach ($this->at2id as $key => $var) { if ($var['id'] == $reply_comment['uid']) { $is_reply = true; $reply_key = key; continue; } } if ($is_reply) { $sended_uid[] = $reply_comment['uid']; unset($comment_at[$reply_key]); $addfeed->addAboutme($reply_comment['uid'], $this->uid, $typeid, $comment_id, $content, $this->at2id, $status_id, 6, $reply_comment); } } } //评论动态 if ($feed_uid != $this->uid && $reply_uid != $feed_uid) { if (!in_array($feed_uid, $sended_uid)) { $sended_uid[] = $feed_uid; $addfeed->addAboutme($feed_uid, $this->uid, $typeid, $comment_id, $content, $this->at2id, $status_id, 1); } } //群组评论动态 if (count($group_member) > 0) { foreach ($group_member as $member) { if (!in_array($member['uid'], $sended_uid) && $member['uid'] != $this->uid) { $sended_uid[] = $member['uid']; $addfeed->addAboutme($member['uid'], $this->uid, $typeid, $comment_id, $content, $this->at2id, $status_id, 1); } } } //动态中@某人 if (!empty($comment_at) && count($comment_at) > 0) { foreach ($comment_at as $key => $var) { if ($var['id'] != $feed_uid && !in_array($var['id'], $sended_uid) && !$var['group_id']) { $sended_uid[] = $var['id']; $addfeed->addAboutme($var['id'], $this->uid, $typeid, $comment_id, $content, $this->at2id, $status_id, 3); } } } $comment_list = array('id' => $comment_id, 'uid' => intval($uid), 'name' => $realname, 'created_at' => intval($time), 'text' => $content, 'at' => $this->at2id, 'source' => $client_id, 'im' => 0); $isbubble = $feed_uid == Kohana::config('uap.xiaomo') ? false : true; $addfeed->addFeedComment($status_id, $comment_list, $isbubble); $addfeed->updateFeed($status_id); $addfeed->delHidden($status_id); $addfeed->mo_sms('comment', $status_id, $comment_id, $this->at2mo); $return = array("success" => true, "data" => array("id" => $comment_id, "text" => $content_link)); return $return; }