| 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__ |
|---|
| 41 |
|
|---|
| 42 |
=head1 NAME |
|---|
| 43 |
|
|---|
| 44 |
Plagger::Plugin::Widget::Delicious - Widget to post to del.icio.us |
|---|
| 45 |
|
|---|
| 46 |
=head1 SYNOPSIS |
|---|
| 47 |
|
|---|
| 48 |
- module: Widget::Delicious |
|---|
| 49 |
|
|---|
| 50 |
=head1 DESCRIPTION |
|---|
| 51 |
|
|---|
| 52 |
This plugin creates a widget to post to del.icio.us in the Publish |
|---|
| 53 |
modules output. |
|---|
| 54 |
|
|---|
| 55 |
=head1 CONFIG |
|---|
| 56 |
|
|---|
| 57 |
=over 4 |
|---|
| 58 |
|
|---|
| 59 |
=item tags |
|---|
| 60 |
|
|---|
| 61 |
Preset tags to tag the post. |
|---|
| 62 |
|
|---|
| 63 |
tags: foo bar |
|---|
| 64 |
|
|---|
| 65 |
will set I<foo bar> as a predefined tag to use. Optional. |
|---|
| 66 |
|
|---|
| 67 |
=item one_click_post |
|---|
| 68 |
|
|---|
| 69 |
Flag to indicate that clicking the widget will automatically post the |
|---|
| 70 |
item, without showing the form. Defaults to 0. (Optional) |
|---|
| 71 |
|
|---|
| 72 |
=back |
|---|
| 73 |
|
|---|
| 74 |
=head1 AUTHOR |
|---|
| 75 |
|
|---|
| 76 |
Tatsuhiko Miyagawa |
|---|
| 77 |
|
|---|
| 78 |
=head1 SEE ALSO |
|---|
| 79 |
|
|---|
| 80 |
L<Plagger>, L<http://del.icio.us/> |
|---|
| 81 |
|
|---|
| 82 |
=cut |
|---|