[ljcom] r5365: New disable virtual gift options, so the...

Aug 21, 2007 23:08


Committer: janineNew disable virtual gift options, so the user can disable the receipt of some/all vgifts:
- Don't disable vgifts = available to all, default for all but Paid/Perm
- Disable all vgifts = available to all, default for none
- Disable sponsored vgifts only = available to all but Plus, default for Paid/Perm

U trunk/bin/upgrading/en_LJ.dat
U trunk/bin/upgrading/proplists-local.dat
A trunk/cgi-bin/LJ/Hooks/Settings.pm
U trunk/cgi-bin/LJ/Pay/ShopVGift.pm

Modified: trunk/bin/upgrading/en_LJ.dat
===================================================================
--- trunk/bin/upgrading/en_LJ.dat 2007-08-21 17:35:48 UTC (rev 5364)
+++ trunk/bin/upgrading/en_LJ.dat 2007-08-21 23:08:39 UTC (rev 5365)
@@ -2204,6 +2204,18 @@

ljcom.entryform.box.paidoptions.voicepost2=Voice Posting

+ljcom.extra_privacy_options.vgifts=Virtual Gifts
+
+ljcom.extra_privacy_options.vgifts.disable=Disable the receipt of virtual gifts:
+
+ljcom.extra_privacy_options.vgifts.disable.all=All
+
+ljcom.extra_privacy_options.vgifts.disable.none=Do not disable
+
+ljcom.extra_privacy_options.vgifts.disable.note=Plus users cannot disable only sponsored virtual gifts.
+
+ljcom.extra_privacy_options.vgifts.disable.sponsored=Sponsored only
+
ljcom.interests.sponsored.head=Sponsored Communities

ljcom.lj-replace.first_post<<

Modified: trunk/bin/upgrading/proplists-local.dat
===================================================================
--- trunk/bin/upgrading/proplists-local.dat 2007-08-21 17:35:48 UTC (rev 5364)
+++ trunk/bin/upgrading/proplists-local.dat 2007-08-21 23:08:39 UTC (rev 5365)
@@ -62,6 +62,22 @@
multihomed: 0
prettyname: Assignment Agreement Received

+userproplist.opt_disable_vgifts:
+ cldversion: 4
+ datatype: char
+ des: Specifies which vgifts the user can't receive: 'all' or 'sponsored'. No value means they're not disabled.
+ indexed: 0
+ multihomed: 0
+ prettyname: Disable Receipt of VGifts
+
+userproplist.opt_disable_vgifts_manually_set:
+ cldversion: 4
+ datatype: char
+ des: Unix time that the opt_disable_vgifts prop was explicitly set by the user.
+ indexed: 0
+ multihomed: 0
+ prettyname: Explicit Time of Disabling VGifts
+
userproplist.paid_before_recbill:
cldversion: 4
datatype: num

Added: trunk/cgi-bin/LJ/Hooks/Settings.pm
===================================================================
--- trunk/cgi-bin/LJ/Hooks/Settings.pm 2007-08-21 17:35:48 UTC (rev 5364)
+++ trunk/cgi-bin/LJ/Hooks/Settings.pm 2007-08-21 23:08:39 UTC (rev 5365)
@@ -0,0 +1,61 @@
+#!/usr/bin/perl
+
+package LJ::LJcom;
+use strict;
+
+LJ::register_hook('extra_privacy_options', sub {
+ my $u = shift;
+
+ my $is_plus = $u->in_class('plus') && !$u->in_class('paid');
+ my $sponsored_text = LJ::Lang::ml('ljcom.extra_privacy_options.vgifts.disable.sponsored');
+ $sponsored_text = "$sponsored_text*" if $is_plus;
+
+ my $ret .= "" . LJ::Lang::ml('ljcom.extra_privacy_options.vgifts') . "\n";
+ $ret .= LJ::Lang::ml('ljcom.extra_privacy_options.vgifts.disable') . " ";
+ $ret .= LJ::html_select({ 'name' => 'opt_disable_vgifts',
+ 'id' => 'opt_disable_vgifts',
+ 'selected' => LJ::run_hook('opt_disable_vgifts_value', $u) },
+ "none" => LJ::Lang::ml('ljcom.extra_privacy_options.vgifts.disable.none'),
+ "all" => LJ::Lang::ml('ljcom.extra_privacy_options.vgifts.disable.all'),
+ { value => "sponsored",
+ text => $sponsored_text,
+ disabled => $is_plus });
+ $ret .= "
*" . LJ::Lang::ml('ljcom.extra_privacy_options.vgifts.disable.note') . "" if $is_plus;
+ $ret .= "\n";
+
+ return $ret;
+});
+
+LJ::register_hook('opt_disable_vgifts_value', sub {
+ my $u = shift;
+
+ # if the user is paid and hasn't explicitly set the vgift option, disable sponsored vgits for them
+ # if the user is plus and is disabling sponsored vgifts, make them enable vgifts
+ if (!$u->prop('opt_disable_vgifts_manually_set') && $u->in_class('paid')) {
+ $u->set_prop('opt_disable_vgifts', 'sponsored');
+ } elsif ($u->in_class('plus') && !$u->in_class('paid') && $u->prop('opt_disable_vgifts') eq "sponsored") {
+ $u->set_prop('opt_disable_vgifts', '');
+ }
+
+ return $u->prop('opt_disable_vgifts') || "";
+});
+
+LJ::register_hook('set_extra_privacy_options', sub {
+ my $u = shift;
+ my $post = shift;
+
+ my $posted_val = $post->{opt_disable_vgifts};
+ if (defined $posted_val) {
+ $u->set_prop('opt_disable_vgifts_manually_set', time());
+
+ my $val = $posted_val;
+ $val = "" unless $posted_val eq "sponsored" || $posted_val eq "all";
+ $val = "" if $u->in_class('plus') && !$u->in_class('paid') && $posted_val eq "sponsored";
+
+ $u->set_prop('opt_disable_vgifts', $val);
+ }
+
+ return;
+});
+
+1;

Modified: trunk/cgi-bin/LJ/Pay/ShopVGift.pm
===================================================================
--- trunk/cgi-bin/LJ/Pay/ShopVGift.pm 2007-08-21 17:35:48 UTC (rev 5364)
+++ trunk/cgi-bin/LJ/Pay/ShopVGift.pm 2007-08-21 23:08:39 UTC (rev 5365)
@@ -240,9 +240,10 @@

my @errs = ();

+ my $new_vg;
if ($additem) {
return unless (LJ::Pay::is_vgift($additem->{'subitem'}));
- my $new_vg = LJ::Pay::ShopVGift->new($additem->{'subitem'});
+ $new_vg = LJ::Pay::ShopVGift->new($additem->{'subitem'});
$free_add = $new_vg->is_free * $additem->{'qty'} + 0;

# Don't allow free vgifts to be sent anonymously
@@ -261,9 +262,20 @@
}
}

- # check to see if the recipient has banned the sender
- push @errs, "You can't send vgifts to this user" if $rcptuser->has_banned($u);
+ my $rcpt_disable_vgifts = LJ::run_hook('opt_disable_vgifts_value', $rcptuser);

+ # check to see if the recipient has:
+ # - banned the sender
+ # - disabled all vgifts
+ # - disabled sponsored vgifts
+ if ($new_vg) {
+ if ($rcptuser->has_banned($u) || $rcpt_disable_vgifts eq "all") {
+ push @errs, "Sorry, you can't send virtual gifts to this user.";
+ } elsif ($new_vg->is_promo && $rcpt_disable_vgifts eq "sponsored") {
+ push @errs, "Sorry, you can't send this virtual gift to this user.";
+ }
+ }
+
return @errs;
}

@@ -292,8 +304,20 @@
foreach my $it (@{$cartobj->{items}}) {
next unless $it->{item} eq "vgift";

+ my $vg = LJ::Pay::ShopVGift->new($it->{subitem});
+
my $rcptuser = LJ::load_userid($it->{rcptid});
- return 0 if $rcptuser && $rcptuser->has_banned($u);
+ return 0 unless $rcptuser;
+
+ my $rcpt_disable_vgifts = LJ::run_hook('opt_disable_vgifts_value', $rcptuser);
+
+ # check to see if the recipient has:
+ # - banned the sender
+ # - disabled sponsored vgifts
+ # - disabled all vgifts
+ return 0 if $rcptuser->has_banned($u);
+ return 0 if $rcpt_disable_vgifts eq "all";
+ return 0 if $vg->is_promo && $rcpt_disable_vgifts eq "sponsored";
}

return 1;

Previous post Next post
Up