Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Revamped plugins/Subscribe to use the users_hits table and to fix

some problems with earlier versions.
  • Loading branch information...
commit 1f20b24abceac6c13f86044bdc8bbee4188a7ae4 1 parent 11b98e3
Jamie McCarthy jamiemccarthy authored
20 Slash/Apache/Log/Log.pm
View
@@ -40,14 +40,22 @@ sub UserLog {
my $user = getCurrentUser();
return if !$user or !$user->{uid} or $user->{is_anon};
- my $slashdb = getCurrentDB();
- my $user_update = { -hits => 'hits+1' };
- my $subscribe = getObject('Slash::Subscribe');
- if ($subscribe and $subscribe->buyingThisPage($r)) {
- $user_update->{-hits_bought} = 'hits_bought+1';
+ my $user_update = undef;
+ my $slashdb = getCurrentDB();
+ my $constants = getCurrentStatic();
+ if ($constants->{subscribe}) {
+ my $is_subscriber = $user->{hits_paidfor}
+ && $user->{hits_bought} < $user->{hits_paidfor};
+ if ($is_subscriber || !$constants->{subscribe_hits_only}) {
+ $user_update = { -hits => 'hits+1' };
+ my $subscribe = getObject('Slash::Subscribe');
+ if ($subscribe and $subscribe->buyingThisPage($r)) {
+ $user_update->{-hits_bought} = 'hits_bought+1';
+ }
+ }
}
- $slashdb->setUser($user->{uid}, $user_update);
+ $slashdb->setUser($user->{uid}, $user_update) if $user_update;
return OK;
}
23 Slash/DB/MySQL/MySQL.pm
View
@@ -1148,6 +1148,7 @@ sub createUser {
$self->sqlInsert("users_prefs", { uid => $uid });
$self->sqlInsert("users_comments", { uid => $uid });
$self->sqlInsert("users_index", { uid => $uid });
+ $self->sqlInsert("users_hits", { uid => $uid });
$self->sqlInsert("users_count", { uid => $uid });
# All param fields should be set here, as some code may not behave
@@ -3728,7 +3729,6 @@ sub getSubmissionForUser {
########################################################
sub calcModval {
my($self, $where_clause, $halflife, $minicache) = @_;
-#my $start_time = Time::HiRes::time();
# There's just no good way to do this with a join; it takes
# over 1 second and if either comment posting or moderation
@@ -3747,7 +3747,6 @@ sub calcModval {
# get the moderatorlog valsum twice.
my $cid_text = join(",", @$cid_ar);
if ($minicache and defined($minicache->{$cid_text})) {
-#printf STDERR "cM 1 %4d %6.3f %7.3f\n", scalar(@$cid_ar), Time::HiRes::time()-$start_time, $minicache->{$cid_text};
return $minicache->{$cid_text};
}
@@ -3779,7 +3778,6 @@ sub calcModval {
}
$minicache->{$cid_text} = $modval if $minicache;
-#printf STDERR "cM 0 %4d %6.3f %7.3f\n", scalar(@$cid_ar), Time::HiRes::time()-$start_time, $modval;
$modval;
}
@@ -3847,23 +3845,17 @@ sub getIsTroll {
my $uid_hoursback = $constants->{istroll_uid_hours} || 72;
my($modval, $trollpoint);
my $minicache = { };
-#my $time = time;
# Check for modval by IPID.
$trollpoint = -abs($constants->{istroll_downmods_ip}) - $good_behavior;
$modval = $self->calcModval("ipid = '$user->{ipid}'",
$ipid_hoursback, $minicache);
-#my $idstuff = "";
-#$idstuff = " uid $user->{uid}" if !$user->{is_anon};
-#$idstuff .= " ipid '$user->{ipid}' subnetid '$user->{subnetid}'";
-#printf STDERR "gIT %d %d ip modval %.3f trollpoint %d%s\n", $time, ($modval <= $trollpoint?1:0), $modval, $trollpoint, $idstuff;
return 1 if $modval <= $trollpoint;
# Check for modval by subnet.
$trollpoint = -abs($constants->{istroll_downmods_subnet}) - $good_behavior;
$modval = $self->calcModval("subnetid = '$user->{subnetid}'",
$ipid_hoursback, $minicache);
-#printf STDERR "gIT %d %d subnet modval %.3f trollpoint %d %s\n", $time, ($modval <= $trollpoint?1:0), $modval, $trollpoint, $idstuff;
return 1 if $modval <= $trollpoint;
# At this point, if the user is not logged in, then we don't need
@@ -3873,7 +3865,6 @@ sub getIsTroll {
# Check for modval by user ID.
$trollpoint = -abs($constants->{istroll_downmods_user}) - $good_behavior;
$modval = $self->calcModval("comments.uid = $user->{uid}", $uid_hoursback);
-#printf STDERR "gIT %d %d user modval %.3f trollpoint %d%s\n", $time, ($modval <= $trollpoint?1:0), $modval, $trollpoint, $idstuff;
return 1 if $modval <= $trollpoint;
# All tests passed, user is not a troll.
@@ -4583,6 +4574,7 @@ sub setUser {
my $tables = [qw(
users users_comments users_index
users_info users_prefs
+ users_hits
)];
# special cases for password, exboxes, people
@@ -4659,7 +4651,7 @@ sub getUser {
my $answer;
my $tables = [qw(
users users_comments users_index
- users_info users_prefs
+ users_info users_prefs users_hits
)];
# The sort makes sure that someone will always get the cache if
# they have the same tables
@@ -4718,7 +4710,8 @@ sub getUser {
# users_comments.
my $n = getCurrentStatic('num_users_selects') || 1;
- my @tables_ordered = qw( users users_index users_info
+ my @tables_ordered = qw( users users_index
+ users_info users_hits
users_comments users_prefs );
while ($n > 0) {
my @tables_thispass = ( );
@@ -4766,12 +4759,6 @@ sub getUser {
}
$answer->{'people'} = thaw($answer->{'people'}) if $answer->{'people'};
- # Why is this here? We keep biz logic out of this layer.
- # getUser() returns the user info, not an actual user hash
- # which has the is_admin stuff in it and such.
- # -Brian
- $answer->{is_anon} = isAnon($id);
-
# ... and for scalars
} else {
if ($val eq 'people') {
10 Slash/DB/Static/MySQL/MySQL.pm
View
@@ -319,6 +319,8 @@ sub deleteDaily {
########################################################
# For dailystuff
+# With users_hits now storing "lastclick", this gets a lot
+# easier. - Jamie XXX
sub updateStamps {
my($self) = @_;
my $columns = "uid";
@@ -518,6 +520,14 @@ WHERE section='$_->{section}'
AND displaystatus > -1
EOT
+ $_->{count_sectional} =
+ $self->{_dbh}->selectrow_array(<<EOT);
+SELECT COUNT(*) FROM stories
+WHERE section='$_->{section}'
+ AND TO_DAYS(NOW()) - TO_DAYS(time) <= 2 AND time < NOW()
+ AND displaystatus > 0
+EOT
+
}
return $sections;
9 Slash/Utility/Anchor/Anchor.pm
View
@@ -302,9 +302,12 @@ sub getAd {
my($num, $log) = @_;
$num ||= 1;
- my $subscribe = getObject('Slash::Subscribe');
- if ($subscribe and $subscribe->buyingThisPage()) {
- return "\n<!-- subscriber, no ad -->\n";
+ my $constants = getCurrentStatic();
+ if ($constants->{subscribe}) {
+ my $subscribe = getObject('Slash::Subscribe');
+ if ($subscribe and $subscribe->buyingThisPage()) {
+ return "\n<!-- subscriber, no ad -->\n";
+ }
}
unless ($ENV{SCRIPT_NAME}) {
2  Slash/Utility/Environment/Environment.pm
View
@@ -1185,7 +1185,7 @@ sub filter_params {
# fields that are numeric only
my %nums = map {($_ => 1)} qw(
- artcount bseclev cid clbig clsmall
+ artcount bseclev buymore cid clbig clsmall
commentlimit commentsort commentspill
commentstatus del displaystatus
filter_id height highlightthresh
1  plugins/Subscribe/PLUGIN
View
@@ -1,6 +1,7 @@
name=Subscribe
description="Subscription system"
htdoc=subscribe.pl
+mysql_dump=mysql_dump
mysql_schema=mysql_schema
task=subscribemail.pl
template=edit;subscribe;default
37 plugins/Subscribe/Subscribe.pm
View
@@ -38,20 +38,16 @@ sub buyingThisPage {
my($self, $r) = @_;
my $user = getCurrentUser();
+ my $uid = $user->{uid} || 0;
return 0 if !$user
- || !$user->{uid}
- || $user->{is_anon}
- || !$user->{hits_paidfor}
+ || !$uid
+ || $user->{is_anon};
+
+ return 0 if !$user->{hits_paidfor}
|| ( $user->{hits_bought}
&& $user->{hits_bought} >= $user->{hits_paidfor} );
- if ($user->{"boughtpage_ALL"}) {
- if (getCurrentStatic('subscribe_debug')) {
- print STDERR "buyingThisPage $user->{uid} $user->{hits_bought} $user->{hits_paidfor} ALL\n";
- }
- return 1;
- }
-
+ my $buying = 0;
$r ||= Apache->request;
my $uri = $r->uri;
if ($uri eq '/') {
@@ -59,14 +55,19 @@ sub buyingThisPage {
} else {
$uri =~ s{^.*/([^/]+)\.pl$}{$1};
}
- if ($user->{"boughtpage_$uri"}) {
- if (getCurrentStatic('subscribe_debug')) {
- print STDERR "buyingThisPage $user->{uid} $user->{hits_bought} $user->{hits_paidfor} uri '$uri'\n";
- }
- return 1;
- }
-
- return 0;
+ if ($uri =~ /^(index|article|comments)$/) {
+ $buying = 1 if $user->{"buypage_$uri"};
+ } else {
+ $buying = 1 if $user->{buypage_index}
+ or $user->{buypage_article}
+ or $user->{buypage_comments};
+ }
+ if (getCurrentStatic('subscribe_debug')) {
+ print STDERR "buyingThisPage $buying $user->{uid}"
+ . " $user->{hits_bought} $user->{hits_paidfor}"
+ . " uri '$uri'\n";
+ }
+ return $buying;
}
1;
25 plugins/Subscribe/edit;subscribe;default
View
@@ -3,12 +3,12 @@ default
__description__
Edit subscription information
-* user = passed in by default. Fields used are boughtpage_*
+* user = passed in by default. Fields used are buypage_*
and hits_{paidfor,bought}.
* user_update = also passed in; supercedes user where its
fields are present.
* pages = arrayref of hashrefs, each hashref having fields:
- pagename = name of the page type to append to "boughtpage_"
+ pagename = name of the page type to append to "buypage_"
descr = description to print for page name
__title__
@@ -24,17 +24,12 @@ __template__
[%
pages = [
- { pagename => "ALL",
- descr => "<b>All pages</b><br>&nbsp;&nbsp;&nbsp;'Ads' permits options below
- <br>&nbsp;&nbsp;&nbsp;'No&nbsp;Ads' overrides options below" },
{ pagename => "index",
descr => "<b>Homepage</b>" },
- { pagename => "articles",
+ { pagename => "article",
descr => "<b>Stories</b> (usually with reader comments)" },
{ pagename => "comments",
descr => "<b>Comments</b>" },
- { pagename => "users",
- descr => "<b>Users</b> (usually your preferences)" },
];
%]
@@ -42,7 +37,7 @@ __template__
hits_paidfor = user_update.hits_paidfor || user.hits_paidfor || 0;
hits_bought = user_update.hits_bought || user.hits_bought || 0;
FOREACH page = pages;
- thispagename = "boughtpage_${page.pagename}";
+ thispagename = "buypage_${page.pagename}";
IF user_update.$thispagename.defined;
page.isbought = user_update.$thispagename;
ELSE;
@@ -68,22 +63,20 @@ and have so far used up [% hits_bought %] of them.
|| (hits_paidfor && ( hits_paidfor > hits_bought ) ) %]
<P>We give you some control over deciding which pages
- you want your money to sponsor. To shut off all ads, click
- "No&nbsp;Ads"-"All&nbsp;Pages." For finer-grained control, click
- "Ads"-"All&nbsp;Pages" and then shut them off explicitly, for
- whatever pages you want to sponsor.
+ you want your money to sponsor. By default, you sponsor
+ everything but comments pages.
<P><TABLE BORDER=0 CELLSPACING=1 WIDTH="100%">
- <TR><TH>Ads</TH><TH>&nbsp;No&nbsp;Ads&nbsp;</TH><TH WIDTH="100%">&nbsp;</TH></TR>
+ <TR><TH>&nbsp;Ads&nbsp;</TH><TH>&nbsp;No&nbsp;Ads&nbsp;</TH><TH WIDTH="100%">&nbsp;</TH></TR>
[% FOREACH page = pages %]
<TR>
<TD VALIGN="top" ALIGN="center"><INPUT TYPE="RADIO"
- NAME="boughtpage_[% page.pagename %]"
+ NAME="buypage_[% page.pagename %]"
VALUE="0" [% IF !page.isbought; " CHECKED"; END %]></TD>
<TD VALIGN="top" ALIGN="center"><INPUT TYPE="RADIO"
- NAME="boughtpage_[% page.pagename %]"
+ NAME="buypage_[% page.pagename %]"
VALUE="1" [% IF page.isbought; " CHECKED"; END %]></TD>
<TD VALIGN="top" ALIGN="left">&nbsp;[% page.descr %]</TD>
</TR>
3  plugins/Subscribe/mysql_dump
View
@@ -0,0 +1,3 @@
+INSERT INTO vars (name, value, description) VALUES ('subscribe', 1, 'Subscriptions enabled?');
+INSERT INTO vars (name, value, description) VALUES ('subscribe_debug', 0, 'Debug plugins/Subscribe?');
+INSERT INTO vars (name, value, description) VALUES ('subscribe_hits_only', 1, '0=All users get users_hits updated, 1=Only subscribed users');
2  plugins/Subscribe/mysql_schema
View
@@ -1,2 +1,2 @@
-ALTER TABLE users_info ADD COLUMN hits_bought INT DEFAULT 0 NOT NULL AFTER hits, ADD COLUMN hits_paidfor INT DEFAULT 0 NOT NULL AFTER hits_bought;
+ALTER TABLE users_hits ADD COLUMN hits_bought INT DEFAULT 0 NOT NULL AFTER hits, ADD COLUMN hits_paidfor INT DEFAULT 0 NOT NULL AFTER hits_bought;
2  plugins/Subscribe/subscribe.pl
View
@@ -68,7 +68,7 @@ sub save {
$user_update->{hits_paidfor} = $user->{hits_paidfor} || 0;
$user_update->{hits_paidfor} += $buymore;
}
- for my $key (grep /^boughtpage_\w+$/, keys %$form) {
+ for my $key (grep /^buypage_\w+$/, keys %$form) {
# Empty string means delete the row from users_param.
$user_update->{$key} = $form->{$key} ? 1 : "";
}
2  plugins/Subscribe/subscribemail.pl
View
@@ -19,7 +19,7 @@
slashdLog('Send Subscribe Mail Begin');
- my $subscribers = $slashdb->sqlCount('users_info', 'hits_paidfor > 0');
+ my $subscribers = $slashdb->sqlCount('users_hits', 'hits_paidfor > 0');
my @numbers = (
$subscribers
13 sql/mysql/slashschema_create.sql
View
@@ -718,6 +718,18 @@ CREATE TABLE users_count (
# Table structure for table 'users_index'
#
+DROP TABLE IF EXISTS users_hits;
+CREATE TABLE users_hits (
+ uid mediumint UNSIGNED NOT NULL,
+ lastclick TIMESTAMP,
+ hits int DEFAULT '0' NOT NULL,
+ PRIMARY KEY (uid)
+) TYPE = myisam;
+
+#
+# Table structure for table 'users_index'
+#
+
DROP TABLE IF EXISTS users_index;
CREATE TABLE users_index (
uid mediumint UNSIGNED NOT NULL,
@@ -738,7 +750,6 @@ CREATE TABLE users_index (
DROP TABLE IF EXISTS users_info;
CREATE TABLE users_info (
uid mediumint UNSIGNED NOT NULL,
- hits int DEFAULT '0' NOT NULL,
totalmods mediumint DEFAULT '0' NOT NULL,
realname varchar(50),
bio text,
Please sign in to comment.
Something went wrong with that request. Please try again.