Changeset 151
- Timestamp:
- 10/24/05 19:13:59 (3 years ago)
- Files:
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
DuplicatedTBPingLookup/trunk/DuplicatedTBPingLookup.pl
r142 r151 20 20 use MT::JunkFilter qw(ABSTAIN); 21 21 22 use constant JUNK => 1; 23 use constant MODERATE => 2; 24 22 25 my $plugin = MT::Plugin::DuplicatedTBPingLookup->new({ 23 26 name => 'Duplicated TBPing Lookup', 24 27 description => "Look up duplicated trackback ping from the same source, and mark it as a 'junk'.", 25 28 version => $VERSION, 26 config_template => \&template,29 blog_config_template => \&template, 27 30 settings => new MT::PluginSettings([ 28 ['dtl_score_weight', { Default => 1 }] 31 ['dtl_score_weight', { Default => 1 }], 32 ['dtl_method', { Default => JUNK }], 29 33 ]), 30 34 }); … … 44 48 $url =~ s/^\s+|\s+$//gs; 45 49 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' }); 53 54 while (my $ping = $iter->()) { 54 55 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 } 59 67 } 60 68 } … … 63 71 64 72 sub template { 65 my $tmpl = <<'EOT'; 73 my $static_img_uri = MT->instance->static_path . 'images'; 74 my $tmpl = <<EOT; 66 75 <script type="text/javascript"> 67 76 <!-- … … 69 78 var fld = getByID(id); 70 79 score = fld.value; 71 score.replace(/\ +/, '');80 score.replace(/\\+/, ''); 72 81 score = parseFloat(score) + amount; 73 82 if (isNaN(score)) score = amount; … … 84 93 <div class="label"><label>Score Weight:</label></div> 85 94 <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> 87 96 <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> 89 107 </div> 90 108 </div> 91 109 EOT 92 my $static_uri = MT->instance->static_path;93 $tmpl =~ s!<TMPL_VAR NAME=STATIC_URI>!$static_uri!g;94 $tmpl;95 110 } 96 111
