package MT::Plugin::HatenaBookmarkCount; use strict; use MT; use MT::Template::Context; use XMLRPC::Lite; use Cache::FastMmap; use constant END_POINT => 'http://b.hatena.ne.jp/xmlrpc'; our $VERSION = '0.01'; our $CACHE_FILE = '/tmp/hbc.cache'; if ( MT->version_number >= 3 ) { require MT::Plugin; my $plugin = new MT::Plugin(); $plugin->description('Get number of bookmarked url in The Hatena Bookmark'); if ( MT->version_number >= 3.2 ) { $plugin->name( 'MT-HatenaBookmarkCount' ); $plugin->version( $VERSION ); $plugin->author_name( 'Yoshiki Kurihara' ); $plugin->author_link( 'http://clouder.jp/yoshiki/mt/' ); } else { $plugin->name( 'MT-HatenaBookmarkCount, v' . $VERSION ); } MT->add_plugin( $plugin ); } MT::Template::Context->add_tag(HatenaBookmarkCount => sub { &_hdlr_hatena_bookmark_count; }); sub _hdlr_hatena_bookmark_count { my($ctx,$args) = @_; my $url = $ctx->stash('entry')->permalink; my $cache = Cache::FastMmap->new( expire_time => 60 * 60, share_file => $CACHE_FILE, raw_values => 1); my $value = $cache->get($url); unless (defined $value) { my $map = XMLRPC::Lite ->proxy(END_POINT) ->call('bookmark.getCount', ($url)) ->result; $value = $map ? $map->{$url} : 0; $cache->set($url, $value); } return $value; } 1; __END__ =head1 NAME hatena-bookmark-count - Get number of bookmarked url in The Hatena Bookmark =head1 SYNOPSIS <$MTHatenaBookmarkCount$> =head1 DESCRIPTION This plugin gets number of bookmarked url in the hatena bookmark(http://b.hatena.ne.jp/). This plugin place result data in the cache(/tmp/hbc.cache). You can specify cache file path($CACHE_FILE), if you change its path. =head1 INSTALLATION Place this file inside of your plugins directory where MT is installed. If the directory does not exist, create the plugins directory. =head1 TAGS =over 4 =item * MTHatenaBookmarkCount =back =head1 CAUTION This plugin access to the hatena bookmark, when you get number of bookmarked url. So please do not specify not much many this tag;-p =head1 LICENSE The software is released under the Artistic License. The terms of the Artistic License are described at http://www.perl.com/language/misc/Artistic.html. =head1 AUTHOR & COPYRIGHT Copyright 2005, Yoshiki Kurihara, clouder at gmail.com. All rights reserved. =cut