function akismet_conf() { if (isset($_POST['submit'])) { check_admin_referer(); $key = preg_replace('/[^a-h0-9]/i', '', $_POST['key']); if (akismet_verify_key($key)) { update_option('wordpress_api_key', $key); } else { $invalid_key = true; } } if (!akismet_verify_key(get_option('wordpress_api_key'))) { $invalid_key = true; } ?> <div class="wrap"> <h2><?php _e('Akismet Configuration'); ?> </h2> <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 a WordPress.com account yet, you can get one at <a href="%2$s">WordPress.com</a>.'), 'http://akismet.com/', 'http://wordpress.com/api-keys/'); ?> </p> <form action="" method="post" id="akismet-conf" style="margin: auto; width: 25em; "> <h3><label for="key"><?php _e('WordPress.com API Key'); ?> </label></h3> <?php if ($invalid_key) { ?> <p style="padding: .5em; background-color: #f33; color: #fff; font-weight: bold;"><?php _e('Your key appears invalid. Double-check it.'); ?> </p> <?php } ?> <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://faq.wordpress.com/2005/10/19/api-key/">What is this?</a>'); ?> )</p> <p class="submit"><input type="submit" name="submit" value="<?php _e('Update API Key »'); ?> " /></p> </form> </div> <?php }
function akismet_check_server_connectivity() { global $akismet_api_host, $akismet_api_port, $wpcom_api_key; $test_host = 'rest.akismet.com'; // Some web hosts may disable one or both functions if (!is_callable('fsockopen') || !is_callable('gethostbynamel')) { return array(); } $ips = gethostbynamel($test_host); if (!$ips || !is_array($ips) || !count($ips)) { return array(); } $servers = array(); foreach ($ips as $ip) { $response = akismet_verify_key(akismet_get_key(), $ip); // even if the key is invalid, at least we know we have connectivity if ($response == 'valid' || $response == 'invalid') { $servers[$ip] = true; } else { $servers[$ip] = false; } } return $servers; }
function akismet_conf() { global $akismet_nonce, $wpcom_api_key; if (isset($_POST['submit'])) { if (function_exists('current_user_can') && !current_user_can('manage_options')) { die(__('Cheatin’ uh?')); } check_admin_referer($akismet_nonce); $key = preg_replace('/[^a-h0-9]/i', '', $_POST['key']); if (empty($key)) { $key_status = 'empty'; $ms[] = 'new_key_empty'; delete_option('wordpress_api_key'); } else { $key_status = akismet_verify_key($key); } if ($key_status == 'valid') { update_option('wordpress_api_key', $key); $ms[] = 'new_key_valid'; } else { if ($key_status == 'invalid') { $ms[] = 'new_key_invalid'; } else { if ($key_status == 'failed') { $ms[] = 'new_key_failed'; } } } if (isset($_POST['akismet_discard_month'])) { update_option('akismet_discard_month', 'true'); } else { update_option('akismet_discard_month', 'false'); } } elseif (isset($_POST['check'])) { akismet_get_server_connectivity(0); } if (empty($key_status) || $key_status != 'valid') { $key = get_option('wordpress_api_key'); if (empty($key)) { if (empty($key_status) || $key_status != 'failed') { if (akismet_verify_key('1234567890ab') == 'failed') { $ms[] = 'no_connection'; } else { $ms[] = 'key_empty'; } } $key_status = 'empty'; } else { $key_status = akismet_verify_key($key); } if ($key_status == 'valid') { $ms[] = 'key_valid'; } else { if ($key_status == 'invalid') { delete_option('wordpress_api_key'); $ms[] = 'key_empty'; } else { if (!empty($key) && $key_status == 'failed') { $ms[] = 'key_failed'; } } } } $messages = array('new_key_empty' => array('color' => 'aa0', 'text' => __('Your key has been cleared.')), 'new_key_valid' => array('color' => '2d2', 'text' => __('Your key has been verified. Happy blogging!')), 'new_key_invalid' => array('color' => 'd22', 'text' => __('The key you entered is invalid. Please double-check it.')), 'new_key_failed' => array('color' => 'd22', 'text' => __('The key you entered could not be verified because a connection to akismet.com could not be established. Please check your server configuration.')), 'no_connection' => array('color' => 'd22', 'text' => __('There was a problem connecting to the Akismet server. Please check your server configuration.')), '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/')), 'key_valid' => array('color' => '2d2', 'text' => __('This key is valid.')), '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.'))); if (!empty($_POST['submit'])) { ?> <div id="message" class="updated fade"><p><strong><?php _e('Options saved.'); ?> </strong></p></div> <?php } ?> <div class="wrap"> <h2><?php _e('Akismet Configuration'); ?> </h2> <div class="narrow"> <form action="" method="post" id="akismet-conf" style="margin: auto; width: 400px; "> <?php if (!$wpcom_api_key) { ?> <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> <h3><label for="key"><?php _e('Akismet API Key'); ?> </label></h3> <?php foreach ($ms as $m) { ?> <p style="padding: .5em; background-color: #<?php echo $messages[$m]['color']; ?> ; color: #fff; font-weight: bold;"><?php echo $messages[$m]['text']; ?> </p> <?php } ?> <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> <?php if (isset($invalid_key) && $invalid_key) { ?> <h3><?php _e('Why might my key be invalid?'); ?> </h3> <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> <?php } } akismet_nonce_field($akismet_nonce); ?> <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('Automatically discard spam comments on posts older than a month.'); ?> </label></p> <p class="submit"><input type="submit" name="submit" value="<?php _e('Update options »'); ?> " /></p> </form> <form action="" method="post" id="akismet-connectivity" style="margin: auto; width: 400px; "> <h3><?php _e('Server Connectivity'); ?> </h3> <?php if (!function_exists('fsockopen') || !function_exists('gethostbynamel')) { ?> <p style="padding: .5em; background-color: #d22; color: #fff; font-weight:bold;"><?php _e('Network functions are disabled.'); ?> </p> <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> <?php } else { $servers = akismet_get_server_connectivity(); $fail_count = count($servers) - count(array_filter($servers)); if (is_array($servers) && count($servers) > 0) { // some connections work, some fail if ($fail_count > 0 && $fail_count < count($servers)) { ?> <p style="padding: .5em; background-color: #aa0; color: #fff; font-weight:bold;"><?php _e('Unable to reach some Akismet servers.'); ?> </p> <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> <?php // all connections fail } elseif ($fail_count > 0) { ?> <p style="padding: .5em; background-color: #d22; color: #fff; font-weight:bold;"><?php _e('Unable to reach any Akismet servers.'); ?> </p> <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> <?php // all connections work } else { ?> <p style="padding: .5em; background-color: #2d2; color: #fff; font-weight:bold;"><?php _e('All Akismet servers are available.'); ?> </p> <p><?php _e('Akismet is working correctly. All servers are accessible.'); ?> </p> <?php } } else { ?> <p style="padding: .5em; background-color: #d22; color: #fff; font-weight:bold;"><?php _e('Unable to find Akismet servers.'); ?> </p> <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> <?php } } if (!empty($servers)) { ?> <table style="width: 100%;"> <thead><th><?php _e('Akismet server'); ?> </th><th><?php _e('Network Status'); ?> </th></thead> <tbody> <?php asort($servers); foreach ($servers as $ip => $status) { $color = $status ? '#2d2' : '#d22'; ?> <tr> <td><?php echo htmlspecialchars($ip); ?> </td> <td style="padding: 0 .5em; font-weight:bold; color: #fff; background-color: <?php echo $color; ?> "><?php echo $status ? __('No problems') : __('Obstructed'); ?> </td> <?php } } ?> </tbody> </table> <p><?php if (get_option('akismet_connectivity_time')) { echo sprintf(__('Last checked %s ago.'), human_time_diff(get_option('akismet_connectivity_time'))); } ?> </p> <p class="submit"><input type="submit" name="check" value="<?php _e('Check network status »'); ?> " /></p> </form> </div> </div> <?php }
function akismet_cron_recheck() { global $wpdb; $status = akismet_verify_key(akismet_get_key()); if (get_option('akismet_alert_code') || $status == 'invalid') { // since there is currently a problem with the key, reschedule a check for 6 hours hence wp_schedule_single_event(time() + 21600, 'akismet_schedule_cron_recheck'); return false; } delete_option('akismet_available_servers'); $comment_errors = $wpdb->get_col("\n\t\tSELECT comment_id\n\t\tFROM {$wpdb->prefix}commentmeta\n\t\tWHERE meta_key = 'akismet_error'\n\t\tLIMIT 100\n\t"); foreach ((array) $comment_errors as $comment_id) { // if the comment no longer exists, or is too old, remove the meta entry from the queue to avoid getting stuck $comment = get_comment($comment_id); if (!$comment || strtotime($comment->comment_date_gmt) < strtotime("-15 days")) { delete_comment_meta($comment_id, 'akismet_error'); continue; } add_comment_meta($comment_id, 'akismet_rechecking', true); $status = akismet_check_db_comment($comment_id, 'retry'); $msg = ''; if ($status == 'true') { $msg = __('Akismet caught this comment as spam during an automatic retry.'); } elseif ($status == 'false') { $msg = __('Akismet cleared this comment during an automatic retry.'); } // If we got back a legit response then update the comment history // other wise just bail now and try again later. No point in // re-trying all the comments once we hit one failure. if (!empty($msg)) { delete_comment_meta($comment_id, 'akismet_error'); akismet_update_comment_history($comment_id, $msg, 'cron-retry'); update_comment_meta($comment_id, 'akismet_result', $status); // make sure the comment status is still pending. if it isn't, that means the user has already moved it elsewhere. $comment = get_comment($comment_id); if ($comment && 'unapproved' == wp_get_comment_status($comment_id)) { if ($status == 'true') { wp_spam_comment($comment_id); } elseif ($status == 'false') { // comment is good, but it's still in the pending queue. depending on the moderation settings // we may need to change it to approved. 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)) { wp_set_comment_status($comment_id, 1); } } } } else { delete_comment_meta($comment_id, 'akismet_rechecking'); wp_schedule_single_event(time() + 1200, 'akismet_schedule_cron_recheck'); return; } delete_comment_meta($comment_id, 'akismet_rechecking'); } $remaining = $wpdb->get_var("SELECT COUNT(*) FROM {$wpdb->commentmeta} WHERE meta_key = 'akismet_error'"); if ($remaining && !wp_next_scheduled('akismet_schedule_cron_recheck')) { wp_schedule_single_event(time() + 1200, 'akismet_schedule_cron_recheck'); } }
<?php $akismet_installed = 0; if ($si_contact_opt['akismet_disable'] == 'false') { if (function_exists('akismet_verify_key')) { if (!isset($_POST['si_contact_akismet_check'])) { echo '<span style="background-color:#99CC99;">' . __('Akismet is installed.', 'si-contact-form') . '</span>'; $akismet_installed = 1; } if (isset($_POST['si_contact_akismet_check'])) { $key_status = 'failed'; $key = get_option('wordpress_api_key'); if (empty($key)) { $key_status = 'empty'; } else { $key_status = akismet_verify_key($key); } if ($key_status == 'valid') { $akismet_installed = 1; ?> <div id="message" class="updated"><strong><?php echo __('Akismet is enabled and the key is valid. This form will be checked with Akismet to help prevent spam', 'si-contact-form'); ?> </strong></div><?php echo '<div class="fsc-notice">' . __('Akismet is installed and the key is valid. This form will be checked with Akismet to help prevent spam.', 'si-contact-form') . '</strong></div>'; } else { if ($key_status == 'invalid') { ?> <div id="message" class="error"><strong><?php echo __('Akismet plugin is enabled but key needs to be activated', 'si-contact-form'); ?>
static function akismet_settings_callback() { ?> <div class="clear"></div> <fieldset class="fscf_settings_group"> <strong><?php _e('Akismet Spam Prevention', 'si-contact-form'); ?> </strong> <a style="cursor:pointer;" title="<?php esc_attr_e('Click for Help!', 'si-contact-form'); ?> " onclick="toggleVisibility('si_contact_akismet_tip');"><?php _e('help', 'si-contact-form'); ?> </a> <div class="fscf_tip" id="si_contact_akismet_tip"> <?php _e('Akismet is a WordPress spam prevention plugin. When Akismet is installed and active, this form will be checked with Akismet to help prevent spam.', 'si-contact-form'); ?> </div> <br /><br /> <?php $akismet_installed = 0; if (self::$form_options['akismet_disable'] == 'false') { if (is_callable(array('Akismet', 'verify_key')) || function_exists('akismet_verify_key')) { if (!isset(self::$form_options['akismet_check'])) { echo '<span style="background-color:#99CC99;">' . __('Akismet is installed.', 'si-contact-form') . '</span>'; $akismet_installed = 1; } // Has an Akismet check been requested? if (strpos($_SERVER['REQUEST_URI'], 'akismet_check') !== false) { $key_status = 'failed'; $key = get_option('wordpress_api_key'); if (empty($key)) { $key_status = 'empty'; } else { if (is_callable(array('Akismet', 'verify_key'))) { $key_status = Akismet::verify_key($key); } else { $key_status = akismet_verify_key($key); } // akismet 2.xx } if ($key_status == 'valid') { $akismet_installed = 1; ?> <div id="message" class="updated"><strong><?php echo __('Akismet is enabled and the key is valid. This form will be checked with Akismet to help prevent spam', 'si-contact-form'); ?> </strong></div><?php echo '<div class="fsc-notice">' . __('Akismet is installed and the key is valid. This form will be checked with Akismet to help prevent spam.', 'si-contact-form') . '</strong></div>'; } else { if ($key_status == 'invalid') { ?> <div id="message" class="error"><strong><?php echo __('Akismet plugin is enabled but key needs to be activated', 'si-contact-form'); ?> </strong></div><?php echo '<div class="fsc-error">' . __('Akismet plugin is installed but key needs to be activated.', 'si-contact-form') . '</div>'; } else { if (!empty($key) && $key_status == 'failed') { ?> <div id="message" class="error"><strong><?php echo __('Akismet plugin is enabled but key failed to verify', 'si-contact-form'); ?> </strong></div><?php echo '<div class="fsc-error">' . __('Akismet plugin is installed but key failed to verify.', 'si-contact-form') . '</div>'; } else { ?> <div id="message" class="error"><strong><?php echo __('Akismet plugin is installed but key has not been entered.', 'si-contact-form'); ?> </strong></div><?php echo '<div class="fsc-error">' . __('Akismet plugin is installed but key has not been entered.', 'si-contact-form') . '</div>'; } } } } ?> <br /> <input name="<?php echo self::$form_option_name; ?> [akismet_check]" id="si_contact_akismet_check" type="checkbox" value="true" /> <label for="<?php echo self::$form_option_name; ?> [akismet_check]"><?php _e('Check this and click "Save Changes" to determine if Akismet key is active.', 'si-contact-form'); ?> </label> <br /> <?php echo '<a href="' . admin_url("options-general.php?page=akismet-key-config") . '">' . __('Configure Akismet', 'si-contact-form') . '</a>'; ?> <?php } else { echo '<div class="fsc-notice">' . __('Akismet plugin is not installed or is deactivated.', 'si-contact-form') . '</div>'; } } else { echo '<div class="fsc-notice">' . __('Akismet is turned off for this form.', 'si-contact-form') . '</div>'; } if (self::$form_options['akismet_disable'] == 'false') { ?> <br /> <label for="<?php echo self::$form_option_name; ?> [akismet_send_anyway]"><?php _e('What should happen if Akismet determines the message is spam?', 'si-contact-form'); ?> </label> <select id="si_contact_akismet_send_anyway" name="<?php echo self::$form_option_name; ?> [akismet_send_anyway]"> <?php $akismet_send_anyway_array = array('false' => __('Block spam messages', 'si-contact-form'), 'true' => __('Tag as spam and send anyway', 'si-contact-form')); $selected = ''; foreach ($akismet_send_anyway_array as $k => $v) { if (self::$form_options['akismet_send_anyway'] == "{$k}") { $selected = ' selected="selected"'; } echo '<option value="' . esc_attr($k) . '"' . $selected . '>' . esc_html($v) . '</option>' . "\n"; $selected = ''; } ?> </select> <a style="cursor:pointer;" title="<?php esc_attr_e('Click for Help!', 'si-contact-form'); ?> " onclick="toggleVisibility('si_contact_akismet_send_anyway_tip');"><?php _e('help', 'si-contact-form'); ?> </a> <div class="fscf_tip" id="si_contact_akismet_send_anyway_tip"> <?php _e('If you select "block spam messages". If Akismet determines the message is spam: An error will display "Invalid Input - Spam?" and the form will not send.', 'si-contact-form'); ?> <?php echo ' '; _e('If you select "tag as spam and send anyway". If Akismet determines the message is spam: The message will send and the subject wil begin with "Akismet: Spam". This way you can have Akismet on and be sure not to miss a message.', 'si-contact-form'); ?> </div> <?php } else { echo '<input name="' . self::$form_option_name . '[akismet_send_anyway]" type="hidden" value="' . self::$form_options['akismet_send_anyway'] . '" />'; } ?> <br /> <input name="<?php echo self::$form_option_name; ?> [akismet_disable]" id="si_contact_akismet_disable" type="checkbox" <?php if (self::$form_options['akismet_disable'] == 'true') { echo 'checked="checked"'; } ?> value="true" /> <label for="<?php echo self::$form_option_name; ?> [akismet_disable]"><?php _e('Turn off Akismet for this form.', 'si-contact-form'); ?> </label> </fieldset> <?php }
function akismet_conf() { global $akismet_nonce, $wpcom_api_key; if (isset($_POST['submit'])) { if (function_exists('current_user_can') && !current_user_can('manage_options')) { die(__('Cheatin’ uh?')); } check_admin_referer($akismet_nonce); $key = preg_replace('/[^a-h0-9]/i', '', $_POST['key']); if (empty($key)) { $key_status = 'empty'; $ms[] = 'new_key_empty'; delete_option('wordpress_api_key'); } else { $key_status = akismet_verify_key($key); } if ($key_status == 'valid') { update_option('wordpress_api_key', $key); $ms[] = 'new_key_valid'; } else { if ($key_status == 'invalid') { $ms[] = 'new_key_invalid'; } else { if ($key_status == 'failed') { $ms[] = 'new_key_failed'; } } } if (isset($_POST['akismet_discard_month'])) { update_option('akismet_discard_month', 'true'); } else { update_option('akismet_discard_month', 'false'); } } if ($key_status != 'valid') { $key = get_option('wordpress_api_key'); if (empty($key)) { if ($key_status != 'failed') { if (akismet_verify_key('1234567890ab') == 'failed') { $ms[] = 'no_connection'; } else { $ms[] = 'key_empty'; } } $key_status = 'empty'; } else { $key_status = akismet_verify_key($key); } if ($key_status == 'valid') { $ms[] = 'key_valid'; } else { if ($key_status == 'invalid') { delete_option('wordpress_api_key'); $ms[] = 'key_empty'; } else { if (!empty($key) && $key_status == 'failed') { $ms[] = 'key_failed'; } } } } $messages = array('new_key_empty' => array('color' => 'aa0', 'text' => __('Your key has been cleared.')), 'new_key_valid' => array('color' => '2d2', 'text' => __('Your key has been verified. Happy blogging!')), 'new_key_invalid' => array('color' => 'd22', 'text' => __('The key you entered is invalid. Please double-check it.')), 'new_key_failed' => array('color' => 'd22', 'text' => __('The key you entered could not be verified because a connection to akismet.com could not be established. Please check your server configuration.')), 'no_connection' => array('color' => 'd22', 'text' => __('There was a problem connecting to the Akismet server. Please check your server configuration.')), 'key_empty' => array('color' => 'aa0', 'text' => sprintf(__('Please enter an API key. (<a href="%s" style="color:#fff">Get your key.</a>)'), 'http://wordpress.com/profile/')), 'key_valid' => array('color' => '2d2', 'text' => __('This key is valid.')), '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.'))); if (!empty($_POST)) { ?> <div id="message" class="updated fade"><p><strong><?php _e('Options saved.'); ?> </strong></p></div> <?php } ?> <div class="wrap"> <h2><?php _e('Akismet Configuration'); ?> </h2> <div class="narrow"> <form action="" method="post" id="akismet-conf" style="margin: auto; width: 400px; "> <?php if (!$wpcom_api_key) { ?> <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 a WordPress.com account yet, you can get one at <a href="%2$s">WordPress.com</a>.'), 'http://akismet.com/', 'http://wordpress.com/api-keys/'); ?> </p> <?php akismet_nonce_field($akismet_nonce); ?> <h3><label for="key"><?php _e('WordPress.com API Key'); ?> </label></h3> <?php foreach ($ms as $m) { ?> <p style="padding: .5em; background-color: #<?php echo $messages[$m]['color']; ?> ; color: #fff; font-weight: bold;"><?php echo $messages[$m]['text']; ?> </p> <?php } ?> <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://faq.wordpress.com/2005/10/19/api-key/">What is this?</a>'); ?> )</p> <?php if ($invalid_key) { ?> <h3><?php _e('Why might my key be invalid?'); ?> </h3> <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> <?php } } ?> <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('Automatically discard spam comments on posts older than a month.'); ?> </label></p> <p class="submit"><input type="submit" name="submit" value="<?php _e('Update options »'); ?> " /></p> </form> </div> </div> <?php }
/** * ajax_save_comment - Saves a comment to the database, returns the updated comment via JSON * * Returns a JSON object of the saved comment * * @since 1.0 * * @param string $_POST[ 'comment_content' ] The comment to save * @param int $_POST[ 'comment_id' ] The Comment ID * @param int $_POST[ 'post_id' ] The Comment's Post ID * @param string $_POST[ 'nonce' ] The nonce to check against * @return JSON object */ public function ajax_save_comment() { define('DOING_SCE', true); $new_comment_content = trim($_POST['comment_content']); $comment_id = absint($_POST['comment_id']); $post_id = absint($_POST['post_id']); $nonce = $_POST['nonce']; $return = array(); $return['errors'] = false; $return['remove'] = false; //If set to true, removes the editing interface //Do a nonce check if (!wp_verify_nonce($nonce, 'sce-edit-comment' . $comment_id)) { $return['errors'] = true; $return['remove'] = true; $return['error'] = $this->errors->get_error_message('nonce_fail'); die(json_encode($return)); } //Check to see if the user can edit the comment if (!$this->can_edit($comment_id, $post_id)) { $return['errors'] = true; $return['remove'] = true; $return['error'] = $this->errors->get_error_message('edit_fail'); die(json_encode($return)); } //Check that the content isn't empty if ('' == $new_comment_content || 'undefined' == $new_comment_content) { $return['errors'] = true; $return['error'] = $this->errors->get_error_message('comment_empty'); die(json_encode($return)); } //Get original comment $comment_to_save = get_comment($comment_id, ARRAY_A); //Check the comment if ($comment_to_save['comment_approved'] == 1) { if (check_comment($comment_to_save['comment_author'], $comment_to_save['comment_author_email'], $comment_to_save['comment_author_url'], $new_comment_content, $comment_to_save['comment_author_IP'], $comment_to_save['comment_agent'], $comment_to_save['comment_type'])) { $comment_to_save['comment_approved'] = 1; } else { $comment_to_save['comment_approved'] = 0; } } //Check comment against blacklist if (wp_blacklist_check($comment_to_save['comment_author'], $comment_to_save['comment_author_email'], $comment_to_save['comment_author_url'], $new_comment_content, $comment_to_save['comment_author_IP'], $comment_to_save['comment_agent'])) { $comment_to_save['comment_approved'] = 'spam'; } //Update comment content with new content $comment_to_save['comment_content'] = $new_comment_content; //Before save comment /** * Filter: sce_comment_check_errors * * Return a custom error message based on the saved comment * * @since 1.2.4 * * @param bool $custom_error Default custom error. Overwrite with a string * @param array $comment_to_save Associative array of comment attributes */ $custom_error = apply_filters('sce_comment_check_errors', false, $comment_to_save); //Filter expects a string returned - $comment_to_save is an associative array if (is_string($custom_error) && !empty($custom_error)) { $return['errors'] = true; $return['error'] = esc_html($custom_error); die(json_encode($return)); } /** * Filter: sce_save_before * * Allow third parties to modify comment * * @since 1.5.0 * * @param object $comment_to_save The Comment Object * @param int $post_id The Post ID * @param int $comment_id The Comment ID */ $comment_to_save = apply_filters('sce_save_before', $comment_to_save, $post_id, $comment_id); //Save the comment wp_update_comment($comment_to_save); /** * Action: sce_save_after * * Allow third parties to save content after a comment has been updated * * @since 1.5.0 * * @param object $comment_to_save The Comment Object * @param int $post_id The Post ID * @param int $comment_id The Comment ID */ ob_start(); do_action('sce_save_after', $comment_to_save, $post_id, $comment_id); ob_end_clean(); //If the comment was marked as spam, return an error if ($comment_to_save['comment_approved'] === 'spam') { $return['errors'] = true; $return['remove'] = true; $return['error'] = $this->errors->get_error_message('comment_marked_spam'); $this->remove_comment_cookie($comment_to_save); die(json_encode($return)); } //Check the new comment for spam with Akismet if (function_exists('akismet_check_db_comment')) { if (akismet_verify_key(get_option('wordpress_api_key')) != "failed") { //Akismet $response = akismet_check_db_comment($comment_id); if ($response == "true") { //You have spam wp_set_comment_status($comment_id, 'spam'); $return['errors'] = true; $return['remove'] = true; $return['error'] = $this->errors->get_error_message('comment_marked_spam'); $this->remove_comment_cookie($comment_to_save); die(json_encode($return)); } } } $comment_to_return = $this->get_comment($comment_id); $comment_content_to_return = $this->get_comment_content($comment_to_return); //Ajax response $return['comment_text'] = $comment_content_to_return; $return['error'] = ''; die(json_encode($return)); }
function check_spam($commentID = 0, $postID = 0) { $options = $this->adminOptions; //Check to see if spam protection is enabled if ($options['spam_protection'] == "none") { return false; } //Return if user is post author or can edit posts if ($this->is_comment_owner($postID)) { return false; } if (function_exists("akismet_check_db_comment") && $options['spam_protection'] == 'akismet') { //Akismet //Check to see if there is a valid API key if (akismet_verify_key(get_option('wordpress_api_key')) != "failed") { //Akismet $response = akismet_check_db_comment($commentID); if ($response == "true") { //You have spam wp_set_comment_status($commentID, 'spam'); return true; } } } elseif ($options['spam_protection'] == "defensio" && function_exists('defensio_post')) { //Defensio global $defensio_conf, $wpdb; $comment = get_comment($commentID, ARRAY_A); if (!$comment) { return true; } $comment['owner-url'] = $defensio_conf['blog']; $comment['user-ip'] = $comment['comment_author_IP']; $comment['article-date'] = strftime("%Y/%m/%d", strtotime($wpdb->get_var("SELECT post_date FROM {$wpdb->posts} WHERE ID=" . $comment['comment_post_ID']))); $comment['comment-author'] = $comment['comment_author']; $comment['comment-author-email'] = $comment['comment_author_email']; $comment['comment-author-url'] = $comment['comment_author_url']; $comment['comment-content'] = defensio_unescape_string($comment['comment_content']); if (!isset($comment['comment_type']) or empty($comment['comment_type'])) { $comment['comment-type'] = 'comment'; } else { $comment['comment-type'] = $comment['comment_type']; } if (defensio_reapply_wp_comment_preferences($comment) === "spam") { return true; } $results = defensio_post('audit-comment', $comment); $ar = Spyc::YAMLLoad($results); if (isset($ar['defensio-result'])) { if ($ar['defensio-result']['spam']) { wp_set_comment_status($commentID, 'spam'); return true; } } } return false; }
function akismet_settings() { global $pixelpost_db_prefix, $cfgrow; $newakismet_key = $cfgrow['akismet_key']; $newakismet_keep = $cfgrow['akismet_keep']; if (isset($_GET['optaction']) && $_GET['optaction'] == "updateantispam") { $newakismet_key = mysql_real_escape_string($_POST['newakismet_key']); $newakismet_keep = $_POST['newakismet_keep']; if ('valid' == akismet_verify_key($newakismet_key)) { $query = "update " . $pixelpost_db_prefix . "config set akismet_key='" . $newakismet_key . "'"; $update = mysql_query($query); $addon_description .= "<font color='#006600'>API key validated succesfully.</font>"; } else { $addon_description .= "<font color='#FF0000'>Unable to validate API Key</font>"; } $query = "update " . $pixelpost_db_prefix . "config set akismet_keep='" . $newakismet_keep . "'"; if ($update = mysql_query($query)) { $addon_description .= "<font color='#006600'>"Days to keep" succesfully saved.</font>"; } else { $addon_description .= '<span style="color:red"><b>Saving "Days to keep" to database failed!</b></span><br />Error: ' . mysql_error(); } } echo "<div class='jcaption'>Akismet settings</div>\n <div class='content'>\n<strong>You need an API key from Wordpress.com to activate this protection.</strong><br />\nIf you have already signed up at Wordpress.com, copy your API key from your profile page.<br />\nOtherwise sign up for a free Wordpress account here: <a href='http://wordpress.com/signup/' target='_blank'>SIGN UP</a>.<br /><br />\nEnter your API key from Wordpress: <input type='text' name='newakismet_key' value='" . $newakismet_key . "' style='width:100px'><br /><br />\nDays to keep comments marked as spam by Akismet: <input type='text' name='newakismet_keep' value='" . $newakismet_keep . "' style='width:20px'><br /><br />\n</div>"; }
function digressit_live_spam_check_comment($comment) { global $akismet_api_host, $akismet_api_port; if (function_exists('akismet_verify_key')) { if (akismet_verify_key(akismet_get_key())) { $comment['user_ip'] = $_SERVER['REMOTE_ADDR']; $comment['user_agent'] = $_SERVER['HTTP_USER_AGENT']; $comment['referrer'] = $_SERVER['HTTP_REFERER']; $comment['blog'] = get_option('home'); $comment['blog_lang'] = get_locale(); $comment['blog_charset'] = get_option('blog_charset'); $comment['permalink'] = get_permalink($comment['comment_post_ID']); $comment['user_role'] = akismet_get_user_roles($comment['user_ID']); $ignore = array('HTTP_COOKIE'); foreach ($_SERVER as $key => $value) { if (!in_array($key, $ignore) && is_string($value)) { $comment["{$key}"] = $value; } } $query_string = ''; foreach ($comment as $key => $data) { $query_string .= $key . '=' . urlencode(stripslashes($data)) . '&'; } $response = akismet_http_post($query_string, $akismet_api_host, '/1.1/comment-check', $akismet_api_port); if ('true' == $response[1]) { return true; } return false; } } return false; }