Skip to content

Commit

Permalink
[#1035] Convert getuserpics endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
afuna committed Nov 6, 2014
1 parent 56ab94d commit 10791a6
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 75 deletions.
51 changes: 51 additions & 0 deletions cgi-bin/DW/Controller/RPC/MiscLegacy.pm
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ DW::Routing->register_rpc( "checkforusername", \&check_username_handler, format
DW::Routing->register_rpc( "controlstrip", \&control_strip_handler, format => 'json' );
DW::Routing->register_rpc( "getsecurityoptions", \&get_security_options_handler, format => 'json' );
DW::Routing->register_rpc( "gettags", \&get_tags_handler, format => 'json' );
DW::Routing->register_rpc( "userpicselect", \&get_userpics_handler, format => 'json' );

sub check_username_handler {
my $r = DW::Request->get;
Expand Down Expand Up @@ -97,4 +98,54 @@ sub get_tags_handler {
return DW::RPC->out( tags => \@tag_names );
}

sub get_userpics_handler {
my $r = DW::Request->get;
my $get = $r->get_args;

my $remote = LJ::get_remote();

my $alt_u;
$alt_u = LJ::load_user( $get->{user} )
if $get->{user} && $remote->has_priv( "supporthelp" );

# get user
my $u = ( $alt_u || $remote );
return DW::RPC->alert( "Sorry, you must be logged in to use this feature." )
unless $u;

# get userpics
my @userpics = LJ::Userpic->load_user_userpics( $u );

my %upics = (); # info to return
$upics{pics} = {}; # upicid -> hashref of metadata

foreach my $upic (@userpics) {
next if $upic->inactive;

my $id = $upic->id;
$upics{pics}{$id} = {
url => $upic->url,
state => $upic->state,
width => $upic->width,
height => $upic->height,

# we don't want the full version of alttext here, because the keywords, etc
# will already likely be displayed by the icon

# We don't want to use ehtml, because we want the JSON converter
# handle escaping ", ', etc. We just escape the < and > ourselves
alt => LJ::etags( $upic->description ),

comment => LJ::strip_html( $upic->comment ),

id => $id,
keywords => [ map { LJ::strip_html( $_ ) } $upic->keywords],
};
}

$upics{ids} = [sort { $a <=> $b } keys %{$upics{pics}}];

return DW::RPC->out( %upics );
}

1;
1 change: 0 additions & 1 deletion cgi-bin/LJ/Global/Defaults.pm
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,6 @@ no strict "vars";
talkscreen => "talkscreen.bml",
ctxpopup => "tools/endpoints/ctxpopup.bml",
changerelation => "tools/endpoints/changerelation.bml",
userpicselect => "tools/endpoints/getuserpics.bml",
esn_inbox => "tools/endpoints/esn_inbox.bml",
esn_subs => "tools/endpoints/esn_subs.bml",
trans_save => "tools/endpoints/trans_save.bml",
Expand Down
74 changes: 0 additions & 74 deletions htdocs/tools/endpoints/getuserpics.bml

This file was deleted.

0 comments on commit 10791a6

Please sign in to comment.