afuna: Cat under a blanket. Text: "Cats are just little people with Fur and Fangs" (Default)
afuna ([personal profile] afuna) wrote in [site community profile] changelog2009-08-09 05:44 pm

[dw-free] Random Account Sponsorship/Paid Account Fairy

[commit: http://hg.dwscoalition.org/dw-free/rev/c90b294a40e7]

http://bugs.dwscoalition.org/show_bug.cgi?id=211

I missed a few necessary files.

Patch by [personal profile] janinedog.

Files modified:
  • bin/get-users-for-paid-accounts.pl
  • cgi-bin/DW/Setting/RandomPaidGifts.pm
  • htdocs/shop/randomgift.bml
  • htdocs/shop/randomgift.bml.text
--------------------------------------------------------------------------------
diff -r f42f4796e620 -r c90b294a40e7 bin/get-users-for-paid-accounts.pl
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/bin/get-users-for-paid-accounts.pl	Sun Aug 09 17:43:37 2009 +0000
@@ -0,0 +1,46 @@
+#!/usr/bin/perl
+
+use strict;
+use warnings;
+use lib "$ENV{'LJHOME'}/cgi-bin";
+require "ljlib.pl";
+require "sysban.pl";
+use DW::Pay;
+use List::Util qw( min );
+
+my $dbslow = LJ::get_dbh( 'slow' );
+my $dbh = LJ::get_db_writer();
+
+my $userids = $dbslow->selectcol_arrayref( "SELECT userid FROM user WHERE statusvis = 'V' AND journaltype = 'P'" );
+my $starttime = $dbslow->selectrow_array( "SELECT UNIX_TIMESTAMP()" );
+
+my $week_ago = $starttime - 60*60*24*7;
+my $month_ago = $starttime - 60*60*24*30;
+
+my $us = LJ::load_userids( @$userids );
+foreach my $userid ( keys %$us ) {
+    my $u = $us->{$userid};
+
+    next if $u->is_paid; # must not be a paid user
+    next unless $u->opt_randompaidgifts; # must allow random paid gifts
+    next if LJ::sysban_check( 'pay_user', $u->user ); # must not be sysbanned from payments
+    next if $u->timecreate > $month_ago; # must be created more than a month ago
+    next if $u->number_of_posts < 10; # must have at least 10 posts
+    next if $u->timeupdate < $week_ago; # must have posted in the past week
+
+    # get the number of entries posted and comments left in the past month
+    my $num_posts = $dbslow->selectrow_array( "SELECT COUNT(*) FROM log2 WHERE journalid = ? AND logtime > ?", undef, $userid, LJ::mysql_time( $month_ago ) );
+    my $num_comments = $dbslow->selectrow_array( "SELECT COUNT(*) FROM talkleft WHERE userid = ? AND posttime > ?", undef, $userid, $month_ago );
+
+    # assign point values based on these numbers
+    my $post_points = min( 10, $num_posts ) || 0;
+    my $comment_points = min( 10, $num_comments ) || 0;
+
+    # insert the total points for the user
+    $dbh->do( "INSERT INTO users_for_paid_accounts ( userid, time_inserted, points ) VALUES ( ?, ?, ? )", undef, $userid, $starttime, $post_points + $comment_points );
+}
+
+# delete all old data
+$dbh->do( "DELETE FROM users_for_paid_accounts WHERE time_inserted < ?", undef, $starttime );
+
+1;
diff -r f42f4796e620 -r c90b294a40e7 cgi-bin/DW/Setting/RandomPaidGifts.pm
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/cgi-bin/DW/Setting/RandomPaidGifts.pm	Sun Aug 09 17:43:37 2009 +0000
@@ -0,0 +1,65 @@
+#!/usr/bin/perl
+#
+# DW::Setting::RandomPaidGifts
+#
+# DW::Setting module for choosing whether you can appear as a choice when others
+# are looking for a random free user to give a paid account to.
+#
+# Authors:
+#      Janine Smith <janine@netrophic.com>
+#
+# Copyright (c) 2009 by Dreamwidth Studios, LLC.
+#
+# This program is free software; you may redistribute it and/or modify it under
+# the same terms as Perl itself.  For a copy of the license, please reference
+# 'perldoc perlartistic' or 'perldoc perlgpl'.
+#
+
+package DW::Setting::RandomPaidGifts;
+use base 'LJ::Setting';
+use strict;
+use warnings;
+
+sub should_render {
+    my ( $class, $u ) = @_;
+
+    return $u->is_personal && !$u->is_perm ? 1 : 0;
+}
+
+sub label {
+    my $class = $_[0];
+
+    return $class->ml( 'setting.randompaidgifts.label' );
+}
+
+sub option {
+    my ( $class, $u, $errs, $args ) = @_;
+    my $key = $class->pkgkey;
+
+    my $randompaidgifts = $class->get_arg( $args, "randompaidgifts" ) || $u->prop( "opt_randompaidgifts" );
+
+    my $ret = LJ::html_check({
+        name => "${key}randompaidgifts",
+        id => "${key}randompaidgifts",
+        value => 1,
+        selected => $randompaidgifts eq 'N' ? 0 : 1,
+    });
+    $ret .= " <label for='${key}randompaidgifts'>";
+    $ret .= $u->is_paid ? $class->ml( 'setting.randompaidgifts.option.paid' ) : $class->ml( 'setting.randompaidgifts.option' );
+    $ret .= "<p class='details'>" . $class->ml( 'setting.randompaidgifts.option.note' ) . "</p>";
+    $ret .= "</label>";
+
+    return $ret;
+}
+
+sub save {
+    my ( $class, $u, $args ) = @_;
+    $class->error_check( $u, $args );
+
+    my $val = $class->get_arg( $args, "randompaidgifts" ) ? 'Y' : 'N';
+    $u->set_prop( opt_randompaidgifts => $val );
+
+    return 1;
+}
+
+1;
diff -r f42f4796e620 -r c90b294a40e7 htdocs/shop/randomgift.bml
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/htdocs/shop/randomgift.bml	Sun Aug 09 17:43:37 2009 +0000
@@ -0,0 +1,66 @@
+<?_c
+#
+# /shop/randomgift.bml
+#
+# Gives a person a random active free user that they can choose to purchase a
+# paid account for.
+#
+# Authors:
+#      Janine Smith <janine@netrophic.com>
+#
+# Copyright (c) 2009 by Dreamwidth Studios, LLC.
+#
+# This program is free software; you may redistribute it and/or modify it under
+# the same terms as Perl itself.  For a copy of the license, please reference
+# 'perldoc perlartistic' or 'perldoc perlgpl'.
+#
+_c?><?page
+body<=
+<?_code
+{
+    use strict;
+    use vars qw/ %GET %POST $title /;
+
+    $title = $ML{'.title'};
+
+    if ( LJ::did_post() ) {
+        my $username = $POST{username};
+        my $u = LJ::load_user( $username );
+        if ( LJ::isu( $u ) ) {
+            return BML::redirect( "$LJ::SITEROOT/shop/account?for=random&user=$username" );
+        }
+    }
+
+    my $randomu = DW::Pay::get_random_active_free_user();
+
+    my $ret;
+
+    $ret .= "<p><a href='$LJ::SITEROOT/shop'>&lt;&lt; " . BML::ml( '.backlink', { sitename => $LJ::SITENAMESHORT } ) . "</a></p>";
+
+    if ( $randomu ) {
+        $ret .= "<p>" . BML::ml( '.intro', { aopts => "href='$LJ::SITEROOT/shop/randomgift'" } ) . "</p>";
+        $ret .= "<p><strong>$ML{'.label.username'}</strong> " . $randomu->ljuser_display . "<br />";
+        $ret .= "<strong>$ML{'.label.createdate'}</strong> " . LJ::mysql_time( $randomu->timecreate ) . "<br />";
+        $ret .= "<strong>$ML{'.label.lastupdated'}</strong> " . substr( LJ::mysql_time( $randomu->timeupdate ), 0, 10 ) . "<br />";
+        $ret .= "<strong>$ML{'.label.numentries'}</strong> " . $randomu->number_of_posted_posts . "<br />";
+        $ret .= "<strong>$ML{'.label.numcomments'}</strong> " . $randomu->num_comments_posted . "<br />";
+        $ret .= "<strong>$ML{'.label.numcommunities'}</strong> " . scalar $randomu->member_of_userids . "<br />";
+        $ret .= "</p>";
+
+        $ret .= "<form method='post'>";
+        $ret .= LJ::html_hidden( username => $randomu->user );
+        $ret .= LJ::html_submit( BML::ml( '.form.submit', { username => $randomu->user } ) ) . " ";
+        $ret .= "<a href='$LJ::SITEROOT/shop/randomgift'>$ML{'.form.getanother'}</a>";
+        $ret .= "</form><br />";
+    } else {
+        $ret .= "<p>$ML{'.nousers'}</p>";
+    }
+
+    $ret .= "<p><a href='$LJ::SITEROOT/shop'>&lt;&lt; " . BML::ml( '.backlink', { sitename => $LJ::SITENAMESHORT } ) . "</a></p>";
+
+    return $ret;
+}
+_code?>
+<=body
+title=><?_code return $title; _code?>
+page?>
diff -r f42f4796e620 -r c90b294a40e7 htdocs/shop/randomgift.bml.text
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/htdocs/shop/randomgift.bml.text	Sun Aug 09 17:43:37 2009 +0000
@@ -0,0 +1,25 @@
+;; -*- coding: utf-8 -*-
+
+.backlink=Back to [[sitename]] Shop
+
+.form.getanother=Find a different random active free user
+
+.form.submit=Purchase a Paid Account for [[username]]
+
+.intro=Here is a random active free user who may appreciate a paid account.  If you'd like to find a different random user, just <a [[aopts]]>refresh</a>.
+
+.label.createdate=Created on:
+
+.label.lastupdated=Last updated on:
+
+.label.numcomments=Number of comments posted:
+
+.label.numcommunities=Number of communities they are a member of:
+
+.label.numentries=Number of entries posted:
+
+.label.username=Username:
+
+.nousers=There are currently no active free users.
+
+.title=Find a Random Active Free User
--------------------------------------------------------------------------------