WordPress.org

Make WordPress Core

Ticket #16100: 16100-remove-files.patch

File 16100-remove-files.patch, 80.3 KB (added by hakre, 7 years ago)

Decision B - 1/2

  • wp-content/plugins/akismet/admin.php

     
    1 <?php
    2 add_action( 'admin_menu', 'akismet_config_page' );
    3 add_action( 'admin_menu', 'akismet_stats_page' );
    4 akismet_admin_warnings();
    5 
    6 function akismet_admin_init() {
    7     global $wp_version;
    8    
    9     // all admin functions are disabled in old versions
    10     if ( !function_exists('is_multisite') && version_compare( $wp_version, '3.0', '<' ) ) {
    11        
    12         function akismet_version_warning() {
    13             echo "
    14             <div id='akismet-warning' class='updated fade'><p><strong>".sprintf(__('Akismet %s requires WordPress 3.0 or higher.'), AKISMET_VERSION) ."</strong> ".sprintf(__('Please <a href="%s">upgrade WordPress</a> to a current version, or <a href="%s">downgrade to version 2.4 of the Akismet plugin</a>.'), 'http://codex.wordpress.org/Upgrading_WordPress', 'http://wordpress.org/extend/plugins/akismet/download/'). "</p></div>
    15             ";
    16         }
    17         add_action('admin_notices', 'akismet_version_warning');
    18        
    19         return;
    20     }
    21 
    22     if ( function_exists( 'get_plugin_page_hook' ) )
    23         $hook = get_plugin_page_hook( 'akismet-stats-display', 'index.php' );
    24     else
    25         $hook = 'dashboard_page_akismet-stats-display';
    26     add_action('admin_head-'.$hook, 'akismet_stats_script');
    27     add_meta_box('akismet-status', __('Comment History'), 'akismet_comment_status_meta_box', 'comment', 'normal');
    28         wp_register_style('akismet.css', AKISMET_PLUGIN_URL . 'akismet.css');
    29         wp_enqueue_style('akismet.css');
    30         wp_register_script('akismet.js', AKISMET_PLUGIN_URL . 'akismet.js', array('jquery'));
    31         wp_enqueue_script('akismet.js');
    32 }
    33 add_action('admin_init', 'akismet_admin_init');
    34 
    35 function akismet_nonce_field($action = -1) { return wp_nonce_field($action); }
    36 $akismet_nonce = 'akismet-update-key';
    37 
    38 function akismet_config_page() {
    39         if ( function_exists('add_submenu_page') )
    40                 add_submenu_page('plugins.php', __('Akismet Configuration'), __('Akismet Configuration'), 'manage_options', 'akismet-key-config', 'akismet_conf');
    41 }
    42 
    43 function akismet_plugin_action_links( $links, $file ) {
    44         if ( $file == plugin_basename( dirname(__FILE__).'/akismet.php' ) ) {
    45                 $links[] = '<a href="plugins.php?page=akismet-key-config">'.__('Settings').'</a>';
    46         }
    47 
    48         return $links;
    49 }
    50 
    51 add_filter( 'plugin_action_links', 'akismet_plugin_action_links', 10, 2 );
    52 
    53 function akismet_conf() {
    54         global $akismet_nonce, $wpcom_api_key;
    55 
    56         if ( isset($_POST['submit']) ) {
    57                 if ( function_exists('current_user_can') && !current_user_can('manage_options') )
    58                         die(__('Cheatin&#8217; uh?'));
    59 
    60                 check_admin_referer( $akismet_nonce );
    61                 $key = preg_replace( '/[^a-h0-9]/i', '', $_POST['key'] );
    62                 $home_url = parse_url( get_bloginfo('url') );
    63 
    64                 if ( empty($key) ) {
    65                         $key_status = 'empty';
    66                         $ms[] = 'new_key_empty';
    67                         delete_option('wordpress_api_key');
    68                 } elseif ( empty($home_url['host']) ) {
    69                         $key_status = 'empty';
    70                         $ms[] = 'bad_home_url';
    71                 } else {
    72                         $key_status = akismet_verify_key( $key );
    73                 }
    74 
    75                 if ( $key_status == 'valid' ) {
    76                         update_option('wordpress_api_key', $key);
    77                         $ms[] = 'new_key_valid';
    78                 } else if ( $key_status == 'invalid' ) {
    79                         $ms[] = 'new_key_invalid';
    80                 } else if ( $key_status == 'failed' ) {
    81                         $ms[] = 'new_key_failed';
    82                 }
    83 
    84                 if ( isset( $_POST['akismet_discard_month'] ) )
    85                         update_option( 'akismet_discard_month', 'true' );
    86                 else
    87                         update_option( 'akismet_discard_month', 'false' );
    88 
    89                 if ( isset( $_POST['akismet_show_user_comments_approved'] ) )
    90                         update_option( 'akismet_show_user_comments_approved', 'true' );
    91                 else
    92                         update_option( 'akismet_show_user_comments_approved', 'false' );
    93 
    94         } elseif ( isset($_POST['check']) ) {
    95                 akismet_get_server_connectivity(0);
    96         }
    97 
    98         if ( empty( $key_status) ||  $key_status != 'valid' ) {
    99                 $key = get_option('wordpress_api_key');
    100                 if ( empty( $key ) ) {
    101                         if ( empty( $key_status ) || $key_status != 'failed' ) {
    102                                 if ( akismet_verify_key( '1234567890ab' ) == 'failed' )
    103                                         $ms[] = 'no_connection';
    104                                 else
    105                                         $ms[] = 'key_empty';
    106                         }
    107                         $key_status = 'empty';
    108                 } else {
    109                         $key_status = akismet_verify_key( $key );
    110                 }
    111                 if ( $key_status == 'valid' ) {
    112                         $ms[] = 'key_valid';
    113                 } else if ( $key_status == 'invalid' ) {
    114                         delete_option('wordpress_api_key');
    115                         $ms[] = 'key_empty';
    116                 } else if ( !empty($key) && $key_status == 'failed' ) {
    117                         $ms[] = 'key_failed';
    118                 }
    119         }
    120 
    121         $messages = array(
    122                 'new_key_empty' => array('color' => 'aa0', 'text' => __('Your key has been cleared.')),
    123                 'new_key_valid' => array('color' => '4AB915', 'text' => __('Your key has been verified. Happy blogging!')),
    124                 'new_key_invalid' => array('color' => '888', 'text' => __('The key you entered is invalid. Please double-check it.')),
    125                 'new_key_failed' => array('color' => '888', 'text' => __('The key you entered could not be verified because a connection to akismet.com could not be established. Please check your server configuration.')),
    126                 'no_connection' => array('color' => '888', 'text' => __('There was a problem connecting to the Akismet server. Please check your server configuration.')),
    127                 'key_empty' => array('color' => 'aa0', 'text' => sprintf(__('Please enter an API key. (<a href="%s" style="color:#fff">Get your key.</a>)'), 'http://akismet.com/get/')),
    128                 'key_valid' => array('color' => '4AB915', 'text' => __('This key is valid.')),
    129                 'key_failed' => array('color' => 'aa0', 'text' => __('The key below was previously validated but a connection to akismet.com can not be established at this time. Please check your server configuration.')),
    130                 'bad_home_url' => array('color' => '888', 'text' => sprintf( __('Your WordPress home URL %s is invalid.  Please fix the <a href="%s">home option</a>.'), esc_html( get_bloginfo('url') ), admin_url('options.php#home') ) ),
    131         );
    132 ?>
    133 <?php if ( !empty($_POST['submit'] ) ) : ?>
    134 <div id="message" class="updated fade"><p><strong><?php _e('Options saved.') ?></strong></p></div>
    135 <?php endif; ?>
    136 <div class="wrap">
    137 <h2><?php _e('Akismet Configuration'); ?></h2>
    138 <?php if (isset($_GET['message']) && $_GET['message'] == 'success') { ?>
    139         <div class="updated below-h2" id="message"><p><?php _e( '<strong>Sign up success!</strong> Please check your email for your Akismet API Key and enter it below.' ); ?></p></div>
    140 <?php } ?>
    141 <div class="narrow">
    142 <form action="" method="post" id="akismet-conf" style="margin: auto; width: 400px; ">
    143 <?php if ( !$wpcom_api_key ) { ?>
    144         <p><?php printf(__('For many people, <a href="%1$s">Akismet</a> will greatly reduce or even completely eliminate the comment and trackback spam you get on your site. If one does happen to get through, simply mark it as "spam" on the moderation screen and Akismet will learn from the mistakes. If you don\'t have an API key yet, you can get one at <a href="%2$s">Akismet.com</a>.'), 'http://akismet.com/', 'http://akismet.com/get/'); ?></p>
    145 
    146 <h3><label for="key"><?php _e('Akismet API Key'); ?></label></h3>
    147 <?php foreach ( $ms as $m ) : ?>
    148         <p style="padding: .5em; background-color: #<?php echo $messages[$m]['color']; ?>; color: #fff; font-weight: bold;"><?php echo $messages[$m]['text']; ?></p>
    149 <?php endforeach; ?>
    150 <p><input id="key" name="key" type="text" size="15" maxlength="12" value="<?php echo get_option('wordpress_api_key'); ?>" style="font-family: 'Courier New', Courier, mono; font-size: 1.5em;" /> (<?php _e('<a href="http://akismet.com/get/">What is this?</a>'); ?>)</p>
    151 <?php if ( isset( $invalid_key) && $invalid_key ) { ?>
    152 <h3><?php _e('Why might my key be invalid?'); ?></h3>
    153 <p><?php _e('This can mean one of two things, either you copied the key wrong or that the plugin is unable to reach the Akismet servers, which is most often caused by an issue with your web host around firewalls or similar.'); ?></p>
    154 <?php } ?>
    155 <?php } ?>
    156 <?php akismet_nonce_field($akismet_nonce) ?>
    157 <p><label><input name="akismet_discard_month" id="akismet_discard_month" value="true" type="checkbox" <?php if ( get_option('akismet_discard_month') == 'true' ) echo ' checked="checked" '; ?> /> <?php _e('Auto-delete spam submitted on posts more than a month old.'); ?></label></p>
    158 <p><label><input name="akismet_show_user_comments_approved" id="akismet_show_user_comments_approved" value="true" type="checkbox" <?php if ( get_option('akismet_show_user_comments_approved') == 'true' ) echo ' checked="checked" '; ?> /> <?php _e('Show the number of comments you\'ve approved beside each comment author.'); ?></label></p>
    159         <p class="submit"><input type="submit" name="submit" value="<?php _e('Update options &raquo;'); ?>" /></p>
    160 </form>
    161 
    162 <form action="" method="post" id="akismet-connectivity" style="margin: auto; width: 400px; ">
    163 
    164 <h3><?php _e('Server Connectivity'); ?></h3>
    165 <?php
    166         if ( !function_exists('fsockopen') || !function_exists('gethostbynamel') ) {
    167                 ?>
    168                         <p style="padding: .5em; background-color: #888; color: #fff; font-weight:bold;"><?php _e('Network functions are disabled.'); ?></p>
    169                         <p><?php echo sprintf( __('Your web host or server administrator has disabled PHP\'s <code>fsockopen</code> or <code>gethostbynamel</code> functions.  <strong>Akismet cannot work correctly until this is fixed.</strong>  Please contact your web host or firewall administrator and give them <a href="%s" target="_blank">this information about Akismet\'s system requirements</a>.'), 'http://blog.akismet.com/akismet-hosting-faq/'); ?></p>
    170                 <?php
    171         } else {
    172                 $servers = akismet_get_server_connectivity();
    173                 $fail_count = count($servers) - count( array_filter($servers) );
    174                 if ( is_array($servers) && count($servers) > 0 ) {
    175                         // some connections work, some fail
    176                         if ( $fail_count > 0 && $fail_count < count($servers) ) { ?>
    177                                 <p style="padding: .5em; background-color: #aa0; color: #fff; font-weight:bold;"><?php _e('Unable to reach some Akismet servers.'); ?></p>
    178                                 <p><?php echo sprintf( __('A network problem or firewall is blocking some connections from your web server to Akismet.com.  Akismet is working but this may cause problems during times of network congestion.  Please contact your web host or firewall administrator and give them <a href="%s" target="_blank">this information about Akismet and firewalls</a>.'), 'http://blog.akismet.com/akismet-hosting-faq/'); ?></p>
    179                         <?php
    180                         // all connections fail
    181                         } elseif ( $fail_count > 0 ) { ?>
    182                                 <p style="padding: .5em; background-color: #888; color: #fff; font-weight:bold;"><?php _e('Unable to reach any Akismet servers.'); ?></p>
    183                                 <p><?php echo sprintf( __('A network problem or firewall is blocking all connections from your web server to Akismet.com.  <strong>Akismet cannot work correctly until this is fixed.</strong>  Please contact your web host or firewall administrator and give them <a href="%s" target="_blank">this information about Akismet and firewalls</a>.'), 'http://blog.akismet.com/akismet-hosting-faq/'); ?></p>
    184                         <?php
    185                         // all connections work
    186                         } else { ?>
    187                                 <p style="padding: .5em; background-color: #4AB915; color: #fff; font-weight:bold;"><?php  _e('All Akismet servers are available.'); ?></p>
    188                                 <p><?php _e('Akismet is working correctly.  All servers are accessible.'); ?></p>
    189                         <?php
    190                         }
    191                 } else {
    192                         ?>
    193                                 <p style="padding: .5em; background-color: #888; color: #fff; font-weight:bold;"><?php _e('Unable to find Akismet servers.'); ?></p>
    194                                 <p><?php echo sprintf( __('A DNS problem or firewall is preventing all access from your web server to Akismet.com.  <strong>Akismet cannot work correctly until this is fixed.</strong>  Please contact your web host or firewall administrator and give them <a href="%s" target="_blank">this information about Akismet and firewalls</a>.'), 'http://blog.akismet.com/akismet-hosting-faq/'); ?></p>
    195                         <?php
    196                 }
    197         }
    198        
    199         if ( !empty($servers) ) {
    200 ?>
    201 <table style="width: 100%;">
    202 <thead><th><?php _e('Akismet server'); ?></th><th><?php _e('Network Status'); ?></th></thead>
    203 <tbody>
    204 <?php
    205                 asort($servers);
    206                 foreach ( $servers as $ip => $status ) {
    207                         $color = ( $status ? '#4AB915' : '#888');
    208         ?>
    209                 <tr>
    210                 <td><?php echo htmlspecialchars($ip); ?></td>
    211                 <td style="padding: 0 .5em; font-weight:bold; color: #fff; background-color: <?php echo $color; ?>"><?php echo ($status ? __('Accessible') : __('Re-trying') ); ?></td>
    212                
    213         <?php
    214                 }
    215         }
    216 ?>
    217 </tbody>
    218 </table>
    219         <p><?php if ( get_option('akismet_connectivity_time') ) echo sprintf( __('Last checked %s ago.'), human_time_diff( get_option('akismet_connectivity_time') ) ); ?></p>
    220         <p class="submit"><input type="submit" name="check" value="<?php _e('Check network status &raquo;'); ?>" /></p>
    221         <p><?php printf( __('<a href="%s" target="_blank">Click here</a> to confirm that <a href="%s" target="_blank">Akismet.com is up</a>.'), 'http://status.automattic.com/9931/136079/Akismet-API', 'http://status.automattic.com/9931/136079/Akismet-API' ); ?></p>
    222 </form>
    223 
    224 </div>
    225 </div>
    226 <?php
    227 }
    228 
    229 function akismet_stats_page() {
    230         if ( function_exists('add_submenu_page') )
    231                 add_submenu_page('index.php', __('Akismet Stats'), __('Akismet Stats'), 'manage_options', 'akismet-stats-display', 'akismet_stats_display');
    232 
    233 }
    234 
    235 function akismet_stats_script() {
    236         ?>
    237 <script type="text/javascript">
    238 function resizeIframe() {
    239     var height = document.documentElement.clientHeight;
    240     height -= document.getElementById('akismet-stats-frame').offsetTop;
    241     height += 100; // magic padding
    242    
    243     document.getElementById('akismet-stats-frame').style.height = height +"px";
    244    
    245 };
    246 function resizeIframeInit() {
    247         document.getElementById('akismet-stats-frame').onload = resizeIframe;
    248         window.onresize = resizeIframe;
    249 }
    250 addLoadEvent(resizeIframeInit);
    251 </script><?php
    252 }
    253 
    254 
    255 function akismet_stats_display() {
    256         global $akismet_api_host, $akismet_api_port, $wpcom_api_key;
    257         $blog = urlencode( get_bloginfo('url') );
    258 
    259         $url = 'http://';
    260         if ( is_ssl() )
    261                 $url = 'https://';
    262 
    263         $url .= 'akismet.com/web/1.0/user-stats.php';
    264         $url .= "?blog={$blog}&api_key=" . akismet_get_key();
    265         ?>
    266         <div class="wrap">
    267         <iframe src="<?php echo $url; ?>" width="100%" height="100%" frameborder="0" id="akismet-stats-frame"></iframe>
    268         </div>
    269         <?php
    270 }
    271 
    272 function akismet_stats() {
    273         if ( !function_exists('did_action') || did_action( 'rightnow_end' ) ) // We already displayed this info in the "Right Now" section
    274                 return;
    275         if ( !$count = get_option('akismet_spam_count') )
    276                 return;
    277         $path = plugin_basename(__FILE__);
    278         echo '<h3>' . _x( 'Spam', 'comments' ) . '</h3>';
    279         global $submenu;
    280         if ( isset( $submenu['edit-comments.php'] ) )
    281                 $link = 'edit-comments.php';
    282         else
    283                 $link = 'edit.php';
    284         echo '<p>'.sprintf( _n( '<a href="%1$s">Akismet</a> has protected your site from <a href="%2$s">%3$s spam comments</a>.', '<a href="%1$s">Akismet</a> has protected your site from <a href="%2$s">%3$s spam comments</a>.', $count ), 'http://akismet.com/', clean_url("$link?page=akismet-admin"), number_format_i18n($count) ).'</p>';
    285 }
    286 add_action('activity_box_end', 'akismet_stats');
    287 
    288 function akismet_admin_warnings() {
    289         global $wpcom_api_key;
    290         if ( !get_option('wordpress_api_key') && !$wpcom_api_key && !isset($_POST['submit']) ) {
    291                 function akismet_warning() {
    292                         echo "
    293                         <div id='akismet-warning' class='updated fade'><p><strong>".__('Akismet is almost ready.')."</strong> ".sprintf(__('You must <a href="%1$s">enter your Akismet API key</a> for it to work.'), "plugins.php?page=akismet-key-config")."</p></div>
    294                         ";
    295                 }
    296                 add_action('admin_notices', 'akismet_warning');
    297                 return;
    298         } elseif ( ( empty($_SERVER['SCRIPT_FILENAME']) || basename($_SERVER['SCRIPT_FILENAME']) == 'edit-comments.php' ) &&  wp_next_scheduled('akismet_schedule_cron_recheck') ) {
    299                 function akismet_warning() {
    300                         global $wpdb;
    301                                 $waiting = $wpdb->get_var( $wpdb->prepare( "SELECT COUNT(*) FROM $wpdb->commentmeta WHERE meta_key = 'akismet_error'" ) );
    302                                 $next_check = human_time_diff( wp_next_scheduled('akismet_schedule_cron_recheck') );
    303                                 if ( $waiting > 0 )
    304                                         echo "
    305                         <div id='akismet-warning' class='updated fade'><p><strong>".__('Akismet has detected a problem.')."</strong> ".sprintf(_n('A server or network problem prevented Akismet from checking %d comment. It has been temporarily held for moderation and will be automatically re-checked in %s.', 'A server or network problem prevented Akismet from checking %d comments. They have been temporarily held for moderation and will be automatically re-checked in %s.', $waiting), number_format_i18n( $waiting ), $next_check)."</p></div>
    306                         ";
    307                 }
    308                 add_action('admin_notices', 'akismet_warning');
    309                 return;
    310         }
    311 }
    312 
    313 // FIXME placeholder
    314 
    315 function akismet_comment_row_action( $a, $comment ) {
    316 
    317         // failsafe for old WP versions
    318         if ( !function_exists('add_comment_meta') )
    319                 return $a;
    320 
    321         $akismet_result = get_comment_meta( $comment->comment_ID, 'akismet_result', true );
    322         $user_result = get_comment_meta( $comment->comment_ID, 'akismet_user_result', true);
    323         $comment_status = wp_get_comment_status( $comment->comment_ID );
    324         $desc = null;
    325         if ( !$user_result || $user_result == $akismet_result ) {
    326                 // Show the original Akismet result if the user hasn't overridden it, or if their decision was the same
    327                 if ( $akismet_result == 'true' && $comment_status != 'spam' && $comment_status != 'trash' )
    328                         $desc = __( 'Flagged as spam by Akismet' );
    329                 elseif ( $akismet_result == 'false' && $comment_status == 'spam' )
    330                         $desc = __( 'Cleared by Akismet' );
    331         } else {
    332                 $who = get_comment_meta( $comment->comment_ID, 'akismet_user', true );
    333                 if ( $user_result == 'true' )
    334                         $desc = sprintf( __('Flagged as spam by %s'), $who );
    335                 else
    336                         $desc = sprintf( __('Un-spammed by %s'), $who );
    337         }
    338 
    339         // add a History item to the hover links, just after Edit
    340         if ( $akismet_result ) {
    341                 $b = array();
    342                 foreach ( $a as $k => $item ) {
    343                         $b[ $k ] = $item;
    344                         if ( $k == 'edit' )
    345                                 $b['history'] = '<a href="comment.php?action=editcomment&amp;c='.$comment->comment_ID.'#akismet-status" title="'. esc_attr__( 'View comment history' ) . '"> '. __('History') . '</a>';
    346                 }
    347                
    348                 $a = $b;
    349         }
    350                
    351         if ( $desc )
    352                 echo '<span class="akismet-status" commentid="'.$comment->comment_ID.'"><a href="comment.php?action=editcomment&amp;c='.$comment->comment_ID.'#akismet-status" title="' . esc_attr__( 'View comment history' ) . '">'.htmlspecialchars($desc).'</a></span>';
    353                
    354         if ( apply_filters( 'akismet_show_user_comments_approved', get_option('akismet_show_user_comments_approved') ) == 'true' ) {
    355                 $comment_count = akimset_get_user_comments_approved( $comment->user_id, $comment->comment_author_email, $comment->comment_author, $comment->comment_author_url );
    356                 echo '<span class="akismet-user-comment-count" commentid="'.$comment->comment_ID.'" style="display:none;"><br><span class="akismet-user-comment-counts">'.sprintf( _n( '%s approved', '%s approved', $comment_count ), intval($comment_count) ).'</span></span>';
    357         }
    358        
    359         return $a;
    360 }
    361 
    362 add_filter( 'comment_row_actions', 'akismet_comment_row_action', 10, 2 );
    363 
    364 function akismet_comment_status_meta_box($comment) {
    365         $history = akismet_get_comment_history( $comment->comment_ID );
    366 
    367         if ( $history ) {
    368                 echo '<div class="akismet-history" style="margin: 13px;">';
    369                 foreach ( $history as $row ) {
    370                         $time = date( 'D d M Y @ h:i:m a', $row['time'] ) . ' GMT';
    371                         echo '<div style="margin-bottom: 13px;"><span style="color: #999;" alt="' . $time . '" title="' . $time . '">' . sprintf( __('%s ago'), human_time_diff( $row['time'] ) ) . '</span> - ';
    372                         echo htmlspecialchars( $row['message'] ) . '</div>';
    373                 }
    374                
    375                 echo '</div>';
    376 
    377         }
    378 }
    379 
    380 
    381 // add an extra column header to the comments screen
    382 function akismet_comments_columns( $columns ) {
    383         $columns[ 'akismet' ] = __( 'Akismet' );
    384         return $columns;
    385 }
    386 
    387 #add_filter( 'manage_edit-comments_columns', 'akismet_comments_columns' );
    388 
    389 // Show stuff in the extra column
    390 function akismet_comment_column_row( $column, $comment_id ) {
    391         if ( $column != 'akismet' )
    392                 return;
    393                
    394         $history = akismet_get_comment_history( $comment_id );
    395        
    396         if ( $history ) {
    397                 echo '<dl class="akismet-history">';
    398                 foreach ( $history as $row ) {
    399                         echo '<dt>' . sprintf( __('%s ago'), human_time_diff( $row['time'] ) ) . '</dt>';
    400                         echo '<dd>' . htmlspecialchars( $row['message'] ) . '</dd>';
    401                 }
    402                
    403                 echo '</dl>';
    404         }
    405 }
    406 
    407 #add_action( 'manage_comments_custom_column', 'akismet_comment_column_row', 10, 2 );
    408 
    409 // END FIXME
    410 
    411 // call out URLS in comments
    412 function akismet_text_add_link_callback( $m ) {
    413        
    414                 // bare link?
    415         if ( $m[4] == $m[2] )
    416                 return '<a '.$m[1].' href="'.$m[2].'" '.$m[3].' class="comment-link">'.$m[4].'</a>';
    417         else
    418                 return '<span title="'.$m[2].'" class="comment-link"><a '.$m[1].' href="'.$m[2].'" '.$m[3].' class="comment-link">'.$m[4].'</a></span>';
    419 }
    420 
    421 function akismet_text_add_link_class( $comment_text ) {
    422 
    423         return preg_replace_callback( '#<a ([^>]*)href="([^"]+)"([^>]*)>(.*?)</a>#i', 'akismet_text_add_link_callback', $comment_text );
    424 }
    425 
    426 add_filter('comment_text', 'akismet_text_add_link_class');
    427 
    428 
    429 // WP 2.5+
    430 function akismet_rightnow() {
    431         global $submenu, $wp_db_version;
    432 
    433         $plural_func = '__ngettext';
    434         if ( function_exists( '_n' ) )
    435                 $plural_func = '_n';
    436 
    437         // clean_url was deprecated in WP 3.0
    438         $esc_url = 'clean_url';
    439         if ( function_exists( 'esc_url' ) )
    440                 $esc_url = 'esc_url';
    441 
    442         if ( 8645 < $wp_db_version  ) // 2.7
    443                 $link = 'edit-comments.php?comment_status=spam';
    444         elseif ( isset( $submenu['edit-comments.php'] ) )
    445                 $link = 'edit-comments.php?page=akismet-admin';
    446         else
    447                 $link = 'edit.php?page=akismet-admin';
    448 
    449         if ( $count = get_option('akismet_spam_count') ) {
    450                 $intro = sprintf( $plural_func(
    451                         '<a href="%1$s">Akismet</a> has protected your site from %2$s spam comment already. ',
    452                         '<a href="%1$s">Akismet</a> has protected your site from %2$s spam comments already. ',
    453                         $count
    454                 ), 'http://akismet.com/', number_format_i18n( $count ) );
    455         } else {
    456                 $intro = sprintf( __('<a href="%1$s">Akismet</a> blocks spam from getting to your blog. '), 'http://akismet.com/' );
    457         }
    458 
    459         if ( $queue_count = akismet_spam_count() ) {
    460                 $queue_text = sprintf( $plural_func(
    461                         'There\'s <a href="%2$s">%1$s comment</a> in your spam queue right now.',
    462                         'There are <a href="%2$s">%1$s comments</a> in your spam queue right now.',
    463                         $queue_count
    464                 ), number_format_i18n( $queue_count ), $esc_url($link) );
    465         } else {
    466                 $queue_text = sprintf( __( "There's nothing in your <a href='%1\$s'>spam queue</a> at the moment." ), $esc_url($link) );
    467         }
    468 
    469         $text = $intro . '<br />' . $queue_text;
    470         echo "<p class='akismet-right-now'>$text</p>\n";
    471 }
    472        
    473 add_action('rightnow_end', 'akismet_rightnow');
    474 
    475 
    476 // For WP >= 2.5
    477 function akismet_check_for_spam_button($comment_status) {
    478         if ( 'approved' == $comment_status )
    479                 return;
    480         if ( function_exists('plugins_url') )
    481                 $link = 'admin.php?action=akismet_recheck_queue';
    482         else
    483                 $link = 'edit-comments.php?page=akismet-admin&amp;recheckqueue=true&amp;noheader=true';
    484         echo "</div><div class='alignleft'><a class='button-secondary checkforspam' href='$link'>" . __('Check for Spam') . "</a>";
    485 }
    486 add_action('manage_comments_nav', 'akismet_check_for_spam_button');
    487 
    488 function akismet_submit_nonspam_comment ( $comment_id ) {
    489         global $wpdb, $akismet_api_host, $akismet_api_port, $current_user, $current_site;
    490         $comment_id = (int) $comment_id;
    491 
    492         $comment = $wpdb->get_row("SELECT * FROM $wpdb->comments WHERE comment_ID = '$comment_id'");
    493         if ( !$comment ) // it was deleted
    494                 return;
    495                
    496         // use the original version stored in comment_meta if available
    497         $as_submitted = get_comment_meta( $comment_id, 'akismet_as_submitted', true);
    498         if ( $as_submitted && is_array($as_submitted) && isset($as_submitted['comment_content']) ) {
    499                 $comment = (object) array_merge( (array)$comment, $as_submitted );
    500         }
    501        
    502         $comment->blog = get_bloginfo('url');
    503         $comment->blog_lang = get_locale();
    504         $comment->blog_charset = get_option('blog_charset');
    505         $comment->permalink = get_permalink($comment->comment_post_ID);
    506         $comment->reporter_ip = $_SERVER['REMOTE_ADDR'];
    507         if ( is_object($current_user) ) {
    508             $comment->reporter = $current_user->user_login;
    509         }
    510         if ( is_object($current_site) ) {
    511                 $comment->site_domain = $current_site->domain;
    512         }
    513 
    514         $comment->user_role = '';
    515         if ( isset( $comment->user_ID ) )
    516                 $comment->user_role = akismet_get_user_roles($comment->user_ID);
    517 
    518         if ( akismet_test_mode() )
    519                 $comment->is_test = 'true';
    520 
    521         $query_string = '';
    522         foreach ( $comment as $key => $data )
    523                 $query_string .= $key . '=' . urlencode( stripslashes($data) ) . '&';
    524 
    525         $response = akismet_http_post($query_string, $akismet_api_host, "/1.1/submit-ham", $akismet_api_port);
    526         if ( $comment->reporter ) {
    527                 akismet_update_comment_history( $comment_id, sprintf( __('%s reported this comment as not spam'), $comment->reporter ), 'report-ham' );
    528                 update_comment_meta( $comment_id, 'akismet_user_result', 'false' );
    529                 update_comment_meta( $comment_id, 'akismet_user', $comment->reporter );
    530         }
    531        
    532         do_action('akismet_submit_nonspam_comment', $comment_id, $response[1]);
    533 }
    534 
    535 function akismet_submit_spam_comment ( $comment_id ) {
    536         global $wpdb, $akismet_api_host, $akismet_api_port, $current_user, $current_site;
    537         $comment_id = (int) $comment_id;
    538 
    539         $comment = $wpdb->get_row("SELECT * FROM $wpdb->comments WHERE comment_ID = '$comment_id'");
    540         if ( !$comment ) // it was deleted
    541                 return;
    542         if ( 'spam' != $comment->comment_approved )
    543                 return;
    544        
    545         // use the original version stored in comment_meta if available
    546         $as_submitted = get_comment_meta( $comment_id, 'akismet_as_submitted', true);
    547         if ( $as_submitted && is_array($as_submitted) && isset($as_submitted['comment_content']) ) {
    548                 $comment = (object) array_merge( (array)$comment, $as_submitted );
    549         }
    550        
    551         $comment->blog = get_bloginfo('url');
    552         $comment->blog_lang = get_locale();
    553         $comment->blog_charset = get_option('blog_charset');
    554         $comment->permalink = get_permalink($comment->comment_post_ID);
    555         $comment->reporter_ip = $_SERVER['REMOTE_ADDR'];
    556         if ( is_object($current_user) ) {
    557             $comment->reporter = $current_user->user_login;
    558         }
    559         if ( is_object($current_site) ) {
    560                 $comment->site_domain = $current_site->domain;
    561         }
    562 
    563         $comment->user_role = '';
    564         if ( isset( $comment->user_ID ) )
    565                 $comment->user_role = akismet_get_user_roles($comment->user_ID);
    566 
    567         if ( akismet_test_mode() )
    568                 $comment->is_test = 'true';
    569 
    570         $query_string = '';
    571         foreach ( $comment as $key => $data )
    572                 $query_string .= $key . '=' . urlencode( stripslashes($data) ) . '&';
    573 
    574         $response = akismet_http_post($query_string, $akismet_api_host, "/1.1/submit-spam", $akismet_api_port);
    575         if ( $comment->reporter ) {
    576                 akismet_update_comment_history( $comment_id, sprintf( __('%s reported this comment as spam'), $comment->reporter ), 'report-spam' );
    577                 update_comment_meta( $comment_id, 'akismet_user_result', 'true' );
    578                 update_comment_meta( $comment_id, 'akismet_user', $comment->reporter );
    579         }
    580         do_action('akismet_submit_spam_comment', $comment_id, $response[1]);
    581 }
    582 
    583 // For WP 2.7+
    584 function akismet_transition_comment_status( $new_status, $old_status, $comment ) {
    585         if ( $new_status == $old_status )
    586                 return;
    587                
    588         if ( !is_admin() )
    589                 return;
    590                
    591         if ( !current_user_can( 'edit_post', $comment->comment_post_ID ) && !current_user_can( 'moderate_comments' ) )
    592                 return;
    593 
    594         if ( defined('WP_IMPORTING') && WP_IMPORTING == true )
    595                 return;
    596                
    597         global $current_user;
    598         $reporter = '';
    599         if ( is_object( $current_user ) )
    600                 $reporter = $current_user->user_login;
    601        
    602         // Assumption alert:
    603         // We want to submit comments to Akismet only when a moderator explicitly spams or approves it - not if the status
    604         // is changed automatically by another plugin.  Unfortunately WordPress doesn't provide an unambiguous way to
    605         // determine why the transition_comment_status action was triggered.  And there are several different ways by which
    606         // to spam and unspam comments: bulk actions, ajax, links in moderation emails, the dashboard, and perhaps others.
    607         // We'll assume that this is an explicit user action if POST or GET has an 'action' key.
    608         if ( isset($_POST['action']) || isset($_GET['action']) ) {
    609                 if ( $new_status == 'spam' && ( $old_status == 'approved' || $old_status == 'unapproved' || !$old_status ) ) {
    610                                 return akismet_submit_spam_comment( $comment->comment_ID );
    611                 } elseif ( $old_status == 'spam' && ( $new_status == 'approved' || $new_status == 'unapproved' ) ) {
    612                                 return akismet_submit_nonspam_comment( $comment->comment_ID );
    613                 }
    614         }
    615        
    616         if ( !get_comment_meta( $comment->comment_ID, 'akismet_rechecking' ) )
    617                 akismet_update_comment_history( $comment->comment_ID, sprintf( __('%s changed the comment status to %s'), $reporter, $new_status ), 'status-' . $new_status );
    618 }
    619 
    620 add_action( 'transition_comment_status', 'akismet_transition_comment_status', 10, 3 );
    621 
    622 // Total spam in queue
    623 // get_option( 'akismet_spam_count' ) is the total caught ever
    624 function akismet_spam_count( $type = false ) {
    625         global $wpdb;
    626 
    627         if ( !$type ) { // total
    628                 $count = wp_cache_get( 'akismet_spam_count', 'widget' );
    629                 if ( false === $count ) {
    630                         if ( function_exists('wp_count_comments') ) {
    631                                 $count = wp_count_comments();
    632                                 $count = $count->spam;
    633                         } else {
    634                                 $count = (int) $wpdb->get_var("SELECT COUNT(comment_ID) FROM $wpdb->comments WHERE comment_approved = 'spam'");
    635                         }
    636                         wp_cache_set( 'akismet_spam_count', $count, 'widget', 3600 );
    637                 }
    638                 return $count;
    639         } elseif ( 'comments' == $type || 'comment' == $type ) { // comments
    640                 $type = '';
    641         } else { // pingback, trackback, ...
    642                 $type  = $wpdb->escape( $type );
    643         }
    644 
    645         return (int) $wpdb->get_var("SELECT COUNT(comment_ID) FROM $wpdb->comments WHERE comment_approved = 'spam' AND comment_type='$type'");
    646 }
    647 
    648 
    649 function akismet_recheck_queue() {
    650         global $wpdb, $akismet_api_host, $akismet_api_port;
    651 
    652         if ( ! ( isset( $_GET['recheckqueue'] ) || ( isset( $_REQUEST['action'] ) && 'akismet_recheck_queue' == $_REQUEST['action'] ) ) )
    653                 return;
    654                
    655         $moderation = $wpdb->get_results( "SELECT * FROM $wpdb->comments WHERE comment_approved = '0'", ARRAY_A );
    656         foreach ( (array) $moderation as $c ) {
    657                 $c['user_ip']    = $c['comment_author_IP'];
    658                 $c['user_agent'] = $c['comment_agent'];
    659                 $c['referrer']   = '';
    660                 $c['blog']       = get_bloginfo('url');
    661                 $c['blog_lang']  = get_locale();
    662                 $c['blog_charset'] = get_option('blog_charset');
    663                 $c['permalink']  = get_permalink($c['comment_post_ID']);
    664 
    665                 $c['user_role'] = '';
    666                 if ( isset( $c['user_ID'] ) )
    667                         $c['user_role']  = akismet_get_user_roles($c['user_ID']);
    668 
    669                 if ( akismet_test_mode() )
    670                         $c['is_test'] = 'true';
    671 
    672                 $id = (int) $c['comment_ID'];
    673 
    674                 $query_string = '';
    675                 foreach ( $c as $key => $data )
    676                 $query_string .= $key . '=' . urlencode( stripslashes($data) ) . '&';
    677 
    678                 $response = akismet_http_post($query_string, $akismet_api_host, '/1.1/comment-check', $akismet_api_port);
    679                 if ( 'true' == $response[1] ) {
    680                         wp_set_comment_status($c['comment_ID'], 'spam');
    681                         update_comment_meta( $c['comment_ID'], 'akismet_result', 'true' );
    682                         akismet_update_comment_history( $c['comment_ID'], __('Akismet re-checked and caught this comment as spam'), 'check-spam' );
    683                
    684                 } elseif ( 'false' == $response[1] ) {
    685                         update_comment_meta( $c['comment_ID'], 'akismet_result', 'false' );
    686                         akismet_update_comment_history( $c['comment_ID'], __('Akismet re-checked and cleared this comment'), 'check-ham' );
    687                 // abnormal result: error
    688                 } else {
    689                         update_comment_meta( $c['comment_ID'], 'akismet_result', 'error' );
    690                         akismet_update_comment_history( $c['comment_ID'], sprintf( __('Akismet was unable to re-check this comment (response: %s)'), $response[1]), 'check-error' );
    691                 }
    692 
    693         }
    694         wp_redirect( $_SERVER['HTTP_REFERER'] );
    695         exit;
    696 }
    697 
    698 add_action('admin_action_akismet_recheck_queue', 'akismet_recheck_queue');
    699 
    700 // Check connectivity between the WordPress blog and Akismet's servers.
    701 // Returns an associative array of server IP addresses, where the key is the IP address, and value is true (available) or false (unable to connect).
    702 function akismet_check_server_connectivity() {
    703         global $akismet_api_host, $akismet_api_port, $wpcom_api_key;
    704        
    705         $test_host = 'rest.akismet.com';
    706        
    707         // Some web hosts may disable one or both functions
    708         if ( !function_exists('fsockopen') || !function_exists('gethostbynamel') )
    709                 return array();
    710        
    711         $ips = gethostbynamel($test_host);
    712         if ( !$ips || !is_array($ips) || !count($ips) )
    713                 return array();
    714                
    715         $servers = array();
    716         foreach ( $ips as $ip ) {
    717                 $response = akismet_verify_key( akismet_get_key(), $ip );
    718                 // even if the key is invalid, at least we know we have connectivity
    719                 if ( $response == 'valid' || $response == 'invalid' )
    720                         $servers[$ip] = true;
    721                 else
    722                         $servers[$ip] = false;
    723         }
    724 
    725         return $servers;
    726 }
    727 
    728 // Check the server connectivity and store the results in an option.
    729 // Cached results will be used if not older than the specified timeout in seconds; use $cache_timeout = 0 to force an update.
    730 // Returns the same associative array as akismet_check_server_connectivity()
    731 function akismet_get_server_connectivity( $cache_timeout = 86400 ) {
    732         $servers = get_option('akismet_available_servers');
    733         if ( (time() - get_option('akismet_connectivity_time') < $cache_timeout) && $servers !== false )
    734                 return $servers;
    735        
    736         // There's a race condition here but the effect is harmless.
    737         $servers = akismet_check_server_connectivity();
    738         update_option('akismet_available_servers', $servers);
    739         update_option('akismet_connectivity_time', time());
    740         return $servers;
    741 }
    742 
    743 // Returns true if server connectivity was OK at the last check, false if there was a problem that needs to be fixed.
    744 function akismet_server_connectivity_ok() {
    745         // skip the check on WPMU because the status page is hidden
    746         global $wpcom_api_key;
    747         if ( $wpcom_api_key )
    748                 return true;
    749         $servers = akismet_get_server_connectivity();
    750         return !( empty($servers) || !count($servers) || count( array_filter($servers) ) < count($servers) );
    751 }
    752 
  • wp-content/plugins/akismet/akismet.css

     
    1 #submitted-on { position: relative; }
    2 #the-comment-list .author { padding-bottom: 5px !important; white-space: nowrap; }
    3 #the-comment-list .author a { padding-left: 42px !important; }
    4 #the-comment-list .author img { position: absolute; top: 0; left: 0; }
    5 #the-comment-list .author strong { padding-left: 42px; font-size: 12px; position: relative; }
    6 #the-comment-list .author .akismet-user-comment-count { display: inline; }
    7 #the-comment-list .author .akismet-user-comment-counts { padding-left: 42px; }
    8 #dashboard_recent_comments .akismet-status { display: none; } /* never show the flagged by text on the dashboard */
    9 .akismet-status { float: right; }
    10 .akismet-status a { color: #AAA; font-style: italic; }
    11 span.comment-link a { text-decoration: underline; }
    12 span.comment-link:after { content: " " attr(title) " "; color: #aaa; text-decoration: none; }
    13  No newline at end of file
  • wp-content/plugins/akismet/akismet.js

    Cannot display: file marked as a binary type.
    svn:mime-type = application/octet-stream
     
    1 jQuery(document).ready(function () {
    2         jQuery('.akismet-status').each(function () {
    3                 var thisId = jQuery(this).attr('commentid');
    4                 jQuery(this).prependTo('#comment-' + thisId + ' .column-comment div:first-child');
    5         });
    6         jQuery('.akismet-user-comment-count').each(function () {
    7                 var thisId = jQuery(this).attr('commentid');
    8                 jQuery(this).insertAfter('#comment-' + thisId + ' .author strong:first').show();
    9         });
    10 });
  • wp-content/plugins/akismet/akismet.php

     
    1 <?php
    2 /**
    3  * @package Akismet
    4  */
    5 /*
    6 Plugin Name: Akismet
    7 Plugin URI: http://akismet.com/
    8 Description: Used by millions, Akismet is quite possibly the best way in the world to <strong>protect your blog from comment and track-back spam</strong>. It keeps your site protected from spam even while you sleep. To get started: 1) Click the "Activate" link to the left of this description, 2) <a href="http://akismet.com/get/?return=true">Sign up for an Akismet API key</a>, and 3) Go to your <a href="plugins.php?page=akismet-key-config">Akismet configuration</a> page, and save your API key.
    9 Version: 2.5.1
    10 Author: Automattic
    11 Author URI: http://automattic.com/wordpress-plugins/
    12 License: GPLv2
    13 */
    14 
    15 /*
    16 This program is free software; you can redistribute it and/or
    17 modify it under the terms of the GNU General Public License
    18 as published by the Free Software Foundation; either version 2
    19 of the License, or (at your option) any later version.
    20 
    21 This program is distributed in the hope that it will be useful,
    22 but WITHOUT ANY WARRANTY; without even the implied warranty of
    23 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    24 GNU General Public License for more details.
    25 
    26 You should have received a copy of the GNU General Public License
    27 along with this program; if not, write to the Free Software
    28 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
    29 */
    30 
    31 define('AKISMET_VERSION', '2.5.0');
    32 define('AKISMET_PLUGIN_URL', plugin_dir_url( __FILE__ ));
    33 
    34 /** If you hardcode a WP.com API key here, all key config screens will be hidden */
    35 if ( defined('WPCOM_API_KEY') )
    36         $wpcom_api_key = constant('WPCOM_API_KEY');
    37 else
    38         $wpcom_api_key = '';
    39 
    40 // Make sure we don't expose any info if called directly
    41 if ( !function_exists( 'add_action' ) ) {
    42         echo "Hi there!  I'm just a plugin, not much I can do when called directly.";
    43         exit;
    44 }
    45 
    46 if ( isset($wp_db_version) && $wp_db_version <= 9872 )
    47         include_once dirname( __FILE__ ) . '/legacy.php';
    48 
    49 include_once dirname( __FILE__ ) . '/widget.php';
    50 
    51 if ( is_admin() )
    52         require_once dirname( __FILE__ ) . '/admin.php';
    53 
    54 function akismet_init() {
    55         global $wpcom_api_key, $akismet_api_host, $akismet_api_port;
    56 
    57         if ( $wpcom_api_key )
    58                 $akismet_api_host = $wpcom_api_key . '.rest.akismet.com';
    59         else
    60                 $akismet_api_host = get_option('wordpress_api_key') . '.rest.akismet.com';
    61 
    62         $akismet_api_port = 80;
    63 }
    64 add_action('init', 'akismet_init');
    65 
    66 function akismet_get_key() {
    67         global $wpcom_api_key;
    68         if ( !empty($wpcom_api_key) )
    69                 return $wpcom_api_key;
    70         return get_option('wordpress_api_key');
    71 }
    72 
    73 function akismet_verify_key( $key, $ip = null ) {
    74         global $akismet_api_host, $akismet_api_port, $wpcom_api_key;
    75         $blog = urlencode( get_option('home') );
    76         if ( $wpcom_api_key )
    77                 $key = $wpcom_api_key;
    78         $response = akismet_http_post("key=$key&blog=$blog", 'rest.akismet.com', '/1.1/verify-key', $akismet_api_port, $ip);
    79         if ( !is_array($response) || !isset($response[1]) || $response[1] != 'valid' && $response[1] != 'invalid' )
    80                 return 'failed';
    81         return $response[1];
    82 }
    83 
    84 // if we're in debug or test modes, use a reduced service level so as not to polute training or stats data
    85 function akismet_test_mode() {
    86         if ( defined('AKISMET_TEST_MODE') && AKISMET_TEST_MODE )
    87                 return true;
    88         return false;
    89 }
    90 
    91 // return a comma-separated list of role names for the given user
    92 function akismet_get_user_roles($user_id ) {
    93         $roles = false;
    94        
    95         if ( !class_exists('WP_User') )
    96                 return false;
    97        
    98         if ( $user_id > 0 ) {
    99                 $comment_user = new WP_User($user_id);
    100                 if ( isset($comment_user->roles) )
    101                         $roles = join(',', $comment_user->roles);
    102         }
    103        
    104         return $roles;
    105 }
    106 
    107 // Returns array with headers in $response[0] and body in $response[1]
    108 function akismet_http_post($request, $host, $path, $port = 80, $ip=null) {
    109         global $wp_version;
    110 
    111         $akismet_ua = "WordPress/{$wp_version} | ";
    112         $akismet_ua .= 'Akismet/' . constant( 'AKISMET_VERSION' );
    113 
    114         $content_length = strlen( $request );
    115 
    116         $http_host = $host;
    117         // use a specific IP if provided
    118         // needed by akismet_check_server_connectivity()
    119         if ( $ip && long2ip( ip2long( $ip ) ) ) {
    120                 $http_host = $ip;
    121         } else {
    122                 $http_host = $host;
    123         }
    124        
    125         // use the WP HTTP class if it is available
    126         if ( function_exists( 'wp_remote_post' ) ) {
    127                 $http_args = array(
    128                         'body'                  => $request,
    129                         'headers'               => array(
    130                                 'Content-Type'  => 'application/x-www-form-urlencoded; ' .
    131                                                                         'charset=' . get_option( 'blog_charset' ),
    132                                 'Host'                  => $host,
    133                                 'User-Agent'    => $akismet_ua
    134                         ),
    135                         'httpversion'   => '1.0'
    136                 );
    137                 $akismet_url = "http://{$http_host}{$path}";
    138                 $response = wp_remote_post( $akismet_url, $http_args );
    139                 if ( is_wp_error( $response ) )
    140                         return '';
    141 
    142                 return array( $response['headers'], $response['body'] );
    143         } else {
    144                 $http_request  = "POST $path HTTP/1.0\r\n";
    145                 $http_request .= "Host: $host\r\n";
    146                 $http_request .= 'Content-Type: application/x-www-form-urlencoded; charset=' . get_option('blog_charset') . "\r\n";
    147                 $http_request .= "Content-Length: {$content_length}\r\n";
    148                 $http_request .= "User-Agent: {$akismet_ua}\r\n";
    149                 $http_request .= "\r\n";
    150                 $http_request .= $request;
    151                
    152                 $response = '';
    153                 if( false != ( $fs = @fsockopen( $http_host, $port, $errno, $errstr, 10 ) ) ) {
    154                         fwrite( $fs, $http_request );
    155 
    156                         while ( !feof( $fs ) )
    157                                 $response .= fgets( $fs, 1160 ); // One TCP-IP packet
    158                         fclose( $fs );
    159                         $response = explode( "\r\n\r\n", $response, 2 );
    160                 }
    161                 return $response;
    162         }
    163 }
    164 
    165 // filter handler used to return a spam result to pre_comment_approved
    166 function akismet_result_spam( $approved ) {
    167         // bump the counter here instead of when the filter is added to reduce the possibility of overcounting
    168         if ( $incr = apply_filters('akismet_spam_count_incr', 1) )
    169                 update_option( 'akismet_spam_count', get_option('akismet_spam_count') + $incr );
    170         // this is a one-shot deal
    171         remove_filter( 'pre_comment_approved', 'akismet_result_spam' );
    172         return 'spam';
    173 }
    174 
    175 function akismet_result_hold( $approved ) {
    176         // once only
    177         remove_filter( 'pre_comment_approved', 'akismet_result_hold' );
    178         return '0';
    179 }
    180 
    181 // how many approved comments does this author have?
    182 function akimset_get_user_comments_approved( $user_id, $comment_author_email, $comment_author, $comment_author_url ) {
    183         global $wpdb;
    184        
    185         if ( !empty($user_id) )
    186                 return $wpdb->get_var( $wpdb->prepare( "SELECT COUNT(*) FROM $wpdb->comments WHERE user_id = %d AND comment_approved = 1", $user_id ) );
    187                
    188         if ( !empty($comment_author_email) )
    189                 return $wpdb->get_var( $wpdb->prepare( "SELECT COUNT(*) FROM $wpdb->comments WHERE comment_author_email = %s AND comment_author = %s AND comment_author_url = %s AND comment_approved = 1", $comment_author_email, $comment_author, $comment_author_url ) );
    190                
    191         return 0;
    192 }
    193 
    194 function akismet_microtime() {
    195         $mtime = explode( ' ', microtime() );
    196         return $mtime[1] + $mtime[0];
    197 }
    198 
    199 // log an event for a given comment, storing it in comment_meta
    200 function akismet_update_comment_history( $comment_id, $message, $event=null ) {
    201         global $current_user;
    202 
    203         // failsafe for old WP versions
    204         if ( !function_exists('add_comment_meta') )
    205                 return false;
    206        
    207         $user = '';
    208         if ( is_object($current_user) && isset($current_user->user_login) )
    209                 $user = $current_user->user_login;
    210 
    211         $event = array(
    212                 'time' => akismet_microtime(),
    213                 'message' => $message,
    214                 'event' => $event,
    215                 'user' => $user,
    216         );
    217 
    218         // $unique = false so as to allow multiple values per comment
    219         $r = add_comment_meta( $comment_id, 'akismet_history', $event, false );
    220 }
    221 
    222 // get the full comment history for a given comment, as an array in reverse chronological order
    223 function akismet_get_comment_history( $comment_id ) {
    224        
    225         // failsafe for old WP versions
    226         if ( !function_exists('add_comment_meta') )
    227                 return false;
    228 
    229         $history = get_comment_meta( $comment_id, 'akismet_history', false );
    230         usort( $history, 'akismet_cmp_time' );
    231         return $history;
    232 }
    233 
    234 function akismet_cmp_time( $a, $b ) {
    235         return $a['time'] > $b['time'] ? -1 : 1;
    236 }
    237 
    238 // this fires on wp_insert_comment.  we can't update comment_meta when akismet_auto_check_comment() runs
    239 // because we don't know the comment ID at that point.
    240 function akismet_auto_check_update_meta( $id, $comment ) {
    241         global $akismet_last_comment;
    242 
    243         // failsafe for old WP versions
    244         if ( !function_exists('add_comment_meta') )
    245                 return false;
    246 
    247         // wp_insert_comment() might be called in other contexts, so make sure this is the same comment
    248         // as was checked by akismet_auto_check_comment
    249         if ( is_object($comment) && !empty($akismet_last_comment) && is_array($akismet_last_comment) ) {
    250                 if ( intval($akismet_last_comment['comment_post_ID']) == intval($comment->comment_post_ID)
    251                         && $akismet_last_comment['comment_author'] == $comment->comment_author
    252                         && $akismet_last_comment['comment_author_email'] == $comment->comment_author_email ) {
    253                                 // normal result: true or false
    254                                 if ( $akismet_last_comment['akismet_result'] == 'true' ) {
    255                                         update_comment_meta( $comment->comment_ID, 'akismet_result', 'true' );
    256                                         akismet_update_comment_history( $comment->comment_ID, __('Akismet caught this comment as spam'), 'check-spam' );
    257                                         if ( $comment->comment_approved != 'spam' )
    258                                                 akismet_update_comment_history( $comment->comment_ID, sprintf( __('Comment status was changed to %s'), $comment->comment_approved), 'status-changed'.$comment->comment_approved );
    259                                 } elseif ( $akismet_last_comment['akismet_result'] == 'false' ) {
    260                                         update_comment_meta( $comment->comment_ID, 'akismet_result', 'false' );
    261                                         akismet_update_comment_history( $comment->comment_ID, __('Akismet cleared this comment'), 'check-ham' );
    262                                         if ( $comment->comment_approved == 'spam' ) {
    263                                                 if ( wp_blacklist_check($comment->comment_author, $comment->comment_author_email, $comment->comment_author_url, $comment->comment_content, $comment->comment_author_IP, $comment->comment_agent) )
    264                                                         akismet_update_comment_history( $comment->comment_ID, __('Comment was caught by wp_blacklist_check'), 'wp-blacklisted' );
    265                                                 else
    266                                                         akismet_update_comment_history( $comment->comment_ID, sprintf( __('Comment status was changed to %s'), $comment->comment_approved), 'status-changed-'.$comment->comment_approved );
    267                                         }
    268                                 // abnormal result: error
    269                                 } else {
    270                                         update_comment_meta( $comment->comment_ID, 'akismet_error', time() );
    271                                         akismet_update_comment_history( $comment->comment_ID, sprintf( __('Akismet was unable to check this comment (response: %s), will automatically retry again later.'), $akismet_last_comment['akismet_result']), 'check-error' );
    272                                 }
    273                                
    274                                 // record the complete original data as submitted for checking
    275                                 if ( isset($akismet_last_comment['comment_as_submitted']) )
    276                                         update_comment_meta( $comment->comment_ID, 'akismet_as_submitted', $akismet_last_comment['comment_as_submitted'] );
    277                 }
    278         }
    279 }
    280 
    281 add_action( 'wp_insert_comment', 'akismet_auto_check_update_meta', 10, 2 );
    282 
    283 
    284 function akismet_auto_check_comment( $commentdata ) {
    285         global $akismet_api_host, $akismet_api_port, $akismet_last_comment;
    286 
    287         $comment = $commentdata;
    288         $comment['user_ip']    = $_SERVER['REMOTE_ADDR'];
    289         $comment['user_agent'] = $_SERVER['HTTP_USER_AGENT'];
    290         $comment['referrer']   = $_SERVER['HTTP_REFERER'];
    291         $comment['blog']       = get_option('home');
    292         $comment['blog_lang']  = get_locale();
    293         $comment['blog_charset'] = get_option('blog_charset');
    294         $comment['permalink']  = get_permalink($comment['comment_post_ID']);
    295        
    296         $comment['user_role'] = akismet_get_user_roles($comment['user_ID']);
    297 
    298         $akismet_nonce_option = apply_filters( 'akismet_comment_nonce', get_option( 'akismet_comment_nonce' ) );
    299         $comment['akismet_comment_nonce'] = 'inactive';
    300         if ( $akismet_nonce_option == 'true' || $akismet_nonce_option == '' ) {
    301                 $comment['akismet_comment_nonce'] = 'failed';
    302                 if ( isset( $_POST['akismet_comment_nonce'] ) && wp_verify_nonce( $_POST['akismet_comment_nonce'], 'akismet_comment_nonce_' . $comment['comment_post_ID'] ) )
    303                         $comment['akismet_comment_nonce'] = 'passed';
    304 
    305                 // comment reply in wp-admin
    306                 if ( isset( $_POST['_ajax_nonce-replyto-comment'] ) && check_ajax_referer( 'replyto-comment', '_ajax_nonce-replyto-comment' ) )
    307                         $comment['akismet_comment_nonce'] = 'passed';
    308 
    309         }
    310 
    311         if ( akismet_test_mode() )
    312                 $comment['is_test'] = 'true';
    313                
    314         foreach ($_POST as $key => $value ) {
    315                 if ( is_string($value) )
    316                         $comment["POST_{$key}"] = $value;
    317         }
    318 
    319         $ignore = array( 'HTTP_COOKIE', 'HTTP_COOKIE2', 'PHP_AUTH_PW' );
    320 
    321         foreach ( $_SERVER as $key => $value ) {
    322                 if ( !in_array( $key, $ignore ) && is_string($value) )
    323                         $comment["$key"] = $value;
    324                 else
    325                         $comment["$key"] = '';
    326         }
    327 
    328         $query_string = '';
    329         foreach ( $comment as $key => $data )
    330                 $query_string .= $key . '=' . urlencode( stripslashes($data) ) . '&';
    331                
    332         $commentdata['comment_as_submitted'] = $comment;
    333 
    334         $response = akismet_http_post($query_string, $akismet_api_host, '/1.1/comment-check', $akismet_api_port);
    335         $commentdata['akismet_result'] = $response[1];
    336         if ( 'true' == $response[1] ) {
    337                 // akismet_spam_count will be incremented later by akismet_result_spam()
    338                 add_filter('pre_comment_approved', 'akismet_result_spam');
    339 
    340                 do_action( 'akismet_spam_caught' );
    341 
    342                 $post = get_post( $comment['comment_post_ID'] );
    343                 $last_updated = strtotime( $post->post_modified_gmt );
    344                 $diff = time() - $last_updated;
    345                 $diff = $diff / 86400;
    346                
    347                 if ( $post->post_type == 'post' && $diff > 30 && get_option( 'akismet_discard_month' ) == 'true' && empty($comment['user_ID']) ) {
    348                         // akismet_result_spam() won't be called so bump the counter here
    349                         if ( $incr = apply_filters('akismet_spam_count_incr', 1) )
    350                                 update_option( 'akismet_spam_count', get_option('akismet_spam_count') + $incr );
    351                         wp_redirect( $_SERVER['HTTP_REFERER'] );
    352                         die();
    353                 }
    354         }
    355        
    356         // if the response is neither true nor false, hold the comment for moderation and schedule a recheck
    357         if ( 'true' != $response[1] && 'false' != $response[1] ) {
    358                 add_filter('pre_comment_approved', 'akismet_result_hold');
    359                 wp_schedule_single_event( time() + 1200, 'akismet_schedule_cron_recheck' );
    360         }
    361        
    362         if ( function_exists('wp_next_scheduled') && function_exists('wp_schedule_event') ) {
    363                 // WP 2.1+: delete old comments daily
    364                 if ( !wp_next_scheduled('akismet_scheduled_delete') )
    365                         wp_schedule_event(time(), 'daily', 'akismet_scheduled_delete');
    366         } elseif ( (mt_rand(1, 10) == 3) ) {
    367                 // WP 2.0: run this one time in ten
    368                 akismet_delete_old();
    369         }
    370         $akismet_last_comment = $commentdata;
    371         return $commentdata;
    372 }
    373 
    374 add_action('preprocess_comment', 'akismet_auto_check_comment', 1);
    375 
    376 function akismet_delete_old() {
    377         global $wpdb;
    378         $now_gmt = current_time('mysql', 1);
    379         $comment_ids = $wpdb->get_col("SELECT comment_id FROM $wpdb->comments WHERE DATE_SUB('$now_gmt', INTERVAL 15 DAY) > comment_date_gmt AND comment_approved = 'spam'");
    380         if ( empty( $comment_ids ) )
    381                 return;
    382                
    383         $comma_comment_ids = implode( ', ', array_map('intval', $comment_ids) );
    384 
    385         do_action( 'delete_comment', $comment_ids );
    386         $wpdb->query("DELETE FROM $wpdb->comments WHERE comment_id IN ( $comma_comment_ids )");
    387         $wpdb->query("DELETE FROM $wpdb->commentmeta WHERE comment_id IN ( $comma_comment_ids )");
    388         clean_comment_cache( $comment_ids );
    389         $n = mt_rand(1, 5000);
    390         if ( apply_filters('akismet_optimize_table', ($n == 11)) ) // lucky number
    391                 $wpdb->query("OPTIMIZE TABLE $wpdb->comments");
    392 
    393 }
    394 
    395 add_action('akismet_scheduled_delete', 'akismet_delete_old');
    396 
    397 function akismet_check_db_comment( $id, $recheck_reason = 'recheck_queue' ) {
    398     global $wpdb, $akismet_api_host, $akismet_api_port;
    399 
    400     $id = (int) $id;
    401     $c = $wpdb->get_row( "SELECT * FROM $wpdb->comments WHERE comment_ID = '$id'", ARRAY_A );
    402     if ( !$c )
    403         return;
    404 
    405     $c['user_ip']    = $c['comment_author_IP'];
    406     $c['user_agent'] = $c['comment_agent'];
    407     $c['referrer']   = '';
    408     $c['blog']       = get_option('home');
    409     $c['blog_lang']  = get_locale();
    410     $c['blog_charset'] = get_option('blog_charset');
    411     $c['permalink']  = get_permalink($c['comment_post_ID']);
    412     $id = $c['comment_ID'];
    413         if ( akismet_test_mode() )
    414                 $c['is_test'] = 'true';
    415         $c['recheck_reason'] = $recheck_reason;
    416 
    417     $query_string = '';
    418     foreach ( $c as $key => $data )
    419     $query_string .= $key . '=' . urlencode( stripslashes($data) ) . '&';
    420 
    421     $response = akismet_http_post($query_string, $akismet_api_host, '/1.1/comment-check', $akismet_api_port);
    422     return $response[1];
    423 }
    424 
    425 function akismet_cron_recheck() {
    426         global $wpdb;
    427 
    428         delete_option('akismet_available_servers');
    429 
    430         $comment_errors = $wpdb->get_col( "
    431                 SELECT comment_id
    432                 FROM {$wpdb->prefix}commentmeta
    433                 WHERE meta_key = 'akismet_error'
    434                 LIMIT 100
    435         " );
    436        
    437         foreach ( (array) $comment_errors as $comment_id ) {
    438                 // if the comment no longer exists, remove the meta entry from the queue to avoid getting stuck
    439                 if ( !get_comment( $comment_id ) ) {
    440                         delete_comment_meta( $comment_id, 'akismet_error' );
    441                         continue;
    442                 }
    443                
    444                 add_comment_meta( $comment_id, 'akismet_rechecking', true );
    445                 $status = akismet_check_db_comment( $comment_id, 'retry' );
    446 
    447                 $msg = '';
    448                 if ( $status == 'true' ) {
    449                         $msg = __( 'Akismet caught this comment as spam during an automatic retry.' );
    450                 } elseif ( $status == 'false' ) {
    451                         $msg = __( 'Akismet cleared this comment during an automatic retry.' );
    452                 }
    453                
    454                 // If we got back a legit response then update the comment history
    455                 // other wise just bail now and try again later.  No point in
    456                 // re-trying all the comments once we hit one failure.
    457                 if ( !empty( $msg ) ) {
    458                         delete_comment_meta( $comment_id, 'akismet_error' );
    459                         akismet_update_comment_history( $comment_id, $msg, 'cron-retry' );
    460                         update_comment_meta( $comment_id, 'akismet_result', $status );
    461                         // make sure the comment status is still pending.  if it isn't, that means the user has already moved it elsewhere.
    462                         $comment = get_comment( $comment_id );
    463                         if ( $comment && 'unapproved' == wp_get_comment_status( $comment_id ) ) {
    464                                 if ( $status == 'true' ) {
    465                                         wp_spam_comment( $comment_id );
    466                                 } elseif ( $status == 'false' ) {
    467                                         // comment is good, but it's still in the pending queue.  depending on the moderation settings
    468                                         // we may need to change it to approved.
    469                                         if ( check_comment($comment->comment_author, $comment->comment_author_email, $comment->comment_author_url, $comment->comment_content, $comment->comment_author_IP, $comment->comment_agent, $comment->comment_type) )
    470                                                 wp_set_comment_status( $comment_id, 1 );
    471                                 }
    472                         }
    473                 } else {
    474                         delete_comment_meta( $comment_id, 'akismet_rechecking' );
    475                         wp_schedule_single_event( time() + 1200, 'akismet_schedule_cron_recheck' );
    476                         return;
    477                 }
    478         }
    479        
    480         $remaining = $wpdb->get_var( $wpdb->prepare( "SELECT COUNT(*) FROM $wpdb->commentmeta WHERE meta_key = 'akismet_error'" ) );
    481         if ( $remaining && !wp_next_scheduled('akismet_schedule_cron_recheck') ) {
    482                 wp_schedule_single_event( time() + 1200, 'akismet_schedule_cron_recheck' );
    483         }
    484 }
    485 add_action( 'akismet_schedule_cron_recheck', 'akismet_cron_recheck' );
    486 
    487 function akismet_add_comment_nonce( $post_id ) {
    488         echo '<p style="display: none;">';
    489         wp_nonce_field( 'akismet_comment_nonce_' . $post_id, 'akismet_comment_nonce', FALSE );
    490         echo '</p>';
    491 }
    492 
    493 $akismet_comment_nonce_option = apply_filters( 'akismet_comment_nonce', get_option( 'akismet_comment_nonce' ) );
    494 
    495 if ( $akismet_comment_nonce_option == 'true' || $akismet_comment_nonce_option == '' )
    496         add_action( 'comment_form', 'akismet_add_comment_nonce' );
  • wp-content/plugins/akismet/legacy.php

     
    1 <?php
    2 
    3 function akismet_spam_comments( $type = false, $page = 1, $per_page = 50 ) {
    4         global $wpdb;
    5 
    6         $page = (int) $page;
    7         if ( $page < 2 )
    8                 $page = 1;
    9 
    10         $per_page = (int) $per_page;
    11         if ( $per_page < 1 )
    12                 $per_page = 50;
    13 
    14         $start = ( $page - 1 ) * $per_page;
    15         $end = $start + $per_page;
    16 
    17         if ( $type ) {
    18                 if ( 'comments' == $type || 'comment' == $type )
    19                         $type = '';
    20                 else
    21                         $type = $wpdb->escape( $type );
    22                 return $wpdb->get_results( "SELECT * FROM $wpdb->comments WHERE comment_approved = 'spam' AND comment_type='$type' ORDER BY comment_date DESC LIMIT $start, $end");
    23         }
    24 
    25         // All
    26         return $wpdb->get_results( "SELECT * FROM $wpdb->comments WHERE comment_approved = 'spam' ORDER BY comment_date DESC LIMIT $start, $end");
    27 }
    28 
    29 // Totals for each comment type
    30 // returns array( type => count, ... )
    31 function akismet_spam_totals() {
    32         global $wpdb;
    33         $totals = $wpdb->get_results( "SELECT comment_type, COUNT(*) AS cc FROM $wpdb->comments WHERE comment_approved = 'spam' GROUP BY comment_type" );
    34         $return = array();
    35         foreach ( $totals as $total )
    36                 $return[$total->comment_type ? $total->comment_type : 'comment'] = $total->cc;
    37         return $return;
    38 }
    39 
    40 function akismet_manage_page() {
    41         global $wpdb, $submenu, $wp_db_version;
    42 
    43         // WP 2.7 has its own spam management page
    44         if ( 8645 <= $wp_db_version )
    45                 return;
    46 
    47         $count = sprintf(__('Akismet Spam (%s)'), akismet_spam_count());
    48         if ( isset( $submenu['edit-comments.php'] ) )
    49                 add_submenu_page('edit-comments.php', __('Akismet Spam'), $count, 'moderate_comments', 'akismet-admin', 'akismet_caught' );
    50         elseif ( function_exists('add_management_page') )
    51                 add_management_page(__('Akismet Spam'), $count, 'moderate_comments', 'akismet-admin', 'akismet_caught');
    52 }
    53 
    54 function akismet_caught() {
    55         global $wpdb, $comment, $akismet_caught, $akismet_nonce;
    56 
    57         akismet_recheck_queue();
    58         if (isset($_POST['submit']) && 'recover' == $_POST['action'] && ! empty($_POST['not_spam'])) {
    59                 check_admin_referer( $akismet_nonce );
    60                 if ( function_exists('current_user_can') && !current_user_can('moderate_comments') )
    61                         die(__('You do not have sufficient permission to moderate comments.'));
    62 
    63                 $i = 0;
    64                 foreach ($_POST['not_spam'] as $comment):
    65                         $comment = (int) $comment;
    66                         if ( function_exists('wp_set_comment_status') )
    67                                 wp_set_comment_status($comment, 'approve');
    68                         else
    69                                 $wpdb->query("UPDATE $wpdb->comments SET comment_approved = '1' WHERE comment_ID = '$comment'");
    70                         akismet_submit_nonspam_comment($comment);
    71                         ++$i;
    72                 endforeach;
    73                 $to = add_query_arg( 'recovered', $i, $_SERVER['HTTP_REFERER'] );
    74                 wp_redirect( $to );
    75                 exit;
    76         }
    77         if ('delete' == $_POST['action']) {
    78                 check_admin_referer( $akismet_nonce );
    79                 if ( function_exists('current_user_can') && !current_user_can('moderate_comments') )
    80                         die(__('You do not have sufficient permission to moderate comments.'));
    81 
    82                 $delete_time = $wpdb->escape( $_POST['display_time'] );
    83                 $comment_ids = $wpdb->get_col( "SELECT comment_id FROM $wpdb->comments WHERE comment_approved = 'spam' AND '$delete_time' > comment_date_gmt" );
    84                 if ( !empty( $comment_ids ) ) {
    85                         do_action( 'delete_comment', $comment_ids );
    86                         $wpdb->query( "DELETE FROM $wpdb->comments WHERE comment_id IN ( " . implode( ', ', $comment_ids ) . " )");
    87                         wp_cache_delete( 'akismet_spam_count', 'widget' );
    88                 }
    89                 $to = add_query_arg( 'deleted', 'all', $_SERVER['HTTP_REFERER'] );
    90                 wp_redirect( $to );
    91                 exit;
    92         }
    93 
    94 if ( isset( $_GET['recovered'] ) ) {
    95         $i = (int) $_GET['recovered'];
    96         echo '<div class="updated"><p>' . sprintf(__('%1$s comments recovered.'), $i) . "</p></div>";
    97 }
    98 
    99 if (isset( $_GET['deleted'] ) )
    100         echo '<div class="updated"><p>' . __('All spam deleted.') . '</p></div>';
    101 
    102 if ( isset( $GLOBALS['submenu']['edit-comments.php'] ) )
    103         $link = 'edit-comments.php';
    104 else
    105         $link = 'edit.php';
    106 ?>
    107 <style type="text/css">
    108 .akismet-tabs {
    109         list-style: none;
    110         margin: 0;
    111         padding: 0;
    112         clear: both;
    113         border-bottom: 1px solid #ccc;
    114         height: 31px;
    115         margin-bottom: 20px;
    116         background: #ddd;
    117         border-top: 1px solid #bdbdbd;
    118 }
    119 .akismet-tabs li {
    120         float: left;
    121         margin: 5px 0 0 20px;
    122 }
    123 .akismet-tabs a {
    124         display: block;
    125         padding: 4px .5em 3px;
    126         border-bottom: none;
    127         color: #036;
    128 }
    129 .akismet-tabs .active a {
    130         background: #fff;
    131         border: 1px solid #ccc;
    132         border-bottom: none;
    133         color: #000;
    134         font-weight: bold;
    135         padding-bottom: 4px;
    136 }
    137 #akismetsearch {
    138         float: right;
    139         margin-top: -.5em;
    140 }
    141 
    142 #akismetsearch p {
    143         margin: 0;
    144         padding: 0;
    145 }
    146 </style>
    147 <div class="wrap">
    148 <h2><?php _e('Caught Spam') ?></h2>
    149 <?php
    150 $count = get_option( 'akismet_spam_count' );
    151 if ( $count ) {
    152 ?>
    153 <p><?php printf(__('Akismet has caught <strong>%1$s spam</strong> for you since you first installed it.'), number_format_i18n($count) ); ?></p>
    154 <?php
    155 }
    156 
    157 $spam_count = akismet_spam_count();
    158 
    159 if ( 0 == $spam_count ) {
    160         echo '<p>'.__('You have no spam currently in the queue. Must be your lucky day. :)').'</p>';
    161         echo '</div>';
    162 } else {
    163         echo '<p>'.__('You can delete all of the spam from your database with a single click. This operation cannot be undone, so you may wish to check to ensure that no legitimate comments got through first. Spam is automatically deleted after 15 days, so don&#8217;t sweat it.').'</p>';
    164 ?>
    165 <?php if ( !isset( $_POST['s'] ) ) { ?>
    166 <form method="post" action="<?php echo attribute_escape( add_query_arg( 'noheader', 'true' ) ); ?>">
    167 <?php akismet_nonce_field($akismet_nonce) ?>
    168 <input type="hidden" name="action" value="delete" />
    169 <?php printf(__('There are currently %1$s comments identified as spam.'), $spam_count); ?>&nbsp; &nbsp; <input type="submit" class="button delete" name="Submit" value="<?php _e('Delete all'); ?>" />
    170 <input type="hidden" name="display_time" value="<?php echo current_time('mysql', 1); ?>" />
    171 </form>
    172 <?php } ?>
    173 </div>
    174 <div class="wrap">
    175 <?php if ( isset( $_POST['s'] ) ) { ?>
    176 <h2><?php _e('Search'); ?></h2>
    177 <?php } else { ?>
    178 <?php echo '<p>'.__('These are the latest comments identified as spam by Akismet. If you see any mistakes, simply mark the comment as "not spam" and Akismet will learn from the submission. If you wish to recover a comment from spam, simply select the comment, and click Not Spam. After 15 days we clean out the junk for you.').'</p>'; ?>
    179 <?php } ?>
    180 <?php
    181 if ( isset( $_POST['s'] ) ) {
    182         $s = $wpdb->escape($_POST['s']);
    183         $comments = $wpdb->get_results("SELECT * FROM $wpdb->comments  WHERE
    184                 (comment_author LIKE '%$s%' OR
    185                 comment_author_email LIKE '%$s%' OR
    186                 comment_author_url LIKE ('%$s%') OR
    187                 comment_author_IP LIKE ('%$s%') OR
    188                 comment_content LIKE ('%$s%') ) AND
    189                 comment_approved = 'spam'
    190                 ORDER BY comment_date DESC");
    191 } else {
    192         if ( isset( $_GET['apage'] ) )
    193                 $page = (int) $_GET['apage'];
    194         else
    195                 $page = 1;
    196 
    197         if ( $page < 2 )
    198                 $page = 1;
    199 
    200         $current_type = false;
    201         if ( isset( $_GET['ctype'] ) )
    202                 $current_type = preg_replace( '|[^a-z]|', '', $_GET['ctype'] );
    203 
    204         $comments = akismet_spam_comments( $current_type, $page );
    205         $total = akismet_spam_count( $current_type );
    206         $totals = akismet_spam_totals();
    207 ?>
    208 <ul class="akismet-tabs">
    209 <li <?php if ( !isset( $_GET['ctype'] ) ) echo ' class="active"'; ?>><a href="edit-comments.php?page=akismet-admin"><?php _e('All'); ?></a></li>
    210 <?php
    211 foreach ( $totals as $type => $type_count ) {
    212         if ( 'comment' == $type ) {
    213                 $type = 'comments';
    214                 $show = __('Comments');
    215         } else {
    216                 $show = ucwords( $type );
    217         }
    218         $type_count = number_format_i18n( $type_count );
    219         $extra = $current_type === $type ? ' class="active"' : '';
    220         echo "<li $extra><a href='edit-comments.php?page=akismet-admin&amp;ctype=$type'>$show ($type_count)</a></li>";
    221 }
    222 do_action( 'akismet_tabs' ); // so plugins can add more tabs easily
    223 ?>
    224 </ul>
    225 <?php
    226 }
    227 
    228 if ($comments) {
    229 ?>
    230 <form method="post" action="<?php echo attribute_escape("$link?page=akismet-admin"); ?>" id="akismetsearch">
    231 <p>  <input type="text" name="s" value="<?php if (isset($_POST['s'])) echo attribute_escape($_POST['s']); ?>" size="17" />
    232   <input type="submit" class="button" name="submit" value="<?php echo attribute_escape(__('Search Spam &raquo;')) ?>"  />  </p>
    233 </form>
    234 <?php if ( $total > 50 ) {
    235 $total_pages = ceil( $total / 50 );
    236 $r = '';
    237 if ( 1 < $page ) {
    238         $args['apage'] = ( 1 == $page - 1 ) ? '' : $page - 1;
    239         $r .=  '<a class="prev" href="' . clean_url(add_query_arg( $args )) . '">'. __('&laquo; Previous Page') .'</a>' . "\n";
    240 }
    241 if ( ( $total_pages = ceil( $total / 50 ) ) > 1 ) {
    242         for ( $page_num = 1; $page_num <= $total_pages; $page_num++ ) :
    243                 if ( $page == $page_num ) :
    244                         $r .=  "<strong>$page_num</strong>\n";
    245                 else :
    246                         $p = false;
    247                         if ( $page_num < 3 || ( $page_num >= $page - 3 && $page_num <= $page + 3 ) || $page_num > $total_pages - 3 ) :
    248                                 $args['apage'] = ( 1 == $page_num ) ? '' : $page_num;
    249                                 $r .= '<a class="page-numbers" href="' . clean_url(add_query_arg($args)) . '">' . ( $page_num ) . "</a>\n";
    250                                 $in = true;
    251                         elseif ( $in == true ) :
    252                                 $r .= "...\n";
    253                                 $in = false;
    254                         endif;
    255                 endif;
    256         endfor;
    257 }
    258 if ( ( $page ) * 50 < $total || -1 == $total ) {
    259         $args['apage'] = $page + 1;
    260         $r .=  '<a class="next" href="' . clean_url(add_query_arg($args)) . '">'. __('Next Page &raquo;') .'</a>' . "\n";
    261 }
    262 echo "<p>$r</p>";
    263 ?>
    264 
    265 <?php } ?>
    266 <form style="clear: both;" method="post" action="<?php echo attribute_escape( add_query_arg( 'noheader', 'true' ) ); ?>">
    267 <?php akismet_nonce_field($akismet_nonce) ?>
    268 <input type="hidden" name="action" value="recover" />
    269 <ul id="spam-list" class="commentlist" style="list-style: none; margin: 0; padding: 0;">
    270 <?php
    271 $i = 0;
    272 foreach($comments as $comment) {
    273         $i++;
    274         $comment_date = mysql2date(get_option("date_format") . " @ " . get_option("time_format"), $comment->comment_date);
    275         $post = get_post($comment->comment_post_ID);
    276         $post_title = $post->post_title;
    277         if ($i % 2) $class = 'class="alternate"';
    278         else $class = '';
    279         echo "\n\t<li id='comment-$comment->comment_ID' $class>";
    280         ?>
    281 
    282 <p><strong><?php comment_author() ?></strong> <?php if ($comment->comment_author_email) { ?>| <?php comment_author_email_link() ?> <?php } if ($comment->comment_author_url && 'http://' != $comment->comment_author_url) { ?> | <?php comment_author_url_link() ?> <?php } ?>| <?php _e('IP:') ?> <a href="http://ws.arin.net/cgi-bin/whois.pl?queryinput=<?php comment_author_IP() ?>"><?php comment_author_IP() ?></a></p>
    283 
    284 <?php comment_text() ?>
    285 
    286 <p><label for="spam-<?php echo $comment->comment_ID; ?>">
    287 <input type="checkbox" id="spam-<?php echo $comment->comment_ID; ?>" name="not_spam[]" value="<?php echo $comment->comment_ID; ?>" />
    288 <?php _e('Not Spam') ?></label> &#8212; <?php comment_date('M j, g:i A');  ?> &#8212; [
    289 <?php
    290 $post = get_post($comment->comment_post_ID);
    291 $post_title = wp_specialchars( $post->post_title, 'double' );
    292 $post_title = ('' == $post_title) ? "# $comment->comment_post_ID" : $post_title;
    293 ?>
    294  <a href="<?php echo get_permalink($comment->comment_post_ID); ?>" title="<?php echo $post_title; ?>"><?php _e('View Post') ?></a> ] </p>
    295 
    296 
    297 <?php
    298 }
    299 ?>
    300 </ul>
    301 <?php if ( $total > 50 ) {
    302 $total_pages = ceil( $total / 50 );
    303 $r = '';
    304 if ( 1 < $page ) {
    305         $args['apage'] = ( 1 == $page - 1 ) ? '' : $page - 1;
    306         $r .=  '<a class="prev" href="' . clean_url(add_query_arg( $args )) . '">'. __('&laquo; Previous Page') .'</a>' . "\n";
    307 }
    308 if ( ( $total_pages = ceil( $total / 50 ) ) > 1 ) {
    309         for ( $page_num = 1; $page_num <= $total_pages; $page_num++ ) :
    310                 if ( $page == $page_num ) :
    311                         $r .=  "<strong>$page_num</strong>\n";
    312                 else :
    313                         $p = false;
    314                         if ( $page_num < 3 || ( $page_num >= $page - 3 && $page_num <= $page + 3 ) || $page_num > $total_pages - 3 ) :
    315                                 $args['apage'] = ( 1 == $page_num ) ? '' : $page_num;
    316                                 $r .= '<a class="page-numbers" href="' . clean_url(add_query_arg($args)) . '">' . ( $page_num ) . "</a>\n";
    317                                 $in = true;
    318                         elseif ( $in == true ) :
    319                                 $r .= "...\n";
    320                                 $in = false;
    321                         endif;
    322                 endif;
    323         endfor;
    324 }
    325 if ( ( $page ) * 50 < $total || -1 == $total ) {
    326         $args['apage'] = $page + 1;
    327         $r .=  '<a class="next" href="' . clean_url(add_query_arg($args)) . '">'. __('Next Page &raquo;') .'</a>' . "\n";
    328 }
    329 echo "<p>$r</p>";
    330 }
    331 ?>
    332 <p class="submit">
    333 <input type="submit" name="submit" value="<?php echo attribute_escape(__('De-spam marked comments &raquo;')); ?>" />
    334 </p>
    335 <p><?php _e('Comments you de-spam will be submitted to Akismet as mistakes so it can learn and get better.'); ?></p>
    336 </form>
    337 <?php
    338 } else {
    339 ?>
    340 <p><?php _e('No results found.'); ?></p>
    341 <?php } ?>
    342 
    343 <?php if ( !isset( $_POST['s'] ) ) { ?>
    344 <form method="post" action="<?php echo attribute_escape( add_query_arg( 'noheader', 'true' ) ); ?>">
    345 <?php akismet_nonce_field($akismet_nonce) ?>
    346 <p><input type="hidden" name="action" value="delete" />
    347 <?php printf(__('There are currently %1$s comments identified as spam.'), $spam_count); ?>&nbsp; &nbsp; <input type="submit" name="Submit" class="button" value="<?php echo attribute_escape(__('Delete all')); ?>" />
    348 <input type="hidden" name="display_time" value="<?php echo current_time('mysql', 1); ?>" /></p>
    349 </form>
    350 <?php } ?>
    351 </div>
    352 <?php
    353         }
    354 }
    355 
    356 add_action('admin_menu', 'akismet_manage_page');
    357 
    358 function redirect_old_akismet_urls( ) {
    359         global $wp_db_version;
    360         $script_name = array_pop( split( '/', $_SERVER['PHP_SELF'] ) );
    361 
    362         $page = '';
    363         if ( !empty( $_GET['page'] ) )
    364                 $page = $_GET['page'];
    365 
    366         // 2.7 redirect for people who might have bookmarked the old page
    367         if ( 8204 < $wp_db_version && ( 'edit-comments.php' == $script_name || 'edit.php' == $script_name ) && 'akismet-admin' == $page ) {
    368                 $new_url = esc_url( 'edit-comments.php?comment_status=spam' );
    369                 wp_redirect( $new_url, 301 );
    370                 exit;
    371         }
    372 }
    373 add_action( 'admin_init', 'redirect_old_akismet_urls' );
    374 
    375 // For WP <= 2.3.x
    376 global $pagenow;
    377 
    378 if ( 'moderation.php' == $pagenow ) {
    379         function akismet_recheck_button( $page ) {
    380                 global $submenu;
    381                 if ( isset( $submenu['edit-comments.php'] ) )
    382                         $link = 'edit-comments.php';
    383                 else
    384                         $link = 'edit.php';
    385                 $button = "<a href='$link?page=akismet-admin&amp;recheckqueue=true&amp;noheader=true' style='display: block; width: 100px; position: absolute; right: 7%; padding: 5px; font-size: 14px; text-decoration: underline; background: #fff; border: 1px solid #ccc;'>" . __('Recheck Queue for Spam') . "</a>";
    386                 $page = str_replace( '<div class="wrap">', '<div class="wrap">' . $button, $page );
    387                 return $page;
    388         }
    389 
    390         if ( $wpdb->get_var( "SELECT COUNT(*) FROM $wpdb->comments WHERE comment_approved = '0'" ) )
    391                 ob_start( 'akismet_recheck_button' );
    392 }
    393 
    394 // This option causes tons of FPs, was removed in 2.1
    395 function akismet_kill_proxy_check( $option ) { return 0; }
    396 add_filter('option_open_proxy_check', 'akismet_kill_proxy_check');
  • wp-content/plugins/akismet/readme.txt

     
    1 === Akismet ===
    2 Contributors: matt, ryan, andy, mdawaffe, tellyworth, josephscott, lessbloat, automattic
    3 Tags: akismet, comments, spam
    4 Requires at least: 3.0
    5 Tested up to: 3.1
    6 Stable tag: 2.5.1
    7 License: GPLv2
    8 
    9 Akismet checks your comments against the Akismet web service to see if they look like spam or not.
    10 
    11 == Description ==
    12 
    13 Akismet checks your comments against the Akismet web service to see if they look like spam or not and lets you
    14 review the spam it catches under your blog's "Comments" admin screen.
    15 
    16 Major new features in Akismet 2.5 include:
    17 
    18 * A comment status history, so you can easily see which comments were caught or cleared by Akismet, and which were spammed or unspammed by a moderator
    19 * Links are highlighted in the comment body, to reveal hidden or misleading links
    20 * If your web host is unable to reach Akismet's servers, the plugin will automatically retry when your connection is back up
    21 * Moderators can see the number of approved comments for each user
    22 * Spam and Unspam reports now include more information, to help improve accuracy
    23 
    24 PS: You'll need an [Akismet.com API key](http://akismet.com/get/) to use it.  Keys are free for personal blogs, with paid subscriptions available for businesses and commercial sites.
    25 
    26 == Installation ==
    27 
    28 Upload the Akismet plugin to your blog, Activate it, then enter your [Akismet.com API key](http://akismet.com/get/).
    29 
    30 1, 2, 3: You're done!
    31 
    32 == Changelog ==
    33 
    34 = 2.5.1 =
    35 
    36 * Fix a bug that caused the "Auto delete" option to fail to discard comments correctly
    37 * Remove the comment nonce form field from the 'Akismet Configuration' page in favor of using a filter, akismet_comment_nonce
    38 * Fixed padding bug in "author" column of posts screen
    39 * Added margin-top to "cleared by ..." badges on dashboard
    40 * Fix possible error when calling akismet_cron_recheck()
    41 * Fix more PHP warnings
    42 * Clean up XHTML warnings for comment nonce
    43 * Fix for possible condition where scheduled comment re-checks could get stuck
    44 * Clean up the comment meta details after deleting a comment
    45 * Only show the status badge if the comment status has been changed by someone/something other than Akismet
    46 * Show a 'History' link in the row-actions
    47 * Translation fixes
    48 * Reduced font-size on author name
    49 * Moved "flagged by..." notification to top right corner of comment container and removed heavy styling
    50 * Hid "flagged by..." notification while on dashboard
    51 
    52 = 2.5.0 =
    53 
    54 * Track comment actions under 'Akismet Status' on the edit comment screen
    55 * Fix a few remaining deprecated function calls ( props Mike Glendinning )
    56 * Use HTTPS for the stats IFRAME when wp-admin is using HTTPS
    57 * Use the WordPress HTTP class if available
    58 * Move the admin UI code to a separate file, only loaded when needed
    59 * Add cron retry feature, to replace the old connectivity check
    60 * Display Akismet status badge beside each comment
    61 * Record history for each comment, and display it on the edit page
    62 * Record the complete comment as originally submitted in comment_meta, to use when reporting spam and ham
    63 * Highlight links in comment content
    64 * New option, "Show the number of comments you've approved beside each comment author."
    65 * New option, "Use a nonce on the comment form."
    66 
    67 = 2.4.0 =
    68 
    69 * Spell out that the license is GPLv2
    70 * Fix PHP warnings
    71 * Fix WordPress deprecated function calls
    72 * Fire the delete_comment action when deleting comments
    73 * Move code specific for older WP versions to legacy.php
    74 * General code clean up
    75 
    76 = 2.3.0 =
    77 
    78 * Fix "Are you sure" nonce message on config screen in WPMU
    79 * Fix XHTML compliance issue in sidebar widget
    80 * Change author link; remove some old references to WordPress.com accounts
    81 * Localize the widget title (core ticket #13879)
    82 
    83 = 2.2.9 =
    84 
    85 * Eliminate a potential conflict with some plugins that may cause spurious reports
    86 
    87 = 2.2.8 =
    88 
    89 * Fix bug in initial comment check for ipv6 addresses
    90 * Report comments as ham when they are moved from spam to moderation
    91 * Report comments as ham when clicking undo after spam
    92 * Use transition_comment_status action when available instead of older actions for spam/ham submissions
    93 * Better diagnostic messages when PHP network functions are unavailable
    94 * Better handling of comments by logged-in users
    95 
    96 = 2.2.7 =
    97 
    98 * Add a new AKISMET_VERSION constant
    99 * Reduce the possibility of over-counting spam when another spam filter plugin is in use
    100 * Disable the connectivity check when the API key is hard-coded for WPMU
    101 
    102 = 2.2.6 =
    103 
    104 * Fix a global warning introduced in 2.2.5
    105 * Add changelog and additional readme.txt tags
    106 * Fix an array conversion warning in some versions of PHP
    107 * Support a new WPCOM_API_KEY constant for easier use with WordPress MU
    108 
    109 = 2.2.5 =
    110 
    111 * Include a new Server Connectivity diagnostic check, to detect problems caused by firewalls
    112 
    113 = 2.2.4 =
    114 
    115 * Fixed a key problem affecting the stats feature in WordPress MU
    116 * Provide additional blog information in Akismet API calls
  • wp-content/plugins/akismet/widget.php

     
    1 <?php
    2 /**
    3  * @package Akismet
    4  */
    5 // Widget stuff
    6 function widget_akismet_register() {
    7         if ( function_exists('register_sidebar_widget') ) :
    8         function widget_akismet($args) {
    9                 extract($args);
    10                 $options = get_option('widget_akismet');
    11                 $count = get_option('akismet_spam_count');
    12                 ?>
    13                         <?php echo $before_widget; ?>
    14                                 <?php echo $before_title . $options['title'] . $after_title; ?>
    15                 <div id="akismetwrap"><div id="akismetstats"><a id="aka" href="http://akismet.com" title=""><?php printf( _n( '%1$s%2$s%3$s %4$sspam comment%5$s %6$sblocked by%7$s<br />%8$sAkismet%9$s', '%1$s%2$s%3$s %4$sspam comments%5$s %6$sblocked by%7$s<br />%8$sAkismet%9$s', $count ), '<span id="akismet1"><span id="akismetcount">', number_format_i18n( $count ), '</span>', '<span id="akismetsc">', '</span></span>', '<span id="akismet2"><span id="akismetbb">', '</span>', '<span id="akismeta">', '</span></span>' ); ?></a></div></div>
    16                         <?php echo $after_widget; ?>
    17         <?php
    18         }
    19 
    20         function widget_akismet_style() {
    21                 $plugin_dir = '/wp-content/plugins';
    22                 if ( defined( 'PLUGINDIR' ) )
    23                         $plugin_dir = '/' . PLUGINDIR;
    24 
    25                 ?>
    26 <style type="text/css">
    27 #aka,#aka:link,#aka:hover,#aka:visited,#aka:active{color:#fff;text-decoration:none}
    28 #aka:hover{border:none;text-decoration:none}
    29 #aka:hover #akismet1{display:none}
    30 #aka:hover #akismet2,#akismet1{display:block}
    31 #akismet2{display:none;padding-top:2px}
    32 #akismeta{font-size:16px;font-weight:bold;line-height:18px;text-decoration:none}
    33 #akismetcount{display:block;font:15px Verdana,Arial,Sans-Serif;font-weight:bold;text-decoration:none}
    34 #akismetwrap #akismetstats{background:url(<?php echo get_option('siteurl'), $plugin_dir; ?>/akismet/akismet.gif) no-repeat top left;border:none;color:#fff;font:11px 'Trebuchet MS','Myriad Pro',sans-serif;height:40px;line-height:100%;overflow:hidden;padding:8px 0 0;text-align:center;width:120px}
    35 </style>
    36                 <?php
    37         }
    38 
    39         function widget_akismet_control() {
    40                 $options = $newoptions = get_option('widget_akismet');
    41                 if ( isset( $_POST['akismet-submit'] ) && $_POST["akismet-submit"] ) {
    42                         $newoptions['title'] = strip_tags(stripslashes($_POST["akismet-title"]));
    43                         if ( empty($newoptions['title']) ) $newoptions['title'] = __('Spam Blocked');
    44                 }
    45                 if ( $options != $newoptions ) {
    46                         $options = $newoptions;
    47                         update_option('widget_akismet', $options);
    48                 }
    49                 $title = htmlspecialchars($options['title'], ENT_QUOTES);
    50         ?>
    51                                 <p><label for="akismet-title"><?php _e('Title:'); ?> <input style="width: 250px;" id="akismet-title" name="akismet-title" type="text" value="<?php echo $title; ?>" /></label></p>
    52                                 <input type="hidden" id="akismet-submit" name="akismet-submit" value="1" />
    53         <?php
    54         }
    55 
    56         if ( function_exists( 'wp_register_sidebar_widget' ) ) {
    57                 wp_register_sidebar_widget( 'akismet', 'Akismet', 'widget_akismet', null, 'akismet');
    58                 wp_register_widget_control( 'akismet', 'Akismet', 'widget_akismet_control', null, 75, 'akismet');
    59         } else {
    60                 register_sidebar_widget('Akismet', 'widget_akismet', null, 'akismet');
    61                 register_widget_control('Akismet', 'widget_akismet_control', null, 75, 'akismet');
    62         }
    63         if ( is_active_widget('widget_akismet') )
    64                 add_action('wp_head', 'widget_akismet_style');
    65         endif;
    66 }
    67 
    68 add_action('init', 'widget_akismet_register');
    69 
    70 // Counter for non-widget users
    71 function akismet_counter() {
    72         $plugin_dir = '/wp-content/plugins';
    73         if ( defined( 'PLUGINDIR' ) )
    74                 $plugin_dir = '/' . PLUGINDIR;
    75 
    76 ?>
    77 <style type="text/css">
    78 #akismetwrap #aka,#aka:link,#aka:hover,#aka:visited,#aka:active{color:#fff;text-decoration:none}
    79 #aka:hover{border:none;text-decoration:none}
    80 #aka:hover #akismet1{display:none}
    81 #aka:hover #akismet2,#akismet1{display:block}
    82 #akismet2{display:none;padding-top:2px}
    83 #akismeta{font-size:16px;font-weight:bold;line-height:18px;text-decoration:none}
    84 #akismetcount{display:block;font:15px Verdana,Arial,Sans-Serif;font-weight:bold;text-decoration:none}
    85 #akismetwrap #akismetstats{background:url(<?php echo get_option('siteurl'), $plugin_dir; ?>/akismet/akismet.gif) no-repeat top left;border:none;color:#fff;font:11px 'Trebuchet MS','Myriad Pro',sans-serif;height:40px;line-height:100%;overflow:hidden;padding:8px 0 0;text-align:center;width:120px}
    86 </style>
    87 <?php
    88 $count = get_option('akismet_spam_count');
    89 printf( _n( '<div id="akismetwrap"><div id="akismetstats"><a id="aka" href="http://akismet.com" title=""><div id="akismet1"><span id="akismetcount">%1$s</span> <span id="akismetsc">spam comment</span></div> <div id="akismet2"><span id="akismetbb">blocked by</span><br /><span id="akismeta">Akismet</span></div></a></div></div>', '<div id="akismetwrap"><div id="akismetstats"><a id="aka" href="http://akismet.com" title=""><div id="akismet1"><span id="akismetcount">%1$s</span> <span id="akismetsc">spam comments</span></div> <div id="akismet2"><span id="akismetbb">blocked by</span><br /><span id="akismeta">Akismet</span></div></a></div></div>', $count ), number_format_i18n( $count ) );
    90 }