[pLog-svn] r6876 - in plugins/branches/lifetype-1.2/contact: class/action class/view locale

jondaley at devel.lifetype.net jondaley at devel.lifetype.net
Fri May 1 10:59:12 EDT 2009


Author: jondaley
Date: 2009-05-01 10:59:12 -0400 (Fri, 01 May 2009)
New Revision: 6876

Modified:
   plugins/branches/lifetype-1.2/contact/class/action/admincontactpluginupdatesettingsaction.class.php
   plugins/branches/lifetype-1.2/contact/class/action/contactpluginsendaction.class.php
   plugins/branches/lifetype-1.2/contact/class/view/admincontactpluginsettingsview.class.php
   plugins/branches/lifetype-1.2/contact/locale/locale_en_UK.php
Log:
banned keywords now working.  save data in a string instead of an array.  It'll be easier to use (and modify if someone needs to modify it directly for some reason).  Also, the filteredWords rule wasn't very useful for what I needed - and probably that rule should be changed, since it has hard coded spaces in the filter, rather than a preg_match or something that could do a better job matching (and not being tricked by trivial hyphens or something to make spaces)

Modified: plugins/branches/lifetype-1.2/contact/class/action/admincontactpluginupdatesettingsaction.class.php
===================================================================
--- plugins/branches/lifetype-1.2/contact/class/action/admincontactpluginupdatesettingsaction.class.php	2009-04-30 21:16:07 UTC (rev 6875)
+++ plugins/branches/lifetype-1.2/contact/class/action/admincontactpluginupdatesettingsaction.class.php	2009-05-01 14:59:12 UTC (rev 6876)
@@ -36,17 +36,21 @@
 			$blogSettings->setValue("plugin_contact_enabled", $this->_pluginEnabled);
 
                 // save word list, ignoring commas and leading and trailing spaces
+
             $bannedKeywords = explode(",", $this->_request->getValue("bannedKeywords"));
-                // remove spaces
-            $bannedKeywordsArray = array();
+                // remove spaces and store in a more regexp-like fashion
+            $bannedKeywordsExp = "";
             foreach($bannedKeywords as $key => $word){
                 $word = trim($word);
-                if($word)
-                    $bannedKeywordsArray[] = $word;
+                if($word){
+                    if($bannedKeywordsExp)
+                        $bannedKeywordsExp .= ",";
+                    $bannedKeywordsExp .= $word;
+                }
             }
-                // remove duplicates
-            $bannedKeywordsArray = array_unique($bannedKeywordsArray);
-			$blogSettings->setValue("plugin_banned_keywords", $bannedKeywordsArray);
+			$blogSettings->setValue("plugin_contact_banned_keywords", $bannedKeywordsExp);
+
+
             
 			$this->_blogInfo->setSettings($blogSettings);
 			

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-30 21:16:07 UTC (rev 6875)
+++ plugins/branches/lifetype-1.2/contact/class/action/contactpluginsendaction.class.php	2009-05-01 14:59:12 UTC (rev 6876)
@@ -29,18 +29,28 @@
             if(!parent::validate())
                 return false;
 
-            lt_include( PLOG_CLASS_PATH."class/data/validator/rules/filteredwordsrule.class.php" );
-			$config =& Config::getConfig();
-			$bannedKeywords = $config->getValue("plugin_contact_banned_keywords", array());
-			$rule = new FilteredWordsRule($bannedKeywords);
+            $blogSettings = $this->_blogInfo->getSettings();
 
+                // get words to match
+			$bannedKeywords = $blogSettings->getValue("plugin_contact_banned_keywords");
+                // no banned words, exit out
+            if(!$bannedKeywords)
+                return true;
+
+                // we use comma delimited in the database and for the users, but we need
+                // a 'pipe' symbol for the regexp to work
+            $bannedKeywords = str_replace(",", "|", $bannedKeywords);
+
+            $regexp = "/($bannedKeywords)/";
+            
             $text = $this->_request->getValue("contactText");
-            if(!$rule->validate($text))
-                return false;
+            $subject = $this->_request->getValue("contactTopic");
 
-            $subject = $this->_request->getValue("contactTopic");
-            if(!$rule->validate($subject))
+            if(preg_match($regexp, $text) || preg_match($regexp, $subject)){
+            	$this->_view = new ErrorView( $this->_blogInfo, $this->_locale->tr("plugin_contact_error_banned_keywords"));
+                $this->setCommonData();
                 return false;
+            }
 
             return true;
         }

Modified: plugins/branches/lifetype-1.2/contact/class/view/admincontactpluginsettingsview.class.php
===================================================================
--- plugins/branches/lifetype-1.2/contact/class/view/admincontactpluginsettingsview.class.php	2009-04-30 21:16:07 UTC (rev 6875)
+++ plugins/branches/lifetype-1.2/contact/class/view/admincontactpluginsettingsview.class.php	2009-05-01 14:59:12 UTC (rev 6876)
@@ -14,16 +14,7 @@
 			// load some configuration settings
 			$blogSettings = $this->_blogInfo->getSettings();
 			$this->setValue( "pluginEnabled", $blogSettings->getValue("plugin_contact_enabled"));
-            $wordsArray = $blogSettings->getValue("plugin_banned_keywords");
-            $words = "";
-            if(count($wordsArray)){
-                foreach($wordsArray as $word){
-                    if($words)
-                        $words .= ",";
-                    $words .= $word;
-                }
-            }
-			$this->setValue( "bannedKeywords", $words);
+			$this->setValue( "bannedKeywords", $blogSettings->getValue("plugin_contact_banned_keywords");
 			parent::render();
 		}
 	}

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-30 21:16:07 UTC (rev 6875)
+++ plugins/branches/lifetype-1.2/contact/locale/locale_en_UK.php	2009-05-01 14:59:12 UTC (rev 6876)
@@ -12,8 +12,9 @@
 $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.  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_error_data"] = "Error sending message. Please go back 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 us by another method.";
+$messages["plugin_contact_error_banned_keywords"] = "Error sending message. You used words in your message that the blog owner doesn't allow.<br/>You'll have to go back and try again or contact us by another method.";
 
 $messages["plugin_contact_email_accepted"] = "Your message was sent successfully!";
 



More information about the pLog-svn mailing list