| 1 | package Plagger::Plugin::Widget::Delicious; | ||
| 2 | use strict; | ||
| 3 | use base qw( Plagger::Plugin ); | ||
| 4 | |||
| 5 | use Encode; | ||
| 6 | use HTML::Entities; | ||
| 7 | use URI; | ||
| 8 | |||
| 9 | sub register { | ||
| 10 | my($self, $context) = @_; | ||
| 11 | $context->register_hook( | ||
| 12 | $self, | ||
| 13 | 'publish.entry.fixup' => \&add, | ||
| 14 | ); | ||
| 15 | } | ||
| 16 | |||
| 17 | sub add { | ||
| 18 | my($self, $context, $args) = @_; | ||
| 19 | $args->{entry}->add_widget($self); | ||
| 20 | } | ||
| 21 | |||
| 22 | sub html { | ||
| 23 | my($self, $entry) = @_; | ||
| 24 | my $uri = URI->new('http://del.icio.us/post'); | ||
| 25 | |||
| 26 | my %query; | ||
| 27 | $query{url} = $entry->permalink; | ||
| 28 | $query{title} = encode('utf-8', $entry->title); | ||
| 29 | $query{tags} = $self->conf->{tags} if $self->conf->{tags}; | ||
| 30 | $query{jump} = 'doclose' if $self->conf->{one_click_post}; | ||
| 31 | |||
| 32 | $uri->query_form(%query, v => 4); | ||
| 33 | |||
| 34 | my $url = HTML::Entities::encode($uri->as_string); | ||
| 35 | return qq(<a href="$url"><img src="http://del.icio.us/static/img/delicious.small.gif" alt="del.icio.us it!" style="border:0;vertical-align:middle" /></a>); | ||
| 36 | } | ||
| 37 | |||
| 38 | 1; | ||
| 39 | |||
| 40 | __END__ |