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"; $ret .= LJ::form_auth(); ### edit friends. only show if they have friends/friend-ofs if (%friends) { $ret .= " "", 'img2' => "" }); $ret .= " p?>
"; $ret .= ""; my @friends; $ret .= ""; $ret .= ""; $ret .= ""; # TODO: paginate my $j = 11; # to uniquely distinguish 'friend-of' checkboxes, 1-10 are reserved for friend-add boxes foreach my $f (@friends) { my $who = $f->{'username'}; $ret .= ""; $ret .= ""; $ret .= "\n"; my $colors; $colors = "color: " . $f->{'fg'} . "; " if $f->{'fg'}; $colors .= "background-color: " . $f->{'bg'} . ";" if $f->{'bg'}; $colors = " style='$colors'" if $colors; $ret .= "" . LJ::ehtml($f->{'name'}) . "\n"; $ret .= ""; $ret .= "\n"; $j++; } $ret .= "
"; if ($GET{'sort'} eq 'rel') { $ret .= ""; @friends = sort { $b->{'rel'} cmp $a->{'rel'} || $a->{'username'} cmp $b->{'username'} } values %friends; } else { $ret .= " 'rel'}) . "'>"; $ret .= ""; } $ret .= ""; if (!defined $GET{'sort'} || $GET{'sort'} eq 'username') { $ret .= "$ML{'.editfriends.username'}"; @friends = sort { $a->{'username'} cmp $b->{'username'} } values %friends; } else { $ret .= " 'username'}) . "'>$ML{'.editfriends.username'}"; } $ret .= "$ML{'.editfriends.name'}$ML{'.editfriends.friend'}
"; $ret .= "friend" if $f->{'rel'} eq 'FR'; $ret .= "friend-of" if $f->{'rel'} eq 'FO'; $ret .= "mutual friend" if $f->{'rel'} eq 'M'; $ret .= "" . LJ::ljuser($who) . ""; # non-checked checkboxes for "friend-of". checking these boxes adds the user if ($f->{'rel'} eq 'FO') { $ret .= LJ::html_check({ 'type' => 'check', 'name' => "editfriend_add_${j}_user", 'id' => "editfriend_add_${j}_user", 'value' => $who }); } else { # checked checkboxes for friend/mutual. unchecking these deletes the user. # protocol wants to know who we're deleting, though, so we keep a hidden field # so we can compare differences before/after $ret .= LJ::html_check({ 'type' => 'check', 'name' => "editfriend_keep_$who", 'id' => "editfriend_keep_$who", 'checked' => 1} ); $ret .= LJ::html_hidden("editfriend_has_${j}", "$who"); } $ret .= "


"; } ### add friends $ret .= "\n"; $ret .= " "href='$LJ::SITEROOT/friends/invite.bml'" }) . " p?>"; $ret .= "
"; $ret .= "
\n"; $ret .= "\n"; # load the colors my @color = (); LJ::load_codes({ "color" => \@color }); $ret .= "\n"; } $ret .= "
$ML{'.friend'}$ML{'.foreground'}$ML{'.background'}"; ### color swatch $ret .= "\n"; $ret .= "\n"; my $col = 0; foreach (@color) { $col = $col % 5; $ret .= "\n" if $col == 0; my $ecolor = LJ::ehtml($_->{'item'}); $ret .= "\n"; $col++; $ret .= "\n" if $col == 5; } $ret .= "\n" if ($col % 5); # close out row if we don't have a full row $ret .= "

$ML{'.hover'}

$ecolor
"; $ret .= "

"editfriend_add_${i}_user", 'size' => '15', 'maxlength' => '15', 'onchange' => "updatePreview(); return true;", 'onfocus' => "setFriend($i);" }); $ret .= "

"; $ret .= LJ::html_select({ 'name' => "editfriend_add_${i}_fg", 'selected' => '#000000', 'onchange' => "updatePreview(); return true;", 'onfocus' => "setFriend($i);" }, map { lc($_->{'code'}), $_->{'item'} } @color ); $ret .= ""; $ret .= LJ::html_select({ 'name' => "editfriend_add_${i}_bg", 'selected' => '#ffffff', 'onchange' => "updatePreview(); return true;", 'onfocus' => "setFriend($i);" }, map { lc($_->{'code'}), $_->{'item'} } @color ); $ret .= "

"; ### ending submit block $ret .= "\n"; $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 .= ""; $ret .= LJ::Widget::GettingStarted->render; return $ret; } else { return $print_with_ad->("
  • $response{'errmsg'} p?>\n"); } } return $print_with_ad->($ML{'error.unknownmode'}); } _code?> <=body head<= }; # end qq{ } } _code?> <=head page?>