internal static void FilterObjectBadWords(Business.DataObject item) { InitFilterBadWords(); // Check if the current object has to be filtered for bad words if (badWordFilterObjects.ContainsKey(item.GetType().ToString())) { FilterObjectProperties(item, badWordFilters, badWordFilterObjects); } }
internal static bool FilterObjectAdWordsWithoutInit(Business.DataObject item) { userWantsFiltering = AdWordHelper.UserWantsAds(item.UserID.Value); bool hasItemChanged = false; // Check if the current object has to be filtered for ad words if (adWordFilterObjects.ContainsKey(item.GetType().ToString())) { AdWordHelper.ResetCampaignObjects(item.ObjectID.Value); hasItemChanged = FilterObjectProperties(item, adWordFilters, adWordFilterObjects); } return(hasItemChanged); }
private void FilterObjectAdWords(UserDataContext udc, string typeName, int objectType, Guid objectId) { MethodInfo loadMethod = typeof(Business.DataObject).GetMethod("Load", new Type[] { typeof(Guid), typeof(ObjectShowState), typeof(bool) }); Type type; if (!string.IsNullOrEmpty(Helper.GetObjectType(objectType).Assembly)) { Assembly assembly = Assembly.Load(Helper.GetObjectType(objectType).Assembly); type = assembly.GetType(typeName); } else { type = Type.GetType(typeName); } MethodInfo genericLoadMethod = loadMethod.MakeGenericMethod(type); Business.DataObject dataObject = (Business.DataObject)genericLoadMethod.Invoke(null, new object[] { objectId, null, true }); if (FilterEngine.FilterObjectAdWordsWithoutInit(dataObject)) { dataObject.UpdateBackground(); } }
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); }
/// <summary> /// Filters a DataObject for bad words and ad words (configured in FilterEngine.config) /// </summary> /// <param name="item">The DataObject, that should be filtered</param> public static void FilterObject(Business.DataObject item) { Data.FilterEngine.FilterObject(item); }
private static bool FilterObjectProperties(Business.DataObject item, List <IWordFilter> wordFilters, Dictionary <string, FilterObject> wordFilterObjects) { bool hasItemChanged = false; Type filterObjectType = item.GetType(); FilterObject filterObject = wordFilterObjects[item.GetType().ToString()]; foreach (FilterObjectProperty filterObjectProperty in filterObject.Properties) { // Get value for filtering PropertyInfo filterObjectPropertyName = filterObjectType.GetProperty(filterObjectProperty.Name, typeof(string)); string propertyValue = (string)filterObjectPropertyName.GetValue(item, null); // Apply the filters string processedPropertyValue = propertyValue; if (userWantsFiltering) // Don't apply filter, if the user disabled them { foreach (IWordFilter wordFilter in wordFilters) { processedPropertyValue = wordFilter.Process(processedPropertyValue, item.GetType(), FilterObjectTypes.DataObject, item.ObjectID.Value, item.UserID.Value); } } // If the filter had some matches, store filtered value if (processedPropertyValue != propertyValue && userWantsFiltering) // Don't store value, if the user disabled the filter { hasItemChanged = true; if (filterObjectProperty.LinkedName != "") { PropertyInfo filterObjectPropertyLinkedName = filterObjectType.GetProperty(filterObjectProperty.LinkedName, typeof(string)); filterObjectPropertyLinkedName.SetValue(item, processedPropertyValue, null); } else { filterObjectPropertyName.SetValue(item, processedPropertyValue, null); } } else // If the filter didn't had any matches { if (filterObjectProperty.LinkedName != "") { PropertyInfo filterObjectPropertyLinkedName = filterObjectType.GetProperty(filterObjectProperty.LinkedName, typeof(string)); string propertyLinkedValue = (string)filterObjectPropertyLinkedName.GetValue(item, null); // If the linked property has been set before, clear it if (propertyLinkedValue != processedPropertyValue) { hasItemChanged = true; filterObjectPropertyLinkedName.SetValue(item, "", null); } else if (propertyLinkedValue != processedPropertyValue && !userWantsFiltering) // Reset value, if the user disabled the filter { hasItemChanged = true; filterObjectPropertyLinkedName.SetValue(item, "", null); } } } } return(hasItemChanged); }
internal static void FilterObject(Business.DataObject item) { FilterObjectBadWords(item); FilterObjectAdWords(item); }