Performing bad word checks

  Previous topic Next topic JavaScript is required for the print function Mail us feedback on this topic! Mail us feedback on this topic!  

The first sample code on this page illustrates how a bad words check can be performed to a message sent via the Messaging module.

 

[C#]

 

using CMS.SiteProvider;

using CMS.CMSHelper;

using CMS.Messaging;

 

...

 

        // Get a message object by its ID

        MessageInfo message = MessageInfoProvider.GetMessageInfo(1);

 

        // Set columns for bad words check

        string columns = "MessageSubject;MessageBody";

 

        // Check if the message contains any bad word, perform appropriate bad word action 

        // and return eventual error text

        string errorText = BadWordsHelper.CheckBadWords(message, columns, CMSContext.CurrentUser.UserID);

 

        // Save message object

        MessageInfoProvider.SetMessageInfo(message);

 

The second code example shows how a bad words check can be performed to a custom string.

 

[C#]

 

using System.Collections;

using CMS.SiteProvider;

using CMS.CMSHelper;

 

...

 

        // Check if the current user can use bad words

        if (!BadWordInfoProvider.CanUseBadWords(CMSContext.CurrentUser, CMSContext.CurrentSiteName))

        {

            string cultureCode = "en-us";

            string text = "This is a string containing two bad words, namely asshole and shit.";

 

            // Hashtable that will contain found bad words

            Hashtable foundWords = new Hashtable();

 

          // Modify the string according to found bad words and return which action should be performed

          BadWordActionEnum action = BadWordInfoProvider.CheckAllBadWords(cultureCode, CMSContext.CurrentSiteName, ref text, foundWords);

 

            switch (action)

            {

                case BadWordActionEnum.Deny:

                    // Some additional actions performed here ...

                    break;

 

                case BadWordActionEnum.RequestModeration:

                    // Some additional actions performed here ...

                    break;

 

                case BadWordActionEnum.Remove:

                    // Some additional actions performed here ...

                    break;

 

                case BadWordActionEnum.Replace:

                    // Some additional actions performed here ...

                    break;

 

                case BadWordActionEnum.ReportAbuse:

                    // Some additional actions performed here ...

                    break;

 

                case BadWordActionEnum.None:

                    // Some additional actions performed here ...

                    break;

            }

        }

 

Page url: http://devnet.kentico.com/docs/5_5r2/devguide/index.html?api_performing_bad_word_checks.htm