Igor Gariev (gariev) wrote in changelog,
Igor Gariev
gariev
changelog

[ljcom] r9369: LJSUP-6545: We should post first picture...

Committer: gariev
LJSUP-6545: We should post first picture of the post instead of userpic
And for comments also
U   trunk/cgi-bin/LJ/Worker/Repost/CommentToFacebook.pm
U   trunk/cgi-bin/LJ/Worker/Repost/EntryToFacebook.pm
U   trunk/cgi-bin/LJ/Worker/Repost.pm
Modified: trunk/cgi-bin/LJ/Worker/Repost/CommentToFacebook.pm
===================================================================
--- trunk/cgi-bin/LJ/Worker/Repost/CommentToFacebook.pm	2010-08-20 07:54:14 UTC (rev 9368)
+++ trunk/cgi-bin/LJ/Worker/Repost/CommentToFacebook.pm	2010-08-20 09:29:14 UTC (rev 9369)
@@ -37,12 +37,18 @@
         },
     );
 
-    if (my $upi = $comment->userpic) {
-        $data->{'picture'} = $upi->url;
+    my $body_raw = $comment->body_raw;
+
+    my $picture = $class->extract_first_picure_url($body_raw);
+    if (!$picture) {
+        if (my $upi = $comment->userpic) {
+            $picture = $upi->url;
+        }
     }
+    $data->{'picture'} = $picture if $picture;
 
     my $title = $class->cleanup($comment->subject_raw);
-    my $body  = $class->cleanup($comment->body_raw);
+    my $body  = $class->cleanup($body_raw);
 
     if ($title ne '') {
         $title = LJ::Text->truncate_to_word_with_ellipsis(

Modified: trunk/cgi-bin/LJ/Worker/Repost/EntryToFacebook.pm
===================================================================
--- trunk/cgi-bin/LJ/Worker/Repost/EntryToFacebook.pm	2010-08-20 07:54:14 UTC (rev 9368)
+++ trunk/cgi-bin/LJ/Worker/Repost/EntryToFacebook.pm	2010-08-20 09:29:14 UTC (rev 9369)
@@ -83,19 +83,4 @@
     return $job->completed;
 }
 
-sub extract_first_picure_url {
-    my $class = shift;
-    my $html = shift;
-
-    ## TODO: should HTML::Parser be used here?
-    while ($html =~ m!<img(.*?)>!gis) {
-        my $attr_text = $1;
-        ## image url MUST be absolute
-        if ($attr_text =~ m!src=(["']?)(https?:\S+?)\1(\s|$)!i) {
-            my $url = $2;
-            return $url;
-        }
-    }
-}
-
 1;

Modified: trunk/cgi-bin/LJ/Worker/Repost.pm
===================================================================
--- trunk/cgi-bin/LJ/Worker/Repost.pm	2010-08-20 07:54:14 UTC (rev 9368)
+++ trunk/cgi-bin/LJ/Worker/Repost.pm	2010-08-20 09:29:14 UTC (rev 9369)
@@ -31,4 +31,21 @@
     return LJ::API::BitLy->shorten($url);
 }
 
+## see also: LJ::html_get_img_urls
+sub extract_first_picure_url {
+    my $class = shift;
+    my $html = shift;
+
+    ## TODO: should HTML::Parser be used here?
+    while ($html =~ m!<img(.*?)>!gis) {
+        my $attr_text = $1;
+        ## image url MUST be absolute
+        if ($attr_text =~ m!src=(["']?)(https?:\S+?)\1(\s|$)!i) {
+            my $url = $2;
+            return $url;
+        }
+    }
+}
+
+
 1;

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