madeon (madeon) wrote in changelog,
madeon
madeon
changelog

[livejournal] r21930: LJSUP-12150: New Repost feature (S2)

Committer: sbelyaev
LJSUP-12150: New Repost feature (S2)
U   trunk/bin/upgrading/s2layers/core1.s2
U   trunk/cgi-bin/LJ/S2/DayPage.pm
U   trunk/cgi-bin/LJ/S2/FriendsPage.pm
U   trunk/cgi-bin/LJ/S2/MonthPage.pm
U   trunk/cgi-bin/LJ/S2/RecentPage.pm
U   trunk/cgi-bin/LJ/S2.pm
Modified: trunk/bin/upgrading/s2layers/core1.s2
===================================================================
--- trunk/bin/upgrading/s2layers/core1.s2	2012-05-12 09:33:19 UTC (rev 21929)
+++ trunk/bin/upgrading/s2layers/core1.s2	2012-05-12 09:40:58 UTC (rev 21930)
@@ -1499,6 +1499,11 @@
 }
 set text_permalink = "Link";
 
+property string text_delete_repost {
+    des = "Text to delete repost link";
+}
+set text_delete_repost = "Delete repost";
+
 property string text_edit_entry {
     des = "Text to edit an entry";
 }

Modified: trunk/cgi-bin/LJ/S2/DayPage.pm
===================================================================
--- trunk/cgi-bin/LJ/S2/DayPage.pm	2012-05-12 09:33:19 UTC (rev 21929)
+++ trunk/cgi-bin/LJ/S2/DayPage.pm	2012-05-12 09:40:58 UTC (rev 21930)
@@ -6,6 +6,7 @@
 
 use LJ::TimeUtil;
 use LJ::UserApps;
+use LJ::Entry::Repost;
 
 sub DayPage
 {
@@ -118,11 +119,11 @@
         my ($posterid, $itemid, $security, $allowmask, $alldatepart, $anum) =
             map { $item->{$_} } qw(posterid itemid security allowmask alldatepart anum);
 
+        my $journalu = $u;
         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'} || 0;
         my $subject = $logtext->{$itemid}->[0];
         my $text = $logtext->{$itemid}->[1];
@@ -133,6 +134,37 @@
             $text    =~ s{<(?!/?lj)(.*?)>} {&lt;$1&gt;}gi;
         }
 
+        my $repost_entry_obj;
+        my $lite_journalu =  $userlite_journal;
+
+        my $content =  { 'original_post_obj' => \$entry_obj,
+                         'repost_obj'        => \$repost_entry_obj,
+                         'ditemid'           => \$ditemid,
+                         'journalu'          => \$journalu,
+                         'posterid'          => \$posterid,
+                         'security'          => \$security,
+                         'allowmask'         => \$allowmask,
+                         'event'             => \$text,
+                         'subject'           => \$subject,
+                         'reply_count'       => \$replycount,
+                         'userlite'          => \$lite_journalu, };
+
+        if (LJ::Entry::Repost->substitute_content( $entry_obj, $content )) {
+            next ENTRY unless $entry_obj->visible_to($remote, { 'viewall'  => $viewall,
+                                                                'viewsome' => $viewsome});
+
+            $logprops{$itemid} = $entry_obj->props;
+
+            $lite_journalu = UserLite($entry_obj->journal);
+
+            $apu_lite{$entry_obj->journalid} = $lite_journalu;
+            $apu{$entry_obj->journalid} = $entry_obj->journal;
+            if (!$apu_lite{$posterid} || !$apu{$posterid}) {
+                $apu_lite{$posterid} = UserLite($entry_obj->poster);
+                $apu{$posterid} = $entry_obj->poster; 
+            }
+        }
+
         # don't show posts from suspended users or suspended posts
         my $pu = $apu{$posterid};
         next ENTRY if $pu && $pu->{'statusvis'} eq 'S' && ! $viewsome;
@@ -148,7 +180,7 @@
         }
 
         if ($LJ::UNICODE && $logprops{$itemid}->{'unknown8bit'}) {
-            LJ::item_toutf8($u, \$subject, \$text, $logprops{$itemid});
+            LJ::item_toutf8($journalu, \$subject, \$text, $logprops{$itemid});
         }
 
         LJ::CleanHTML::clean_subject(\$subject) if $subject;
@@ -170,7 +202,7 @@
         );
 
         LJ::expand_embedded(
-            $u,
+            $journalu,
             $ditemid,
             $remote,
             \$text,
@@ -187,7 +219,7 @@
         my $nc = "";
         $nc .= "nc=$replycount" if $replycount && $remote && $remote->{'opt_nctalklinks'};
 
-        my $permalink = "$journalbase/$ditemid.html";
+        my $permalink = $entry_obj->url;
         my $readurl = $permalink;
         $readurl .= "?$nc" if $nc;
         my $posturl = $permalink . "?mode=reply";
@@ -217,7 +249,7 @@
 
         my @taglist;
         while (my ($kwid, $kw) = each %{$tags->{$itemid} || {}}) {
-            push @taglist, Tag($u, $kwid => $kw);
+            push @taglist, Tag($journalu, $kwid => $kw);
         }
         @taglist = sort { $a->{name} cmp $b->{name} } @taglist;
 
@@ -233,7 +265,7 @@
             }
         }
 
-        my $entry = Entry($u, {
+        my $entry = Entry($journalu, {
             'subject' => $subject,
             'text' => $text,
             'dateparts' => $alldatepart,
@@ -242,12 +274,15 @@
             'allowmask' => $allowmask,
             'props' => $logprops{$itemid},
             'itemid' => $ditemid,
-            'journal' => $userlite_journal,
+            'journal' => $lite_journalu,
             'poster' => $userlite_poster,
             'comments' => $comments,
             'tags' => \@taglist,
             'userpic' => $userpic,
             'permalink_url' => $permalink,
+            'real_journalid' => $repost_entry_obj ? $repost_entry_obj->journalid : undef,
+            'real_itemid'    => $repost_entry_obj ? $repost_entry_obj->jitemid : undef,
+
         });
 
         push @{$p->{'entries'}}, $entry;

Modified: trunk/cgi-bin/LJ/S2/FriendsPage.pm
===================================================================
--- trunk/cgi-bin/LJ/S2/FriendsPage.pm	2012-05-12 09:33:19 UTC (rev 21929)
+++ trunk/cgi-bin/LJ/S2/FriendsPage.pm	2012-05-12 09:40:58 UTC (rev 21930)
@@ -7,6 +7,7 @@
 use LJ::Request;
 use LJ::TimeUtil;
 use LJ::UserApps;
+use LJ::Entry::Repost;
 
 sub FriendsPage
 {
@@ -259,7 +260,30 @@
 
         my $ditemid = $itemid * 256 + $item->{'anum'};
         my $entry_obj = LJ::Entry->new($friends{$friendid}, ditemid => $ditemid);
+        my $repost_entry_obj;
+        
+        my $content =  { 'original_post_obj' => \$entry_obj,
+                         'repost_obj'        => \$repost_entry_obj,
+                         'ditemid'           => \$ditemid,
+                         'itemid'            => \$itemid,
+                         'journalid'         => \$friendid,
+                         'posterid'          => \$posterid,
+                         'security'          => \$security,
+                         'allowmask'         => \$allowmask,
+                         'event_friend'      => \$text,
+                         'subject'           => \$subject,
+                         'reply_count'       => \$replycount, };
 
+        if (LJ::Entry::Repost->substitute_content( $entry_obj, $content )) {
+            next ENTRY unless $entry_obj->visible_to($remote);
+
+            $friend   = $poster = $entry_obj->journal;
+
+            $posters{$posterid} = $poster;
+            $friends{$friendid} = $friend;
+            $datakey   = "$friendid $itemid";
+        }
+
         if ( $remote && $logprops{$datakey}->{'repost'} && $remote->prop('hidefriendsreposts') && ! $remote->prop('opt_ljcut_disable_friends') ) {
             $text = LJ::Lang::ml(
                 'friendsposts.reposted',

Modified: trunk/cgi-bin/LJ/S2/MonthPage.pm
===================================================================
--- trunk/cgi-bin/LJ/S2/MonthPage.pm	2012-05-12 09:33:19 UTC (rev 21929)
+++ trunk/cgi-bin/LJ/S2/MonthPage.pm	2012-05-12 09:40:58 UTC (rev 21930)
@@ -7,6 +7,7 @@
 use LJ::TimeUtil;
 use LJ::UserApps;
 use LJ::DelayedEntry;
+use LJ::Entry::Repost;
 
 sub MonthPage
 {
@@ -106,11 +107,34 @@
             map { $item->{$_} } qw(posterid jitemid security allowmask alldatepart replycount anum);
         my $subject = $lt->{$itemid}->[0];
         my $day = $item->{'day'};
+        my $journalu = $u;
 
         my $ditemid = $itemid*256 + $anum;
         my $entry_obj  = LJ::Entry->new($u, ditemid => $ditemid);
         $entry_obj->handle_prefetched_props($logprops{$itemid}); 
 
+        my $repost_entry_obj;
+        my $lite_journalu = $userlite_journal;
+
+        my $content =  { 'original_post_obj' => \$entry_obj,
+                         'repost_obj'        => \$repost_entry_obj,
+                         'ditemid'           => \$ditemid,
+                         'itemid'            => \$itemid,
+                         'journalu'          => \$journalu,                        
+                         'posterid'          => \$posterid,
+                         'security'          => \$security,
+                         'allowmask'         => \$allowmask,
+                         'subject_repost'    => \$subject,
+                         'reply_count'       => \$replycount, };
+
+        if (LJ::Entry::Repost->substitute_content( $entry_obj, $content )) {
+            next ENTRY unless $entry_obj->visible_to($remote);
+
+            $pu{$posterid} = $entry_obj->poster;
+            $lite_journalu =  UserLite($entry_obj->journal);
+            $pu_lite{$posterid} = UserLite($entry_obj->poster);
+        }
+
         # don't show posts from suspended users or suspended posts
         my $pu = $pu{$posterid};
         next unless $pu;
@@ -125,10 +149,9 @@
             next ENTRY if $purge_community_entries;
         }
 
-
         if ($LJ::UNICODE && $logprops{$itemid}->{'unknown8bit'}) {
                 my $text;
-            LJ::item_toutf8($u, \$subject, \$text, $logprops{$itemid});
+            LJ::item_toutf8($journalu, \$subject, \$text, $logprops{$itemid});
         }
         
         if ($opt_text_subjects) {
@@ -139,7 +162,7 @@
 
         my $nc = "";
         $nc .= "nc=$replycount" if $replycount && $remote && $remote->{'opt_nctalklinks'};
-        my $permalink = "$journalbase/$ditemid.html";
+        my $permalink = $entry_obj->url;
         my $readurl = $permalink;
         $readurl .= "?$nc" if $nc;
         my $posturl = $permalink . "?mode=reply";
@@ -148,14 +171,14 @@
             'read_url' => $readurl,
             'post_url' => $posturl,
             'count' => $replycount,
-            'maxcomments' => ($replycount >= LJ::get_cap($u, 'maxcomments')) ? 1 : 0,
+            'maxcomments' => ($replycount >= LJ::get_cap($journalu, 'maxcomments')) ? 1 : 0,
             'enabled' => $entry_obj->comments_shown,
             'locked' => !$entry_obj->posting_comments_allowed,
             'screened' => ($logprops{$itemid}->{'hasscreened'} && $remote &&
-                           ($remote->{'user'} eq $u->{'user'} || $remote->can_manage($u))) ? 1 : 0,
+                           ($remote->user eq $journalu->user || $remote->can_manage($journalu))) ? 1 : 0,
         });
 
-        my $userlite_poster = $userlite_journal;
+        my $userlite_poster = $lite_journalu;
         my $userpic = $p->{'journal'}->{'default_pic'};
         if ($u->{'userid'} != $posterid) {
             $userlite_poster = $pu_lite{$posterid};
@@ -163,7 +186,7 @@
             $userpic = Image_userpic($pu{$posterid}, 0, $pickw);
         }
 
-        my $entry = Entry($u, {
+        my $entry = Entry($journalu, {
             'subject' => $subject,
             'text' => "",
             'dateparts' => $alldatepart,
@@ -172,11 +195,13 @@
             'allowmask' => $allowmask,
             'props' => $logprops{$itemid},
             'itemid' => $ditemid,
-            'journal' => $userlite_journal,
+            'journal' => $lite_journalu,
             'poster' => $userlite_poster,
             'comments' => $comments,
             'userpic' => $userpic,
             'permalink_url' => $permalink,
+            'original_journalid' => $repost_entry_obj ? $repost_entry_obj->journalid : undef,
+            'original_itemid'    => $repost_entry_obj ? $repost_entry_obj->jitemid : undef,
         });
 
         push @{$day_entries{$day}}, $entry;

Modified: trunk/cgi-bin/LJ/S2/RecentPage.pm
===================================================================
--- trunk/cgi-bin/LJ/S2/RecentPage.pm	2012-05-12 09:33:19 UTC (rev 21929)
+++ trunk/cgi-bin/LJ/S2/RecentPage.pm	2012-05-12 09:40:58 UTC (rev 21930)
@@ -2,6 +2,7 @@
 package LJ::S2;
 
 use LJ::DelayedEntry;
+use LJ::Entry::Repost;
 use LJ::UserApps;
 
 sub RecentPage
@@ -149,16 +150,48 @@
         my ($posterid, $itemid, $security, $allowmask, $alldatepart) =
             map { $item->{$_} } qw(posterid itemid security allowmask alldatepart);
 
+        my $journalu      = $u;
+        my $lite_journalu = $userlite_journal;
+
         my $ditemid   = $itemid * 256 + $item->{'anum'};
         my $entry_obj = LJ::Entry->new($u, ditemid => $ditemid);
+       
+        my $repost_entry_obj; 
 
-        next ENTRY unless $entry_obj->visible_to($remote, {'viewall' => $viewall, 'viewsome' => $viewsome});
+        next ENTRY unless $entry_obj->visible_to($remote, { 'viewall'  => $viewall, 
+                                                            'viewsome' => $viewsome});
 
         $entry_obj->handle_prefetched_props($logprops{$itemid});
         my $replycount = $logprops{$itemid}->{'replycount'};
+
         my $subject    = $logtext->{$itemid}->[0];
         my $text       = $logtext->{$itemid}->[1];
 
+        my $content =  { 'original_post_obj' => \$entry_obj,
+                         'repost_obj'        => \$repost_entry_obj,
+                         'ditemid'           => \$ditemid,
+                         'journalu'          => \$journalu,
+                         'posterid'          => \$posterid,
+                         'security'          => \$security,
+                         'allowmask'         => \$allowmask,
+                         'event'             => \$text,
+                         'subject'           => \$subject,
+                         'reply_count'       => \$replycount,
+                         'userlite'          => \$lite_journalu, };
+
+        if (LJ::Entry::Repost->substitute_content( $entry_obj, $content )) {        
+            next ENTRY unless $entry_obj->visible_to($remote, { 'viewall'  => $viewall,
+                                                                'viewsome' => $viewsome});
+
+            $logprops{$itemid} = $entry_obj->props;
+
+            $lite_journalu = UserLite($entry_obj->journal);
+            $apu_lite{$entry_obj->journalid} = $lite_journalu;
+            if (!$apu_lite{$posterid}) {
+                $apu_lite{$posterid} = UserLite($entry_obj->poster);
+            }
+        }
+
         if ( $get->{'nohtml'} ) {
             # quote all non-LJ tags
             $subject =~ s{<(?!/?lj)(.*?)>} {&lt;$1&gt;}gi;
@@ -168,7 +201,7 @@
         $itemnum++;
 
         if ($LJ::UNICODE && $logprops{$itemid}->{'unknown8bit'}) {
-            LJ::item_toutf8($u, \$subject, \$text, $logprops{$itemid});
+            LJ::item_toutf8($journalu, \$subject, \$text, $logprops{$itemid});
         }
 
         my $date = substr($alldatepart, 0, 10);
@@ -199,7 +232,7 @@
         );
 
         LJ::expand_embedded(
-            $u,
+            $journalu,
             $ditemid,
             $remote,
             \$text,
@@ -208,16 +241,16 @@
 
         $text = LJ::ContentFlag->transform_post(
             'post'    => $text,
-            'journal' => $u,
+            'journal' => $journalu,
             'remote'  => $remote,
             'entry'   => $entry_obj,
         );
 
         my @taglist;
-        while (my ($kwid, $kw) = each %{$tags->{"$u->{userid} $itemid"} || {}}) {
-            push @taglist, Tag($u, $kwid => $kw);
+        while (my ($kwid, $kw) = each %{$tags->{"$journalu->{userid} $itemid"} || {}}) {
+            push @taglist, Tag($journalu, $kwid => $kw);
         }
-        LJ::run_hooks('augment_s2_tag_list', u => $u, jitemid => $itemid, tag_list => \@taglist);
+        LJ::run_hooks('augment_s2_tag_list', u => $journalu, jitemid => $itemid, tag_list => \@taglist);
         @taglist = sort { $a->{name} cmp $b->{name} } @taglist;
 
         if ($opts->{enable_tags_compatibility} && @taglist) {
@@ -227,12 +260,12 @@
         my $nc = "";
         $nc .= "nc=$replycount" if $replycount && $remote && $remote->prop('opt_nctalklinks');
 
-        my $permalink = "$journalbase/$ditemid.html";
+        my $permalink = $entry_obj->url;
         my $readurl = $permalink;
         $readurl .= "?$nc" if $nc;
         my $posturl = $permalink . "?mode=reply";
 
-        my $has_screened = ($logprops{$itemid}->{'hasscreened'} && $remote && $remote->can_manage($u)) ? 1 : 0;
+        my $has_screened = ($logprops{$itemid}->{'hasscreened'} && $remote && $remote->can_manage($journalu)) ? 1 : 0;
 
         my $comments = CommentInfo({
             'read_url' => $readurl,
@@ -246,9 +279,9 @@
             'show_postlink' => $entry_obj->posting_comments_allowed,
         });
 
-        my $userlite_poster = $userlite_journal;
-        my $pu = $u;
-        if ($u->{'userid'} != $posterid) {
+        my $userlite_poster = $lite_journalu;
+        my $pu = $journalu;
+        if ($journalu->userid != $posterid) {
             $userlite_poster = $apu_lite{$posterid} or die "No apu_lite for posterid=$posterid";
             $pu = $apu{$posterid};
         }
@@ -263,7 +296,7 @@
             }
         }
 
-        my $entry = $lastentry = Entry($u, {
+        my $entry = $lastentry = Entry($journalu, {
             'subject' => $subject,
             'text' => $text,
             'dateparts' => $alldatepart,
@@ -272,14 +305,16 @@
             'allowmask' => $allowmask,
             'props' => $logprops{$itemid},
             'itemid' => $ditemid,
-            'journal' => $userlite_journal,
-            'poster' => $userlite_poster,
+            'journal' => $lite_journalu,
+            'poster'  => $userlite_poster,
             'comments' => $comments,
             'new_day' => $new_day,
             'end_day' => 0,   # if true, set later
             'tags' => \@taglist,
             'userpic' => $userpic,
             'permalink_url' => $permalink,
+            'real_journalid' => $repost_entry_obj ? $repost_entry_obj->journalid : undef,
+            'real_itemid'    => $repost_entry_obj ? $repost_entry_obj->jitemid : undef,
         });
         
         push @{$p->{'entries'}}, $entry;

Modified: trunk/cgi-bin/LJ/S2.pm
===================================================================
--- trunk/cgi-bin/LJ/S2.pm	2012-05-12 09:33:19 UTC (rev 21929)
+++ trunk/cgi-bin/LJ/S2.pm	2012-05-12 09:40:58 UTC (rev 21930)
@@ -1944,7 +1944,8 @@
     };
 
     foreach (qw(subject text journal poster new_day end_day
-                comments userpic permalink_url itemid tags delayedid )) {
+                comments userpic permalink_url itemid tags delayedid 
+                real_journalid real_itemid )) {
         $e->{$_} = $arg->{$_};
     }
 
@@ -1957,6 +1958,7 @@
     $e->{'depth'} = 0;  # Entries are always depth 0.  Comments are 1+.
 
     my $link_keyseq = $e->{'link_keyseq'};
+    push @$link_keyseq, 'delete_reference'  if LJ::is_enabled('entry_reference');
     push @$link_keyseq, 'mem_add'           if LJ::is_enabled('memories');
     push @$link_keyseq, 'tell_friend'       if LJ::is_enabled('tellafriend');
     push @$link_keyseq, 'share'             if LJ::is_enabled('sharing');
@@ -3981,9 +3983,22 @@
     my $posteru  = $this->{'poster'}->{'_u'};
     my $remote = LJ::get_remote();
     my $null_link = { '_type' => 'Link', '_isnull' => 1 };
-    my $journalu = LJ::load_user($journal);
+    my $journalu      = LJ::load_user($journal);
+    my $real_user = $this->{'real_journalid'} ? LJ::want_user($this->{'real_journalid'}) : undef;
 
+    if ($this->{'real_itemid'}) {
+        if ($key eq 'delete_reference') {
+            return $null_link unless $remote;
+            return $null_link unless LJ::u_equals($remote, $real_user);
+
+            return LJ::S2::Link("$LJ::SITEROOT/$this->{'real_itemid'}",
+                            $ctx->[S2::PROPS]->{"text_delete_repost"},
+                            LJ::S2::Image("$LJ::IMGPREFIX/btn_delete_repost.gif", 24, 24));
+        }
+    }
+
     if ($key eq "edit_entry") {
+        return $null_link if (LJ::is_enabled('entry_reference') && $this->{'real_itemid'});
         return $null_link unless $remote &&
                                     ( LJ::u_equals( $remote, $journalu ) ||
                                       LJ::u_equals( $remote, $posteru ) ||
@@ -4005,6 +4020,7 @@
     return $null_link if $this->{delayed};
 
     if ($key eq "edit_tags") {
+        return $null_link if (LJ::is_enabled('entry_reference') && $this->{'real_itemid'});
         my $entry = LJ::Entry->new($journalu->{'userid'}, ditemid => $this->{'itemid'});
 
         return $null_link 

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