Skip to content

Commit

Permalink
Bugfixes, most notably the way that the default selection of pages is
Browse files Browse the repository at this point in the history
handled.  Now, Subscribe.pm knows that selection and will use it for
users who have not clicked Save to pick one for themselves.
  • Loading branch information
jamiemccarthy committed Mar 1, 2002
1 parent 8100277 commit 1b09466
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 21 deletions.
26 changes: 25 additions & 1 deletion plugins/Subscribe/Subscribe.pm
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,17 @@ sub new {
my $plugins = $slashdb->getDescriptions('plugins');
return unless $plugins->{Subscribe};

$self->{defpage} = {
map { ( $_, 1 ) }
split / /, (
getCurrentStatic("subscribe_defpages")
|| "index"
)
};
$self->{defpage}{index} ||= 0;
$self->{defpage}{article} ||= 0;
$self->{defpage}{comments} ||= 0;

bless($self, $class);

return $self;
Expand All @@ -45,6 +56,8 @@ sub _subscribeDecisionPage {
|| ( $user->{hits_bought}
&& $user->{hits_bought} >= $user->{hits_paidfor} );

# The user has paid for pages and may be buying this one.

my $decision = 0;
$r ||= Apache->request;
my $uri = $r->uri;
Expand All @@ -54,7 +67,18 @@ sub _subscribeDecisionPage {
$uri =~ s{^.*/([^/]+)\.pl$}{$1};
}
if ($uri =~ /^(index|article|comments)$/) {
$decision = 1 if $user->{"buypage_$uri"};
# We check to see if the user has saved preferences for
# which page types they want to buy. This assumes the
# data like $user->{buypage_index} is stored in
# users_param; if the first (alphabetic) page listed
# in the var does not exist, then we simply use the
# default values.
my $first_defpage = (sort keys %{$self->{defpage}})[0];
if (exists $user->{"buypage_$first_defpage"}) {
$decision = 1 if $user->{"buypage_$uri"};
} else {
$decision = 1 if $self->{defpage}{$uri};
}
} elsif ($trueOnOther) {
$decision = 1 if $user->{buypage_index}
or $user->{buypage_article}
Expand Down
41 changes: 21 additions & 20 deletions plugins/Subscribe/subscribe.pl
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ sub main {
# subscribe.pl is not yet for regular users
if ($user->{seclev} < 100
&& $op ne 'paypal'
&& $op ne 'pause'
&& $user->{hits_paidfor} == 0) {
my $rootdir = getCurrentStatic('rootdir');
redirect("$rootdir/users.pl");
Expand Down Expand Up @@ -70,14 +71,13 @@ sub edit {
}
$user_edit ||= $user;

my $subscribe = getObject('Slash::Subscribe');
my @defpages = sort keys %{$subscribe->{defpage}};
my $edited_defaults_yet = exists $user->{"buypage_$defpages[0]"};
my $user_newvalues = { };
my $bought_nothing_yet = ($user_edit->{hits_paidfor} ? 0 : 1);
if ($bought_nothing_yet) {
if ($constants->{subscribe_defpages}) {
my @defpages = split / /, $constants->{subscribe_defpages};
for my $page (@defpages) {
$user_newvalues->{"buypage_$page"} = 1;
}
if (!$edited_defaults_yet) {
for my $page (@defpages) {
$user_newvalues->{"buypage_$page"} = $subscribe->{defpage}{$page};
}
}

Expand Down Expand Up @@ -107,9 +107,12 @@ sub save {
if $form->{secretword} eq $constants->{subscribe_secretword}
or $user->{seclev} >= 100;

my $subscribe = getObject('Slash::Subscribe');
my @defpages = sort keys %{$subscribe->{defpage}};
my $edited_defaults_yet = exists $user->{"buypage_$defpages[0]"};

my $user_update = { };
my $user_newvalues = { };
my $bought_nothing_yet = ($user_edit->{hits_paidfor} ? 0 : 1);
if ($has_buying_permission) {
my($buymore) = $form->{buymore} =~ /(\d+)/;
if ($buymore) {
Expand All @@ -119,20 +122,18 @@ sub save {
$user_edit->{hits_paidfor} + $buymore;
}
}
if (!$edited_defaults_yet) {
# Set default values in case some of the form fields
# somehow aren't sent to us.
for my $page (@defpages) {
$user_newvalues->{"buypage_$page"} = $subscribe->{defpage}{$page};
}
}
for my $key (grep /^buypage_\w+$/, keys %$form) {
# Empty string means delete the row from users_param.
# False value (probably empty string) means set the row to 0
# in users_param.
$user_newvalues->{$key} =
$user_update->{$key} = $form->{$key} ? 1 : "";
}
if ($bought_nothing_yet) {
my @buypage_updates = grep /^buypage_/, keys %$user_update;
if (!@buypage_updates && $constants->{subscribe_defpages}) {
my @defpages = split / /, $constants->{subscribe_defpages};
for my $page (@defpages) {
$user_newvalues->{"buypage_$page"} =
$user_update->{"buypage_$page"} = 1 if $page;
}
}
$user_update->{$key} = $form->{$key} ? 1 : 0;
}
$slashdb->setUser($user_edit->{uid}, $user_update);

Expand Down

0 comments on commit 1b09466

Please sign in to comment.