Changeset 1074

Show
Ignore:
Timestamp:
07/12/06 18:49:57
Author:
miyagawa
Message:

Update Widget::HatenaBookmarkUsersCount? via http://hatena.g.hatena.ne.jp/hatenabookmark/20060712/1152696382

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/plagger/lib/Plagger/Plugin/Widget/HatenaBookmarkUsersCount.pm

    r643 r1074  
    55sub register { 
    66    my($self, $context) = @_; 
    7     $context->autoload_plugin('Filter::HatenaBookmarkUsersCount'); 
     7 
     8    if ($context->is_loaded('Filter::HatenaBookmarkUsersCount')) { 
     9        $self->conf->{use_filter} = 1; 
     10    } 
     11 
    812    $context->register_hook( 
    913        $self, 
     
    1418sub add { 
    1519    my($self, $context, $args) = @_; 
    16     $args->{entry}->add_widget($self) 
    17         if defined($args->{entry}->meta->{hatenabookmark_users}); 
     20    $args->{entry}->add_widget($self); 
    1821} 
    1922 
     
    2326    my $permalink = $entry->permalink; 
    2427       $permalink =~ s/\#/%23/; 
    25     my $uri = URI->new('http://b.hatena.ne.jp/entry/' . $permalink); 
     28    my $url = HTML::Entities::encode("http://b.hatena.ne.jp/entry/$permalink"); 
    2629 
    27     my $url = HTML::Entities::encode($uri->as_string); 
     30    if ($self->conf->{use_filter}) { 
     31        my $user = $entry->meta->{hatenabookmark_users}; 
     32        my $users = $user >= 2 ? "$user users" : "$user user"; 
    2833 
    29     my $user = $entry->meta->{hatenabookmark_users}; 
    30     my $users = $user >= 2 ? "$user users" : "$user user"; 
    31  
    32     $user >= 10 ? 
    33         qq(<strong style="background-color: #ffcccc; font-weight: bold; font-style: normal; display: inline;"><a href="$url" style="color: red;">$users</a></strong>) 
    34         : $user >= 2 ? 
    35         qq(<em style="background-color: #fff0f0; font-weight: bold; display: inline; font-style: normal;"><a href="$url" style="color: #ff6666;">$users</a></em>) 
    36         : qq(<a href="$url">$users</a>); 
     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    } 
    3743} 
    3844 
    39451; 
    4046 
     47__END__ 
     48 
     49=head1 NAME 
     50 
     51Plagger::Plugin::Widget::HatenaBookmarkUsersCount - Widget to Hatena Bookmark with users count 
     52 
     53=head1 SYNOPSIS 
     54 
     55  - module: Widget::HatenaBookmarkUsersCount 
     56 
     57=head1 DESCRIPTION 
     58 
     59This plugin allows you to put a widget containing Hatena Bookmarks 
     60users count and linking to the individual entry page. 
     61 
     62If I<Filter::HatenaBookmarkUsersCount> plugin is loaded, it uses the 
     63metadata found via XML-RPC, otherwise it uses Hatena Bookmarks' image 
     64based API. 
     65 
     66=head1 CONFIG 
     67 
     68=over 4 
     69 
     70=item image_size 
     71 
     72If you use the default Hatena Bookmarks image API, you can change the 
     73size of the image by this config. Optional and defaults to I<normal>. 
     74 
     75=back 
     76 
     77=head1 AUTHOR 
     78 
     79Kazuhiro Osawa 
     80 
     81Tatsuhiko Miyagawa 
     82 
     83=head1 SEE ALSO 
     84 
     85L<Plagger>, L<Plagger::Plugin::Filter::HatenaBookmarkUsersCount>, L<http://hatena.g.hatena.ne.jp/hatenabookmark/20060712/1152696382>