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

[ljcom] r12445: 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/CleanHtml/Like.pm
Modified: trunk/cgi-bin/LJ/CleanHtml/Like.pm
===================================================================
--- trunk/cgi-bin/LJ/CleanHtml/Like.pm	2012-08-08 07:18:54 UTC (rev 12444)
+++ trunk/cgi-bin/LJ/CleanHtml/Like.pm	2012-08-09 12:11:52 UTC (rev 12445)
@@ -7,8 +7,12 @@
 
 use Encode;
 use LJ::Entry;
-use LJ::HTML::Template;
 
+use Class::Autouse qw( 
+                       LJ::HTML::Template
+                       HTML::TokeParser
+                       );
+
 sub new {
     my ($class, $opts) = @_;
 
@@ -24,7 +28,7 @@
 
     my $self = bless {}, $class;
     $self->{'entry_url'} = $entry_url;
-    $self->{'buttons'}   = __extract_buttons($buttons);
+    ($self->{'buttons'}) = __extract_buttons($buttons);
     $self->{'meta'}      = $meta;
     $self->{'entry'}     = $entry; 
     
@@ -43,9 +47,12 @@
     }
 
     my @buttons = ();
-        
+    
+    my $params = {};
+   
     foreach my $button ( split /,\s*/, $buttons_list ) {
-        if ($button =~ /^(?:re|repost)$/i) {
+        if ($button =~ /^(?:re|repost)(?:\?budget=(\d+))?$/i) {
+            $params->{repost_budget} = $1 if $1;
             push @buttons, 'repost';
         }
         elsif ( $button =~ /^(?:fb|facebook)$/i ) {
@@ -65,7 +72,7 @@
         }
     }
 
-    return \@buttons;
+    return \@buttons, $params;
 }
 
 sub  __repost {
@@ -213,5 +220,69 @@
     return Encode::decode_utf8($template->output);
 }
 
+sub contains_repost_button {
+    my ($class, $htmlref) = @_;
+
+    while ($$htmlref =~ /(<lj-like\b.+?>)/gi) {
+        my $like = $class->like_from_tag($1);
+        return 1 if grep /repost/, @{$like->{buttons}};
+    }
+    
+    return 0;
+    
+}
+
+sub like_from_tag {
+    my ($class, $tag) = @_;
+    
+    my $p = HTML::TokeParser->new(\$tag);
+    my $token = $p->get_token;
+    my $attrs = $token->[2];
+    
+    my ($buttons, $params) = __extract_buttons($attrs->{buttons});
+
+    return {
+        buttons       => $buttons,
+        repost_budget => $params->{repost_budget},
+    };
+}
+
+sub extract_repost_budget {
+    my ($class, $htmlref) = @_;
+
+    my $tag;
+
+    if ($$htmlref =~ /(<lj-like\b.+?>)/i) {
+        my $like = $class->like_from_tag($1);
+        return $like->{repost_budget};
+    } 
+
+    return undef;
+}
+
+sub clean_repost_budget {
+    my ($class, $htmlref) = @_;
+    
+    $$htmlref =~ s/(<lj-like\b.+?>)/__clean_repost_budget($1)/ieg;
+}
+
+sub __clean_repost_budget {
+    my $tag = shift;
+
+    my $p = HTML::TokeParser->new(\$tag);
+    my $token = $p->get_token;
+    my $attrs = $token->[2];
+
+    return $tag unless $attrs->{buttons}; 
+    
+    my @buttons = split /,/, $attrs->{buttons};
+
+    foreach my $button (@buttons) {
+        $button =~ s/^(re|repost)\?budget=\d+$/$1/i;
+    }
+
+    return '<lj-like buttons="'.(join ',', @buttons).'" />';
+}
+
 1;
 

Tags: ljcom, nikulochkina, nnikulochkina, 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