/** * check_comment_with_defensio() * * @return */ function check_comment_with_defensio() { global $pixelpost_db_prefix, $cfgrow, $parent_id, $message, $ip, $name, $url; require_once 'addons/_defensio2.0/lib/defensio-php/Defensio.php'; require_once 'addons/_defensio2.0/lib/pixelpost/defensio_pixelpost.php'; $defensio_result = mysql_query("SELECT * FROM `{$pixelpost_db_prefix}defensio` LIMIT 1") or die(mysql_error()); $defensio_conf = mysql_fetch_array($defensio_result); $defensio = new Defensio($defensio_conf['key']); $document = array(); // store the $cfgrow['commentemail'] in a seperate temp variable and set it to no $tmp_commentmail = $cfgrow['commentemail']; $cfgrow['commentemail'] = 'no'; // first update the comment in the database, assume it has failed. // sometimes the callback isn't issued properly. $query = "UPDATE {$pixelpost_db_prefix}comments \r\n SET publish = 'dfn',\r\n `spaminess` = '-1',\r\n `status` = 'fail' \r\n WHERE id = last_insert_id()"; mysql_query($query); /** * Only continue with Defensio if the API key is valid */ if (array_shift($defensio->getUser()) == 200) { $document = array('client' => 'Pixelpost Defensio Addon | ' . $addon_version . ' | Schonhose | schonhose@pixelpost.org', 'content' => $message, 'platform' => 'pixelpost', 'type' => 'comment', 'async' => 'true', 'async-callback' => $defensio_conf['blog'] . 'addons/_defensio2.0/lib/callback.php?id=' . md5($defensio_conf['key']), 'author-email' => $email, 'author-ip' => $ip, 'author-logged-in' => 'false', 'author-name' => $name, 'parent-document-date' => defensio_get_datetime_post($parent_id), 'parent-document-permalink' => $defensio_conf['blog'] . "index.php?showimage=" . $parent_id, 'referrer' => $_SERVER['HTTP_REFERER'], 'author-url' => $url); $post_result = $defensio->postDocument($document); $cfgrow['commentemail'] = $tmp_commentmail; defensio_process_comment_pixelpost($post_result, true); } }
public function check($api_key, $comment, $name, $email, $url = '') { $defensio = new Defensio($api_key); $document = array(); if (array_shift($defensio->getUser()) != 200) { // api key is invalid return false; } $document = array('type' => 'comment', 'content' => $comment, 'author-name' => $name, 'author-email' => $email, 'platform' => 'php', 'client' => 'Photocake', 'async' => 'false'); if ($url != '') { $document['author-url'] = $url; } $result = $defensio->postDocument($document); return $result[1]->classification == 'legitimate'; }
private function get_spam_level($content) { if ($this->comment_settings['monitor_enable']) { try { $defensio = new Defensio($this->comment_settings['monitor_api_key']); // Invalid API KEY if (array_shift($defensio->getUser()) != 200) { return false; } $document = array('type' => 'comment', 'content' => $content, 'platform' => 'Nibbleblog', 'client' => 'Nibbleblog', 'async' => 'false'); $defensio_result = $defensio->postDocument($document); return (double) $defensio_result[1]->spaminess; } catch (Exception $e) { // Something fail, timeout, invalid key, etc... return false; } } // Spam monitor disabled return 0; }
die("The API key is invalid!!! Bye Bye."); } } //Check whether ADMIN has submitted a comment to resend to Defensio if (isset($_GET['view']) && $_GET['view'] == 'comments' && isset($_GET['action']) and $_GET['action'] == 'defensiorecheck') { // build $comment array used for testing. $comment_id = (int) $_GET['cid']; // get the comment info in question $query = "SELECT * FROM `{$pixelpost_db_prefix}comments` WHERE `id` = '" . $comment_id . "'"; $defensio_result = mysql_query($query) or die(mysql_error()); $row = mysql_fetch_array($defensio_result); $document = array('client' => 'Pixelpost Defensio Addon | ' . $addon_version . ' | Schonhose | schonhose@pixelpost.org', 'content' => $row['message'], 'platform' => 'pixelpost', 'type' => 'comment', 'async' => 'true', 'async-callback' => $defensio_conf['blog'] . 'addons/_defensio2.0/lib/callback.php?id=' . md5($defensio_conf['key']), 'author-email' => $row['email'], 'author-ip' => $row['ip'], 'author-logged-in' => 'false', 'author-name' => $row['name'], 'parent-document-date' => defensio_get_datetime_post($row['parent_id']), 'parent-document-permalink' => $defensio_conf['blog'] . "index.php?showimage=" . $row['parent_id'], 'referrer' => $_SERVER['HTTP_REFERER'], 'author-url' => $row['url']); $defensio = new Defensio($defensio_conf['key']); /** * Only continue with Defensio if the API key is valid */ if (array_shift($defensio->getUser()) == 200) { $post_result = $defensio->postDocument($document); // we always do a NEW request here. defensio_process_comment_pixelpost($post_result, true, $comment_id); } else { die("The API key is invalid!!! Bye Bye."); } } //Check whether ADMIN has submitted an empty quarantine request if (isset($_GET['view']) && $_GET['view'] == 'comments' && isset($_GET['action']) and $_GET['action'] == 'emptyquarantine') { $query = "DELETE FROM {$pixelpost_db_prefix}comments WHERE publish='dfn'"; $defensio_result = mysql_query($query); $GLOBALS['defensio_result_message'] = '<div class="jcaption confirm">The Defensio Quarantine has been emptied.</div>'; } }
/** * defensio_process_unprocessed() * * @param mixed $defensio_conf * @return */ function defensio_process_unprocessed($defensio_conf) { global $pixelpost_db_prefix, $defensio; //There are three possibilities: it can have failed, it is pending or somehow the status is null //For each step there is a different approach. $defensio = new Defensio($defensio_conf['key']); $seconds = 1209600; //86399 is 24 hours, but in this case we approximately 14 days. // 1) first get all the comments that have failed or have status null for the last 2 weeks and process them again. $query = "SELECT *\n FROM `{$pixelpost_db_prefix}comments`\n WHERE (\n (\n `status` = 'fail'\n OR `status` IS NULL\n )\n AND (\n UNIX_TIMESTAMP( `datetime` )\n BETWEEN UNIX_TIMESTAMP( DATE_ADD( CURDATE( ) , INTERVAL - " . $seconds . "\n SECOND ) )\n AND UNIX_TIMESTAMP( DATE_ADD( CURDATE( ) , INTERVAL +86400\n SECOND ) )\n )\n )"; $defensio_result = mysql_query($query) or die(mysql_error()); while ($row = mysql_fetch_array($defensio_result)) { $document = array('client' => 'Pixelpost Defensio Addon | ' . $addon_version . ' | Schonhose | schonhose@pixelpost.org', 'content' => $row['message'], 'platform' => 'pixelpost', 'type' => 'comment', 'async' => 'true', 'async-callback' => $defensio_conf['blog'] . 'addons/_defensio2.0/lib/callback.php?id=' . md5($defensio_conf['key']), 'author-email' => $row['email'], 'author-ip' => $row['ip'], 'author-logged-in' => 'false', 'author-name' => $row['name'], 'parent-document-date' => defensio_get_datetime_post($row['parent_id']), 'parent-document-permalink' => $defensio_conf['blog'] . "index.php?showimage=" . $row['parent_id'], 'referrer' => $_SERVER['HTTP_REFERER'], 'author-url' => $row['url']); /** * Only continue with Defensio if the API key is valid */ if (array_shift($defensio->getUser()) == 200) { $post_result = $defensio->postDocument($document); // we always do a NEW request here. defensio_process_comment_pixelpost($post_result, true, $row['id']); } else { die("The API key is invalid!!! Bye Bye."); } } // 2) get the pending comments. But those are a bit tricky: depending on the date we either have to GET // results or process them again. $query = "SELECT * FROM `{$pixelpost_db_prefix}comments` WHERE `status` = 'pending'"; $defensio_result = mysql_query($query) or die(mysql_error()); while ($row = mysql_fetch_array($defensio_result)) { $document = array('client' => 'Pixelpost Defensio Addon | ' . $addon_version . ' | Schonhose | schonhose@pixelpost.org', 'content' => $row['message'], 'platform' => 'pixelpost', 'type' => 'comment', 'async' => 'true', 'async-callback' => $defensio_conf['blog'] . 'addons/_defensio2.0/lib/callback.php?id=' . md5($defensio_conf['key']), 'author-email' => $row['email'], 'author-ip' => $row['ip'], 'author-logged-in' => 'false', 'author-name' => $row['name'], 'parent-document-date' => defensio_get_datetime_post($row['parent_id']), 'parent-document-permalink' => $defensio_conf['blog'] . "index.php?showimage=" . $row['parent_id'], 'referrer' => $_SERVER['HTTP_REFERER'], 'author-url' => $row['url']); /** * Only continue with Defensio if the API key is valid */ if (array_shift($defensio->getUser()) == 200) { // here is the magic to decide if we need to GET or process // if the difference is less than thirty days we can still get it from Defensio // if it is more, then reprocess the comment. $no_days = floor((time() - strtotime($row['datetime'])) / 86400); if ($no_days < 30) { $get_result = $defensio->getDocument($row['signature']); // we always try to get the results here. defensio_process_comment_pixelpost($get_result, false); } else { $post_result = $defensio->postDocument($document); // we always do a NEW request here. defensio_process_comment_pixelpost($post_result, true, $row['id']); } } else { die("The API key is invalid!!! Bye Bye."); } } $defensio_comments_processed_at = mktime(); mysql_query("UPDATE " . $pixelpost_db_prefix . "defensio SET defensio_comments_processed_at='" . $defensio_comments_processed_at . "'"); }