slartyblartfast (slartyblartfast) wrote in changelog,
slartyblartfast
slartyblartfast
changelog

[ljcom] r8166: LJGI-52: Posts of friends in widget.

Committer: mchernyshev
LJGI-52: Posts of friends in widget.
- some code from cgi-bin/LJ/S2/FriendsPage.pm transfered to htdocs/gadgets/friends.bml
U   trunk/htdocs/gadgets/friends.bml
Modified: trunk/htdocs/gadgets/friends.bml
===================================================================
--- trunk/htdocs/gadgets/friends.bml	2010-02-05 07:24:40 UTC (rev 8165)
+++ trunk/htdocs/gadgets/friends.bml	2010-02-05 07:54:34 UTC (rev 8166)
@@ -14,38 +14,108 @@
 
     my $limit = $GET{limit} ? $GET{limit} : $LJ::GOOGLE_WIDGET_FRIENDS_ITEMS;
     my $skip = $GET{skip} ? ($GET{skip} - 1) : 0;
-        
+
+    my %idsbycluster;
+    my %friends;
+
     my @entries = LJ::get_friend_items({
         'remoteid'          => $u->userid,
-            'itemshow'          => $limit,
-            'skip'              => $skip,
-            'showtypes'         => undef, ## may be undef, journal types string
-            'u'                 => $u,
-            'userid'            => $u->userid,
-            'filter'            => undef,
-            'dateformat'        => 'S2',
-            ## 'common_filter' really not used inside
-        });
+        'itemshow'          => $limit,
+        'skip'              => $skip,
+        'showtypes'         => undef, ## may be undef, journal types string
+        'u'                 => $u,
+        'userid'            => $u->userid,
+        'filter'            => undef,
+        'dateformat'        => 'S2',
+        'idsbycluster'      => \%idsbycluster,
+        'friends_u'         => \%friends,
+    });
 
-    my @attrs = qw/subject_raw journalid posterid jitemid ditemid security url journal poster event_raw/;
- 
+    # 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);
+
+    my %posters;
+    {
+        my @posterids;
+        foreach my $e (@entries) {
+            next if $friends{$e->{'posterid'}};
+            push @posterids, $e->{'posterid'};
+        }
+        LJ::load_userids_multiple([ map { $_ => \$posters{$_} } @posterids ])
+            if @posterids;
+    }
+
     my $out;
     foreach my $e (@entries) {
-        my $entry = LJ::Entry->new_from_item_hash($e);
+        my ($friendid, $posterid, $itemid, $security, $allowmask, $alldatepart) =
+            map { $e->{$_} } qw(ownerid posterid itemid security allowmask alldatepart);
 
-        # event result data structure
-        my %h = ();
-        
-        # Add more data for public posts
-        foreach my $method (@attrs) {
-            $h{$method} = $entry->$method;
+        my $fr = $friends{$friendid};
+
+        my $datakey = "$friendid $itemid";
+
+        my $replycount = $logprops{$datakey}->{'replycount'};
+        my $subject = $logtext->{$datakey}->[0];
+        my $text = $logtext->{$datakey}->[1];
+
+        if ($LJ::UNICODE && $logprops{$datakey}->{'unknown8bit'}) {
+            LJ::item_toutf8($friends{$friendid}, \$subject, \$text, $logprops{$datakey});
         }
 
-        $h{title} = delete $h{subject_raw};
-        LJ::CleanHTML::clean_subject(\$h{title});
+        my ($friend, $poster);
+        $friend = $poster = $friends{$friendid}->{'user'};
 
-        $h{text} = delete $h{event_raw};
+        LJ::CleanHTML::clean_subject(\$subject) if $subject;
 
+        my $ditemid = $itemid * 256 + $e->{'anum'};
+        my $entry = LJ::Entry->new($friends{$friendid}, ditemid => $ditemid);
+
+        my $suspend_msg = $entry && $entry->should_show_suspend_msg_to($u) ? 1 : 0;
+        LJ::CleanHTML::clean_event(\$text,
+            {
+                'preformatted' => $logprops{$datakey}->{'opt_preformatted'},
+                'cuturl' => LJ::item_link(
+                    $friends{$friendid}, $itemid, $e->{'anum'}, ''),
+                'ljcut_disable' => $u ? $u->{'opt_ljcut_disable_friends'} : undef,
+                'suspend_msg' => $suspend_msg,
+                'unsuspend_supportid' => $suspend_msg ? $entry->prop("unsuspend_supportid") : 0, });
+        LJ::expand_embedded($friends{$friendid}, $ditemid, $u, \$text);
+        $text = LJ::ContentFlag->transform_post(post => $text, journal => $friends{$friendid},
+            remote => $u, entry => $entry);
+
+        my $po = $posters{$posterid} || $friends{$posterid};
+
+        # don't allow posts from suspended users or suspended posts
+        next if $po->{'statusvis'} eq 'S' || ($entry && $entry->is_suspended_for($u));
+
+        # event result data structure
+        my %h = (
+            title           => $subject,
+            text            => $text,
+
+            comments        => $replycount,
+            security        => $security,
+
+            link            => $entry->url,
+            pubDate         => $entry->{eventtime}, # deprecated field, use 'displaytime'
+
+            ditemid         => $ditemid,
+            jitemid         => $itemid,
+
+            journalname     => $fr->user,
+            journaltype     => $fr->journaltype,
+            journalid       => $friendid,
+
+            posterid        => $posterid,
+            postername      => $po->user,
+            postertype      => $po->journaltype,
+            posteruserpic   => ($entry->userpic ? $entry->userpic->url : undef),
+        );
+
         # Get first <img> from text and remember it's src=
         unless (exists($h{img})) {
             $h{text} =~ /\<img([^>]*)/i;
@@ -58,24 +128,6 @@
 
         LJ::CleanHTML::clean_friends(\$h{text});
 
-        $h{pubDate}     = $entry->{eventtime}; # deprecated field, use 'displaytime'
-
-        $h{link}        = delete $h{url};
-
-        $h{journalname} = $h{journal}->user;
-        $h{journaltype} = $h{journal}->journaltype;
-        delete $h{journal};
-
-        $h{postername}  = $h{poster}->user;
-        $h{postertype}  = $h{poster}->journaltype;
-        delete $h{poster};
-
-        $h{posteruserpic}   = $entry->userpic->url if $entry->userpic;
-
-        # As in cgi-bin/LJ/Entry.pm, method $entry->comment_list must returns a list of comments
-        # to the entry, but here, in scalar context, it returns quantity of a comments as integer number.
-        $h{comments} = $entry->comment_list;
-
         push @$out, \%h;
     }
 

Tags: bml, ljcom, slartyblartfast
Subscribe

  • Post a new comment

    Error

    Anonymous comments are disabled in this journal

    default userpic

    Your reply will be screened

    Your IP address will be recorded 

  • 0 comments