. // 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("Already friends"); } $notify = BoincNotify::lookup($destuser->id, NOTIFY_FRIEND_REQ, $user->id); if ($notify) { page_head("Request pending"); $t = date_str($friend->create_time); echo "You requested friendship with $destuser->name on $t.

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("$destuser->name is not accepting friendship requests from you"); } } // 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("You can't be friends with yourself"); } $destuser = BoincUser::lookup_id($destid); if (!$destuser) error_page("No such user"); check_pending($user, $destuser); check_ignoring($user, $destuser); page_head("Add friend"); echo "

You have asked to add $destuser->name as a friend. We will notify $destuser->name and will ask him/her to confirm that you are friends.

Add an optional message here:

"; 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("No such user"); check_pending($user, $destuser); check_ignoring($user, $destuser); $msg = post_str('message', true); if ($msg) $msg = strip_tags(process_user_text($msg)); $now = time(); $ret = BoincFriend::replace( "user_src=$user->id, user_dest=$destid, message='$msg', create_time=$now, reciprocated=0" ); if (!$ret) { error_page("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("Friend request sent"); echo " We have notified $destuser->name of your request. "; 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("No such user"); $friend = BoincFriend::lookup($srcid, $user->id); if (!$friend) error_page("Request not found"); page_head("Friend request"); $x = user_links($srcuser, true); echo " $x has added you as a friend. "; if (strlen($friend->message)) { echo "

$srcuser->name says: $friend->message

"; } echo "