body<= 'bml.friends.edit/error', ljadwrapper => 1 }); return $ad_full_width . $str; }; return $print_with_ad->(LJ::server_down_html()) if $LJ::SERVER_DOWN; return $print_with_ad->("") unless LJ::text_in(\%POST); my $remote = LJ::get_remote(); return $print_with_ad->("") unless $remote; my $authas = $GET{'authas'} || $remote->user; my $getextra = $authas ne $remote->user ? "?authas=$authas" : ''; my $u = LJ::get_authas_user($authas); return $print_with_ad->(LJ::bad_input($ML{'error.invalidauth'})) unless $u; return BML::redirect("$LJ::SITEROOT/community/members.bml?authas=$u->{'user'}") if $u->is_community; return $print_with_ad->(LJ::bad_input($ML{'.error.badjournaltype'})) unless $u->is_person || $u->is_shared || $u->is_identity; my $ret; # no post, show edit form unless (LJ::did_post()) { ### who has you defined as a friend? my %res = (); LJ::do_request({ "user" => $u->{'user'}, "mode" => "friendof", "ver" => $LJ::PROTOCOL_VER, }, \%res, { "noauth" => 1, 'u' => $u }); ### who do you have defined as a friend? my %resf = (); LJ::do_request({ "user" => $u->{'user'}, "mode" => "getfriends", "ver" => $LJ::PROTOCOL_VER, }, \%resf, { "noauth" => 1, 'u' => $u }); # put it all together! my %friends = (); foreach my $i (1..$resf{'friend_count'}) { my $who = $resf{"friend_${i}_user"}; $friends{$who} = { username => $who, rel => 'FR', # for "friend" map { $_ => $resf{"friend_${i}_$_"} } qw(name bg fg) }; } foreach my $i (1..$res{'friendof_count'}) { my $who = $res{"friendof_${i}_user"}; if (defined $friends{$who}) { $friends{$who}->{'rel'} = 'M'; # for "mutual" } else { $friends{$who} = { username => $who, name => $res{"friendof_${i}_name"}, rel => 'FO' }; } } $ret .= "
\n"; return $print_with_ad->($ret); } # if they did a post, then process their changes if (LJ::did_post()) { return $print_with_ad->(LJ::bad_input($ML{'error.invalidform'})) unless LJ::check_form_auth(); my %request = (); $request{'mode'} = "editfriends"; $request{'ver'} = $LJ::PROTOCOL_VER; $request{'user'} = $u->user; # process the additions foreach (grep { /^editfriend_add/ } keys %POST) { $request{$_} = $POST{$_}; } # now flip the logic and process the deletions foreach (grep { /^editfriend_has/} keys %POST) { my $who = $POST{$_}; $request{"editfriend_delete_${who}"} = 1 unless $POST{"editfriend_keep_${who}"}; } my %response = (); LJ::do_request(\%request, \%response, { 'noauth' => 1, 'u' => $u }); if ($response{'success'} eq "OK") { $ret = LJ::get_ads({ location => 'bml.friends.edit/main', ljadwrapper => 1, below_ad => LJ::CProd->full_box_for($remote, width => 300) }); $ret .= ""; $ret .= ""; $ret .= "