madeon (madeon) wrote in changelog,
madeon
madeon
changelog

[livejournal] r19533: LJSUP-9307: sticky entry prototype.

Committer: sbelyaev
LJSUP-9307: sticky entry prototype.
U   branches/delayed_entries/bin/upgrading/proplists.dat
U   branches/delayed_entries/bin/upgrading/s2layers/core1.s2
U   branches/delayed_entries/cgi-bin/LJ/Entry.pm
U   branches/delayed_entries/cgi-bin/LJ/S2.pm
U   branches/delayed_entries/cgi-bin/LJ/User.pm
U   branches/delayed_entries/cgi-bin/LJ/Widget/EntryForm.pm
U   branches/delayed_entries/cgi-bin/ljfeed.pl
U   branches/delayed_entries/cgi-bin/ljlib.pl
U   branches/delayed_entries/cgi-bin/ljprotocol.pl
U   branches/delayed_entries/htdocs/editjournal.bml
U   branches/delayed_entries/htdocs/editjournal.bml.text
U   branches/delayed_entries/htdocs/update.bml
U   branches/delayed_entries/htdocs/update.bml.text
Modified: branches/delayed_entries/bin/upgrading/proplists.dat
===================================================================
--- branches/delayed_entries/bin/upgrading/proplists.dat	2011-07-27 03:01:18 UTC (rev 19532)
+++ branches/delayed_entries/bin/upgrading/proplists.dat	2011-07-27 03:25:33 UTC (rev 19533)
@@ -1694,3 +1694,10 @@
   indexed: 0
   multihomed: 1
   cldversion: 8
+
+userproplist.sticky_entries:
+  datatype: char
+  des: Sticky entries ids
+  indexed: 0
+  prettyname: Sticky enries
+

Modified: branches/delayed_entries/bin/upgrading/s2layers/core1.s2
===================================================================
--- branches/delayed_entries/bin/upgrading/s2layers/core1.s2	2011-07-27 03:01:18 UTC (rev 19532)
+++ branches/delayed_entries/bin/upgrading/s2layers/core1.s2	2011-07-27 03:25:33 UTC (rev 19533)
@@ -350,6 +350,7 @@
 {
     var readonly string security "The security level of the entry ('private', 'protected'), or blank if public.";
     var Image security_icon "A little icon which should be displayed somewhere on an entry to represent the security setting";
+    var Image sticky_icon "A little icon which should be displyaed somewhere on an entry to represent the sticky setting";
 
     var Image mood_icon "Mood icon, or null.";
     var CommentInfo comments "Comment information on this entry";
@@ -2521,7 +2522,7 @@
 function Page::print_entry(Entry e) {
     ## For most styles, this will be overridden by FriendsPage::print_entry and such.
     """<div class="entry" id="$e.dom_id">\n""";
-    "<h3>$e.security_icon $e.subject</h3>\n";
+    "<h3>$e.sticky_icon $e.security_icon $e.subject</h3>\n";
     if ($.view == "friends" or $e.poster.username != $e.journal.username) {
         "<div>"; $this->print_entry_poster($e); "</div>";
     }

Modified: branches/delayed_entries/cgi-bin/LJ/Entry.pm
===================================================================
--- branches/delayed_entries/cgi-bin/LJ/Entry.pm	2011-07-27 03:01:18 UTC (rev 19532)
+++ branches/delayed_entries/cgi-bin/LJ/Entry.pm	2011-07-27 03:25:33 UTC (rev 19533)
@@ -1445,6 +1445,13 @@
     return \%meta;
 }
 
+sub is_sticky {
+    my ($self) = @_;
+
+    my $u = $self->{u};
+    return $self->{jitemid} == $u->get_sticky_entry();
+}
+
 package LJ;
 
 use Class::Autouse qw (
@@ -1805,7 +1812,8 @@
 
 sub get_log2_recent_log
 {
-    my ($u, $cid, $update, $notafter, $events_date) = @_;
+    my ($u, $cid, $update, $notafter, $events_date, $exclude_sticky) = @_;
+    $exclude_sticky = $exclude_sticky || 0; # optional
     my $jid = LJ::want_userid($u);
     $cid ||= $u->{'clusterid'} if ref $u;
 
@@ -1934,9 +1942,17 @@
                AND rlogtime >= ($LJ::EndOfTime - " . ($events_date + 24*3600) . ")"
             :
             "AND rlogtime <= ($LJ::EndOfTime - UNIX_TIMESTAMP()) + $max_age"
-         )
-         ;
+         );
 
+    if ( $exclude_sticky ) {
+        my $uobj = LJ::want_user($u);
+        my $sticky = $uobj->get_sticky_entry();
+
+        if ($sticky) {
+            $sql .= " AND jitemid <> $sticky";
+        }
+    }
+
     my $sth = $db->prepare($sql);
     $sth->execute($jid);
     my @row = ();
@@ -1984,7 +2000,8 @@
     my $ret = [];
 
     my $log = LJ::get_log2_recent_log($opts->{'userid'}, $opts->{'clusterid'},
-              $opts->{'update'}, $opts->{'notafter'}, $opts->{events_date});
+              $opts->{'update'}, $opts->{'notafter'}, $opts->{events_date},
+              $opts->{'exclude_sticky'});
 
     ## UNUSED: my $left     = $opts->{'itemshow'};
     my $notafter = $opts->{'notafter'};
@@ -2332,6 +2349,10 @@
     # delete all comments
     LJ::delete_all_comments($u, 'L', $jitemid);
 
+    if ( $jitemid == $u->get_sticky_entry() ){
+        $u->remove_sticky_entry();
+    }
+
     return 1;
 }
 

Modified: branches/delayed_entries/cgi-bin/LJ/S2.pm
===================================================================
--- branches/delayed_entries/cgi-bin/LJ/S2.pm	2011-07-27 03:01:18 UTC (rev 19532)
+++ branches/delayed_entries/cgi-bin/LJ/S2.pm	2011-07-27 03:25:33 UTC (rev 19533)
@@ -1971,6 +1971,10 @@
     #   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");
+    }
+
     return $e;
 }
 
@@ -2109,6 +2113,7 @@
             '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'}),
         };
     }
     return $LJ::S2::RES_CACHE->{$name};

Modified: branches/delayed_entries/cgi-bin/LJ/User.pm
===================================================================
--- branches/delayed_entries/cgi-bin/LJ/User.pm	2011-07-27 03:01:18 UTC (rev 19532)
+++ branches/delayed_entries/cgi-bin/LJ/User.pm	2011-07-27 03:25:33 UTC (rev 19533)
@@ -6148,6 +6148,25 @@
     return 0;
 }
 
+# returns sticky entry jitemid
+sub get_sticky_entry {
+    my ($self) = @_;
+    return $self->prop("sticky_entries") || '';
+}
+
+# returns sticky entry jitemid
+sub remove_sticky {
+    my ($self) = @_;
+    $self->clear_prop("sticky_entries");
+}
+
+# set sticky entry? 
+sub set_sticky {
+    my ($self, $itemid) = @_;
+    die "itemid is not set" unless ($itemid);
+    $self->set_prop( sticky_entries => $itemid );
+}
+
 package LJ;
 
 use Carp;

Modified: branches/delayed_entries/cgi-bin/LJ/Widget/EntryForm.pm
===================================================================
--- branches/delayed_entries/cgi-bin/LJ/Widget/EntryForm.pm	2011-07-27 03:01:18 UTC (rev 19532)
+++ branches/delayed_entries/cgi-bin/LJ/Widget/EntryForm.pm	2011-07-27 03:25:33 UTC (rev 19533)
@@ -520,6 +520,19 @@
         </noscript>
     };
 
+    my $sticky = '';
+    if ($opts->{jitemid}) {
+        my $journalu = LJ::load_user($opts->{'usejournal'}) || $remote;
+        my $sticky_entry = $journalu->get_sticky_entry();
+        $sticky = 'checked' if ( $sticky_entry eq $opts->{jitemid});
+    }
+
+    $out .= qq{ <p id='sticky_checkbox'class='pkg'>
+                    <input type='checkbox' name='type' value='sticky' $sticky>
+                        $BML::ML{'entryform.sticky.edit'}
+                    </input> 
+                </p> };
+
     $$onload .= " defaultDate();";
 
     # User Picture

Modified: branches/delayed_entries/cgi-bin/ljfeed.pl
===================================================================
--- branches/delayed_entries/cgi-bin/ljfeed.pl	2011-07-27 03:01:18 UTC (rev 19532)
+++ branches/delayed_entries/cgi-bin/ljfeed.pl	2011-07-27 03:25:33 UTC (rev 19533)
@@ -150,6 +150,7 @@
             'entry_objects' => \@objs,
             'load_props'    => 1,
             'load_text'     => 1,
+            'exclude_sticky' => 1,
         });
     }
 

Modified: branches/delayed_entries/cgi-bin/ljlib.pl
===================================================================
--- branches/delayed_entries/cgi-bin/ljlib.pl	2011-07-27 03:01:18 UTC (rev 19532)
+++ branches/delayed_entries/cgi-bin/ljlib.pl	2011-07-27 03:25:33 UTC (rev 19533)
@@ -916,6 +916,7 @@
             'dateformat'  => $opts->{'dateformat'},
             'update'      => $LJ::EndOfTime - $fr->[1], # reverse back to normal
             'events_date' => $events_date,
+            'exclude_sticky'   => 1,
         });
 
         # stamp each with clusterid if from cluster, so ljviews and other
@@ -1096,6 +1097,8 @@
         $remote = LJ::load_userid($remoteid);
     }
 
+    my $exclude_sticky = $opts->{exclude_sticky} || 0;
+
     my $max_hints = $LJ::MAX_SCROLLBACK_LASTN;  # temporary
     my $sort_key = "revttime";
 
@@ -1126,6 +1129,9 @@
     #   with 32 bit time_t structs dies)
     my $notafter = $opts->{'notafter'} + 0 || $LJ::EndOfTime - 1;
 
+    # sticky entries array
+    my $sticky = $u->get_sticky_entry();
+
     my $skip = $opts->{'skip'}+0;
     my $itemshow = $opts->{'itemshow'}+0;
     if ($itemshow > $max_hints) { $itemshow = $max_hints; }
@@ -1134,6 +1140,15 @@
     if ($skip > $maxskip) { $skip = $maxskip; }
     my $itemload = $itemshow + $skip;
 
+    #
+    # modificate 'usual elements to be shown'
+    #
+    
+    # begin point
+    $skip = ($skip - 1) if ( $sticky && $skip > 0);
+    # elements count
+    my $usual_show = $skip > 0 ? $itemshow  : $itemshow - 1;
+
     my $mask = 0;
     if ($remote && ($remote->{'journaltype'} eq "P" || $remote->{'journaltype'} eq "I") && $remoteid != $userid) {
         $mask = LJ::get_groupmask($userid, $remoteid);
@@ -1229,6 +1244,7 @@
     }
 
     my $sql;
+    my $sticky_sql;
 
     my $dateformat = "%a %W %b %M %y %Y %c %m %e %d %D %p %i %l %h %k %H";
     if ($opts->{'dateformat'} eq "S2") {
@@ -1256,7 +1272,7 @@
         $sql_select = "AND year=$year AND month=$month AND day=$day";
         $extra_sql .= "allowmask, ";
     } else {
-        $sql_limit  = "LIMIT $skip,$itemshow";
+        $sql_limit  = "LIMIT $skip, $usual_show";
         $sql_select = "AND $sort_key <= $notafter";
     }
 
@@ -1288,20 +1304,28 @@
                allowmask, eventtime, logtime
         FROM log2 USE INDEX ($sort_key)
         WHERE journalid=$userid $sql_select $secwhere $jitemidwhere $securitywhere $posterwhere $after_sql $suspend_where
-        ORDER BY journalid, $sort_key
-        $sql_limit
     };
 
+    if ($sticky) {
+        # build request to receive sticky entries
+        if (!$skip && !$exclude_sticky) {
+            $sticky_sql = "$sql AND jitemid = $sticky ";
+            $sticky_sql .= "ORDER BY journalid, $sort_key ";
+        }
+
+        # sticky exculustion
+        $sql .= "AND jitemid <> $sticky";
+    }
+    
+    $sql .= qq{
+        ORDER BY journalid, $sort_key
+        $sql_limit};
+
     unless ($logdb) {
         $$err = "nodb" if ref $err eq "SCALAR";
         return ();
     }
-
-    $sth = $logdb->prepare($sql);
-    $sth->execute;
-    if ($logdb->err) { die $logdb->errstr; }
-
-    # keep track of the last alldatepart, and a per-minute buffer
+    
     my $last_time;
     my @buf;
 
@@ -1311,19 +1335,29 @@
         @buf = ();
     };
 
-    while (my $li = $sth->fetchrow_hashref) {
-        push @{$opts->{'itemids'}}, $li->{'itemid'};
+    my $absorb_data = sub {
+        my ($sql_request) = @_;
+        $sth = $logdb->prepare($sql_request);
+        $sth->execute;
+        if ($logdb->err) { die $logdb->errstr; }
+    
+        # keep track of the last alldatepart, and a per-minute buffer
+        while (my $li = $sth->fetchrow_hashref) {
+            push @{$opts->{'itemids'}}, $li->{'itemid'};
+    
+            $flush->() if $li->{alldatepart} ne $last_time;
+            push @buf, $li;
+            $last_time = $li->{alldatepart};
+    
+            # construct an LJ::Entry singleton
+            my $entry = LJ::Entry->new($userid, jitemid => $li->{itemid}, rlogtime => $li->{rlogtime});
+            $entry->absorb_row($li);
+            push @{$opts->{'entry_objects'}}, $entry;
+        }
+    };
 
-        $flush->() if $li->{alldatepart} ne $last_time;
-        push @buf, $li;
-        $last_time = $li->{alldatepart};
-
-        # construct an LJ::Entry singleton
-        my $entry = LJ::Entry->new($userid, jitemid => $li->{itemid}, rlogtime => $li->{rlogtime});
-        $entry->absorb_row($li);
-        push @{$opts->{'entry_objects'}}, $entry;
-    }
-
+    $absorb_data->($sticky_sql) if ( $sticky && !$skip && !$exclude_sticky );
+    $absorb_data->($sql);
     $flush->();
 
     if ( exists $opts->{load_props} && $opts->{load_props} ) {

Modified: branches/delayed_entries/cgi-bin/ljprotocol.pl
===================================================================
--- branches/delayed_entries/cgi-bin/ljprotocol.pl	2011-07-27 03:01:18 UTC (rev 19532)
+++ branches/delayed_entries/cgi-bin/ljprotocol.pl	2011-07-27 03:25:33 UTC (rev 19533)
@@ -1964,6 +1964,14 @@
         !$req->{'props'}->{'opt_backdated'}) {
         return fail($err, 153, "You have an entry which was posted at $u->{'newesteventtime'}, but you're trying to post an entry before this. Please check the date and time of both entries. If the other entry is set in the future on purpose, edit that entry to use the \"Date Out of Order\" option. Otherwise, use the \"Date Out of Order\" option for this entry instead.");
     }
+    
+    if ( $req->{type} && $req->{type} eq 'sticky' &&
+         $uowner->{'journaltype'} eq 'C' &&
+          !( LJ::check_rel($ownerid, $posterid, 'S') ||
+             LJ::check_rel($ownerid, $posterid, 'M') ) )
+    {
+        return fail($err, 174);
+    }
 
     my $qallowmask = $req->{'allowmask'}+0;
     my $security = "public";
@@ -2225,6 +2233,11 @@
                      "UNIX_TIMESTAMP($qeventtime), $rlogtime, $anum)");
     return $fail->($err,501,$dberr) if $dberr;
 
+    # post become 'sticky post'
+    if ( $req->{type} && $req->{type} eq 'sticky' ) {
+        $uowner->set_sticky($jitemid);
+    }
+
     LJ::MemCache::incr([$ownerid, "log2ct:$ownerid"]);
     LJ::memcache_kill($ownerid, "dayct2");
 
@@ -2622,6 +2635,10 @@
             }
         };
 
+        if ( $itemid == $uowner->get_sticky_entry() ) {
+            $u->remove_sticky();
+        }
+
         return $res;
     }
 
@@ -2653,6 +2670,17 @@
     my %curprops;
     LJ::load_log_props2($dbcm, $ownerid, [ $itemid ], \%curprops);
 
+    # make post sticky
+    if ( $req->{type} && $req->{type} eq 'sticky') {
+        if( $uowner->get_sticky_entry() != $itemid ) {
+            $uowner->set_sticky($itemid);
+            LJ::MemCache::delete([$ownerid, "log2lt:$ownerid"]);
+        }
+    } elsif ( $itemid == $uowner->get_sticky_entry() ) {
+        $uowner->remove_sticky();
+        LJ::MemCache::delete([$ownerid, "log2lt:$ownerid"]);
+    }
+
     ## give features
     my $give_features = $req->{'props'}->{'give_features'};
     if ($give_features) {

Modified: branches/delayed_entries/htdocs/editjournal.bml
===================================================================
--- branches/delayed_entries/htdocs/editjournal.bml	2011-07-27 03:01:18 UTC (rev 19532)
+++ branches/delayed_entries/htdocs/editjournal.bml	2011-07-27 03:25:33 UTC (rev 19533)
@@ -201,10 +201,11 @@
                 return LJ::bad_input($ML{'error.invalidform'}) unless LJ::check_form_auth();
 
                 my %req = (
-                            'ver' => $LJ::PROTOCOL_VER,
-                            'username' => $u->{'user'},
+                            'ver'        => $LJ::PROTOCOL_VER,
+                            'username'   => $u->{'user'},
                             'usejournal' => $usejournal,
-                            'itemid' => $itemid,
+                            'itemid'     => $itemid,
+                            'type'       => $POST{'type'} || $POST{'type'},
                             );
                 LJ::entry_form_decode(\%req, \%POST);
 
@@ -381,6 +382,7 @@
                 'disabled_spamdelete' => $disabled_spamdelete,
                 'suspended' => $suspend_msg,
                 'unsuspend_supportid' => $suspend_msg ? $entry_obj->prop("unsuspend_supportid") : 0,
+                'jitemid' => $itemid,
             };
             for (my $i = 1; $i <= $res{'prop_count'}; $i++) {
                 $entry->{"prop_" . $res{"prop_${i}_name"}} = $res{"prop_${i}_value"};

Modified: branches/delayed_entries/htdocs/editjournal.bml.text
===================================================================
--- branches/delayed_entries/htdocs/editjournal.bml.text	2011-07-27 03:01:18 UTC (rev 19532)
+++ branches/delayed_entries/htdocs/editjournal.bml.text	2011-07-27 03:25:33 UTC (rev 19533)
@@ -42,5 +42,7 @@
 
 .title=Edit Journal Entries
 
+.title_sticky=Edit Journal Sticky Entries
+
 .viewwhat=View What Entries:
 

Modified: branches/delayed_entries/htdocs/update.bml
===================================================================
--- branches/delayed_entries/htdocs/update.bml	2011-07-27 03:01:18 UTC (rev 19532)
+++ branches/delayed_entries/htdocs/update.bml	2011-07-27 03:25:33 UTC (rev 19533)
@@ -12,9 +12,10 @@
     my $body     = \$_[0]->{'body'};
     my $bodyopts = \$_[0]->{'bodyopts'};
     my $onload   = \$_[0]->{'onload'};
+    
+    my $update_type = $POST{'type'} || $GET{'type'};
+    $$title = ($update_type eq 'sticky') ?  $ML{'.title2_sticky'} : $ML{'.title2'};
 
-    $$title = $ML{'.title2'};
-
     # server down?
     if ($LJ::SERVER_DOWN) {
         $$body = LJ::server_down_html();
@@ -345,6 +346,10 @@
             $$body .= LJ::html_hidden( 'reposted_from' => $reposted_from );
         }
 
+        if ($update_type) {
+            $$body .= LJ::html_hidden( 'type' => $update_type );
+        }
+
         if ($opts->{require_tos}){
             $$body .= LJ::tosagree_html('update', $POST{agree_tos}, $errors->{require_tos});
         }
@@ -456,6 +461,7 @@
                     'password'    => $POST{'password'},
                     'usejournal'  => ($usejournalu) ? $usejournalu->user : undef,
                     'tz'          => 'guess',
+                    'type'        => $POST{'type'} || $POST{'type'},
                     );
 
         LJ::entry_form_decode(\%req, \%POST);

Modified: branches/delayed_entries/htdocs/update.bml.text
===================================================================
--- branches/delayed_entries/htdocs/update.bml.text	2011-07-27 03:01:18 UTC (rev 19532)
+++ branches/delayed_entries/htdocs/update.bml.text	2011-07-27 03:25:33 UTC (rev 19533)
@@ -126,6 +126,9 @@
 .title2|staleness=1
 .title2=Post an Entry
 
+.title2_sticky|staleness=1
+.title2_sticky=Post an Entry: entry will be displayed at the top of the journal
+
 .update.head=Update your Journal...
 
 .update.success2=Update successful. You can view your updated journal <a [[aopts]]>here</a>.

Tags: bml, dat, livejournal, madeon, pl, pm, s2, text
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