Plagger::Plugin::Filter::TTP - Replace ttp:// with http://


Plagger documentation Contained in the Plagger distribution.

Index


Code Index:

NAME

Top

Plagger::Plugin::Filter::TTP - Replace ttp:// with http://

SYNOPSIS

Top

  - module: Filter::TTP

DESCRIPTION

Top

This plugin replaces ttp:// with http://. ttp:// is a widely adopted way of linking an URL without leaking a referer.

CONFIG

Top

text_only

When set to 1, uses HTML::Parser to avoid replacing ttp:// inside HTML attributes. Defaults to 0.

AUTHOR

Top

Matsuno Tokuhiro

Tatsuhiko Miyagawa

SEE ALSO

Top

Plagger, HTML::Parser


Plagger documentation Contained in the Plagger distribution.

package Plagger::Plugin::Filter::TTP;
use strict;
use base qw( Plagger::Plugin::Filter::Base );

use URI::Find;
use URI::http;

sub filter {
    my($self, $body) = @_;

    local @URI::ttp::ISA = qw(URI::http);

    my $count = 0;
    my $finder = URI::Find->new(sub {
        my ($uri, $orig_uri) = @_;
        if ($uri->scheme eq 'ttp') {
            $count++;
            return qq{<a href="h$orig_uri">$orig_uri</a>};
        } else {
            return $orig_uri;
        }
    });

    $finder->find(\$body);
    ($count, $body);
}

1;

__END__