/** * Show the profile of a student */ public function view($params) { $this->setView('view.php'); $is_logged = isset(User_Model::$auth_data); $is_student = $is_logged && isset(User_Model::$auth_data['student_number']); $is_admin = $is_logged && User_Model::$auth_data['admin'] == '1'; // If the user isn't logged in if (!$is_logged) { throw new ActionException('User', 'signin', array('redirect' => $_SERVER['REQUEST_URI'])); } try { $student = $this->model->getInfo($params['username']); $post_model = new Post_Model(); $this->setTitle(htmlspecialchars($student['firstname'] . ' ' . $student['lastname'])); $this->set(array('student' => $student, 'groups' => isset($student['id']) ? Group_Model::getAuth((int) $student['id']) : array(), 'is_owner' => User_Model::$auth_data['username'] == $student['username'], 'is_logged' => true, 'is_student' => $is_student, 'is_admin' => $is_admin, 'username' => User_Model::$auth_data['username'])); if ($is_student) { $this->set(array('firstname' => User_Model::$auth_data['firstname'], 'lastname' => User_Model::$auth_data['lastname'], 'avatar_url' => User_Model::$auth_data['avatar_url'])); } // If the student is a user, we show their posts if (isset($student['id'])) { $category = isset($params['category']) ? $params['category'] : null; $category_model = new Category_Model(); $this->set(array('posts' => $post_model->getPosts(array('restricted' => true, 'user_id' => (int) $student['id'], 'category_name' => $category, 'official' => false, 'show_private' => $is_student), Config::POST_DISPLAYED), 'categories' => $category_model->getAll(), 'current_category' => $category)); } } catch (Exception $e) { throw new ActionException('Page', 'error404'); } }
public static function &instance() { if (!is_object(Group_Model::$instances)) { // Create a new instance Group_Model::$instances = new Group_Model(); } return Group_Model::$instances; }
public function __construct() { parent::__construct(); $this->uid = $this->getUid(); $this->feedModel = Feed_Model::instance(); $this->new_format = $this->input->get('new_format', 0); $this->friendModel = Friend_Model::instance(); $this->groupModel = Group_Model::instance(); $this->activityModel = Activity_Model::instance(); }
public function __construct() { parent::__construct(); $this->model = new Message_Model(); $this->message_type = null; $this->activityModel = Activity_Model::instance(); $this->friendModel = Friend_Model::instance(); $this->groupModel = Group_Model::instance(); $this->groupContactModel = Group_Contact_Model::instance(); $this->contactModel = Contact_Model::instance(); }
/** * 添加赞 */ 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, '赞失败,你已经赞过'); }
/** * Delete a post */ public function delete($params) { $this->setView('delete.php'); try { $comment = $this->model->get((int) $params['id']); $is_logged = isset(User_Model::$auth_data); $is_admin = $is_logged && User_Model::$auth_data['admin'] == '1'; $groups_auth = isset($is_logged) ? Group_Model::getAuth() : array(); if ($is_logged && User_Model::$auth_data['id'] == $comment['user_id'] || $is_admin || isset($post['group_id']) && isset($groups_auth[(int) $post['group_id']]) && $groups_auth[(int) $post['group_id']]['admin']) { $this->model->delete((int) $params['id']); $this->set('success', true); } else { $this->set('success', false); } } catch (Exception $e) { // Post not found $this->set('success', true); } }
/** * Search posts, groups, and students */ public function index($params) { $this->setView('index.php'); $is_logged = isset(User_Model::$auth_data); $is_student = $is_logged && isset(User_Model::$auth_data['student_number']); $is_admin = $is_logged && User_Model::$auth_data['admin'] == '1'; if (!isset($_GET['q'])) { throw new ActionException('Page', 'error404'); } $limit = 100; $results = $this->model->search($_GET['q'], null, $limit, !$is_logged, $is_student); $posts_ids = array(); $students_usernames = array(); $groups_ids = array(); foreach ($results as &$result) { switch ($result['_type']) { case 'student': $students_usernames[] = $result['_id']; break; case 'group': $groups_ids[] = (int) $result['_id']; break; case 'post': $posts_ids[] = (int) $result['_id']; break; } } $post_model = new Post_Model(); $this->setTitle(__('SEARCH_TITLE', array('query' => htmlspecialchars($_GET['q'])))); $this->set(array('query' => $_GET['q'], 'posts' => $post_model->getPosts(array('restricted' => true, 'ids' => $posts_ids, 'show_private' => $is_student), $limit), 'students' => Student_Model::getInfoByUsernames($students_usernames), 'groups' => Group_Model::getInfoByIds($groups_ids), 'is_logged' => true, 'is_student' => $is_student, 'is_admin' => $is_admin)); if ($is_logged) { $this->set(array('username' => User_Model::$auth_data['username'])); } if ($is_student) { $this->set(array('firstname' => User_Model::$auth_data['firstname'], 'lastname' => User_Model::$auth_data['lastname'], 'avatar_url' => User_Model::$auth_data['avatar_url'])); } }
function is_membership_approved($group_id) { require_once WPPR_PLUGIN_DIR . '/models/group-model.php'; $model = new Group_Model(); $user_id = get_current_user_id(); if ($model->get_membership_status($group_id, $user_id)) { return true; } else { return false; } }
public function userAboutActivityNum($uid, $end = 0) { $groupModel = new Group_Model(); $gidList = $groupModel->getUserAllGroupId($uid); $gids = ''; $separator = ''; foreach ($gidList as $value) { $gids .= $separator . $value['gid']; $separator = ','; } $friendModel = new Friend_Model(); $fidList = $friendModel->getAllFriendIDs($uid); $fids = ''; if ($fidList) { $fids = implode(',', $fidList); } $applyAids = $this->getApplyAids($uid); $companyModel = Company_Model::instance(); $companyList = $companyModel->getCompanyList($uid); $companyIds = ""; $separator = ''; foreach ($companyList as $value) { $companyIds .= $separator . $value['cid']; $separator = ','; } $belongType = Kohana::config('activity.belongType.company'); if (!empty($companyIds)) { if (empty($applyAids)) { $separator = ''; } else { $separator = ','; } $activityList = $this->getBelongActivityList($belongType, $companyIds); foreach ($activityList as $value) { $applyAids .= $separator . $value['aid']; $separator = ','; } } if ($fids) { $where = "(gid = -1 AND creator_id in ({$fids}))"; $friendApplyaids = $this->getFriendsApplyAids($fids); if ($friendApplyaids) { $where .= " OR (is_allow_invite = 1 AND aid IN ({$friendApplyaids}))"; } } if ($gids) { if ($where) { $where .= " OR gid in ({$gids})"; } else { $where .= "gid in ({$gids})"; } } if ($applyAids) { if ($where) { $where .= " OR aid in ({$applyAids})"; } else { $where .= "aid in ({$applyAids})"; } } if (!$where) { return 0; } if ($end == 0) { //未结束的活动 $nowTime = time(); $where = "{$nowTime} < end_time AND " . "({$where})"; } $query = $this->db->query("SELECT COUNT(DISTINCT aid) AS num FROM action WHERE {$where}"); $result = $query->result_array(FALSE); return (int) $result[0]['num']; }
/** * Returns the information of the N last posts, with attachments, surveys, events... * * @param array $params Associative array of paramaters. Possibles keys : * * official: Only official posts if true, only non-official posts if false, all posts if null * * show_private: Private posts include if true * * category_id: Category's id * * category_name: Category's name * * group_id: Group's id * * group_name: Group's name * * user_id: User's id * * id: ID of a post to get * * ids: List of IDs of post to get * * restricted: If true, limits the number of photos displayed * @param int $limit Number of posts to be returned * @param int $offset Number of posts to skip * @return array */ public function getPosts($params, $limit, $offset = 0) { $cache_entry = 'posts-' . $limit . '-' . $offset; foreach ($params as $key => $value) { if (isset($value)) { $cache_entry .= '-' . $key . ':' . (is_array($value) ? implode(',', $value) : $value); } } $posts = Cache::read($cache_entry); if ($posts !== false) { return $posts; } $where = array(); if (isset($params['group_id'])) { $where[] = 'p.group_id = ' . $params['group_id']; } if (isset($params['group_name'])) { $where[] = 'a.url_name = ' . DB::quote($params['group_name']); } if (isset($params['official'])) { $where[] = 'p.official = ' . ($params['official'] ? 1 : 0); } if (!isset($params['show_private']) || !$params['show_private']) { $where[] = 'p.private = 0'; } if (isset($params['category_id'])) { $where[] = 'c.id = "' . $params['category_id'] . '"'; } if (isset($params['category_name'])) { $where[] = 'c.url_name = ' . DB::quote($params['category_name']); } if (isset($params['user_id'])) { $where[] = 'p.user_id = ' . DB::quote($params['user_id']); } if (isset($params['ids']) && is_array($params['ids'])) { if (count($params['ids']) == 0) { return array(); } $where[] = 'p.id IN (' . implode(',', $params['ids']) . ')'; } if (isset($params['id']) && (is_int($params['id']) || ctype_digit($params['id']))) { $where[] = 'p.id = ' . $params['id']; } $posts = DB::select(' SELECT p.id, p.message, p.time, p.private, p.official, p.category_id,p.dislike, a.id AS group_id, a.name AS group_name, a.url_name AS group_url, u.username, s.student_number, s.firstname, s.lastname FROM posts p INNER JOIN categories c ON c.id = p.category_id INNER JOIN users u ON u.id = p.user_id ' . (isset($params['group_id']) || isset($params['group_name']) ? 'INNER' : 'LEFT') . ' JOIN groups a ON a.id = p.group_id LEFT JOIN students s ON s.username = u.username ' . (count($where) != 0 ? 'WHERE ' . implode(' AND ', $where) : '') . ' ORDER BY p.time DESC LIMIT ' . $offset . ', ' . $limit . ' '); if (count($posts) != 0) { if (isset($params['ids']) && is_array($params['ids'])) { Utils::arraySort($posts, 'id', $params['ids']); } $post_ids = array(); foreach ($posts as $post) { $post_ids[] = (int) $post['id']; } // Comments $comments = DB::select(' SELECT pc.post_id, pc.id, pc.message, pc.time, pc.attachment_id, pc.id, u.username, s.student_number, s.firstname, s.lastname FROM post_comments pc INNER JOIN users u ON u.id = pc.user_id INNER JOIN students s ON s.username = u.username WHERE pc.post_id IN (' . implode(',', $post_ids) . ') ' . (isset($params['restricted']) && $params['restricted'] ? 'AND pc.attachment_id IS NULL' : '') . ' ORDER BY pc.time ASC '); $comment_likes = DB::select(' SELECT pcl.comment_id, pcl.user_id as comment_like_user_id, u.username, s.student_number, s.firstname, s.lastname FROM post_comment_likes pcl INNER JOIN post_comments pc ON pcl.comment_id = pc.id INNER JOIN users u ON u.id = pcl.user_id INNER JOIN students s ON s.username = u.username WHERE pc.post_id IN (' . implode(',', $post_ids) . ') ' . (isset($params['restricted']) && $params['restricted'] ? 'AND pc.attachment_id IS NULL' : '') . ' '); $comments_by_post_id = array(); foreach ($comments as $comment) { $post_id = (int) $comment['post_id']; if (!isset($comments_by_post_id[$post_id])) { $comments_by_post_id[$post_id] = array(); } unset($comment['post_id']); $comment['avatar_url'] = Student_Model::getAvatarURL($comment['student_number'], true); /* Traitement des Likes */ foreach ($comment_likes as $comment_like) { // Si c'est le like en question : if ($comment['id'] == $comment_like['comment_id']) { $comment['like'][] = $comment_like; $comment['user_liked'][] = $comment_like['comment_like_user_id']; } } $comments_by_post_id[$post_id][] = $comment; } unset($comments); // Posts Likes $likes = DB::select(' SELECT li.post_id, li.id, li.user_id as like_user_id,li.attachment_id, u.username, s.firstname, s.lastname FROM post_likes li INNER JOIN users u ON u.id = li.user_id INNER JOIN students s ON s.username = u.username WHERE li.post_id IN (' . implode(',', $post_ids) . ') ' . (isset($params['restricted']) && $params['restricted'] ? 'AND li.attachment_id IS NULL' : '') . ' ORDER BY li.id DESC '); $likes_by_post_id = array(); $users_likes = array(); foreach ($likes as $like) { // Les trie par post_id => puis par $attachement_id $post_id = (int) $like['post_id']; // On Extrait le n° d'attachment if ($like['attachment_id'] == null) { $attachment_id = 0; } else { $attachment_id = (int) $like['attachment_id']; } if (empty($likes_by_post_id[$post_id][$attachment_id])) { $likes_by_post_id[$post_id][$attachment_id] = array(); } // Pour savoir qui a "Aimé" if (empty($users_likes[$post_id][$attachment_id])) { $users_likes[$post_id][$attachment_id] = array(); } $users_likes[$post_id][$attachment_id][] = $like['like_user_id']; unset($like['post_id']); unset($like['attachment_id']); $likes_by_post_id[$post_id][$attachment_id][] = $like; } unset($likes); // Posts Dislikes $dislikes = DB::select(' SELECT dli.post_id, dli.id, dli.user_id as dislike_user_id,dli.attachment_id, u.username, s.firstname, s.lastname FROM post_dislikes dli INNER JOIN users u ON u.id = dli.user_id INNER JOIN students s ON s.username = u.username WHERE dli.post_id IN (' . implode(',', $post_ids) . ') ' . (isset($params['restricted']) && $params['restricted'] ? 'AND dli.attachment_id IS NULL' : '') . ' ORDER BY dli.id DESC '); $dislikes_by_post_id = array(); $users_dislikes = array(); foreach ($dislikes as $dislike) { // Les trie par post_id => puis par $attachement_id $post_id = (int) $dislike['post_id']; // On Extrait le n° d'attachment if ($dislike['attachment_id'] == null) { $attachment_id = 0; } else { $attachment_id = (int) $dislike['attachment_id']; } if (empty($dislikes_by_post_id[$post_id][$attachment_id])) { $dislikes_by_post_id[$post_id][$attachment_id] = array(); } // Pour savoir qui a "Aimé" if (empty($users_dislikes[$post_id][$attachment_id])) { $users_dislikes[$post_id][$attachment_id] = array(); } $users_dislikes[$post_id][$attachment_id][] = $dislike['dislike_user_id']; unset($dislike['post_id']); unset($dislike['attachment_id']); $dislikes_by_post_id[$post_id][$attachment_id][] = $dislike; } unset($dislikes); // echo '<pre>'; // print_r($likes_by_post_id); // echo '</pre>'; // Attachments $attachments = DB::select(' SELECT post_id, id, name, ext FROM attachments WHERE post_id IN (' . implode(',', $post_ids) . ') ORDER BY ext, id ASC '); $attachments_by_post_id = array(); $nb_photos_by_post_id = array(); foreach ($attachments as $attachment) { $post_id = (int) $attachment['post_id']; // Limitation of the number of displayed photos if (in_array($attachment['ext'], array('jpg', 'png', 'gif'))) { if (!isset($nb_photos_by_post_id[$post_id])) { $nb_photos_by_post_id[$post_id] = 0; } $nb_photos_by_post_id[$post_id]++; if (isset($params['restricted']) && $params['restricted'] && $nb_photos_by_post_id[$post_id] > Config::PHOTOS_PER_POST) { continue; } } $attachment['url'] = self::getAttachedFileURL((int) $attachment['id'], $attachment['ext']); if (in_array($attachment['ext'], array('jpg', 'png', 'gif', 'flv', 'mp4'))) { $attachment['thumb'] = self::getAttachedFileURL((int) $attachment['id'], 'jpg', 'thumb'); } if (!isset($attachments_by_post_id[$post_id])) { $attachments_by_post_id[$post_id] = array(); } unset($attachment['post_id']); $attachments_by_post_id[$post_id][] = $attachment; } unset($attachments); // Events $events = DB::select(' SELECT post_id, id, title, date_start, date_end FROM events WHERE post_id IN (' . implode(',', $post_ids) . ') '); $events_by_post_id = array(); foreach ($events as $event) { $post_id = (int) $event['post_id']; unset($event['post_id']); $events_by_post_id[$post_id] = $event; } unset($events); // Surveys $surveys = DB::select(' SELECT post_id, id, question, multiple, date_end FROM surveys WHERE post_id IN (' . implode(',', $post_ids) . ') '); $surveys_by_post_id = array(); if (count($surveys) != 0) { $surveys_ids = array(); foreach ($surveys as $survey) { $surveys_ids[] = (int) $survey['id']; } $survey_answers = DB::select(' SELECT id, survey_id, answer, nb_votes, votes FROM survey_answers WHERE survey_id IN (' . implode(',', $surveys_ids) . ') ORDER BY id ASC '); $survey_answers_by_survey_id = array(); foreach ($survey_answers as $survey_answer) { $survey_id = (int) $survey_answer['survey_id']; unset($survey_answer['survey_id']); if (!isset($survey_answers_by_survey_id[$survey_id])) { $survey_answers_by_survey_id[$survey_id] = array(); } $survey_answers_by_survey_id[$survey_id][] = $survey_answer; } unset($survey_answers); foreach ($surveys as $survey) { $post_id = (int) $survey['post_id']; unset($survey['post_id']); $survey['answers'] = isset($survey_answers_by_survey_id[(int) $survey['id']]) ? $survey_answers_by_survey_id[(int) $survey['id']] : array(); $surveys_by_post_id[$post_id] = $survey; } unset($survey_answers_by_survey_id); } unset($surveys); foreach ($posts as &$post) { $post_id = (int) $post['id']; if (isset($comments_by_post_id[$post_id])) { $post['comments'] =& $comments_by_post_id[$post_id]; } if (isset($likes_by_post_id[$post_id])) { $post['likes']['data'] =& $likes_by_post_id[$post_id]; } if (isset($users_likes[$post_id])) { $post['likes']['users'] =& $users_likes[$post_id]; } if (isset($dislikes_by_post_id[$post_id])) { $post['dislikes']['data'] =& $dislikes_by_post_id[$post_id]; } if (isset($users_dislikes[$post_id])) { $post['dislikes']['users'] =& $users_dislikes[$post_id]; } if (isset($attachments_by_post_id[$post_id])) { $post['attachments'] =& $attachments_by_post_id[$post_id]; } if (isset($events_by_post_id[$post_id])) { $post['event'] =& $events_by_post_id[$post_id]; } if (isset($surveys_by_post_id[$post_id])) { $post['survey'] =& $surveys_by_post_id[$post_id]; } $post['attachments_nb_photos'] = isset($nb_photos_by_post_id[$post_id]) ? $nb_photos_by_post_id[$post_id] : 0; // Avatar if (isset($post['group_id']) && $post['official'] == '1') { $post['avatar_url'] = Group_Model::getAvatarURL((int) $post['group_id'], true); } else { if (isset($post['student_number'])) { $post['avatar_url'] = Student_Model::getAvatarURL((int) $post['student_number'], true); } } } } // Write the cache Cache::write($cache_entry, $posts, 20 * 60); $cache_list = Cache::read('posts-cachelist'); if (!$cache_list) { $cache_list = array(); } if (!in_array($cache_entry, $cache_list)) { $cache_list[] = $cache_entry; } Cache::write('posts-cachelist', $cache_list, 20 * 60); return $posts; }
/** * 创建活动 */ public function create() { if ($this->get_method() != 'POST') { $this->send_response(405, NULL, '请求的方法不存在'); } $data = $this->get_data(); if (!$data) { $this->send_response(400, NULL, '400505:活动信息非法'); } $post = new Validation($data); $post->add_rules('title', 'required', 'length[1, 30]'); $post->add_rules('start_at', 'required', 'numeric'); $post->add_rules('end_at', 'required', 'numeric'); $post->add_rules('spot', 'required', 'length[1, 30]'); $post->add_rules('type', 'required', 'numeric', array($this, '_check_type_validation')); $post->add_rules('is_allow_invite', 'required', 'numeric', array($this, '_check_allow_invite_validation')); $post->add_rules('content', 'length[0, 300]'); $post->add_rules('group_ids', array($this, '_check_group_ids_validation')); $post->add_callbacks(TRUE, array($this, '_check_time_validation')); if ($post->validate()) { $activity = array(); $form = $post->as_array(); $activity['creator_id'] = $this->user_id; $activity['title'] = $form['title']; $activity['start_time'] = $form['start_at']; $activity['end_time'] = $form['end_at']; $nowTime = time(); $activity['create_time'] = $nowTime; $activity['spot'] = $form['spot']; $activity['type'] = $form['type']; $activity['is_allow_invite'] = $form['is_allow_invite']; if (isset($form['content'])) { $activity['content'] = $form['content']; } $groupIds = array(); if (isset($form['group_ids'])) { $groupIds = $form['group_ids']; } $groupModel = new Group_Model(); $gidArray = array(); foreach ($groupIds as $id) { $id = floatval($id); if ($id != -1) { $groupInfo = $groupModel->getGroupInfo($id); if (!$groupInfo) { $this->send_response(400, NULL, '400506:活动发布到的群不存在'); } $grade = $groupModel->getMemberGrade($id, $this->user_id); if ($grade < 1) { $this->send_response(400, NULL, '400507:您不是活动指定发布到群的成员'); } } $gidArray[] = $id; } if (!$gidArray) { $activity['is_publish'] = 0; } else { $activity['is_publish'] = 1; } $activity_id = $this->model->add($activity); $activityMember = array('aid' => $activity_id, 'uid' => $this->user_id, 'apply_type' => Kohana::config('activity.apply_type.join'), 'apply_time' => $nowTime, 'grade' => Kohana::config('activity.grade.creator')); $result = $this->model->applyActivity($activityMember); $this->model->addActivityUser($activity_id, $this->user_id); $friendModel = new Friend_Model(); $fidList = $friendModel->getAllFriendIDs($this->user_id, false); //活动动态发送到指定momo成员 foreach ($gidArray as $gid) { $this->model->addActivityGroup($activity_id, $gid); if ($gid == -1) { $friendModel = new Friend_Model(); $fidList = $friendModel->getAllFriendIDs($this->user_id, false); foreach ($fidList as $fid) { $this->model->addActivityUser($activity_id, $fid); } } else { $this->model->addActivityGroup($activity_id, $gid); $members = $groupModel->getGroupAllMember($gid); foreach ($members as $value) { $this->model->addActivityUser($activity_id, $value['uid']); } } } $feedModel = new Feed_Model(); $title = array('uid' => $this->user_id, 'name' => sns::getrealname($this->user_id), 'id' => $activity_id, 'title' => $activity['title']); $messageModel = new Message_Model(); if ($activity['is_publish']) { $feedModel->addFeed($this->user_id, 'action_add', Kohana::config('uap.app.action'), $title, array(), $activity_id); } $this->send_response(200, array('id' => floatval($activity_id))); } $errors = $post->errors(); $this->send_response(400, NULL, '400505:活动信息非法'); }
public function getFriendFeedNew($uid, $uptime, $pretime, $downtime, $pos, $type_id = 0) { $uptime = $uptime . ''; $downtime = $downtime . ''; $pretime = $pretime . ''; $direct = ''; if ($uptime && $downtime) { $direct = 'middle'; } else { if ($uptime) { $direct = 'up'; } else { if ($downtime) { $direct = 'down'; } else { if ($pretime) { $direct = 'pre'; } } } } $uids = null; if (!$uids) { $uids = $this->friend->get_user_link_cache($uid); $uids[] = $uid . ''; $uids[] = Kohana::config('uap.xiaomo'); //群组动态 $group_array = Group_Model::instance()->getUserAllGroupId($uid); if ($group_array) { foreach ($group_array as $group) { $uids[] = '1_' . $group['gid']; } } } switch ($direct) { case 'pre': $condition = array('mix_id' => array('$in' => $uids), 'last_updated' => array('$gt' => $pretime), '_id' => array('$nin' => $this->hiddenId())); $deltime = $pretime; break; case 'up': $condition = array('mix_id' => array('$in' => $uids), 'last_updated' => array('$gt' => $uptime), '_id' => array('$nin' => $this->hiddenId())); $deltime = $uptime; break; case 'down': //$pos += 1; $condition = array('mix_id' => array('$in' => $uids), 'last_updated' => array('$lt' => $downtime), '_id' => array('$nin' => $this->hiddenId())); break; case 'middle': $condition = array('mix_id' => array('$in' => $uids), 'last_updated' => array('$lt' => $uptime, '$gt' => $downtime), '_id' => array('$nin' => $this->hiddenId())); break; default: $condition = array('mix_id' => array('$in' => $uids), '_id' => array('$nin' => $this->hiddenId())); break; } $id_del = array(); if ($direct == 'pre' || $direct == 'up') { $con_del = array('qid' => array('$in' => $uids), 'time' => array('$gt' => $deltime)); $cur = $this->m->selectCollection('feed_del'); $arr_del = iterator_to_array($cur->find($con_del)); foreach ($arr_del as $row_del) { if ($row_del['objid']) { $id_del[] = array('id' => $row_del['objid']); } } $con_del = array('uid' => intval($uid), 'time' => array('$gt' => $deltime)); $cur = $this->m->selectCollection('feed_hide'); $arr_del = iterator_to_array($cur->find($con_del)); foreach ($arr_del as $row_del) { if ($row_del['objid']) { $id_del[] = array('id' => $row_del['objid']); } } } if ($type_id) { $condition['typeid'] = intval($type_id); } if ($direct == 'pre') { $col = $this->feed_new->find($condition)->sort(array('last_updated' => 1))->limit(intval($pos)); } else { $col = $this->feed_new->find($condition)->sort(array('last_updated' => -1))->limit(intval($pos)); } $arr = iterator_to_array($col); if ($direct == 'pre') { $arr = array_reverse($arr); } $count = count($arr); if ($count) { $res = array('code' => 200, 'result' => array('count' => $count, 'data' => $arr, 'delete' => $id_del)); } else { $res = array('code' => 404, 'result' => array('delete' => $id_del)); } return $res; }
/** * 取得列表json数据 * @method GET * * fail=1 失效 * sale=1 供 dealer=2 求 * city=城市名(eg:福州) * circle:1、好友; 6、熟人; 8、同城 * cate:1二手物品,2租房,3售房,4团购 * keyword:用户输入 * |myfav=1 我的收藏 * |mytrade=1 我的二手 * |myrent=1 我的租房 * |replymy=1 回复我的 * |hide=1 我的隐藏 * * @access public * @return void */ public function index() { if ($this->input->get("hide", 0)) { $start = (int) $this->input->get('page', 1); if ($start <= 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 = abs(($start - 1) * $pos); $result = $this->model->get_hidden_ids($this->user_id, $start, $pos); self::get_market_json(array("object_id" => array('$in' => $result), "status" => "all"), "", false); return null; } if ($this->input->get("myfav", 0)) { $start = (int) $this->input->get('page', 1); if ($start <= 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 = abs(($start - 1) * $pos); $result = $this->model->get_favorite_ids($this->user_id, $start, $pos); self::get_market_json(array("object_id" => array('$in' => $result), "status" => "all"), "", false); return null; } if ($this->input->get("mytrade", 0)) { self::get_market_json(array("user_id" => (int) $this->user_id, "category" => 1, "status" => "all"), "", false); return null; } if ($this->input->get("myrent", 0)) { self::get_market_json(array("user_id" => (int) $this->user_id, "category" => 2, "status" => "all"), "", false); return null; } if ($this->input->get("replymy", 0)) { $this->send_response(501, null, "暂不支持"); return null; } $fail = $this->input->get("fail", 0); $sale = $this->input->get("sale", 0); $city = $this->input->get("city", ""); $circle = $this->input->get("circle", 0); $cate = $this->input->get("cate", 0); $keyword = $this->input->get("keyword", ""); $keyword = $keyword ? strtr(trim($keyword), array("." => "", "*" => "", "+" => "", "?" => "", "[" => "", "]" => "", "(" => "", ")" => "", "," => "", "," => "")) : ""; $where = array(); if ($fail) { $where['status'] = 'all'; } if ($sale && in_array($sale, array('1', '2'))) { $where['type'] = (int) $sale; } if ($city) { $where['city'] = $city; } if ($cate && in_array($cate, array('1', '2', '3', '4', '5'))) { $where['category'] = (int) $cate; } //取得两个月内的隐藏数据 $lastmonth = mktime(0, 0, 0, date("m") - 2, date("d"), date("Y")); $not_id = $this->model->get_hidden_ids($this->uid, null, null, $lastmonth); if (!empty($not_id)) { $where['object_id'] = array('$nin' => $not_id); } //权限处理 没选权限默认是同城 if ($circle && in_array($circle, array('1', '6'))) { do { $user_ids = array(); if ($circle == 1) { $user_ids = Friend_Model::instance()->getAllFriendIDs($this->user_id); array_walk($user_ids, function (&$item) { $item = (int) $item; }); $user_ids[] = (int) $this->user_id; $where['privacy'] = array('$in' => array(1, 7, 9, 15)); break; } if ($circle == 6) { $sub_model = new Company_Model(); $cids = $sub_model->getCompanyList($this->user_id); foreach ($cids as $v) { $uids = $sub_model->getCompanyMemberIds($v["cid"]); $user_ids = array_merge($user_ids, $uids); } $sub_model = new Group_Model(); $gids = $sub_model->getUserAllGroupId($this->user_id); foreach ($gids as $v) { $uids = $sub_model->getGroupAllMember($v["gid"]); array_walk($uids, function (&$item) { $item = $item["uid"]; }); $user_ids = array_merge($user_ids, $uids); } unset($cids, $gids, $sub_model); array_walk($user_ids, function (&$item) { $item = (int) $item; }); $user_ids[] = (int) $this->user_id; $user_ids = array_unique($user_ids); $where['privacy'] = array('$in' => array(6, 7, 14, 15)); break; } } while (0); $where['user_id'] = array('$in' => $user_ids); } else { // 同城,(钩上同城选项)或者(好友、群友、同事、在同城) $where['privacy'] = array('$in' => array(0, 8, 9, 14, 15)); if (!$city) { $where['city'] = self::city_visitors(); } } self::get_market_json($where, $keyword); }
private function _add_feed_comment($activity, $old_apply_type, $apply_type, $uid) { $feedModel = new Feed_Model(); if ($apply_type == Kohana::config('activity.apply_type.join')) { $feedStatus = "参加"; $applyStatus = "参加"; } else { if ($apply_type == Kohana::config('activity.apply_type.interest')) { $feedStatus = "关注"; $applyStatus = "感兴趣"; } } if ($activity['gid'] != 0) { if ($apply_type != Kohana::config('activity.apply_type.not_join')) { $commentModel = new Comment_Model(); $content = "参与报名:" . $applyStatus; if ($activity['feed_id']) { $feed_id = $activity['feed_id']; $feedInfo = $feedModel->getFeedById($feed_id); if ($feedInfo) { $group_type = $feedInfo[$feed_id]['group_type']; $group_id = $feedInfo[$feed_id]['group_id']; $owner_uid = $feedInfo[$feed_id]['owner_uid']; if (!$group_type) { //好友 $friendModel = Friend_Model::instance(); $isFriend = $friendModel->check_isfriend($owner_uid, $uid); if ($isFriend) { $commentModel->saveComment($feed_id, $content, $owner_uid); } } else { if ($group_type == 1) { //群内 $groupModel = Group_Model::instance(); $grade = $groupModel->getMemberGrade($group_id, $uid); if ($grade > 0) { $commentModel->saveComment($feed_id, $content, $owner_uid); } } else { if ($group_type == 2) { //活动内 $activityModel = Activity_Model::instance(); $apply_type = $activityModel->getActivityApplyType($group_id, $uid); if ($apply_type > 0) { $commentModel->saveComment($feed_id, $content, $owner_uid); } } } } } } if ($activity['action_feed_id']) { $commentModel->saveComment($activity['action_feed_id'], $content, $activity['creator_id']); } } } if (!$old_apply_type && ($apply_type == Kohana::config('activity.apply_type.join') || $apply_type == Kohana::config('activity.apply_type.interest')) && $activity['is_allow_invite']) { $application = array('id' => floatval($activity['aid']), 'title' => '查看活动', 'url' => 'action/showblogbox/' . $activity['aid']); $feedModel->addFeed($uid, 7, $text = $feedStatus . '了活动:' . $activity['title'], $this->get_source(), $application, $at = array(), $images = array(), $sync = array(), $group_type = 0, $group_id = 0, $retweet_id = 0, $allow_rt = 0, $allow_comment = 1, $allow_praise = 1, $allow_del = 1, $allow_hide = 1); } }
/** * 批量获取联系人信息 * @param int $id 联系人ID */ public function show_batch($id = NULL) { if ($this->get_method() != 'POST') { $this->send_response(405, NULL, '请求的方法不存在'); } if (!is_numeric($id) or empty($id)) { $this->send_response(400, NULL, '400401:群ID为空'); } $groupModel = new Group_Model(); $groupInfo = $groupModel->getGroupInfo($id); if (!$groupInfo) { $this->send_response(400, NULL, '400402:群不存在'); } $grade = $groupModel->getMemberGrade($id, $this->user_id); if ($grade < Kohana::config('group.grade.normal')) { $this->send_response(400, NULL, '400411:非群成员,无权限查看联系人详细信息'); } $data = $this->get_data(); $ids = isset($data['ids']) ? $data['ids'] : ''; if (empty($ids)) { $this->send_response(400, NULL, '400215:群联系人ids为空'); } $ids = explode(',', $ids); $result = array(); if (count($ids) > 100) { $this->send_response(400, NULL, '400216:群联系人ids超过上限(100个)'); } $contact_ids = array_keys($this->model->get($id)); $friendModel = new Friend_Model(); foreach ($ids as $cid) { if (in_array($cid, $contact_ids)) { $contact = $this->model->get($id, $cid); if ($contact !== FALSE) { $contact['is_friend'] = 0; if ($contact['user_id'] > 0) { $isFriend = $friendModel->check_isfriend($this->user_id, $contact['user_id']); if ($isFriend) { $contact['is_friend'] = 1; } } $contact['momo_user_id'] = intval($contact['user_id']); unset($contact['user_id']); $result[] = $contact; } unset($contact); } } $this->send_response(200, $result); }
public function group_requests() { require_once WPPR_PLUGIN_DIR . '/models/group-model.php'; $model = new Group_Model(); $model->user_id = get_current_user_id(); return $model->join_requests(); }
/** * 从群组中删除 * @param $event_info 活动信息 */ private function _del_group_user($gid, $uid) { //从群组中删除 if (Group_Model::instance()->delGroupMember($gid, $uid)) { Group_Model::instance()->reduceMemberNum($gid); } //从tab中删除 Tab_Model::instance()->delete($uid, Kohana::config('group.type.event'), $gid); }
/** * * 获取用户的mix_id */ private function get_user_mix_ids() { $uids = array(); //联系人 $uids = Friend_Model::instance()->get_user_link_cache($this->user_id); //群组 $group_array = Group_Model::instance()->getUserAllGroupId($this->user_id); if ($group_array) { foreach ($group_array as $group) { $uids[] = '1_' . $group['gid']; } } array_push($uids, $this->user_id); return $uids; }
function is_not_joined_in_group($group_id) { require_once WP_PLUGIN_DIR . '/pr-membership/models/group-model.php'; $model = new Group_Model(); $user_id = get_current_user_id(); $result = $model->check_group_joins($group_id, $user_id); if ($result) { return true; } else { return false; } }
/** * Delete a group */ public function delete($params) { $this->setView('delete.php'); $is_logged = isset(User_Model::$auth_data); $is_admin = $is_logged && User_Model::$auth_data['admin'] == '1'; try { if (!$is_logged) { throw new Exception(); } $group = $this->model->getInfoByName($params['group']); } catch (Exception $e) { throw new ActionException('Page', 'error404'); } $this->setTitle(__('GROUP_DELETE_TITLE')); // Authorization $groups_auth = Group_Model::getAuth(); if (!$is_admin && !(isset($groups_auth[(int) $group['id']]) && $groups_auth[(int) $group['id']]['admin'])) { throw new ActionException('Page', 'error404'); } $this->set('group_name', $group['name']); $this->model->delete((int) $group['id']); }
public function updateNum() { $result = $this->model->updateNum(); $this->send_response(200, $result); }
public function updateGroupMemberContact($user_id) { $groupModel = new Group_Model(); $gidList = $groupModel->getUserGroupIdList($user_id, Kohana::config('group.type.private')); $contactModel = Contact_Model::instance(); $contact = $contactModel->get_user_info($user_id); $dateline = time(); foreach ($gidList as $value) { $gid = $value['gid']; $id = $this->getGroupCidbyGidAndUid($gid, $user_id); if ($id) { $contact->set_id($id)->set_user_id($user_id)->set_modified_at($dateline); $result = $this->edit($gid, $contact, 'overwrite'); $groupInfo['modify_time'] = $dateline; $groupModel->modifyGroup($gid, $groupInfo); unset($groupInfo); } } }
/** * 取得某条留言标题 * @param integer $appid 留言唯一标识 * */ public function getOnlySubject($sign = 1, $appid) { switch ($sign) { case 1: $subject = $this->db->getOne('diary', 'subject', "id='{$appid}'"); break; case 2: $subject = $this->db->getOne('vote', 'subject', "id='{$appid}'"); break; case 3: $subject = $this->db->getOne('userrecord', 'content', "id='{$appid}'"); break; case 4: $album = new Album_Model(); $array = $album->getAlbumInfoByAid($appid); $subject = $array['data']['album_name']; break; case 5: $photo = new Photo_Model(); $array = $photo->getPhotoInfoByPid($appid); $subject = $array['data']['pic_title']; break; case 6: $album = new Group_Model(); $array = $album->getAlbumInfoByAid($appid); $subject = $array['data']['album_name']; break; case 7: $photo = new Group_Model(); $array = $photo->getPhotoInfoByPid($appid); $subject = $array['data']['pic_title']; break; case 8: $album = new Group_Model(); $array = $album->getAlbumInfoByAid($appid); $subject = $array['data']['group_id']; break; default: break; } return $subject; }