Ejemplo n.º 1
0
 /**
  * 添加赞
  */
 public function create()
 {
     $post = $this->get_data();
     $statuses_id = $post['statuses_id'];
     if (empty($statuses_id)) {
         $this->send_response(400, NULL, '对象id为空');
     }
     $feed = new Feed_Model();
     $doc = $feed->findFeed($statuses_id);
     if (!$doc) {
         $this->send_response(404, NULL, '该动态不存在');
     }
     $owner = $doc['owner_uid'];
     $had_praise = 0;
     foreach ($doc['like_list'] as $key => $var) {
         $uid = $var['uid'] ? $var['uid'] : $var['id'];
         if ((int) $uid == (int) $this->uid) {
             $had_praise = 1;
             break;
         }
     }
     $group_member = array();
     if ($doc['group_type'] > 0) {
         $grade = Group_Model::instance()->getMemberGrade($doc['group_id'], $this->uid);
         if ($grade < 1) {
             $this->send_response(400, NULL, '400:你不是该群成员,无权限赞');
         }
         $group_member = Group_Model::instance()->getGroupAllMember($doc['group_id']);
     }
     $is_bubble = $owner == Kohana::config('uap.xiaomo') ? false : true;
     if ($doc['last_updated'] && $had_praise == 0) {
         if (count($group_member) > 0) {
             foreach ($group_member as $member) {
                 if ($member['uid'] != $this->uid) {
                     if (!$feed->addAboutme($member['uid'], $this->uid, $doc['typeid'], 0, '', array(), $statuses_id, 4)) {
                         $this->send_response(400, NULL, $feed->get_error_msg());
                     }
                 }
             }
         } elseif ($owner != $this->uid) {
             if (!$feed->addAboutme($owner, $this->uid, $doc['typeid'], 0, '', array(), $statuses_id, 4)) {
                 $this->send_response(400, NULL, $feed->get_error_msg());
             }
         }
         $feed->addLike($this->uid, sns::getrealname($this->uid), $statuses_id, $is_bubble);
         if ($doc['group_type'] == 1 && $doc['group_id']) {
             Tab_Model::instance()->lastModify($this->uid, 1, $doc['group_id']);
         }
         $this->send_response(200);
     }
     $this->send_response(400, NULL, '赞失败,你已经赞过');
 }
Ejemplo n.º 2
0
 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;
 }