# This code was forked from the LiveJournal project owned and operated # by Live Journal, Inc. The code has been modified and expanded by # Dreamwidth Studios, LLC. These files were originally licensed under # the terms of the license supplied by Live Journal, Inc, which can # currently be found at: # # http://code.livejournal.org/trac/livejournal/browser/trunk/LICENSE-LiveJournal.txt # # In accordance with the original license, this code and all its # modifications are provided under the GNU General Public License. # A copy of that license can be found in the LICENSE file included as # part of this distribution. package LJ::Widget::UserpicSelector; use strict; use base qw(LJ::Widget); use Carp qw(croak); use LJ::Talk; sub need_res { # Just let need_res work normally for the main stuff LJ::Talk::init_iconbrowser_js(); # Hand off extra stuff to LJ::Widget's weird need_res shim return ('stc/entry.css'); } sub handle_post { return; } sub render_body { my ( $class, %opts ) = @_; my ( $u, $head, $pic, $picform ) = @{ $opts{picargs} }; my $opts = \%opts; # to avoid rewriting below return "" unless LJ::isu($u); return "" unless LJ::is_enabled('userpicselect') || $u->can_use_userpic_select; my $res; $res = LJ::Protocol::do_request( "login", { ver => $LJ::PROTOCOL_VER, username => $u->user, getpickws => 1, getpickwurls => 1, }, undef, { noauth => 1, u => $u, } ) unless $opts->{no_auth}; my $has_icons = $res && ref $res->{pickws} eq 'ARRAY' && scalar @{ $res->{pickws} } > 0; my $userpic_msg_default = LJ::Lang::ml('entryform.userpic.default'); my $userpic_msg_upload = LJ::Lang::ml('entryform.userpic.upload'); my $defpic = LJ::Lang::ml('entryform.opt.defpic'); my $onload = $opts->{onload}; if ( !$opts->{altlogin} && $has_icons ) { # start with default picture info my $defpicurl = $res->{defaultpicurl} // ''; my $num = 0; my $userpics .= " userpics[$num] = \"$defpicurl\";\n"; my $altcode .= " alttext[$num] = \"$defpic\";\n"; foreach ( @{ $res->{pickwurls} } ) { $num++; $userpics .= " userpics[$num] = \"$_\";\n"; } $num = 0; # reset foreach ( @{ $res->{pickws} } ) { $num++; $altcode .= " alttext[$num] = \"" . LJ::ejs($_) . "\";\n"; } $$onload .= " userpic_preview();" if $onload; $$head .= qq { }; my $viewthumbnails_link = ''; if ( $opts->{entry_js} ) { my $thumbnail_text = LJ::Lang::ml('/update.bml.link.view_thumbnails'); $viewthumbnails_link = qq { var ml = new Object(); ml.viewthumbnails_link = "$thumbnail_text"; }; } $$head .= qq { } if $u->can_use_userpic_select; $$pic .= "\n"; } elsif ( !$u || $opts->{altlogin} ) { $$pic .= "

selected userpic

"; } else { $$pic .= "

$userpic_msg_upload

"; } if ($has_icons) { my @pickws = map { ( $_, $_ ) } @{ $res->{pickws} }; my $display = ''; if ( exists $opts->{altlogin} ) { my $userpic_display = $opts->{altlogin} ? 'none' : 'block'; $display = " style='display: $userpic_display;'"; } my $tabindex = $opts->{entry_js} ? '~~TABINDEX~~' : undef; $$picform .= "

\n"; $$picform .= "\n"; $$picform .= LJ::html_select( { name => 'prop_picture_keyword', id => 'prop_picture_keyword', class => 'select', selected => $opts->{prop_picture_keyword}, onchange => "userpic_preview()", tabindex => $tabindex, }, "", $defpic, @pickws ) . "\n"; $$picform .= " "; # userpic browse button if ($onload) { $$onload .= " insertViewThumbs();" if $u->can_use_userpic_select; # random icon button $$picform .= ""; $$picform .= LJ::Lang::ml('entryform.userpic.random') . ""; $$onload .= " showRandomIcon();"; } else { $$picform .= q { \n"; } $$picform .= LJ::help_icon_html( "userpics", "", " " ); $$picform .= "

\n\n"; } return; } 1;