madeon (madeon) wrote in changelog,
madeon
madeon
changelog

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

Committer: sbelyaev
LJSUP-11909: New Repost feature
A   trunk/cgi-bin/LJ/CleanHtml/
D   trunk/cgi-bin/LJ/CleanHtml/Like.pm
A   trunk/cgi-bin/LJ/CleanHtml/Like.pm
Deleted: trunk/cgi-bin/LJ/CleanHtml/Like.pm
===================================================================
--- trunk/cgi-bin/LJ/Clean/Like.pm	2012-04-26 09:51:11 UTC (rev 11809)
+++ trunk/cgi-bin/LJ/CleanHtml/Like.pm	2012-04-26 14:29:11 UTC (rev 11828)
@@ -1,201 +0,0 @@
-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;
-

Copied: trunk/cgi-bin/LJ/CleanHtml/Like.pm (from rev 11826, trunk/cgi-bin/LJ/Clean/Like.pm)
===================================================================
--- trunk/cgi-bin/LJ/CleanHtml/Like.pm	                        (rev 0)
+++ trunk/cgi-bin/LJ/CleanHtml/Like.pm	2012-04-26 14:29:11 UTC (rev 11828)
@@ -0,0 +1,201 @@
+package LJ::Clean::Like;
+
+use strict;
+use warnings;
+
+use Encode;
+use LJ::Entry;
+use LJ::HTML::Template;
+
+sub new {
+    my ($class, $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 Encode::decode_utf8($template->output);
+}
+
+1;
+

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