wisest owl (wisest_owl) wrote in changelog,
wisest owl
wisest_owl
changelog

[ljcom] r9365: LJSUP-6515. Custom Userheads

Committer: gprochaev
LJSUP-6515. Custom Userheads

A   trunk/cgi-bin/LJ/Widget/Shop/View/UserHeads.pm
A   trunk/htdocs/shop/userheads.bml
Added: trunk/cgi-bin/LJ/Widget/Shop/View/UserHeads.pm
===================================================================
--- trunk/cgi-bin/LJ/Widget/Shop/View/UserHeads.pm	                        (rev 0)
+++ trunk/cgi-bin/LJ/Widget/Shop/View/UserHeads.pm	2010-08-20 06:57:48 UTC (rev 9365)
@@ -0,0 +1,115 @@
+package LJ::Widget::Shop::View::UserHeads;
+
+use strict;
+use base 'LJ::Widget::Shop::View';
+use LJ::UserHead;
+use LJ::Pay::Payment::PayItem::UserHead;
+
+sub get_subpage { 'userhead' }
+sub require_remote { 0 }
+
+sub premature_checks {
+    my ($self) = @_;
+
+    $self->SUPER::premature_checks();
+    return if LJ::Request->redirected();
+
+    my $remote = LJ::get_remote();
+    if (!$remote) {
+        $self->{'gift_only'} = 1;
+        $self->ml_warning('shop.view.userheads.warning.disabled.anon');
+    } elsif ($remote->is_identity) {
+        $self->{'gift_only'} = 1;
+        $self->ml_warning('shop.view.userheads.warning.disabled.openid');
+    } else {
+        $self->{'gift_only'} = 0;
+    }
+}
+
+sub gift_only {
+    my ($self) = @_;
+    return $self->{'gift_only'};
+}
+
+sub get_page_params {
+    my ($self) = @_;
+
+    my $remote = LJ::get_remote();
+    my $gift = ((!$remote || LJ::Request->get_param('gift')) && LJ::Request->get_param('giftto')) || 0;
+    my $recipient = $gift ? LJ::load_user(LJ::Request->get_param('giftto')) : undef;
+
+    # [10,6,2] == foreach period, for 1 packet
+    my $js_prices = [];#[ map { $options{$_}{amount} } sort { $b <=> $a } keys %options ];
+    my $js_prices_rcpt = [];#[ map { $options_rcpt{$_}{amount} } sort { $b <=> $a } keys %options_rcpt ];
+
+    my ($sec, $min, $hour, $mday, $mon, $year) = localtime(time);
+
+    # autocomplete To field on Add form
+    my @flist =
+        LJ::isu($remote) ?
+        map { $_->user } ($remote->people_friends) : ();
+    my $js_complete = LJ::JSUtil::autocomplete(list => \@flist);
+
+    my %ret = (
+        siteroot            => $LJ::SITEROOT,
+        is_gift             => $gift,
+        is_self_disabled    => $self->gift_only,
+        userheads           => LJ::UserHead->get_all_userheads (1),
+        default_page        => $gift && LJ::u_equals($remote, $recipient) ? 'gift' : $gift && $recipient ? 'self' : 'gift',
+        rcpt_username       => $recipient && $recipient->user,
+        thispage            => "$LJ::SITEROOT/shop/userheads.bml",
+        giveafter_dd        => LJ::Request->post_param('giveafter_dd') || $mday,
+        giveafter_mm        => LJ::Request->post_param('giveafter_mm') || ($mon + 1),
+        giveafter_yyyy      => LJ::Request->post_param('giveafter_yyyy') || ($year + 1900),
+        js_prices           => LJ::JSON->to_json($js_prices),
+        js_prices_rcpt      => LJ::JSON->to_json($js_prices_rcpt),
+
+        js_complete         => $js_complete,
+
+    );
+
+    return \%ret;
+}
+
+sub process_post_request {
+    my ($self) = @_;
+
+    my $giveafter_dd   = LJ::Request->post_param('giveafter_dd');
+    my $giveafter_mm   = LJ::Request->post_param('giveafter_mm');
+    my $giveafter_yyyy = LJ::Request->post_param('giveafter_yyyy');
+
+    my ($uh_id) = LJ::Request->post_param('uh') =~ m#uh-(\d+)#;
+    my $uh = LJ::UserHead->get_userhead($uh_id);
+
+    my $recipient = 
+        (LJ::Request->get_param('gift') and LJ::Request->get_param('giftto'))
+        ? LJ::load_user(LJ::Request->get_param('giftto'))
+        : LJ::get_remote();
+
+    die "Unknown recipient" unless $recipient;
+
+    my $cart = $self->try_get_cart;
+
+    my $it = LJ::Pay::Payment::PayItem::UserHead->new_memonly(
+        subitem => LJ::Request->post_param('uh'),
+        qty     => 1,
+        amt     => $uh->get_price (), 
+        anon    => LJ::get_remote() ? LJ::Request->post_param('gift_anon') : 1,
+        rcptid  => $recipient->userid,
+    );
+
+    if ($giveafter_yyyy) {
+        my $err_msg = $it->set_giveafter(
+            $giveafter_yyyy, $giveafter_mm, $giveafter_dd,
+            $recipient->timezone
+        );
+    }
+
+    $self->cart->add_item_to_cart($it);
+
+    return LJ::Request->redirect($self->cart->cart_link);
+}
+
+sub get_template_file { 'UserHeads' }
+
+1;

Added: trunk/htdocs/shop/userheads.bml
===================================================================
--- trunk/htdocs/shop/userheads.bml	                        (rev 0)
+++ trunk/htdocs/shop/userheads.bml	2010-08-20 06:57:48 UTC (rev 9365)
@@ -0,0 +1,27 @@
+<?page
+body<=
+<?_code
+{
+
+    use strict;
+    use vars qw(%GET %POST $title $headextra @errors @warnings);
+
+    LJ::set_active_crumb('shop.userheads');
+
+    $title = $ML{'shop.view.userheads.title'};
+
+    use LJ::Pay::Payment::PayItem::Items;
+
+    # Auto redirect to status if disabled
+    return BML::redirect("http://status.livejournal.org/")
+        if $LJ::DISABLED{'recbill_shop'};
+
+    return LJ::Widget::Shop::View::UserHeads->render();
+}
+_code?>
+<=body
+title=><?_code return $title; _code?>
+head<=
+<?_code return $headextra; _code?>
+<=head
+page?>

Tags: bml, ljcom, pm, wisest-owl
Subscribe
  • Post a new comment

    Error

    Anonymous comments are disabled in this journal

    default userpic

    Your reply will be screened

    Your IP address will be recorded 

  • 0 comments