function akismet_create_topic($msg_options, $topic_options, $poster_options) { global $modSettings, $scripturl, $smcFunc, $sourcedir; require $sourcedir . '/Akismet.class.php'; // If the subject is 'akismet-test-123', then mark it as spam (this is a test) if ($msg_options['subject'] == 'akismet-test-123') { $spam = true; } else { // If the API key has been set if (isset($modSettings['akismetAPIKey']) && $modSettings['akismetAPIKey'] != "") { // Set up the Akismet class $akismet = new Akismet($scripturl, $modSettings['akismetAPIKey']); $akismet->setAuthor($poster_options['name']); $akismet->setAuthorEmail($poster_options['email']); //$akismet->setCommentAuthorURL(""); -- URL's not used in SMF. $akismet->setContent($msg_options['body']); if (!empty($topic_options['id'])) { $akismet->setPermalink($scripturl . '?topic=' . $topicOptions['id']); } $akismet->setType('smf-post'); // Now, the moment of truth... Send the post to Akismet $akismet_return = $akismet->isSpam(); // Was the server down? if ($akismet_return === 'conn_error') { // Assume it's not spam. We log an error to the error log later $spam = false; // Log it! if (empty($modSettings['akismetNoLog'])) { log_error(sprintf($txt['akismet_cant_connect2'], $_POST['guestname'], $scripturl . '?topic=' . $topic . (isset($_REQUEST['msg']) ? '.msg' . $_REQUEST['msg'] : ''))); } } elseif ($akismet_return === true) { // Oh, the horror! Someone posted spam to your forum! $spam = true; } else { $spam = false; } } else { // No API key, assume it isn't spam $spam = false; } } if ($spam) { // Mark the message as spam and unapprove the post. Post moderation is a big help here. :) $smcFunc['db_query']('', ' UPDATE {db_prefix}topics SET spam = 1, approved = 0, unapproved_posts = 1 WHERE id_topic = {int:id_topic}', array('id_topic' => $topic_options['id'])); $smcFunc['db_query']('', ' UPDATE {db_prefix}messages SET approved = 0 WHERE id_msg = {int:id_msg}', array('id_msg' => $msg_options['id'])); // Increase spam count $smcFunc['db_query']('', ' UPDATE {db_prefix}settings SET value = value + 1 WHERE variable = {string:akismetCaughtSpam}', array('akismetCaughtSpam' => 'akismetCaughtSpam')); } }
function plugin_akismet_validate($bool, $contents) { if (!$bool) { return false; } global $fp_config; $akismet = new Akismet($fp_config['general']['www'], plugin_getoptions('akismet', 'apikey')); $akismet->setAuthor($contents['name']); $akismet->setAuthorEmail(isset($contents['email']) ? $contents['email'] : ''); $akismet->setAuthorURL(isset($contents['url']) ? $contents['url'] : ''); $akismet->setContent($contents['content']); if ($v = $akismet->isSpam()) { global $smarty; $smarty->assign('error', array('ERROR: Comment is invalid')); return false; } return true; }