====== NP_TypePadAntiSpam ====== ===== What is this? ===== NP_TypePadAntiSpam is a plugin that integrates TypePad AntiSpam with Nucleus CMS. [[http://antispam.typepad.com/|TypePad AntiSpam]] is an Akismet-compatible collaborative spam blocking service from Six Apart. NP_TypePadAntiSpam は、Nucleus CMS で TypePad AntiSpam を利用できるようにするプラグインです。[[http://antispam.typepad.jp/|TypePad AntiSpam]] は、シックス・アパート社が提供する Akismet 互換の協調スパムフィルターサービスです。 ===== The Code ===== This program is actually a quick hack based on [[http://forum.nucleuscms.org/viewtopic.php?t=9515|NP_Akismet]]. Install the plugin files in your Nucleus plugin directory, and set your [[http://antispam.typepad.com/info/get-api-key.html|TypePad AntiSpam API Key]] in the admin area. This plugin provides the core anti-spam engine only. It is recommended to use with an anti-spam UI plugin such as [[http://forum.nucleuscms.org/viewtopic.php?t=9515|NP_Moderate]]. Japanese language files for NP_Moderate is also available. Put these language files in "moderate/language" directory, and install the plugin. このプログラムは[[http://forum.nucleuscms.org/viewtopic.php?t=9515|NP_Akismet]]を元に少しだけ変更を加えたものです。 プラグインのファイルをNucleusのプラグインディレクトリにインストールして、プラグインの管理画面でType[[http://antispam.typepad.jp/info/how-to-get-api-key.html|TypePad AntiSpam APIキー]]を設定するだけで使えます。 このプラグインにはコアとなるスパム防止のエンジンだけが入っています。スパムコメントの管理などのユーザーインターフェースを追加する[[http://forum.nucleuscms.org/viewtopic.php?t=9515|NP_Moderate]]などのプラグインを併用することをお勧めします。 NP_Moderateの日本語ランゲージファイルも用意しました。このランゲージファイルを "moderata/language" ディレクトリにコピーしてから、プラグインのインストールを行ってください。 {{nucleus:np_typepadantispam.0.2.zip|Download NP_TypePadAntiSpam}} {{nucleus:np_moderate_japanese.zip|Download Japanese language files for NP_Moderate}} ===== Source Code ===== createOption('ApiKey', 'TypePad API key', 'text', ''); $this->createOption('Privacy', 'Privacy protection', 'select', 'normal', 'Paranoid|high|Moderate|normal|None|low'); } function event_SpamPlugin(&$data) { $data['spamplugin'][] = array ( 'name' => $this->getName(), 'version' => $this->getVersion() ); } function event_SpamCheck(&$data) { global $CONF, $manager; if (isset($data['spamcheck']['result']) && $data['spamcheck']['result'] == true) return; if ($data['spamcheck']['type'] == 'comment' || $data['spamcheck']['type'] == 'trackback') { if ($data['spamcheck']['type'] == 'comment') $comment = array ( 'comment_post_ID' => $data['spamcheck']['id'], 'comment_author' => $data['spamcheck']['author'], 'comment_author_email' => $data['spamcheck']['email'], 'comment_author_url' => $data['spamcheck']['url'], 'comment_content' => $data['spamcheck']['body'], 'comment_type' => '', 'blog' => $CONF['IndexURL'] ); if ($data['spamcheck']['type'] == 'trackback') $comment = array ( 'comment_post_ID' => $data['spamcheck']['id'], 'comment_author' => $data['spamcheck']['blogname'], 'comment_author_url' => $data['spamcheck']['url'], 'comment_content' => $data['spamcheck']['title'] . ' ' . $data['spamcheck']['excerpt'], 'comment_type' => '', 'blog' => $CONF['IndexURL'] ); if (isset($data['spamcheck']['live']) && $data['spamcheck']['live'] == true) { $comment['user_ip'] = $_SERVER['REMOTE_ADDR']; $comment['user_agent'] = $_SERVER['HTTP_USER_AGENT']; $comment['referrer'] = $_SERVER['HTTP_REFERER']; if ($this->getOption('Privacy') == 'low') { $ignore = array ( 'HTTP_COOKIE' ); foreach ($_SERVER as $key => $value) if (!in_array($key, $ignore)) $comment[$key] = $value; } if ($this->getOption('Privacy') == 'normal') { $approved = array ( 'HTTP_HOST', 'HTTP_USER_AGENT', 'HTTP_ACCEPT', 'HTTP_ACCEPT_LANGUAGE', 'HTTP_ACCEPT_ENCODING', 'HTTP_ACCEPT_CHARSET', 'HTTP_KEEP_ALIVE', 'HTTP_REFERER', 'HTTP_CONNECTION', 'HTTP_FORWARDED', 'HTTP_FORWARDED_FOR', 'HTTP_X_FORWARDED', 'HTTP_X_FORWARDED_FOR', 'HTTP_CLIENT_IP', 'REMOTE_ADDR', 'REMOTE_HOST', 'REMOTE_PORT', 'SERVER_PROTOCOL', 'REQUEST_METHOD' ); foreach ($_SERVER as $key => $value) if (in_array($key, $approved)) $comment[$key] = $value; } } $query_string = ''; foreach ($comment as $key => $part) $query_string .= $key . '=' . urlencode(stripslashes($part)) . '&'; $response = $this->_PostHTTP( $query_string, $this->getOption('ApiKey') . '.api.antispam.typepad.com', '/1.1/comment-check', 80 ); if (is_array($response)) { $data['spamcheck']['result'] = ($response[1] == 'true'); if ($response[1] == 'true') { $data['spamcheck']['plugin'] = $this->getName(); $data['spamcheck']['message'] = 'Marked as spam by TypePad AntiSpam'; } } $manager->notify('TypePadAntiSpamResult', array ('id' => $data['spamcheck']['id'], 'status' => (int) $data['spamcheck']['result'])); } } function event_SpamMark(&$data) { global $CONF; if ($data['spammark']['type'] == 'comment' || $data['spammark']['type'] == 'trackback') { if ($data['spammark']['type'] == 'comment') $comment = array ( 'comment_post_ID' => $data['spammark']['id'], 'comment_author' => $data['spammark']['author'], 'comment_author_email' => $data['spammark']['email'], 'comment_author_url' => $data['spammark']['url'], 'comment_content' => $data['spammark']['body'], 'comment_type' => '', 'blog' => $CONF['IndexURL'] ); if ($data['spammark']['type'] == 'trackback') $comment = array ( 'comment_post_ID' => $data['spammark']['id'], 'comment_author' => $data['spammark']['blogname'], 'comment_author_url' => $data['spammark']['url'], 'comment_content' => $data['spammark']['title'] . ' ' . $data['spammark']['excerpt'], 'comment_type' => '', 'blog' => $CONF['IndexURL'] ); $query_string = ''; foreach ($comment as $key => $part) $query_string .= $key . '=' . urlencode(stripslashes($part)) . '&'; if ($data['spammark']['result'] == true) { $response = $this->_PostHTTP( $query_string, $this->getOption('ApiKey') . '.api.antispam.typepad.com', '/1.1/submit-spam', 80 ); } else { $response = $this->_PostHTTP( $query_string, $this->getOption('ApiKey') . '.api.antispam.typepad.com', '/1.1/submit-ham', 80 ); } } } function _PostHTTP($request, $host, $path, $port = 80) { global $nucleus; $http_request = "POST $path HTTP/1.0\r\n"; $http_request .= "Host: $host\r\n"; $http_request .= "Content-Type: application/x-www-form-urlencoded; charset=" . _CHARSET . "\r\n"; $http_request .= "Content-Length: " . strlen($request) . "\r\n"; $http_request .= "User-Agent: Nucleus/" . substr($nucleus['version'], 1) . " | TypePadAntiSpam/" . $this->getVersion() . "\r\n"; $http_request .= "\r\n"; $http_request .= $request; $response = ''; if( false !== ( $fs = @fsockopen($host, $port, $errno, $errstr, 3) ) ) { fwrite($fs, $http_request); while ( !feof($fs) ) $response .= fgets($fs, 1160); // One TCP-IP packet fclose($fs); $response = explode("\r\n\r\n", $response, 2); } return $response; } } ?>