Андрей (andy) wrote in changelog,
Андрей
andy
changelog

[livejournal] r19318: LJSUP-8972 (Lj like: Add image or userhe...

Committer: ailyin
LJSUP-8972 (Lj like: Add image or userhead for liked posts.)
LJSUP-9026 (Incorrect title when liking an entry from recent entries through vkontakte)
LJSUP-8988 (LJ-Like: Add Twitter to LJ-Like tag)
LJSUP-8987 (LJ-Like: Change text type for Facebook like button)

U   trunk/cgi-bin/LJ/Entry.pm
U   trunk/cgi-bin/LJ/Hooks/LJLike.pm
U   trunk/cgi-bin/LJ/S2/EntryPage.pm
U   trunk/cgi-bin/cleanhtml.pl
U   trunk/htdocs/talkread.bml
Modified: trunk/cgi-bin/LJ/Entry.pm
===================================================================
--- trunk/cgi-bin/LJ/Entry.pm	2011-06-17 09:05:38 UTC (rev 19317)
+++ trunk/cgi-bin/LJ/Entry.pm	2011-06-20 02:18:04 UTC (rev 19318)
@@ -1394,6 +1394,39 @@
     return $nterms;
 }
 
+# returns a hashref: { title => '', description => '', image => $url }
+sub extract_metadata {
+    my ($self) = @_;
+
+    my %meta;
+
+    $meta{'title'} = LJ::Text->drop_html( $self->subject_raw );
+
+    $meta{'description'} = eval {
+        my $text = $self->event_raw;
+        $text = LJ::Text->drop_html($text);
+        $text = LJ::Text->truncate_to_word_with_ellipsis( 'str' => $text, 'bytes' => 300 );
+        return $text;
+    };
+    die "cannot get entry description: $@" unless defined $meta{'description'};
+
+    $meta{'image'} = eval {
+        my $text = $self->event_raw;
+        my $images = LJ::html_get_img_urls( \$text, 'exclude_site_imgs' => 1 );
+        return $images->[0] if $images && @$images;
+
+        my $userpic = $self->userpic;
+        return $userpic->url if $userpic;
+
+        my $journal = $self->journal;
+        my ($userhead_url) = $journal->userhead;
+        return $userhead_url;
+    };
+    die "cannot get entry image: $@" unless defined $meta{'image'};
+
+    return \%meta;
+}
+
 package LJ;
 
 use Class::Autouse qw (

Modified: trunk/cgi-bin/LJ/Hooks/LJLike.pm
===================================================================
--- trunk/cgi-bin/LJ/Hooks/LJLike.pm	2011-06-17 09:05:38 UTC (rev 19317)
+++ trunk/cgi-bin/LJ/Hooks/LJLike.pm	2011-06-20 02:18:04 UTC (rev 19318)
@@ -24,6 +24,14 @@
     $$after_body_open_ref .= qq{<div id="fb-root"></div><script src="http://connect.facebook.net/$locale/all.js#appId=214181831945836&amp;xfbml=1"></script>};
 } );
 
+LJ::register_hook( 'insert_html_after_body_open' => sub {
+    my ($after_body_open_ref) = @_;
+
+    return if $LJ::REQ_GLOBAL{'sitewide_resources_ljlike_twitter'}++;
+
+    $$after_body_open_ref .=  qq{<script type="text/javascript" src="http://platform.twitter.com/widgets.js"></script>};
+} );
+
 LJ::register_hook( 'sitewide_resources' => sub {
     return unless $LJ::VKONTAKTE_CONF;
     return if $LJ::REQ_GLOBAL{'sitewide_resources_ljlike_vkontakte'}++;

Modified: trunk/cgi-bin/LJ/S2/EntryPage.pm
===================================================================
--- trunk/cgi-bin/LJ/S2/EntryPage.pm	2011-06-17 09:05:38 UTC (rev 19317)
+++ trunk/cgi-bin/LJ/S2/EntryPage.pm	2011-06-20 02:18:04 UTC (rev 19318)
@@ -367,19 +367,12 @@
         $p->{'head_content'} .= $js;
     }
 
-    my %meta = (
-        'title'
-            => LJ::ehtml( LJ::Text->drop_html( $entry->subject_raw ) ),
+    my %meta = %{ $entry->extract_metadata };
 
-        'description'
-            => LJ::ehtml( LJ::Text->drop_html( $entry->event_raw ) ),
-    );
+    $p->{'head_content'} .= "<meta property=\"og:title\" name=\"title\" content=\"" . LJ::ehtml( $meta{'title'} ) . "\" />\n";
+    $p->{'head_content'} .= "<meta property=\"og:description\" name=\"description\" content=\"" . LJ::ehtml( $meta{'description'} ) . "\" />\n";
+    $p->{'head_content'} .= "<meta property=\"og:image\" content=\"" . LJ::ehtml( $meta{'image'} ) . "\" />\n";
 
-    $p->{'head_content'} .= qq[
-        <meta property="og:title" name="title" content="$meta{'title'}" />
-        <meta property="og:description" name="description" content="$meta{'description'}" />
-    ];
-
     LJ::need_res(qw(
                     js/commentmanage.js
                     ));

Modified: trunk/cgi-bin/cleanhtml.pl
===================================================================
--- trunk/cgi-bin/cleanhtml.pl	2011-06-17 09:05:38 UTC (rev 19317)
+++ trunk/cgi-bin/cleanhtml.pl	2011-06-20 02:18:04 UTC (rev 19318)
@@ -724,8 +724,22 @@
                 }
 
                 my $entry_url = $opts->{'entry_url'};
-                my @buttons = qw( facebook google twitter vkontakte livejournal );
+                my $entry = LJ::Entry->new_from_url($entry_url);
+                my $meta = $entry->extract_metadata;
 
+                unless ($entry) {
+                    $newdata .= '<b>[lj-like in invalid context]</b>';
+                    next TOKEN;
+                }
+
+                my @buttons = qw(
+                    facebook
+                    twitter
+                    google
+                    vkontakte
+                    livejournal
+                );
+
                 if ( exists $attr->{'buttons'} && $attr->{'buttons'} ) {
                     my $buttons = $attr->{'buttons'};
 
@@ -758,10 +772,26 @@
 
                         $newdata .= qq{<div class="lj-like-item lj-like-item-facebook">}
                                   . qq{<fb:like href="$entry_url_ehtml" send="false" layout="button_count" }
-                                  . qq{width="100" show_faces="false" font="">}
+                                  . qq{width="100" show_faces="false" font="" action="recommend">}
                                   . qq{</fb:like></div>};
                     }
 
+                    elsif ( $button eq 'twitter' ) {
+                        my $language = LJ::Lang::get_remote_lang();
+
+                        my $locale = LJ::lang_to_locale($language);
+                        $locale =~ s/_.*//;
+
+                        my $entry_url_ehtml = LJ::ehtml($entry_url);
+                        my $title_ehtml = Encode::decode_utf8( LJ::ehtml( $meta->{'title'} ) );
+
+                        $newdata .= qq{<div class="lj-like-item lj-like-item-twitter">}
+                                  . qq{<a href="http://twitter.com/share" class="twitter-share-button" }
+                                  . qq{data-url="$entry_url_ehtml" data-text="$title_ehtml" data-count="horizontal" }
+                                  . qq{data-lang="$locale">Tweet</a>}
+                                  . qq{</div>};
+                    }
+
                     elsif ( $button eq 'google' ) {
                         my $entry_url_ehtml = LJ::ehtml($entry_url);
                         $newdata .= qq{<div class="lj-like-item lj-like-item-google">}
@@ -777,12 +807,21 @@
 
                         $LJ::REQ_GLOBAL{'ljlike_vkontakte_id'} ||= 1;
                         my $uniqid = $LJ::REQ_GLOBAL{'ljlike_vkontakte_id'}++;
-                        my $entry_url_ejs = LJ::js_dumper($entry_url);
 
+                        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{VK.Widgets.Like("vk_like_$uniqid", {type: "mini", pageUrl: $entry_url_ejs});}
+                            . qq{VK.Widgets.Like("vk_like_$uniqid",$widget_opts_out);}
                             . qq{</script>};
                         $newdata .= qq{<div class="lj-like-item lj-like-item-vkontakte"><x-vk-like id="$uniqid"></div>};
                     }

Modified: trunk/htdocs/talkread.bml
===================================================================
--- trunk/htdocs/talkread.bml	2011-06-17 09:05:38 UTC (rev 19317)
+++ trunk/htdocs/talkread.bml	2011-06-20 02:18:04 UTC (rev 19318)
@@ -105,19 +105,12 @@
         return;
     }
 
-    my %meta = (
-        'title'
-            => LJ::ehtml( LJ::Text->drop_html( $entry->subject_raw ) ),
+    my %meta = %{ $entry->extract_metadata };
 
-        'description'
-            => LJ::ehtml( LJ::Text->drop_html( $entry->event_raw ) ),
-    );
+    $$head .= "<meta property=\"og:title\" name=\"title\" content=\"" . LJ::ehtml( $meta{'title'} ) . "\" />\n";
+    $$head .= "<meta property=\"og:description\" name=\"description\" content=\"" . LJ::ehtml( $meta{'description'} ) . "\" />\n";
+    $$head .= "<meta property=\"og:image\" content=\"" . LJ::ehtml( $meta{'image'} ) . "\" />\n";
 
-    $$head .= qq[
-        <meta property="og:title" name="title" content="$meta{'title'}" />
-        <meta property="og:description" name="description" content="$meta{'description'}" />
-    ];
-
     my $talkurl = LJ::journal_base($u) . "/$ditemid.html";
 
     ### load users

Tags: andy, bml, livejournal, 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