function akismet($var_akismet_key, $nname, $gbemail, $newurl, $mmu, $errormsg) { $url = get_bloginfo('wpurl'); $phpvers = explode(".", phpversion()); if ($phpvers[0] == 4) { include_once 'microakismet/func.microakismet.inc.php'; } if ($phpvers[0] >= 5) { include_once "microakismet/class.microakismet.inc.php"; } // The array of data we need $vars = array(); $vars["user_ip"] = $_SERVER["REMOTE_ADDR"]; $vars["user_agent"] = $_SERVER["HTTP_USER_AGENT"]; $vars["reerrer"] = $_SERVER["HTTP_REFERER"]; $vars["comment_content"] = $mmu; $vars["comment_author"] = $nname; $vars["comment_author_url"] = $newurl; $vars["comment_author_email"] = $gbemail; $vars["permalink"] = get_permalink($var_page_id); $vars["comment_type"] = "comment"; /* php 4 */ if ($phpvers[0] == 4) { if (akismet_check($vars)) { //echo "Spam detected!"; //echo $errormsg; return 1; } else { return 0; } } /* php 5 & 6 */ if ($phpvers[0] >= 5) { $akismet = new MicroAkismet("{$var_akismet_key}", $vars["permalink"], "{$url}/1.0"); if ($akismet->check($vars)) { //echo "Spam detected!"; //echo $errormsg; return 1; } else { return 0; } } }
$post_id = $_POST['post_id']; $ip = $_SERVER['REMOTE_ADDR']; $user_agent = $_SERVER['HTTP_USER_AGENT']; // Now check if the comment is spam with Akismet $vars = array(); // Mandatory fields of information $vars["user_ip"] = $ip; $vars["user_agent"] = $user_agent; // The body of the message to check, the name of the person who // posted it, and their email address $vars["comment_content"] = $comment; $vars["comment_author"] = $name; $vars["comment_author_email"] = $email; $akismet = new MicroAkismet("{$akismet_key}", "{$tld}", "{$tUrl}"); // Check if it's spam if ($akismet->check($vars)) { //it's a spam $sql = "insert into `{$tprefix}" . "_comments` ( `post_id` , `name` , `email` , `website`,`comment`,`ip` ,`user_agent`, `status` ) values ('{$post_id}','{$name}','{$email}','{$website}','{$comment}','{$ip}','{$user_agent}','U')"; //echo $sql; } else { // it's not a spam $sql = "insert into `{$tprefix}" . "_comments` ( `post_id` , `name` , `email` , `website`,`comment`,`ip` ,`user_agent`, `status` ) values ('{$post_id}','{$name}','{$email}','{$website}','{$comment}','{$ip}','{$user_agent}','P')"; //echo $sql; } /*insert the comment into the comments table if all verification passed statuses : U unpublished P published D deleted A awaiting moderation */