Committer: gariev
LJSUP-6545: We should post first picture of the post instead of userpicU trunk/cgi-bin/LJ/Worker/Repost/EntryToFacebook.pm
Modified: trunk/cgi-bin/LJ/Worker/Repost/EntryToFacebook.pm =================================================================== --- trunk/cgi-bin/LJ/Worker/Repost/EntryToFacebook.pm 2010-08-20 03:16:16 UTC (rev 9361) +++ trunk/cgi-bin/LJ/Worker/Repost/EntryToFacebook.pm 2010-08-20 04:24:21 UTC (rev 9362) @@ -37,12 +37,18 @@ }, ); - if (my $upi = $entry->userpic) { - $data->{'picture'} = $upi->url; + my $event_raw = $entry->event_raw; + + my $picture = $class->extract_first_picure_url($event_raw); + if (!$picture) { + if (my $upi = $entry->userpic) { + $picture = $upi->url; + } } + $data->{'picture'} = $picture if $picture; my $title = $class->cleanup($entry->subject_raw); - my $event = $class->cleanup($entry->event_raw); + my $event = $class->cleanup($event_raw); if ($title ne '') { $title = LJ::Text->truncate_to_word_with_ellipsis( @@ -77,4 +83,19 @@ 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;