[dw-free] clean up duplicated code for post display
[commit: http://hg.dwscoalition.org/dw-free/rev/513857907330]
http://bugs.dwscoalition.org/show_bug.cgi?id=2743
Refactor S2 mood assignment so it can use LJ::currents. Switch LJ::currents
to use a hashref of opts to pass in extra / optional inforamtion.
Patch by
kareila.
Files modified:
http://bugs.dwscoalition.org/show_bug.cgi?id=2743
Refactor S2 mood assignment so it can use LJ::currents. Switch LJ::currents
to use a hashref of opts to pass in extra / optional inforamtion.
Patch by
![[personal profile]](https://www.dreamwidth.org/img/silk/identity/user.png)
Files modified:
- cgi-bin/LJ/Entry.pm
- cgi-bin/LJ/S2.pm
- htdocs/preview/entry.bml
-------------------------------------------------------------------------------- diff -r f98d1fce4157 -r 513857907330 cgi-bin/LJ/Entry.pm --- a/cgi-bin/LJ/Entry.pm Mon Jul 05 14:39:20 2010 +0800 +++ b/cgi-bin/LJ/Entry.pm Mon Jul 05 14:56:15 2010 +0800 @@ -2217,9 +2217,15 @@ sub item_toutf8 # function to fill in hash for basic currents sub currents { - my ( $props, $u, $key ) = @_; + my ( $props, $u, $opts ) = @_; return unless ref $props eq 'HASH'; my %current; + + my ( $key, $s2imgref ); + if ( $opts && ref $opts ) { + $key = $opts->{key}; + $s2imgref = $opts->{s2imgref}; + } # Mood if ( $props->{"${key}current_mood"} || $props->{"${key}current_moodid"} ) { @@ -2236,14 +2242,22 @@ sub currents { if ( my $val = $moodid ) { $moodname ||= DW::Mood->mood_name( $val ); - my $themeid = LJ::isu( $u ) ? $u->moodtheme : undef; - # $u might be a hashref instead of a user object? - $themeid ||= ref $u ? $u->{moodthemeid} : undef; - my $theme = DW::Mood->new( $themeid ); - my %pic; - if ( $theme && $theme->get_picture( $val, \%pic ) ) { - $moodpic = "<img class='moodpic' src=\"$pic{pic}\" align='absmiddle' " . - "width='$pic{w}' height='$pic{h}' vspace='1' alt='' /> "; + if ( defined $u ) { + my $themeid = LJ::isu( $u ) ? $u->moodtheme : undef; + # $u might be a hashref instead of a user object? + $themeid ||= ref $u ? $u->{moodthemeid} : undef; + my $theme = DW::Mood->new( $themeid ); + my %pic; + if ( $theme && $theme->get_picture( $val, \%pic ) ) { + if ( $s2imgref && ref $s2imgref ) { + # return argument array for S2::Image + $$s2imgref = [ $pic{pic}, $pic{w}, $pic{h} ]; + } else { + $moodpic = "<img class='moodpic' src=\"$pic{pic}\" " . + "width='$pic{w}' height='$pic{h}' " . + "align='absmiddle' vspace='1' alt='' /> "; + } + } } } diff -r f98d1fce4157 -r 513857907330 cgi-bin/LJ/S2.pm --- a/cgi-bin/LJ/S2.pm Mon Jul 05 14:39:20 2010 +0800 +++ b/cgi-bin/LJ/S2.pm Mon Jul 05 14:56:15 2010 +0800 @@ -1865,10 +1865,15 @@ sub Entry # do nothing. } - my $p = $arg->{'props'}; - my %current = LJ::currents( $p ); + my $m_arg = $arg; + # if moodthemeid not given, look up the user's if we have it + $m_arg = $u if ! defined $arg->{moodthemeid} && LJ::isu( $u ); + + my $p = $arg->{props}; + my $img_arg; + my %current = LJ::currents( $p, $m_arg, { s2imgref => \$img_arg } ); $e->{metadata}->{lc $_} = $current{$_} foreach keys %current; - # FIXME: mood reassigned below - doesn't match LJ::currents code + $e->{mood_icon} = Image( @$img_arg ) if defined $img_arg; # check for xpost values if ( $p->{xpostdetail} ) { @@ -1887,23 +1892,6 @@ sub Entry if ( $xpostlinks ) { $e->{metadata}->{xpost} = $xpostlinks; } - } - - if (my $mid = $p->{'current_moodid'}) { - my $theme = $arg->{'moodthemeid'}; - # if moodthemeid not given, look up the user's if we have it - $theme = $u->moodtheme if ! defined $theme && LJ::isu( $u ); - my %pic; - my $mobj = DW::Mood->new( $theme ); - $e->{mood_icon} = Image( $pic{pic}, $pic{w}, $pic{h} ) - if $mobj && $mobj->get_picture( $mid, \%pic ); - if ( my $mood = DW::Mood->mood_name( $mid ) ) { - $e->{metadata}->{mood} = $mood; - } - } - if ($p->{'current_mood'}) { - $e->{'metadata'}->{'mood'} = $p->{'current_mood'}; - LJ::CleanHTML::clean_subject(\$e->{'metadata'}->{'mood'}); } my $r = BML::get_request(); diff -r f98d1fce4157 -r 513857907330 htdocs/preview/entry.bml --- a/htdocs/preview/entry.bml Mon Jul 05 14:39:20 2010 +0800 +++ b/htdocs/preview/entry.bml Mon Jul 05 14:56:15 2010 +0800 @@ -148,7 +148,7 @@ _c?> } ## dump the log entry, unless we're browsing a thread. - my %current = LJ::currents( \%req, $up, 'prop_' ); + my %current = LJ::currents( \%req, $up, { key => 'prop_' } ); # custom friend groups if ( $u ) { --------------------------------------------------------------------------------