Changeset 1668
- Timestamp:
- 09/07/06 19:23:48
- Files:
-
- trunk/plagger (modified) (previous)
- trunk/plagger/lib/Plagger/Entry.pm (modified) (2 diffs)
- trunk/plagger/lib/Plagger/Feed.pm (modified) (1 diff)
- trunk/plagger/lib/Plagger/Plugin/Notify/Audio.pm (modified) (1 diff)
- trunk/plagger/lib/Plagger/Plugin/Publish/CSV.pm (modified) (2 diffs)
- trunk/plagger/lib/Plagger/Plugin/Publish/Delicious.pm (modified) (1 diff)
- trunk/plagger/lib/Plagger/Plugin/Publish/Feed.pm (modified) (3 diffs)
- trunk/plagger/lib/Plagger/Plugin/Publish/HatenaBookmark.pm (modified) (1 diff)
- trunk/plagger/lib/Plagger/Plugin/Publish/IMAP.pm (modified) (1 diff)
- trunk/plagger/lib/Plagger/Plugin/Publish/JavaScript.pm (modified) (2 diffs)
- trunk/plagger/lib/Plagger/Plugin/Publish/LivedoorClip.pm (modified) (1 diff)
- trunk/plagger/lib/Plagger/Plugin/Publish/Maildir.pm (modified) (1 diff)
- trunk/plagger/lib/Plagger/Plugin/Publish/PowerPoint.pm (modified) (3 diffs)
- trunk/plagger/lib/Plagger/Plugin/Publish/Takahashi.pm (modified) (1 diff)
- trunk/plagger/lib/Plagger/Util.pm (modified) (2 diffs)
- trunk/plagger/t/core/id_safe.t (added)
- trunk/plagger/t/plugins/Bundle-Planet/feedvalidator.t (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/plagger/lib/Plagger/Entry.pm
r1173 r1668 3 3 4 4 use base qw( Plagger::Thing ); 5 __PACKAGE__->mk_accessors(qw( title author tags link feed_link idsummary body rate icon meta source ));5 __PACKAGE__->mk_accessors(qw( title author tags link feed_link summary body rate icon meta source )); 6 6 __PACKAGE__->mk_date_accessors(qw( date )); 7 7 … … 48 48 } 49 49 50 sub id { 51 my $self = shift; 52 $self->{id} = shift if @_; 53 $self->{id} || $self->permalink || do { 54 my $id = $self->feed_link; 55 $id .= $self->date ? $self->date->epoch : $self->title; 56 $id; 57 }; 58 } 59 50 60 sub id_safe { 51 61 my $self = shift; 52 my $id = $self->id || $self->permalink; 53 54 # entry without id or permalink. Try entry's date or title 55 unless ($id) { 56 $id = $self->feed_link; 57 $id .= $self->date ? $self->date->epoch : $self->title; 58 } 59 60 $id =~ m!^https?://! ? Digest::MD5::md5_hex($id) : $id; 62 Plagger::Util::safe_id($self->id); 61 63 } 62 64 trunk/plagger/lib/Plagger/Feed.pm
r1386 r1668 55 55 my $self = shift; 56 56 $self->{id} = shift if @_; 57 $self->{id} || Digest::MD5::md5_hex($self->url || $self->link);57 $self->{id} || $self->url || $self->link; 58 58 } 59 59 60 60 sub id_safe { 61 61 my $self = shift; 62 my $id = $self->id; 63 $id =~ s![^\w\s]+!_!g; 64 $id =~ s!\s+!_!g; 65 $id; 62 Plagger::Util::safe_id($self->id); 66 63 } 67 64 trunk/plagger/lib/Plagger/Plugin/Notify/Audio.pm
r1406 r1668 22 22 $context->register_hook( 23 23 $self, 24 'publish.entry .fixup' => \&update,24 'publish.entry' => \&update, 25 25 'publish.finalize' => \&finalize, 26 26 ); trunk/plagger/lib/Plagger/Plugin/Publish/CSV.pm
r304 r1668 28 28 } 29 29 30 my $file = $self->gen_filename($args->{feed}) || $args->{feed}->id . ".csv";30 my $file = Plagger::Util::filename_for($args->{feed}, $self->conf->{filename} || "%i.csv"); 31 31 my $path = File::Spec->catfile($dir, $file); 32 32 my $io = IO::File->new($append ? ">> $path" : "> $path"); … … 53 53 utf8::decode($str) unless utf8::is_utf8($str); 54 54 return encode($self->conf->{encoding} || 'utf8', $str); 55 }56 57 my %formats = (58 'u' => sub { my $s = $_[0]->url; $s =~ s!^https?://!!; $s },59 'l' => sub { my $s = $_[0]->link; $s =~ s!^https?://!!; $s },60 't' => sub { $_[0]->title },61 'i' => sub { $_[0]->id },62 );63 64 my $format_re = qr/%(u|l|t|i)/;65 66 sub gen_filename {67 my($self, $feed) = @_;68 69 my $file = $self->conf->{filename} || '';70 $file =~ s{$format_re}{71 $self->safe_filename($formats{$1}->($feed))72 }egx;73 74 $file;75 }76 77 sub safe_filename {78 my($self, $path) = @_;79 $path =~ s![^\w\s]+!_!g;80 $path =~ s!\s+!_!g;81 $path;82 55 } 83 56 trunk/plagger/lib/Plagger/Plugin/Publish/Delicious.pm
r647 r1668 10 10 $context->register_hook( 11 11 $self, 12 'p ublish.init'=> \&initialize,13 'publish.entry .fixup' => \&add_entry,12 'plugin.init' => \&initialize, 13 'publish.entry' => \&add_entry, 14 14 ); 15 15 } 16 17 sub rule_hook { 'publish.entry' } 16 18 17 19 sub initialize { trunk/plagger/lib/Plagger/Plugin/Publish/Feed.pm
r1636 r1668 13 13 sub register { 14 14 my($self, $context) = @_; 15 $context->autoload_plugin('Filter::FloatingDateTime'); 15 16 $context->register_hook( 16 17 $self, … … 105 106 106 107 # generate file path 107 my $filepath = File::Spec->catfile($self->conf->{dir}, $self->gen_filename($f)); 108 my $tmpl = '%i.' . ($feed_format eq 'RSS' ? 'rss' : 'atom'); 109 my $file = Plagger::Util::filename_for($f, $self->conf->{filename} || $tmpl); 110 my $filepath = File::Spec->catfile($self->conf->{dir}, $file); 108 111 109 112 $context->log(info => "save feed for " . $f->link . " to $filepath"); … … 114 117 print $output $xml; 115 118 close $output; 116 }117 118 my %formats = (119 'u' => sub { my $s = $_[0]->url; $s =~ s!^https?://!!; $s },120 'l' => sub { my $s = $_[0]->link; $s =~ s!^https?://!!; $s },121 't' => sub { $_[0]->title },122 'i' => sub { $_[0]->id },123 );124 125 my $format_re = qr/%(u|l|t|i)/;126 127 sub gen_filename {128 my($self, $feed) = @_;129 130 my $file = $self->conf->{filename} ||131 '%i.' . ($self->conf->{format} eq 'RSS' ? 'rss' : 'atom');132 $file =~ s{$format_re}{133 $self->safe_filename($formats{$1}->($feed))134 }egx;135 $file;136 }137 138 sub safe_filename {139 my($self, $path) = @_;140 $path =~ s![^\w\s]+!_!g;141 $path =~ s!\s+!_!g;142 $path;143 119 } 144 120 trunk/plagger/lib/Plagger/Plugin/Publish/HatenaBookmark.pm
r746 r1668 12 12 $context->register_hook( 13 13 $self, 14 'p ublish.init'=> \&initialize,15 'publish.entry .fixup' => \&add_entry,14 'plugin.init' => \&initialize, 15 'publish.entry' => \&add_entry, 16 16 ); 17 17 } 18 18 19 sub rule_hook { 'publish.entry .fixup' }19 sub rule_hook { 'publish.entry' } 20 20 21 21 sub initialize { trunk/plagger/lib/Plagger/Plugin/Publish/IMAP.pm
r1173 r1668 17 17 $context->register_hook( 18 18 $self, 19 'p ublish.init' => \&initialize,20 'publish.entry .fixup' => \&store_entry,19 'plugin.init' => \&initialize, 20 'publish.entry' => \&store_entry, 21 21 'publish.finalize' => \&finalize, 22 22 ); 23 23 } 24 25 sub rule_hook { 'publish.entry' } 24 26 25 27 sub initialize { trunk/plagger/lib/Plagger/Plugin/Publish/JavaScript.pm
r1173 r1668 27 27 my($self, $context, $args) = @_; 28 28 29 my $file = $self->gen_filename($args->{feed}, $self->conf->{filename} || '%i.js');29 my $file = Plagger::Util::filename_for($args->{feed}, $self->conf->{filename} || '%i.js'); 30 30 my $path = File::Spec->catfile($self->conf->{dir}, $file); 31 31 $context->log(info => "writing output to $path"); … … 36 36 print $out $body; 37 37 close $out; 38 }39 40 my %formats = (41 'u' => sub { my $s = $_[0]->url; $s =~ s!^https?://!!; $s },42 'l' => sub { my $s = $_[0]->link; $s =~ s!^https?://!!; $s },43 't' => sub { $_[0]->title },44 'i' => sub { $_[0]->id },45 );46 47 my $format_re = qr/%(u|l|t|i)/;48 49 sub gen_filename {50 my($self, $feed, $file) = @_;51 52 $file =~ s{$format_re}{53 $self->safe_filename($formats{$1}->($feed))54 }egx;55 56 $file;57 }58 59 sub safe_filename {60 my($self, $path) = @_;61 $path =~ s![^\w\s]+!_!g;62 $path =~ s!\s+!_!g;63 $path;64 38 } 65 39 trunk/plagger/lib/Plagger/Plugin/Publish/LivedoorClip.pm
r1081 r1668 12 12 $context->register_hook( 13 13 $self, 14 'publish.entry .fixup' => \&add_entry,15 'publish.init' => \&initialize,14 'publish.entry' => \&add_entry, 15 'publish.init' => \&initialize, 16 16 ); 17 17 } trunk/plagger/lib/Plagger/Plugin/Publish/Maildir.pm
r1173 r1668 12 12 use File::Find; 13 13 14 our $VERSION = '0.3';15 16 14 sub register { 17 15 my($self, $context) = @_; 18 16 $context->register_hook( 19 17 $self, 20 'p ublish.init'=> \&initialize,21 'publish.entry .fixup' => \&store_entry,22 'publish.finalize' => \&finalize,18 'plugin.init' => \&initialize, 19 'publish.entry' => \&store_entry, 20 'publish.finalize' => \&finalize, 23 21 ); 24 22 } 23 24 sub rule_hook { 'publish.entry' } 25 25 26 26 sub initialize { trunk/plagger/lib/Plagger/Plugin/Publish/PowerPoint.pm
r1432 r1668 12 12 $context->register_hook( 13 13 $self, 14 'publish.init' => \&connect_powerpoint,15 14 'publish.feed' => \&publish_presentation, 15 'publish.init' => \&connect_powerpoint, 16 16 ); 17 17 } … … 45 45 # generate file path; 46 46 my $file = File::Spec->catfile( 47 $self->conf->{dir}, $self->gen_filename($feed)47 $self->conf->{dir}, Plagger::Util::filename_for($feed, $self->conf->{filename} || '%i.pps'), 48 48 ); 49 49 … … 65 65 $context->log(debug => "hello, PowerPoint"); 66 66 $self->{powerpoint} = Win32::PowerPoint->new; 67 }68 69 # stolen from ::Publish::Feed70 71 my %formats = (72 'u' => sub { my $s = $_[0]->url; $s =~ s!^https?://!!; $s },73 'l' => sub { my $s = $_[0]->link; $s =~ s!^https?://!!; $s },74 't' => sub { $_[0]->title },75 'i' => sub { $_[0]->id },76 );77 78 my $format_re = qr/%(u|l|t|i)/;79 80 sub gen_filename {81 my($self, $feed) = @_;82 83 my $file = $self->conf->{filename} || '%i.pps';84 $file =~ s{$format_re}{85 $self->safe_filename($formats{$1}->($feed))86 }egx;87 $file;88 }89 90 sub safe_filename {91 my($self, $path) = @_;92 $path =~ s![^\w\s]+!_!g;93 $path =~ s!\s+!_!g;94 $path;95 67 } 96 68 trunk/plagger/lib/Plagger/Plugin/Publish/Takahashi.pm
r1656 r1668 22 22 my($self, $context, $args) = @_; 23 23 24 my $file = $args->{feed}->id . '.xul';24 my $file = $args->{feed}->id_safe . '.xul'; 25 25 my $path = File::Spec->catfile($self->conf->{dir}, $file); 26 26 $context->log(info => "writing output to $path"); trunk/plagger/lib/Plagger/Util.pm
r1606 r1668 172 172 'l' => sub { my $s = $_[0]->link; $s =~ s!^https?://!!; $s }, 173 173 't' => sub { $_[0]->title }, 174 'i' => sub { $_[0]->id },174 'i' => sub { $_[0]->id_safe }, 175 175 ); 176 176 … … 192 192 } 193 193 194 sub safe_id { 195 my $id = shift; 196 $id =~ s/^urn:guid://; 197 $id =~ /^([\w\-]+)$/ ? $1 : Digest::MD5::md5_hex($id); 198 } 199 194 200 1; trunk/plagger/t/plugins/Bundle-Planet/feedvalidator.t
r1311 r1668 18 18 19 19 END { 20 rmtree $dir if $dir && -e $dir;20 # rmtree $dir if $dir && -e $dir; 21 21 } 22 22
