[pLog-svn] r6869 - in plugins/branches/lifetype-1.2/contact: . class/action locale
jondaley at devel.lifetype.net
jondaley at devel.lifetype.net
Sat Apr 18 17:46:29 EDT 2009
Author: jondaley
Date: 2009-04-18 17:46:29 -0400 (Sat, 18 Apr 2009)
New Revision: 6869
Modified:
plugins/branches/lifetype-1.2/contact/class/action/contactpluginsendaction.class.php
plugins/branches/lifetype-1.2/contact/locale/locale_en_UK.php
plugins/branches/lifetype-1.2/contact/plugincontact.class.php
plugins/branches/lifetype-1.2/contact/readme.txt
Log:
now uses bayesian filter
Modified: plugins/branches/lifetype-1.2/contact/class/action/contactpluginsendaction.class.php
===================================================================
--- plugins/branches/lifetype-1.2/contact/class/action/contactpluginsendaction.class.php 2009-04-18 21:03:37 UTC (rev 6868)
+++ plugins/branches/lifetype-1.2/contact/class/action/contactpluginsendaction.class.php 2009-04-18 21:46:29 UTC (rev 6869)
@@ -26,17 +26,27 @@
function perform(){
- $postText =
- $this->_locale->pr("plugin_contact_contact_from",
- $this->_request->getValue("userName") . " <".
- $this->_request->getValue("userEmailAddress").">").
- $this->_request->getValue("contactText");
+ $username = $this->_request->getValue("userName");
+ $emailAddress = $this->_request->getValue("userEmailAddress");
+ $text = $this->_request->getValue("contactText");
+ $subject = $this->_request->getValue("contactTopic");
+ if($this->_checkSpam($username, $emailAddress, $text, $subject)){
+ $this->_view = new ErrorView($this->_blogInfo);
+ $this->_view->setErrorMessage($this->_locale->tr("plugin_contact_error_spam"));
+ $this->setCommonData();
+ return false;
+ }
+
+ $postText = $this->_locale->pr("plugin_contact_contact_from",
+ "$username <$emailAddress>");
+ $postText .= $text;
+
$config =& Config::getConfig();
$message = new EmailMessage();
$message->setFrom($config->getValue( "post_notification_source_address"));
- $message->setSubject($this->_request->getValue("contactTopic"));
+ $message->setSubject($subject);
$message->setCharset($this->_locale->getCharset());
$message->setBody($postText);
@@ -46,9 +56,41 @@
$service = new EmailService();
$service->sendMessage($message);
- $this->_view = new PluginTemplatedView( $this->_blogInfo, "contact", "accepted" );
- $this->setCommonData();
-
+ $this->_view = new PluginTemplatedView($this->_blogInfo, "contact", "accepted");
+ $this->setCommonData();
return true;
}
+
+ // run the inputs through the bayesian filter to see if it thinks it is spam
+ // copied from bayesianfilter::getSpamProbability since that function is marked
+ // as private
+ function _checkSpam($userName, $userEmail, $text, $topic){
+ $config =& Config::getConfig();
+ if($config->getValue("bayesian_filter_enabled")){
+ lt_include( PLOG_CLASS_PATH."class/bayesian/bayesiantokenizer.class.php" );
+ $tokenizer = new BayesianTokenizer();
+
+ $tokensTopic = $tokenizer->addContextMark(
+ $tokenizer->tokenize($topic), TOKEN_TOPIC_MARK);
+ $tokensText = $tokenizer->tokenize($text);
+
+ $tokensUserName = $tokenizer->addContextMark(
+ $tokenizer->tokenize($userName), TOKEN_USER_NAME_MARK);
+ $tokensUserEmail = $tokenizer->addContextMark(
+ $tokenizer->tokenize($userEmail), TOKEN_USER_EMAIL_MARK);
+
+ $tokens = array_merge($tokensTopic, $tokensText,
+ $tokensUserName, $tokensUserEmail);
+ $significantTokens = BayesianFilter::_getMostSignificantTokens(
+ $this->_blogInfo->getId(), $tokens);
+
+ $spamicity = BayesianFilter::_getBayesProbability($significantTokens);
+ if($spamicity >= $config->getValue("bayesian_filter_spam_probability_treshold"))
+ return true;
+ }
+
+ // TODO: use auth image or hidden input?
+ return false;
+ }
+
}
Modified: plugins/branches/lifetype-1.2/contact/locale/locale_en_UK.php
===================================================================
--- plugins/branches/lifetype-1.2/contact/locale/locale_en_UK.php 2009-04-18 21:03:37 UTC (rev 6868)
+++ plugins/branches/lifetype-1.2/contact/locale/locale_en_UK.php 2009-04-18 21:46:29 UTC (rev 6869)
@@ -9,7 +9,8 @@
$messages["plugin_contact_error_updating_settings"] = "There was an error updating the settings.";
$messages["plugin_contact_settings_saved_ok"] = "The settings were updated successfully.";
-$messages["plugin_contact_error_data"] = "Error sending message. Please click <a href='javascript:history.go(-1)'>'back'</a> and try again.";
+$messages["plugin_contact_error_data"] = "Error sending message. Please click <a href='javascript:history.go(-1)'>'back'</a> and try again. All fields are required.";
+$messages["plugin_contact_error_spam"] = "Error sending message, it looks like too much like spam. You'll have to go back and try again or contact this person in another way.";
$messages["plugin_contact_email_accepted"] = "Your message was sent successfully!";
Modified: plugins/branches/lifetype-1.2/contact/plugincontact.class.php
===================================================================
--- plugins/branches/lifetype-1.2/contact/plugincontact.class.php 2009-04-18 21:03:37 UTC (rev 6868)
+++ plugins/branches/lifetype-1.2/contact/plugincontact.class.php 2009-04-18 21:46:29 UTC (rev 6869)
@@ -16,7 +16,7 @@
$this->id = "contact";
$this->desc = "Allows visitors to submit a message to the blog owner (via email)";
$this->author = "Jon Daley";
- $this->version = "20090418beta";
+ $this->version = "20090418";
if( $source == "admin" )
$this->initAdmin();
Modified: plugins/branches/lifetype-1.2/contact/readme.txt
===================================================================
--- plugins/branches/lifetype-1.2/contact/readme.txt 2009-04-18 21:03:37 UTC (rev 6868)
+++ plugins/branches/lifetype-1.2/contact/readme.txt 2009-04-18 21:46:29 UTC (rev 6869)
@@ -5,6 +5,8 @@
This plugin offers a method for visitors to privately contact blog
owners via form/email.
+It will use the bayesian filter if it is enabled.
+
Install:
1. Configure and enable the plugin in your LifeType control center
@@ -17,7 +19,6 @@
TODO:
- It will use the bayesian filter if it is enabled
Can we use authimage and hiddeninput if they are installed?
More information about the pLog-svn
mailing list