Clean up duplicated currents code; consolidate into one function. (The
logic for the mood in S2 is still somewhat different)
Patch by kareila.
diffs (363 lines):
diff -r 24559c4bb3b0 -r 4cd29aaf2434 cgi-bin/LJ/Entry.pm
--- a/cgi-bin/LJ/Entry.pm Thu Jul 01 14:43:12 2010 +0800
+++ b/cgi-bin/LJ/Entry.pm Thu Jul 01 15:55:26 2010 +0800
@@ -2215,4 +2215,77 @@ sub item_toutf8
return;
}
+# function to fill in hash for basic currents
+sub currents {
+ my ( $props, $u, $key ) = @_;
+ return unless ref $props eq 'HASH';
+ my %current;
+
+ # Mood
+ if ( $props->{"${key}current_mood"} || $props->{"${key}current_moodid"} ) {
+ my $moodid = $props->{"${key}current_moodid"};
+ my $mood = $props->{"${key}current_mood"};
+ my $moodname;
+ my $moodpic;
+
+ # favor custom mood over system mood
+ if ( my $val = $mood ) {
+ LJ::CleanHTML::clean_subject( \$val );
+ $moodname = $val;
+ }
+
+ 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=''
/> ";
+ }
+ }
+
+ $current{Mood} = "$moodpic$moodname";
+ }
+
+ # Music
+ if ( $props->{"${key}current_music"} ) {
+ $current{Music} = $props->{"${key}current_music"};
+ LJ::CleanHTML::clean_subject( \$current{Music} );
+ }
+
+ # Location
+ if ( $props->{"${key}current_location"} ||
$props->{"${key}current_coords"} ) {
+ my $loc = eval { LJ::Location->new( coords =>
$props->{"${key}current_coords"},
+ location =>
$props->{"${key}current_location"}
+ ) };
+ $current{Location} = $loc->as_html_current if $loc;
+ }
+
+ return %current;
+}
+
+# function to format table for currents display
+sub currents_table {
+ my ( %current ) = @_;
+ my $ret = '';
+ return $ret unless %current;
+
+ $ret .= "<table class='currents' border=0>\n";
+ foreach ( sort keys %current ) {
+ my $curkey = "talk.curname_" . $_;
+ my $curname = LJ::Lang::ml( $curkey );
+ $curname = "<b>Current $_:</b>" unless $curname;
+
+ $ret .= "<tr><td align='right'>$curname</td>";
+ $ret .= "<td>$current{$_}</td></tr>\n";
+ }
+ $ret .= "</table><p>\n";
+
+ return $ret;
+}
+
+
1;
diff -r 24559c4bb3b0 -r 4cd29aaf2434 cgi-bin/LJ/S2.pm
--- a/cgi-bin/LJ/S2.pm Thu Jul 01 14:43:12 2010 +0800
+++ b/cgi-bin/LJ/S2.pm Thu Jul 01 15:55:26 2010 +0800
@@ -1866,10 +1866,9 @@ sub Entry
}
my $p = $arg->{'props'};
- if ($p->{'current_music'}) {
- $e->{'metadata'}->{'music'} = $p->{'current_music'};
- LJ::CleanHTML::clean_subject(\$e->{'metadata'}->{'music'});
- }
+ my %current = LJ::currents( $p );
+ $e->{metadata}->{lc $_} = $current{$_} foreach keys %current;
+ # FIXME: mood reassigned below - doesn't match LJ::currents code
# check for xpost values
if ( $p->{xpostdetail} ) {
@@ -1906,12 +1905,6 @@ sub Entry
if ($p->{'current_mood'}) {
$e->{'metadata'}->{'mood'} = $p->{'current_mood'};
LJ::CleanHTML::clean_subject(\$e->{'metadata'}->{'mood'});
- }
-
- if ($p->{'current_location'} || $p->{'current_coords'}) {
- my $loc = eval { LJ::Location->new(coords => $p->{'current_coords'},
- location =>
$p->{'current_location'}) };
- $e->{'metadata'}->{'location'} = $loc->as_html_current if $loc;
}
my $r = BML::get_request();
diff -r 24559c4bb3b0 -r 4cd29aaf2434 htdocs/community/moderate.bml
--- a/htdocs/community/moderate.bml Thu Jul 01 14:43:12 2010 +0800
+++ b/htdocs/community/moderate.bml Thu Jul 01 15:55:26 2010 +0800
@@ -446,43 +446,14 @@ body<=
$ret .= BML::fill_template("standout", {'DATA'=> $actions});
$ret .= "</form>";
- my %current;
- if ($props->{'current_mood'} || $props->{'current_moodid'}) {
- $current{'Mood'} = $props->{'current_mood'};
- LJ::CleanHTML::clean_subject(\$current{'Mood'});
- if ( my $mid = $props->{current_moodid} ) {
- my $theme = $up ? DW::Mood->new( $up->moodtheme ) : undef;
- my %pic;
- my $name = DW::Mood->mood_name( $mid );
- if ( $theme && $theme->get_picture( $mid, \%pic ) ) {
- $current{Mood} =
- "<img src='$pic{pic}' align='absmiddle' "
- . "width='$pic{w}' height='$pic{h}' vspace='1'> $name";
- } else {
- $current{Mood} = $name;
- }
- }
- }
- if ($props->{'current_music'}) {
- $current{'Music'} = $props->{'current_music'};
- LJ::CleanHTML::clean_subject(\$current{'Music'});
- }
+ my %current = LJ::currents( $props, $up );
+
if ($props->{'taglist'}) {
$current{'Tags'} = join(", ", sort split(/\s*,\s*/,
$props->{'taglist'}));
}
$ret .= "<div style='margin-left: 30px'>";
- if (%current)
- {
- $ret .= "<table border=0>\n";
- foreach (sort keys %current) {
- my $curkey = "talk.curname_" . $_;
- my $curname = BML::ml($curkey);
- $curname = "<b>Current $_:</b>" unless $curname;
- $ret .= "<tr><td
align=right>$curname</td><td>$current{$_}</td></tr>\n";
- }
- $ret .= "</table><p>\n";
- }
+ $ret .= LJ::currents_table( %current );
### security indicator
my $sec = "";
diff -r 24559c4bb3b0 -r 4cd29aaf2434 htdocs/preview/entry.bml
--- a/htdocs/preview/entry.bml Thu Jul 01 14:43:12 2010 +0800
+++ b/htdocs/preview/entry.bml Thu Jul 01 15:55:26 2010 +0800
@@ -148,42 +148,7 @@ _c?>
}
## dump the log entry, unless we're browsing a thread.
- my %current;
- if ($req{'prop_current_mood'} || $req{'prop_current_moodid'}) {
- my $moodid = $req{'prop_current_moodid'};
- my $mood = $req{'prop_current_mood'};
-
- my $moodname;
- my $moodpic;
-
- # favor custom mood over system mood
- if (my $val = $mood) {
- LJ::CleanHTML::clean_subject(\$val);
- $moodname = $val;
- }
-
- if ( my $val = $moodid ) {
- $moodname ||= DW::Mood->mood_name( $val );
- my $themeid = $up ? $up->moodtheme : 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='' /> ";
- }
- }
-
- $current{'Mood'} = "$moodpic$moodname";
- }
- if ($req{'prop_current_music'}) {
- $current{'Music'} = $req{'prop_current_music'};
- LJ::CleanHTML::clean_subject(\$current{'Music'});
- }
- if ( $req{prop_current_location} || $req{prop_current_coords} ) {
- my $loc = eval { LJ::Location->new( coords =>
$req{prop_current_coords},
- location =>
$req{prop_current_location} ) };
- $current{Location} = $loc->as_html_current if $loc;
- }
+ my %current = LJ::currents( \%req, $up, 'prop_' );
# custom friend groups
if ( $u ) {
@@ -203,17 +168,7 @@ _c?>
$ret .= "<div id='entry' class='usercontent' style='margin-left:
30px'>";
- if (%current)
- {
- $ret .= "<table border=0>\n";
- foreach (sort keys %current) {
- my $curkey = "talk.curname_" . $_;
- my $curname = BML::ml($curkey);
- $curname = "<b>Current $_:</b>" unless $curname;
- $ret .= "<tr><td
align=right>$curname</td><td>$current{$_}</td></tr>\n";
- }
- $ret .= "</table><p>\n";
- }
+ $ret .= LJ::currents_table( %current );
### security indicator
my $sec = "";
diff -r 24559c4bb3b0 -r 4cd29aaf2434 htdocs/talkpost.bml
--- a/htdocs/talkpost.bml Thu Jul 01 14:43:12 2010 +0800
+++ b/htdocs/talkpost.bml Thu Jul 01 15:55:26 2010 +0800
@@ -292,43 +292,7 @@ body<=
$ret .= "<div class='warningbar warning-background' style='text-align:
center; margin: 5px auto;'>$ML{'statusvis_message.readonly'}</div>";
}
- my %current;
- if ($props->{'current_mood'} || $props->{'current_moodid'}) {
- my $moodid = $props->{'current_moodid'};
- my $mood = $props->{'current_mood'};
-
- my $moodname;
- my $moodpic;
-
- # favor custom mood over system mood
- if (my $val = $mood) {
- LJ::CleanHTML::clean_subject(\$val);
- $moodname = $val;
- }
-
- if ( my $val = $moodid ) {
- $moodname ||= DW::Mood->mood_name( $val );
- my $themeid = $up ? $up->moodtheme : 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=''
/> ";
- }
- }
-
- $current{'Mood'} = "$moodpic$moodname";
- }
- if ($props->{'current_music'}) {
- $current{'Music'} = $props->{'current_music'};
- LJ::CleanHTML::clean_subject(\$current{'Music'});
- }
-
- if ($props->{'current_location'} || $props->{'current_coords'}) {
- my $loc = eval { LJ::Location->new(coords =>
$props->{'current_coords'},
- location =>
$props->{'current_location'}) };
- $current{'Location'} = $loc->as_html_current if $loc;
- }
+ my %current = LJ::currents( $props, $up );
# custom friend groups
my $group_names = $entry->group_names;
@@ -353,17 +317,7 @@ body<=
$ret .= "<div id='entry' class='usercontent' style='margin-left: 30px'>";
### currents
- if (! $init->{'replyto'} && %current)
- {
- $ret .= "<table class='currents' border=0>\n";
- foreach (sort keys %current) {
- my $curkey = "talk.curname_" . $_;
- my $curname = BML::ml($curkey);
- $curname = "<b>Current $_:</b>" unless $curname;
- $ret .= "<tr><td
align=right>$curname</td><td>$current{$_}</td></tr>\n";
- }
- $ret .= "</table><p>\n";
- }
+ $ret .= LJ::currents_table( %current ) unless $init->{replyto};
### security indicator
my $sec = "";
diff -r 24559c4bb3b0 -r 4cd29aaf2434 htdocs/talkread.bml
--- a/htdocs/talkread.bml Thu Jul 01 14:43:12 2010 +0800
+++ b/htdocs/talkread.bml Thu Jul 01 15:55:26 2010 +0800
@@ -306,42 +306,7 @@ body<=
}
## dump the log entry, unless we're browsing a thread.
- my %current;
- if ($props->{'current_mood'} || $props->{'current_moodid'}) {
- my $moodid = $props->{'current_moodid'};
- my $mood = $props->{'current_mood'};
-
- my $moodname;
- my $moodpic;
-
- # favor custom mood over system mood
- if (my $val = $mood) {
- LJ::CleanHTML::clean_subject(\$val);
- $moodname = $val;
- }
-
- if ( my $val = $moodid ) {
- $moodname ||= DW::Mood->mood_name( $val );
- my $themeid = $up ? $up->moodtheme : 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=''
/> ";
- }
- }
-
- $current{'Mood'} = "$moodpic$moodname";
- }
- if ($props->{'current_music'}) {
- $current{'Music'} = $props->{'current_music'};
- LJ::CleanHTML::clean_subject(\$current{'Music'});
- }
- if ($props->{'current_location'} || $props->{'current_coords'}) {
- my $loc = eval { LJ::Location->new(coords =>
$props->{'current_coords'},
- location =>
$props->{'current_location'}) };
- $current{'Location'} = $loc->as_html_current if $loc;
- }
+ my %current = LJ::currents( $props, $up );
# custom friend groups
my $group_names = $entry->group_names;
@@ -375,20 +340,7 @@ body<=
$ret .= "<div id='entry' class='usercontent' style='margin-left: 30px'>";
-
- if (%current)
- {
- $ret .= "<table class='currents' border=0>\n";
- foreach (sort keys %current) {
- my $curkey = "talk.curname_" . $_;
- my $curname = BML::ml($curkey);
- $curname = "<b>Current $_:</b>" unless $curname;
-
- $ret .= "<tr><td align=right>$curname</td>";
- $ret .= "<td>$current{$_}</td></tr>\n";
- }
- $ret .= "</table><p>\n";
- }
+ $ret .= LJ::currents_table( %current );
### security indicator
my $sec = "";
_______________________________________________
dw-changelog mailing list
[email protected]
http://lists.dwscoalition.org/mailman/listinfo/dw-changelog