OSDN Git Service

v1.1.0 jp2.0
authorhsur <hsur@1ca29b6e-896d-4ea0-84a5-967f57386b96>
Sat, 3 May 2008 22:38:17 +0000 (22:38 +0000)
committerhsur <hsur@1ca29b6e-896d-4ea0-84a5-967f57386b96>
Sat, 3 May 2008 22:38:17 +0000 (22:38 +0000)
git-svn-id: https://svn.sourceforge.jp/svnroot/nucleus-jp/plugin@619 1ca29b6e-896d-4ea0-84a5-967f57386b96

trunk/NP_SpamBayes/NP_SpamBayes.php
trunk/NP_SpamBayes/sharedlibs/cles/AsyncHTTP.php [new file with mode: 0644]
trunk/NP_SpamBayes/sharedlibs/cles/Feedback.php [new file with mode: 0644]
trunk/NP_SpamBayes/sharedlibs/cles/Template.php [new file with mode: 0644]
trunk/NP_SpamBayes/sharedlibs/sharedlibs.php [new file with mode: 0644]
trunk/NP_SpamBayes/spambayes/help.html [new file with mode: 0644]
trunk/NP_SpamBayes/spambayes/index.php
trunk/NP_SpamBayes/spambayes/spambayes.php

index a5ea253..12ab9f3 100644 (file)
@@ -1,9 +1,9 @@
 <?php
 
 /**
-  * NP_SpamBayes(JP) ($Revision: 1.6 $)
+  * NP_SpamBayes(JP) ($Revision: 1.7 $)
   * by hsur ( http://blog.cles.jp/np_cles )
-  * $Id: NP_SpamBayes.php,v 1.6 2007-06-25 11:47:33 hsur Exp $
+  * $Id: NP_SpamBayes.php,v 1.7 2008-05-03 22:38:17 hsur Exp $
   *
   * Copyright (C) 2007 cles All rights reserved.
 */
@@ -83,7 +83,7 @@ class NP_SpamBayes extends NucleusPlugin {
        }
 
        function getEventList() {
-               return array('QuickMenu', 'SpamCheck');
+               return array('QuickMenu', 'SpamCheck', 'FormExtra');
        }
 
        function hasAdminArea() {
@@ -144,8 +144,8 @@ class NP_SpamBayes extends NucleusPlugin {
        function getName()                { return 'SpamBayes(JP)'; }
        function getAuthor()      { return 'xiffy + hsur'; }
        function getURL()                 { return 'http://blog.cles.jp/np_cles/category/31/subcatid/17'; }
-       function getVersion()     { return '1.1.0 jp1.6b'; }
-       function getDescription() { return 'SpamBayes filter for comment and trackback spam. In adherence with Spam API 1.0 for Nucleus';       }
+       function getVersion()     { return '1.1.0 jp2.0'; }
+       function getDescription() { return 'Yahoo!の形態素解析APIとBayesianフィルタによってコメント/トラックバックspamを防ぎます。';    }
        function supportsFeature($what) {
                switch($what) {
                        case 'SqlTablePrefix':
@@ -175,17 +175,29 @@ class NP_SpamBayes extends NucleusPlugin {
                        );
                }
        }
-
+       
+       function event_FormExtra(&$data) {
+               switch ($data['type']) {
+                       case 'commentform-notloggedin' :
+                       case 'membermailform-notloggedin': 
+                               break;
+                       default :
+                               return;
+               }
+               
+               echo '<!-- Begin Yahoo! JAPAN Web Services Attribution Snippet --><a href="http://developer.yahoo.co.jp/about"><img src="http://i.yimg.jp/images/yjdn/yjdn_attbtn1_125_17.gif" title="Webサービス by Yahoo! JAPAN" alt="Web Services by Yahoo! JAPAN" width="125" height="17" border="0" style="margin:4px 15px 15px 15px" /></a><!-- End Yahoo! JAPAN Web Services Attribution Snippet --><br />';
+       }
+       
        function install() {
                // create some options
-               $this->createOption('probability','Score at which point we sould consider a text as spam?','text','0.95');
-               $this->createOption('ignorelist','Which words should not be taken into consideration?','textarea','you the for and');
-               $this->createOption('enableTrainall','Show SpamBayes train all ham in menu?','yesno','no');
-               $this->createOption('enableQuickmenu','Show SpamBayes in quickmenu?','yesno','yes');
-               $this->createOption('enableLogging','Use SpamBayes action logging? (this could slow down during a spamrun and can cost huge amounts of db space!)','yesno','no');
+               $this->createOption('probability','spam判定するためのスコアの閾値(0.00~1.00)','text','0.95');
+               $this->createOption('ignorelist','無視する単語(カンマもしくはスペース区切り)','textarea','you the for and');
+               $this->createOption('enableTrainall','メニューに「全てを学習」を表示するか','yesno','no');
+               $this->createOption('enableQuickmenu','管理画面の左メニューにSpamBayesを表示する','yesno','yes');
+               $this->createOption('enableLogging','spamの履歴を保存 (DBに十分な容量が必要です。)','yesno','yes');
                
                $this->createOption('appid','Yahoo!Japan AppID','text','');
-               $this->createOption('DropTable','Clear the database when uninstalling','yesno','no');
+               $this->createOption('DropTable','アンインストール時に全てのデータを削除する','yesno','no');
 
                // create some sql tables as well
                sql_query("CREATE TABLE IF NOT EXISTS ".$this->table_cat." (catcode varchar(50) NOT NULL default '', probability double NOT NULL default '0', wordcount bigint(20) NOT NULL default '0',  PRIMARY KEY (catcode))");
@@ -206,4 +218,4 @@ class NP_SpamBayes extends NucleusPlugin {
                }
        }
 
-}
\ No newline at end of file
+}
diff --git a/trunk/NP_SpamBayes/sharedlibs/cles/AsyncHTTP.php b/trunk/NP_SpamBayes/sharedlibs/cles/AsyncHTTP.php
new file mode 100644 (file)
index 0000000..6dc07bf
--- /dev/null
@@ -0,0 +1,301 @@
+<?php
+// vim: tabstop=2:shiftwidth=2
+
+/**
+ * AsyncHTTP.php ($Revision: 1.1 $)
+ *
+ * by hsur ( http://blog.cles.jp/np_cles )
+ * $Id: AsyncHTTP.php,v 1.1 2008-05-03 22:38:17 hsur Exp $
+ */
+
+/*
+ * Copyright (C) 2007 CLES. All rights reserved.
+ *
+ * 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., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA
+ *
+ * In addition, as a special exception, cles( http://blog.cles.jp/np_cles ) gives
+ * permission to link the code of this program with those files in the PEAR
+ * library that are licensed under the PHP License (or with modified versions
+ * of those files that use the same license as those files), and distribute
+ * linked combinations including the two. You must obey the GNU General Public
+ * License in all respects for all of the code used other than those files in
+ * the PEAR library that are licensed under the PHP License. If you modify
+ * this file, you may extend this exception to your version of the file,
+ * but you are not obligated to do so. If you do not wish to do so, delete
+ * this exception statement from your version.
+ */
+
+/* Examples
+ * 
+ * $ahttp = new cles_AsyncHTTP();
+ * 
+ * $reqestId[] = $http->setRequest('http://example.com/url1','GET');
+ * $reqestId[] = $http->setRequest('http://example.com/url2','GET');
+ * 
+ * $response = $http->getResponses();
+ */
+
+define('CLES_ASYNCHTTP_GETBYTES', 8192);
+define('CLES_ASYNCHTTP_INPROGRESS', 115);
+define('CLES_ASYNCHTTP_TIMEOUT', 110);
+
+class cles_AsyncHTTP {
+       var $asyncMode;
+       var $timeout = 120;
+       var $userAgent = 'CLES AsyncHTTP Lib';
+
+       var $_requests;
+       var $_sockets;
+       var $_responses;
+       var $_errornos;
+       var $_errorstrs;
+       
+       var $_debug = false;
+       var $_debugMsg = '';
+       
+       function _getTimeStamp(){
+               list($usec, $sec) = explode(" ", microtime());
+               return $timestamp = date('Y/m/d H:i:s').substr($usec,1);        
+       }
+       
+       function _log($msg){
+               $m = $this->_getTimeStamp().':'.$msg."\n";
+               $this->_debugMsg .= $m;
+               //echo $msg;
+       }
+       
+       function cles_AsyncHTTP(){
+               $this->init();
+       }
+       
+       function init() {
+               $this->_requests = array();
+               $this->_sockets = array();
+               $this->_responses = array();
+               $this->_errornos = array();
+               $this->_errorstrs = array();
+               
+               $this->asyncMode = function_exists('socket_create') ? true : false;
+       }
+
+       function setRequest($url, $method = "", $headers = "", $post = array ("")){
+               $this->_requests[] = func_get_args();
+               return count($this->_requests) - 1;
+       }
+       
+       function getResponses(){
+               $this->_startedTimestamp = $this->_getTimeStamp();
+
+               if( $this->asyncMode )
+                       $this->_sendAsync();
+               else
+                       $this->_sendSync();
+               
+               foreach( $this->_responses as $id => $response){
+                       if( $this->_errornos[$id] !== 0 ){
+                               unset($this->_responses[$id]);
+                               continue;
+                       }
+                       
+                       list($header, $body) = split("\r\n\r\n", $response, 2);
+                       preg_match("/HTTP\/1\.[0-1] ([0-9]+) ([^\r\n]*)\r?\n/", $header, $httpresp);
+                       $respCd = $httpresp[1];
+                       $respMsg = $httpresp[2];
+       
+                       if( $respCd != '200' ){
+                               $this->_errornos[$id] = -1;
+                               $this->_errorstrs[$id] = 'HTTP Error: '."[$respCd] (".$this->_requests[$id][0].") $respMsg";
+                               unset($this->_responses[$id]);
+                       } else {
+                               $this->_responses[$id] = $body;
+                       }
+               }
+
+               $this->_finishedTimestamp = $this->_getTimeStamp();
+               return $this->_responses;
+       }
+       
+       function isError($id){
+               if( $this->_errornos[$id] === 0 )
+                       return false;
+               else
+                       return true;
+       }
+       
+       function getErrorNo($id){
+               return $this->_errornos[$id];
+       }
+       
+       function getError($id){
+               return $this->_errorstrs[$id];
+       }
+       
+       function _sendAsync(){
+               $this->_debug && $this->_log('Using async mode.');
+               $expired = time() + $this->timeout;
+
+               // connect
+               foreach ($this->_requests as $id => $request) {
+                       $url = parse_url($request[0]);
+                       $port = ($url['port'] ? $url['port'] : 80);
+
+                       $this->_debug && $this->_log('Open async connection (id:'.$id.')');
+                       $s = $this->_async_connect($url['host'], $port, $this->_errornos[$id], $this->_errorstrs[$id], $this->timeout);
+                       if ($s) {
+                               $this->_sockets[$id] = $s;
+                               $this->_responses[$id] = '';
+                       }
+               }
+               
+               // send and recieve
+               while (count($this->_sockets)) {
+                       $read = $write = $this->_sockets;
+                       $e = null;
+
+                       $timeout = $expired - time();
+                       $timeout = ($timeout < 0 ) ? 0 : $timeout;
+                       
+                       $this->_debug && $this->_log('socket_select (timeout:'.$timeout.')');
+                       $n = socket_select($read, $write, $e, $timeout );
+                       
+                       if( $n ){
+                               foreach ($write as $w) {
+                                       $id = array_search($w, $this->_sockets);
+                                       $this->_debug && $this->_log('Request send (id:'.$id.')');
+                                       socket_write($w, $this->_makePayload($id));
+                                       socket_shutdown($w, 1);
+                               }
+                               foreach ($read as $r) {
+                                       $id = array_search($r, $this->_sockets);
+                                       $data = socket_read($r, CLES_ASYNCHTTP_GETBYTES);
+                                       $this->_debug && $this->_log('Response recieved (id:'.$id.', length:'.strlen($data).')');
+                                       if (strlen($data) == 0) {
+                                               if ($this->_errornos[$id] == CLES_ASYNCHTTP_INPROGRESS) {
+                                                       $this->_errornos[$id] = -1;
+                                                       $this->_errorstrs[$id] = 'Connection Failed'.__LINE__;
+                                               }
+                                               socket_close($r);
+                                               unset($this->_sockets[$id]);
+                                               $this->_debug && $this->_log('Connection closed (id:'.$id.')');
+                                       } else {
+                                               $this->_errornos[$id] = 0;
+                                               $this->_errorstrs[$id] = '';
+                                               $this->_responses[$id] .= $data;
+                                       }
+                               }
+                       } else {
+                               foreach ($this->_sockets as $id => $s) {
+                                       $this->_debug && $this->_log('Timeout (id:'.$id.')');
+                                       $this->_errornos[$id] = CLES_ASYNCHTTP_TIMEOUT;
+                                       $this->_errorstrs[$id] = socket_strerror(CLES_ASYNCHTTP_TIMEOUT);
+                                       socket_close($s);
+                                       unset($this->_sockets[$id]);
+                               }
+                               break;
+                       }
+               }
+       }
+       
+       function _sendSync(){
+               $this->_debug && $this->_log('Using sync mode.');
+               $expired = time() + $this->timeout;
+
+               foreach ($this->_requests as $id => $request) {
+                       $url = parse_url($request[0]);
+                       $port = ($url['port'] ? $url['port'] : 80);
+
+                       $timeout = $expired - time();
+                       $timeout = ($timeout < 1 ) ? 1 : $timeout;
+                       $s = fsockopen($url['host'], $port, $this->_errornos[$id], $this->_errorstrs[$id], $timeout);
+                       stream_set_timeout($s, $timeout);
+                       if ($s) {
+                               $this->_responses[$id] = '';
+                               $this->_debug && $this->_log('Request send (id:'.$id.')');
+                               fputs($s, $this->_makePayload($id));
+                               while (!feof($s)) {
+                                       $data = fgets($s, CLES_ASYNCHTTP_GETBYTES);
+                                       $this->_debug && $this->_log('Response recieved (id:'.$id.', length:'.strlen($data).')');
+                                       $this->_responses[$id] .= $data;
+                               }
+                               $this->_debug && $this->_log('Connection closed (id:'.$id.')');
+                               fclose($s);
+                       } else {
+                               $this->_errornos[$id] = -1;
+                               $this->_errorstrs[$id] = 'Connection Failed '.__LINE__;
+                       }
+               }
+       }
+       
+       function _makePayload($id){
+               $params = $this->_requests[$id];
+               $url = $params[0];
+               $method =  (strtoupper($params[1]) == 'POST') ? 'POST' : 'GET';
+               $headers = $params[2];
+               $post = $params[3];
+               
+               $url = parse_url($url);
+               if (isset ($url['query'])) {
+                       $url['query'] = "?".$url['query'];
+               } else {
+                       $url['query'] = "";
+               }
+
+               if (!isset ($url['port']))
+                       $url['port'] = 80;
+
+               $request = $method.' '.$url['path'].$url['query']." HTTP/1.0\r\n";
+               $request .= ( $url['port'] == 80 )?
+                       "Host: " . $url['host'] . "\r\n" :
+                       "Host: " . $url['host'] . ':' . $url['port'] . "\r\n";
+               $request .= 'User-Agent: '.$this->userAgent."\r\n";
+               if (isset ($url['user']) && isset ($url['pass'])) {
+                       $request .= "Authorization: Basic ".base64_encode($url['user'].":".$url['pass'])."\r\n";
+               }
+               $request .= $headers;
+
+               if( $method == "POST" ){
+                       $postdata = array();
+                       while (list ($name, $value) = each($post)) {
+                               $postdata[] = $name."=".urlencode($value);
+                       }
+                       $postdata = implode("&", $postdata);
+                       $request .= "Connection: Close\r\n";
+                       $request .= "Content-Type: application/x-www-form-urlencoded\r\n";
+                       $request .= "Content-Length: ".strlen($postdata)."\r\n";
+                       $request .= "\r\n";
+                       $request .= $postdata;
+               } else {
+                       $request .= "\r\n";
+               }
+               
+               return $request;
+       }
+
+       function _async_connect($host, $port, &$errno, &$errstr, $timeout) {
+               $ip = gethostbyname($host);
+               $socket = socket_create(AF_INET, SOCK_STREAM, SOL_TCP);
+               if (socket_set_nonblock($socket)) {
+                       $r = @socket_connect($socket, $ip, $port);
+                       if ($r || socket_last_error() == CLES_ASYNCHTTP_INPROGRESS) {
+                               return $socket;
+                       }
+               }
+
+               $errno = socket_last_error($socket);
+               $errstr = socket_strerror($errno);
+               socket_close($socket);
+               return false;
+       }
+}
diff --git a/trunk/NP_SpamBayes/sharedlibs/cles/Feedback.php b/trunk/NP_SpamBayes/sharedlibs/cles/Feedback.php
new file mode 100644 (file)
index 0000000..c8785e4
--- /dev/null
@@ -0,0 +1,176 @@
+<?php
+// vim: tabstop=2:shiftwidth=2
+
+/**
+  * Feedback.php ($Revision: 1.1 $)
+  * 
+  * by hsur ( http://blog.cles.jp/np_cles )
+  * $Id: Feedback.php,v 1.1 2008-05-03 22:38:17 hsur Exp $
+*/
+
+/*
+  * Copyright (C) 2006 CLES. All rights reserved.
+  *
+  * 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., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA
+  * 
+  * In addition, as a special exception, cles( http://blog.cles.jp/np_cles ) gives
+  * permission to link the code of this program with those files in the PEAR
+  * library that are licensed under the PHP License (or with modified versions
+  * of those files that use the same license as those files), and distribute
+  * linked combinations including the two. You must obey the GNU General Public
+  * License in all respects for all of the code used other than those files in
+  * the PEAR library that are licensed under the PHP License. If you modify
+  * this file, you may extend this exception to your version of the file,
+  * but you are not obligated to do so. If you do not wish to do so, delete
+  * this exception statement from your version.
+*/
+
+class cles_Feedback {
+       var $oPluginAdmin;
+       function CLES_Feedback(&$pluginAdmin){
+               $this->oPluginAdmin = $pluginAdmin;
+       }
+       
+       function getMenuStr(){
+               return mb_convert_encoding('動作確認/不具合報告', _CHARSET, 'UTF-8');
+       }
+       
+       function printForm($extra = '') {
+               ob_start();
+               
+               global $nucleus, $CONF;
+               
+               echo "<h2>動作確認/不具合報告</h2>";
+               echo '<p>下記より、作者への動作確認/不具合の報告を行うことができます。</p>';
+
+               // js
+               echo '<script langage="JavaScript">
+                       function selectall(){
+                               var elements = document.getElementsByTagName(\'input\');
+                               for( var i=0; i < elements.length; i++){
+                                       var e = elements[i];
+                                       if( e.type == \'checkbox\' ){
+                                               e.checked = true;
+                                       }
+                               }
+                               return false;
+                       }
+               </script>';
+               
+               echo "<h3>収集する情報と公開について</h3>";
+               echo '<p>デフォルトで必要最低限の環境情報(赤字のもの)を開発者のサーバへ送信します。<br />
+                                                       <span style="font-weight:bold; color:red">差し支えない範囲で環境情報の提供にご協力ください。</span></p>
+                                                       <p>※ 収集した情報は統計処理、及びプラグインのBugFixのみに利用されます。また統計処理した結果については公表することがあります。</p>';
+               echo '<p><a href="#" onclick="javascript:selectall();return false;">全て送信する場合はここをクリック</a></p>';
+               
+               echo "<h3>サイト固有コードについて</h3>";
+               echo '<p>動作報告の重複を取り除くため、管理画面のURLのmd5を計算したものを送信しています。この情報から管理画面のURLを復元することはできないようになっています。<a href="http://computers.yahoo.co.jp/dict/security/hash/677.html" target="_blank">md5の解説についてはこちらをご覧ください。(Yahoo!コンピュータ用語辞典)</a></p>';
+               
+               // form 
+               echo '<form method="post" action="http://blog.cles.jp/support/report.php">' . "\n";
+
+               // table
+               echo "<table>\n";
+               echo "<tr>\n";
+               echo "<th>項目の説明</th>\n";
+               echo "<th>送信される値</th>\n";
+               echo "<th><a href=\"#\" onclick=\"javascript:selectall();return false;\">全て送信する</th>\n";
+               echo "</tr>\n";
+
+               $res = sql_query("show variables like 'version'");
+               $assoc = mysql_fetch_assoc($res);
+               $mysqlVersion = $assoc['Value'];
+               
+               if( function_exists('gd_info') )
+                       $gdinfo = @gd_info();
+               else
+                       $gdinfo['GD Version'] = 'GD is not supported';
+
+               global $CONF;
+
+               $this->_printtr('siteid', 'サイトの固有コード', md5(trim($CONF['AdminURL'])));
+               $this->_printtr('plugin_name', 'プラグイン名', $this->oPluginAdmin->plugin->getName());
+               $this->_printtr('plugin_version', 'プラグインのバージョン', $this->oPluginAdmin->plugin->getVersion());
+               $this->_printtr('plugin_info', 'プラグインの情報', $extra, true);
+               $this->_printtr('nucleus_version', 'Nucleusのバージョン', $nucleus['version'], true);
+               $this->_printtr('nucleus_charset', 'Nucleusのキャラクタセット', _CHARSET);
+               $this->_printtr('php_version', 'PHPのバージョン', PHP_VERSION, true);
+               $this->_printtr('php_sapi', 'PHPの種類', php_sapi_name());
+               $this->_printtr('php_os', 'OSの種類', PHP_OS, true);
+               $this->_printtr('php_safemode', 'セーフモードの有無', ini_get('safe_mode') ? 'on' : 'off');
+               $this->_printtr('php_gd_version', 'GDのバージョン', $gdinfo['GD Version'], true);
+               $this->_printtr('php_gd_support', 'サポートしているイメージタイプ', implode(',', $this->_supportedImageTypes()) );
+               $this->_printtr('mysql_version', 'MySQLのバージョン', $mysqlVersion, true);
+
+               echo "<tr>\n";
+               echo "<td>このプラグインは機能しましたか?</td>\n";
+               echo '<td colsan="2"><input type="radio" name="user_intention" value="ok" />はい <br/> <input type="radio" name="intention" value="ng" />いいえ'."</td>\n";
+               echo "</tr>\n";
+
+               echo "<tr>\n";
+               echo "<td>不具合の内容をお寄せください<br /><em>必ず回答が必要な質問については、<a href=\"http://japan.nucleuscms.org/bb/\">Nucleusサポートフォーラム</a>もしくは<a href=\"http://blog.cles.jp/np_cles/\">作者ページ</a>でご質問ください。</em></td>\n";
+               echo '<td colspan="2"><textarea name="user_freetext" rows="10" cols="70"></textarea>'."</td>\n";
+               echo "</tr>\n";
+
+               echo "<tr>\n";
+               echo "<td>よろしければサイトのURLを教えてください</td>\n";
+               echo '<td colspan="2"><textarea name="user_url" rows="1" cols="70"></textarea>'."</td>\n";
+               echo "</tr>\n";
+               
+               echo "<tr>\n";
+               echo "<td>リンク集作成の際、リンクをはらせていただけますか?</td>\n";
+               echo '<td colspan="2"><input type="radio" name="user_disclose" value="yes" />はい <br/> <input type="radio" name="intention" value="no" />いいえ'."</td>\n";
+               echo "</tr>\n";
+
+               echo '<tr><td colspan="3"><div align="right"><input type="submit" name="submit" value="動作確認を送信する" /></div></td></tr>';
+               echo "</table>\n";
+               echo "</form>\n";
+               
+               $contents = ob_get_contents();
+               ob_end_clean();
+               echo mb_convert_encoding($contents, _CHARSET, 'UTF-8');
+       }
+       
+       function _printtr($name, $desc, $value, $canDisable = false) {
+               echo "<tr>\n";
+       
+               if ($canDisable) {
+                       echo "<td>".$desc."</td>\n";
+                       echo "<td>".htmlspecialchars($value)."</td>\n";
+                       echo '<td><input type="checkbox" name="'.htmlspecialchars($name).'" value="'.htmlspecialchars($value).'" /></td>'."\n";
+               } else {
+                       echo '<td><span style="font-weight:bold; color:red">'.$desc."</span></td>\n";
+                       echo '<td><span style="font-weight:bold; color:red">'.htmlspecialchars($value)."</span></td>\n";
+                       echo '<td><input type="checkbox" name="'.htmlspecialchars($name).'" value="'.htmlspecialchars($value).'" readonly="readonly" checked="checked"/></span></td>'."\n";
+               }
+               echo "</tr>\n";
+       }
+       
+       function _supportedImageTypes() {
+               if( !function_exists('gd_info') ) return "";
+               
+               $aSupportedTypes = array ();
+               $aPossibleImageTypeBits = array (IMG_GIF => 'GIF', IMG_JPG => 'JPG', IMG_PNG => 'PNG', IMG_WBMP => 'WBMP');
+       
+               foreach ($aPossibleImageTypeBits as $iImageTypeBits => $sImageTypeString) {
+                       if (imagetypes() & $iImageTypeBits) {
+                               $aSupportedTypes[] = $sImageTypeString;
+                       }
+               }
+       
+               return $aSupportedTypes;
+       }
+
+}
diff --git a/trunk/NP_SpamBayes/sharedlibs/cles/Template.php b/trunk/NP_SpamBayes/sharedlibs/cles/Template.php
new file mode 100644 (file)
index 0000000..7077668
--- /dev/null
@@ -0,0 +1,76 @@
+<?php
+// vim: tabstop=2:shiftwidth=2
+
+/**
+  * Template.php ($Revision: 1.1 $)
+  * 
+  * by hsur ( http://blog.cles.jp/np_cles )
+  * $Id: Template.php,v 1.1 2008-05-03 22:38:17 hsur Exp $
+*/
+
+/*
+  * Copyright (C) 2006 CLES. All rights reserved.
+  *
+  * 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., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA
+  * 
+  * In addition, as a special exception, cles( http://blog.cles.jp/np_cles ) gives
+  * permission to link the code of this program with those files in the PEAR
+  * library that are licensed under the PHP License (or with modified versions
+  * of those files that use the same license as those files), and distribute
+  * linked combinations including the two. You must obey the GNU General Public
+  * License in all respects for all of the code used other than those files in
+  * the PEAR library that are licensed under the PHP License. If you modify
+  * this file, you may extend this exception to your version of the file,
+  * but you are not obligated to do so. If you do not wish to do so, delete
+  * this exception statement from your version.
+*/
+
+class cles_Template {
+       var $defaultLang = 'japanese-utf8';
+       var $defalutPattern = '#{{(.*?)(\|)?}}#ie';
+       var $lang;
+       var $templateDir;
+
+       function cles_Template($templateDir) {
+               global $CONF;
+               $this->templateDir = $templateDir;
+               $this->lang = ereg_replace( '[\\|/]', '', getLanguageName());
+       }
+
+       function fetch($name, $dir = null, $suffix = 'html') {
+               $path = $this->templateDir.'/'.( $dir ? strtolower($dir) . '/' : '' ).strtolower($name).'_'.$this->lang.( $suffix ? '.'.strtolower($suffix) : '' );
+               if ( ! file_exists($path) ){
+                       $path = $this->templateDir.'/'.( $dir ? strtolower($dir) . '/' : '' ).strtolower($name).'_'.$this->defaultLang.( $suffix ? '.'.strtolower($suffix) : '' );
+                       if ( ! file_exists($path) )
+                               return '';
+               }
+               
+               $fsize = filesize($path);
+               if ($fsize <= 0) return '';
+               
+               $fd = fopen($path, 'r');
+               $contents = fread($fd, $fsize);
+               fclose($fd);
+               return $contents;
+       }
+       
+       function fill($template, $values, $default = null) {
+               if( $default )
+                       return preg_replace($this->defalutPattern, 'isset($values["$1"]) ? ("$2" ? htmlspecialchars($values["$1"], ENT_QUOTES) : $values["$1"]) : $default', $template);
+               if( $default === null )
+                       return preg_replace($this->defalutPattern, '("$2") ? htmlspecialchars($values["$1"], ENT_QUOTES) : $values["$1"]', $template);
+               return preg_replace($this->defalutPattern, 'isset($values["$1"]) ? ("$2" ? htmlspecialchars($values["$1"], ENT_QUOTES) : $values["$1"]) : "{{$1}}" ', $template);
+       }
+}
diff --git a/trunk/NP_SpamBayes/sharedlibs/sharedlibs.php b/trunk/NP_SpamBayes/sharedlibs/sharedlibs.php
new file mode 100644 (file)
index 0000000..0b9bf32
--- /dev/null
@@ -0,0 +1,51 @@
+<?php
+// vim: tabstop=2:shiftwidth=2
+
+/**
+  * sharedlibs.php ($Revision: 1.1 $)
+  * 
+  * by hsur ( http://blog.cles.jp/np_cles )
+  * $Id: sharedlibs.php,v 1.1 2008-05-03 22:38:17 hsur Exp $
+*/
+
+/*
+  * Copyright (C) 2006 CLES. All rights reserved.
+  *
+  * 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., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA
+  * 
+  * In addition, as a special exception, cles( http://blog.cles.jp/np_cles ) gives
+  * permission to link the code of this program with those files in the PEAR
+  * library that are licensed under the PHP License (or with modified versions
+  * of those files that use the same license as those files), and distribute
+  * linked combinations including the two. You must obey the GNU General Public
+  * License in all respects for all of the code used other than those files in
+  * the PEAR library that are licensed under the PHP License. If you modify
+  * this file, you may extend this exception to your version of the file,
+  * but you are not obligated to do so. If you do not wish to do so, delete
+  * this exception statement from your version.
+*/
+
+if (!defined('NP_SHAREDLIBS_LOADED')) {
+       if (!defined('PATH_SEPARATOR')) {
+               if (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') {
+                       define('PATH_SEPARATOR', ';');
+               } else {
+                       define('PATH_SEPARATOR', ':');
+               }
+       }
+       ini_set('include_path', dirname(__FILE__).PATH_SEPARATOR.ini_get('include_path'));
+
+       define('NP_SHAREDLIBS_LOADED', true);
+}
diff --git a/trunk/NP_SpamBayes/spambayes/help.html b/trunk/NP_SpamBayes/spambayes/help.html
new file mode 100644 (file)
index 0000000..10eaf65
--- /dev/null
@@ -0,0 +1,10 @@
+
+<h3>バージョン履歴</h3>
+
+<ul>
+       <li>Version v1.1.0 jp2]: (2008/05/04)</li>
+       <li> [Changed] インタフェイスを日本語化</li>
+       
+       <li>Version v1.1.0 jp1b]: (2007/06/21)</li>
+       <li> [New!] 初版公開</li>
+</ul>
\ No newline at end of file
index 6fbe9e6..d63478c 100644 (file)
@@ -1,18 +1,21 @@
 <?php
 /**
   * Modified by hsur ( http://blog.cles.jp/np_cles )
-  * $Id: index.php,v 1.5 2007-06-25 11:47:30 hsur Exp $
+  * $Id: index.php,v 1.6 2008-05-03 22:38:17 hsur Exp $
 */
        // vim: tabstop=2:shiftwidth=2
        //
        // Nucleus Admin section;
        // Created by Xiffy
        //
-       // Modified by hsur ($Id: index.php,v 1.5 2007-06-25 11:47:30 hsur Exp $)
+       // Modified by hsur ($Id: index.php,v 1.6 2008-05-03 22:38:17 hsur Exp $)
+
        $strRel = '../../../';
        include($strRel . 'config.php');
        
        include($DIR_LIBS . 'PLUGINADMIN.php');
+       require_once($DIR_PLUGINS . 'sharedlibs/sharedlibs.php');
+       require_once('cles/Feedback.php');
        
        if ($blogid) {$isblogadmin = $member->isBlogAdmin($blogid);}
        else $isblogadmin = 0;
        // create the admin area page
        $oPluginAdmin = new PluginAdmin('SpamBayes');
        $oPluginAdmin->start();
+       $fb =& new cles_Feedback($oPluginAdmin);
        
        if( defined('NP_SPAMBAYES_APIURL') && (! $oPluginAdmin->plugin->getOption('appid'))){
                echo '<h2>Plugin Error!</h2>';
-               echo '<h3>Yahoo! Japan Application ID is not set.</h3>';
+               echo '<h3>Yahoo! Japan Application ID が設定されていません</h3>';
                $oPluginAdmin->end();
                exit;
        }
                case 'trainblockednew':
                        sb_trainblockednew();
                        break;
+               
+               case 'report' :
+                       $extradata = '';
+                       if( defined('NP_SPAMBAYES_TOKENIZER') )
+                               $extradata .= 'Mecab';
+                       if( defined('NP_SPAMBAYES_APIURL') )
+                               $extradata .= 'Yahoo!';
+                               
+                       $fb->printForm($extradata);
+                       break;
        }
        
        $cats = $oPluginAdmin->plugin->spambayes->nbs->getCategories();
        $i = 0;
        $keys = array_keys($cats);
-       echo '<fieldset><legend>Baysian DB statistics</legend><table>';
-       echo '<tr><th>category</th><th>probability</th><th>wordcount</th></tr>';
+       echo '<fieldset><legend>Bayesianフィルタ 統計情報</legend><table>';
+       echo '<tr><th>カテゴリ</th><th>確率</th><th>単語数</th></tr>';
        foreach($cats as $category) {
                echo "<tr><td><b>$keys[$i]</b></td>";
                foreach($category as $key => $value) {
                                $docid = $oPluginAdmin->plugin->spambayes->nbs->nextdocid();
                                $oPluginAdmin->plugin->spambayes->train($docid,requestVar('catcode'),$arr['content']);
                                $oPluginAdmin->plugin->spambayes->updateProbabilities();
-                               echo '<h3>document added to the database as: '.requestVar('catcode').'</h3>';
+                               echo '<h3>文例を'.requestVar('catcode').'として学習しました</h3>';
                        } else {
-                               echo 'An error occured';
+                               echo 'エラーが発生しました';
                        }
                }
        }
                if ($expression > '') {
                        $score = $oPluginAdmin->plugin->spambayes->categorize($expression);
                        if ((float)$score['spam'] > (float)$oPluginAdmin->plugin->getOption('probability')) {
-                               echo '<h2>Testresult: Spam! [score:'.$score['spam'].']</h2>';
+                               echo '<h2>テスト結果: spamです! [score:'.$score['spam'].']</h2>';
                        } else {
-                               echo '<h2>Testresult: Ham! [score:'.$score['ham'].']</h2>';
+                               echo '<h2>テスト結果: hamです! [score:'.$score['ham'].']</h2>';
                        }
-                       echo '<fieldset style="width:90%;"><legend>Tested:</legend>';
+                       echo '<fieldset style="width:90%;"><legend>入力した文例:</legend>';
                        echo htmlspecialchars($expression,ENT_QUOTES);
                        echo '</fieldset>';
                }
                if (requestVar('ref') > 0) {
                        $oPluginAdmin->plugin->spambayes->untrain(requestVar('ref'));
                        $oPluginAdmin->plugin->spambayes->updateProbabilities();
-                       echo '<h3>document untrained</h3>';
+                       echo '<h3>文例を削除しました</h3>';
                }
                // build document table ...
                $startpos = requestVar('startpos') ? requestVar('startpos') : 0;
                $pager = buildpager($startpos, $total, $filter, $filtertype, $filterform,'untrain', $keyword, 10);
                $res = $oPluginAdmin->plugin->spambayes->nbs->getreftable($startpos);
        
-               echo '<h2>Spam Bayesian: Training data ['.$total.'] </h2>';
+               echo '<h2>Bayesianフィルタ: 学習済み文例 ['.$total.'] </h2>';
                echo '<table>';
                echo $pager;
-               echo '<tr><th>Type</th><th>content</th><th>action</th></tr>';
+               echo '<tr><th>種別</th><th>文例</th><th>&nbsp;</th></tr>';
        
                while ($arr = mysql_fetch_array($res)) {
-                       echo '<tr><td>'.$arr['catcode'].'</td><td>'.htmlspecialchars($arr['content'],ENT_QUOTES).'</td><td><a href="'.htmlspecialchars($manager->addTicketToUrl(serverVar('PHP_SELF').'?page=untrain&ref='.$arr['ref']),ENT_QUOTES).'">untrain</a></td></tr>';
+                       echo '<tr><td>'.$arr['catcode'].'</td><td>'.htmlspecialchars($arr['content'],ENT_QUOTES).'</td><td><a href="'.htmlspecialchars($manager->addTicketToUrl(serverVar('PHP_SELF').'?page=untrain&ref='.$arr['ref']),ENT_QUOTES).'">文例を削除</a></td></tr>';
                }
                echo $pager;
                echo '</table>';
        function sb_explain(){
                global $oPluginAdmin;
                $id = requestVar('id');
-               echo '<h2>Explain: Scorelog unweighed results (sorted on ham scores)</h2>';
+               echo '<h2>評価の詳細: 調整前のスコアデータ (hamのスコアの昇順)</h2>';
                $arr = $oPluginAdmin->plugin->spambayes->nbs->getLogevent($id);
        
                $oPluginAdmin->plugin->spambayes->explain($arr['content']);
        }
-       
+
        function sb_promote(){
                global $oPluginAdmin;
                $id = requestVar('id');
-               echo '<h2>Promoting to blog: '.$id.'</h2>';
+               echo '<h2>コメントの復活: '.$id.'</h2>';
                $arr = $oPluginAdmin->plugin->spambayes->nbs->getLogevent($id);
                $itemid = explode('itemid:', $arr['log']);
                $itemid = $itemid[1];
                $query = 'INSERT INTO '.sql_table('comment').' (CUSER, CMAIL, CMEMBER, CBODY, CITEM, CTIME, CHOST, CIP, CBLOG) '
                                   . "VALUES ('$name', '$url', $memberid, '$body', $itemid, '$timestamp', '$host', '$ip', '$blogid')";
                sql_query($query);
-               echo '<b>comment added</b><br />';
-               echo '-- end promote --';
+               echo '<b>コメントを復活させました</b><br />';
+               //echo '-- end promote --';
        }
        
        function sb_batch() {
                                                $docid = $oPluginAdmin->plugin->spambayes->nbs->nextdocid();
                                                $cat = substr($action,1);
                                                $oPluginAdmin->plugin->spambayes->train($docid,$cat,$ar['content']);
-                                               echo 'train '.$cat.': '.$id.'<br />';
+                                               echo '学習しました('.$cat.'): '.$id.'<br />';
                                                break;
                                        case 'delete':
-                                               echo 'delete: '.$id.'<br />';
+                                               echo '削除しました: '.$id.'<br />';
                                                $oPluginAdmin->plugin->spambayes->nbs->removeLogevent($id);
                                }
                        }
                        $oPluginAdmin->plugin->spambayes->updateProbabilities();
                }
-               echo '--end of batch--';
+               //echo '--end of batch--';
        }
                
        function sb_nucmenu($trainall, $logging) {
-               global $oPluginAdmin, $manager;
-               ?>
-       
+               global $oPluginAdmin, $manager, $CONF;
+?>
        <!-- sorry, it's stronger then me :-) this javascript less popup's are styled using: http://meyerweb.com/eric/css/edge/popups/demo.html -->
        <style type="text/css">
-                               .adminmenu span {
-                                       display:none;
-                               }
-                               .adminmenu a:hover span {
-                                       display:block;
-                                       position: absolute;
-                                       text-decoration: none;
-                                       top: 100px;
-                                       left: 350px;
-                                       width: 225px;
-                                       background-color:#ffff7d;
-                                       padding: 10px;
-                                       font-weight: normal;
-                                       font-size: 14px;
-                                       border: 1px solid black;
-                                       z-index: 100;
-                               }
-                               .adminmenu a:hover {
-                                       background-color: #ffff7d;
-                               }
-                       </style>
-               <?php
+               .adminmenu span {
+                       display:none;
+               }
+               .adminmenu a:hover span {
+                       display:block;
+                       position: absolute;
+                       text-decoration: none;
+                       top: 100px;
+                       left: 350px;
+                       width: 225px;
+                       background-color:#ffff7d;
+                       padding: 10px;
+                       font-weight: normal;
+                       font-size: 14px;
+                       border: 1px solid black;
+                       z-index: 100;
+               }
+               .adminmenu a:hover {
+                       background-color: #ffff7d;
+               }
+       </style>
+<?php
                $total = $oPluginAdmin->plugin->spambayes->nbs->countlogtable('all');
-               echo "<h2>SpamBayes menu</h2>\n";
+               echo "<h2>SpamBayes 管理</h2>\n";
                echo "<ul class=\"adminmenu\">\n";
-               echo "<li><a href=\"".htmlspecialchars($manager->addTicketToUrl(serverVar('PHP_SELF')."?page=train"),ENT_QUOTES)."\">Spam Bayes training<span>Use this to train the Spam Bayesian filter with either 'ham' (not spam) or 'spam' messages. Your Bayessian filter needs both type of messages. The filter will become better with each message submitted.</span></a></li>\n";
-               echo "<li><a href=\"".htmlspecialchars($manager->addTicketToUrl(serverVar('PHP_SELF')."?page=untrain"),ENT_QUOTES)."\">Spam Bayes untraining<span>Use this to remove references to a earlier trained document.</span></a></li>\n";
+               echo sb_menu(
+                       $CONF['PluginURL'].'spambayes/index.php?page=train',
+                       '学習データを入力',
+                       "Bayesianフィルタのための学習データを手動で入力します。学習データはham(spamでないもの)とspamの2種類があります。プラグインの動作精度を向上させるためには両方のデータが満遍なく必要です。"
+               );
+               echo sb_menu(
+                       $CONF['PluginURL'].'spambayes/index.php?page=untrain',
+                       '学習データの削除',
+                       "これまでに学習したデータをBayesianフィルタから削除します"
+               );
+
                if ($logging == 'yes') {
-                       echo "<li><a href=\"".htmlspecialchars($manager->addTicketToUrl(serverVar('PHP_SELF')."?page=log"),ENT_QUOTES)."\">Spam Bayes log ($total)<span>This page shows you the logging of Spam Bayes. You can browse through all 'ham' and 'spam' messages and train the filter with them if you like. (Especially usefull when SpamBayes got it wrong).</span></a></li>\n";
+                       echo sb_menu(
+                               $CONF['PluginURL'].'spambayes/index.php?page=log',
+                               "Bayesianフィルタの動作履歴 ($total)",
+                               "フィルタの動作履歴を表示します。Bayesianフィルタがコメントやトラックバックをどのように判定したのかが判ります。判定に誤りがある場合にはBayesianフィルタにそれを教えることができます。(運用初期における動作の微調整に有効です)"
+                       );
                }
+               
                if ($trainall == 'yes') {
-                       echo "<li><a href=\"".htmlspecialchars($manager->addTicketToUrl(serverVar('PHP_SELF')."?page=trainall"),ENT_QUOTES)."\">Train HAM (not spam) with all comments<span>Use this to train the Spam Bayesian filter with all your comments as 'ham' (not spam). This can take a while but you don't have to do anything. Just sit back and relax. Once you've run this option it's save to remove it from the menu. (See options)</span></a></li>\n";
-                       //echo "<li><a href=\"".htmlspecialchars($manager->addTicketToUrl(serverVar('PHP_SELF')."?page=trainblocked"),ENT_QUOTES)."\">Train spam with all blocked comments</a></li>\n";
-                       echo "<li><a href=\"".htmlspecialchars($manager->addTicketToUrl(serverVar('PHP_SELF')."?page=traintb"),ENT_QUOTES)."\">Train ham with all trackbacks.</a></li>\n";
-                       echo "<li><a href=\"".htmlspecialchars($manager->addTicketToUrl(serverVar('PHP_SELF')."?page=trainspamtb"),ENT_QUOTES)."\">Train spam with all blocked trackbacks.</a></li>\n";
-                       echo "<li><a href=\"".htmlspecialchars($manager->addTicketToUrl(serverVar('PHP_SELF')."?page=untrainall"),ENT_QUOTES)."\">Remove all comments from the HAM (not spam).<span>Use this to untrain the Spam Bayesian filter. This can take a while but you don't have to do anything. Just sit back and relax. Use only if you think earlier training went wrong.</span></a></li>\n";
-               }
-               echo "<li><a href=\"".htmlspecialchars($manager->addTicketToUrl(serverVar('PHP_SELF')."?page=trainnew"),ENT_QUOTES)."\">Train HAM (not spam) with all NEW comments<span>Use this to train the Spam Bayesian filter with all your yet untrained comments as 'ham' (not spam). This can take a while but you don't have to do anything. Just sit back and relax. You can use this option as much as you like. Only untrained comments will be added.</span></a></li>\n";
-               //echo "<li><a href=\"".htmlspecialchars($manager->addTicketToUrl(serverVar('PHP_SELF')."?page=trainblockednew"),ENT_QUOTES)."\">Train spam with all NEW blocked comments</a></li>\n";
-               echo "<li><a href=\"".htmlspecialchars($manager->addTicketToUrl(serverVar('PHP_SELF')."?page=traintbnew"),ENT_QUOTES)."\">Train HAM (not spam) with all NEW trackbacks.</a></li>\n";
-               echo "<li><a href=\"".htmlspecialchars($manager->addTicketToUrl(serverVar('PHP_SELF')."?page=trainspamtbnew"),ENT_QUOTES)."\">Train spam with all NEW blocked trackbacks.</a></li>\n";
-               echo "<li><a href=\"".htmlspecialchars($manager->addTicketToUrl(serverVar('PHP_SELF')."?page=update"),ENT_QUOTES)."\">Update probabilities<span>After some training, you must use this to finalise</span></a></li>\n";
-               echo "<li><a href=\"".htmlspecialchars($manager->addTicketToUrl(serverVar('PHP_SELF')."?page=test"),ENT_QUOTES)."\">Spam Bayes Test<span>Use this to test if a certain message would be considered 'ham' (not spam) or 'spam' message</span></a></li>\n";
-               echo "<li><a href=\"".htmlspecialchars($manager->addTicketToUrl(dirname(serverVar('PHP_SELF'))."/../../index.php?action=pluginoptions&plugid=".getPlugid()),ENT_QUOTES)."\">Spam Bayes options<span>This will take you to the plugins options page. This menu is NOT available on that page. Sorry for this. Use the quickmenu option to show a quicklink to the admin page!</span></a></li>\n";
-               echo "</ul>\n";
+                       echo sb_menu(
+                               $CONF['PluginURL'].'spambayes/index.php?page=trainall',
+                               '全てのコメントをhamとして学習',
+                               "このコマンドを実行すると、これまでに寄せられている全てのコメントをham(spamでないもの)として学習します。あらかじめspamコメントは削除しておきましょう。コメントの量によっては時間がかかる可能性があります。(このメニューはオプションによって非表示にすることができます。)"
+                       );
+                       echo sb_menu(
+                               $CONF['PluginURL'].'spambayes/index.php?page=untrainall',
+                               "hamとして学習したデータを全て削除",
+                               "上記の「全てのコメントをhamとして学習する」で学習したデータを全て削除します。上記による学習の効果が芳しくなかった場合にのみ、実行してください。コメントの量によっては時間がかかる可能性があります。(このメニューはオプションによって非表示にすることができます。)"
+                       );
+                       echo sb_menu(
+                               $CONF['PluginURL'].'spambayes/index.php?page=traintb',
+                               "全ての公開済みトラックバックをhamとして学習",
+                               'このコマンドを実行すると、全ての公開済みトラックバックをhamとして学習します。(このメニューはオプションによって非表示にすることができます。)'
+                               );
+                       echo sb_menu(
+                               $CONF['PluginURL'].'spambayes/index.php?page=trainspamtb',
+                               "全ての保留トラックバックをspamとして学習",
+                               'このコマンドを実行すると、全ての保留済みトラックバックをspamとして学習します。(このメニューはオプションによって非表示にすることができます。)'
+                       );
+               }
+               echo sb_menu(
+                       $CONF['PluginURL'].'spambayes/index.php?page=trainnew',
+                       "コメントをhamとして学習",
+                       "前回の実行後に新たに登録されたコメントをhamとして学習します。該当するコメントがない場合は何もしません。"
+               );
+               echo sb_menu(
+                       $CONF['PluginURL'].'spambayes/index.php?page=traintbnew',
+                       "公開済みトラックバックをhamとして学習",
+                       "前回の実行後に新たに公開されたトラックバックをhamとして学習します。該当するトラックバックがない場合何もしません。"
+               );
+               echo sb_menu(
+                       $CONF['PluginURL'].'spambayes/index.php?page=trainspamtbnew',
+                       "保留トラックバックをspamとして学習",
+                       "前回の実行後に新たに保留されたトラックバックをspamとして学習します。該当するトラックバックがない場合何もしません。"
+               );
+               echo sb_menu(
+                       $CONF['PluginURL'].'spambayes/index.php?page=update',
+                       "統計情報のアップデート",
+                       "Bayesianフィルタの統計情報をアップデートします。統計情報は自動的にアップデートされるため、通常は実行する必要はありません。"
+               );
+               echo sb_menu(
+                       $CONF['PluginURL'].'spambayes/index.php?page=test',
+                       "動作テスト",
+                       "実際に文例を入力して、Bayesianフィルタの動作をテストすることができます。"
+               );
+               echo sb_menu(
+                       $CONF['AdminURL']."index.php?action=pluginoptions&plugid=".getPlugid(),
+                       "SpamBayes プラグインオプション",
+                       "SpamBayes プラグインオプションを変更することができます。"
+               );
+               echo sb_menu(
+                       $CONF['PluginURL'].'spambayes/index.php?page=report',
+                       "動作確認報告",
+                       "作者に動作確認レポートを送信します。"
+               );
+                       echo "</ul>\n";
+       }
+       
+       function sb_menu($path, $menu, $popup=''){
+               global $manager;
+               return '<li><a href="'.htmlspecialchars($manager->addTicketToUrl($path),ENT_QUOTES).'">'.$menu.'<span>'.$popup.'</span></a></li>'."\n";
        }
        
        function sb_log() {
                if ($filter == 'all') {
                        $htotal = $oPluginAdmin->plugin->spambayes->nbs->countlogtable('ham',$filtertype, $keyword);
                        $stotal = $oPluginAdmin->plugin->spambayes->nbs->countlogtable('spam',$filtertype, $keyword);
-                       echo '<h2>Spam Bayesian: Log [total events: '.$total.' (ham: '.$htotal.' spam: '.$stotal.') ]</h2>';
+                       echo '<h2>Bayesianフィルタ: 動作履歴 [計:'.$total.'件 (ham: '.$htotal.'件, spam: '.$stotal.'件) ]</h2>';
                } else {
-                       echo '<h2>Spam Bayesian: Log [total '.$filter.' events: '.$total.']</h2>';
+                       echo '<h2>Bayesianフィルタ: 動作履歴 [計:'.$total.'件]</h2>';
                }
        
                $res = $oPluginAdmin->plugin->spambayes->nbs->getlogtable($startpos,$filter, $filtertype, $keyword, $ipp);
                }
                $cp = intval($startpos + $ipp) / $ipp;
                echo '<table>';
-               echo '<tr><th colspan="2">Page '.$cp.' of '.$ap.'</th><td colspan="2">Browse: <form style="display:inline"><input type="hidden" name="ticket" value="'.$ticket.'" /><input type="text" size="3" name="ipp" value="'.$ipp.'" /> items per page. <input type="submit" value="Go" /><input type="hidden" name="amount" value="cp" /><input type="hidden" name="filter" value="'.$filter.'" /><input type="hidden" name="filtertype" value="'.$filtertype.'" /><input type="hidden" name="keyword" value="'.$keyword.'" /><input type="hidden" name="page" value="log" /></form>';
+               echo '<tr><th colspan="2">'.$cp.'/'.$ap.'ページ</th><td colspan="2">表示: <form style="display:inline"><input type="hidden" name="ticket" value="'.$ticket.'" /><input type="text" size="3" name="ipp" value="'.$ipp.'" /> 行を1ページに表示する <input type="submit" value="変更" /><input type="hidden" name="amount" value="cp" /><input type="hidden" name="filter" value="'.$filter.'" /><input type="hidden" name="filtertype" value="'.$filtertype.'" /><input type="hidden" name="keyword" value="'.$keyword.'" /><input type="hidden" name="page" value="log" /></form>';
                echo '<span style="text-align:right" class="batchoperations">';
                if ($filter <> 'all') {
-                       echo ' type: <b>'.$filter.'</b>';
+                       $filter_text .= ' 種別: <b>'.$filter.'</b>';
                }
                if ($filtertype <> 'all') {
-                       echo ' event: <b>'.$filtertype.'</b>';
+                       $filter_text .= ' イベント: <b>'.$filtertype.'</b>';
                }
                if ($keyword > '') {
-                       echo ' keyword: <b>'.$keyword.'</b>';
+                       $filter_text .= ' キーワード: <b>'.$keyword.'</b>';
                }
+               
+               if( $filter_text ){
+                       echo "絞込み条件: ".$filter_text;
+               }
+               
                echo '</span></td></tr>';
                echo $pager;
                $extraaction = '&filter='.$filter.'&filtertype='.urlencode($filtertype).'&startpos='.$startpos.'&keyword='.$keyword.'&ipp='.$ipp.'&ticket='.$ticket;
-               echo '<tr><th>Date</th><th>event</th><th>content</th><th>action</th></tr><form method="post"><input type="hidden" name="ticket" value="'.$ticket.'" />';
+               echo '<tr><th>日付</th><th>イベント</th><th>文例</th><th>&nbsp;</th></tr><form method="post"><input type="hidden" name="ticket" value="'.$ticket.'" />';
                $i = 0;
                while ($arr = mysql_fetch_array($res)) {
                        echo '<tr onmouseover="focusRow(this);" onmouseout="blurRow(this);"><td>'.$arr['logtime'].'<br /><b>'.$arr['catcode'].'</b></td><td>'.$arr['log'].'</td><td><input id="batch'.$i.'" name="batch['.$i.']" value="'.$arr['id'].'" type="checkbox"><label for="batch'.$i.'">'.htmlspecialchars(str_replace('^^', ' ',$arr['content']),ENT_QUOTES).'</label></td>';
-                       echo '<td><a href="'.htmlspecialchars(serverVar('PHP_SELF').'?page=trainlog&catcode=ham&id='.$arr['id'].$extraaction,ENT_QUOTES).'"><nobr>train ham</nobr></a>';
-                       echo ' <a href="'.htmlspecialchars(serverVar('PHP_SELF').'?page=trainlog&catcode=spam&id='.$arr['id'].$extraaction,ENT_QUOTES).'"><nobr>train spam</nobr></a>';
-                       echo '<br /><a href="'.htmlspecialchars(serverVar('PHP_SELF').'?page=explain&id='.$arr['id'].$extraaction,ENT_QUOTES).'"><nobr>explain</nobr></a>';
+                       echo '<td><a href="'.htmlspecialchars(serverVar('PHP_SELF').'?page=trainlog&catcode=ham&id='.$arr['id'].$extraaction,ENT_QUOTES).'"><nobr>hamとして学習</nobr></a>';
+                       echo ' <a href="'.htmlspecialchars(serverVar('PHP_SELF').'?page=trainlog&catcode=spam&id='.$arr['id'].$extraaction,ENT_QUOTES).'"><nobr>spamとして学習</nobr></a>';
+                       echo '<br /><a href="'.htmlspecialchars(serverVar('PHP_SELF').'?page=explain&id='.$arr['id'].$extraaction,ENT_QUOTES).'"><nobr>評価の詳細</nobr></a>';
                        if (strstr($arr['log'], 'itemid:')) {
-                               echo '<br /><br /><a style="color:red" href="'.htmlspecialchars(serverVar('PHP_SELF').'?page=promote&id='.$arr['id'].$extraaction,ENT_QUOTES).'"><nobr>publish</nobr></a>';
+                               echo '<br /><br /><a style="color:red" href="'.htmlspecialchars(serverVar('PHP_SELF').'?page=promote&id='.$arr['id'].$extraaction,ENT_QUOTES).'"><nobr>復活</nobr></a>';
                        }
                        echo '</td>';
                        echo '</tr>';
                        $i++;
                }
                if (mysql_num_rows($res) == 0) {
-                       echo '<tr><td colspan="4"><b>Eventlog is empty</b></td></tr>';
+                       echo '<tr><td colspan="4"><b>ログは空です。</b></td></tr>';
                }
-               echo '<tr><td colspan="4"><div class="batchoperations">with selected:<select name="batchaction">';
-               echo '<option value="tspam">Train spam</option>';
-               echo '<option value="tham">Train ham</option>';
-               echo '<option value="delete">Delete</option></select><input name="page" value="batch" type="hidden">';
+               echo '<tr><td colspan="4"><div class="batchoperations">選択したものを次の通り処理する:<select name="batchaction">';
+               echo '<option value="tspam">spamとして学習</option>';
+               echo '<option value="tham">hamとして学習</option>';
+               echo '<option value="delete">削除</option></select><input name="page" value="batch" type="hidden">';
                echo '<input type="hidden" name="ipp" value="'.$ipp.'"/><input type="hidden" name="filter" value="'.$filter.'" /><input type="hidden" name="filtertype" value="'.$filtertype.'" /><input type="hidden" name="keyword" value="'.$keyword.'" />';
-               echo '<input value="Execute" type="submit">(
-                                <a href="" onclick="if (event && event.preventDefault) event.preventDefault(); return batchSelectAll(1); ">select all</a> -
-                                <a href="" onclick="if (event && event.preventDefault) event.preventDefault(); return batchSelectAll(0); ">deselect all</a>
+               echo '<input value="実行" type="submit">(
+                                <a href="" onclick="if (event && event.preventDefault) event.preventDefault(); return batchSelectAll(1); ">全て選択</a> -
+                                <a href="" onclick="if (event && event.preventDefault) event.preventDefault(); return batchSelectAll(0); ">選択解除</a>
                                )
                        </div></td></tr></form>';
-               echo '<tr><td colspan="4"><div class="batchoperations"><form action="" method="get" style="display:inline"><input type="hidden" name="ticket" value="'.$ticket.'" /><input type="hidden" name="ipp" value="'.$ipp.'"/><input type="hidden" name="page" value="clearlog" /><input type="hidden" name="amount" value="cp" /><input type="hidden" name="filter" value="'.$filter.'" /><input type="hidden" name="filtertype" value="'.$filtertype.'" /><input type="hidden" name="keyword" value="'.$keyword.'" /><input type="submit" value="Clear first '.$ipp.'" /></form> <form action="" method="get" style="display:inline"><input type="hidden" name="ticket" value="'.$ticket.'" /><input type="hidden" name="ipp" value="'.$ipp.'"/><input type="hidden" name="page" value="clearlog" /><input type="hidden" name="amount" value="cf" /><input type="hidden" name="filter" value="'.$filter.'" /><input type="hidden" name="filtertype" value="'.$filtertype.'" /><input type="hidden" name="keyword" value="'.$keyword.'" /><input type="submit" value="Clear current filtered logs" /></form> <form action="" method="get" style="display:inline"><input type="hidden" name="ticket" value="'.$ticket.'" /><input type="hidden" name="page" value="clearlog" /><input type="submit" value="Clear complete log" /></form></div></td></tr>';
-               echo '<tr><th colspan="2">Page '.$cp.' of '.$ap.'</th><td colspan="2">Browse: <form style="display:inline"><input type="hidden" name="ticket" value="'.$ticket.'" /><input type="text" size="3" name="ipp" value="'.$ipp.'" /> items per page. <input type="submit" value="Go" /><input type="hidden" name="amount" value="cp" /><input type="hidden" name="filter" value="'.$filter.'" /><input type="hidden" name="filtertype" value="'.$filtertype.'" /><input type="hidden" name="keyword" value="'.$keyword.'" /><input type="hidden" name="page" value="log" /></form></td></tr>';
+               echo '<tr><td colspan="4"><div class="batchoperations"><form action="" method="get" style="display:inline"><input type="hidden" name="ticket" value="'.$ticket.'" /><input type="hidden" name="ipp" value="'.$ipp.'"/><input type="hidden" name="page" value="clearlog" /><input type="hidden" name="amount" value="cp" /><input type="hidden" name="filter" value="'.$filter.'" /><input type="hidden" name="filtertype" value="'.$filtertype.'" /><input type="hidden" name="keyword" value="'.$keyword.'" /><input type="submit" value="最初の'.$ipp.'件を削除" /></form> <form action="" method="get" style="display:inline"><input type="hidden" name="ticket" value="'.$ticket.'" /><input type="hidden" name="ipp" value="'.$ipp.'"/><input type="hidden" name="page" value="clearlog" /><input type="hidden" name="amount" value="cf" /><input type="hidden" name="filter" value="'.$filter.'" /><input type="hidden" name="filtertype" value="'.$filtertype.'" /><input type="hidden" name="keyword" value="'.$keyword.'" /><input type="submit" value="現在の絞込み条件に該当するログを削除" /></form> <form action="" method="get" style="display:inline"><input type="hidden" name="ticket" value="'.$ticket.'" /><input type="hidden" name="page" value="clearlog" /><input type="submit" value="全てのログを削除" /></form></div></td></tr>';
+               echo '<tr><th colspan="2">'.$cp.'/'.$ap.'ページ</th><td colspan="2">表示: <form style="display:inline"><input type="hidden" name="ticket" value="'.$ticket.'" /><input type="text" size="3" name="ipp" value="'.$ipp.'" />行を1ページに表示する <input type="submit" value="変更" /><input type="hidden" name="amount" value="cp" /><input type="hidden" name="filter" value="'.$filter.'" /><input type="hidden" name="filtertype" value="'.$filtertype.'" /><input type="hidden" name="keyword" value="'.$keyword.'" /><input type="hidden" name="page" value="log" /></form></td></tr>';
                echo $pager;
                echo '</table>';
        }
                echo "<form action=\"".serverVar('PHP_SELF')."\" method=\"get\">\n";
                echo $manager->addTicketHidden();
                echo "<input type=\"hidden\" name=\"page\" value=\"train\" />\n";
-               echo "<select name=\"catcode\"><option value=\"ham\">Ham (not spam)</option><option value=\"spam\" selected=\"1\">Spam</option></select><br />";
+               echo "<select name=\"catcode\"><option value=\"ham\">ham(spamでないもの)として学習</option><option value=\"spam\" selected=\"1\">spamとして学習</option></select><br />";
                echo "<textarea class=\"sb_textinput\" cols=\"60\" rows=\"6\" name=\"expression\" ></textarea><br />";
-               echo "<input type=\"submit\" value=\"Train\" />\n";
+               echo "<input type=\"submit\" value=\"学習する\" />\n";
                echo "</form>\n";
        }
        
        function sb_testform() {
                global $manager;
-               echo "<h2>Enter a message that needs to be tested against Spam Bayes</h2>";
+               echo "<h2>文例を入力</h2>";
                echo "<form action=\"".serverVar('PHP_SELF')."\" method=\"get\">\n";
                echo $manager->addTicketHidden();
                echo "<input type=\"hidden\" name=\"page\" value=\"test\" />\n";
                echo "<textarea class=\"sb_textinput\" cols=\"60\" rows=\"6\" name=\"expression\" ></textarea><br />";
-               echo "<input type=\"submit\" value=\"Test this!\" />\n";
+               echo "<input type=\"submit\" value=\"この文例をテストする\" />\n";
                echo "</form>\n";
        }
        
                $pager = '<tr>';
                if ($startpos >= $ipp) {
                        $pager .= '<td><form action="" method="get" style="display:inline"><input type="hidden" name="page" value="'.$action.'" />';
-                       $pager .= '<input type="hidden" value="'.($startpos - $ipp).'" name="startpos" /><input type="hidden" name="ticket" value="'.$ticket.'" /><input type="submit" value="Previous page" /><input type="hidden" name="filter" value="'.$filter.'" /><input type="hidden" name="filtertype" value="'.$filtertype.'" /><input type="hidden" name="keyword" value="'.$keyword.'" /><input type="hidden" name="ipp" value="'.$ipp.'"/></form></td>'.$filterform;
+                       $pager .= '<input type="hidden" value="'.($startpos - $ipp).'" name="startpos" /><input type="hidden" name="ticket" value="'.$ticket.'" /><input type="submit" value="前ページ" /><input type="hidden" name="filter" value="'.$filter.'" /><input type="hidden" name="filtertype" value="'.$filtertype.'" /><input type="hidden" name="keyword" value="'.$keyword.'" /><input type="hidden" name="ipp" value="'.$ipp.'"/></form></td>'.$filterform;
                } else {
                        $pager .= '<td></td>'.$filterform;
                }
                if (($total - $ipp) > $startpos) {
                        $pager .= '<td><form action="" method="get" style="display:inline"><input type="hidden" name="page" value="'.$action.'" />';
-                       $pager .= '<input type="hidden" value="'.($startpos + $ipp).'" name="startpos" /><input type="hidden" name="ticket" value="'.$ticket.'" /><input type="submit" value="Next page" /><input type="hidden" name="filter" value="'.$filter.'" /><input type="hidden" name="filtertype" value="'.$filtertype.'" /><input type="hidden" name="keyword" value="'.$keyword.'" /><input type="hidden" name="ipp" value="'.$ipp.'"/></form></td>';
+                       $pager .= '<input type="hidden" value="'.($startpos + $ipp).'" name="startpos" /><input type="hidden" name="ticket" value="'.$ticket.'" /><input type="submit" value="次ページ" /><input type="hidden" name="filter" value="'.$filter.'" /><input type="hidden" name="filtertype" value="'.$filtertype.'" /><input type="hidden" name="keyword" value="'.$keyword.'" /><input type="hidden" name="ipp" value="'.$ipp.'"/></form></td>';
                } else {
                        $pager .= '<td></td>';
                }
                $ticket = $manager->_generateTicket();
 
                $selected   = $filter == 'all' ? 'selected':'';
-               $filterform = '<td colspan="2"><form style="display:inline">Show: <select name="filter"><option value="all" '.$selected.'>All</option>';
+               $filterform = '<td colspan="2"><form style="display:inline">絞込み: <select name="filter"><option value="all" '.$selected.'>全て</option>';
                $selected   = $filter == 'ham' ? 'selected':'';
-               $filterform .= '<option value="ham" '.$selected.'>Ham (not spam)</option>';
+               $filterform .= '<option value="ham" '.$selected.'>hamのみ</option>';
                $selected   = $filter == 'spam' ? 'selected':'';
-               $filterform .= '<option value="spam" '.$selected.'>Spam</option></select> <input type="hidden" name="page" value="log"/><input type="hidden" name="ipp" value="'.$ipp.'"/>';
+               $filterform .= '<option value="spam" '.$selected.'>spamのみ</option></select> <input type="hidden" name="page" value="log"/><input type="hidden" name="ipp" value="'.$ipp.'"/>';
        
                $logtypes   = $oPluginAdmin->plugin->spambayes->nbs->getlogtypes();
                $selected   = $filtertype == 'all' ? 'selected':'';
-               $filterform .= '<select name="filtertype"><option value="all" '.$selected.'>All events</option>';
+               $filterform .= '<select name="filtertype"><option value="all" '.$selected.'>全てのイベント</option>';
                foreach($logtypes as $logtype) {
                        $selected = $filtertype == $logtype ? 'selected' : '';
                        $show = explode(' ',$logtype);
                        $show = $show[0] == 'event' ? $show[1] : $show[0];
                        $filterform .= '<option value="'.$logtype.'" '.$selected.'>'.$show.'</option>';
                }
-               $filterform .= '</select><input type="hidden" name="ticket" value="'.$ticket.'" /><input type="submit" value="Apply filter" /></form>';
-               $filterform .= '&nbsp;|&nbsp;<form style="display:inline"><input type="hidden" name="ticket" value="'.$ticket.'" /><input type="hidden" name="page" value="log"/><input type="hidden" name="filter" value="'.$filter.'"/><input type="hidden" name="filtertype" value="'.$filtertype.'"/><input type="hidden" name="ipp" value="'.$ipp.'"/><input type="text" name="keyword" value="'.$keyword.'" /><input type="submit" value="search" /></form>';
+               $filterform .= '</select><input type="hidden" name="ticket" value="'.$ticket.'" /><input type="submit" value="適用" /></form>';
+               $filterform .= '&nbsp;|&nbsp;<form style="display:inline"><input type="hidden" name="ticket" value="'.$ticket.'" /><input type="hidden" name="page" value="log"/><input type="hidden" name="filter" value="'.$filter.'"/><input type="hidden" name="filtertype" value="'.$filtertype.'"/><input type="hidden" name="ipp" value="'.$ipp.'"/><input type="text" name="keyword" value="'.$keyword.'" /><input type="submit" value="検索" /></form>';
                $filterform .= '</td>';
                return $filterform;
        }
index 87e2509..e7ee496 100644 (file)
@@ -2,7 +2,7 @@
 
 /**
   * Modified by hsur ( http://blog.cles.jp/np_cles )
-  * $Id: spambayes.php,v 1.5 2007-06-25 11:47:30 hsur Exp $
+  * $Id: spambayes.php,v 1.6 2008-05-03 22:38:17 hsur Exp $
 
     ***** BEGIN LICENSE BLOCK *****
        This file is part of PHP Naive Bayesian Filter.
        the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
        in which case the provisions of the LGPL are applicable instead
        of those above.
-***** END LICENSE BLOCK ******/
+       ***** END LICENSE BLOCK ******/
 
 //define('NP_SPAMBAYES_TOKENIZER', '/usr/local/bin/mecab -F "%h\t%m\t%f[6]\n" -E ""');
 define('NP_SPAMBAYES_APIURL', 'http://api.jlp.yahoo.co.jp/MAService/V1/parse');
 
+require_once(dirname(__FILE__).'/../sharedlibs/sharedlibs.php');
+require_once('cles/AsyncHTTP.php');
+
 class NaiveBayesian {
        /** min token length for it to be taken into consideration */
        var $min_token_length = 2;
@@ -146,7 +149,7 @@ class NaiveBayesian {
                        echo '<td>'.$value['spam'].'</td>';
                        echo '</tr>';
                }
-               echo '<tr><td>Rescaled probability:</td><th>'.$scores['ham'].'</th><th>'.$scores['spam'].'</th></tr>';
+               echo '<tr><td>調整後のスコア:</td><th>'.$scores['ham'].'</th><th>'.$scores['spam'].'</th></tr>';
                echo '</table>';
                //debug: print_r ($scores);
        }
@@ -281,7 +284,12 @@ class NaiveBayesian {
                        $postData['response'] = 'baseform';
                        $postData['sentence'] = $string;
                                
-                       $data = $this->_http(NP_SPAMBAYES_APIURL, 'POST', '', $postData);
+                       $ahttp = new cles_AsyncHTTP();
+                       $ahttp->asyncMode = false;
+                       $ahttp->userAgent = 'NP_SpamBayesJP';
+                       $ahttp->setRequest(NP_SPAMBAYES_APIURL, 'POST', '', $postData);
+                       list($data) = $ahttp->getResponses();
+                       
                        if( $data ){
                                $p = new NP_SpamBayes_XMLParser();
                                $rawtokens = $p->parse($data);
@@ -298,7 +306,10 @@ class NaiveBayesian {
                                }
                                
                                $p->free();
+                       } else {
+                               ACTIONLOG :: add(WARNING, 'NP_SpamBayes: AsyncHTTP Error['.$ahttp->getErrorNo(0).']'.$ahttp->getError(0));
                        }
+                                               
                } else if( defined('NP_SPAMBAYES_TOKENIZER') && function_exists(proc_open) ) {
                        // using mecab
                        $string = preg_replace('/\r|\n/', '', $string);
@@ -343,68 +354,6 @@ class NaiveBayesian {
                return $tokens;
        } // function _getTokens
 
-       function _http($url, $method = "GET", $headers = "", $post = array ("")) {
-               $URL = parse_url($url);
-
-               if (isset ($URL['query'])) {
-                       $URL['query'] = "?".$URL['query'];
-               } else {
-                       $URL['query'] = "";
-               }
-
-               if (!isset ($URL['port']))
-               $URL['port'] = 80;
-
-               $request = $method." ".$URL['path'].$URL['query']." HTTP/1.0\r\n";
-
-               $request .= "Host: ".$URL['host']."\r\n";
-               $request .= "User-Agent: NP_SpamBayes\r\n";
-
-               if (isset ($URL['user']) && isset ($URL['pass'])) {
-                       $request .= "Authorization: Basic ".base64_encode($URL['user'].":".$URL['pass'])."\r\n";
-               }
-
-               $request .= $headers;
-
-               if (strtoupper($method) == "POST") {
-                       while (list ($name, $value) = each($post)) {
-                               $POST[] = $name."=".urlencode($value);
-                       }
-                       $postdata = implode("&", $POST);
-                       $request .= "Content-Type: application/x-www-form-urlencoded\r\n";
-                       $request .= "Content-Length: ".strlen($postdata)."\r\n";
-                       $request .= "\r\n";
-                       $request .= $postdata;
-               } else {
-                       $request .= "\r\n";
-               }
-
-               /* debug
-               $test = fopen("/tmp/postdata.dat","wb");
-               fwrite($test, $request);
-               fclose($test);
-               */
-
-               $fp = fsockopen($URL['host'], $URL['port'], $errno, $errstr, 20);
-
-               if ($fp) {
-                       socket_set_timeout($fp, 20);
-                       fputs($fp, $request);
-                       $response = "";
-                       while (!feof($fp)) {
-                               $response .= fgets($fp, 4096);
-                       }
-                       fclose($fp);
-                       $DATA = split("\r\n\r\n", $response, 2);
-                       return $DATA[1];
-               } else {
-                       $host = $URL['host'];
-                       $port = $URL['port'];
-                       ACTIONLOG :: add(WARNING, 'NP_SpamBayes: HTTP Error: '."[$errno]($host:$port) $errstr");
-                       return null;
-               }
-       }
-
        /** clean a string from the diacritics
        @author Antoine Bajolet [phpdig_at_toiletoine.net]
        @author SPIP [http://uzine.net/spip/]
@@ -433,18 +382,24 @@ class NaiveBayesian {
 
 class NP_SpamBayes_XMLParser {
        function NP_SpamBayes_XMLParser(){
-               $this->parser = xml_parser_create();
+               $this->parser = xml_parser_create('UTF-8');
                xml_set_object($this->parser, $this);
                xml_set_element_handler($this->parser, "_open", "_close");
                xml_set_character_data_handler($this->parser, "_cdata");
-
-               $this->target = null ;
+               
+               $this->isError = false;
                $this->inTarget = false;
        }
 
        function parse($data){
                $this->words = array();
                xml_parse($this->parser, $data);
+               $errcode = xml_get_error_code($this->parser);
+           if ( $errcode != XML_ERROR_NONE ) {
+               $this->isError = true;
+               $this->words = array();
+                       $this->words[] = 'XML Parse Error: ' . xml_error_string($errcode) . ' in '. xml_get_current_line_number($this->parser);
+           }
                return $this->words;
        }
 
@@ -468,7 +423,7 @@ class NP_SpamBayes_XMLParser {
        }
 
        function _close($parser, $name){
-               if( $name == $this->target ) $this->inTarget = null;
+               if( $name == $this->inTarget ) $this->inTarget = null;
        }
 
        function _cdata($parser, $data){