Committer: amyshkin
LJSUP-10691: Image placeholders in commentsU trunk/bin/upgrading/en.dat U trunk/cgi-bin/LJ/S2/EntryPage.pm U trunk/cgi-bin/LJ/S2/FriendsPage.pm U trunk/cgi-bin/LJ/Setting/ImagePlaceholders.pm U trunk/cgi-bin/cleanhtml.pl U trunk/cgi-bin/ljhooks.pl U trunk/cgi-bin/ljviews.pl
Modified: trunk/bin/upgrading/en.dat =================================================================== --- trunk/bin/upgrading/en.dat 2012-01-27 06:29:38 UTC (rev 21018) +++ trunk/bin/upgrading/en.dat 2012-01-27 08:00:16 UTC (rev 21019) @@ -4968,6 +4968,11 @@ setting.imageplaceholders.option|staleness=1 setting.imageplaceholders.option=Replace inline images on your Friends page with a placeholder for +setting.imageplaceholders.option2=Replace inline images with a placeholder: + +setting.imageplaceholders.option2.checkbox1=On your Friends page +setting.imageplaceholders.option2.checkbox2=In comments + setting.imageplaceholders.option.select.all|staleness=1 setting.imageplaceholders.option.select.all=all images Modified: trunk/cgi-bin/LJ/S2/EntryPage.pm =================================================================== --- trunk/cgi-bin/LJ/S2/EntryPage.pm 2012-01-27 06:29:38 UTC (rev 21018) +++ trunk/cgi-bin/LJ/S2/EntryPage.pm 2012-01-27 08:00:16 UTC (rev 21019) @@ -143,6 +143,18 @@ my $convert_comments = sub { my ($self, $destlist, $srclist, $depth) = @_; + my $replace_images_in_comments = 0; + + if( $remote ) { + my $opt = $remote->prop("opt_imagelinks") || "0:0"; + $opt = "0:0" unless $opt; + $opt = "1:0" unless $opt =~ /^\d\:\d$/; + + if ( $opt =~ /^\d\:(\d)$/ ) { + $replace_images_in_comments = $1; + } + } + foreach my $com (@$srclist) { my $pu = $com->{'posterid'} ? $user{$com->{'posterid'}} : undef; @@ -152,12 +164,16 @@ # quote all non-LJ tags $text =~ s{<(?!/?lj)(.*?)>} {<$1>}gi; } - LJ::CleanHTML::clean_comment(\$text, { 'preformatted' => $com->{'props'}->{'opt_preformatted'}, - 'anon_comment' => (!$pu || $pu->{'journaltype'} eq 'I'), - 'nocss' => 1, - 'posterid' => $com->{'posterid'}, - }); + LJ::CleanHTML::clean_comment( + \$text, { + 'preformatted' => $com->{'props'}->{'opt_preformatted'}, + 'anon_comment' => (!$pu || $pu->{'journaltype'} eq 'I'), + 'nocss' => 1, + 'posterid' => $com->{'posterid'}, + 'img_placeholders' => $replace_images_in_comments, + }); + # local time in mysql format to gmtime my $datetime = DateTime_unix($com->{'datepost_unix'}); my $datetime_remote = $tz_remote ? DateTime_tz($com->{'datepost_unix'}, $tz_remote) : undef; Modified: trunk/cgi-bin/LJ/S2/FriendsPage.pm =================================================================== --- trunk/cgi-bin/LJ/S2/FriendsPage.pm 2012-01-27 06:29:38 UTC (rev 21018) +++ trunk/cgi-bin/LJ/S2/FriendsPage.pm 2012-01-27 08:00:16 UTC (rev 21019) @@ -63,12 +63,6 @@ LJ::load_user_props($remote, "opt_nctalklinks", "opt_stylemine", "opt_imagelinks", "opt_ljcut_disable_friends"); - # load options for image links - my ($maximgwidth, $maximgheight) = (undef, undef); - ($maximgwidth, $maximgheight) = ($1, $2) - if ($remote && $remote->{'userid'} == $u->{'userid'} && - $remote->{'opt_imagelinks'} =~ m/^(\d+)\|(\d+)$/); - my $itemshow = S2::get_property_value($opts->{'ctx'}, "page_friends_items")+0; if ($itemshow < 1) { $itemshow = 20; } elsif ($itemshow > 50) { $itemshow = 50; } @@ -224,6 +218,18 @@ my $eventnum = 0; my $hiddenentries = 0; + my $replace_images_in_friendspage = 0; + + if( $u->equals($remote) ) { + my $opt = $u->prop("opt_imagelinks") || "0:0"; + $opt = "0:0" unless $opt; + $opt = "1:0" unless $opt =~ /^\d\:\d$/; + + if ( $opt =~ /^(\d)\:\d$/ ) { + $replace_images_in_friendspage = $1; + } + } + ENTRY: foreach my $item (@items) { my ($friendid, $posterid, $itemid, $security, $allowmask, $alldatepart) = @@ -286,19 +292,19 @@ } my $suspend_msg = $entry_obj && $entry_obj->should_show_suspend_msg_to($remote) ? 1 : 0; + LJ::CleanHTML::clean_event( \$text, { 'preformatted' => $logprops{$datakey}->{'opt_preformatted'}, 'cuturl' => $entry_obj->prop('reposted_from') || $entry_obj->url(%urlopts_style), 'entry_url' => $entry_obj->prop('reposted_from') || $entry_obj->url, - 'maximgwidth' => $maximgwidth, - 'maximgheight' => $maximgheight, 'ljcut_disable' => $remote ? $remote->{'opt_ljcut_disable_friends'} : undef, 'suspend_msg' => $suspend_msg, 'unsuspend_supportid' => $suspend_msg ? $entry_obj->prop("unsuspend_supportid") : 0, 'journalid' => $entry_obj->journalid, 'posterid' => $entry_obj->posterid, + 'img_placeholders' => $replace_images_in_friendspage, }); LJ::expand_embedded($friends{$friendid}, $ditemid, $remote, \$text); Modified: trunk/cgi-bin/LJ/Setting/ImagePlaceholders.pm =================================================================== --- trunk/cgi-bin/LJ/Setting/ImagePlaceholders.pm 2012-01-27 06:29:38 UTC (rev 21018) +++ trunk/cgi-bin/LJ/Setting/ImagePlaceholders.pm 2012-01-27 08:00:16 UTC (rev 21019) @@ -26,55 +26,53 @@ my ($class, $u, $errs, $args) = @_; my $key = $class->pkgkey; - my $imgplaceholders = $class->get_arg($args, "imgplaceholders") || $u->prop("opt_imagelinks"); + my $imgplaceholders = $u->prop("opt_imagelinks") || "0:0"; - my ($maxwidth, $maxheight) = (0, 0); - ($maxwidth, $maxheight) = ($1, $2) - if $imgplaceholders and $imgplaceholders =~ /^(\d+)\|(\d+)$/; + # just for a case + $imgplaceholders = "0:0" unless $imgplaceholders; + $imgplaceholders = "1:0" unless $imgplaceholders =~ /^\d\:\d$/; - my $is_stock = grep { $imgplaceholders eq $_ } - (qw/320|240 640|480 0|0/, ''); # standard sizes + my( $chk1, $chk2 ); - my $extra = undef; - $extra = $class->ml('setting.imageplaceholders.option.select.custom', { width => $maxwidth, height => $maxheight }) - unless $is_stock; + if ( $imgplaceholders =~ /^(\d)\:(\d)$/ ) { + $chk1 = $1; + $chk2 = $2; + } + else { + $chk1 = 0; + $chk2 = 0; + } - my @options = ( - "0" => $class->ml('setting.imageplaceholders.option.select.none'), - "0|0" => $class->ml('setting.imageplaceholders.option.select.all'), - "320|240" => $class->ml('setting.imageplaceholders.option.select.medium', { width => 320, height => 240 }), - "640|480" => $class->ml('setting.imageplaceholders.option.select.large', { width => 640, height => 480 }), - $extra ? ("$maxwidth|$maxheight" => $extra) : () - ); + my $ret = $class->ml('setting.imageplaceholders.option2') + . "<label for='${key}check1'>" + . LJ::html_check({ + selected => $chk1, + name => "${key}check1", + }) + . $class->ml('setting.imageplaceholders.option2.checkbox1') + . "</label> " + . "<label for='${key}check2'>" + . LJ::html_check({ + selected => $chk2, + name => "${key}check2", + }) + . $class->ml('setting.imageplaceholders.option2.checkbox2') + . "</label> "; - my $ret = "<label for='${key}imgplaceholders'>" . $class->ml('setting.imageplaceholders.option') . "</label> "; - $ret .= LJ::html_select({ - name => "${key}imgplaceholders", - id => "${key}imgplaceholders", - selected => $imgplaceholders, - }, @options); - my $errdiv = $class->errdiv($errs, "imgplaceholders"); $ret .= "<br />$errdiv" if $errdiv; return $ret; } -sub error_check { - my ($class, $u, $args) = @_; - my $val = $class->get_arg($args, "imgplaceholders"); - - $class->errors( imgplaceholders => $class->ml('setting.imageplaceholders.error.invalid') ) - unless !$val || $val =~ /^(\d+)\|(\d+)$/; - - return 1; -} - sub save { my ($class, $u, $args) = @_; - $class->error_check($u, $args); - my $val = $class->get_arg($args, "imgplaceholders"); + my @val; + push @val, $class->get_arg($args, $_) for map { "check$_" } 1..2; + @val = map { $_ eq 'on' ? 1 : 0 } @val; + + my $val = join( ':', @val ); $u->set_prop( opt_imagelinks => $val ); return 1; Modified: trunk/cgi-bin/cleanhtml.pl =================================================================== --- trunk/cgi-bin/cleanhtml.pl 2012-01-27 06:29:38 UTC (rev 21018) +++ trunk/cgi-bin/cleanhtml.pl 2012-01-27 08:00:16 UTC (rev 21019) @@ -1092,12 +1092,16 @@ if (defined $opts->{'maximgwidth'} && (! defined $hash->{'width'} || $hash->{'width'} > $opts->{'maximgwidth'})) { $img_bad = 1; } + if (defined $opts->{'maximgheight'} && (! defined $hash->{'height'} || $hash->{'height'} > $opts->{'maximgheight'})) { $img_bad = 1; } } + if ($opts->{'extractimages'}) { $img_bad = 1; } + if ($opts->{'img_placeholders'}) { $img_bad = 1; } + ## Option 'allowed_img_attrs' provides a list of allowed attributes if (my $allowed = $opts->{'allowed_img_attrs'}){ while (my ($attr, undef) = each %$hash){ @@ -1961,23 +1965,24 @@ # slow path: need to be run it through the cleaner return clean($ref, { - 'linkify' => 1, - 'wordlength' => 40, - 'addbreaks' => $opts->{preformatted} ? 0 : 1, - 'eat' => [qw[head title style layer applet object]], - 'mode' => 'deny', - 'allow' => \@comment_all, - 'autoclose' => \@comment_close, - 'cleancss' => 1, - 'strongcleancss' => 1, - 'extractlinks' => $opts->{'anon_comment'}, - 'extractimages' => $opts->{'anon_comment'}, - 'noearlyclose' => 1, - 'tablecheck' => 1, - 'nocss' => $opts->{'nocss'}, - 'textonly' => $opts->{'textonly'} ? 1 : 0, + 'linkify' => 1, + 'wordlength' => 40, + 'addbreaks' => $opts->{preformatted} ? 0 : 1, + 'eat' => [qw[head title style layer applet object]], + 'mode' => 'deny', + 'allow' => \@comment_all, + 'autoclose' => \@comment_close, + 'cleancss' => 1, + 'strongcleancss' => 1, + 'extractlinks' => $opts->{'anon_comment'}, + 'extractimages' => $opts->{'anon_comment'}, + 'noearlyclose' => 1, + 'tablecheck' => 1, + 'nocss' => $opts->{'nocss'}, + 'textonly' => $opts->{'textonly'} ? 1 : 0, 'remove_positioning' => 1, - 'posterid' => $opts->{'posterid'}, + 'posterid' => $opts->{'posterid'}, + 'img_placeholders' => $opts->{'img_placeholders'}, }); } Modified: trunk/cgi-bin/ljhooks.pl =================================================================== --- trunk/cgi-bin/ljhooks.pl 2012-01-27 06:29:38 UTC (rev 21018) +++ trunk/cgi-bin/ljhooks.pl 2012-01-27 08:00:16 UTC (rev 21019) @@ -164,11 +164,11 @@ register_setter("maximagesize", sub { my ($u, $key, $value, $err) = @_; - unless ($value =~ m/^(\d+)[x,|](\d+)$/) { - $$err = "Illegal value. Must be width,height."; + unless ($value =~ m/^(0|1)[\:\s](0|1)$/) { + $$err = "Illegal value. Must be 0|1:0|1."; return 0; } - $value = "$1|$2"; + $value = "$1:$2"; $u->set_prop("opt_imagelinks", $value); return 1; }); Modified: trunk/cgi-bin/ljviews.pl =================================================================== --- trunk/cgi-bin/ljviews.pl 2012-01-27 06:29:38 UTC (rev 21018) +++ trunk/cgi-bin/ljviews.pl 2012-01-27 08:00:16 UTC (rev 21019) @@ -1780,11 +1780,17 @@ LJ::load_user_props($remote, "opt_stylemine", "opt_imagelinks", "opt_ljcut_disable_friends"); # load options for image links - my ($maximgwidth, $maximgheight) = (undef, undef); - ($maximgwidth, $maximgheight) = ($1, $2) - if ($remote && $remote->{'userid'} == $u->{'userid'} && - $remote->{'opt_imagelinks'} =~ m/^(\d+)\|(\d+)$/); + my $replace_images_in_friendspage = 0; + if( $u->equals($remote) ) { + my $opt = $u->prop("opt_imagelinks") || "0:0"; + $opt = "0:0" unless $opt; + $opt = "1:0" unless $opt =~ /^\d\:\d$/; + if ( $opt =~ /^(\d)\:\d$/ ) { + $replace_images_in_friendspage = $1; + } + } + my %friends_events = (); my $events = \$friends_events{'events'}; @@ -1892,17 +1898,19 @@ } my $suspend_msg = $entry_obj && $entry_obj->should_show_suspend_msg_to($remote) ? 1 : 0; - LJ::CleanHTML::clean_event(\$event, { 'preformatted' => $logprops{$datakey}->{'opt_preformatted'}, - 'cuturl' => $entry_obj->prop('reposted_from') || $entry_obj->url(%urlopts_style), - 'entry_url' => $entry_obj->prop('reposted_from') || $entry_obj->url, - 'maximgwidth' => $maximgwidth, - 'maximgheight' => $maximgheight, - 'ljcut_disable' => ($remote) ? $remote->{'opt_ljcut_disable_friends'} : undef, - 'suspend_msg' => $suspend_msg, - 'unsuspend_supportid' => $suspend_msg ? $entry_obj->prop("unsuspend_supportid") : 0, - 'journalid' => $entry_obj->journalid, - 'posterid' => $entry_obj->posterid, - }); + + LJ::CleanHTML::clean_event( + \$event, { + 'preformatted' => $logprops{$datakey}->{'opt_preformatted'}, + 'cuturl' => $entry_obj->prop('reposted_from') || $entry_obj->url(%urlopts_style), + 'entry_url' => $entry_obj->prop('reposted_from') || $entry_obj->url, + 'ljcut_disable' => ($remote) ? $remote->{'opt_ljcut_disable_friends'} : undef, + 'suspend_msg' => $suspend_msg, + 'unsuspend_supportid' => $suspend_msg ? $entry_obj->prop("unsuspend_supportid") : 0, + 'journalid' => $entry_obj->journalid, + 'posterid' => $entry_obj->posterid, + 'img_placeholders' => $replace_images_in_friendspage, + }); LJ::expand_embedded($friends{$friendid}, $ditemid, $remote, \$event); $event = LJ::ContentFlag->transform_post(post => $event, journal => $friends{$friendid},