Products and Services
Graffiti CMS
Learn more about our simple content publishing platform.
Harvest Reporting Server
Get business intelligence tools for measuring online behavior.
Professional Services
Consulting, creative, and Web services from the people who know Community Server best.
Solutions
Telligent
Learn more about our team at Telligent.com.
 

Migrating Spam Rules

Community Server 2008 updated the spam rules to support dynamic configuration options so the dynamic configuration code is consistent across new features. For example, the same way you code for dynamic options in a content fragment (widget) is the same as in spam rules. These updates allow you to easily configure the spam rule dynamic options.

 

Community Server 2007 vs Community Server 2008 Structure

The Community Server 2007 spam rules were configurable, but the configuration options were much more limited and the presentation was not as controllable or consistent. You would use an ArrayList to store the available settings and when you retrieved these settings you would have to parse them out.

The following example shows how to update the BodyLengthSpamRule in Community Server 2007:

public class BodyLengthSpamRule : BlogSpamRule

{

private static Guid ruleID = new Guid("843ACA49-6342-4997-A98C-F7A948B32111");

private static int defaultPoints = 5;

private static int defaultLength = 10;

public BodyLengthSpamRule() { }

public override ArrayList GetAvailableSettings()

{

ArrayList settings = new ArrayList();

settings.Add(new RuleSetting(ruleID, "points", "Points for failure",

defaultPoints.ToString()));

settings.Add(new RuleSetting(ruleID, "length", "Minimum body length",

defaultLength.ToString()));

return settings;

}

public override int CalculateSpamScore(WeblogPost post, CSPostEventArgs e)

{

// Retrieve setting values

int points = Globals.SafeInt(this.GetSettingValue("points"), defaultPoints);

int length = Globals.SafeInt(this.GetSettingValue("length"), defaultLength);

if ((post.Body == null) || (post.Body.Trim().Length < length))

return points;

return 0;

}

public override string Name

{

get { return "Comment Length Blog Spam Rule"; }

}

public override string Description

{

get { return "Requires comments meet a certain minimum length"; }

}

public override Guid RuleID

{

get { return ruleID; }

}

}

In Community Server 2008, the same rule looks like this:

public class BodyLengthSpamRule : BlogSpamRule

{

private static Guid ruleID = new Guid("843ACA49-6342-4997-A98C-F7A948B32111");

private static int defaultPoints = 5;

private static int defaultLength = 10;

public BodyLengthSpamRule() { }

public override PropertyGroup[] GetAvailablePropertyGroups()

{

PropertyGroup[] propertyGroups = new PropertyGroup[] {

new PropertyGroup("spamOptions", "Spam Settings", 0)

};

propertyGroups[0].Properties.Add(new Property("points", "Points for failure",

PropertyType.Int, 0, defaultPoints.ToString()));

propertyGroups[0].Properties.Add(new Property("length", "Minimum body length",

PropertyType.Int, 1, defaultLength.ToString()));

return propertyGroups;

}

public override int CalculateSpamScore(WeblogPost post, CSPostEventArgs e)

{

// Retrieve setting values

int points = GetIntValue("points", defaultPoints);

int length = GetIntValue("length", defaultLength);

if ((post.Body == null) || (post.Body.Trim().Length < length))

return points;

return 0;

}

public override string Name

{

get { return "Comment Length Blog Spam Rule"; }

}

public override string Description

{

get { return "Requires comments meet a certain minimum length"; }

}

public override Guid RuleID

{

get { return ruleID; }

}

}

As you can see, there are not many dramatic differences in the rule. The rule used in Community Server 2007 will still work in Community Server 2008, the only difference being that it cannot be configured in the Control Panel in Community Server 2008. To get it to work, you must update the rule to override the GetAvailablePropertyGroups method.

Whenever you update your previous rule, the configuration options you set previously are available after the update. A schema patch that runs during the upgrade process copies over your spam settings into the new table structure so any updated spam rules settings remain intact.

Only two things need to be updated in the Community Server 2008 spam rules:

  • Replace the GetAvailableSettings with the GetAvailablePropertyGroups method. This method returns a collection of Telligent.DynamicConfiguration.Components.PropertyGroup objects. These are the same type of propertyGroups that you can find in the theme.config file. You can follow the example here to go by or read up on ContentFragments as they too have a similar method that returns the same type of collection.
  • Update your retrieval of the configuration settings. This is done by calling one of the ConfigurationDataBase’s Get[Type]Value methods. In the Community Server 2008 example above, the GetIntValue method was called because it was retrieving an integer type value. These methods take two parameters: the identity of the configuration property and a default value in case the property does not exist.