[dw-free] Implement v-gifts
[commit: http://hg.dwscoalition.org/dw-free/rev/0a7dcc4d9f1f]
http://bugs.dwscoalition.org/show_bug.cgi?id=215
Setting to control who can send you vgifts (will only be made visible once
we are closer to having vgifts in the shop).
Patch by
kareila.
Files modified:
http://bugs.dwscoalition.org/show_bug.cgi?id=215
Setting to control who can send you vgifts (will only be made visible once
we are closer to having vgifts in the shop).
Patch by
Files modified:
- bin/upgrading/en.dat
- bin/upgrading/proplists.dat
- cgi-bin/DW/Setting/AllowVgiftsFrom.pm
- cgi-bin/LJ/Event/Birthday.pm
- cgi-bin/LJ/User.pm
- cgi-bin/LJ/Widget/FriendBirthdays.pm
- htdocs/manage/settings/index.bml
--------------------------------------------------------------------------------
diff -r e8854e4f674b -r 0a7dcc4d9f1f bin/upgrading/en.dat
--- a/bin/upgrading/en.dat Fri Oct 29 18:15:36 2010 +0800
+++ b/bin/upgrading/en.dat Fri Oct 29 19:03:05 2010 +0800
@@ -1805,6 +1805,8 @@ This letter was sent out automatically t
This letter was sent out automatically to help you keep your account secure. You cannot opt-out of receiving these letters.
.
+esn.shop_for_gift=Buy a gift from our shop:
+
esn.supofficialpost.html=There is <a href="[[url]]">a new announcement</a> in [[username]]
esn.supofficialpost.nosubject=[[sitenameshort]] Announcement: New [[username]] announcement
@@ -2532,6 +2534,26 @@ setting.allowsearchby.sel.f=Allow people
setting.allowsearchby.sel.f=Allow people on my access list to search my journal (default)
setting.allowsearchby.sel.n=Allow nobody else (only me) to search my journal
+
+setting.allowvgiftsfrom.anon=Allow sender to remain anonymous
+
+setting.allowvgiftsfrom.error=Invalid selection.
+
+setting.allowvgiftsfrom.label=Allow Virtual Gifts From
+
+setting.allowvgiftsfrom.sel.a=Anyone
+
+setting.allowvgiftsfrom.sel.c=Users in my circle
+
+setting.allowvgiftsfrom.sel.g=Users in the access group:
+
+setting.allowvgiftsfrom.sel.m=Community members
+
+setting.allowvgiftsfrom.sel.n=Nobody
+
+setting.allowvgiftsfrom.sel.r=Registered users
+
+setting.allowvgiftsfrom.sel.t=Trusted users
setting.bio.desc|notes=There shouldn't be a description unless the page specifies one
setting.bio.desc=_none
@@ -4508,8 +4530,6 @@ widget.friendbirthdays.friends_link=View
widget.friendbirthdays.gift=Gift
-widget.friendbirthdays.paidtime_link=Find out which friends need paid time
-
widget.friendbirthdays.title=Birthdays
widget.friendbirthdays.userbirthday=[[month]] [[day]]
diff -r e8854e4f674b -r 0a7dcc4d9f1f bin/upgrading/proplists.dat
--- a/bin/upgrading/proplists.dat Fri Oct 29 18:15:36 2010 +0800
+++ b/bin/upgrading/proplists.dat Fri Oct 29 19:03:05 2010 +0800
@@ -565,6 +565,22 @@ userproplist.opt_allowsearchby:
indexed: 0
multihomed: 0
prettyname: Allow Search By
+
+userproplist.opt_allowvgiftsfrom:
+ cldversion: 4
+ datatype: char
+ des: all/registered/circle/access/(trustmask)/none
+ indexed: 0
+ multihomed: 0
+ prettyname: Allow Virtual Gifts From
+
+userproplist.opt_anonvgift_optout:
+ cldversion: 4
+ datatype: bool
+ des: If true, user does not want to receive "anonymous" vgifts.
+ indexed: 0
+ multihomed: 0
+ prettyname: Opt Out Of Anonymous Virtual Gifts
userproplist.opt_bdaymail:
cldversion: 0
diff -r e8854e4f674b -r 0a7dcc4d9f1f cgi-bin/DW/Setting/AllowVgiftsFrom.pm
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/cgi-bin/DW/Setting/AllowVgiftsFrom.pm Fri Oct 29 19:03:05 2010 +0800
@@ -0,0 +1,113 @@
+#!/usr/bin/perl
+#
+# DW::Setting::AllowVgiftsFrom
+#
+# LJ::Setting module for allowing a user to restrict
+# who can send virtual gifts to that user or to
+# opt out of receiving anonymous virtual gifts.
+#
+# Authors:
+# Jen Griffin <kareila@livejournal.com>
+#
+# Copyright (c) 2010 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::AllowVgiftsFrom;
+use base 'LJ::Setting';
+use strict;
+use warnings;
+
+sub should_render {
+ my ( $class, $u ) = @_;
+ return exists $LJ::SHOP{vgifts};
+}
+
+sub label {
+ my $class = $_[0];
+ return $class->ml( 'setting.allowvgiftsfrom.label' );
+}
+
+sub option {
+ my ( $class, $u, $errs, $args ) = @_;
+ my $key = $class->pkgkey;
+
+ my $allowed = $class->get_arg( $args, "allowvgiftsfrom" )
+ || $u->prop( 'opt_allowvgiftsfrom' ) || 'all';
+ my $anonopt = $class->get_arg( $args, "anonvgift_optout" )
+ || $u->prop( 'opt_anonvgift_optout' ) || 0;
+
+ my %menu_items = (
+ all => [ qw( all a ) ],
+ registered => [ qw( registered r ) ],
+ circle => [ qw( circle c ) ],
+ access => [ qw( access t ) ],
+ members => [ qw( access m ) ],
+ none => [ qw( none n ) ],
+ );
+
+ my @opts;
+ if ( $u->is_community ) {
+ @opts = map { $menu_items{$_}->[0], $class->ml( "setting.allowvgiftsfrom.sel.$menu_items{$_}->[1]" ) }
+ qw( all registered members none );
+ } else {
+ @opts = map { $menu_items{$_}->[0], $class->ml( "setting.allowvgiftsfrom.sel.$menu_items{$_}->[1]" ) }
+ qw( all registered circle access none );
+
+ # trust group selection
+ my @groups = sort { $a->{sortorder} <=> $b->{sortorder} }
+ $u->trust_groups;
+ if ( @groups ) {
+ my @items;
+ push @items, { value => $_->{groupnum}, text => $_->{groupname} }
+ foreach @groups;
+
+ push @opts, { optgroup => $class->ml( 'setting.allowvgiftsfrom.sel.g' ), items => \@items };
+ }
+ }
+
+ my $ret = LJ::html_select( { name => "${key}allowvgiftsfrom",
+ id => "${key}allowvgiftsfrom",
+ selected => $allowed },
+ @opts );
+
+ my $errdiv = $class->errdiv( $errs, "allowvgiftsfrom" );
+ $ret .= $errdiv if $errdiv;
+
+ $ret .= "<br />\n";
+ # anonymous optout
+ $ret .= ' ';
+ $ret .= LJ::html_check( { name => "${key}anonvgift_optout",
+ id => "${key}anonvgift_optout",
+ label => $class->ml( 'setting.allowvgiftsfrom.anon' ),
+ selected => $anonopt } );
+ return $ret;
+}
+
+sub error_check {
+ my ( $class, $u, $args ) = @_;
+
+ my $allowed = $class->get_arg( $args, "allowvgiftsfrom" );
+ $class->errors( allowvgiftsfrom => $class->ml( 'setting.allowvgiftsfrom.error' ) )
+ if $allowed && $allowed !~ /^(?:all|registered|circle|access|none|\d+)$/;
+
+ return 1;
+}
+
+sub save {
+ my ( $class, $u, $args ) = @_;
+ $class->error_check( $u, $args );
+
+ my $allowed = $class->get_arg( $args, "allowvgiftsfrom" );
+ my $anonopt = $class->get_arg( $args, "anonvgift_optout" );
+
+ $u->set_prop( 'opt_allowvgiftsfrom' => $allowed ) if $allowed;
+ $u->set_prop( 'opt_anonvgift_optout' => $anonopt ? 1 : 0 );
+
+ return 1;
+}
+
+1;
diff -r e8854e4f674b -r 0a7dcc4d9f1f cgi-bin/LJ/Event/Birthday.pm
--- a/cgi-bin/LJ/Event/Birthday.pm Fri Oct 29 18:15:36 2010 +0800
+++ b/cgi-bin/LJ/Event/Birthday.pm Fri Oct 29 19:03:05 2010 +0800
@@ -133,6 +133,7 @@ sub _as_email {
$self->format_options($is_html, $lang, undef,
{
'esn.post_happy_bday' => [ 1, "$LJ::SITEROOT/update" ],
+ 'esn.shop_for_gift' => [ LJ::is_enabled( 'payments' ) ? 2 : 0, $self->bdayuser->gift_url ],
},
LJ::Hooks::run_hook('birthday_notif_extra_' . ($is_html ? 'html' : 'plaintext'), $u)
);
diff -r e8854e4f674b -r 0a7dcc4d9f1f cgi-bin/LJ/User.pm
--- a/cgi-bin/LJ/User.pm Fri Oct 29 18:15:36 2010 +0800
+++ b/cgi-bin/LJ/User.pm Fri Oct 29 19:03:05 2010 +0800
@@ -2006,6 +2006,48 @@ sub can_post_disabled {
return $_[0]->get_cap( 'disable_can_post' ) ? 1 : 0;
}
+sub can_receive_vgifts_from {
+ my ( $u, $remote, $is_anon ) = @_;
+ $remote ||= LJ::get_remote();
+ my $valid_remote = LJ::isu( $remote ) ? 1 : 0;
+
+ # check for shop status
+ return 0 unless exists $LJ::SHOP{vgifts};
+
+ # check for anonymous
+ return 0 if $is_anon && $u->prop( 'opt_anonvgift_optout' );
+
+ # if the prop isn't set, default to true
+ my $prop = $u->prop( 'opt_allowvgiftsfrom' );
+ return 1 unless $prop;
+
+ # all: always true; none: always false
+ return 1 if $prop eq 'all';
+ return 0 if $prop eq 'none';
+
+ # registered: must have $remote
+ return $valid_remote if $prop eq 'registered';
+ return 0 unless $valid_remote; # shortcut: skip remaining tests
+
+ # access: anyone on trust/membership list
+ return $u->trusts_or_has_member( $remote ) if $prop eq 'access';
+
+ # remaining options not allowed for communities
+ return 0 if $u->is_community;
+
+ # circle: also includes watch list
+ return $u->watches( $remote ) || $u->trusts( $remote )
+ if $prop eq 'circle';
+
+ # only remaining valid option: trust group, which must be numeric.
+ # if it's not a valid value, assume false
+ return 0 unless $prop =~ /^\d+$/;
+
+ # check the trustmask
+ my $mask = 1 << $prop;
+ return ( $u->trustmask( $remote ) & $mask );
+}
+
sub can_show_location {
my $u = shift;
croak "invalid user object passed" unless LJ::isu($u);
@@ -2302,6 +2344,12 @@ sub get_cap {
my ( $u, $cname ) = @_;
return 1 if $LJ::T_HAS_ALL_CAPS;
return LJ::get_cap( $u, $cname );
+}
+
+# returns the gift shop URL to buy a gift for that user
+sub gift_url {
+ my ( $u ) = @_;
+ return "$LJ::SITEROOT/shop/account?for=gift&user=" . $u->user;
}
@@ -6963,13 +7011,6 @@ sub show_mutualfriends {
}
-# FIXME: Needs updating for our gift shop
-# after that, it goes in section 7
-# returns the gift shop URL to buy a gift for that user
-sub gift_url {
- return "$LJ::SITEROOT/shop/account?for=gift";
-}
-
########################################################################
diff -r e8854e4f674b -r 0a7dcc4d9f1f cgi-bin/LJ/Widget/FriendBirthdays.pm
--- a/cgi-bin/LJ/Widget/FriendBirthdays.pm Fri Oct 29 18:15:36 2010 +0800
+++ b/cgi-bin/LJ/Widget/FriendBirthdays.pm Fri Oct 29 19:03:05 2010 +0800
@@ -56,7 +56,7 @@ sub render_body {
$ret .= "<tr>";
$ret .= "<td>" . $u->ljuser_display . "</td>";
$ret .= "<td>" . $class->ml('widget.friendbirthdays.userbirthday', {'month' => LJ::Lang::month_short($month), 'day' => $day}) . "</td>";
- $ret .= "<td><a href='$LJ::SITEROOT/shop/account?for=gift&user=" . $u->user . "' class='gift-link'>";
+ $ret .= "<td><a href='" . $u->gift_url . "' class='gift-link'>";
$ret .= $class->ml('widget.friendbirthdays.gift') . "</a></td>";
$ret .= "</tr>";
}
@@ -66,9 +66,6 @@ sub render_body {
$ret .= "<p class='indent_sm'>» <a href='$LJ::SITEROOT/birthdays'>" .
$class->ml('widget.friendbirthdays.friends_link') .
"</a></p>" if $opts{friends_link};
- $ret .= "<p class='indent_sm'>» <a href='$LJ::SITEROOT/paidaccounts/friends.bml'>" .
- $class->ml('widget.friendbirthdays.paidtime_link') .
- "</a></p>" if $opts{paidtime_link};
return $ret;
}
diff -r e8854e4f674b -r 0a7dcc4d9f1f htdocs/manage/settings/index.bml
--- a/htdocs/manage/settings/index.bml Fri Oct 29 18:15:36 2010 +0800
+++ b/htdocs/manage/settings/index.bml Fri Oct 29 19:03:05 2010 +0800
@@ -132,6 +132,7 @@ body<=
LJ::Setting::CommentCaptcha
LJ::Setting::CommentIP
LJ::Setting::Display::BanUsers
+ DW::Setting::AllowVgiftsFrom
DW::Setting::RandomPaidGifts
DW::Setting::GlobalSearch
DW::Setting::AllowSearchBy
--------------------------------------------------------------------------------
