alf (red_alf) wrote in changelog,
alf
red_alf
changelog

[livejournal] r19062: LJSUP-8689: Donate (Give) button

Committer: afedorov
LJSUP-8689: Donate (Give) button

U   trunk/bin/upgrading/proplists.dat
U   trunk/bin/upgrading/s2layers/core1.s2
U   trunk/cgi-bin/LJ/S2.pm
U   trunk/cgi-bin/LJ/Talk.pm
U   trunk/cgi-bin/LJ/Widget/EntryForm.pm
U   trunk/cgi-bin/ljdefaults.pl
U   trunk/cgi-bin/ljprotocol.pl
U   trunk/cgi-bin/weblib.pl
U   trunk/htdocs/manage/settings/index.bml
Modified: trunk/bin/upgrading/proplists.dat
===================================================================
--- trunk/bin/upgrading/proplists.dat	2011-05-17 03:12:36 UTC (rev 19061)
+++ trunk/bin/upgrading/proplists.dat	2011-05-17 05:12:38 UTC (rev 19062)
@@ -1639,4 +1639,14 @@
   cldversion: 8
   prettyname: Email is faulty
 
+logproplist.give_features:
+  datatype: char
+  des: Enable "Give" features in this entry
+  prettyname: "Give" features 
+  sortorder: 109
 
+logproplist.give_count:
+  datatype: num
+  des: Given tokens counter
+  prettyname: Given counter
+  sortorder: 110

Modified: trunk/bin/upgrading/s2layers/core1.s2
===================================================================
--- trunk/bin/upgrading/s2layers/core1.s2	2011-05-17 03:12:36 UTC (rev 19061)
+++ trunk/bin/upgrading/s2layers/core1.s2	2011-05-17 05:12:38 UTC (rev 19062)
@@ -334,6 +334,7 @@
     function print_text() [fixed]
         "Print the entry text. Doesn't print anything in some contexts, such as on a month view or in a collapsed comment.";
     function builtin get_link (string key) : Link "Get a link to some action related to this entry or comment. You can iterate over [member[EntryLite.link_keyseq]] to get keys to pass in here to produce a 'toolbar' of links.";
+    function builtin get_give_button (string type) : string "Get a button or link to Give features. Type can be 'button' or 'link'";
     function builtin get_plain_subject () : string "For Entries that can contain HTML subjects, this returns the subject without HTML.  Comments can't have HTML in subjects, so this is equivalent to just using \$.subject.  The returned 'plain' subject may still contain HTML entities, so don't do substring chops on it either.";
     function builtin get_tags_text () : string "Returns a string containing a div of class 'ljtags' with the tags for the entry.  If there are no tags on the entry, returns a blank string.  The string is formatted according to the 'text_tags' property.";
     function print_linkbar() "Print the link bar for this entry or comment.";
@@ -2549,9 +2550,13 @@
     }
     var Link link;
     foreach var string k ($.link_keyseq) {
-        $link = $this->get_link($k);
-        " $link ";
-        $link->print_raw();
+        if ($k == "give_button") {
+            print $this->get_give_button("button");
+        } else {
+            $link = $this->get_link($k);
+            " $link ";
+            $link->print_raw();
+        }
     }
     if ($show_interentry) {
         $this->print_link_next();

Modified: trunk/cgi-bin/LJ/S2.pm
===================================================================
--- trunk/cgi-bin/LJ/S2.pm	2011-05-17 03:12:36 UTC (rev 19061)
+++ trunk/cgi-bin/LJ/S2.pm	2011-05-17 05:12:38 UTC (rev 19062)
@@ -1890,6 +1890,7 @@
     push @$link_keyseq, 'watch_comments'    if LJ::is_enabled('esn');
     push @$link_keyseq, 'unwatch_comments'  if LJ::is_enabled('esn');
     push @$link_keyseq, 'flag'              if LJ::is_enabled('content_flag');
+    push @$link_keyseq, 'give_button'       if LJ::is_enabled('give_features');
 
     # Note: nav_prev and nav_next are not included in the keyseq anticipating
     #      that their placement relative to the others will vary depending on
@@ -3876,6 +3877,10 @@
                             $ctx->[S2::PROPS]->{"text_flag"},
                             LJ::S2::Image("$LJ::IMGPREFIX/button-flag.gif", 24, 24));
     }
+    
+    if ($key eq "give_button") {
+        return $null_link;
+    }
 
     my $etypeid          = 'LJ::Event::JournalNewComment'->etypeid;
     my $newentry_etypeid = 'LJ::Event::JournalNewEntry'->etypeid;
@@ -3964,6 +3969,35 @@
     }
 }
 
+sub EntryLite__get_give_button
+{
+    my ($ctx, $this, $type) = @_;
+    $type = 'button' unless $type =~ /^(?:button|link)$/;
+    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');
+    
+    my $remote_balance = LJ::Pay::Wallet->get_user_balance($remote);
+    my $give_link = ($remote_balance < $LJ::GIVE_TOKENS) ?
+                    "$LJ::SITEROOT/shop/tokens.bml" :
+                    "$LJ::SITEROOT/give_tokens.bml?journal=$journal&itemid=$this->{itemid}";
+    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.'">
+                       <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>';
+    return $give_button;
+}
+
+*Entry__c = \&EntryLite__get_give_button;
+
 sub Entry__plain_subject
 {
     my ($ctx, $this) = @_;

Modified: trunk/cgi-bin/LJ/Talk.pm
===================================================================
--- trunk/cgi-bin/LJ/Talk.pm	2011-05-17 03:12:36 UTC (rev 19061)
+++ trunk/cgi-bin/LJ/Talk.pm	2011-05-17 05:12:38 UTC (rev 19062)
@@ -14,6 +14,7 @@
 use LJ::Share;
 use LJ::Talk::Author;
 use LJ::TimeUtil;
+use LJ::Pay::Wallet;
 
 use constant PACK_FORMAT => "NNNNC"; ## $talkid, $parenttalkid, $poster, $time, $state 
 
@@ -162,6 +163,23 @@
         push @linkele, $mlink->($flag_url, 'flag');
     }
 
+    ## Give features
+    if (LJ::is_enabled('give_features') && $remote && $entry->prop('give_features')) {
+        my $remote_balance = LJ::Pay::Wallet->get_user_balance($remote);
+        my $give_link = ($remote_balance < $LJ::GIVE_TOKENS) ?
+                        "$LJ::SITEROOT/shop/tokens.bml" :
+                        "$LJ::SITEROOT/give_tokens.bml?${jarg}itemid=$itemid";
+        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.'">
+                           <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>';
+        
+        push @linkele, $give_button;
+    }
 
     ## Next
     push @linkele, $mlink->("$LJ::SITEROOT/go.bml?${jargent}itemid=$itemid&amp;dir=next", "next_entry");

Modified: trunk/cgi-bin/LJ/Widget/EntryForm.pm
===================================================================
--- trunk/cgi-bin/LJ/Widget/EntryForm.pm	2011-05-17 03:12:36 UTC (rev 19061)
+++ trunk/cgi-bin/LJ/Widget/EntryForm.pm	2011-05-17 05:12:38 UTC (rev 19062)
@@ -1011,6 +1011,34 @@
             $out .= LJ::help_icon_html("adult_content", "", " ");
             return $out;
         },
+        'give_features' => sub {
+            my $out = '';
+
+            return unless LJ::is_enabled("give_features");
+            
+            my @give_menu = (
+                ""        => BML::ml('entryform.give.default'),
+                "enable"  => BML::ml('entryform.give.enable'),
+                "disable" => BML::ml('entryform.give.disable'),
+            );
+
+            $out .= "<label for='prop_give_features' class='left options'>" .
+                BML::ml('entryform.give') . "</label>\n";
+
+            $out .= LJ::html_select({
+                name => 'prop_give_features',
+                id => 'prop_give_features',
+                class => 'select',
+                selected => $opts->{prop_give_features} || "",
+                tabindex => $self->tabindex,
+            }, @give_menu);
+
+            $out .= LJ::help_icon_html("give", "", " ");
+            return $out;
+        },
+        'blank' => sub {
+          return '';  
+        },
         'lastfm_logo' => sub {
             return unless $self->should_show_lastfm;
             return qq{
@@ -1075,6 +1103,7 @@
         [ 'mood', 'comment_settings' ],
         [ 'location', 'comment_screening' ],
         [ 'music', 'content_flag' ],
+        [ 'blank', 'give_features' ],
         'extra',
         [ 'lastfm_logo', 'spellcheck' ],
     );

Modified: trunk/cgi-bin/ljdefaults.pl
===================================================================
--- trunk/cgi-bin/ljdefaults.pl	2011-05-17 03:12:36 UTC (rev 19061)
+++ trunk/cgi-bin/ljdefaults.pl	2011-05-17 05:12:38 UTC (rev 19062)
@@ -403,6 +403,7 @@
                        jobstatus      => "tools/endpoints/jobstatus.bml",
                        widget         => "tools/endpoints/widget.bml",
                        multisearch    => "tools/endpoints/multisearch.bml",
+                       give_tokens    => "give_tokens.bml",
                        );
 
     foreach my $src (keys %ajaxmapping) {

Modified: trunk/cgi-bin/ljprotocol.pl
===================================================================
--- trunk/cgi-bin/ljprotocol.pl	2011-05-17 03:12:36 UTC (rev 19061)
+++ trunk/cgi-bin/ljprotocol.pl	2011-05-17 05:12:38 UTC (rev 19062)
@@ -2097,6 +2097,13 @@
     } else {
         delete $req->{'props'}->{'copyright'};
     }
+    
+    ## give features
+    if (LJ::is_enabled('give_features')) {
+        $req->{'props'}->{'give_features'} = ($req->{'props'}->{'give_features'} eq 'enable') ? 1 :
+                                             ($req->{'props'}->{'give_features'} eq 'disable') ? 0 :
+                                             $uowner->prop('give_features') ? 1 : 0;
+    }
 
     # meta-data
     if (%{$req->{'props'}}) {

Modified: trunk/cgi-bin/weblib.pl
===================================================================
--- trunk/cgi-bin/weblib.pl	2011-05-17 03:12:36 UTC (rev 19061)
+++ trunk/cgi-bin/weblib.pl	2011-05-17 05:12:38 UTC (rev 19062)
@@ -1121,7 +1121,7 @@
                 prop_opt_screening prop_opt_noemail
                 prop_opt_preformatted prop_opt_nocomments prop_opt_lockcomments
                 prop_current_location prop_current_coords
-                prop_taglist prop_qotdid)) {
+                prop_taglist prop_qotdid prop_give_features)) {
         $req->{$_} = $POST->{$_};
     }
 

Modified: trunk/htdocs/manage/settings/index.bml
===================================================================
--- trunk/htdocs/manage/settings/index.bml	2011-05-17 03:12:36 UTC (rev 19061)
+++ trunk/htdocs/manage/settings/index.bml	2011-05-17 05:12:38 UTC (rev 19062)
@@ -149,6 +149,7 @@
                 LJ::Setting::VkontakteConnect
                 LJ::Setting::WebmasterTools::Google
                 LJ::Setting::WebmasterTools::Yandex
+                LJ::Setting::GiveFeatures
                 LJ::Setting::LJTimes
             )],
         },

Tags: bml, dat, livejournal, pl, pm, red_alf, s2
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