Code cleanup: refactor the code that generates CommentInfo in S2.

        Patch by kareila. 

diffs (147 lines):

diff -r 190d8daebf5d -r 648857570a1f cgi-bin/LJ/Entry.pm
--- a/cgi-bin/LJ/Entry.pm       Tue Apr 13 04:31:40 2010 -0700
+++ b/cgi-bin/LJ/Entry.pm       Tue Apr 13 06:28:29 2010 -0700
@@ -507,6 +507,44 @@ sub comment_text {
     }
 
     return $comments;
+}
+
+
+# returns data hashref suitable for use in S2 CommentInfo function
+sub comment_info {
+    my ( $self, %opts )= @_;
+    return unless %opts;
+    return unless exists $opts{u};
+    return unless exists $opts{remote};
+    return unless exists $opts{style_args};
+
+    my $u = $opts{u};
+    my $remote = $opts{remote};
+    my $style_args = $opts{style_args};
+    my $viewall = $opts{viewall};
+
+    my $journal = exists $opts{journal} ? $opts{journal} : $u;
+
+    my $permalink = $self->url;
+    my $comments_enabled = ( $viewall ||
+        ( $journal->{opt_showtalklinks} eq "Y" && !$self->comments_disabled ) 
) ? 1 : 0;
+    my $has_screened = ( $self->props->{hasscreened} && $remote && 
LJ::can_manage( $remote, $journal ) ) ? 1 : 0;
+    my $replycount = $self->reply_count;
+    my $nc = "";
+    $nc .= "nc=$replycount" if $replycount && $remote && 
$remote->{opt_nctalklinks};
+
+    return {
+        read_url => LJ::Talk::talkargs( $permalink, $nc, $style_args ),
+        post_url => LJ::Talk::talkargs( $permalink, "mode=reply", $style_args 
),
+        permalink_url => LJ::Talk::talkargs( $permalink, $style_args ),
+        count => $replycount,
+        maxcomments => ( $replycount >= $u->count_maxcomments ) ? 1 : 0,
+        enabled => $comments_enabled,
+        comments_disabled_maintainer => $self->comments_disabled_maintainer,
+        screened => $has_screened,
+        show_readlink => $comments_enabled && ( $replycount || $has_screened ),
+        show_postlink => $comments_enabled,
+    };
 }
 
 
diff -r 190d8daebf5d -r 648857570a1f cgi-bin/LJ/S2.pm
--- a/cgi-bin/LJ/S2.pm  Tue Apr 13 04:31:40 2010 -0700
+++ b/cgi-bin/LJ/S2.pm  Tue Apr 13 06:28:29 2010 -0700
@@ -1980,30 +1980,10 @@ sub Entry_from_entryobj
         $text .= LJ::S2::get_tags_text($opts->{ctx}, \...@taglist);
     }
 
-    # comment information
-    my $permalink = $entry_obj->url;
-    my $replycount = $entry_obj->reply_count;
-    my $nc;
-    $nc = "nc=$replycount" if $replycount && $remote && $remote->prop( 
'opt_nctalklinks' );
-    my $linkurl = LJ::Talk::talkargs( $permalink, $style_args );
-    my $readurl = LJ::Talk::talkargs( $permalink, $nc, $style_args );
-    my $posturl = LJ::Talk::talkargs( $permalink, 'mode=reply', $style_args );
-
-    my $comments_enabled = ( ( $journal->{opt_showtalklinks} eq "Y" ) && 
!$entry_obj->comments_disabled ) ? 1 : 0;
-    my $has_screened = ( $entry_obj->props->{hasscreened} && LJ::can_manage( 
$remote, $journal ) ) ? 1 : 0;
-
     # building the CommentInfo and Entry objects
-    my $comments = CommentInfo({
-        read_url => $readurl,
-        post_url => $posturl,
-        permalink_url => $linkurl,
-        count => $replycount,
-        maxcomments => ( $replycount >= $u->count_maxcomments ) ? 1 : 0,
-        enabled => $comments_enabled,
-        screened => $has_screened,
-        show_readlink => $comments_enabled && ( $replycount || $has_screened ),
-        show_postlink => $comments_enabled,
-    });
+    my $comments = CommentInfo( $entry_obj->comment_info(
+        u => $u, remote => $remote, style_args => $style_args, journal => 
$journal
+    ) );
 
     my $entry = Entry($u, {
         subject => $subject,
@@ -2022,7 +2002,7 @@ sub Entry_from_entryobj
         end_day => 0,   #if true, set later
         userpic => $userpic,
         tags => \...@taglist,
-        permalink_url => $permalink,
+        permalink_url => $entry_obj->url,
         moodthemeid => $moodthemeid
         });
 
diff -r 190d8daebf5d -r 648857570a1f cgi-bin/LJ/S2/EntryPage.pm
--- a/cgi-bin/LJ/S2/EntryPage.pm        Tue Apr 13 04:31:40 2010 -0700
+++ b/cgi-bin/LJ/S2/EntryPage.pm        Tue Apr 13 06:28:29 2010 -0700
@@ -467,34 +467,18 @@ sub EntryPage_entry
         return;
     }
 
-    my $replycount = $entry->prop("replycount");
-    my $nc = "";
-    $nc .= "nc=$replycount" if $replycount && $remote && 
$remote->{'opt_nctalklinks'};
-
-    my $style_arg = LJ::viewing_style_args( %$get );
+    my $style_args = LJ::viewing_style_args( %$get );
     
     # load the userpic; include the keyword selected by the user
     # as a backup for the alttext
     my $pickw = LJ::Entry->userpic_kw_from_props($entry->props);
     my $userpic = Image_userpic($pu, $entry->userpic ? $entry->userpic->picid 
: 0, $pickw);
 
-    my $permalink = $entry->url;
-    my $linkurl = LJ::Talk::talkargs( $permalink, $style_arg );
-    my $readurl = LJ::Talk::talkargs( $permalink, $nc, $style_arg );
-    my $posturl = LJ::Talk::talkargs( $permalink, "mode=reply", $style_arg );
-
-    my $comments = CommentInfo({
-        'read_url' => $readurl,
-        'post_url' => $posturl,
-        'permalink_url' => $linkurl,
-        'count' => $replycount,
-        'maxcomments' => ( $replycount >= $u->count_maxcomments ) ? 1 : 0,
-        enabled => ( $viewall || ( $u->{opt_showtalklinks} eq "Y" && 
!$entry->comments_disabled ) ) ? 1 : 0,
-        comments_disabled_maintainer => $entry->comments_disabled_maintainer,
-        'screened' => ($entry->prop("hasscreened") && $remote && 
LJ::can_manage($remote, $u)) ? 1 : 0,
-    });
-    $comments->{show_postlink} = $comments->{enabled} && $get->{mode} ne 
'reply';
-    $comments->{show_readlink} = $comments->{enabled} && ($replycount || 
$comments->{screened}) && $get->{mode} eq 'reply';
+    my $comments = CommentInfo( $entry->comment_info(
+        u => $u, remote => $remote, style_args => $style_args, viewall => 
$viewall
+    ) );
+    $comments->{show_postlink} &&= $get->{mode} ne 'reply';
+    $comments->{show_readlink} &&= $get->{mode} eq 'reply';
 
     # load tags
     my @taglist;
@@ -544,7 +528,7 @@ sub EntryPage_entry
         'new_day' => 0,
         'end_day' => 0,
         'userpic' => $userpic,
-        'permalink_url' => $permalink,
+        'permalink_url' => $entry->url,
     });
 
     return ($entry, $s2entry);
_______________________________________________
dw-changelog mailing list
[email protected]
http://lists.dwscoalition.org/mailman/listinfo/dw-changelog

Reply via email to