public static function addFriend($rater_group_id)
 {
     try {
         $q = Doctrine::getTable('RatersGroup')->findOneBy("id", $rater_group_id);
         $friendship = new Friendship();
         $friendship->setMemberId($q->rater);
         $friendship->setFriendId($q->ratee);
         $friendship->setStatus(1);
         $friendship->save();
     } catch (Exception $e) {
         die($e->getMessage());
     }
 }
Example #2
0
 public static function get_profile($u, $privacy = true, $badges = true, $social_networks = true, $friends = true, $exp = true, $aditional_info = true, $gamertags = true)
 {
     Phalanx::loadClasses('Privacy', 'Badges', 'Friendship', 'SocialNetwork', 'Posts', 'GamerTags');
     $m = Model::Factory('user u');
     $m->where("login='******'");
     $user = $m->get();
     if (!$user) {
         return false;
     }
     # Em alguns casos, não é necessário utilizarmos todos os dados do usuário
     if ($privacy) {
         $user->privacy = Privacy::from_user($user->id);
     }
     if ($badges) {
         $user->badges = Badges::from_user($user->id);
     }
     if ($social_networks) {
         $user->social_networks = SocialNetwork::from_user($user->id);
     }
     if ($friends) {
         $user->friends = Friendship::from_user($user->id, 12);
     }
     if ($exp) {
         $user->experience = self::experience($user->id);
     }
     if ($aditional_info) {
         $user->aditional_info = self::other_data($user->id);
     }
     if ($gamertags) {
         $user->gamertags = GamerTags::from_user($user->id);
     }
     return $user;
 }
 public function get_json()
 {
     $o = new stdClass();
     $o->friends = Friendship::pending($this->session->user->id);
     $o->notifications = Notification::from_user($this->session->user->id, 15);
     $o->messages = Message::get($this->session->user->id, 10);
     header("Content-type: text/html; charset=utf-8");
     die('(' . json_encode($o) . ');');
 }
Example #4
0
 public static function build_from_list($uid, $list_id, stdClass $config)
 {
     Phalanx::loadClasses('Friendship');
     $friends_ids = Friendship::get_friend_array($uid);
     $friends_ids = implode(', ', $friends_ids);
     $where = "";
     if (property_exists($config, 'min')) {
         $where .= " AND p.id < '{$config->min}'";
     }
     if (property_exists($config, 'max')) {
         $where .= " AND p.id < '{$config->max}'";
     }
     Phalanx::loadClasses('Lists', 'SocialNetwork', 'Facebook', 'Twitter', 'twitteroauth', 'Instagram', 'PostCategory', 'Favorites', 'Profile');
     $list = Lists::from_user($uid, $list_id);
     $categories = array();
     foreach ($list->categories as $category) {
         $categories[] = $category->id;
     }
     if (sizeof($categories) > 0) {
         Phalanx::loadClasses('Posts', 'PostComments');
         $categories_ids = implode("', '", $categories);
         $custom_tl = array();
         $m = Model::Factory('posts p', false, 0);
         $m->fields('DISTINCT p.id 	AS id', 'p.original_posts_id	AS original_id', 'p.user_id 		AS user_id', 'p.content 		AS content', 'p.date 		AS date', 'p.title		AS title', 'p.promoted		AS promoted', 'u.name 		AS name', 'u.login		AS user', 'ud.avatar 		AS avatar', 'p.like_count		AS likes', 'p.dislike_count	AS dislikes', 'p.comment_count	AS comments', 'p.reblog_count		AS reblogs', 'p.reply_count		AS replies');
         $m->innerJoin('user u', 'u.id = p.user_id');
         $m->innerJoin('user_data ud', 'ud.user_id = p.user_id');
         $m->innerJoin('posts_has_category phc', 'p.id = phc.posts_id');
         $m->where("p.user_id IN({$friends_ids})  AND phc.category_id IN ('{$categories_ids}') {$where} AND u.banned IS NULL AND  p.status=1 AND p.date > DATE_SUB(NOW(), INTERVAL 1 MONTH)");
         #	$m->group("p.original_posts_id");
         $m->order('p.id DESC');
         $m->limit(NUMBER_OF_POSTS_LOADED_PER_TIME);
         $skynerd_posts = $m->all();
         foreach ($skynerd_posts as $each) {
             $o = new stdClass();
             $o->date = Date::RelativeTime($each->date);
             $o->id = $each->id;
             $o->user = $each->user;
             $o->name = $each->name;
             $o->title = $each->title;
             $o->avatar = $each->avatar;
             $o->user_id = $each->user_id;
             $o->rating = new stdClass();
             $o->rating->megaboga = $each->likes;
             $o->rating->whatever = $each->dislikes;
             $o->my_rating = Posts::userRating($uid, $each->id);
             $o->content = trim($each->content);
             $o->comments = $v->comments;
             $o->replies = $v->replies;
             $o->categories = PostCategory::from_post($each->id);
             $o->is_reblogged = Posts::userHasReblogged($each->id, $uid);
             $o->is_favorite = Favorites::is_favorite($uid, $each->id);
             $o->user_points = Profile::experience($v->user_id);
             $o->promoted = (bool) $each->promoted;
             if (!empty($o->original_id)) {
                 //Se o post for um reblog, então o conteúdo dele deve ser o do reblogado, mostrando as ações
                 $originalPost = Posts::from_user(false, $o->original_id);
                 $originalPost = reset($originalPost);
                 $o->content = $originalPost->content;
                 $o->title = $originalPost->title;
                 $o->reblogged_from = $originalPost->user;
                 $o->original_date = $originalPost->date;
                 $o->rating->reblog_count = $originalPost->rating->reblog_count;
                 $o->is_reblogged = Posts::userHasReblogged($originalPost->id, $uid);
             }
             $custom_tl[] = $o;
         }
     }
     return $custom_tl;
 }
 /**
  * get the 'other' view of this friendship 
  */
 public function reciprocal()
 {
     return Friendship::get()->filter(array('InitiatorID' => $this->OtherID, 'OtherID' => $this->InitiatorID))->first();
 }
    public function executeUpdateRequestStatus(sfWebRequest $request)
    {
        $userId = $_SESSION['userId'];
        $stat = $_POST['stat'];
        $friendship_id = $_POST['friendship_id'];
        Friendship::updateRequestStatus($stat, $friendship_id);
        $q1 = Doctrine::getTable('Friendship')->findOneBy("id", $friendship_id);
        $q2 = Doctrine::getTable('Member')->findOneBy("id", $q1->member_id);
        $q3 = Doctrine::getTable('Member')->findOneBy("id", $userId);
        if ($stat == 2) {
            $body = '<div style="font-family:tahoma;font-size:12px;">
                    Hi <b>' . $q2->nick_name . '</b>,
                    <br/>
                    <p>
                        <b> ' . $q3->nick_name . ' </b> has added you as their friend!
                    </p>

                    <blockqoute>
                        <div>
                        You can log onto your account and send messages to each other at any time.
                        </div>
                    </blockqoute>
                    <br/>                    
                </div>';
        } else {
            $body = '<div style="font-family:tahoma;font-size:12px;">
                    Hi <b>' . $q2->nick_name . '</b>,
                    <br/>
                    <p>
                        <b> ' . $q3->nick_name . ' </b> has decided not to add you as their friend at this time.
                    </p>

                    <blockqoute>
                        <div>
                        Don’t let that discourage you.  Log onto your account and respond to or create your own postings and meet a new friend today.
                        </div>
                    </blockqoute>
                    <br/>                    
                </div>';
        }
        $recipient = $q2->email;
        CustomHangout::email($recipient, $body, 'HangOutToday', 'HangOutToday Notification');
        die;
    }
 /**
  * Create a friendship relationship object
  * 
  * @param DataObject $member
  *				"me", as in the person who triggered the follow
  * @param DataObject $followed
  *				"them", the person "me" is wanting to add 
  * @return \Friendship
  * @throws PermissionDeniedException 
  */
 public function addFriendship(DataObject $member, DataObject $followed)
 {
     if (!$member || !$followed) {
         throw new PermissionDeniedException('Read', 'Cannot read those users');
     }
     if ($member->ID != $this->securityContext->getMember()->ID) {
         throw new PermissionDeniedException('Write', 'Cannot create a friendship for that user');
     }
     $existing = Friendship::get()->filter(array('InitiatorID' => $member->ID, 'OtherID' => $followed->ID))->first();
     if ($existing) {
         return $existing;
     }
     // otherwise, we have a new one!
     $friendship = new Friendship();
     $friendship->InitiatorID = $member->ID;
     $friendship->OtherID = $followed->ID;
     // we add the initiator into the
     // lets see if we have the reciprocal; if so, we can mark these as verified
     $reciprocal = $friendship->reciprocal();
     // so we definitely add the 'member' to the 'followers' group of $followed
     $followers = $followed->getGroupFor(MicroBlogMember::FOLLOWERS);
     $followers->Members()->add($member);
     if ($reciprocal) {
         $reciprocal->Status = 'Approved';
         $reciprocal->write();
         $friendship->Status = 'Approved';
         // add to each other's friends groups
         $friends = $followed->getGroupFor(MicroBlogMember::FRIENDS);
         $friends->Members()->add($member);
         $friends = $member->getGroupFor(MicroBlogMember::FRIENDS);
         $friends->Members()->add($followed);
     }
     $friendship->write();
     return $friendship;
 }
Example #8
0
 public function SearchPeople()
 {
     #Goodbye, XSS
     if ($this->session->accept_token != REQUEST_TOKEN) {
         Request::redirect(HOST . 'login');
         return;
     }
     $m = Model::Factory('user u', true, 180);
     $username = trim($this->post->username);
     $m->fields("DISTINCT\tu.name\tAS name", "u.id\t\t\t\tAS id", "u.login\t\t\tAS login", "ud.avatar\t\t\tAS avatar");
     $m->leftJoin('user_data ud', 'ud.user_id = u.id');
     $m->where("((u.login LIKE '{$username}%') OR u.name LIKE '{$username}%') AND u.id NOT IN('{$this->session->user->id}', 0)");
     $m->limit(15);
     $users = $m->all();
     foreach ($data as $k => $v) {
         $users[$k]->friendship_status = Friendship::get_status($this->session->user->id, $v->id);
     }
     $o = new stdClass();
     header("Content-type:application/json;charset=utf-8");
     if ($users) {
         $o->status = 1;
         $o->users = $users;
     } else {
         $o->status = 0;
         $o->message = "NOT FOUND";
     }
     die(json_encode($o));
 }
Example #9
0
 private function send($action_type, $taken_by, $action_id, $notify_uid)
 {
     //Monta o model de notifications, com os valores padrão.
     $m = Model::Factory('notifications');
     $m->action_id = $action_id;
     $m->action_type = $action_type;
     $m->date = date('Y-m-d H:i:s');
     $m->readed = 0;
     switch ($action_type) {
         case Notification::WON_A_BADGE:
             $notify_user_id = $taken_by;
             break;
         case Notification::FAVORITED_A_POST:
         case Notification::DISLIKED_POST:
         case Notification::LIKED_POST:
         case Notification::REBLOGGED_POST:
             //Cria um model auxiliar para descobrir quem é o dono do post
             $aux_m = Model::Factory('posts');
             $aux_m->where("id='{$action_id}'");
             $m->notify_user_id = $aux_m->get()->user_id;
             $m->took_by_user_id = $taken_by;
             break;
         case Notification::LIKED_COMMENT:
         case Notification::DISLIKED_COMMENT:
             //Cria um model auxiliar para descobrir quem é o dono do comment
             $aux_m = Model::Factory('comment');
             $aux_m->where("id='{$action_id}'");
             $m->notify_user_id = $aux_m->get()->user_id;
             $m->took_by_user_id = $taken_by;
             break;
         case Notification::COMMENTED_POST:
             //Cria um model auxiliar para descobrir quem é o dono do post
             $postModel = Model::Factory('posts');
             $postModel->where("id='{$action_id}'");
             $post = $postModel->get();
             $m->notify_user_id = $post->user_id;
             $m->took_by_user_id = $taken_by;
             break;
         case Notification::REPLYED_COMMENT:
             //Cria um model auxiliar para descobrir quem é o dono do comment
             $aux_m = Model::Factory('comment');
             $aux_m->where("id='{$action_id}'");
             $m->notify_user_id = $aux_m->get()->user_id;
             $m->took_by_user_id = $taken_by;
             break;
         case Notification::LEVELED_UP:
             $m->notify_user_id = $taken_by;
             break;
         case Notification::BEFRIENDED:
         case Notification::TAGGED_IN_A_COMMENT:
         case Notification::TAGGED_IN_A_POST:
             $m->notify_user_id = $notify_uid;
             $m->took_by_user_id = $taken_by;
             $m->action_id = $action_id;
             break;
         case Notification::CHANGED_AVATAR:
             Phalanx::loadClasses('Friendship');
             $friends = Friendship::from_user($taken_by);
             $date = date('Y-m-d H:i:s');
             foreach ($friends as $friend) {
                 $m = Model::Factory('notifications');
                 $m->action_id = $action_id;
                 $m->action_type = $action_type;
                 $m->date = $date;
                 $m->readed = 0;
                 $m->notify_user_id = $friend->id;
                 $m->took_by_user_id = $taken_by;
                 if ($m->took_by_user_id == $m->notify_user_id) {
                     continue;
                 }
                 $m->insert();
             }
             break;
     }
     if ($m->took_by_user_id == $m->notify_user_id) {
         return;
     }
     foreach ($m as $k => $v) {
         $notify = array();
         $notify[$k] = $v;
     }
     return $m->insert();
 }
Example #10
0
 public function DisplayPost()
 {
     if ($this->get->username == 'wordpressagent') {
         Request::redirect(HOST);
     }
     Phalanx::loadClasses('Profile', 'Friendship', 'Posts');
     $profile_data = Profile::get_profile($this->get->username, 0, 0, 0, 0, 0, 0, 0);
     if ($profile_data->banned == 1) {
         $this->views->display("profile_banned.phtml");
         return;
     }
     if ($profile_data->active == 0) {
         $this->views->display("profile_deactivated.phtml");
         return;
     }
     $friendship_status = Friendship::get_status($this->session->user->id, $profile_data->id);
     $this->views->data->friendship_status = $friendship_status;
     $this->views->data = $profile_data;
     $p = Posts::from_user($profile_data->id, $this->get->post_id);
     if (!$p) {
         $this->views->display("post_unavailable.phtml");
         return;
     }
     $p = reset($p);
     $can_be_displayed = true;
     #Verifica se o post é privado.
     if ($p->privacy == 1) {
         if (!$this->session->user->id) {
             $this->views->display("post_unavailable.phtml");
             die;
         }
         if ($this->session->user->id == $p->user_id) {
             $can_be_displayed = true;
         } else {
             $can_be_displayed = Friendship::get_status($this->session->user->id, $p->user_id);
         }
     }
     if (!$can_be_displayed) {
         $this->views->display("post_unavailable.phtml");
         die;
     }
     $v = new Views();
     $v->title = $p->title;
     $v->user = $p->user;
     $v->name = $p->name;
     $v->content = $p->content;
     $v->comments = $p->comments;
     $v->comments_array = PostComments::get($this->get->post_id);
     $v->replies = $p->replies;
     $v->post_id = $p->id;
     $v->original_id = $p->original_id;
     $v->avatar = $p->avatar;
     $v->rating = $p->rating;
     $v->promoted = (bool) $p->promoted;
     $v->accept_nsfw = Profile::acceptNSFW($this->session->user->id);
     $v->when = $p->date;
     $v->my_rating = $p->my_rating;
     $v->current_user = $this->session->user->login;
     $v->categories = PostCategory::from_post($p->id);
     $v->its_mine = $profile_data->id == $this->session->user->id ? true : false;
     $v->is_favorite = $p->is_favorite;
     $v->user_points = $p->user_points;
     if (!empty($p->original_id)) {
         //Se o post for um reblog, então o conteúdo dele deve ser o do reblogado, mostrando as ações
         $originalPost = Posts::from_user(false, $p->original_id);
         $originalPost = reset($originalPost);
         $v->content = $originalPost->content;
         $v->title = $originalPost->title;
         $v->reblogged_from = $originalPost->user;
         $v->reblog_avatar = $originalPost->avatar;
         $v->reblog_points = $originalPost->user_points;
         $v->original_date = $originalPost->date;
         $v->rating = $originalPost->rating;
         $v->comments = $originalPost->comments;
         $v->replies = $originalPost->replies;
         $v->is_favorite = $originalPost->is_favorite;
         $v->categories = PostCategory::from_post($p->original_id);
         $v->comments_array = PostComments::get($p->original_id);
         $v->id = $p->id;
         $v->post_id = $originalPost->id;
     }
     $content = $v->render("post_body.phtml");
     $template = new Template("default");
     $template->og = new stdClass();
     $template->og->title = $v->user . ': ' . $v->title;
     $template->og->description = $p->content;
     $template->og->type = FACEBOOK_APPNAMESPACE . ':article_';
     $template->og->img = MEDIA_DIR . 'images/avatar/big/' . $p->avatar;
     if (!$this->isLoggedIn) {
         $template->show_login_bar = true;
     }
     $this->views = new Views($template);
     $this->views->data = $profile_data;
     $this->views->data->friendship_status = $friendship_status;
     $this->views->data->post = $content;
     $this->views->display("single_post_display.phtml");
 }