+1-888-365-2779
Try Now
More in this section

Forums / Developing with Sitefinity / Blocking certain words in comments and forums

Blocking certain words in comments and forums

4 posts, 0 answered
  1. Gregory
    Gregory avatar
    25 posts
    Registered:
    16 Mar 2009
    16 Apr 2009
    Link to this post
    Is there any sort of language filter for the forums and comments? I know there are spam protections in place but are there ways to censor certain words out (swear words and other offensive language) of the public forum posts and comments on the various areas?
  2. Dido
    Dido avatar
    149 posts
    Registered:
    24 Sep 2012
    20 Apr 2009
    Link to this post
    Hi Gregory,

    No, there is not. However, you can do the following:

    Design an inteface, something like:
    public enum OffenceSubstitution 
       // apply this when you want to change character for character 
       // e.g. "stupid" -> "******" 
       ReplaceSymbols, 
       // apply this when you want to delete the whole word 
       Remove, 
       // apply this when you want to replace any given phrase with a given word 
       // e.g. "stupid" -> "[censored]" 
       ReplaceWord    
     
    public interface IOffenceFilter 
       // this will contain a comma-delimited list of words that should be censored 
       string OffenceFilter {get; set;}
       // defines behaviour of the control 
       OffenceSubstitution SubstitutionMode {get;set;}
       // used in OffenceSubstitution.ReplaceWord 
       string OffenceSubstitutionPhrase {get;set;}
       // used in OffenceSubstitution.ReplaceSymbols 
       char OffenceSubsitutionSymbol {get;set;}
       // this will actually apply the filter to a given content 
       string ApplyOffenceFilter(string contentToCensor); 

    Then you could implement this interface for all the controls you want filtering. This could be ForumList, SingleForum, SingleThread, or Forums.

    A nice place to filter the content would be Render. First, render the parent control to a string, pass the string to the filter and finally render the censored text.

    Another thing you could try to is to handle the Executing event of the necessary content manager. This event is being called each time you or someone else create a content/comment item. Here's an example for the Blogs module:
    global.asax
        void Application_Start(object sender, EventArgs e)  
        { 
            // Code that runs on application startup 
             
            //subscribe for the Executing event 
            Telerik.Cms.Engine.ContentManager.Executing += new EventHandler<Telerik.ExecutingEventArgs>(ContentManager_Executing); 
        } 
     
        void ContentManager_Executing(object sender, Telerik.ExecutingEventArgs e) 
        { 
            //check if the user is creating comment 
            if (e.CommandName.Equals("CreateComment")) 
            { 
                //take the comment if there is such.. 
                Telerik.Cms.Engine.IComment comment = e.CommandArguments as Telerik.Cms.Engine.IComment; 
                if (comment != null
                { 
                    //initilaze our filter 
                    string[] badwords = { """""" }; 
                    string filtered = comment.Text; 
                    foreach (string badword in badwords) 
                    { 
                        filtered.Replace(badword, "beeep"); 
                    } 
                    //save the filtered text to the Comment. 
                    comment.Text = filtered; 
                } 
            } 
        } 

    There are some comments in the code that will help you.

    Hope this helps.

    Sincerely yours,
    Dido
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Check out the tips for optimizing your support resource searches.
  3. JAllen
    JAllen avatar
    34 posts
    Registered:
    23 Dec 2010
    17 Jun 2011
    Link to this post
    Hi guys,
    We're looking to implement something similar, but can you confirm if this affects all the modules or just specific ones?  Ie, would we be able to limit this to just the blog/news comments?

    Thanks in advance,
  4. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    25 Nov 2016
    17 Jun 2011
    Link to this post
    Hello JAllen,

    This will affect all content based modules where comments are enabled.

    Kind regards,
    Ivan Dimitrov
    the Telerik team
    Do you want to have your say in the Sitefinity development roadmap? Do you want to know when a feature you requested is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
Register for webinar
4 posts, 0 answered