madeon (madeon) wrote in changelog,
madeon
madeon
changelog

[livejournal] r19776: Delayed entries support added

Committer: sbelyaev
Delayed entries support added
U   branches/delayed_entries/cgi-bin/LJ/S2/DayPage.pm
U   branches/delayed_entries/cgi-bin/LJ/S2/EntryPage.pm
U   branches/delayed_entries/cgi-bin/LJ/S2/MonthPage.pm
U   branches/delayed_entries/cgi-bin/LJ/S2.pm
Modified: branches/delayed_entries/cgi-bin/LJ/S2/DayPage.pm
===================================================================
--- branches/delayed_entries/cgi-bin/LJ/S2/DayPage.pm	2011-08-18 13:01:21 UTC (rev 19775)
+++ branches/delayed_entries/cgi-bin/LJ/S2/DayPage.pm	2011-08-18 13:17:46 UTC (rev 19776)
@@ -83,6 +83,7 @@
 
     my @items;
     push @items, $_ while $_ = $sth->fetchrow_hashref;
+    
     my @itemids = map { $_->{'itemid'} } @items;
 
     # load 'opt_ljcut_disable_lastn' prop for $remote.
@@ -106,6 +107,11 @@
 
     # load tags
     my $tags = LJ::Tags::get_logtags($u, \@itemids);
+    
+    my @ditems = LJ::DelayedEntry->get_entries_for_day($u, $year, $month, $day, $dateformat, $secwhere);
+    foreach my $ditem (@ditems) {
+        push @items, $ditem;
+    }
 
     my $userlite_journal = UserLite($u);
 
@@ -116,12 +122,25 @@
             map { $item->{$_} } qw(posterid itemid security allowmask alldatepart anum);
 
         my $ditemid = $itemid*256 + $anum;
-        my $entry_obj = LJ::Entry->new($u, ditemid => $ditemid);
-        $entry_obj->handle_prefetched_props($logprops{$itemid});
-
-        my $replycount = $logprops{$itemid}->{'replycount'};
-        my $subject = $logtext->{$itemid}->[0];
-        my $text = $logtext->{$itemid}->[1];
+        my $entry_obj;
+        if ($item->{delayedid}) {
+            $entry_obj = LJ::DelayedEntry->get_entry_by_id($u, $item->{delayedid});
+        } else {
+            $entry_obj = LJ::Entry->new($u, ditemid => $ditemid);
+            $entry_obj->handle_prefetched_props($logprops{$itemid});
+        }
+        
+        my ($replycount, $subject, $text);
+        if ($item->{delayedid}) {
+            $replycount = 0;
+            $subject = $entry_obj->subject;
+            $text = $entry_obj->event;
+        } else {
+            $replycount = $logprops{$itemid}->{'replycount'} || 0;
+            $subject = $logtext->{$itemid}->[0];
+            $text = $logtext->{$itemid}->[1];
+        }
+        
         if ($get->{'nohtml'}) {
             # quote all non-LJ tags
             $subject =~ s{<(?!/?lj)(.*?)>} {&lt;$1&gt;}gi;
@@ -166,7 +185,7 @@
         my $nc = "";
         $nc .= "nc=$replycount" if $replycount && $remote && $remote->{'opt_nctalklinks'};
 
-        my $permalink = "$journalbase/$ditemid.html";
+        my $permalink = $entry_obj->is_delayed ? $entry_obj->url : "$journalbase/$ditemid.html";
         my $readurl = $permalink;
         $readurl .= "?$nc" if $nc;
         my $posturl = $permalink . "?mode=reply";
@@ -220,6 +239,7 @@
             'security' => $security,
             'allowmask' => $allowmask,
             'props' => $logprops{$itemid},
+            'delayedid' => $entry_obj->is_delayed ? $entry_obj->delayedid : undef,
             'itemid' => $ditemid,
             'journal' => $userlite_journal,
             'poster' => $userlite_poster,

Modified: branches/delayed_entries/cgi-bin/LJ/S2/EntryPage.pm
===================================================================
--- branches/delayed_entries/cgi-bin/LJ/S2/EntryPage.pm	2011-08-18 13:01:21 UTC (rev 19775)
+++ branches/delayed_entries/cgi-bin/LJ/S2/EntryPage.pm	2011-08-18 13:17:46 UTC (rev 19776)
@@ -409,10 +409,10 @@
 
     my $uri = LJ::Request->uri;
 
-    my ($ditemid, $itemid);
+    my ($ditemid, $itemid, $delayedid);
     my $entry = $opts->{ljentry};  # only defined in named-URI case.  otherwise undef.
 
-    unless ($entry || $uri =~ /(\d+)\.html/) {
+    unless ($entry || $uri =~ /(\d+)\.html/ || $uri =~ /d(\d+)\.html/) {
         $opts->{'handler_return'} = 404;
         LJ::Request->pnotes ('error' => 'e404');
         LJ::Request->pnotes ('remote' => LJ::get_remote());
@@ -421,7 +421,7 @@
 
     $entry ||= LJ::Entry->new($u, ditemid => $1);
 
-    unless ($entry and $entry->correct_anum) {
+    unless ($entry and ($entry->correct_anum or $entry->is_delayed)) {
         $opts->{'handler_return'} = 404;
         LJ::Request->pnotes ('error' => 'e404');
         LJ::Request->pnotes ('remote' => LJ::get_remote());
@@ -430,6 +430,7 @@
 
     $ditemid = $entry->ditemid;
     $itemid  = $entry->jitemid;
+    $delayedid = $entry->delayedid;
 
     my $pu = $entry->poster;
 
@@ -512,7 +513,9 @@
         while (my ($kwid, $kw) = each %$tag_map) {
             push @taglist, Tag($u, $kwid => $kw);
         }
-        LJ::run_hooks('augment_s2_tag_list', u => $u, jitemid => $itemid, tag_list => \@taglist);
+        if (!$delayedid) {
+            LJ::run_hooks('augment_s2_tag_list', u => $u, jitemid => $itemid, tag_list => \@taglist);
+        }
         @taglist = sort { $a->{name} cmp $b->{name} } @taglist;
     }
 
@@ -557,6 +560,7 @@
         'allowmask' => $entry->allowmask,
         'props' => $entry->props,
         'itemid' => $ditemid,
+        'delayedid' => $entry->is_delayed ? $entry->delayedid : undef ,
         'comments' => $comments,
         'journal' => $userlite_journal,
         'poster' => $userlite_poster,

Modified: branches/delayed_entries/cgi-bin/LJ/S2/MonthPage.pm
===================================================================
--- branches/delayed_entries/cgi-bin/LJ/S2/MonthPage.pm	2011-08-18 13:01:21 UTC (rev 19775)
+++ branches/delayed_entries/cgi-bin/LJ/S2/MonthPage.pm	2011-08-18 13:17:46 UTC (rev 19776)
@@ -6,6 +6,7 @@
 
 use LJ::TimeUtil;
 use LJ::UserApps;
+use LJ::DelayedEntry;
 
 sub MonthPage
 {
@@ -76,6 +77,12 @@
 
     my @items;
     push @items, $_ while $_ = $sth->fetchrow_hashref;
+    
+    my @ditems = LJ::DelayedEntry->get_entries_for_month($u, $year, $month, $dateformat, $secwhere);
+    foreach my $ditem (@ditems) {
+        push @items, $ditem;
+    }
+    
     @items = sort { $a->{'alldatepart'} cmp $b->{'alldatepart'} } @items;
 
     my @itemids = map { $_->{'jitemid'} } @items;
@@ -106,8 +113,16 @@
         my $day = $item->{'day'};
 
         my $ditemid = $itemid*256 + $anum;
-        my $entry_obj = LJ::Entry->new($u, ditemid => $ditemid);
-        $entry_obj->handle_prefetched_props($logprops{$itemid});
+        my $entry_obj; 
+        if ($item->{delayedid}) {
+            $entry_obj = LJ::DelayedEntry->get_entry_by_id($u, $item->{delayedid});
+        } else {
+            $entry_obj = LJ::Entry->new($u, ditemid => $ditemid);
+        }
+        
+        if (!$entry_obj->is_delayed()) {
+            $entry_obj->handle_prefetched_props($logprops{$itemid});
+        }
 
         # don't show posts from suspended users or suspended posts
         my $pu = $pu{$posterid};
@@ -124,10 +139,14 @@
         }
 
 
-	if ($LJ::UNICODE && $logprops{$itemid}->{'unknown8bit'}) {
-            my $text;
-	    LJ::item_toutf8($u, \$subject, \$text, $logprops{$itemid});
-	}
+        if ($LJ::UNICODE && $logprops{$itemid}->{'unknown8bit'}) {
+                my $text;
+            LJ::item_toutf8($u, \$subject, \$text, $logprops{$itemid});
+        }
+        
+        if ($entry_obj->is_delayed) {
+            $subject = $entry_obj->subject;
+        }
 
         if ($opt_text_subjects) {
             LJ::CleanHTML::clean_subject_all(\$subject);
@@ -137,7 +156,7 @@
 
         my $nc = "";
         $nc .= "nc=$replycount" if $replycount && $remote && $remote->{'opt_nctalklinks'};
-        my $permalink = "$journalbase/$ditemid.html";
+        my $permalink = $entry_obj->is_delayed ? $entry_obj->url : "$journalbase/$ditemid.html";
         my $readurl = $permalink;
         $readurl .= "?$nc" if $nc;
         my $posturl = $permalink . "?mode=reply";

Modified: branches/delayed_entries/cgi-bin/LJ/S2.pm
===================================================================
--- branches/delayed_entries/cgi-bin/LJ/S2.pm	2011-08-18 13:01:21 UTC (rev 19775)
+++ branches/delayed_entries/cgi-bin/LJ/S2.pm	2011-08-18 13:17:46 UTC (rev 19776)
@@ -1819,14 +1819,13 @@
 {
     my ($u, $kwid, $kw) = @_;
     return undef unless $u && $kwid && $kw;
-
+    
     my $t = {
         _type => 'Tag',
         _id => $kwid,
         name => LJ::ehtml($kw),
         url => LJ::journal_base($u) . '/tag/' . LJ::eurl($kw),
     };
-
     return $t;
 }
 
@@ -1863,7 +1862,7 @@
         'metadata' => {},
     };
     foreach (qw(subject text journal poster new_day end_day
-                comments userpic permalink_url itemid tags)) {
+                comments userpic permalink_url itemid tags delayedid )) {
         $e->{$_} = $arg->{$_};
     }
 
@@ -1960,19 +1959,29 @@
         }
     }
 
-    # custom friend groups
-    my $entry = LJ::Entry->new($e->{journal}->{_u}, ditemid => $e->{itemid});
-    my $group_names = $entry->group_names;
-    $e->{metadata}->{groups} = $group_names if $group_names;
+    if (!$e->{delayedid}) {
+        # custom friend groups
+        my $entry = LJ::Entry->new($e->{journal}->{_u}, ditemid => $e->{itemid});
+        my $group_names = $entry->group_names;
+        $e->{metadata}->{groups} = $group_names if $group_names;
 
-    # TODO: Populate this field more intelligently later, but for now this will
-    #   hopefully disuade people from hardcoding logic like this into their S2
-    #   layers when they do weird parsing/manipulation of the text member in
-    #   untrusted layers.
-    $e->{text_must_print_trusted} = 1 if $e->{text} =~ m!<(script|object|applet|embed|iframe)\b!i;
+        # TODO: Populate this field more intelligently later, but for now this will
+        #   hopefully disuade people from hardcoding logic like this into their S2
+        #   layers when they do weird parsing/manipulation of the text member in
+        #   untrusted layers.
+        $e->{text_must_print_trusted} = 1 if $e->{text} =~ m!<(script|object|applet|embed|iframe)\b!i;
+            
+        if ($entry->is_sticky()) {
+           $e->{'sticky_icon'} = Image_std("sticky-entry");
+        }
+    } else {
+        my $entry = LJ::DelayedEntry->get_entry_by_id( $e->{journal}->{_u}, 
+                                                        $e->{delayedid} );
+        if ( $entry->is_sticky) {
+            $e->{'sticky_icon'} = Image_std("sticky-entry");
+        }
 
-    if ($entry->is_sticky()) {
-       $e->{'sticky_icon'} = Image_std("sticky-entry");
+        $e->{'delayed_icon'} = Image_std("delayed-entry");
     }
 
     return $e;
@@ -2113,7 +2122,8 @@
             'security-protected' => Image("$LJ::IMGPREFIX/icon_protected.gif", 14, 15, $ctx->[S2::PROPS]->{'text_icon_alt_protected'}),
             'security-private' => Image("$LJ::IMGPREFIX/icon_private.gif", 16, 16, $ctx->[S2::PROPS]->{'text_icon_alt_private'}),
             'security-groups' => Image("$LJ::IMGPREFIX/icon_groups.gif", 19, 16, $ctx->[S2::PROPS]->{'text_icon_alt_groups'}),
-            'sticky-entry' => Image("$LJ::IMGPREFIX/icon_sticky.gif", 19, 16, $ctx->[S2::PROPS]->{'text_icon_alt_sticky'}),
+            'sticky-entry' => Image("$LJ::IMGPREFIX/icon_sticky.gif", 11, 15, $ctx->[S2::PROPS]->{'text_icon_alt_sticky'}),
+            'delayed-entry' => Image("$LJ::IMGPREFIX/icon_delayed.gif", 11, 15, $ctx->[S2::PROPS]->{'text_icon_alt_delayed'}),
         };
     }
     return $LJ::S2::RES_CACHE->{$name};
@@ -3768,6 +3778,7 @@
     my $remote = LJ::get_remote();
     my $is_remote = defined($remote) && $remote->{userid} eq $u->{userid};
     my $has_journal = $u->{journaltype} ne 'I';
+    my $null_link = { '_type' => 'Link', '_isnull' => 1 };
 
     my $button = sub {
         return LJ::S2::Link($_[0], $_[1], LJ::S2::Image("$LJ::IMGPREFIX/$_[2]", 24, 24));
@@ -3803,7 +3814,7 @@
     }
 
     # Else?
-    return undef;
+    return $null_link;
 }
 *User__get_link = \&UserLite__get_link;
 
@@ -3871,24 +3882,45 @@
     my $remote = LJ::get_remote();
     my $null_link = { '_type' => 'Link', '_isnull' => 1 };
     my $journalu = LJ::load_user($journal);
-    my $entry = LJ::Entry->new($journalu, ditemid => $this->{itemid});
+    my $entry;
 
+    if ( $this->{itemid} ) {
+        $entry = LJ::Entry->new($journalu, ditemid => $this->{itemid});
+    } else {
+        $entry = LJ::DelayedEntry->get_entry_by_id($journalu, $this->{delayedid});
+    }
+
     if ($key eq "edit_entry") {
         return $null_link unless $remote &&
                                     ( LJ::u_equals( $remote, $journalu ) ||
                                       LJ::u_equals( $remote, $posteru ) ||
                                       $remote->can_manage($journalu)
                                     );
-        return LJ::S2::Link("$LJ::SITEROOT/editjournal.bml?journal=$journal&amp;itemid=$this->{'itemid'}",
+        
+        if ($entry->is_delayed) {
+            return LJ::S2::Link("$LJ::SITEROOT/editjournal.bml?journal=$journal&amp;delayedid=" . $entry->delayedid,
+                        $ctx->[S2::PROPS]->{"text_edit_entry"},
+                        LJ::S2::Image("$LJ::IMGPREFIX/btn_edit.gif", 24, 24));  
+        } else {
+            return LJ::S2::Link("$LJ::SITEROOT/editjournal.bml?journal=$journal&amp;itemid=$this->{'itemid'}",
                             $ctx->[S2::PROPS]->{"text_edit_entry"},
                             LJ::S2::Image("$LJ::IMGPREFIX/btn_edit.gif", 24, 24));
+        }
     }
 
     if ($key eq "edit_tags") {
-        return $null_link unless $remote && LJ::Tags::can_add_entry_tags($remote, $entry);
-        return LJ::S2::Link("$LJ::SITEROOT/edittags.bml?journal=$journal&amp;itemid=$this->{'itemid'}",
+        return $null_link 
+            unless $remote && LJ::Tags::can_add_entry_tags( $remote, $entry );
+        if ($entry->is_delayed) {
+            return LJ::S2::Link("$LJ::SITEROOT/edittags.bml?journal=$journal&amp;delayedid=" . $entry->delayedid,
+                                $ctx->[S2::PROPS]->{"text_edit_tags"},
+                                LJ::S2::Image("$LJ::IMGPREFIX/btn_edittags.gif", 24, 24));
+
+        } else {
+            return LJ::S2::Link("$LJ::SITEROOT/edittags.bml?journal=$journal&amp;itemid=$this->{'itemid'}",
                             $ctx->[S2::PROPS]->{"text_edit_tags"},
                             LJ::S2::Image("$LJ::IMGPREFIX/btn_edittags.gif", 24, 24));
+        }
     }
 
     if ($key eq "tell_friend") {
@@ -3896,7 +3928,8 @@
         return $null_link;
     }
 
-    if ( $key eq 'share' ) {
+    if ( $key eq 'share') {
+        return $null_link if $entry->is_delayed;
         return $null_link
             unless LJ::is_enabled('sharing') && $entry->is_public;
 
@@ -3911,6 +3944,8 @@
     }
 
     if ($key eq "share_facebook") {
+        return $null_link if $entry->is_delayed;
+
         my $entry = LJ::Entry->new($journalu->{'userid'}, ditemid => $this->{'itemid'});
         return $null_link unless $entry->security eq 'public';
         my $entry_url = LJ::eurl($entry->url);
@@ -3920,6 +3955,8 @@
     }
 
     if ($key eq "share_twitter") {
+        return $null_link if $entry->is_delayed;
+
         my $entry = LJ::Entry->new($journalu->{'userid'}, ditemid => $this->{'itemid'});
         return $null_link unless $entry->security eq 'public';
         my $post_id = $entry->journalid . ':' . $entry->ditemid;
@@ -3930,6 +3967,8 @@
     }
 
     if ($key eq "share_email") {
+        return $null_link if $entry->is_delayed;
+
         my $entry = LJ::Entry->new($journalu->{'userid'}, ditemid => $this->{'itemid'});
         return $null_link unless $entry->security eq 'public';
         my $entry_url = LJ::eurl($entry->url);
@@ -3940,6 +3979,8 @@
     }
 
     if ($key eq "facebook_like") {
+        return $null_link if $entry->is_delayed;
+
         my $entry = LJ::Entry->new($journalu->{'userid'}, ditemid => $this->{'itemid'});
         return $null_link unless $entry->security eq 'public';
         my $entry_url = LJ::eurl($entry->url);
@@ -3950,6 +3991,7 @@
     }
 
     if ($key eq "mem_add") {
+        return $null_link if $entry->is_delayed;
         return $null_link if $LJ::DISABLED{'memories'};
         return LJ::S2::Link("$LJ::SITEROOT/tools/memadd.bml?journal=$journal&amp;itemid=$this->{'itemid'}",
                             $ctx->[S2::PROPS]->{"text_mem_add"},
@@ -3957,7 +3999,14 @@
     }
 
     if ($key eq "nav_prev") {
-        my $jumpid = LJ::get_itemid_before2($journalu, int($this->{'itemid'}/256));
+        my $jumpid;
+        if ($entry->is_delayed) {
+            my $nextid = $entry->get_itemid_before2();
+            return $null_link unless $nextid;
+            $jumpid = "d" . $nextid;
+        } else {
+            $jumpid = LJ::get_itemid_before2($journalu, int($this->{'itemid'}/256));
+        }
         if ($jumpid) {
             return LJ::S2::Link($journalu->journal_base . "/$jumpid.html",
                             $ctx->[S2::PROPS]->{"text_entry_prev"},
@@ -3968,7 +4017,16 @@
     }
 
     if ($key eq "nav_next") {
-        my $jumpid = LJ::get_itemid_after2($journalu, int($this->{'itemid'}/256));
+        my $jumpid;
+        if ($entry->is_delayed) {
+            my $nextid = $entry->get_itemid_after2();
+            return $null_link unless $nextid;
+
+            $jumpid = "d" . $nextid;
+        } else {
+            $jumpid = LJ::get_itemid_after2($journalu, int($this->{'itemid'}/256));
+        }
+        
         if ($jumpid) {
             return LJ::S2::Link($journalu->journal_base . "/$jumpid.html",,
                             $ctx->[S2::PROPS]->{"text_entry_next"},
@@ -3979,8 +4037,8 @@
     }
 
     if ($key eq "flag") {
+        return $null_link if $entry->is_delayed;
         return $null_link unless LJ::is_enabled("content_flag");
-
         return $null_link unless $remote && $remote->can_see_content_flag_button( content => $entry );
         return LJ::S2::Link(LJ::ContentFlag->adult_flag_url($entry),
                             $ctx->[S2::PROPS]->{"text_flag"},
@@ -4005,17 +4063,16 @@
     if ($newentry_sub) {
         $newentry_auth_token = LJ::Auth->ajax_auth_token($remote, '/__rpc_esn_subs',
                                                          subid     => $newentry_sub->id,
-                                                         action    => 'delsub',
-                                                         );
+                                                         action    => 'delsub',);
     } elsif ($remote) {
         $newentry_auth_token = LJ::Auth->ajax_auth_token($remote, '/__rpc_esn_subs',
                                                          journalid => $journalu->id,
                                                          action    => 'addsub',
-                                                         etypeid   => $newentry_etypeid,
-                                                         );
+                                                         etypeid   => $newentry_etypeid,);
     }
 
     if ($key eq "watch_comments") {
+        return $null_link if $entry->is_delayed;
         return $null_link if $LJ::DISABLED{'esn'};
         return $null_link unless $remote && $remote->can_use_esn;
         return $null_link if $remote->has_subscription(
@@ -4047,6 +4104,7 @@
                                           'class'               => 'TrackButton'));
     }
     if ($key eq "unwatch_comments") {
+        return $null_link if $entry->is_delayed;
         return $null_link if $LJ::DISABLED{'esn'};
         return $null_link unless $remote && $remote->can_use_esn;
         my @subs = $remote->has_subscription(
@@ -4076,6 +4134,8 @@
                                           'lj_newentry_subid'   => $newentry_sub ? $newentry_sub->id : 0,
                                           'class'               => 'TrackButton'));
     }
+    
+    return $null_link;
 }
 
 sub EntryLite__print_give_button
@@ -4402,7 +4462,7 @@
             1;
         };
 
-        return [] unless $parse_result;
+        return unless $parse_result;
     } else {
         $tags = LJ::Tags::get_usertags($u, { remote => $remote });
     }

Tags: livejournal, madeon, pm
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