Changeset 728
- Timestamp:
- 05/13/06 06:07:25
- Files:
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/plagger/lib/Plagger/Plugin/Filter/TruePermalink.pm
r614 r728 43 43 my($self, $context, $args) = @_; 44 44 45 my $orig = $args->{entry}->permalink; 45 $self->rewrite($args->{entry}->permalink, sub { $args->{entry}->link(@_) }); 46 for my $enclosure ($args->{entry}->enclosures) { 47 $self->rewrite($enclosure->url, sub { $enclosure->url( URI->new(@_) ) }); 48 } 49 } 50 51 sub rewrite { 52 my($self, $link, $callback) = @_; 53 54 my $context = Plagger->context; 55 56 my $orig = $link; # copy 46 57 my $count = 0; 58 my $rewritten; 47 59 48 60 for my $plugin (@{ $self->{plugins}}) { 49 61 my $match = $plugin->{match} || '.'; # anything 50 next unless $ args->{entry}->permalink =~ m/$match/i;62 next unless $link =~ m/$match/i; 51 63 52 64 if ($plugin->{rewrite}) { 53 local $_ = $ args->{entry}->permalink;65 local $_ = $link; 54 66 $count += eval $plugin->{rewrite}; 55 67 if ($@) { 56 68 $context->error("$@ in $plugin->{rewrite}"); 57 69 } 58 $args->{entry}->link($_); 70 $callback->($_); 71 $rewritten = $_; 59 72 } elsif ($plugin->{query_param}) { 60 my $ link = URI->new($args->{entry}->permalink)->query_param($plugin->{query_param})61 or $context->error("No query param $plugin->{query_param} in " . $ args->{entry}->permalink);62 $ args->{entry}->link($link);73 my $param = URI->new($link)->query_param($plugin->{query_param}) 74 or $context->error("No query param $plugin->{query_param} in " . $link); 75 $callback->($param); 63 76 $count++; 77 $rewritten = $param; 78 last; 64 79 } 65 80 } 66 81 67 82 if ($count) { 68 $context->log(info => " Permalink $orig rewritten to " . $args->{entry}->permalink);83 $context->log(info => "Link $orig rewritten to $rewritten"); 69 84 } 70 85 } … … 89 104 this plugin. 90 105 91 This plugin rewrites I<link> attribute of C<$entry>, rather than I<permalink>. 106 This plugin rewrites I<link> attribute of C<$entry>, rather than 107 I<permalink>. If C<$entry> has enclosures, this plugin also tries to 108 rewrite url of them. 92 109 93 110 =head1 PATTERN FILES
