差分

このページの2つのバージョン間の差分を表示します。

この比較画面へのリンク

次のリビジョン
前のリビジョン
nucleus:np_typepadantispam [2008/06/01 09:12] – 作成 osamunucleus:np_typepadantispam [2008/06/06 16:41] (現在) osamu
行 1: 行 1:
 ====== NP_TypePadAntiSpam ====== ====== 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 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 互換の協調スパムフィルターサービスです。 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 =====
 +
 +<code php>
 +<?php
 +   /* ========================================================================
 +    * NP_TypePadAntiSpam -- TypePad AntiSpam Plugin for Nucleus CMS
 +    * Copyright (C) 2008 Niels Leenheer, Matt Mullenweg, and Osamu Higuchi
 +    * ------------------------------------------------------------------------
 +    * This program is free software; you can redistribute it and/or
 +    * modify it under the terms of the GNU General Public License
 +    * as published by the Free Software Foundation; either version 2
 +    * of the License, or (at your option) any later version.
 +    *
 +    * This program is distributed in the hope that it will be useful,
 +    * but WITHOUT ANY WARRANTY; without even the implied warranty of
 +    * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 +    * GNU General Public License for more details.
 +    *
 +    * You should have received a copy of the GNU General Public License along
 +    * with this program; if not, write to the Free Software Foundation, Inc.,
 +    * 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA  or visit
 +    * http://www.gnu.org/licenses/gpl.html
 +    * ========================================================================
 +    * By Osamu Higuchi http://www.higuchi.com/
 +    * Based on NP_Akismet by Niels Leenheer and Matt Mullenweg
 +    * ------------------------------------------------------------------------
 +    * Version History
 +    * 0.1 May 30, 2008 : Prototype
 +    * 0.2 May 30, 2008 : Prototype
 +    * ========================================================================
 +    */
 +
 +class NP_TypePadAntiSpam extends NucleusPlugin {
 + function getName() { return 'TypePadAntiSpam'; }
 + function getAuthor()    { return 'Osamu Higuchi'; }
 + function getURL()  { return 'http://www.higuchi.com/'; }
 + function getVersion()   { return '0.2'; }
 + function getDescription() { return 'Spam Check with TypePad AntiSpam'; }
 +
 + function supportsFeature($what) {
 + switch($what) {
 +     case 'SqlTablePrefix':
 + return 1;
 + default:
 + return 0;
 + }
 + }
 +
 + function getEventList() {
 + return array('SpamCheck', 'SpamMark', 'SpamPlugin');
 + }
 +
 + function install() {
 + $this->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;
 + }
 +}
  
 +?>
 +</code>
  
nucleus/np_typepadantispam.1212279138.txt.gz · 最終更新: 2008/06/01 09:12 by osamu
CC Attribution-Noncommercial-Share Alike 4.0 International
Driven by DokuWiki Recent changes RSS feed Valid CSS Valid XHTML 1.0