. // stuff related to "buddy lists" require_once("../inc/forum_db.inc"); require_once("../inc/profile.inc"); // see if there's already a request, // and whether the notification record is there // function check_pending($user, $destuser) { $friend = BoincFriend::lookup($user->id, $destuser->id); if ($friend) { if ($friend->reciprocated) { error_page(tra("Already friends")); } $notify = BoincNotify::lookup($destuser->id, NOTIFY_FRIEND_REQ, $user->id); if ($notify) { page_head(tra("Request pending")); $t = date_str($friend->create_time); echo tra("You requested friendship with %1 on %2.", $destuser->name,$t) . "
" . tra("This request is still pending confirmation."); page_tail(); exit(); } BoincFriend::delete($user->id, $destuser->id); } } function check_ignoring($srcuser, $destuser) { BoincForumPrefs::lookup($destuser); if (is_ignoring($destuser, $srcuser)) { error_page(tra("%1 is not accepting friendship requests from you",$destuser->name)); } } // user has clicked "add to friends". Ask them if they really mean it. // function handle_add($user) { $destid = get_int('userid'); if ($destid == $user->id) { error_page(tra("You can't be friends with yourself")); } $destuser = BoincUser::lookup_id($destid); if (!$destuser) error_page(tra("No such user")); check_pending($user, $destuser); check_ignoring($user, $destuser); page_head(tra("Add friend")); echo "
"; page_tail(); } // User really means it. Make DB entry and send notification // function handle_add_confirm($user) { $destid = post_int('userid'); $destuser = BoincUser::lookup_id($destid); if (!$destuser) error_page(tra("No such user")); check_pending($user, $destuser); check_ignoring($user, $destuser); $msg = post_str('message', true); if ($msg) $msg = strip_tags(BoincDb::escape_string($msg)); $now = time(); $ret = BoincFriend::replace( "user_src=$user->id, user_dest=$destid, message='$msg', create_time=$now, reciprocated=0" ); if (!$ret) { error_page(tra("Database error")); } $now = time(); $type = NOTIFY_FRIEND_REQ; BoincNotify::replace("userid=$destid, create_time=$now, type=$type, opaque=$user->id"); BoincForumPrefs::lookup($destuser); if ($destuser->prefs->pm_notification == 1) { send_friend_request_email($user, $destuser, $msg); } page_head(tra("Friend request sent")); echo tra("We have notified %1 of your request.","".$destuser->name.""); page_tail(); } // Show destination user the details of request, ask if they accept // function handle_query($user) { $srcid = get_int('userid'); $srcuser = BoincUser::lookup_id($srcid); if (!$srcuser) error_page(tra("No such user")); $friend = BoincFriend::lookup($srcid, $user->id); if (!$friend) error_page(tra("Request not found")); page_head(tra("Friend request")); $x = user_links($srcuser, true); echo tra("%1 has added you as a friend.", $x); if (strlen($friend->message)) { echo "".tra("%1 says: %2", $srcuser->name, $friend->message)."
"; } echo ""; page_tail(); } // Here if they accepted // function handle_accept($user) { $srcid = get_int('userid'); $srcuser = BoincUser::lookup_id($srcid); if (!$srcuser) error_page(tra("No such user")); $friend = BoincFriend::lookup($srcid, $user->id); if (!$friend) { error_page(tra("No request")); } $friend->update("reciprocated=1"); // "accept message" not implemented in interface yet $msg = post_str('message', true); if ($msg) $msg = strip_tags(BoincDb::escape_string($msg)); $now = time(); $ret = BoincFriend::replace("user_src=$user->id, user_dest=$srcid, message='$msg', create_time=$now, reciprocated=1"); if (!$ret) { error_page(tra("Database error")); } $type = NOTIFY_FRIEND_ACCEPT; BoincNotify::replace("userid=$srcid, create_time=$now, type=$type, opaque=$user->id"); BoincForumPrefs::lookup($srcuser); if ($srcuser->prefs->pm_notification == 1) { send_friend_accept_email($user, $srcuser, $msg); } $notify = BoincNotify::lookup($user->id, NOTIFY_FRIEND_REQ, $srcid); if ($notify) { $notify->delete(); } page_head(tra("Friendship confirmed")); echo tra("Your friendship with %1 has been confirmed.","" . $srcuser->name .""); page_tail(); } // Here if they declined // function handle_ignore($user) { $srcid = get_int('userid'); $srcuser = BoincUser::lookup_id($srcid); if (!$srcuser) error_page("No such user"); $friend = BoincFriend::lookup($srcid, $user->id); if (!$friend) { error_page("No request"); } $notify = BoincNotify::lookup($user->id, NOTIFY_FRIEND_REQ, $srcid); if ($notify) { $notify->delete(); } page_head(tra("Friendship declined")); echo tra("You have declined friendship with %1","".$srcuser->name.""); page_tail(); } // Here if initiator clicked on "confirmed" notification. // Delete notification // function handle_accepted($user) { $destid = get_int('userid'); $destuser = BoincUser::lookup_id($destid); if (!$destuser) error_page(tra("No such user")); $notify = BoincNotify::lookup($user->id, NOTIFY_FRIEND_ACCEPT, $destid); if ($notify) { $notify->delete(); } else { echo tra("Notification not found"); } page_head(tra("Friend confirmed")); echo tra("You are now friends with %1.",$destuser->name); page_tail(); } function handle_cancel_confirm($user) { $destid = get_int('userid'); $destuser = BoincUser::lookup_id($destid); if (!$destuser) error_page(tra("No such user")); page_head(tra("Cancel friendship?")); echo tra("Are you sure you want to cancel your friendship with %1?",$destuser->name) ."