Changeset 151

Show
Ignore:
Timestamp:
10/24/05 19:13:59 (3 years ago)
Author:
ogawa
Message:

Bugfix: when setting the score weight to 0, the plugin uses the default value(=1).
Fix: Change to use "blog_template_config" instead of "template_config".
Fix: Now you can select how the plugin treats wrong trackback pings as. The plugin allows you to just moderate them, as well as treat them as junk.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • DuplicatedTBPingLookup/trunk/DuplicatedTBPingLookup.pl

    r142 r151  
    2020use MT::JunkFilter qw(ABSTAIN); 
    2121 
     22use constant JUNK => 1; 
     23use constant MODERATE => 2; 
     24 
    2225my $plugin = MT::Plugin::DuplicatedTBPingLookup->new({ 
    2326    name => 'Duplicated TBPing Lookup', 
    2427    description => "Look up duplicated trackback ping from the same source, and mark it as a 'junk'.", 
    2528    version => $VERSION, 
    26     config_template => \&template, 
     29    blog_config_template => \&template, 
    2730    settings => new MT::PluginSettings([ 
    28         ['dtl_score_weight', { Default => 1 }] 
     31        ['dtl_score_weight', { Default => 1 }], 
     32        ['dtl_method', { Default => JUNK }], 
    2933    ]), 
    3034}); 
     
    4448    $url =~ s/^\s+|\s+$//gs; 
    4549 
    46     my $iter = MT::TBPing->load_iter({ 
    47         blog_id => $blog_id, 
    48         tb_id => $obj->tb_id, 
    49     }, { 
    50         sort => 'created_on', 
    51         direction => 'descend', 
    52     }); 
     50    my $iter = MT::TBPing->load_iter({ blog_id => $blog_id, 
     51                                       tb_id => $obj->tb_id }, 
     52                                     { sort => 'created_on', 
     53                                       direction => 'descend' }); 
    5354    while (my $ping = $iter->()) { 
    5455        if ($ping->source_url eq $url) { 
    55             my $weight = $plugin->get_config_value('dtl_score_weight', 'blog:' . $blog_id) 
    56                 || $plugin->get_config_value('dtl_score_weight') || 1; 
    57             return (-1 * $weight, 
    58                     "Duplicated trackback ping from the same source: $url"); 
     56            my $config = $plugin->get_config_hash("blog:$blog_id"); 
     57            my $method = $config->{dtl_method} || JUNK; 
     58            my $weight = $config->{dtl_score_weight}; 
     59            $weight = 1 unless defined $weight; 
     60            my $msg = "Duplicated trackback ping from the same source: $url"; 
     61            if ($method == JUNK) { 
     62                return (-1 * $weight, $msg); 
     63            } elsif ($method == MODERATE) { 
     64                $obj->moderate; 
     65                return (0, $msg); 
     66            } 
    5967        } 
    6068    } 
     
    6371 
    6472sub template { 
    65     my $tmpl = <<'EOT'; 
     73    my $static_img_uri = MT->instance->static_path . 'images'; 
     74    my $tmpl = <<EOT; 
    6675<script type="text/javascript"> 
    6776<!-- 
     
    6978    var fld = getByID(id); 
    7079    score = fld.value; 
    71     score.replace(/\+/, ''); 
     80    score.replace(/\\+/, ''); 
    7281    score = parseFloat(score) + amount; 
    7382    if (isNaN(score)) score = amount; 
     
    8493<div class="label"><label>Score Weight:</label></div> 
    8594<div class="field"> 
    86 <a href="#" class="spinner" onclick="return dtlScoreNudge(-1, 'dtl_score_weight')"><img src="<TMPL_VAR NAME=STATIC_URI>images/decrease.gif" alt="<MT_TRANS phrase="Decrease">" width="12" height="8" /></a> 
     95<a href="#" class="spinner" onclick="return dtlScoreNudge(-1, 'dtl_score_weight')"><img src="$static_img_uri/decrease.gif" alt="<MT_TRANS phrase="Decrease">" width="12" height="8" /></a> 
    8796<input type="text" size="3" name="dtl_score_weight" id="dtl_score_weight" value="<TMPL_VAR NAME=DTL_SCORE_WEIGHT ESCAPE=HTML>" /> 
    88 <a href="#" class="spinner" onclick="return dtlScoreNudge(1, 'dtl_score_weight')"><img src="<TMPL_VAR NAME=STATIC_URI>images/increase.gif" alt="<MT_TRANS phrase="Increase">" width="12" height="8" /></a> 
     97<a href="#" class="spinner" onclick="return dtlScoreNudge(1, 'dtl_score_weight')"><img src="$static_img_uri/increase.gif" alt="<MT_TRANS phrase="Increase">" width="12" height="8" /></a> 
     98</div> 
     99</div> 
     100<div class="setting"> 
     101<div class="label"><label>Action:</label></div> 
     102<div class="field"> 
     103<ul> 
     104<li><label><input type="radio" name="dtl_method" value="1"<TMPL_IF NAME=DTL_METHOD_1> checked="checked"</TMPL_IF> /> Junk</label></li> 
     105<li><label><input type="radio" name="dtl_method" value="2"<TMPL_IF NAME=DTL_METHOD_2> checked="checked"</TMPL_IF> /> Not Junk, but Moderated</label></li> 
     106</ul> 
    89107</div> 
    90108</div> 
    91109EOT 
    92     my $static_uri = MT->instance->static_path; 
    93     $tmpl =~ s!<TMPL_VAR NAME=STATIC_URI>!$static_uri!g; 
    94     $tmpl; 
    95110} 
    96111