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.
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: