February 1, 2008

Permalink Now With Action Streams

I installed the new Action Stream plugin. Other than creating a nice sidebar widget, I wanted to use this plugin to help ease my aggegating of other network services. Action Stream provides a nice way for you to get that data into Movable Type. I had been writing my own MT plugin per service (MT-Twitter, MT-YouTube, etc.) which was fine. It easy to rip those out once you have the pattern down.

However, the Action Stream plugin just gives you a new set of tags to print out the “events” it captures. That doesn’t give me a way to interleave those into my main blog listing. So as with the other plugins I did, I wanted a way to turn these into entries — which seems to be the best way to make it work since “you are moving with the current”.

I noticed a call to a MT callback in Action Stream on each event so I used that to hook in a new mini plugin I wrote. So it does:

MT->add_callback( 'post_build_action_streams_event.googlereader_shared', 8, $plugin, \&processEventGoogleReaderShared );
MT->add_callback( 'post_build_action_streams_event.delicious_links', 8, $plugin, \&processEventDeliciousLinks );
MT->add_callback( 'post_build_action_streams_event.digg_links', 8, $plugin, \&processEventDiggLinks );
MT->add_callback( 'post_build_action_streams_event.flickr_photos', 8, $plugin, \&processEventFlickrPhotos );
MT->add_callback( 'post_build_action_streams_event.twitter_tweets', 8, $plugin, \&processEventTwitterTweets );
MT->add_callback( 'post_build_action_streams_event.youtube_favorites', 8, $plugin, \&processEventYouTubeFavorites );

Then each of those functions gets an event object which it can use to build a entry and post it like:

 
sub processEventDeliciousLinks
{
        my ($cb, $mt, $item, $event, $author, $profile) = @_;

my $total = MT::Entry->count({ blog_id => 2, basename => dirify( $event->identifier ) });
if ( $total == 0 )
{
my $entry = MT::Entry->new;
$entry->blog_id( 2 );
$entry->status( MT::Entry::FUTURE() );
$entry->author_id( $event->author_id );
$entry->title( 'Link: ' . $event->title );
$entry->basename( dirify( $event->identifier ) );
$entry->text( $event->as_html() );
$entry->text_more( $event->url );
$entry->keywords( 'delicious' );
$entry->created_on( $event->created_on );
$entry->authored_on( $event->created_on );
$entry->convert_breaks( '0' );
$entry->save;
}
}

I am not going to publish the plugin because its tailored to my site and its all hard coded and stuff. But thought I would share to get others started.

Anyway, so if you see all these little “Brandon did….” icons in my blog — now you know. We will see how it goes. I know some hate that shit. I am filtering it out of the RSS though.

Posted: 2008-02-01 at 11:10 MST in Movable Type
Related Posts with Thumbnails