⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 nofollow.pl

📁 1. 记录每个帖子的访问人情况
💻 PL
字号:
# $Id: nofollow.pl 12713 2005-06-01 00:54:30Z ezra $# Released under the Artistic License# SCRiPTMAFiA 2005 - THE DiRTY HANDS ON YOUR SCRiPTSpackage MT::Plugin::Nofollow;use strict;use MT;use vars qw( $VERSION );$VERSION = '1.2';my $plugin;eval {    require MT::Plugin;    $plugin = MT::Plugin->new({        name => 'Nofollow',        description => q{Adds a 'nofollow' relationship to comment and TrackBack hyperlinks to reduce spam.},        config_link => 'mt-nofollow.cgi'    });    MT->add_plugin($plugin);};use MT::Template::Context;my $tags_to_filter = {    CommentBody       => [0, \&MT::Template::Context::_hdlr_comment_body],    CommentAuthorLink => [0, \&MT::Template::Context::_hdlr_comment_author_link],    Pings             => [1, \&MT::Template::Context::_hdlr_pings]};foreach (keys %$tags_to_filter) {    my $meth = $tags_to_filter->{$_}->[0] ? 'add_container_tag' : 'add_tag';    MT::Template::Context->$meth( $_ => \&nofollowfy_hdlr );}MT::Template::Context->add_global_filter('nofollowfy' => \&nofollowfy);sub config {    my $config = {};    if ($plugin) {        require MT::Request;        $config = MT::Request->instance->cache('nofollow_config');        if (!$config) {            $config = $plugin->get_config_hash() || {};            MT::Request->instance->cache('nofollow_config', $config);        }    }    $config;}sub nofollowfy_hdlr {    my ($ctx, $args, $cond) = @_;    my $config = config();    my $tag = $ctx->stash('tag');    my $enabled = 1;    if (exists $config->{nofollow_enabled} && !$config->{nofollow_enabled}) {        $enabled = 0;    }    if ($enabled && ($tag eq 'CommentAuthorLink')) {        $args->{no_redirect} = 1 unless exists $args->{no_redirect};    }    my $fn = $tags_to_filter->{$tag}->[1];    my $out = $fn->($ctx, $args, $cond);    return $out unless $enabled;    my $sanitize_spec;    if (exists $args->{__sanitize}) {        $sanitize_spec = $args->{__sanitize};    } else {        # calculate the effective sanitize setting for this tag        $sanitize_spec = $args->{sanitize};        if (((!defined $sanitize_spec) || ($sanitize_spec))            && !$tags_to_filter->{$tag}->[0]) {            # if user specified a sanitize="1", blank that out so we can            # pull the spec from the blog or global setting.            $sanitize_spec = '' if (defined $sanitize_spec) && ($sanitize_spec eq '1');            $sanitize_spec ||= $ctx->stash('blog')->sanitize_spec                || MT::ConfigMgr->instance->GlobalSanitizeSpec || '';        }        $args->{__sanitize} = $sanitize_spec;    }    # if user requests sanitize filtering, do that now so    # before we add the 'rel' attribute to hyperlinks    if ($sanitize_spec) {        require MT::Sanitize;        $out = MT::Sanitize->sanitize($out, $sanitize_spec);    }    # force sanitize attribute to 0 so the global sanitize    # filter doesn't reprocess and strip out our 'rel' attribute    $args->{sanitize} = '0';    if (($tag =~ m/Comment/) && ($config->{follow_auth_links})) {        my $comment = $ctx->stash('comment');        if ($comment) {            my $commenter_id = $comment->commenter_id;            if ($commenter_id) {                require MT::Author;                my $commenter = MT::Author->load($commenter_id);                if ($commenter) {                    # return links as-is for approved commenters                    return $out if $commenter->status($ctx->stash('blog_id')) == MT::Author::APPROVED();                }            }        }    }    # finally, nofollowfize any hyperlinks...    nofollowfy($out, '1', $ctx);}sub nofollowfy {    my ($str, $arg, $ctx) = @_;    return $str unless $arg;    $str =~ s#<\s*a\s([^>]*\s*href\s*=[^>]*)>#        my @attr = $1 =~ /[^=[:space:]]*\s*=\s*"[^"]*"|[^=[:space:]]*\s*=\s*'[^']*'|[^=[:space:]]*\s*=[^[:space:]]*/g;        my @rel = grep { /^rel\s*=/i } @attr;        my $rel;        $rel = pop @rel if @rel;        if ($rel) {            $rel =~ s/^(rel\s*=\s*['"]?)/$1nofollow /i;        } else {            $rel = 'rel="nofollow"';        }        @attr = grep { !/^rel\s*=/i } @attr;        '<a ' . (join ' ', @attr) . ' ' . $rel . '>';    #xieg;    $str;}1;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -