Add 'recently active entries' module to S2 for paid users.  Shows list 
of entries that have been most recently commented on.

        Patch by yvi. 

diffs (412 lines):

diff -r 9c0dab361c91 -r 7cfc6612710c bin/upgrading/s2layers/bases/layout.s2
--- a/bin/upgrading/s2layers/bases/layout.s2    Thu Dec 03 05:44:45 2009 +0000
+++ b/bin/upgrading/s2layers/bases/layout.s2    Thu Dec 03 06:13:17 2009 +0000
@@ -111,6 +111,7 @@ propgroup modules {
     property use module_calendar_group;
     property use module_pagesummary_group;
     property use module_tags_group;
+    property use module_active_group;
     property use module_links_group;
     property use module_syndicate_group;
     property use module_time_group;
diff -r 9c0dab361c91 -r 7cfc6612710c bin/upgrading/s2layers/blanket/layout.s2
--- a/bin/upgrading/s2layers/blanket/layout.s2  Thu Dec 03 05:44:45 2009 +0000
+++ b/bin/upgrading/s2layers/blanket/layout.s2  Thu Dec 03 06:13:17 2009 +0000
@@ -81,6 +81,7 @@ propgroup modules {
     property use module_customtext_group;
     property use module_calendar_group;
     property use module_pagesummary_group;
+    property use module_active_group;
     property use module_tags_group;
     property use module_links_group;
     property use module_syndicate_group;
diff -r 9c0dab361c91 -r 7cfc6612710c bin/upgrading/s2layers/brittle/layout.s2
--- a/bin/upgrading/s2layers/brittle/layout.s2  Thu Dec 03 05:44:45 2009 +0000
+++ b/bin/upgrading/s2layers/brittle/layout.s2  Thu Dec 03 06:13:17 2009 +0000
@@ -180,6 +180,7 @@ propgroup modules {
     property use module_calendar_group;
     property use module_pagesummary_group;
     property use module_tags_group;
+    property use module_active_group;
     property use module_links_group;
     property use module_syndicate_group;
     property use module_time_group;
diff -r 9c0dab361c91 -r 7cfc6612710c bin/upgrading/s2layers/core2.s2
--- a/bin/upgrading/s2layers/core2.s2   Thu Dec 03 05:44:45 2009 +0000
+++ b/bin/upgrading/s2layers/core2.s2   Thu Dec 03 06:13:17 2009 +0000
@@ -522,6 +522,12 @@ class Page
     var readonly UserLink[] linklist
     "An array of UserLink objects defined by the user to be displayed on their 
journal.";
 
+    var bool has_activeentries
+    "So we don't try to load the activeentries array when there are no entries 
to display";
+
+    var readonly Entry[] activeentries
+    "Array of recently active entries available to be seen by the viewer of 
the page.";
+
     var readonly DateTime local_time
     "A DateTime object filled with the time (in the viewer's timezone) when 
the page was created.";
 
@@ -1376,6 +1382,20 @@ set module_links_show = true;
 set module_links_show = true;
 set module_links_order = 4;
 set module_links_section = "one";
+
+property string[] module_active_group {
+    des = "Recent active entries";
+    grouptype = "module";
+    requires_cap = "activeentries";
+}
+set module_active_group = ["module_active_show", "module_active_order", 
"module_active_section"];
+property bool module_active_show     { grouped = 1; }
+property int  module_active_order    { grouped = 1; }
+property string module_active_section { grouped = 1; }
+
+set module_active_show = true;
+set module_active_order = 8;
+set module_active_section = "one";
 
 property string[] module_syndicate_group {
     des = "Syndication";
@@ -2033,6 +2053,13 @@ property string text_module_popular_tags
     example = "Most Popular Tags";
 }
 
+property string text_module_active_entries {
+    des = "Text for the 'Active Entries' heading";
+    maxlength = 50;
+    size = 20;
+    example = "Active Entries";
+}
+
 property string text_module_customtext {
     des = "Text for the 'Custom text' heading";
     maxlength = 50;
@@ -2066,6 +2093,7 @@ set text_module_syndicate = "Syndicate";
 set text_module_syndicate = "Syndicate";
 set text_module_tags = "Tags";
 set text_module_popular_tags = "Most Popular Tags";
+set text_module_active_entries = "Active Entries";
 set text_module_credit = "Layout Credit";
 
 set text_module_customtext = "Custom text";
@@ -2566,6 +2594,7 @@ function modules_init()
     if ( $*module_navlinks_show ) { 
$*module_sections{$*module_navlinks_section}[$*module_navlinks_order]=["navlinks"];
 }
     if ( $*module_calendar_show ) { 
$*module_sections{$*module_calendar_section}[$*module_calendar_order]=["calendar"];
 }
     if ( $*module_links_show ) { 
$*module_sections{$*module_links_section}[$*module_links_order]=["links"]; }
+    if ( $*module_active_show ) { 
$*module_sections{$*module_active_section}[$*module_active_order]=["active"]; }
     if ( $*module_syndicate_show ) { 
$*module_sections{$*module_syndicate_section}[$*module_syndicate_order]=["syndicate"];
 }
     if ( $*module_tags_show ) { 
$*module_sections{$*module_tags_section}[$*module_tags_order]=["tags"]; }
     if ( $*module_pagesummary_show ) { 
$*module_sections{$*module_pagesummary_section}[$*module_pagesummary_order]=["pagesummary"];
 }
@@ -3608,6 +3637,23 @@ function print_module_tags() {
     }
 }
 
+function print_module_active() {
+    var Page p = get_page();
+    if ( $p.has_activeentries and not $p isa FriendsPage ) {
+        var Entry[] activeentries = $p.activeentries;
+        var string[] subjects;
+        open_module( "active", $*text_module_active_entries, "" );
+        var int i = 1;
+                foreach var Entry activeentry ( $activeentries ) {
+                    var string subject = ( $activeentry.subject != "" ? 
$activeentry.subject : "$*text_nosubject" );
+                    $subjects[size $subjects] = """$i: <a 
href="$activeentry.permalink_url">$subject</a>""";
+                    $i++;
+                 }
+        print_module_list( $subjects );
+        close_module();
+    }
+}
+
 function print_module_calendar() {
     var Page p = get_page();
     var YearMonth mon = $p->get_latest_month();
@@ -3794,6 +3840,9 @@ function handle_module_group_array(strin
         }
         elseif ($module == "tags") {
             print_module_tags();
+        }
+        elseif ($module == "active") {
+            print_module_active();
         }
         elseif ($module == "calendar") {
             print_module_calendar();
diff -r 9c0dab361c91 -r 7cfc6612710c bin/upgrading/s2layers/core2base/layout.s2
--- a/bin/upgrading/s2layers/core2base/layout.s2        Thu Dec 03 05:44:45 
2009 +0000
+++ b/bin/upgrading/s2layers/core2base/layout.s2        Thu Dec 03 06:13:17 
2009 +0000
@@ -184,6 +184,7 @@ propgroup modules {
     property use module_customtext_group;
     property use module_calendar_group;
     property use module_pagesummary_group;
+    property use module_active_group;
     property use module_tags_group;
     property use module_links_group;
     property use module_syndicate_group;
diff -r 9c0dab361c91 -r 7cfc6612710c bin/upgrading/s2layers/drifting/layout.s2
--- a/bin/upgrading/s2layers/drifting/layout.s2 Thu Dec 03 05:44:45 2009 +0000
+++ b/bin/upgrading/s2layers/drifting/layout.s2 Thu Dec 03 06:13:17 2009 +0000
@@ -189,6 +189,7 @@ propgroup modules
     property use module_pagesummary_group;
     property use module_links_group;
     property use module_calendar_group;
+    property use module_active_group;
     property use module_poweredby_group;
     property use module_tags_group;
     property use module_syndicate_group;
diff -r 9c0dab361c91 -r 7cfc6612710c bin/upgrading/s2layers/negatives/layout.s2
--- a/bin/upgrading/s2layers/negatives/layout.s2        Thu Dec 03 05:44:45 
2009 +0000
+++ b/bin/upgrading/s2layers/negatives/layout.s2        Thu Dec 03 06:13:17 
2009 +0000
@@ -167,6 +167,7 @@ propgroup modules {
     property use module_customtext_group;
     property use module_calendar_group;
     property use module_pagesummary_group;
+    property use module_active_group;
     property use module_tags_group;
     property use module_links_group;
     property use module_syndicate_group;
diff -r 9c0dab361c91 -r 7cfc6612710c 
bin/upgrading/s2layers/skittlishdreams/layout.s2
--- a/bin/upgrading/s2layers/skittlishdreams/layout.s2  Thu Dec 03 05:44:45 
2009 +0000
+++ b/bin/upgrading/s2layers/skittlishdreams/layout.s2  Thu Dec 03 06:13:17 
2009 +0000
@@ -174,6 +174,7 @@ propgroup modules {
     property use module_calendar_group;
     property use module_pagesummary_group;
     property use module_tags_group;
+    property use module_active_group;
     property use module_links_group;
     property use module_syndicate_group;
     property use module_time_group;
@@ -187,6 +188,7 @@ set module_userprofile_section = "two";
 set module_userprofile_section = "two";
 set module_pagesummary_section = "two";
 set module_tags_section = "two";
+set module_active_section = "two";
 set module_links_section = "two";
 set module_syndicate_section = "two";
 set module_calendar_section = "two";
diff -r 9c0dab361c91 -r 7cfc6612710c cgi-bin/DW/Logic/LogItems.pm
--- a/cgi-bin/DW/Logic/LogItems.pm      Thu Dec 03 05:44:45 2009 +0000
+++ b/cgi-bin/DW/Logic/LogItems.pm      Thu Dec 03 06:13:17 2009 +0000
@@ -547,5 +547,38 @@ sub recent_items
 *LJ::User::recent_items = \&recent_items;
 *DW::User::recent_items = \&recent_items;
 
+# name: $u->active_entries
+# des: Returns 10 last active entries for an account
+# returns: array of itemids
+sub active_entries
+{
+    my ( $u ) = @_;
+    my $uid = $u->userid;
+
+    # check memcache first
+    my $activeentries = LJ::MemCache::get( [ $uid, "activeentries:$uid" ] );
+    return @$activeentries if $activeentries;
+
+    # get latest 10 entries that were commented on - we will see whether 
$remote can view them later
+    # disregard screened and deleted comments when ordering
+
+    my $entryids = $u->selectcol_arrayref(
+        q{SELECT DISTINCT nodeid FROM talk2
+          WHERE journalid = ? AND state NOT IN ('D', 'S') 
+          ORDER BY jtalkid DESC LIMIT 10},
+        undef, $u->id
+    );
+    die $u->errstr if $u->err;
+    return unless $entryids && @$entryids;
+
+    # memcache this data in the form: activeentries:journalid
+    LJ::MemCache::set( [ $uid, "activeentries:$uid" ], \...@$entryids );
+
+    # return. we check whether the user viewing is allowed to view these 
entries later
+    return @$entryids;
+}
+
+*LJ::User::active_entries = \&active_entries;
+*DW::User::active_entries = \&active_entries;
 
 1;
diff -r 9c0dab361c91 -r 7cfc6612710c cgi-bin/LJ/Entry.pm
--- a/cgi-bin/LJ/Entry.pm       Thu Dec 03 05:44:45 2009 +0000
+++ b/cgi-bin/LJ/Entry.pm       Thu Dec 03 06:13:17 2009 +0000
@@ -1856,6 +1856,7 @@ sub delete_entry
 
     my $dc = $u->log2_do(undef, "DELETE FROM log2 WHERE journalid=$jid AND 
jitemid=$jitemid $and");
     LJ::MemCache::delete([$jid, "log2:$jid:$jitemid"]);
+    LJ::MemCache::delete( [ $jid, "activeentries:$jid" ] );
     LJ::MemCache::decr([$jid, "log2ct:$jid"]) if $dc > 0;
     LJ::memcache_kill($jid, "dayct2");
     LJ::run_hooks("deletepost", $jid, $jitemid, $anum);
diff -r 9c0dab361c91 -r 7cfc6612710c cgi-bin/LJ/S2.pm
--- a/cgi-bin/LJ/S2.pm  Thu Dec 03 05:44:45 2009 +0000
+++ b/cgi-bin/LJ/S2.pm  Thu Dec 03 06:13:17 2009 +0000
@@ -2120,6 +2120,28 @@ sub Page
     $p->{views_order} = [ 'read', 'userinfo' ] if $u->is_identity;
     $p->{views_order} = [ 'recent', 'archive', 'read', 'network', 'tags', 
'memories', 'userinfo' ] if $u->can_use_network_page;
 
+    $p->{has_activeentries} = 0;
+
+    # don't need to load active entries if the user does not have the cap to 
display them
+    if ( $u->can_use_active_entries ) {
+        my @active = $u->active_entries;
+
+        # array to hold the Entry objects
+        my @activeentries;
+        foreach my $itemid ( @active ) {
+            my $entry_obj = LJ::Entry->new( $u, jitemid => $itemid );
+
+            # only show the entries $remote has the permission to view
+            if ( $entry_obj->visible_to( $remote ) ) {
+                my $activeentry = Entry_from_entryobj( $u, $entry_obj, $opts );
+                push @{$p->{activeentries}}, $activeentry;
+
+                # if at least one is accessible to $remote , show active 
entries module on journal page
+                $p->{has_activeentries} = 1;
+            }
+        }
+    }
+
     return $p;
 }
 
diff -r 9c0dab361c91 -r 7cfc6612710c cgi-bin/LJ/S2Theme.pm
--- a/cgi-bin/LJ/S2Theme.pm     Thu Dec 03 05:44:45 2009 +0000
+++ b/cgi-bin/LJ/S2Theme.pm     Thu Dec 03 06:13:17 2009 +0000
@@ -696,6 +696,7 @@ sub module_props {
         text_module_pagesummary
         text_module_syndicate
         text_module_tags
+        text_module_active_entries
         text_generated_on
         text_tags_manage
         text_tag_uses
diff -r 9c0dab361c91 -r 7cfc6612710c cgi-bin/LJ/Talk.pm
--- a/cgi-bin/LJ/Talk.pm        Thu Dec 03 05:44:45 2009 +0000
+++ b/cgi-bin/LJ/Talk.pm        Thu Dec 03 06:13:17 2009 +0000
@@ -593,6 +593,7 @@ sub screen_comment {
 
     # invalidate talk2row memcache props
     LJ::Talk::invalidate_talk2row_memcache($u->id, @jtalkids);
+    LJ::MemCache::delete( [ $userid, "activeentries:$userid" ] );
 
     if ($updated > 0) {
         LJ::replycount_do($u, $itemid, "decr", $updated);
@@ -623,6 +624,7 @@ sub unscreen_comment {
     return undef unless $updated;
 
     LJ::Talk::invalidate_talk2row_memcache($u->id, @jtalkids);
+    LJ::MemCache::delete( [ $userid, "activeentries:$userid" ] );
 
     if ($updated > 0) {
         LJ::replycount_do($u, $itemid, "incr", $updated);
@@ -2579,6 +2581,8 @@ sub enter_comment {
     LJ::MemCache::set([$journalu->{'userid'},"talksubject:$memkey"], 
$comment->{subject});
     LJ::MemCache::set([$journalu->{'userid'},"talkbody:$memkey"], 
$comment->{body});
 
+    LJ::MemCache::delete( [ $journalu->{userid}, "activeentries:" . 
$journalu->{userid} ] );
+
     # dudata
     my $bytes = length($comment->{subject}) + length($comment->{body});
     # we used to do a LJ::dudata_set(..) on 'T' here, but decided
diff -r 9c0dab361c91 -r 7cfc6612710c cgi-bin/LJ/User.pm
--- a/cgi-bin/LJ/User.pm        Thu Dec 03 05:44:45 2009 +0000
+++ b/cgi-bin/LJ/User.pm        Thu Dec 03 06:13:17 2009 +0000
@@ -1957,6 +1957,10 @@ sub can_use_network_page {
 }
 
 
+sub can_use_active_entries {
+    return $_[0]->get_cap( 'activeentries' ) ? 1 : 0;
+}
+
 # Check if the user can use *any* page statistic module for their own journal.
 sub can_use_page_statistics {
     return $_[0]->can_use_google_analytics;
diff -r 9c0dab361c91 -r 7cfc6612710c cgi-bin/LJ/Widget/S2PropGroup.pm
--- a/cgi-bin/LJ/Widget/S2PropGroup.pm  Thu Dec 03 05:44:45 2009 +0000
+++ b/cgi-bin/LJ/Widget/S2PropGroup.pm  Thu Dec 03 06:13:17 2009 +0000
@@ -90,7 +90,7 @@ sub render_body {
         my %prop_in_subheader;
         foreach my $prop_name ( @$groupprops ) {
             next unless $prop_name =~ /_group$/;
-            
+ 
             my $prop_name_section = $prop_name;
             $prop_name_section =~ s/(.*)_group$/\1_section/;
 
@@ -99,6 +99,12 @@ sub render_body {
 
             # put this property under the proper subheader
             my %prop_values = LJ::Customize->get_s2_prop_values( 
$prop_name_section, $u, $style );
+
+            # see whether a cap is needed for this module and don't show the 
module if the user does not have that cap
+            my $cap;
+            $cap = $props->{$prop_name}->{requires_cap};
+            next if $cap && !( $u->get_cap( $cap ) );
+
             # force it to the "none" section, if property value is not a valid 
subheader
             my $subheader = $subheaders{$prop_values{override}} ? 
$prop_values{override} : "none";
             $prop_in_subheader{$subheader} ||= [];
diff -r 9c0dab361c91 -r 7cfc6612710c cgi-bin/ljlib.pl
--- a/cgi-bin/ljlib.pl  Thu Dec 03 05:44:45 2009 +0000
+++ b/cgi-bin/ljlib.pl  Thu Dec 03 06:13:17 2009 +0000
@@ -1814,6 +1814,8 @@ sub delete_comments {
     my $sclient = LJ::theschwartz();
     $sclient->insert_jobs(@jobs) if @jobs;
 
+    LJ::MemCache::delete( [ $jid, "activeentries:$jid" ] );
+
     return $num;
 }
 
diff -r 9c0dab361c91 -r 7cfc6612710c etc/config.pl
--- a/etc/config.pl     Thu Dec 03 05:44:45 2009 +0000
+++ b/etc/config.pl     Thu Dec 03 06:13:17 2009 +0000
@@ -295,6 +295,7 @@
     # default capability limits, used only when no other
     # class-specific limit below matches.
     %CAP_DEF = (
+            activeentries => 0,
             'getselfemail' => 0,
             'checkfriends' => 0,
             'checkfriends_interval' => 300,
@@ -353,6 +354,7 @@
             '_key' => 'free_user',
             '_account_type' => 'free',
             '_account_default' => 1,    # default account for payment system
+            'activeentries' => 0,
             'bookmark_max' => 25,
             'checkfriends' => 0,
             'checkfriends_interval' => 0,
@@ -408,6 +410,7 @@
             '_key' => 'paid_user', # Some things expect that key name
             '_visible_name' => 'Paid Account',
             '_account_type' => 'paid',
+            'activeentries' => 1,
             'bookmark_max' => 500,
             'checkfriends' => 1,
             'checkfriends_interval' => 600,
@@ -461,6 +464,7 @@
             '_key' => 'premium_user',
             '_visible_name' => 'Premium Paid Account',
             '_account_type' => 'premium',
+            'activeentries' => 1,
             'bookmark_max' => 1000,
             'checkfriends' => 1,
             'checkfriends_interval' => 600,
@@ -521,6 +525,7 @@
             '_key' => 'permanent_user',
             '_visible_name' => 'Seed Account',
             '_account_type' => 'seed',
+            'activeentries' => 1,
             'bookmark_max' => 1000,
             'checkfriends' => 1,
             'checkfriends_interval' => 600,
@@ -572,6 +577,7 @@
             '_name' => 'Staff',
             '_key' => 'staff',
             '_visible_name' => 'Staff Account',
+            'activeentries' => 1,
             'bookmark_max' => 1000,
             'checkfriends' => 1,
             'checkfriends_interval' => 600,
_______________________________________________
dw-changelog mailing list
[email protected]
http://lists.dwscoalition.org/mailman/listinfo/dw-changelog

Reply via email to