журнал (shhh) wrote in changelog,
журнал
shhh
changelog

[livejournal] r22619: LJSUP-13017: Paid Repost in update.bml a...

Committer: nnikulochkina
LJSUP-13017: Paid Repost in update.bml and editjournal.bml
U   trunk/cgi-bin/LJ/Widget/EntryForm.pm
U   trunk/cgi-bin/ljprotocol.pl
U   trunk/cgi-bin/weblib.pl
U   trunk/htdocs/editjournal.bml
Modified: trunk/cgi-bin/LJ/Widget/EntryForm.pm
===================================================================
--- trunk/cgi-bin/LJ/Widget/EntryForm.pm	2012-08-10 12:31:39 UTC (rev 22618)
+++ trunk/cgi-bin/LJ/Widget/EntryForm.pm	2012-08-10 13:05:59 UTC (rev 22619)
@@ -886,6 +886,62 @@
     $out .= "<ul id='options' class='pkg'>";
 
     my %blocks = (
+        'paid_repost' => sub {
+            return '' unless LJ::is_enabled("paid_repost");
+            
+            my ($offer, $budget) = ($opts->{repost_offer}, $opts->{repost_budget});
+            
+            my $out = '';
+
+            my $checkbox = LJ::html_check({
+                'type'     => 'check',
+                'class'    => 'paid_repost_on',
+                'value'    => '1',
+                'name'     => 'paid_repost_on',
+                'id'       => 'paid_repost_on',
+                'selected' => ($budget > 0 ? 1 : 0),
+                $opts->{'prop_opt_preformatted'} || $opts->{'event_format'},
+                'label'    => "",
+            });
+            my $checkbox_text = LJ::Lang::ml('entryform.paid_repost.checkbox');
+            
+            my $current_budget = $offer && $budget > 0 ? 
+                LJ::Lang::ml('entryform.paid_repost.current_budget', {qty => $budget}) : 
+                '' ;
+
+            $out .= qq{$checkbox $checkbox_text $current_budget <br />};
+
+            $out .= LJ::html_hidden({ 'name' => 'revoke_repost_offer' });
+            
+            my ($label, $opts);
+            unless ($offer) {
+                $opts = {
+                    'name'  => 'repost_budget',
+                    'id'    => 'repost_budget',
+                    'value' => $budget,
+                };
+                $label = LJ::Lang::ml('entryform.paid_repost.budget');
+            } else {
+                $opts = {
+                    'name'  => 'add_repost_budget',
+                    'value' => $opts->{add_repost_budget},
+                };
+
+                $label =  $budget > 0 ? 
+                    LJ::Lang::ml('entryform.paid_repost.add_budget') :
+                    LJ::Lang::ml('entryform.paid_repost.budget');
+            }
+
+            my $field = LJ::html_text({
+                'size'     => '10',
+                'raw'      => "autocomplete='off'",
+                %$opts,
+            });
+
+            $out .= "$label  $field";
+
+            return $out;
+        },         
         'sticky' => sub {
             return '' unless LJ::is_enabled("delayed_entries");
             my $journalu = LJ::load_user($opts->{'usejournal'}) || $remote;
@@ -1328,6 +1384,7 @@
         [ 'music', 'content_flag' ],
         [ 'spellcheck', 'do_not_add' ],
         [ 'none','sticky'],
+        [ 'paid_repost' ],
         'extra',
         [ 'lastfm_logo'  ],
     );

Modified: trunk/cgi-bin/ljprotocol.pl
===================================================================
--- trunk/cgi-bin/ljprotocol.pl	2012-08-10 12:31:39 UTC (rev 22618)
+++ trunk/cgi-bin/ljprotocol.pl	2012-08-10 13:05:59 UTC (rev 22619)
@@ -2433,9 +2433,13 @@
 
     if (LJ::is_enabled("paid_repost")) {
 
-        my $repost_budget = LJ::CleanHtml::Like->extract_repost_budget(\$event) || $req->{'repost_budget'};
+        my $repost_button = LJ::CleanHtml::Like->contains_repost_button(\$event);
         
-        if ($repost_budget) {
+        my $budget_from_html = $repost_button ? LJ::CleanHtml::Like->extract_repost_budget(\$event) : undef;
+
+        my $repost_budget = $budget_from_html || $req->{'repost_budget'};
+        
+        if ($repost_button && $repost_budget) {
     
             # cannot create paid repost via api
             return fail($err,222) unless $flags->{noauth};
@@ -2454,7 +2458,7 @@
 
             return fail($err,160,$error) unless $res;
 
-            LJ::CleanHtml::Like->clean_repost_budget(\$event);
+            LJ::CleanHtml::Like->clean_repost_budget(\$event) if defined $budget_from_html;
         }
     }
 
@@ -3291,48 +3295,62 @@
     my %curprops;
     LJ::load_log_props2($dbcm, $ownerid, [ $itemid ], \%curprops);
 
+
     # create, edit, revoke repost offer
     my ($repost_offer, $repost_offer_action);
     
-    if(LJ::is_enabled("paid_repost") && $req->{'event'} =~ /\S/) {
+    if (LJ::is_enabled("paid_repost") && $req->{'event'} =~ /\S/) {
         
+        my $repost_button = LJ::CleanHtml::Like->contains_repost_button(\$req->{event});
         my $curr_repost_offer = $curprops{$itemid}->{repost_offer} || '';
-        my $repost_budget = $req->{repost_budget};
-        my $contains_repost_button = LJ::CleanHtml::Like->contains_repost_button(\$req->{event});
+        
+        LJ::CleanHtml::Like->clean_repost_budget(\$req->{event}) if $repost_button;
 
-        if ($contains_repost_button && $repost_budget) { 
-            # cannot create or edit repost offer via api
+        my $is_active = $repost_button && !$req->{revoke_repost_offer};
+        
+        # create
+        if ( !$curr_repost_offer && $req->{repost_budget} && $is_active ) {
+            # cannot create repost offer via api
             return fail($err,222) unless $flags->{noauth};
+            
+            $repost_offer_action = 'create';
 
             $repost_offer = {
-                id        => $curr_repost_offer,
                 userid    => $posterid,
                 journalid => $ownerid,
                 jitemid   => $itemid,
-                budget    => int $repost_budget,
+                budget    => int $req->{repost_budget},
             };
+        }
+        
+        # edit
+        if( $curr_repost_offer && $req->{add_repost_budget} && $is_active ) {
+            # cannot edit repost offer via api
+            return fail($err,222) unless $flags->{noauth};
+            
+            $repost_offer_action = 'edit';
 
+            $repost_offer = {
+                id            => $curr_repost_offer,
+                userid        => $posterid,
+                add_budget    => int $req->{add_repost_budget},
+            };
+        }
+
+        if( $repost_offer ) {
             my $error = '';
             my $res = LJ::Pay::Repost::Offer->check(
                 \$error,
                 \$repost_offer,
             );
-   
             return fail($err,160,$error) unless $res;
-            
-            # no need to update repost offer
-            if ($curr_repost_offer) {
-                undef $repost_offer if $repost_offer->budget == $repost_budget;
-            }
+        }
 
-            $repost_offer_action = $curr_repost_offer ? 'edit' : 'create';
-
-        } elsif ( $curr_repost_offer && 
-                  defined $repost_budget && !$repost_budget or
-                  !$contains_repost_button ) {
+        # revoke
+        if ( $curr_repost_offer && !$is_active ) { 
             
             # cannot revoke repost offer via api
-            return fail($err,222) unless $flags->{noauth};
+            #return fail($err,222) unless $flags->{noauth};
 
             $repost_offer_action = 'revoke';
             
@@ -3504,9 +3522,7 @@
             
         } elsif($repost_offer_action eq 'edit') {
             
-            $repost_offer->mark_active if $repost_offer->inactive;
-
-            $repost_offer->set_budget(\$error, int $req->{repost_budget}) or 
+            $repost_offer->add_budget(\$error, int $req->{add_repost_budget}) or 
                 fail(\$warning,160,$error);
        
         } elsif($repost_offer_action eq 'revoke') {

Modified: trunk/cgi-bin/weblib.pl
===================================================================
--- trunk/cgi-bin/weblib.pl	2012-08-10 12:31:39 UTC (rev 22618)
+++ trunk/cgi-bin/weblib.pl	2012-08-10 13:05:59 UTC (rev 22619)
@@ -1158,7 +1158,7 @@
                 prop_opt_preformatted prop_opt_nocomments prop_opt_lockcomments
                 prop_current_location prop_current_coords
                 prop_taglist prop_qotdid prop_give_features 
-                repost_budget revoke_repost_offer)) {
+                repost_budget add_repost_budget revoke_repost_offer)) {
         $req->{$_} = $POST->{$_};
     }
 

Modified: trunk/htdocs/editjournal.bml
===================================================================
--- trunk/htdocs/editjournal.bml	2012-08-10 12:31:39 UTC (rev 22618)
+++ trunk/htdocs/editjournal.bml	2012-08-10 13:05:59 UTC (rev 22619)
@@ -582,7 +582,7 @@
                 'opt_backdated' => $entry_obj->prop('opt_backdated'),
             };
 
-            if($entry_obj->prop('repost_offer')) {
+            if($entry->{'repost_offer'} = $entry_obj->prop('repost_offer')) {
                 my $offer = LJ::Pay::Repost::Offer->get_repost_offer(
                                                         $entry_obj->posterid,
                                                         $entry_obj->prop('repost_offer'),

Tags: bml, livejournal, nikulochkina, nnikulochkina, pl, pm
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