public string Process(string value, Type type, FilterObjectTypes filterObjectType, Guid objectId, Guid userId) { string processedValue = value; if (!string.IsNullOrEmpty(processedValue)) { if ((action & BadWordFilterActions.Inform) == BadWordFilterActions.Inform) { if (regex.IsMatch(value)) { BadWordHelper.InformAdmin(action, value, word, isExactMatch, type, filterObjectType, objectId, userId); } } if ((action & BadWordFilterActions.Censor) == BadWordFilterActions.Censor) { if (regex.IsMatch(value)) { processedValue = regex.Replace(value, replacementPattern); } } if ((action & BadWordFilterActions.Lock) == BadWordFilterActions.Lock) { if (regex.IsMatch(value)) { BadWordHelper.LockUser(userId); } } } return(processedValue); }
internal static string FilterStringBadWords(string value, FilterObjectTypes filterObjectTypes, Guid objectId, Guid userId) { InitFilterBadWords(); Type type = null; Business.DataObject dataObject = Business.DataObject.Load <Business.DataObject>(objectId); // TODO: Make comment a dataobject and we don't need such hacks try { type = Type.GetType(string.Format("_4screen.CSB.DataAccess.Business.DataObject{0}", dataObject.ObjectType)); } catch { } // Apply the filters foreach (BadWordFilter badWordFilter in badWordFilters) { value = badWordFilter.Process(value, type, filterObjectTypes, objectId, userId); } return(value); }
public string Process(string value, Type type, FilterObjectTypes filterObjectType, Guid objectId, Guid userId) { this.objectId = objectId; string processedValue = value; value = "<DUMMY_TAG>" + value + "</DUMMY_TAG>"; if (!AdWordHelper.CreditsLeft(campaignId, action)) { return(processedValue); } switch (action) { case AdWordFilterActions.Link: if (regex.IsMatch(value)) { linkCounter = 0; processedValue = regex.Replace(value, linkMatchEvaluator); processedValue = Regex.Replace(processedValue, "</{0,1}DUMMY_TAG>", "", RegexOptions.IgnoreCase); AdWordHelper.AddToCampaignObjects(campaignId, objectId, word, linkCounter); } break; case AdWordFilterActions.Popup: if (regex.IsMatch(value)) { linkCounter = 0; processedValue = regex.Replace(value, popupMatchEvaluator); processedValue = Regex.Replace(processedValue, "</{0,1}DUMMY_TAG>", "", RegexOptions.IgnoreCase); AdWordHelper.AddToCampaignObjects(campaignId, objectId, word, linkCounter); } break; } return(processedValue); }
internal static void InformAdmin(BadWordFilterActions action, string value, string word, bool isExactMatch, Type type, FilterObjectTypes filterObjectType, Guid objectId, Guid userId) { try { string markedValue = Regex.Replace(value, @"(\w*" + word + @"\w*)(?=[^>]*?<)", "<u><font color=\"#AA0000\">$1</font></u>", RegexOptions.IgnoreCase); string exactValue = isExactMatch ? "Ja" : "Nein"; string userLink = FilterEngine.GetFilterEngineConfig().ObjectLinks["User"] + userId.ToString(); string objectLink = ""; switch (filterObjectType) { case FilterObjectTypes.DataObject: if (FilterEngine.GetFilterEngineConfig().ObjectLinks.ContainsKey(type.ToString())) { objectLink = FilterEngine.GetFilterEngineConfig().ObjectLinks[type.ToString()] + objectId.ToString(); } break; case FilterObjectTypes.Comment: if (FilterEngine.GetFilterEngineConfig().ObjectLinks.ContainsKey(type.ToString())) { objectLink = FilterEngine.GetFilterEngineConfig().ObjectLinks[type.ToString()] + objectId.ToString(); } break; case FilterObjectTypes.Profile: objectLink = FilterEngine.GetFilterEngineConfig().ObjectLinks["Profile"] + objectId.ToString(); break; } SmtpSection smtpSection = (SmtpSection)ConfigurationManager.GetSection("system.net/mailSettings/smtp"); MailMessage mailMessage = new MailMessage(); mailMessage.From = new MailAddress(smtpSection.From); foreach (KeyValuePair <string, string> adminEmail in FilterEngine.GetFilterEngineConfig().AdminEmailList) { mailMessage.To.Add(new MailAddress(adminEmail.Key, adminEmail.Value)); } mailMessage.Subject = "Bad Word Filter"; StringBuilder bodyString = new StringBuilder(1000); bodyString.Append("<table border=0>"); bodyString.Append(" <tr>"); bodyString.Append(" <td>Aktion(en):</td><td>" + GetActionsString(action) + "</td>"); bodyString.Append(" </tr><tr>"); bodyString.Append(" <td>Wort:</td><td>" + word + "<br/>"); bodyString.Append(" </tr><tr>"); bodyString.Append(" <td>Genau:</td><td>" + exactValue + "<br/>"); bodyString.Append(" </tr><tr>"); bodyString.Append(" <td valign=\"top\">Text:</td><td>" + markedValue + "<br/>"); bodyString.Append(" </tr><tr>"); bodyString.Append(" <td>Typ:</td><td>" + filterObjectType + "<br/>"); bodyString.Append(" </tr><tr>"); bodyString.Append(" <td>Object:</td><td><a href=\"" + objectLink + "\">" + objectId + "</a><br/>"); bodyString.Append(" </tr><tr>"); bodyString.Append(" <td>User:</td><td><a href=\"" + userLink + "\">" + userId + "</a><br/>"); bodyString.Append(" </tr>"); bodyString.Append("</table>"); mailMessage.Body = bodyString.ToString(); mailMessage.IsBodyHtml = true; SmtpClient smtpClient = new SmtpClient(); smtpClient.Send(mailMessage); } catch (Exception e) { new Exception("Error while sending bad word info mail", e); } }