|
||
|
API examples for newer versions Please visit the latest API Examples documentation to view API examples for newer versions of Kentico. |
The following example checks the declared custom string for presence of a single bad word.
private bool CheckSingleBadWord() { // Prepare parameters for selection of the checked bad word string where = "[WordExpression] = 'testbadword' ";
// Get the data DataSet words = BadWordInfoProvider.GetBadWords(where, null);
if (!DataHelper.DataSourceIsEmpty(words)) { // Get DataRow with bad word DataRow wordDr = words.Tables[0].Rows[0];
// Get BadWordInfo object BadWordInfo badWord = new BadWordInfo(wordDr);
// String to be checked for presence of the bad word string text = "This is a string containing the sample testbadword, which can be created by the first code example on this page.";
// 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.CheckBadWord(badWord, null, null, ref text, foundWords);
if (foundWords.Count != 0) { 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; }
return true; }
apiCheckSingleBadWord.ErrorMessage = "Bad word 'testbadword' is not present in the checked string."; return false; }
return false; } |
The following example checks the declared custom string for presence of a all defined bad words.
private bool CheckAllBadWords() { // String to be checked for presence of bad words string text = "This is a string containing the sample testbadword, which can be created by the first code example on this page. It also contains the word asshole, which is one of the default bad words defined in the system.";
// 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(null, null, ref text, foundWords);
if (foundWords.Count != 0) { 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; }
return true; }
return false; } |