Esempio n. 1
0
 private function _user($uid, $avatar_size = 130)
 {
     //外部应用不需获取用户信息
     if ($this->is_app_standalone) {
         return array('id' => $uid, 'name' => '', 'avatar' => '');
     }
     if (!$uid) {
         return array('id' => 0, 'name' => '', 'avatar' => '', 'nick' => array(), 'mobile' => '', 'zone_code' => '');
     }
     if (!$this->_cache_users[$uid]) {
         $user_info = sns::getuser($uid);
         $nicks = Friend_Model::instance()->get_contact_formatted_name($this->uid, $user_info['mobile'], $user_info['zone_code']);
         $mobile = $user_info['mobile'];
         $this->_cache_users[$uid] = array('id' => (int) $uid, 'name' => $user_info['realname'], 'avatar' => sns::getavatar($uid, $avatar_size), 'nick' => $nicks, 'mobile' => $mobile, 'zone_code' => $user_info['zone_code']);
     }
     return $this->_cache_users[$uid];
 }
Esempio n. 2
0
 /**
  * 获取群成员列表
  */
 public function index($id = NULL)
 {
     $data = $this->get_data();
     $id = (int) $id;
     $result = NULL;
     if ($this->get_method() != 'GET') {
         $this->send_response(405, NULL, '请求的方法不存在');
     } elseif (empty($id)) {
         $this->send_response(400, NULL, '400401:群ID为空');
     }
     $groupInfo = $this->model->getGroupInfo($id);
     if (!$groupInfo) {
         $this->send_response(400, NULL, '400402:群不存在');
     }
     $grade = $this->model->getMemberGrade($id, $this->user_id);
     if ($grade < Kohana::config('group.grade.normal')) {
         $this->send_response(400, NULL, '400403:非群成员,无权限查看成员列表');
     }
     $start = 0;
     $maxMemberNum = Kohana::config('group.maxMemberNum');
     if ($groupInfo['type'] == Kohana::config('group.type.public')) {
         $pos = $maxMemberNum['public'];
     } else {
         $pos = $maxMemberNum['private'];
     }
     $result = $this->model->getGroupMember($id, $start, $pos);
     $memberList = array();
     foreach ($result as $value) {
         if ($value['uid'] == Kohana::config('uap.xiaomo')) {
             continue;
         }
         $member = array();
         $member['id'] = floatval($value['uid']);
         $member['name'] = sns::getrealname($value['uid']);
         $member['avatar'] = sns::getavatar($value['uid']);
         $member['grade'] = intval($value['grade']);
         $member['zone_code'] = $value['zone_code'];
         $member['mobile'] = $value['mobile'];
         $memberList[] = $member;
         unset($member);
     }
     $this->send_response(200, $memberList);
 }
Esempio n. 3
0
 /**
  * 获取机器人信息
  * @param int $robot_id 机器人ID
  * @return array
  */
 public function find_by_id($robot_id)
 {
     $query = $this->db->getwhere('app_robot', array('robot_id' => $robot_id));
     $result = array();
     if ($query->count()) {
         $res = $query->result_array(FALSE);
         $result = $res[0];
         $result['avatar'] = sns::getavatar($robot_id);
     }
     return $result;
 }
Esempio n. 4
0
 public function format_comment_list($comment_lists, $source)
 {
     $data = array();
     if (count($comment_lists) > 0 && is_array($comment_lists)) {
         $comment_lists = array_reverse($comment_lists);
         foreach ($comment_lists as $k => $v) {
             if (empty($source)) {
                 if ($k > 3) {
                     break;
                 }
                 $data[$k]['id'] = $v['id'];
                 $data[$k]['user']['id'] = intval($v['uid']);
                 $data[$k]['user']['name'] = $this->_str($v['name']);
                 $data[$k]['user']['avatar'] = sns::getavatar($v['uid'], 'small');
                 $data[$k]['text'] = $this->format_title($v['text'], $source);
                 $data[$k]['at'] = $v['at'] ? $v['at'] : array();
                 $data[$k]['created_at'] = intval($v['created_at']);
                 $data[$k]['source_name'] = $this->client_from($v['source']);
                 $k++;
             } else {
                 if ($k > 0) {
                     break;
                 }
                 $data['id'] = $v['id'];
                 $data['user']['id'] = intval($v['uid']);
                 $data['user']['name'] = $this->_str($v['name']);
                 $data['user']['avatar'] = sns::getavatar($v['uid'], 'small');
                 $data['text'] = $this->format_title($v['text'], $source);
                 $data['at'] = $v['at'] ? $v['at'] : array();
                 $data['created_at'] = intval($v['created_at']);
                 $data['source_name'] = $this->client_from($v['source']);
                 $k++;
             }
         }
     }
     return empty($data) ? new stdClass() : $data;
 }
Esempio n. 5
0
 /**
  * 填充活动列表信息
  * @param array $aidList 活动ID列表
  * @param int $start 开始位置
  * @param int $pos 获取数量
  * return array
  */
 private function _fill_activity_list($aidList, $start, $pos)
 {
     $activityList = array();
     $activityType = array_flip(Kohana::config('activity.type'));
     $activityTypeName = Kohana::config('activity.typeName');
     $nowTime = time();
     $friendModel = new Friend_Model();
     $groupModel = new Group_Model();
     $index = 0;
     foreach ($aidList as $value) {
         $aid = $value['aid'];
         $gidArray = $this->model->getActivityGroupId($aid);
         $activityInfo = $this->model->getActivityInfo($aid);
         if ($activityInfo['creator_id'] != $this->user_id && !$activityInfo['is_allow_invite']) {
             $permit = false;
             foreach ($gidArray as $val) {
                 if ($val['gid'] == -1) {
                     $isFriend = $friendModel->check_isfriend($this->user_id, $activityInfo['creator_id']);
                     if ($isFriend) {
                         $permit = true;
                         break;
                     }
                     continue;
                 }
                 $grade = $groupModel->getMemberGrade($val['gid'], $this->user_id);
                 if ($grade > 0) {
                     $permit = true;
                     break;
                 }
             }
             if (!$permit) {
                 continue;
             }
         }
         if ($pos == 0 || $index >= $start && $index < $start + $pos) {
             $activity = array();
             $activity['id'] = floatval($activityInfo['aid']);
             $user = array();
             $user['id'] = floatval($activityInfo['creator_id']);
             $user['name'] = sns::getrealname($activityInfo['creator_id']);
             $user['avatar'] = sns::getavatar($activityInfo['creator_id']);
             $activity['user'] = $user;
             $activity['title'] = $activityInfo['title'];
             $activity['start_at'] = api::get_date($activityInfo['start_time']);
             $activity['end_at'] = api::get_date($activityInfo['end_time']);
             $activity['spot'] = $activityInfo['spot'];
             //$activity['content'] = $activityInfo['content'];
             $type = $activityType[$activityInfo['type']];
             $activity['type'] = $activityTypeName[$type];
             if ($activityInfo['end_time'] < $nowTime) {
                 $status = Kohana::config('activity.status.end.id');
             } else {
                 if ($activityInfo['start_time'] > $nowTime) {
                     $status = Kohana::config('activity.status.enroll.id');
                 } else {
                     $status = Kohana::config('activity.status.working.id');
                 }
             }
             $activity['status'] = $status;
             $activity['apply_type'] = $this->model->getActivityApplyType($activity['id'], $this->user_id);
             $activity['is_hide'] = -1;
             $result = $this->model->getActivityOrganizer($activity['id']);
             $organizer = array();
             unset($user);
             foreach ($result as $val) {
                 $user = array();
                 $user['id'] = floatval($val['uid']);
                 $userInfo = sns::getuser($val['uid']);
                 $user['name'] = $userInfo['realname'];
                 $user['avatar'] = sns::getavatar($val['uid']);
                 $user['mobile'] = $userInfo['mobile'];
                 $organizer[] = $user;
                 unset($userInfo);
                 unset($user);
             }
             $activity['organizer'] = $organizer;
             $activityList[] = $activity;
             unset($activityInfo);
             unset($activity);
             unset($user);
         }
         $index++;
     }
     return array('data' => $activityList, 'count' => $index);
 }
Esempio n. 6
0
 /**
  * 
  * 获取群组管理员
  */
 private function _get_group_manager($gid)
 {
     $gm_user = array();
     $gm = $this->model->getGroupManager($gid);
     if ($gm) {
         foreach ($gm as $v) {
             $gm_user[] = array('id' => $v['uid'], 'name' => sns::getrealname($v['uid']), 'avatar' => sns::getavatar($v['uid']));
         }
     }
     return $gm_user;
 }
Esempio n. 7
0
 public function __construct()
 {
     parent::__construct();
     switch ($this->second) {
         case 'request_token':
             $this->oauth_server->requestToken();
             exit;
         case 'authorize':
             if ($this->get_method() == 'POST' || !empty($_POST)) {
                 if (!empty($_POST)) {
                     $oauth_token = $_POST['oauth_token'];
                     $account = $_POST['account'];
                     $password = $_POST['password'];
                     $oauth_callback = $_POST['oauth_callback'];
                 } else {
                     $data = $this->get_data();
                     $oauth_token = $data['oauth_token'];
                     $account = isset($data['account']) ? $data['account'] : '';
                     $password = isset($data['password']) ? $data['password'] : '';
                     $oauth_callback = isset($data['oauth_callback']) ? $data['oauth_callback'] : '';
                     $this->is_mobile = true;
                 }
                 $to_post['account'] = $account;
                 $to_post['password'] = $password;
                 $result = $this->_uc_fopen(API_PATH . 'user/verify.json', 0, $this->to_postdata($to_post), 'POST');
                 $result_obj = json_decode($result['data']);
                 if (isset($result_obj->error_code) && $result_obj->error_code == 400) {
                     $this->error = $result_obj->error;
                     if (empty($oauth_callback)) {
                         $this->send_response(400, NULL, $result_obj->error);
                     }
                 }
                 if (isset($result_obj->uid) && $result_obj->uid > 0) {
                     $this->oauth_server->authorizeVerify($oauth_token, $oauth_callback, $this->is_mobile);
                     $verifier = $this->oauth_server->authorizeFinish(true, $result_obj->uid, $oauth_token);
                     if (!empty($verifier)) {
                         if ($this->is_mobile) {
                             $result = array();
                             $result['verifier'] = $verifier;
                             $result['user_id'] = $result_obj->uid;
                             $result['name'] = $result_obj->name;
                             $result['avatar'] = sns::getavatar($result_obj->uid);
                             $result['role'] = $result_obj->role;
                             $this->send_response(200, $result);
                         }
                         $this->render_authorize_verifier($verifier);
                     }
                 }
             }
             try {
                 $app_info = $this->oauth_server->authorizeVerify();
                 $this->assert_logged_in($app_info);
             } catch (OAuthException2 $e) {
                 header('HTTP/1.1 400 Bad Request');
                 header('Content-Type: text/plain');
                 echo "Failed OAuth Request: " . $e->getMessage();
             }
             exit;
         case 'access_token':
             $this->oauth_server->accessToken();
             exit;
         default:
             header('HTTP/1.1 404 Not Found');
             header('Content-Type: text/plain');
             echo "Unknown request";
             exit;
     }
 }
Esempio n. 8
0
 public function search()
 {
     $friends = $this->friend_model->get_user_link_cache($this->user_id);
     $data = $this->get_data();
     $mobiles = isset($data['mobiles']) ? $data['mobiles'] : array();
     $result = array();
     foreach ($mobiles as $mobile) {
         $res = international::check_mobile($mobile);
         if (!$res) {
             continue;
         }
         $user = $this->model->get_user_by_mobile($res['country_code'], $res['mobile']);
         if ($user) {
             $uuid = $this->user_id;
             $pos = array_search($user['id'], $friends);
             //已经是好友或者是登录者自己
             if ($pos !== False || $user['id'] == $this->user_id) {
                 continue;
             }
             $result[] = array('id' => $user['id'], 'name' => $user['username'], 'avatar' => sns::getavatar($user['id']));
         }
     }
     $this->send_response(200, $result);
 }
Esempio n. 9
0
 /**
  * 根据需求查询
  * @param string $query 查询字符串
  * @return array
  */
 public function cypher($query)
 {
     $result = $this->_graph_query($query, 25);
     if ($result) {
         $cols = $result->getColumns();
         $return = array();
         foreach ($result as $i => $row) {
             /** @var Everyman\Neo4j\PropertyContainer[] $row */
             foreach ($cols as $col) {
                 if ($row[$col] instanceof Everyman\Neo4j\Node) {
                     /** @var Everyman\Neo4j\Node[] $row */
                     $return[$i][$col]['meta']['id'] = $row[$col]->getId();
                     $return[$i][$col]['property'] = $row[$col]->getProperties();
                     if ($user_id = $row[$col]->getProperty('uid')) {
                         $return[$i][$col]['property']['name'] = sns::getrealname($user_id);
                         $return[$i][$col]['property']['avatar'] = sns::getavatar($user_id);
                     }
                 } elseif ($row[$col] instanceof Everyman\Neo4j\Relationship) {
                     /** @var Everyman\Neo4j\Relationship[] $row */
                     $return[$i][$col]['meta']['id'] = $row[$col]->getId();
                     $return[$i][$col]['meta']['type'] = $row[$col]->getType();
                     $return[$i][$col]['meta']['start_node'] = $row[$col]->getStartNode()->getId();
                     $return[$i][$col]['meta']['end_node'] = $row[$col]->getEndNode()->getId();
                     $return[$i][$col]['property'] = $row[$col]->getProperties();
                 } elseif ($row[$col] instanceof Everyman\Neo4j\Query\Row) {
                     foreach ($row[$col] as $j => $r) {
                         if ($r instanceof Everyman\Neo4j\Node) {
                             /** @var Everyman\Neo4j\Node[] $row */
                             $return[$i][$col][$j]['meta']['id'] = $r->getId();
                             $return[$i][$col][$j]['property'] = $r->getProperties();
                             if ($user_id = $r->getProperty('uid')) {
                                 $return[$i][$col][$j]['property']['name'] = sns::getrealname($user_id);
                                 $return[$i][$col][$j]['property']['avatar'] = sns::getavatar($user_id);
                             }
                         } elseif ($r instanceof Everyman\Neo4j\Relationship) {
                             /** @var Everyman\Neo4j\Relationship[] $row */
                             $return[$i][$col][$j]['meta']['id'] = $row[$col]->getId();
                             $return[$i][$col][$j]['meta']['type'] = $row[$col]->getType();
                             $return[$i][$col][$j]['meta']['start_node'] = $row[$col]->getStartNode()->getId();
                             $return[$i][$col][$j]['meta']['end_node'] = $row[$col]->getEndNode()->getId();
                             $return[$i][$col][$j]['property'] = $r->getProperties();
                         } else {
                             $return[$i][$col][$j] = $r;
                         }
                     }
                 } else {
                     $return[$i][$col] = $row[$col];
                 }
             }
         }
         return $return;
     }
     return false;
 }
Esempio n. 10
0
 /**
  * 
  * 整理用户信息
  * @param array $item
  * @param int $apply_type
  */
 private function _arrange_user_item($item, $apply_type, $event_info)
 {
     $arranged_item = array();
     if (!empty($item)) {
         $arranged_item['uid'] = $item['uid'];
         $arranged_item['pid'] = $item['pid'];
         $arranged_item['name'] = $item['name'];
         $arranged_item['avatar'] = sns::getavatar($item['uid']);
         if ($this->user_id == $event_info['organizer'] || $this->user_id == $item['uid'] || $this->user_id == $item['pid']) {
             $arranged_item['mobile'] = $item['mobile'];
             if ($apply_type == Kohana::config('event.apply_type.joined')) {
                 $arranged_item['apply_doc'] = $this->model->getUserApplyDoc($item['eid'], $item['uid'], $item['pid'], '', $item['name']);
             }
         }
     }
     return $arranged_item;
 }
Esempio n. 11
0
 /**
  * 报名活动
  */
 public function create($id = 0)
 {
     $data = $this->get_data();
     $aid = (int) $id;
     $apply_type = (int) $data['type'];
     $webRequest = (int) $data['web'];
     if ($webRequest != 2) {
         $webRequest = 0;
     }
     if ($this->get_method() != 'POST') {
         $this->send_response(405, NULL, '请求的方法不存在');
     }
     if ($id == 0) {
         $this->send_response(400, NULL, '400501:活动id为空');
     }
     if ($apply_type < Kohana::config('activity.apply_type.join') || $apply_type > Kohana::config('activity.apply_type.interest')) {
         $this->send_response(400, NULL, '400508:活动报名类型非法');
     }
     $activity = $this->model->getActivityInfo($aid);
     if (!$activity) {
         $this->send_response(400, NULL, '400502:活动不存在');
     }
     if ($activity['end_time'] < time()) {
         $this->send_response(400, NULL, '活动已结束');
     }
     $permit = $this->_check_activity_view_permission($activity, $this->user_id);
     if (!$permit) {
         $this->send_response(400, NULL, '400510:无权限报名活动');
     }
     if ($webRequest > 0) {
         $types = array_flip(Kohana::config('activity.type'));
         $typeId = $types[$activity['type']];
         $typeNames = Kohana::config('activity.typeName');
         $type = $typeNames[$typeId];
         $view = new View('activity/details');
         $view->webRequest = $webRequest;
         $view->type = $type;
         $user = array();
         $user['id'] = floatval($activity['creator_id']);
         $userInfo = sns::getuser($activity['creator_id']);
         $user['name'] = $userInfo['realname'];
         $user['mobile'] = $userInfo['mobile'];
         $activity['user'] = $user;
         unset($user);
         $organizer = array();
         $organizerList = $this->model->getActivityOrganizer($aid);
         $organizerIdList = array();
         foreach ($organizerList as $value) {
             $user = array();
             $user['id'] = floatval($value['uid']);
             $userInfo = sns::getuser($value['uid']);
             $user['name'] = $userInfo['realname'];
             $user['avatar'] = sns::getavatar($value['uid']);
             $user['mobile'] = $userInfo['mobile'];
             $organizer[] = $user;
             $organizerIdList[] = $user['id'];
             unset($userInfo);
             unset($user);
         }
         $activity['organizer'] = $organizer;
         $view->activity = $activity;
         $view->apply_type = $apply_type;
     }
     $userModel = new User_Model();
     $nowTime = time();
     $feedModel = new Feed_Model();
     //获取用户是否已经参与了报名
     $applyResult = $this->model->getActivityApplyType($aid, $this->user_id);
     if ($applyResult) {
         $tab = $userModel->getTag($this->user_id, 15, $aid);
         if ($applyResult == $apply_type) {
             if ($webRequest > 0) {
                 $view->render(true);
                 exit;
             }
             $this->send_response(200);
         } else {
             if ($applyResult == Kohana::config('activity.apply_type.not_join') && !$tab) {
                 $userModel->insertTag($this->user_id, 15, $aid);
             } else {
                 if ($apply_type == Kohana::config('activity.apply_type.not_join')) {
                     //$userModel->deleteTag($this->user_id, 15, $aid);
                 }
             }
         }
         $activityMember = array('apply_type' => $apply_type, 'apply_time' => $nowTime);
         $grade = $this->model->getMemberGrade($aid, $this->user_id);
         if ($grade == Kohana::config('activity.grade.manager') && $apply_type != Kohana::config('activity.apply_type.join')) {
             $activityMember['grade'] = Kohana::config('activity.group.normal');
         }
         $result = $this->model->updateApplyActivity($aid, $this->user_id, $activityMember);
         $this->_add_feed_comment($activity, $applyResult, $apply_type, $this->user_id);
         $feedModel->addTab($aid, $activity['title'], 15, $this->user_id);
         if ($webRequest > 0) {
             $view->render(true);
             exit;
         }
         $this->send_response(200);
     }
     $activityMember['aid'] = $aid;
     $activityMember['uid'] = $this->user_id;
     $activityMember['apply_type'] = $apply_type;
     $activityMember['apply_time'] = $nowTime;
     $activityMember['grade'] = Kohana::config('activity.grade.normal');
     $this->model->applyActivity($activityMember);
     $userModel->insertTag($this->user_id, 15, $aid);
     $messageModel = new Message_Model();
     $appid = Kohana::config('uap.app.action');
     $tplid = Kohana::config('noticetpl.actionInvite.id');
     while (true) {
         $inviteMsg = $messageModel->getNoticeInfo(array('uid' => $this->user_id, 'appid' => $appid, 'tplid' => $tplid, 'objid' => $aid, 'status' => 0));
         if ($inviteMsg) {
             //修改系统消息模板
             $invite_uid = $inviteMsg['authorid'];
             $nid = $inviteMsg['id'];
             $messageModel->putChangeTplByid($this->user_id, $nid, $apply_type);
             $this->model->setInviteStatus($aid, $invite_uid, $this->user_id);
         } else {
             break;
         }
     }
     if ($apply_type == Kohana::config('activity.apply_type.not_join')) {
         if ($webRequest > 0) {
             $view->render(true);
             exit;
         }
         $this->send_response(200);
     }
     $this->_add_feed_comment($activity, 0, $apply_type, $this->user_id);
     $feedModel->addTab($aid, $activity['title'], 15, $this->user_id);
     if ($webRequest > 0) {
         $view->render(true);
         exit;
     }
     $this->send_response(200);
 }
Esempio n. 12
0
 /**
  * 根据用户权限获取好友信息
  * @param int $user_id        当前用户ID
  * @param int $friend_user_id 获取用户ID
  * @return Contact
  */
 public function get_user_info($user_id, $friend_user_id)
 {
     $user_model = User_Model::instance();
     $result = $user_model->get_user_info($friend_user_id);
     if ($result !== FALSE) {
         $friend_country_code = $result['zone_code'];
         $data = $user_model->profile_assembly($result, $user_id);
         $data = array_merge($data, Contact_Helper::formatted_name_to_name($data['name']));
         //根据权限获取好友信息
         $user_country_code = $this->get_country_code($user_id);
         $prefix = '';
         if ($user_country_code and $friend_country_code and $user_country_code != $friend_country_code) {
             $prefix = '+' . $friend_country_code;
         }
         $array = array();
         foreach ($data as $key => $value) {
             if (in_array($key, array('family_name', 'given_name', 'nickname', 'department', 'title', 'birthday', 'organization'))) {
                 $array[$key] = $value;
             } elseif ($key == 'tels') {
                 if (!empty($value)) {
                     foreach ($value as $val) {
                         if ($prefix and strpos($val['value'], $prefix) !== 0) {
                             $tel = $prefix . $val['value'];
                         } else {
                             $tel = $val['value'];
                         }
                         if (!empty($val['pref'])) {
                             $array[$key][] = array('type' => $val['type'], 'value' => $tel, 'pref' => $val['pref']);
                         } else {
                             $array[$key][] = array('type' => $val['type'], 'value' => $tel);
                         }
                     }
                 }
             } elseif (in_array($key, array('emails', 'ims', 'addresses', 'urls'))) {
                 if (!empty($value)) {
                     foreach ($value as $val) {
                         $array[$key][] = $val;
                     }
                 }
             }
         }
         //获取好友头像
         $array['avatar'] = sns::getavatar($friend_user_id, 130);
         return Contact_Helper::array_to_contact($array, $user_country_code);
     }
     return FALSE;
 }
Esempio n. 13
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;
 }
Esempio n. 14
0
 /**
  * 获取关于我的动态,提供iphone,andriod使用
  * @return <type>
  */
 public function aboutme_alone()
 {
     $pos = $this->input->get('pagesize', 20);
     $start = $this->input->get('page', 1);
     $new = $this->input->get('new', 0);
     $pos = $pos > 100 ? 100 : $pos;
     $start = abs(($start - 1) * $pos);
     $arr = $this->feedModel->findAboutme($new, $pos, $start);
     $res = array();
     if ($arr) {
         $i = 0;
         foreach ($arr as $row) {
             $res[$i]['id'] = $row['_id'];
             $res[$i]['statuses_id'] = $row['feed_id'];
             $res[$i]['kind'] = $row['kind'];
             $res[$i]['group'] = array('id' => $this->_st($row['group_id'], 0), 'name' => $this->_st($row['group_name'], ''));
             $res[$i]['text'] = $this->_st($this->feedModel->format_title($row['comment_content'], $this->source), '');
             $res[$i]['source'] = $row['source'] == 0 ? '' : $this->get_source($row['source']);
             $res[$i]['user'] = array('id' => $this->_st($row['comment_uid'], 0), 'name' => $this->_st(sns::getrealname($row['comment_uid'])), 'avatar' => sns::getavatar($row['comment_uid'], 'small'));
             $res[$i]['new'] = $row['new'] == 1 ? true : false;
             $res[$i]['created_at'] = ceil($row['addtime'] / 10000);
             $aboutme_opt = array();
             if ($row['kind'] == 6) {
                 $content = $this->_st(strip_tags($row['reply_content']), '');
                 $aboutme_opt['reply_source'] = array('id' => $row['reply_id'], 'text' => $this->feedModel->format_title($content, $this->source), 'at' => $row['reply_at'], 'user' => array('id' => $row['reply_uid'], 'name' => $row['reply_name'], 'avatar' => sns::getavatar($row['reply_uid'], 'small')));
             } elseif ($row['kind'] == 2) {
                 $aboutme_opt['message'] = array('text' => $this->_st($this->feedModel->format_title($row['feed_content'], $this->source), ''), 'at' => $row['feed_at']);
             } else {
                 $content = $this->_st(strip_tags($row['feed_content']), '');
                 $aboutme_opt['statuses'] = array('text' => $this->feedModel->format_title($content, $this->source), 'at' => $row['feed_at'], 'uid' => $this->_st($row['feed_uid'], 0), 'name' => $this->_st($row['feed_name']));
             }
             if (in_array($row['kind'], array(1, 3, 6))) {
                 $aboutme_opt['comment'] = array('id' => $row['comment_id'], 'text' => $this->_st($this->feedModel->format_title(str_replace(array('评论道:', '回复:'), '', $row['comment_content']), $this->source), ''), 'at' => $row['comment_at']);
             }
             $res[$i]['opt'] = $aboutme_opt;
             $i++;
         }
         $this->feedModel->updateAboutmeRead();
     }
     $this->send_response(200, $res);
 }
Esempio n. 15
0
 /**
  * 精确查找用户
  * @method GET
  */
 public function search()
 {
     if ($this->get_method() != 'GET') {
         $this->send_response(405, NULL, '请求的方法不存在');
     }
     $name = $this->input->get("name");
     $name = trim($name);
     if (empty($name)) {
         $this->send_response(400, NULL, "name不能为空");
     }
     $page = (int) $this->input->get("page", 1);
     if ($page <= 0) {
         $this->send_response(400, NULL, "输入有误");
     }
     $pos = (int) $this->input->get("pagesize", 20);
     if ($pos < 0 || $pos > self::MAX_PAGESIZE) {
         $this->send_response(400, NULL, "输入有误");
     }
     $start = ($page - 1) * $pos;
     $total = $this->model->get_user_counts_byname($name);
     if (!$total) {
         $this->send_response(200, array("count" => $total, "start" => 0, "pos" => 0, "data" => array()));
     }
     $result = $this->model->get_users_byname($name, $start, $pos);
     $tmp = array();
     $curYear = date('Y');
     //@FIXME birthplace residence 现只处理了中国
     $zipmap = (include Kohana::find_file('vendor', 'cityarray', true));
     $residence = "";
     foreach ($result as $key => $val) {
         //居住地
         if (!empty($val["resideprovince"])) {
             $residence = isset($zipmap["province"][$val["resideprovince"]]) ? $zipmap["province"][$val["resideprovince"]] : "";
         }
         if (!empty($val["residecity"])) {
             $residence .= isset($zipmap["city"][$val["residecity"]]) ? " " . $zipmap["city"][$val["residecity"]] : "";
         }
         $tmp[$key]["id"] = (int) $val["uid"];
         $tmp[$key]["name"] = $val["realname"];
         $tmp[$key]["gender"] = (int) $val["sex"];
         $tmp[$key]["age"] = (string) $val["birthyear"] > 0 ? $curYear - $val["birthyear"] : '';
         $tmp[$key]["city"] = $residence;
         $tmp[$key]["company"] = $val["company"];
         $tmp[$key]["school"] = $val["college"];
         $tmp[$key]["zodiac"] = $val["astro"];
         $tmp[$key]["sign"] = $val["sign"];
         $tmp[$key]["avatar"] = sns::getavatar($val["uid"]);
         $tmp[$key]["modified_at"] = $val["updatetime"];
         //date('D M d H:i:s O Y', $val["updatetime"]);
     }
     unset($result);
     $this->send_response(200, array("count" => $total, "start" => $start, "pos" => count($tmp), "data" => $tmp));
 }
Esempio n. 16
0
 public function message_opt_friend_apply($data, $message_id, $mini)
 {
     $location = '';
     $sex = 0;
     $together_count = 0;
     $same_friend = array();
     $result = $this->getNoticeInfo(array('id' => $message_id, 'authorid' => $this->uid), true);
     if ($result) {
         $tmp = $result['body'] ? json_decode($result['body'], true) : array("explain" => "");
         //取得共同好友
         $friendModel = new Friend_Model();
         $ffids = $friendModel->getAllFriendIDs($result['authorid'], false);
         $mfids = $friendModel->getAllFriendIDs($this->uid, false);
         $together = array_intersect($ffids, $mfids);
         $data = sns::getuser($result['authorid']);
         $tmp['reside'] = '';
         if ($data['resideprovince'] || $data['residecity']) {
             $config = Kohana::config_load('cityarray');
             //加载城市数组
             $province = isset($data['resideprovince']) ? isset($config['province'][$data['resideprovince']]) ? $config['province'][$data['resideprovince']] : '' : "";
             $city = isset($data['residecity']) ? isset($config['city'][$data['residecity']]) ? $config['city'][$data['residecity']] : '' : "";
             $location = $province . " " . $city;
         }
         $sex = $data['sex'] == 1 ? "男" : "女";
         $tmp['fid'] = $result['authorid'];
         $tmp['explain'] = $tmp['explain'] ? str::unhtmlspecialchars($tmp['explain']) : '';
         unset($data, $ffids, $mfids, $config);
         $str = "";
         $urlpre = url::base();
         $avatar = sns::getavatar($result['authorid']);
         if (!empty($together)) {
             $together_count = count($together);
             $i = 0;
             foreach ($together as $val) {
                 $item = array();
                 $item['id'] = $val;
                 $item['name'] = sns::getrealname($val);
                 $same_friend[] = $item;
                 if (9 < ++$i) {
                     break;
                 }
             }
         }
     }
     return array('location' => $location, 'sex' => $sex, 'together_count' => $together_count, 'together' => $same_friend);
 }
Esempio n. 17
0
 /**
  * 
  * @param $deal_id
  * @return array
  */
 public function item($deal_id, $user_id = 0)
 {
     $result = $this->get($deal_id);
     if ($result) {
         $deal_user_info = sns::getuser($result['uid']);
         $return = array('deal_id' => (int) $result['id'], 'user' => array('id' => (int) $result['uid'], 'name' => $deal_user_info['realname'], 'mobile' => $deal_user_info['mobile'], 'avatar' => sns::getavatar($result['uid'], 'small')), 'status' => (int) $result['status'], 'private' => (int) $result['private'], 'price' => (double) $result['price'], 'location' => array('longitude' => (double) $result['longitude'], 'latitude' => (double) $result['latitude']), 'created_at' => (int) $result['created_at']);
         if ($user_id) {
             $name = $this->_get_relation_contacts_name($user_id, $result['uid']);
             $return['weight'] = $name ? 1 : 0;
             $return['relation']['contact'] = array('name' => $name);
             /*** @todo for deal start ***/
             $units = User_Model::instance()->get_unit_dict(array($user_id, $result['uid']));
             if ($units[$result['uid']] && $units[$user_id]['unitid'] == $units[$result['uid']]['unitid']) {
                 $return['relation']['company'] = array('name' => $units[$result['uid']]['unitname'], 'username' => $units[$result['uid']]['username']);
             }
             /*** @todo for deal end ***/
         }
         $deal_detail = $this->_select_mongo($result['deal_id']);
         if ($deal_detail) {
             $return['sync'] = $deal_detail['sync'] ? $deal_detail['sync'] : array();
             $return['title'] = $deal_detail['title'];
             $return['description'] = $deal_detail['description'];
             $return['image'] = $this->_format_image($deal_detail['image']);
         }
     }
     return $return;
 }
Esempio n. 18
0
 public function message_opt_recommend_friend($data, $message_id, $mini)
 {
     $tmpdata = json_decode($data, true);
     $recommend = array();
     if (is_array($tmpdata['recommend']) && count($tmpdata['recommend']) > 0) {
         foreach ($tmpdata['recommend'] as $k => $v) {
             $recommend[$k]['id'] = $this->_str($v['id'], 0);
             $recommend[$k]['name'] = $this->_str($v['name']);
             $recommend[$k]['avatar'] = sns::getavatar($v['id']);
         }
     }
     return $recommend;
 }
Esempio n. 19
0
 /**
  * 根据用户权限获取好友信息
  * @param int $friend_user_id
  * @return Contact
  */
 public function get_user_info($user_id)
 {
     $user_model = User_Model::instance();
     $result = $user_model->get_user_info($user_id);
     if ($result !== FALSE) {
         $data = $user_model->profile_assembly($result);
         //根据权限获取好友信息
         $array = array();
         foreach ($data as $key => $value) {
             if (in_array($key, array('family_name', 'given_name', 'nickname', 'department', 'title'))) {
                 $array[$key] = $value;
             } elseif (in_array($key, array('tels', 'emails', 'ims', 'addresses', 'urls'))) {
                 if (!empty($value)) {
                     foreach ($value as $val) {
                         if (!empty($val['is_master'])) {
                             $array[$key][] = array('type' => $val['type'], 'value' => $val['value'], 'pref' => $val['is_master']);
                         } elseif ($val['is_public']) {
                             $array[$key][] = $val;
                         }
                     }
                 }
             } elseif ($key == 'company') {
                 $array['organization'] = $value;
             }
         }
         if (!empty($data['is_hide_year'])) {
             $data['birthyear'] = 1900;
         }
         if (!empty($data['birthmonth']) && !empty($data['birthday']) && !empty($data['birthyear'])) {
             if (strlen($data['birthday']) == 1) {
                 $data['birthday'] = '0' . $data['birthday'];
             }
             if (strlen($data['birthmonth']) == 1) {
                 $data['birthmonth'] = '0' . $data['birthmonth'];
             }
             if (checkdate($data['birthmonth'], $data['birthday'], $data['birthyear'])) {
                 $array['birthday'] = $data['birthyear'] . '-' . $data['birthmonth'] . '-' . $data['birthday'];
             } else {
                 $array['birthday'] = '';
             }
         } else {
             $array['birthday'] = '';
         }
         //获取好友头像
         $array['avatar'] = sns::getavatar($user_id, 130);
         return $this->array_to_Group_contact($array);
     }
     return FALSE;
 }
Esempio n. 20
0
 public function token()
 {
     if ($this->get_method() != 'POST') {
         $this->send_response(405, NULL, '请求的方法不存在');
     }
     $data = $this->get_data();
     $zone_code = isset($data['zone_code']) ? $data['zone_code'] : '';
     $mobile = isset($data['mobile']) ? $data['mobile'] : '';
     $code = isset($data['code']) ? $data['code'] : '';
     if (!international::check_is_valid($zone_code, $mobile)) {
         $this->send_response(400, NULL, Kohana::lang('authorization.mobile_invalid'));
     }
     $username = $this->model->get_full_mobile($zone_code, $mobile);
     if (!$this->is_test_mobile($mobile)) {
         if (!$this->model->check_verify_code($username, $code)) {
             $this->send_response(400, NULL, Kohana::lang('authorization.code_invalid'));
         }
     }
     $user = $this->model->get_user_by_mobile($zone_code, $mobile);
     if ($user) {
         $id = $user['id'];
     } else {
         $regip = $this->get_ip();
         $id = $this->model->create_user($zone_code, $mobile, '', $regip);
     }
     $token = $this->model->create_token(3600, TRUE, array('zone_code' => $zone_code, 'mobile' => $mobile, 'id' => (int) $id));
     if ($user) {
         $token['name'] = $user['username'];
         $token['avatar'] = sns::getavatar($user['id']);
     }
     $this->send_response(200, $token);
 }