*/ // must be run within Dokuwiki if(!defined('DOKU_INC')) die(); if(!defined('DOKU_PLUGIN')) define('DOKU_PLUGIN',DOKU_INC.'lib/plugins/'); require_once(DOKU_PLUGIN.'action.php'); class action_plugin_akismet extends DokuWiki_Action_Plugin { /** * return some info */ function getInfo(){ return array( 'author' => 'Andreas Gohr', 'email' => 'andi@splitbrain.org', 'date' => '2006-11-09', 'name' => 'Akismet Plugin', 'desc' => 'Use the Wordpress Akismet webservice to protect the Wiki against spam', 'url' => 'http://wiki:splitbrain.org/plugin:akismet', ); } /** * register the eventhandlers */ function register(&$controller){ $controller->register_hook('ACTION_ACT_PREPROCESS', 'BEFORE', $this, 'handle_act_preprocess', array()); } /** * Will intercept the 'save' action and check for Spam first. */ function handle_act_preprocess(&$event, $param){ if('save' != act_clean($event->data)) return; // nothing to do for us if(!$this->getConf('apikey')) return; // we need an API key // preprocess all available data global $ID; global $PRE; global $TEXT; global $SUF; global $INFO; $data = array(); $data['blog'] = DOKU_URL; $data['user_ip'] = $_SERVER['REMOTE_ADDR']; $data['user_agent'] = $_SERVER['HTTP_USER_AGENT']; $data['referrer'] = $_SERVER['HTTP_REFERER']; $data['permalink'] = wl($ID,'',true,'&'); $data['comment_type'] = 'wikipageedit'; $data['comment_author'] = $INFO['userinfo']['name']; $data['comment_author_email'] = $INFO['userinfo']['email']; $data['comment_content'] = con($PRE,$TEXT,$SUF,1); // check for spam an return if negative if(!$this->_checkForSpam($data)) return; // send mail if wanted if($this->getConf('notify')){ $mail = "The Akismet plugin blocked the saving of the page ".$ID."\n\n"; $mail .= $data['comment_content']; mail_send($this->getConf('notify'),'DokuWiki Akismet: blocked save',$mail); } // now block if configured if(!$this->getConf('dryrun')) $event->data = 'wordblock'; } /** * Submit the data to the Akismet webservice and return the result */ function _checkForSpam($data){ $info = $this->getInfo(); $http = new DokuHTTPClient(); // The Aksimet guys ask for a verbose UserAgent: $http->agent = 'DokuWiki/'.getVersion().' | '.$info['name'].'/'.$info['date']; $http->timeout = 5; $resp = $http->post('http://'.$this->getConf('apikey').'.rest.akismet.com/1.1/comment-check',$data); if($resp == 'true') return true; return false; } }