Changeset 176

Show
Ignore:
Timestamp:
01/19/07 11:51:41 (2 years ago)
Author:
jallen
Message:

Comment Challenge Version 1.02
* Fixed 'Can't locate object method "translate"' error under MT 3.2
* Implemented backwards-compatible L10N for MT 3.2
* Augmented the en_us L10N phrase file to aid in localization
* Some "best practices" code rearrangement

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/comment_challenge/plugins/commchallenge/commchallenge.pl

    r170 r176  
    88 
    99use strict; 
     10use 5.006;    # requires Perl 5.6.x 
     11use MT 3.2;   # requires MT 3.2 or later 
     12use warnings; 
     13 
    1014use constant DEBUG_MODE => 0; 
    11 use MT 3.2; 
     15 
    1216use base 'MT::Plugin'; 
    13 use MT::JunkFilter qw(ABSTAIN); 
    14 use vars qw($VERSION $plugin $_cache); 
    1517 
    16 $VERSION = '1.01'; 
    17 $plugin = new MT::Plugin::CommentChallenge({ 
     18our $VERSION = "1.02"; 
     19(our $PLUGIN_MODULE = __PACKAGE__) =~ s/^MT::Plugin:://; 
     20 
     21my $plugin; 
     22MT->add_plugin($plugin = __PACKAGE__->new({ 
    1823    name => 'Comment Challenge', 
    1924    version => $VERSION, 
     
    3338        ['commchallenge_throttle_nobeacon', { Default => 0 }] 
    3439    ]), 
    35 }); 
    36 MT->add_plugin($plugin); 
     40})); 
     41 
     42# Adding L10N bootstrapping for MT 3.2 
     43if ($MT::VERSION < 3.3) { 
     44    foreach my $class (qw(CMS Comments Trackback)) { 
     45        MT->add_callback('MT::App::'.$class.'::pre_run', 1, $plugin, \&add_l10n); 
     46    } 
     47
    3748 
    3849require MT::Template::Context; 
     
    5768} 
    5869 
    59 # sub apply_default_settings { 
    60 #     my $plugin = shift; 
    61 #     my ($data, $scope) = @_; 
    62 #     if ($scope ne 'system') { 
    63 #         my $sys = $plugin->get_config_obj('system'); 
    64 #         my $sysdata = $sys->data(); 
    65 #         if ($plugin->{settings} && $sysdata) { 
    66 #             foreach (keys %$sysdata) { 
    67 #                 $data->{$_} = $sysdata->{$_} 
    68 #                     if (!exists $data->{$_}) || (!defined $data->{$_}); 
    69 #             } 
    70 #         } 
    71 #     } else { 
    72 #         $plugin->SUPER::apply_default_settings(@_); 
    73 #     } 
    74 # } 
    7570 
    7671sub load_tmpl { 
     
    9994} 
    10095 
     96# We use an MT::App::CMS::pre_run callback to 
     97# bootstrap the plugin's localization module 
     98# and then handle the translate calls if needed. 
     99sub add_l10n { 
     100    my ($cb,$app) = @_; 
     101    (my $lang = $app->current_language) =~ s/-/_/g; 
     102    eval "require commchallenge::L10N::$lang"; 
     103} 
     104sub translate { 
     105    my $plugin = shift; 
     106    return $MT::VERSION < 3.3   ?   MT->instance->translate(@_) 
     107                                :   $plugin->SUPER::translate(@_); 
     108} 
     109 
    101110# Utility debug method for writing to error log 
    102111sub debug { 
  • trunk/comment_challenge/plugins/commchallenge/lib/commchallenge.pm

    r168 r176  
    66 
    77package commchallenge; 
     8 
     9use MT::JunkFilter qw(ABSTAIN); 
    810 
    911use constant DEBUG_MODE => 0; 
  • trunk/comment_challenge/plugins/commchallenge/lib/commchallenge/L10N.pm

    r119 r176  
    22use strict; 
    33 
    4 use base 'MT::Plugin::L10N'; 
     4eval { 
     5    require MT::Plugin::L10N;  
     6    @commchallenge::L10N::ISA = ('MT::Plugin::L10N'); 
     7}; 
     8# use base 'MT::Plugin::L10N'; 
    59 
    6101; 
  • trunk/comment_challenge/plugins/commchallenge/lib/commchallenge/L10N/en_us.pm

    r169 r176  
    55# $Id$ 
    66 
     7# Comment challenge localization file 
     8# 
     9# This package defines the English phrases used by the plugin 
     10# and can be used as a basis for localization of Comment Challenge 
     11# 
     12# To create a localization, simply do the following: 
     13# 
     14# 1) Create a copy of this file with a name beginning with your 
     15#    language code and ending in '.pm'.  For example, a French 
     16#    localization file would be named 'fr.pm'. 
     17# 2) Translate the strings on the right side of the => operators 
     18#    below or on the following line if following a => operator. 
     19#    You must use a backslash to escape single quotes. 
     20# 3) Replace all occurances of 'en_us' in this file with your 
     21#    own language code 
     22# 
    723package commchallenge::L10N::en_us; 
    8  
    924use strict; 
    10  
    1125use base 'commchallenge::L10N'; 
    1226use vars qw( %Lexicon ); 
    13 %Lexicon = (); 
     27 
     28%Lexicon = ( 
     29 
     30    # 
     31    # Strings from plugin template 
     32    # 
     33    'Beacon:'            => 'Beacon:', 
     34    'BEACON_SETTING'     => 'Check for MTCommentChallenge beacon in comment submissions.', 
     35    'BEACON_DESCRIPTION' => 
     36'This option prevents spam bots from directly injecting comments into the system via the comment script.', 
     37    'BEACON_WARNING'     => 'WARNING: Make sure that the MTCommentChallenge tag is in your templates and that they are rebuilt before enabling this option', 
     38 
     39    'THROTTLE_SETTING'     => 'Deny (&quot;throttle&quot;) submissions without beacon (instead of Junking)', 
     40    'THROTTLE_DESCRIPTION' => 'While throttling such submissions reduces the load on the system, it could also cause lost comments if the MTCommentChallenge tag is not in your comment form. <strong>See plugin documentation for discussion</strong> before enabling this option.', 
     41 
     42    'Challenge/Response CAPTCHA:' => 'Challenge/Response CAPTCHA:', 
     43    'CAPTCHA_DESCRIPTION'         => 'You can optionally present your commenters with a challenge CAPTCHA.  The answer given will be compared case-insensitively to the answer you provide below.', 
     44    'Challenge:'      => 'Challenge:', 
     45    'Response:'       => 'Response:', 
     46    'REBUILD_WARNING' => 'WARNING: If you change this setting and the template containing your comment form is static, you must immediately rebuild that template type after you save this configuration! For most people, this means a rebuild of your individual entries.', 
     47 
     48    'Incorrect response action:'  => 'Incorrect response action:', 
     49    'Score comment as Junk'       => 'Score comment as Junk', 
     50    'Inform commenter of problem' => 'Inform commenter of problem', 
     51    'RESPONSE_DESCRIPTION'        => 'Informing the commenter of a blank or incorrect response allows them to correct the error, but if your question is too difficult, their comment is never submitted.  See plugin documentation for discussion.', 
     52 
     53    # 
     54    # Strings within the application code 
     55    # 
     56    'This anti-spam plugin stops direct injection of comment spam into Movable Type and enables you to implement a challenge/response defense via an accessible CAPTCHA.'   => 
     57    'This anti-spam plugin stops direct injection of comment spam into Movable Type and enables you to implement a challenge/response defense via an accessible CAPTCHA.', 
     58     
     59    'Beaconless comment from commenter \'[_1]\' throttled' => 
     60    'Beaconless comment from commenter \'[_1]\' throttled', 
     61 
     62    'A response to the challenge question (\'[_1]\') is required for comment submission. Please go back and enter the correct value.'   => 
     63    'A response to the challenge question (\'[_1]\') is required for comment submission. Please go back and enter the correct value.', 
     64     
     65    'Comment throttled from commenter (\'[_1]\') due to blank challenge response.'  => 
     66    'Comment throttled from commenter (\'[_1]\') due to blank challenge response.', 
     67 
     68    'Your response to the challenge question (\'[_1]\') was not correct. Please go back and try again.' => 
     69    'Your response to the challenge question (\'[_1]\') was not correct. Please go back and try again.', 
     70 
     71    'Comment throttled from commenter (\'[_1]\') due to incorrect challenge response (\'[_2]\').' => 
     72    'Comment throttled from commenter (\'[_1]\') due to incorrect challenge response (\'[_2]\').', 
     73 
     74    'Challenge beacon not submitted with comment.'  => 
     75    'Challenge beacon not submitted with comment.', 
     76 
     77    'Challenge question (\'[_1]\') answered correctly.' => 
     78    'Challenge question (\'[_1]\') answered correctly.', 
     79 
     80    'Comment challenge question (\'[_1]\') not answered.'   => 
     81    'Comment challenge question (\'[_1]\') not answered.', 
     82 
     83    'Answer (\'[_1]\') to challenge question (\'[_2]\') does not match stored answer (\'[_3]\').'   => 
     84    'Answer (\'[_1]\') to challenge question (\'[_2]\') does not match stored answer (\'[_3]\').', 
     85 
     86); 
     87 
     88if ($MT::VERSION < 3.3) { 
     89    require MT::L10N::en_us; 
     90    $MT::L10N::en_us::Lexicon{$_} = $Lexicon{$_} 
     91        foreach keys %Lexicon; 
     92
    1493 
    15941; 
  • trunk/comment_challenge/plugins/commchallenge/tmpl/blog_config.tmpl

    r119 r176  
    55                <ul> 
    66                <li> 
    7                         <input type="checkbox" name="commchallenge_mode" id="commchallenge_mode" value="1" <TMPL_IF NAME=COMMCHALLENGE_MODE>checked="checked"</TMPL_IF> onclick="toggleAdvancedPrefs(event,'commchallenge_mode')" /> <MT_TRANS phrase="Check for MTCommentChallenge beacon in comment submissions."> 
    8                         <p><MT_TRANS phrase="This option prevents spam bots from directly injecting comments into the system via the comment script.">  <TMPL_UNLESS NAME=COMMCHALLENGE_MODE><MT_TRANS phrase="WARNING: Make sure that the MTCommentChallenge tag is in your templates and that they are rebuilt before enabling this option"></TMPL_UNLESS>  <TMPL_UNLESS NAME=COMMCHALLENGE_THROTTLE_NOBEACON><span id="nobeacon-toggle"><a href="#" onclick="show('nobeacon');hide('nobeacon-toggle');return false;">(advanced)</a></span></TMPL_UNLESS></p> 
     7                        <input type="checkbox" name="commchallenge_mode" id="commchallenge_mode" value="1" <TMPL_IF NAME=COMMCHALLENGE_MODE>checked="checked"</TMPL_IF> onclick="toggleAdvancedPrefs(event,'commchallenge_mode')" /> <MT_TRANS phrase="BEACON_SETTING"> 
     8                        <p><MT_TRANS phrase="BEACON_DESCRIPTION">  <TMPL_UNLESS NAME=COMMCHALLENGE_MODE><MT_TRANS phrase="BEACON_WARNING"></TMPL_UNLESS>  <TMPL_UNLESS NAME=COMMCHALLENGE_THROTTLE_NOBEACON><span id="nobeacon-toggle"><a href="#" onclick="show('nobeacon');hide('nobeacon-toggle');return false;">(advanced)</a></span></TMPL_UNLESS></p> 
    99                </li> 
    1010                </ul> 
     
    1616        <ul> 
    1717            <li> 
    18                 <input type="checkbox" name="commchallenge_throttle_nobeacon" id="commchallenge_throttle_nobeacon" value="1" <TMPL_IF NAME=COMMCHALLENGE_THROTTLE_NOBEACON>checked="checked"</TMPL_IF> /> <label for="commchallenge_throttle_nobeacon"><MT_TRANS phrase="Deny (&quot;throttle&quot;) submissions without beacon (instead of Junking)"></label> 
     18                <input type="checkbox" name="commchallenge_throttle_nobeacon" id="commchallenge_throttle_nobeacon" value="1" <TMPL_IF NAME=COMMCHALLENGE_THROTTLE_NOBEACON>checked="checked"</TMPL_IF> /> <label for="commchallenge_throttle_nobeacon"><MT_TRANS phrase="THROTTLE_SETTING"></label> 
    1919            </li> 
    2020        </ul> 
    21         <p><MT_TRANS phrase="While throttling such submissions reduces the load on the system, it could also cause lost comments if the MTCommentChallenge tag is not in your comment form. <strong>See plugin documentation for discussion</strong> before enabling this option."></p> 
     21        <p><MT_TRANS phrase="THROTTLE_DESCRIPTION"></p> 
    2222        </div> 
    2323    </div> 
     
    3030                <div class="label"><MT_TRANS phrase="Challenge/Response CAPTCHA:"></div> 
    3131                <div class="field"> 
    32                         <p><MT_TRANS phrase="You can optionally present your commenters with a challenge CAPTCHA.  The answer given will be compared case-insensitively to the answer you provide below."></p> 
     32                        <p><MT_TRANS phrase="CAPTCHA_DESCRIPTION"></p> 
    3333                        <ul> 
    3434                        <li>                             
     
    4141                        </li> 
    4242                        </ul> 
    43             <p id="commchallenge_rebuild_warning" style="display:none; background-color: #faa; border: 1px solid #f00;padding: 3px;color: #333;"><MT_TRANS phrase="WARNING: If you change this setting and the template containing your comment form is static, you must immediately rebuild that template type after you save this configuration! For most people, this means a rebuild of your individual entries."></p> 
     43            <p id="commchallenge_rebuild_warning" style="display:none; background-color: #faa; border: 1px solid #f00;padding: 3px;color: #333;"><MT_TRANS phrase="REBUILD_WARNING"></p> 
    4444                </div> 
    4545        </div> 
     
    5353            <li><input type="radio" name="commchallenge_inform_commenter" value="1" <TMPL_IF NAME=COMMCHALLENGE_INFORM_COMMENTER>checked="checked"</TMPL_IF> class="rb" /> <MT_TRANS phrase="Inform commenter of problem"></li> 
    5454        </ul> 
    55                 <p><MT_TRANS phrase="Informing the commenter of a blank or incorrect response allows them to correct the error, but if your question is too difficult, their comment is never submitted.  See plugin documentation for discussion."></p> 
     55                <p><MT_TRANS phrase="RESPONSE_DESCRIPTION"></p> 
    5656        </div> 
    5757    </div>