| 1 |
package Plagger::Plugin::Widget::HatenaBookmarkUsersCount; |
|---|
| 2 |
use strict; |
|---|
| 3 |
use base qw( Plagger::Plugin Class::Accessor::Fast ); |
|---|
| 4 |
|
|---|
| 5 |
sub register { |
|---|
| 6 |
my($self, $context) = @_; |
|---|
| 7 |
|
|---|
| 8 |
if ($context->is_loaded('Filter::HatenaBookmarkUsersCount')) { |
|---|
| 9 |
$self->conf->{use_filter} = 1; |
|---|
| 10 |
} |
|---|
| 11 |
|
|---|
| 12 |
$context->register_hook( |
|---|
| 13 |
$self, |
|---|
| 14 |
'publish.entry.fixup' => \&add, |
|---|
| 15 |
); |
|---|
| 16 |
} |
|---|
| 17 |
|
|---|
| 18 |
sub add { |
|---|
| 19 |
my($self, $context, $args) = @_; |
|---|
| 20 |
$args->{entry}->add_widget($self); |
|---|
| 21 |
} |
|---|
| 22 |
|
|---|
| 23 |
sub html { |
|---|
| 24 |
my($self, $entry) = @_; |
|---|
| 25 |
|
|---|
| 26 |
my $permalink = $entry->permalink; |
|---|
| 27 |
$permalink =~ s/\ |
|---|
| 28 |
my $url = HTML::Entities::encode("http://b.hatena.ne.jp/entry/$permalink"); |
|---|
| 29 |
|
|---|
| 30 |
if ($self->conf->{use_filter}) { |
|---|
| 31 |
my $user = $entry->meta->{hatenabookmark_users}; |
|---|
| 32 |
my $users = $user >= 2 ? "$user users" : "$user user"; |
|---|
| 33 |
|
|---|
| 34 |
return |
|---|
| 35 |
$user >= 10 ? qq(<strong style="background-color: #ffcccc; font-weight: bold; font-style: normal; display: inline;"><a href="$url" style="color: red;">$users</a></strong>) |
|---|
| 36 |
: $user >= 2 ? qq(<em style="background-color: #fff0f0; font-weight: bold; display: inline; font-style: normal;"><a href="$url" style="color: #ff6666;">$users</a></em>) |
|---|
| 37 |
: qq(<a href="$url">$users</a>); |
|---|
| 38 |
} else { |
|---|
| 39 |
my $size = $self->conf->{image_size} || 'normal'; |
|---|
| 40 |
my $img_url = HTML::Entities::encode("http://b.hatena.ne.jp/entry/image/$size/$permalink"); |
|---|
| 41 |
return qq(<a href="$url"><img src="$img_url" style="border:0;vertical-align:middle" /></a>); |
|---|
| 42 |
} |
|---|
| 43 |
} |
|---|
| 44 |
|
|---|
| 45 |
1; |
|---|
| 46 |
|
|---|
| 47 |
__END__ |
|---|
| 48 |
|
|---|
| 49 |
=head1 NAME |
|---|
| 50 |
|
|---|
| 51 |
Plagger::Plugin::Widget::HatenaBookmarkUsersCount - Widget to Hatena Bookmark with users count |
|---|
| 52 |
|
|---|
| 53 |
=head1 SYNOPSIS |
|---|
| 54 |
|
|---|
| 55 |
- module: Widget::HatenaBookmarkUsersCount |
|---|
| 56 |
|
|---|
| 57 |
=head1 DESCRIPTION |
|---|
| 58 |
|
|---|
| 59 |
This plugin allows you to put a widget containing Hatena Bookmarks |
|---|
| 60 |
users count and linking to the individual entry page. |
|---|
| 61 |
|
|---|
| 62 |
If I<Filter::HatenaBookmarkUsersCount> plugin is loaded, it uses the |
|---|
| 63 |
metadata found via XML-RPC, otherwise it uses Hatena Bookmarks' image |
|---|
| 64 |
based API. |
|---|
| 65 |
|
|---|
| 66 |
=head1 CONFIG |
|---|
| 67 |
|
|---|
| 68 |
=over 4 |
|---|
| 69 |
|
|---|
| 70 |
=item image_size |
|---|
| 71 |
|
|---|
| 72 |
If you use the default Hatena Bookmarks image API, you can change the |
|---|
| 73 |
size of the image by this config. Optional and defaults to I<normal>. |
|---|
| 74 |
|
|---|
| 75 |
=back |
|---|
| 76 |
|
|---|
| 77 |
=head1 AUTHOR |
|---|
| 78 |
|
|---|
| 79 |
Kazuhiro Osawa |
|---|
| 80 |
|
|---|
| 81 |
Tatsuhiko Miyagawa |
|---|
| 82 |
|
|---|
| 83 |
=head1 SEE ALSO |
|---|
| 84 |
|
|---|
| 85 |
L<Plagger>, L<Plagger::Plugin::Filter::HatenaBookmarkUsersCount>, L<http://hatena.g.hatena.ne.jp/hatenabookmark/20060712/1152696382> |
|---|