[pLog-svn] r7188 - in plugins/branches/lifetype-1.2/moderate: . class/action class/view locale templates

jondaley at devel.lifetype.net jondaley at devel.lifetype.net
Fri May 11 11:52:42 EDT 2012


Author: jondaley
Date: 2012-05-11 11:52:42 -0400 (Fri, 11 May 2012)
New Revision: 7188

Modified:
   plugins/branches/lifetype-1.2/moderate/class/action/adminmoderatepluginupdatesettingsaction.class.php
   plugins/branches/lifetype-1.2/moderate/class/view/adminmoderatepluginsettingsview.class.php
   plugins/branches/lifetype-1.2/moderate/locale/locale_en_UK.php
   plugins/branches/lifetype-1.2/moderate/pluginmoderate.class.php
   plugins/branches/lifetype-1.2/moderate/templates/pluginsettings.template
Log:
new feature: mark comments as spam automatically if the user currently has at least two comments that aren't yet approved, since probably only spammers would comment that much.  At some point, it might be nice to make the number of times a configuration parameter, since some sites might like it higher (or lower) than 2

Modified: plugins/branches/lifetype-1.2/moderate/class/action/adminmoderatepluginupdatesettingsaction.class.php
===================================================================
--- plugins/branches/lifetype-1.2/moderate/class/action/adminmoderatepluginupdatesettingsaction.class.php	2012-04-19 20:22:08 UTC (rev 7187)
+++ plugins/branches/lifetype-1.2/moderate/class/action/adminmoderatepluginupdatesettingsaction.class.php	2012-05-11 15:52:42 UTC (rev 7188)
@@ -9,6 +9,7 @@
 		var $_pluginEnabled;
 		var $_bypassByIp;
 		var $_bypassByAuth;
+		var $_markRepeatedByIp;
 
     	/**
          * Constructor. If nothing else, it also has to call the constructor of the parent
@@ -28,11 +29,14 @@
 
             $this->_bypassByIp = $this->_request->getValue( "bypassByIp" );
             $this->_bypassByIp = ($this->_bypassByIp != "" );			
-
+			
             $this->_bypassByAuth = $this->_request->getValue( "bypassByAuth" );
             $this->_bypassByAuth = ($this->_bypassByAuth != "" );			
 			
-			return true;
+            $this->_markRepeatedByIp = $this->_request->getValue( "markRepeatedByIp" );
+            $this->_markRepeatedByIp = ($this->_markRepeatedByIp != "" );
+
+            return true;
 		}
 		
         /**
@@ -45,6 +49,7 @@
             $blogSettings->setValue( "plugin_moderate_enabled", $this->_pluginEnabled );
             $blogSettings->setValue( "plugin_moderate_bypass_by_ip", $this->_bypassByIp );
             $blogSettings->setValue( "plugin_moderate_bypass_by_auth", $this->_bypassByAuth );
+            $blogSettings->setValue( "plugin_moderate_mark_repeated_by_ip", $this->_markRepeatedByIp );
             $this->_blogInfo->setSettings( $blogSettings ); 
 		
 			// save the blogs settings

Modified: plugins/branches/lifetype-1.2/moderate/class/view/adminmoderatepluginsettingsview.class.php
===================================================================
--- plugins/branches/lifetype-1.2/moderate/class/view/adminmoderatepluginsettingsview.class.php	2012-04-19 20:22:08 UTC (rev 7187)
+++ plugins/branches/lifetype-1.2/moderate/class/view/adminmoderatepluginsettingsview.class.php	2012-05-11 15:52:42 UTC (rev 7188)
@@ -20,11 +20,13 @@
 			$pluginEnabled = $blogSettings->getValue( "plugin_moderate_enabled" );
 			$bypassByIp = $blogSettings->getValue( "plugin_moderate_bypass_by_ip" );
 			$bypassByAuth = $blogSettings->getValue( "plugin_moderate_bypass_by_auth" );
+			$markRepeatedByIp = $blogSettings->getValue( "plugin_moderate_mark_repeated_by_ip" );
 			
 			// create a view and export the settings to the template
 			$this->setValue( "pluginEnabled", $pluginEnabled );		
-			$this->setValue( "bypassByIp", $bypassByIp );
+            $this->setValue( "bypassByIp", $bypassByIp );
 			$this->setValue( "bypassByAuth", $bypassByAuth );
+            $this->setValue( "markRepeatedByIp", $markRepeatedByIp );
 			
 			parent::render();
 		}

Modified: plugins/branches/lifetype-1.2/moderate/locale/locale_en_UK.php
===================================================================
--- plugins/branches/lifetype-1.2/moderate/locale/locale_en_UK.php	2012-04-19 20:22:08 UTC (rev 7187)
+++ plugins/branches/lifetype-1.2/moderate/locale/locale_en_UK.php	2012-05-11 15:52:42 UTC (rev 7188)
@@ -27,5 +27,6 @@
 $messages["error_you_have_been_blocked"] = "Thank you! However, there was a problem processing your request.";
 
 $messages["moderate_label_skip_moderation"] = "Allow commenters to bypass moderation";
-$messages["moderate_bypass_by_ip"] = "Do not moderate commenters from computers (ip addresses) who have previously commented.";
-$messages["moderate_bypass_by_auth"] = "Do not moderate authenticated users.";
+$messages["moderate_bypass_by_ip"] = "Do not moderate commenters from computers (ip addresses) who have previously commented";
+$messages["moderate_bypass_by_auth"] = "Do not moderate authenticated users";
+$messages["moderate_mark_repeated_by_ip"] = "Automatically mark as spam those comments from computers who have previously commented at least twice but who haven't yet been approved";

Modified: plugins/branches/lifetype-1.2/moderate/pluginmoderate.class.php
===================================================================
--- plugins/branches/lifetype-1.2/moderate/pluginmoderate.class.php	2012-04-19 20:22:08 UTC (rev 7187)
+++ plugins/branches/lifetype-1.2/moderate/pluginmoderate.class.php	2012-05-11 15:52:42 UTC (rev 7188)
@@ -18,7 +18,7 @@
 			$this->desc = "Provides moderation of comments";
 			$this->author = "The LifeType Project";
 			$this->locales = Array( "en_UK", "zh_TW", "es_ES", "fr_FR", "ca_ES" );
-            $this->version = "20101205";
+            $this->version = "20120511";
 
 			if( $source == "admin" )
 				$this->initAdmin();
@@ -51,31 +51,49 @@
             }
             
             $comment = $params["comment"];
-                            
-            if($blogSettings->getValue("plugin_moderate_bypass_by_ip")){
-                $ip = $comment->getClientIp();
-                    // Only check if this IP is valid
-                if($ip){
-                        // if this ip has previously been used for a validated comment,
-                        // don't moderate it
-
+            $status = COMMENT_STATUS_UNMODERATED;
+            
+            $ip = $comment->getClientIp();
+                // Only check if this IP is valid
+            if($ip){
+                if($blogSettings->getValue("plugin_moderate_bypass_by_ip")){
                     lt_include( PLOG_CLASS_PATH."class/database/db.class.php" );
                     $this->db =& Db::getDb();
                     $dbPrefix = Db::getPrefix();
+
+                        // if this ip has previously been used for a validated comment,
+                        // don't moderate it
                     $query = "SELECT id FROM ${dbPrefix}articles_comments WHERE ".
                         "blog_id = '".$this->blogInfo->getId()."' AND ".
                         "status = ".COMMENT_STATUS_NONSPAM." AND ".
                         "client_ip = '$ip' LIMIT 1";
-
                     $result = $this->db->Execute($query);
                     if($result && $result->RecordCount())
                         return true;
                 }
+                if($blogSettings->getValue("plugin_moderate_mark_repeated_by_ip")){
+                    lt_include( PLOG_CLASS_PATH."class/database/db.class.php" );
+                    $this->db =& Db::getDb();
+                    $dbPrefix = Db::getPrefix();
+
+                        // if this ip has previously been used for multiple comments that haven't been
+                        // approved yet, conditionally mark it as spam (based on the user's preferences)
+                        // The idea is that normal users won't keep commenting before seeing their
+                        // comments published
+                    $query = "SELECT count(id) FROM ${dbPrefix}articles_comments WHERE ".
+                        "blog_id = '".$this->blogInfo->getId()."' AND ".
+                        "status = ".COMMENT_STATUS_UNMODERATED." AND ".
+                        "client_ip = '$ip' LIMIT 2";
+
+                    $result = $this->db->Execute($query);
+                    if($result && $result->RecordCount() > 1)
+                        $status = COMMENT_STATUS_SPAM;
+                }
             }
-
-                // set the comment as moderated:
-                // change the status of the comment, as is easy as it seems...
-			$comment->setStatus( COMMENT_STATUS_UNMODERATED );
+            
+                // mark the comment as moderated (default), or according to the
+                // preferences/checks above
+			$comment->setStatus( $status );
 			$params["comment"] = $comment;
 		      
 			return true;
@@ -119,7 +137,8 @@
 			return( Array(
                         Array( "name" => "plugin_moderate_enabled", "type" => "boolean" ),
                         Array( "name" => "plugin_moderate_bypass_by_ip", "type" => "boolean" ),
-                        Array( "name" => "plugin_moderate_bypass_by_auth", "type" => "boolean" )
+                        Array( "name" => "plugin_moderate_bypass_by_auth", "type" => "boolean" ),
+                        Array( "name" => "plugin_moderate_mark_repeated_by_ip", "type" => "boolean" )
 			));
 		}	
 	}  

Modified: plugins/branches/lifetype-1.2/moderate/templates/pluginsettings.template
===================================================================
--- plugins/branches/lifetype-1.2/moderate/templates/pluginsettings.template	2012-04-19 20:22:08 UTC (rev 7187)
+++ plugins/branches/lifetype-1.2/moderate/templates/pluginsettings.template	2012-05-11 15:52:42 UTC (rev 7188)
@@ -18,12 +18,16 @@
    <div class="formHelp">   
     <input class="checkbox" type="checkbox" name="bypassByIp" id="bypassByIp" {if $bypassByIp} checked="checked" {/if} value="1"  {user_cannot_override key=plugin_moderate_bypass_by_ip}disabled="disabled"{/user_cannot_override}/>{$locale->tr("moderate_bypass_by_ip")}
    </div>
+
    <div class="formHelp">   
     <input class="checkbox" type="checkbox" name="bypassByAuth" id="bypassByAuth" {if $bypassByAuth} checked="checked" {/if} value="1"  {user_cannot_override key=plugin_moderate_bypass_by_auth}disabled="disabled"{/user_cannot_override}/>{$locale->tr("moderate_bypass_by_auth")}
    </div>
+
+   <div class="formHelp">   
+    <input class="checkbox" type="checkbox" name="markRepeatedByIp" id="markRepeatedByIp" {if $markRepeatedByIp} checked="checked" {/if} value="1"  {user_cannot_override key=plugin_moderate_mark_repeated_by_ip}disabled="disabled"{/user_cannot_override}/>{$locale->tr("moderate_mark_repeated_by_ip")}
+   </div>
   </div>
 
-  
  </fieldset>  
 
  <div class="buttons">



More information about the pLog-svn mailing list