Changeset 1583
- Timestamp:
- 08/24/06 16:12:47
- Files:
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/plagger/lib/Plagger/Plugin/Filter/TruePermalink.pm
r933 r1583 12 12 my $self = shift; 13 13 $self->SUPER::init(@_); 14 $self->conf->{follow_redirect} = 1 unless exists $self->conf->{follow_redirect}; 14 15 $self->load_plugins; 15 16 } … … 32 33 my $data = YAML::LoadFile($file); 33 34 if (ref($data) eq 'ARRAY') { 34 push @{$self->{redirectors}}, { follow_link => "^(?:" . join("|", @$data) . ")" };35 # redirectors.yaml ... make it backward compatible to ignore 35 36 } else { 36 37 push @{$self->{plugins}}, $data; … … 99 100 } 100 101 101 unless ($count) { 102 for my $red (@{ $self->{redirectors} }) { 103 next unless $red->{follow_link}; 104 if ($link =~ /$red->{follow_link}/i) { 105 my $url = $self->follow_redirect($link); 106 if ($url && $url ne $link) { 107 $count++; 108 $rewritten = $url; 109 last; 110 } 111 } 102 # No match to known sites. Try redirect by issuing GET 103 if (!$count && $self->conf->{follow_redirect}) { 104 my $url = $self->follow_redirect($link); 105 if ($url && $url ne $link) { 106 $count++; 107 $rewritten = $url; 112 108 } 113 109 } … … 127 123 "redirector:$link", 128 124 sub { 125 Plagger->context->log(debug => "Issuing GET to $link to follow redirects"); 129 126 my $ua = Plagger::UserAgent->new; 130 127 my $res = $ua->simple_request( HTTP::Request->new(GET => $link) ); … … 137 134 ); 138 135 139 Plagger->context->log(debug => "Resolv ing redirection of $link:$url") if $url;136 Plagger->context->log(debug => "Resolved redirection of $link => $url") if $url; 140 137 141 138 return $url; … … 165 162 tries to rewrite url of them. 166 163 164 =head1 CONFIG 165 166 =over 4 167 168 =item follow_redirect 169 170 If set to 1, this plugin issues GET request to entry permalinks to see 171 if the server returns 301 or 302 redirect to other URL. Defaults to 1. 172 173 =back 174 167 175 =head1 PATTERN FILES 168 176 trunk/plagger/t/plugins/Filter-TruePermalink/oreilly.t
r1301 r1583 1 1 use t::TestPlagger; 2 2 3 test_requires_network; 3 4 plan 'no_plan'; 4 5 run_eval_expected;
