table_cat = sql_table('plug_sb_cat'); // categories $this->table_wf = sql_table('plug_sb_wf'); // word frequencies $this->table_ref = sql_table('plug_sb_ref'); // references $this->table_log = sql_table('plug_sb_log'); // logging include_once($DIR_PLUGINS."spambayes/spambayes.php"); $this->spambayes = new NaiveBayesian(&$this); } function getEventList() { return array('QuickMenu', 'SpamCheck'); } function hasAdminArea() { return 1; } function event_SpamCheck (&$data) { global $DIR_PLUGINS; if( isset($data['spamcheck']['result']) && $data['spamcheck']['result'] == true) return; switch( strtolower($data['spamcheck']['type']) ){ case 'trackback': case 'mailtoafriend': case 'comment': break; default: return; } // for SpamCheck API 2.0 compatibility if( ! $data['spamcheck']['data'] ){ $data['spamcheck']['data'] = $data['spamcheck']['body'] ."\n"; $data['spamcheck']['data'] .= $data['spamcheck']['author'] ."\n"; $data['spamcheck']['data'] .= $data['spamcheck']['email'] ."\n"; $data['spamcheck']['data'] .= $data['spamcheck']['url'] ."\n"; } $score = $this->spambayes->categorize($data['spamcheck']['data']); if( (float)$score['spam'] > (float)$this->getOption('probability') ) { $log = $data['spamcheck']['type'] > '' ? $data['spamcheck']['type'] ." SpamCheck":"event SpamCheck"; $this->spambayes->nbs->logevent( $log.' SPAM detected. score: (ham '.$score['ham'].') (spam: '.$score['spam'].')', $data['spamcheck']['data'], 'spam' ); if(isset($data['spamcheck']['return']) && $data['spamcheck']['return'] == true) { // Return to caller $data['spamcheck']['result'] = true; $data['spamcheck']['plugin'] = $this->getName(); $data['spamcheck']['message'] = 'Marked as spam by NP_SpamBayes spamScore:'.(float)$score['spam'].' hamScore:'.(float)$score['ham']; return; } else { exit; } } elseif ( trim($data['spamcheck']['data']) != '' ) { $log = $data['spamcheck']['type'] > '' ? $data['spamcheck']['type'] ." SpamCheck":"event SpamCheck"; $this->spambayes->nbs->logevent( $log.' HAM detected. score: (ham '.$score['ham'].') (spam: '.$score['spam'].')', $data['spamcheck']['data'], 'ham' ); } // in case of SpamCheck we do NOT log HAM events ... } /* some default functions for a plugin */ 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.4b'; } function getDescription() { return 'SpamBayes filter for comment and trackback spam. In adherence with Spam API 1.0 for Nucleus'; } function supportsFeature($what) { switch($what) { case 'SqlTablePrefix': return 1; default: return 0; } } function event_QuickMenu(&$data) { global $member, $nucleus, $blogid; // only show to admins if (preg_match("/MD$/", $nucleus['version'])) { $isblogadmin = $member->isBlogAdmin(-1); } else { $isblogadmin = $member->isBlogAdmin($blogid); } if (!($member->isLoggedIn() && ($member->isAdmin() | $isblogadmin))) return; if ($this->getOption('enableQuickmenu') == 'yes' ) { array_push( $data['options'], array( 'title' => 'SpamBayes', 'url' => $this->getAdminURL(), 'tooltip' => 'Manage SpamBayes filter' ) ); } } 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('appid','Yahoo!Japan AppID','text',''); $this->createOption('DropTable','Clear the database when uninstalling','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))"); sql_query("CREATE TABLE IF NOT EXISTS ".$this->table_wf." (word varchar(250) NOT NULL default '', catcode varchar(50) NOT NULL default '', wordcount bigint(20) NOT NULL default '0', PRIMARY KEY (word, catcode))"); sql_query("CREATE TABLE IF NOT EXISTS ".$this->table_ref." (ref bigint(20) NOT NULL, catcode varchar(250) NOT NULL default '', content text NOT NULL default '', PRIMARY KEY (ref), KEY(catcode))"); sql_query("CREATE TABLE IF NOT EXISTS ".$this->table_log." (id bigint(20) NOT NULL auto_increment, log varchar(250) NOT NULL default '', content text NOT NULL default '', catcode varchar(250) NOT NULL default '', logtime timestamp, PRIMARY KEY (id), KEY(catcode))"); // create 'ham' and 'spam' categories sql_query("insert into ".$this->table_cat." (catcode) values ('ham')"); sql_query("insert into ".$this->table_cat." (catcode) values ('spam')"); } function unInstall() { if ($this->getOption('DropTable') == 'yes') { sql_query('drop table if exists '.$this->table_cat); sql_query('drop table if exists '.$this->table_ref); sql_query('drop table if exists '.$this->table_wf); sql_query('drop table if exists '.$this->table_log); } } }