Committer: afedorov
LJSUP-8689: Donate buttonU trunk/cgi-bin/LJ/S2.pm U trunk/cgi-bin/LJ/Talk.pm
Modified: trunk/cgi-bin/LJ/S2.pm =================================================================== --- trunk/cgi-bin/LJ/S2.pm 2011-05-24 08:43:51 UTC (rev 19116) +++ trunk/cgi-bin/LJ/S2.pm 2011-05-24 08:46:31 UTC (rev 19117) @@ -3975,43 +3975,12 @@ sub EntryLite__get_give_button { my ($ctx, $this, $type, $image) = @_; - $type = 'button' unless $type =~ /^(?:button|string)$/; - my $journal = $this->{'journal'}->{'username'}; - my $journalu = LJ::load_user($journal); - my $entry = LJ::Entry->new($journalu, ditemid => $this->{itemid}); - - my $remote = LJ::get_remote(); - - return '' unless LJ::is_enabled('give_features') && $remote && $entry->prop('give_features'); - return '' if $journalu->equals($remote); - - my $remote_balance = LJ::Pay::Wallet->get_user_balance($remote); - my $can_give = ( $remote_balance < $LJ::GIVE_TOKENS ) ? 0 : 1; - my $give_link = $can_give ? - "$LJ::SITEROOT/give_tokens.bml?journal=$journal&itemid=$this->{itemid}" : - "$LJ::SITEROOT/shop/tokens.bml"; - my $give_onclick = $can_give ? - 'DonateButton.donate(this,\'journal='.$journal.'&itemid='.$this->{itemid}.'\',{ml_message:\''.LJ::ejs(BML::ml('/give_tokens.bml.confirm.submit.body', { 'give_count' => $LJ::GIVE_TOKENS, 'poster' => $entry->poster->user })).'\',lj_form_auth:\''.LJ::form_auth('raw').'\'});return false' : - 'DonateButton.buyMore(this,\''.LJ::ejs(BML::ml('/give_tokens.bml.confirm.submit.body', { 'give_count' => $LJ::GIVE_TOKENS, 'poster' => $entry->poster->user })).'\');return false'; - my $give_count = $entry->prop('give_count') || 0; - my $give_button = ''; - if ($type eq 'button') { - $give_button .= '<span class="lj-button light"><span class="lj-button-wrapper"> - <a class="lj-button-link" href="'.$give_link.'" onClick="'.$give_onclick.'"> - <span class="lj-button-a"><span class="lj-button-b">'.$LJ::GIVE_TOKENS.' <img src="'.$LJ::IMGPREFIX.'/icons/donate.png" /></span><span class="lj-button-c">'.($give_count ? BML::ml('give_features.given', {'count' => $give_count}) : BML::ml('give_features.give')).'</span></span> - </a> - </span></span>'; - } else { - my $give_text = BML::ml('give_features.give') . $LJ::GIVE_TOKENS . ' LJ Tokens'; - $give_text .= " ($give_count)" if $give_count; - - if ($image) { - $give_button .= '<a href="'.$give_link.'" title="'.$give_text.'" onClick="'.$give_onclick.'"><img src="'.$image.'"></a>'; - } else { - $give_button .= '<a href="'.$give_link.'" onClick="'.$give_onclick.'">'.$give_text.'</a>'; - } - } - return $give_button; + return LJ::run_hook("give_button", { + 'journal' => $this->{'journal'}->{'username'}, + 'itemid' => $this->{itemid}, + 'type' => $type, + 'image' => $image, + }); } *Entry__get_give_button = \&EntryLite__get_give_button; Modified: trunk/cgi-bin/LJ/Talk.pm =================================================================== --- trunk/cgi-bin/LJ/Talk.pm 2011-05-24 08:43:51 UTC (rev 19116) +++ trunk/cgi-bin/LJ/Talk.pm 2011-05-24 08:46:31 UTC (rev 19117) @@ -165,20 +165,10 @@ ## Give features if (LJ::is_enabled('give_features') && $remote && !$u->equals($remote) && $entry->prop('give_features')) { - my $remote_balance = LJ::Pay::Wallet->get_user_balance($remote); - my $can_give = ( $remote_balance < $LJ::GIVE_TOKENS ) ? 0 : 1; - my $give_link = $can_give ? - "$LJ::SITEROOT/give_tokens.bml?${jarg}itemid=$itemid" : - "$LJ::SITEROOT/shop/tokens.bml"; - my $give_onclick = $can_give ? - 'DonateButton.donate(this,\''.$jarg.'itemid='.$itemid.'\',{ml_message:\''.LJ::ejs(BML::ml('/give_tokens.bml.confirm.submit.body', { 'give_count' => $LJ::GIVE_TOKENS, 'poster' => $entry->poster->user })).'\',lj_form_auth:\''.LJ::form_auth('raw').'\'});return false' : - 'DonateButton.buyMore(this,\''.LJ::ejs(BML::ml('/give_tokens.bml.confirm.submit.body', { 'give_count' => $LJ::GIVE_TOKENS, 'poster' => $entry->poster->user })).'\');return false'; - my $give_count = $entry->prop('give_count') || 0; - my $give_button = '<span class="lj-button light"><span class="lj-button-wrapper"> - <a class="lj-button-link" href="'.$give_link.'" onClick="'.$give_onclick.'"> - <span class="lj-button-a"><span class="lj-button-b">'.$LJ::GIVE_TOKENS.' <img src="'.$LJ::IMGPREFIX.'/icons/donate.png" /></span><span class="lj-button-c">'.($give_count ? BML::ml('give_features.given', {'count' => $give_count}) : BML::ml('give_features.give')).'</span></span> - </a> - </span></span>'; + my $give_button = LJ::run_hook("give_button", { + 'journal' => $u->{'user'}, + 'itemid' => $itemid, + }); push @linkele, $give_button; }