fu: Close-up of Fu, bringing a scoop of water to her mouth (Default)
fu ([personal profile] fu) wrote in [site community profile] changelog2010-07-05 09:00 am

[dw-free] clean up duplicated code for post display

[commit: http://hg.dwscoalition.org/dw-free/rev/42ace13d0436]

http://bugs.dwscoalition.org/show_bug.cgi?id=2743

Refactor the xpost details into LJ::currents.

Patch by [personal profile] kareila.

Files modified:
  • cgi-bin/LJ/Entry.pm
  • cgi-bin/LJ/S2.pm
  • htdocs/talkpost.bml
  • htdocs/talkread.bml
--------------------------------------------------------------------------------
diff -r 8b0182046c0d -r 42ace13d0436 cgi-bin/LJ/Entry.pm
--- a/cgi-bin/LJ/Entry.pm	Mon Jul 05 16:56:57 2010 +0800
+++ b/cgi-bin/LJ/Entry.pm	Mon Jul 05 17:06:28 2010 +0800
@@ -1083,6 +1083,7 @@ use Carp qw(confess);
 use Carp qw(confess);
 use LJ::Poll;
 use LJ::EmbedModule;
+use DW::External::Account;
 
 # <LJFUNC>
 # name: LJ::get_logtext2multi
@@ -2278,6 +2279,20 @@ sub currents {
         $current{Location} = $loc->as_html_current if $loc;
     }
 
+    # Crossposts
+    if ( my $xpost = $props->{"${key}xpostdetail"} ) {
+        my $xposthash = DW::External::Account->xpost_string_to_hash( $xpost );
+        my $xpostlinks = "";
+        foreach my $xpostvalue ( values %$xposthash ) {
+            if ( $xpostvalue->{url} ) {
+                my $xpost_url = LJ::no_utf8_flag( $xpostvalue->{url} );
+                $xpostlinks .= " " if $xpostlinks;
+                $xpostlinks .= "<a href='$xpost_url'>$xpost_url</a>";
+            }
+        }
+        $current{Xpost} = $xpostlinks if $xpostlinks;
+    }
+
     return %current;
 }
 
diff -r 8b0182046c0d -r 42ace13d0436 cgi-bin/LJ/S2.pm
--- a/cgi-bin/LJ/S2.pm	Mon Jul 05 16:56:57 2010 +0800
+++ b/cgi-bin/LJ/S2.pm	Mon Jul 05 17:06:28 2010 +0800
@@ -33,7 +33,6 @@ use LJ::S2::EntryPage;
 use LJ::S2::EntryPage;
 use LJ::S2::ReplyPage;
 use LJ::S2::TagsPage;
-use DW::External::Account;
 use Storable;
 use Apache2::Const qw/ :common /;
 use POSIX ();
@@ -1874,25 +1873,6 @@ sub Entry
     my %current = LJ::currents( $p, $m_arg, { s2imgref => \$img_arg } );
     $e->{metadata}->{lc $_} = $current{$_} foreach keys %current;
     $e->{mood_icon} = Image( @$img_arg ) if defined $img_arg;
-
-    # check for xpost values
-    if ( $p->{xpostdetail} ) {
-        my $xposthash = DW::External::Account->xpost_string_to_hash( $p->{xpostdetail} );
-        my $xpostlinks = "";
-        foreach my $xpostkey ( keys %$xposthash ) {
-            my $xpostvalue = $xposthash->{$xpostkey};
-            if ( $xpostvalue->{url} ) {
-                my $xpost_url = LJ::no_utf8_flag( $xpostvalue->{url} );
-                if ( $xpostlinks ) {
-                    $xpostlinks = $xpostlinks . " ";
-                }
-                $xpostlinks = $xpostlinks . '<a href = "' .  $xpost_url . '">' .  $xpost_url . '</a>';
-            }
-        }
-        if ( $xpostlinks ) {
-            $e->{metadata}->{xpost} = $xpostlinks;
-        }
-    }
 
     my $r = BML::get_request();
 
diff -r 8b0182046c0d -r 42ace13d0436 htdocs/talkpost.bml
--- a/htdocs/talkpost.bml	Mon Jul 05 16:56:57 2010 +0800
+++ b/htdocs/talkpost.bml	Mon Jul 05 17:06:28 2010 +0800
@@ -285,22 +285,6 @@ body<=
     my $group_names = $entry->group_names;
     $current{'Groups'} = $group_names if $group_names;
 
-    if ($props->{xpostdetail} ) {
-        my $xposthash = DW::External::Account->xpost_string_to_hash( $props->{xpostdetail} );
-        my $xpostlinks = "";
-        foreach my $xpostkey ( keys %$xposthash ) {
-            my $xpostvalue = $xposthash->{$xpostkey};
-            if ( $xpostvalue->{url} ) {
-                my $xpost_url = LJ::no_utf8_flag( $xpostvalue->{url} );
-                if ( $xpostlinks ) {
-                    $xpostlinks = $xpostlinks . " ";
-                }
-                $xpostlinks = $xpostlinks . '<a href = "' .  $xpost_url . '">' .  $xpost_url . '</a>';
-            }
-        }
-        $current{Xpost} = $xpostlinks;
-    }
-
     $ret .= "<div id='entry' class='usercontent' style='margin-left: 30px'>";
 
     ### currents
diff -r 8b0182046c0d -r 42ace13d0436 htdocs/talkread.bml
--- a/htdocs/talkread.bml	Mon Jul 05 16:56:57 2010 +0800
+++ b/htdocs/talkread.bml	Mon Jul 05 17:06:28 2010 +0800
@@ -305,22 +305,6 @@ body<=
                                map { "<a href='$base/tag/" . LJ::eurl($_) . "'>" . LJ::ehtml($_) . "</a>" }
                                sort values %{$logtags->{$itemid}}
                            );
-    }
-
-    if ($props->{xpostdetail} ) {
-        my $xposthash = DW::External::Account->xpost_string_to_hash( $props->{xpostdetail} );
-        my $xpostlinks = "";
-        foreach my $xpostkey ( keys %$xposthash ) {
-            my $xpostvalue = $xposthash->{$xpostkey};
-            if ( $xpostvalue->{url} ) {
-                my $xpost_url = LJ::no_utf8_flag( $xpostvalue->{url} );
-                if ( $xpostlinks ) {
-                    $xpostlinks = $xpostlinks . " ";
-                }
-                $xpostlinks = $xpostlinks . '<a href = "' .  $xpost_url . '">' .  $xpost_url . '</a>';
-            }
-        }
-        $current{Xpost} = $xpostlinks;
     }
 
     $ret .= "<div id='entry' class='usercontent' style='margin-left: 30px'>";
--------------------------------------------------------------------------------

Post a comment in response:

This account has disabled anonymous posting.
If you don't have an account you can create one now.
HTML doesn't work in the subject.
More info about formatting

If you are unable to use this captcha for any reason, please contact us by email at support@dreamwidth.org