madeon (madeon) wrote in changelog,
madeon
madeon
changelog

[ljcom] r11809: LJSUP-11909: New Repost feature

Committer: sbelyaev
LJSUP-11909: New Repost feature
A   trunk/cgi-bin/LJ/Clean/
A   trunk/cgi-bin/LJ/Clean/Like.pm
A   trunk/templates/Clean/
A   trunk/templates/Clean/Like.tmpl
Added: trunk/cgi-bin/LJ/Clean/Like.pm
===================================================================
--- trunk/cgi-bin/LJ/Clean/Like.pm	                        (rev 0)
+++ trunk/cgi-bin/LJ/Clean/Like.pm	2012-04-26 09:51:11 UTC (rev 11809)
@@ -0,0 +1,201 @@
+package LJ::Clean::Like;
+
+use strict;
+use warnings;
+
+use LJ::Entry;
+use LJ::HTML::Template;
+
+sub new {
+    my ($class, $opts) = @_;
+    warn LJ::D($opts);
+
+    my $entry_url = $opts->{'entry_url'};
+    my $buttons   = $opts->{'buttons'};
+
+    my $entry = LJ::Entry->new_from_url($entry_url);
+
+    my $meta = { map { $_ => '' } qw( title description image ) };
+    if ($entry and $entry->valid) {
+        $meta = $entry->extract_metadata;
+    }
+
+    my $self = bless {}, $class;
+    $self->{'entry_url'} = $entry_url;
+    $self->{'buttons'}   = __extract_buttons($buttons);
+    $self->{'meta'}      = $meta;
+    $self->{'entry'}     = $entry; 
+    
+    return $self;
+}
+
+sub __extract_buttons {
+    my ($buttons_list) = @_;
+
+    unless ($buttons_list) {
+        return qw( repost
+                   facebook
+                   twitter
+                   google
+                   vkontakte
+                   livejournal);
+    }
+
+    my @buttons = ();
+        
+    foreach my $button ( split /,\s*/, $buttons_list ) {
+        if ($button =~ /^(?:re|repost)%/i) {
+            push @buttons, 'repost';
+        }
+        elsif ( $button =~ /^(?:fb|facebook)$/i ) {
+            push @buttons, 'facebook';
+        }
+        elsif ( $button =~ /^(?:go|google)$/i ) {
+            push @buttons, 'google';
+        }
+        elsif ( $button =~ /^(?:tw|twitter)$/i ) {
+            push @buttons, 'twitter';
+        }
+        elsif ( $button =~ /^(?:vk|vkontakte)$/i ) {
+            push @buttons, 'vkontakte';
+        }
+        elsif ( $button =~ /^(?:lj|livejournal)$/i ) {
+            push @buttons, 'livejournal';
+        }
+    }
+
+    return \@buttons;
+}
+
+sub  __repost {
+
+}
+
+sub  __facebook {
+    my ($self, $params) = @_;
+
+    $params->{'lj_like.facebook'} = 1;
+}
+
+sub __twitter {
+    my ($self,$params) = @_;
+
+    my $meta      = $self->{'meta'};   
+
+    my $language = LJ::Lang::get_remote_lang();
+    my $locale = LJ::lang_to_locale($language);
+    $locale =~ s/_.*//;
+
+    my $title_ehtml = Encode::decode_utf8( LJ::ehtml( $meta->{'title'} ) );
+
+    $params->{'lj_like.twitter'} = 1;
+    $params->{'title_ehtml'}  = $title_ehtml;
+    $params->{'locale'} = $locale;
+}
+
+sub __google {
+    my ($self, $params) = @_;
+    $params->{'lj_like.google'} = 1;
+}
+
+sub __vkontakte {
+    my ($self, $params, $vkontakte_like_js) = @_;
+
+    unless ( $LJ::VKONTAKTE_CONF ) {
+        $params->{'lj_like.vk_no_conf'} = 1;
+        return;
+    }
+
+    my $entry_url = $self->{'entry_url'};
+    my $meta      = $self->{'meta'};
+
+    $LJ::REQ_GLOBAL{'ljlike_vkontakte_id'} ||= 1;
+    my $uniqid = int(rand(1_000_000_000));
+
+    my $widget_opts = { 'type'              => 'mini',
+                        'verb'              => '1',
+                        'pageUrl'           => $entry_url,
+                        'pageTitle'         => $meta->{'title'},
+                        'pageDescription'   => $meta->{'description'},
+                        'pageImage'         => $meta->{'image'}, };
+
+    my $widget_opts_out = Encode::decode_utf8( LJ::JSON->to_json($widget_opts) );
+
+    $vkontakte_like_js->{$uniqid}
+                            = qq{<div id="vk_like_$uniqid"></div>}
+                            . qq{<script type="text/javascript">}
+                            . qq{jQuery.VK.addButton("vk_like_$uniqid",$widget_opts_out);}
+                            . qq{</script>};
+
+    $params->{'lj_like.vk'} = 1;
+    $params->{'vk_uniqid'} = $uniqid
+}
+
+sub __livejournal {
+    my ($self, $params) = @_; 
+    my $entry = $self->{'entry'}; 
+
+    my $give_button = LJ::run_hook("give_button", {
+                            'journal' => $entry ? $entry->journal->user : '',
+                            'itemid'  => $entry ? $entry->ditemid : 0,
+                            'type'    => 'tag',
+                        });
+
+    $params->{'lj_like.livejournal'} = 1;
+    $params->{'give_button'} = $give_button;
+}
+
+sub __params {
+    my ($self, $opts) = @_;
+    my $buttons = $self->{'buttons'};
+
+    my $params = {};
+
+    my $entry_url = $self->{'entry_url'};
+    my $entry_url_ehtml = LJ::ehtml($entry_url);
+
+    $params->{'tmpl_var url_ehtml'} = $entry_url_ehtml;
+
+    foreach my $button (@$buttons) {
+        if ( $button eq 'repost') {
+            $self->__repost($params);
+        }
+        elsif ( $button eq 'facebook' ) {
+            $self->__facebook($params);
+        }
+        elsif ( $button eq 'twitter' ) {
+            $self->__twitter($params);
+        }
+        elsif ( $button eq 'google' ) {
+            $self->__google($params);
+        }
+        elsif ( $button eq 'vkontakte' ) {
+            $self->__vkontakte($params, $opts->{'vkontakte_like_js'});
+        }
+        elsif ( $button eq 'livejournal' ) {
+            $self->__livejournal($params);
+        }
+    }
+
+    return $params;
+}
+
+sub html {
+    my ($self, $opts) = @_;
+ 
+    my $template_file = $ENV{'LJHOME'} . '/templates/Clean/Like.tmpl';
+    
+    my $template = LJ::HTML::Template->new(
+        { use_expr => 1 }, # force HTML::Template::Pro with Expr support
+        filename => $template_file,
+        die_on_bad_params => 0,
+        strict => 0,
+    ) or die "Can't open template '$template_file': $!";
+
+    my $params = $self->__params($opts);
+    $template->param(  %$params  );
+    return $template->output;
+}
+
+1;
+

Added: trunk/templates/Clean/Like.tmpl
===================================================================
--- trunk/templates/Clean/Like.tmpl	                        (rev 0)
+++ trunk/templates/Clean/Like.tmpl	2012-04-26 09:51:11 UTC (rev 11809)
@@ -0,0 +1,39 @@
+<div class="lj-like"><!--
+<tmpl_if lj_like.facebook>
+<div class="lj-like-item lj-like-item-facebook">
+    <fb:like href="<tmpl_var url_ehtml>" send="false" layout="button_count" width="100" show_faces="false" font="" action="recommend">
+    </fb:like>
+</div>
+</tmpl_if>
+
+<tmpl_if lj_like.twitter>
+<div class="lj-like-item lj-like-item-twitter">
+    <a href="http://twitter.com/share" class="twitter-share-button" data-url="<tmpl_var url_ehtml>" data-text="<tmpl_var title_ehtml>" data-count="horizontal" 
+            data-lang="<tmpl_var locale>">Tweet</a>
+</div>
+</tmpl_if>
+
+
+<tmpl_if lj_like.google>
+<div class="lj-like-item lj-like-item-google">
+    <g:plusone size="medium" href="<tmpl_var url_ehtml>">
+    </g:plusone>
+</div>
+</tmpl_if>
+
+<tmpl_if lj_like.vk_no_conf>
+<div class="lj-like-item lj-like-item-vkontakte"><b>[vkontakte like]</b></div>
+</tmpl_if>
+
+<tmpl_if lj_like.vk>
+<div class="lj-like-item lj-like-item-vkontakte"><x-vk-like id="<tmpl_var vk_uniqid>"></div>
+</tmpl_if>
+
+<tmpl_if lj_like.livejournal>
+<div class="lj-like-item lj-like-item-livejournal">
+            <tmpl_var give_button>
+</div>
+</tmpl_if>
+
+--></div>
+

Tags: ljcom, madeon, pm, sbelyaev, tmpl
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