示例#1
0
 /**
  * Function used to add a friend request 
  * 
  * @param INT userid (one who is rquesting)
  * @param INT friend_id (one whos userid is requesting)
  * 
  */
 function add_friend_request($array)
 {
     $uid = $array['userid'];
     $fid = $array['friend_id'];
     $msg = $array['message'];
     if ($fid == $uid && $uid) {
         e(lang('You cannot send friend request to yourself'));
         return false;
     }
     if (!userid()) {
         e(lang('You are not logged in'));
         return false;
     }
     $friend = get_basic_user_details($fid);
     $user = get_basic_user_details($uid);
     if (!$friend) {
         e(lang('Unknown user'));
         return false;
     }
     $fname = name($friend);
     if ($this->is_friend($uid, $fid)) {
         e(sprintf(lang('You and %s are already friends'), $fname));
         return false;
     }
     if ($this->is_friend_requested($uid, $fid)) {
         e(sprintf(lang('You have already sent a friend request to %s'), $fname));
         return false;
     }
     //@todo : add restricions on sending requst >.<
     $db_fields = array('userid' => $uid, 'message' => $msg, 'friend_id' => $fid, 'time_added' => time());
     $req_id = db_insert(tbl('friend_requests'), $db_fields);
     //Add Friend notification..
     $this->new_notify($fid, 'new_friend_requests');
     e(sprintf(lang('Your friend request has been sent to %s'), $fname), 'm');
     return $req_id;
 }
示例#2
0
 /**
  * Create the thread
  */
 function create_thread($params)
 {
     $default_values = array('userid' => userid(), 'subject' => "", 'thread_type' => 'private', 'recipients' => array());
     $data = array_merge($default_values, $params);
     $the_data = array();
     //Keep only specific indexes
     foreach ($default_values as $key => $value) {
         $the_data[$key] = $data[$key];
     }
     //Turn Keys to variables...
     extract($the_data);
     if (!$recipients) {
         e(lang('No recipients with the thread'));
         return false;
     }
     $recipients[] = $userid;
     $recipients = array_unique($recipients);
     if (!$userid) {
         e(lang('Please login / Invalid user'));
         return false;
     }
     arsort($recipients);
     $total_recipients = count($recipients);
     if ($subject) {
         $subject = strip_tags(replacer($subject));
     }
     $recipients_imploded = implode('|', $recipients);
     $recipient_md5 = md5($recipients_imploded);
     //Make first three MAIN recipients
     $main_limit = 3;
     $main_recipients = array();
     for ($i = 0; $i < $main_limit; $i++) {
         if ($recipients[$i]) {
             $main_recipients[] = get_basic_user_details($recipients[$i]);
         }
     }
     $thread_id = $this->get_thread_from_md5($recipient_md5);
     if (!$thread_id) {
         $insert_array = array('thread_type' => $thread_type, 'userid' => $userid, 'recipient_md5' => $recipient_md5, 'total_recipients' => $total_recipients, 'date_added' => now(), 'subject' => $subject, 'main_recipients' => json_encode($main_recipients), 'time_added' => time());
         $thread_id = db_insert(tbl('threads'), $insert_array);
         //Add recipients
         $this->add_recipients($recipients, $thread_id);
     }
     if ($thread_id) {
         return $thread_id;
     } else {
         return false;
     }
 }