hatenastar_mobile
# Blosxom Plugin: hatenastar mobile
# Author(s): mattn
# Version: Fri, 06 Jun 2008
package hatenastar_mobile;
use strict;
use warnings;
use vars qw($stars);
use LWP::UserAgent;
use URI::Escape;
use HTTP::Request;
use JSON::PP;
$stars = '';
my $permalink_flavour = 'htm';
my @mobile_ua = qw(UP\.Browser KDDI PDXGW DoCoMo J-PHONE L-mode Vodafone SoftBank);
sub start {
return 1 if map { $ENV{'HTTP_USER_AGENT'} =~ /$_/ } @mobile_ua;
}
sub story {
my($pkg, $path, $fn, $story_ref, $title_ref, $body_ref) = @_;
return 0 if $ENV{'PATH_INFO'} !~ /\.$permalink_flavour$/;
eval {
my $uri = 'http://s.hatena.ne.jp/entries.json?uri=' . URI::Escape::uri_escape("$blosxom::url$path/$fn.$permalink_flavour");
my $ua = LWP::UserAgent->new;
my $req = HTTP::Request->new(GET => $uri);
my $res = $ua->request($req);
$res->is_success or return 0;
my $json = decode_json( $res->content );
my @sts = @{$json->{entries}->[0]->{stars}};
for my $st (@sts) {
$stars .= '<img src="http://s.hatena.ne.jp/images/star.gif" title="' . $st->{name} . '" />'
}
};
1;
}
パーマリンクとなるflavour名をpermalink_flavourに指定し、flavourに"$hatenastar_mobile::stars"を入れると表示されます。