holyandrew (holyandrew) wrote in changelog,
holyandrew
holyandrew
changelog

[ljcom] r12661: LJINT-482: Comments for side projects (l...

Committer: akanashin
LJINT-482: Comments for side projects (letidor) - improvements
U   trunk/cgi-bin/LJ/Hooks/PartnerSites.pm
U   trunk/cgi-bin/LJ/PartnerSite.pm
Modified: trunk/cgi-bin/LJ/Hooks/PartnerSites.pm
===================================================================
--- trunk/cgi-bin/LJ/Hooks/PartnerSites.pm	2012-09-18 07:43:29 UTC (rev 12660)
+++ trunk/cgi-bin/LJ/Hooks/PartnerSites.pm	2012-09-18 08:00:09 UTC (rev 12661)
@@ -3,6 +3,8 @@
 use warnings;
 
 use LJ::PartnerSite;
+use LWP;
+use HTML::HeadParser;
 
 LJ::register_hook( 'replycount_change' => sub {
     my ( $entry, $posterid ) = @_;
@@ -138,4 +140,36 @@
     @$auth_sequence = split(' ', $partner->overrides->{'auth_sequence'});
 } );
 
+LJ::register_hook( 'override_event_entry' => sub {
+    my ( $u, $ref_event, $ref_subject, $link) = @_;
+
+    return unless $u;
+    return unless $link;
+
+    my $partner = LJ::PartnerSite->find_by_journal_username( $u->username );
+    return unless $partner && $partner->overrides->{'extended_entry'};
+
+    my $ua = LWP::UserAgent->new;    
+    my $res = $ua->get($link);
+
+    if ($res->is_success()) {
+        my $parse = HTML::HeadParser->new;
+        $parse->parse($res->content());
+        
+        my $meta_title = $partner->overrides->{'meta_title'};
+        my $meta_image = $partner->overrides->{'meta_image'};
+        my $meta_desc  = $partner->overrides->{'meta_desc'};
+
+        my $lj_title = $meta_title ? $parse->header("X-Meta-$meta_title") : '';
+        my $lj_image = $meta_image ? $parse->header("X-Meta-$meta_image") : '';
+        my $lj_desc  = $meta_desc  ? $parse->header("X-Meta-$meta_desc") : '';
+
+        $$ref_subject = $lj_title;
+        $$ref_event .= $lj_image;
+        $$ref_event .= $lj_desc; 
+        $$ref_event .= $link; 
+    }
+
+} );
+
 1;

Modified: trunk/cgi-bin/LJ/PartnerSite.pm
===================================================================
--- trunk/cgi-bin/LJ/PartnerSite.pm	2012-09-18 07:43:29 UTC (rev 12660)
+++ trunk/cgi-bin/LJ/PartnerSite.pm	2012-09-18 08:00:09 UTC (rev 12661)
@@ -388,6 +388,9 @@
         # there is no entry, let's create one
         my $link = $self->article_link($docid);
 
+        my ($event, $subject);
+        LJ::run_hook('override_event_entry', $self->journal, \$event, \$subject, $link);
+
         my (undef, $min, $hour, $day, $month, $year) = gmtime;
         $month++;
         $year += 1900;
@@ -397,8 +400,8 @@
         my $protocol_res = LJ::Protocol::do_request(
             'postevent',
             {
-                event   => $link,
-                subject => '',
+                event   => $event || $link,
+                subject => $subject || '',
                 allowmask   => 0,
                 username => $self->journal_username,
                 security => 'public',

Tags: akanashin, holyandrew, 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