Code cleanup: move the complicated code that builds S2 Entry objects 
from four places to one central place.

        Patch by yvi. 

diffs (827 lines):

diff -r 683362edcc78 -r 2235b84b1dfe cgi-bin/LJ/S2.pm
--- a/cgi-bin/LJ/S2.pm  Fri Oct 09 23:41:43 2009 +0000
+++ b/cgi-bin/LJ/S2.pm  Sat Oct 10 05:58:08 2009 +0000
@@ -1832,6 +1832,143 @@ sub Entry
     $e->{text_must_print_trusted} = 1 if $e->{text} =~ 
m!<(script|object|applet|embed|iframe)\b!i;
 
     return $e;
+}
+
+#returns an S2 Entry from a user object and an entry object 
+sub Entry_from_entryobj
+{
+    my ($u, $entry_obj, $opts) = @_;
+    my $remote = LJ::get_remote();
+    my $get = $opts->{getargs};
+
+    my $anum = $entry_obj->anum;
+    my $jitemid = $entry_obj->jitemid;
+    my $ditemid = $entry_obj->ditemid;
+
+    # $journal: journal posted to
+    my $journalid = $entry_obj->journalid;
+    my $journal = LJ::load_userid( $journalid );
+
+    #load and prepare subject and text of entry
+    my $subject = $entry_obj->subject_html;
+    my $text = $entry_obj->event_raw;
+    if ( $get->{nohtml} ) {
+        $subject =~ s{<(?!/?lj)(.*?)>} {&lt;$1&gt;}gi;
+        $text    =~ s{<(?!/?lj)(.*?)>} {&lt;$1&gt;}gi;
+    }
+    LJ::item_toutf8( $journal, \$subject, \$text, $entry_obj->props ) if 
$LJ::UNICODE && $entry_obj->props->{unknown8bit};
+
+    LJ::CleanHTML::clean_subject( \$subject ) if $subject;
+
+    my $suspend_msg = $entry_obj && $entry_obj->should_show_suspend_msg_to( 
$remote ) ? 1 : 0;
+    # cleaning the entry text: cuts and such
+    my $cleanhtml_opts = { cuturl => LJ::item_link( $journal, $jitemid, $anum 
),
+        ljcut_disable => $remote ? $remote->prop( 'opt_cut_disable_journal' ) 
: undef,
+        suspend_msg => $suspend_msg,
+        unsuspend_supportid => $suspend_msg ? $entry_obj->prop( 
'unsuspend_supportid' ) : 0
+    };
+    # reading pages might need to display image placeholders
+    my $cleanhtml_extra = $opts->{cleanhtml_extra} || {};
+    foreach my $k ( keys %$cleanhtml_extra ) {
+        $cleanhtml_opts->{$k} = $cleanhtml_extra->{$k}
+    }
+    LJ::CleanHTML::clean_event( \$text, $cleanhtml_opts );
+
+    LJ::expand_embedded( $journal, $jitemid, $remote, \$text );
+    $text = DW::Logic::AdultContent->transform_post( post => $text, journal => 
$journal,
+                                                     remote => $remote, entry 
=> $entry_obj );
+
+    # security information
+    my $allowmask = $entry_obj->allowmask;
+    my $security = $entry_obj->security;
+    # time when entry was posted
+    my $alldatepart = LJ::alldatepart_s2( $entry_obj->{eventtime} );
+    my $system_alldatepart = LJ::alldatepart_s2( $entry_obj->{logtime} );;
+
+    # journal: posted to; poster: posted by
+    my $posterid = $entry_obj->posterid;
+    my $userlite_journal = UserLite ( $journal );
+    my $poster = $journal;
+    my $userlite_poster = $userlite_journal;
+    # except for communities, posterid and journalid should match, only load 
separate UserLite object if that is not the case
+    my $userlite_journal = $userlite_poster;
+    unless ( $posterid == $journalid ) {
+        $poster = LJ::load_userid( $posterid );
+        $userlite_poster = UserLite( $poster );
+    }
+
+    # loading S2 Userpic
+    my $userpic;
+    # if the post was made in a community, use either the userpic it was 
posted with or the community pic depending on the style setting
+    if ( $posterid == $journalid || !S2::get_property_value($opts->{ctx}, 
'use_shared_pic') ) {
+        $userpic = Image_userpic($poster, $entry_obj->userpic->picid) if 
$entry_obj->userpic;
+    } else {
+       $userpic = Image_userpic($journal, $journal->userpic->picid) if 
$journal->userpic;
+    } 
+
+    # override used moodtheme if necessary
+    my $moodthemeid = $u->prop( 'opt_forcemoodtheme' ) eq 'Y' ?
+       $u->{moodthemeid} : $poster->{moodthemeid};
+
+    # tags loading and sorting
+    my $tags = LJ::Tags::get_logtags( $journal, $jitemid );
+    my @taglist;
+    while (my ($keywordid, $keyword) = each %{$tags->{$jitemid} || {}}) {
+            push @taglist, Tag( $journal, $keywordid => $keyword );
+        }
+    @taglist = sort { $a->{name} cmp $b->{name} } @taglist;
+    if ( $opts->{enable_tags_compatibility} && @taglist ) {
+            $text .= LJ::S2::get_tags_text($opts->{ctx}, \...@taglist);
+    }
+
+    # is style=mine used? if so, it needs to be added to comment links
+    my $stylemine = "";
+    $stylemine = $get->{style} eq "mine" ? "style=mine" : "";;
+
+    # comment information
+    my $permalink = $entry_obj->url;
+    my $replycount = $entry_obj->reply_count;
+    my $nc = $replycount if $replycount && $remote && $remote->prop( 
'opt_nctalklinks' );
+    my $readurl = LJ::Talk::talkargs( $permalink, $nc, $stylemine );
+    my $posturl = LJ::Talk::talkargs( $permalink, 'mode=reply', $stylemine );
+
+    my $comments_enabled = ( ( $journal->{opt_showtalklinks} eq "Y" ) && ( ! 
$entry_obj->props->{opt_nocomments} ) ) ? 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,
+        count => $replycount,
+        maxcomments => ( $replycount >= LJ::get_cap( $u, 'maxcomments' ) ) ? 1 
: 0,
+        enabled => $comments_enabled,
+        screened => $has_screened,
+        show_readlink => $comments_enabled && ( $replycount || $has_screened ),
+        show_postlink => $comments_enabled,
+    });
+
+    my $entry = Entry($u, {
+        subject => $subject,
+        text => $text,
+        dateparts => $alldatepart,
+        system_dateparts => $system_alldatepart,
+        security => $security,
+        adult_content_level => $entry_obj->adult_content_calculated || 
$u->adult_content_calculated,
+        allowmask => $allowmask,
+        props => $entry_obj->props,
+        itemid => $ditemid,
+        journal => $userlite_journal,
+        poster => $userlite_poster,
+        comments => $comments,
+        new_day => 0, #if true, set later
+        end_day => 0,   #if true, set later
+        userpic => $userpic,
+        tags => \...@taglist,
+        permalink_url => $permalink,
+        moodthemeid => $moodthemeid
+        });
+
+    return $entry;
 }
 
 sub Friend
diff -r 683362edcc78 -r 2235b84b1dfe cgi-bin/LJ/S2/DayPage.pm
--- a/cgi-bin/LJ/S2/DayPage.pm  Fri Oct 09 23:41:43 2009 +0000
+++ b/cgi-bin/LJ/S2/DayPage.pm  Sat Oct 10 05:58:08 2009 +0000
@@ -79,136 +79,31 @@ sub DayPage
 
     my @items;
     push @items, $_ while $_ = $sth->fetchrow_hashref;
-    my @itemids = map { $_->{'itemid'} } @items;
 
-    $remote->preload_props( "opt_cut_disable_journal" ) if $remote;
-
-    ### load the log properties
-    my %logprops = ();
-    my $logtext;
-    LJ::load_log_props2($dbcr, $u->{'userid'}, \...@itemids, \%logprops);
-    $logtext = LJ::get_logtext2($u, @itemids);
-
-    my (%apu, %apu_lite);  # alt poster users; UserLite objects
+    my %apu;  # alt poster users
     foreach (@items) {
-        next unless $_->{'posterid'} != $u->{'userid'};
-        $apu{$_->{'posterid'}} = undef;
+        next unless $_->{posterid} != $u->{userid};
+        $apu{$_->{posterid}} = undef;
     }
-    if (%apu) {
-        LJ::load_userids_multiple([map { $_, \$apu{$_} } keys %apu], [$u]);
-        $apu_lite{$_} = UserLite($apu{$_}) foreach keys %apu;
-    }
-
-    # load tags
-    my $tags = LJ::Tags::get_logtags($u, \...@itemids);
-
-    my $userlite_journal = UserLite($u);
 
   ENTRY:
     foreach my $item (@items)
     {
-        my ($posterid, $itemid, $security, $allowmask, $alldatepart, $anum) =
-            map { $item->{$_} } qw(posterid itemid security allowmask 
alldatepart anum);
+        my ($posterid, $itemid, $anum) =
+            map { $item->{$_} } qw(posterid itemid anum);
 
         my $ditemid = $itemid*256 + $anum;
-        my $entry_obj = LJ::Entry->new($u, ditemid => $ditemid);
-
-        my $replycount = $logprops{$itemid}->{'replycount'};
-        my $subject = $logtext->{$itemid}->[0];
-        my $text = $logtext->{$itemid}->[1];
-        if ($get->{'nohtml'}) {
-            # quote all non-LJ tags
-            $subject =~ s{<(?!/?lj)(.*?)>} {&lt;$1&gt;}gi;
-            $text    =~ s{<(?!/?lj)(.*?)>} {&lt;$1&gt;}gi;
-        }
+        my $entry_obj = LJ::Entry->new( $u, ditemid => $ditemid );
 
         # don't show posts from suspended users or suspended posts
         next ENTRY if $apu{$posterid} && $apu{$posterid}->is_suspended && ! 
$viewsome;
         next ENTRY if $entry_obj && $entry_obj->is_suspended_for($remote);
 
-        if ($LJ::UNICODE && $logprops{$itemid}->{'unknown8bit'}) {
-            LJ::item_toutf8($u, \$subject, \$text, $logprops{$itemid});
-        }
+        # create S2 Entry object
+        my $entry = Entry_from_entryobj( $u, $entry_obj, $opts );
 
-        LJ::CleanHTML::clean_subject(\$subject) if $subject;
-
-        my $suspend_msg = $entry_obj && 
$entry_obj->should_show_suspend_msg_to($remote) ? 1 : 0;
-        LJ::CleanHTML::clean_event(\$text, { 'preformatted' => 
$logprops{$itemid}->{'opt_preformatted'},
-                                             'cuturl' => LJ::item_link($u, 
$itemid, $anum),
-                                             'ljcut_disable' => $remote ? 
$remote->{'opt_cut_disable_journal'} : undef,
-                                             'suspend_msg' => $suspend_msg,
-                                             'unsuspend_supportid' => 
$suspend_msg ? $entry_obj->prop("unsuspend_supportid") : 0, });
-        LJ::expand_embedded($u, $ditemid, $remote, \$text);
-
-        $text = DW::Logic::AdultContent->transform_post( post => $text, 
journal => $u,
-                                                         remote => $remote, 
entry => $entry_obj );
-
-        my $nc = "";
-        $nc .= "nc=$replycount" if $replycount && $remote && 
$remote->{'opt_nctalklinks'};
-
-        my $permalink = "$journalbase/$ditemid.html";
-        my $readurl = $permalink;
-        $readurl .= "?$nc" if $nc;
-        my $posturl = $permalink . "?mode=reply";
-
-        my $comments = CommentInfo({
-            'read_url' => $readurl,
-            'post_url' => $posturl,
-            'count' => $replycount,
-            'maxcomments' => ($replycount >= LJ::get_cap($u, 'maxcomments')) ? 
1 : 0,
-            'enabled' => ($u->{'opt_showtalklinks'} eq "Y" && ! 
$logprops{$itemid}->{'opt_nocomments'}) ? 1 : 0,
-            'screened' => ($logprops{$itemid}->{'hasscreened'} && $remote && 
LJ::can_manage($remote, $u)) ? 1 : 0,
-        });
-        $comments->{show_postlink} = $comments->{enabled};
-        $comments->{show_readlink} = $comments->{enabled} && ($replycount || 
$comments->{screened});
-
-        my $userlite_poster = $userlite_journal;
-        my $pu = $u;
-        if ($u->{'userid'} != $posterid) {
-            $userlite_poster = $apu_lite{$posterid} or die "No apu_lite for 
posterid=$posterid";
-            $pu = $apu{$posterid};
-        }
-
-        my $kw = LJ::Entry->userpic_kw_from_props($logprops{$itemid});
-        my $userpic = Image_userpic($pu, 0, $kw);
-
-        my @taglist;
-        while (my ($kwid, $kw) = each %{$tags->{$itemid} || {}}) {
-            push @taglist, Tag($u, $kwid => $kw);
-        }
-        @taglist = sort { $a->{name} cmp $b->{name} } @taglist;
-
-        if ($opts->{enable_tags_compatibility} && @taglist) {
-            $text .= LJ::S2::get_tags_text($opts->{ctx}, \...@taglist);
-        }
-
-        if ($security eq "public" && 
!$LJ::REQ_GLOBAL{'text_of_first_public_post'}) {
-            $LJ::REQ_GLOBAL{'text_of_first_public_post'} = $text;
-
-            if (@taglist) {
-                $LJ::REQ_GLOBAL{'tags_of_first_public_post'} = [map { 
$_->{name} } @taglist];
-            }
-        }
-
-        my $entry = Entry($u, {
-            'subject' => $subject,
-            'text' => $text,
-            'dateparts' => $alldatepart,
-            'system_dateparts' => $item->{system_alldatepart},
-            'security' => $security,
-            'adult_content_level' => $entry_obj->adult_content_calculated || 
$u->adult_content_calculated,
-            'allowmask' => $allowmask,
-            'props' => $logprops{$itemid},
-            'itemid' => $ditemid,
-            'journal' => $userlite_journal,
-            'poster' => $userlite_poster,
-            'comments' => $comments,
-            'tags' => \...@taglist,
-            'userpic' => $userpic,
-            'permalink_url' => $permalink,
-        });
-
-        push @{$p->{'entries'}}, $entry;
+        # add S2 Entry object to page
+        push @{$p->{entries}}, $entry;
         LJ::run_hook('notify_event_displayed', $entry_obj);
     }
 
diff -r 683362edcc78 -r 2235b84b1dfe cgi-bin/LJ/S2/FriendsPage.pm
--- a/cgi-bin/LJ/S2/FriendsPage.pm      Fri Oct 09 23:41:43 2009 +0000
+++ b/cgi-bin/LJ/S2/FriendsPage.pm      Sat Oct 10 05:58:08 2009 +0000
@@ -137,16 +137,6 @@ sub FriendsPage
 
     return $p unless %friends;
 
-    ### load the log properties
-    my %logprops = ();  # key is "$owneridOrZero $[j]itemid"
-    LJ::load_log_props2multi(\%idsbycluster, \%logprops);
-
-    # load the text of the entries
-    my $logtext = LJ::get_logtext2multi(\%idsbycluster);
-
-    # load tags on these entries
-    my $logtags = LJ::Tags::get_logtagsmulti(\%idsbycluster);
-
     my %posters;
     {
         my @posterids;
@@ -158,71 +148,20 @@ sub FriendsPage
             if @posterids;
     }
 
-    my %objs_of_picid;
-    my @userpic_load;
-
-    my %lite;   # posterid -> s2_UserLite
-    my $get_lite = sub {
-        my $id = shift;
-        return $lite{$id} if $lite{$id};
-        return $lite{$id} = UserLite($posters{$id} || $friends{$id});
-    };
-
     my $eventnum = 0;
     my $hiddenentries = 0;
   ENTRY:
     foreach my $item (@items)
     {
-        my ($friendid, $posterid, $itemid, $security, $allowmask, 
$alldatepart) =
-            map { $item->{$_} } qw(ownerid posterid itemid security allowmask 
alldatepart);
+        my ($friendid, $posterid, $itemid, $anum) =
+            map { $item->{$_} } qw(ownerid posterid itemid anum);
 
+        # $fr = journal posted in, can be community
         my $fr = $friends{$friendid};
-        $p->{'friends'}->{$fr->{'user'}} ||= Friend($fr);
+        $p->{friends}->{$fr->{user}} ||= Friend($fr);
 
-        my $clusterid = $item->{'clusterid'}+0;
-        my $datakey = "$friendid $itemid";
-
-        my $replycount = $logprops{$datakey}->{'replycount'};
-        my $subject = $logtext->{$datakey}->[0];
-        my $text = $logtext->{$datakey}->[1];
-        if ($get->{'nohtml'}) {
-            # quote all non-LJ tags
-            $subject =~ s{<(?!/?lj)(.*?)>} {&lt;$1&gt;}gi;
-            $text    =~ s{<(?!/?lj)(.*?)>} {&lt;$1&gt;}gi;
-        }
-
-        if ($LJ::UNICODE && $logprops{$datakey}->{'unknown8bit'}) {
-            LJ::item_toutf8($friends{$friendid}, \$subject, \$text, 
$logprops{$datakey});
-        }
-
-        my ($friend, $poster);
-        $friend = $poster = $friends{$friendid}->{'user'};
-
-        LJ::CleanHTML::clean_subject(\$subject) if $subject;
-
-        my $ditemid = $itemid * 256 + $item->{'anum'};
-        my $entry_obj = LJ::Entry->new($friends{$friendid}, ditemid => 
$ditemid);
-
-        my $stylemine = "";
-        $stylemine .= "style=mine" if $remote && $remote->{'opt_stylemine'} &&
-                                      $remote->{'userid'} != $friendid;
-
-        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' => 
LJ::item_link($friends{$friendid}, $itemid, $item->{'anum'}, $stylemine),
-                                             'maximgwidth' => $maximgwidth,
-                                             'maximgheight' => $maximgheight,
-                                             'imageplaceundef' => $remote ? 
$remote->{'opt_imageundef'} : undef,
-                                             'ljcut_disable' => $remote ? 
$remote->{'opt_cut_disable_reading'} : undef,
-                                             'suspend_msg' => $suspend_msg,
-                                             'unsuspend_supportid' => 
$suspend_msg ? $entry_obj->prop("unsuspend_supportid") : 0, });
-        LJ::expand_embedded($friends{$friendid}, $ditemid, $remote, \$text);
-
-        $text = DW::Logic::AdultContent->transform_post( post => $text, 
journal => $friends{$friendid},
-                                                         remote => $remote, 
entry => $entry_obj );
-
-        my $userlite_poster = $get_lite->($posterid);
-        my $userlite_journal = $get_lite->($friendid);
+        my $ditemid = $itemid * 256 + $anum;
+        my $entry_obj = LJ::Entry->new( $fr, ditemid => $ditemid );
 
         # get the poster user
         my $po = $posters{$posterid} || $friends{$posterid};
@@ -233,92 +172,22 @@ sub FriendsPage
             next ENTRY;
         }
 
-        my $eobj = LJ::Entry->new($friends{$friendid}, ditemid => $ditemid);
+        # reading page might need placeholder images
+        $opts->{cleanhtml_extra} = {
+            maximgheight => $maximgheight,
+            maximgwidth =>  $maximgwidth,
+            imageplaceundef => $remote ? $remote->{'opt_imageundef'} : undef
+        };
 
-        # do the picture
-        my $picid = 0;
-        my $picu = undef;
-        if ($friendid != $posterid && S2::get_property_value($opts->{ctx}, 
'use_shared_pic')) {
-            # using the community, the user wants to see shared pictures
-            $picu = $friends{$friendid};
+        # make S2 entry
+        my $entry = Entry_from_entryobj( $u, $entry_obj, $opts );
 
-            # use shared pic for community
-            $picid = $friends{$friendid}->{defaultpicid};
-        } else {
-            # we're using the poster for this picture
-            $picu = $po;
-
-            # check if they specified one
-            $picid = $eobj->userpic ? $eobj->userpic->picid : 0;
-        }
-
-        my $nc = "";
-        $nc .= "nc=$replycount" if $replycount && $remote && 
$remote->{'opt_nctalklinks'};
-
-        my $journalbase = LJ::journal_base($friends{$friendid});
-        my $permalink = $eobj->url;
-        my $readurl = LJ::Talk::talkargs($permalink, $nc, $stylemine);
-        my $posturl = LJ::Talk::talkargs($permalink, "mode=reply", $stylemine);
-
-        my $comments = CommentInfo({
-            'read_url' => $readurl,
-            'post_url' => $posturl,
-            'count' => $replycount,
-            'maxcomments' => ($replycount >= LJ::get_cap($u, 'maxcomments')) ? 
1 : 0,
-            'enabled' => ($friends{$friendid}->{'opt_showtalklinks'} eq "Y" &&
-                          ! $logprops{$datakey}->{'opt_nocomments'}) ? 1 : 0,
-            'screened' => ($logprops{$datakey}->{'hasscreened'} && $remote && 
LJ::can_manage($remote, $fr)) ? 1 : 0,
-        });
-        $comments->{show_postlink} = $comments->{enabled};
-        $comments->{show_readlink} = $comments->{enabled} && ($replycount || 
$comments->{screened});
-
-        my $moodthemeid = $u->{'opt_forcemoodtheme'} eq 'Y' ?
-            $u->{'moodthemeid'} : $friends{$friendid}->{'moodthemeid'};
-
-        my @taglist;
-        while (my ($kwid, $kw) = each %{$logtags->{$datakey} || {}}) {
-            push @taglist, Tag($friends{$friendid}, $kwid => $kw);
-        }
-        LJ::run_hooks('augment_s2_tag_list', u => $u, jitemid => $itemid, 
tag_list => \...@taglist);
-        @taglist = sort { $a->{name} cmp $b->{name} } @taglist;
-
-        if ($opts->{enable_tags_compatibility} && @taglist) {
-            $text .= LJ::S2::get_tags_text($opts->{ctx}, \...@taglist);
-        }
-
-        if ($security eq "public" && 
!$LJ::REQ_GLOBAL{'text_of_first_public_post'}) {
-            $LJ::REQ_GLOBAL{'text_of_first_public_post'} = $text;
-
-            if (@taglist) {
-                $LJ::REQ_GLOBAL{'tags_of_first_public_post'} = [map { 
$_->{name} } @taglist];
-            }
-        }
-
-        my $entry = Entry($u, {
-            'subject' => $subject,
-            'text' => $text,
-            'dateparts' => $alldatepart,
-            'system_dateparts' => $item->{'system_alldatepart'},
-            'security' => $security,
-            'adult_content_level' => $eobj->adult_content_calculated || 
$friends{$friendid}->adult_content_calculated,
-            'allowmask' => $allowmask,
-            'props' => $logprops{$datakey},
-            'itemid' => $ditemid,
-            'journal' => $userlite_journal,
-            'poster' => $userlite_poster,
-            'comments' => $comments,
-            'new_day' => 0,  # setup below
-            'end_day' => 0,  # setup below
-            'userpic' => Image_userpic( $picu, $picid, 
$eobj->userpic_kw_from_props( $logprops{$datakey} ) ),
-            'tags' => \...@taglist,
-            'permalink_url' => $permalink,
-            'moodthemeid' => $moodthemeid,
-        });
-        $entry->{'_ymd'} = join('-', map { $entry->{'time'}->{$_} } qw(year 
month day));
+        $entry->{_ymd} = join('-', map { $entry->{'time'}->{$_} } qw(year 
month day));
 
         push @{$p->{'entries'}}, $entry;
         $eventnum++;
-        LJ::run_hook('notify_event_displayed', $eobj);
+
+        LJ::run_hook('notify_event_displayed', $entry_obj);
     } # end while
 
     # set the new_day and end_day members.
diff -r 683362edcc78 -r 2235b84b1dfe cgi-bin/LJ/S2/MonthPage.pm
--- a/cgi-bin/LJ/S2/MonthPage.pm        Fri Oct 09 23:41:43 2009 +0000
+++ b/cgi-bin/LJ/S2/MonthPage.pm        Sat Oct 10 05:58:08 2009 +0000
@@ -73,104 +73,33 @@ sub MonthPage
     push @items, $_ while $_ = $sth->fetchrow_hashref;
     @items = sort { $a->{'alldatepart'} cmp $b->{'alldatepart'} } @items;
 
-    my @itemids = map { $_->{'jitemid'} } @items;
-
-    # load the log properties
-    my %logprops = ();
-    LJ::load_log_props2($u->{'userid'}, \...@itemids, \%logprops);
-    my $lt = LJ::get_logtext2($u, @itemids);
-
-    # load tags
-    my $tags = LJ::Tags::get_logtags($u, \...@itemids);
-
-    my (%pu, %pu_lite);  # poster users; UserLite objects
+    my %pu;  # poster users; 
     foreach (@items) {
-        $pu{$_->{'posterid'}} = undef;
+        $pu{$_->{posterid}} = undef;
     }
     LJ::load_userids_multiple([map { $_, \$pu{$_} } keys %pu], [$u]);
-    $pu_lite{$_} = UserLite($pu{$_}) foreach keys %pu;
 
     my %day_entries;  # <day> -> [ Entry+ ]
 
-    my $opt_text_subjects = S2::get_property_value($ctx, 
"page_month_textsubjects");
-    my $userlite_journal = UserLite($u);
+    my $opt_text_subjects = S2::get_property_value( $ctx, 
"page_month_textsubjects" );
 
   ENTRY:
     foreach my $item (@items)
     {
-        my ($posterid, $itemid, $security, $allowmask, $alldatepart, 
$replycount, $anum) =
-            map { $item->{$_} } qw(posterid jitemid security allowmask 
alldatepart replycount anum);
-        my $subject = $lt->{$itemid}->[0];
+        my ($posterid, $itemid, $anum) =
+            map { $item->{$_} } qw(posterid jitemid anum);
         my $day = $item->{'day'};
 
         my $ditemid = $itemid*256 + $anum;
-        my $entry_obj = LJ::Entry->new($u, ditemid => $ditemid);
+        my $entry_obj = LJ::Entry->new( $u, ditemid => $ditemid );
 
         # don't show posts from suspended users or suspended posts
         next unless $pu{$posterid};
         next ENTRY if $pu{$posterid}->is_suspended && !$viewsome;
         next ENTRY if $entry_obj && $entry_obj->is_suspended_for($remote);
 
-       if ($LJ::UNICODE && $logprops{$itemid}->{'unknown8bit'}) {
-            my $text;
-           LJ::item_toutf8($u, \$subject, \$text, $logprops{$itemid});
-       }
-
-        if ($opt_text_subjects) {
-            LJ::CleanHTML::clean_subject_all(\$subject);
-        } else {
-            LJ::CleanHTML::clean_subject(\$subject);
-        }
-
-        my $nc = "";
-        $nc .= "nc=$replycount" if $replycount && $remote && 
$remote->{'opt_nctalklinks'};
-        my $permalink = "$journalbase/$ditemid.html";
-        my $readurl = $permalink;
-        $readurl .= "?$nc" if $nc;
-        my $posturl = $permalink . "?mode=reply";
-
-        my $comments = CommentInfo({
-            'read_url' => $readurl,
-            'post_url' => $posturl,
-            'count' => $replycount,
-            'maxcomments' => ($replycount >= LJ::get_cap($u, 'maxcomments')) ? 
1 : 0,
-            'enabled' => ($u->{'opt_showtalklinks'} eq "Y" && ! 
$logprops{$itemid}->{'opt_nocomments'}) ? 1 : 0,
-            'screened' => ($logprops{$itemid}->{'hasscreened'} && $remote && 
LJ::can_manage($remote, $u)) ? 1 : 0,
-        });
-
-        my $userlite_poster = $userlite_journal;
-        my $userpic = $p->{'journal'}->{'default_pic'};
-        if ($u->{'userid'} != $posterid) {
-            $userlite_poster = $pu_lite{$posterid};
-            my $pickw = LJ::Entry->userpic_kw_from_props($logprops{$itemid});
-            $userpic = Image_userpic($pu{$posterid}, 0, $pickw);
-        }
-
-        my $entry_obj = LJ::Entry->new($u, ditemid => $ditemid);
-
-        my @taglist;
-        while (my ($kwid, $kw) = each %{$tags->{$itemid} || {}}) {
-            push @taglist, Tag($u, $kwid => $kw);
-        }
-        @taglist = sort { $a->{name} cmp $b->{name} } @taglist;
-
-        my $entry = Entry($u, {
-            'subject' => $subject,
-            'text' => "",
-            'dateparts' => $alldatepart,
-            'system_dateparts' => $item->{system_alldatepart},
-            'security' => $security,
-            'adult_content_level' => $entry_obj->adult_content_calculated || 
$u->adult_content_calculated,
-            'allowmask' => $allowmask,
-            'props' => $logprops{$itemid},
-            'itemid' => $ditemid,
-            'journal' => $userlite_journal,
-            'poster' => $userlite_poster,
-            'comments' => $comments,
-            'tags' => \...@taglist,
-            'userpic' => $userpic,
-            'permalink_url' => $permalink,
-        });
+        # create the S2 entry
+        my $entry = Entry_from_entryobj( $u, $entry_obj, $opts );
 
         push @{$day_entries{$day}}, $entry;
     }
diff -r 683362edcc78 -r 2235b84b1dfe cgi-bin/LJ/S2/RecentPage.pm
--- a/cgi-bin/LJ/S2/RecentPage.pm       Fri Oct 09 23:41:43 2009 +0000
+++ b/cgi-bin/LJ/S2/RecentPage.pm       Sat Oct 10 05:58:08 2009 +0000
@@ -101,181 +101,65 @@ sub RecentPage
 
     die $err if $err;
 
-    # prepare sticky entry for S2 - should there ever be a function to get an 
s2 formatted entry from an Entry object
-    # this should be changed to use that.  only show sticky entry on first 
page of Recent Entries, not on skip= pages
+    # prepare sticky entry for S2 - only show sticky entry on first page of 
Recent Entries, not on skip= pages
     # or tag and security subfilters
     my $stickyentry = $u->get_sticky_entry
         if $skip == 0 && ! $opts->{securityfilter} && ! $opts->{tagids};
-
     # only show if visible to user
     if ( $stickyentry && $stickyentry->visible_to( $remote, $get->{viewall} ) 
) {
-        unshift @items, {
-            posterid    => $stickyentry->poster->userid, 
-            itemid      => $stickyentry->jitemid, 
-            anum        => $stickyentry->anum,
-            security    => $stickyentry->security, 
-            allowmask   => $stickyentry->allowmask, 
-            alldatepart => LJ::alldatepart_s2($stickyentry->eventtime_mysql), 
-            sticky      => 1 
-        };
+        # create S2 entry object and show first on page
+        my $entry = Entry_from_entryobj( $u, $stickyentry, $opts ); 
+        # sticky entry specific things
+        my $sticky_icon = Image_std( 'sticky-entry' );
+        $entry->{_type} = 'StickyEntry';
+        $entry->{sticky_entry_icon} = $sticky_icon;
+        # show on top of page
+        push @{$p->{entries}}, $entry;
     }
-  
-    ### load the log properties
-    my %logprops = ();
-    my $logtext;
-    LJ::load_log_props2($u->{'userid'}, \...@itemids, \%logprops);
-    $logtext = LJ::get_logtext2($u, @itemids);
-
+    
     my $lastdate = "";
     my $itemnum = 0;
     my $lastentry = undef;
 
-    my (%apu, %apu_lite);  # alt poster users; UserLite objects
+    my (%apu);  # alt poster users
     foreach (@items) {
-        next unless $_->{'posterid'} != $u->{'userid'};
-        $apu{$_->{'posterid'}} = undef;
+        next unless $_->{posterid} != $u->{userid};
+        $apu{$_->{posterid}} = undef;
     }
-    if (%apu) {
-        LJ::load_userids_multiple([map { $_, \$apu{$_} } keys %apu], [$u]);
-        $apu_lite{$_} = UserLite($apu{$_}) foreach keys %apu;
-    }
-
-    # load tags
-    my $idsbyc = { $u->{clusterid} => [ ] };
-    push @{$idsbyc->{$u->{clusterid}}}, [ $u->{userid}, $_->{itemid} ]
-        foreach @items;
-    my $tags = LJ::Tags::get_logtagsmulti($idsbyc);
-
-    my $userlite_journal = UserLite($u);
 
   ENTRY:
     foreach my $item (@items)
     {
-        my ($posterid, $itemid, $security, $allowmask, $alldatepart) =
-            map { $item->{$_} } qw(posterid itemid security allowmask 
alldatepart);
+        my ($posterid, $itemid, $anum) =
+            map { $item->{$_} } qw(posterid itemid anum);
 
-        my $ditemid = $itemid * 256 + $item->{'anum'};
-        my $entry_obj = LJ::Entry->new($u, ditemid => $ditemid);
+        my $ditemid = $itemid * 256 + $anum;
+        my $entry_obj = LJ::Entry->new( $u, ditemid => $ditemid );
 
-        my $replycount = $logprops{$itemid}->{'replycount'};
-        my $subject = $logtext->{$itemid}->[0];
-        my $text = $logtext->{$itemid}->[1];
-        if ($get->{'nohtml'}) {
-            # quote all non-LJ tags
-            $subject =~ s{<(?!/?lj)(.*?)>} {&lt;$1&gt;}gi;
-            $text    =~ s{<(?!/?lj)(.*?)>} {&lt;$1&gt;}gi;
-        }
-
-        #don't count sticky item towards total
-        $itemnum++ unless $item->{sticky};
+        $itemnum++;
 
         # don't show posts from suspended users or suspended posts unless the 
user doing the viewing says to (and is allowed)
         next ENTRY if $apu{$posterid} && $apu{$posterid}->is_suspended && 
!$viewsome;
         next ENTRY if $entry_obj && $entry_obj->is_suspended_for($remote);
 
-        if ($LJ::UNICODE && $logprops{$itemid}->{'unknown8bit'}) {
-            LJ::item_toutf8($u, \$subject, \$text, $logprops{$itemid});
-        }
+        # create S2 entry, journal posted to is $u
+        my $entry = $lastentry = Entry_from_entryobj( $u, $entry_obj, $opts );
 
+        # end_day and new_day need to be set
+        my $alldatepart = LJ::alldatepart_s2( $entry_obj->{eventtime} );
         my $date = substr($alldatepart, 0, 10);
         my $new_day = 0;
-        if ($date ne $lastdate) {
+        if ( $date ne $lastdate ) {
             $new_day = 1;
             $lastdate = $date;
-            $lastentry->{'end_day'} = 1 if $lastentry;
+            $lastentry->{end_day} = 1 if $lastentry;
         }
+        $entry->{new_day} = $new_day,
 
-        LJ::CleanHTML::clean_subject(\$subject) if $subject;
+        push @{$p->{entries}}, $entry;
 
-        my $suspend_msg = $entry_obj && 
$entry_obj->should_show_suspend_msg_to($remote) ? 1 : 0;
-        LJ::CleanHTML::clean_event(\$text, { 'preformatted' => 
$logprops{$itemid}->{'opt_preformatted'},
-                                              'cuturl' => LJ::item_link($u, 
$itemid, $item->{'anum'}),
-                                              'ljcut_disable' => $remote ? 
$remote->prop("opt_cut_disable_journal") : undef,
-                                              'suspend_msg' => $suspend_msg,
-                                              'unsuspend_supportid' => 
$suspend_msg ? $entry_obj->prop("unsuspend_supportid") : 0, });
-        LJ::expand_embedded($u, $ditemid, $remote, \$text);
-
-        $text = DW::Logic::AdultContent->transform_post( post => $text, 
journal => $u,
-                                                         remote => $remote, 
entry => $entry_obj );
-
-        my @taglist;
-        while (my ($kwid, $kw) = each %{$tags->{"$u->{userid} $itemid"} || 
{}}) {
-            push @taglist, Tag($u, $kwid => $kw);
-        }
-        LJ::run_hooks('augment_s2_tag_list', u => $u, jitemid => $itemid, 
tag_list => \...@taglist);
-        @taglist = sort { $a->{name} cmp $b->{name} } @taglist;
-
-        if ($opts->{enable_tags_compatibility} && @taglist) {
-            $text .= LJ::S2::get_tags_text($opts->{ctx}, \...@taglist);
-        }
-
-        my $permalink = "$journalbase/$ditemid.html";
-        my $nc = $replycount if $replycount && $remote && 
$remote->prop('opt_nctalklinks');
-        my $posturl = $permalink . "?mode=reply";
-        my $readurl = LJ::make_link( $permalink, { style => $mine,
-                                                   s2id  => LJ::eurl( 
$get->{s2id} ) || "",
-                                                   nc    => $nc || "" } );
-
-        my $comments_enabled = ($u->{'opt_showtalklinks'} eq "Y" && ! 
$logprops{$itemid}->{'opt_nocomments'}) ? 1 : 0;
-        my $has_screened = ($logprops{$itemid}->{'hasscreened'} && 
LJ::can_manage($remote, $u)) ? 1 : 0;
-
-        my $comments = CommentInfo({
-            'read_url' => $readurl,
-            'post_url' => $posturl,
-            'count' => $replycount,
-            'maxcomments' => ($replycount >= LJ::get_cap($u, 'maxcomments')) ? 
1 : 0,
-            'enabled' => $comments_enabled,
-            'screened' => $has_screened,
-            'show_readlink' => $comments_enabled && ($replycount || 
$has_screened),
-            'show_postlink' => $comments_enabled,
-        });
-
-        my $userlite_poster = $userlite_journal;
-        my $pu = $u;
-        if ($u->{'userid'} != $posterid) {
-            $userlite_poster = $apu_lite{$posterid} or die "No apu_lite for 
posterid=$posterid";
-            $pu = $apu{$posterid};
-        }
-        my $pickw = LJ::Entry->userpic_kw_from_props($logprops{$itemid});
-        my $userpic = Image_userpic($pu, 0, $pickw);
-
-        if ($security eq "public" && 
!$LJ::REQ_GLOBAL{'text_of_first_public_post'}) {
-            $LJ::REQ_GLOBAL{'text_of_first_public_post'} = $text;
-
-            if (@taglist) {
-                $LJ::REQ_GLOBAL{'tags_of_first_public_post'} = [map { 
$_->{name} } @taglist];
-            }
-        }
-
-        my $entry = $lastentry = Entry($u, {
-            'subject' => $subject,
-            'text' => $text,
-            'dateparts' => $alldatepart,
-            'system_dateparts' => $item->{system_alldatepart},
-            'security' => $security,
-            'adult_content_level' => $entry_obj->adult_content_calculated || 
$u->adult_content_calculated,
-            'allowmask' => $allowmask,
-            'props' => $logprops{$itemid},
-            'itemid' => $ditemid,
-            'journal' => $userlite_journal,
-            'poster' => $userlite_poster,
-            'comments' => $comments,
-            'new_day' => $new_day,
-            'end_day' => 0,   # if true, set later
-            'tags' => \...@taglist,
-            'userpic' => $userpic,
-            'permalink_url' => $permalink,
-        });
-
-        if ( $item->{sticky} ) {
-            my $sticky_icon = Image_std('sticky-entry');
-            $entry->{_type} = 'StickyEntry';
-            $entry->{'sticky_entry_icon'} = $sticky_icon;
-        }
-
-        push @{$p->{'entries'}}, $entry;
         LJ::run_hook('notify_event_displayed', $entry_obj);
-    } # end huge while loop
+    }
 
     # mark last entry as closing.
     $p->{'entries'}->[-1]->{'end_day'} = 1 if @{$p->{'entries'} || []};
_______________________________________________
dw-changelog mailing list
[email protected]
http://lists.dwscoalition.org/mailman/listinfo/dw-changelog

Reply via email to