Exemple #1
0
    /// <summary>
    /// Sets data to database.
    /// </summary>
    protected void btnOK_Click(object sender, EventArgs e)
    {
        string errorMessage = new Validator().NotEmpty(txtWordExpression.Text, GetString("general.requiresvalue")).Result;

        if (errorMessage == string.Empty)
        {
            if (badWordObj == null)
            {
                badWordObj = new BadWordInfo();
            }

            // Set edited object
            EditedObject = badWordObj;

            // If bad word doesn't already exist, create new one
            if (!(((badWordId <= 0) || WordExpressionHasChanged()) && BadWordInfoProvider.BadWordExists(txtWordExpression.Text.Trim())))
            {
                badWordObj.WordExpression = txtWordExpression.Text.Trim();
                BadWordActionEnum action =
                    (BadWordActionEnum)Convert.ToInt32(SelectBadWordActionControl.Value.ToString().Trim());
                badWordObj.WordAction              = !chkInheritAction.Checked ? action : 0;
                badWordObj.WordReplacement         = (!chkInheritReplacement.Checked && (action == BadWordActionEnum.Replace)) ? txtWordReplacement.Text : null;
                badWordObj.WordLastModified        = DateTime.Now;
                badWordObj.WordIsRegularExpression = chkIsRegular.Checked;
                badWordObj.WordMatchWholeWord      = chkMatchWholeWord.Checked;

                if (badWordId <= 0)
                {
                    badWordObj.WordIsGlobal = true;
                }

                BadWordInfoProvider.SetBadWordInfo(badWordObj);

                if (badWordId <= 0)
                {
                    string redirectTo = badWordId <= 0 ? UIContextHelper.GetElementUrl("CMS.Badwords", "Administration.BadWords.Edit") : UIContextHelper.GetElementUrl("CMS.Badwords", "Administration.BadWords.Edit.General");
                    redirectTo = URLHelper.AddParameterToUrl(redirectTo, "objectid", badWordObj.WordID.ToString());
                    redirectTo = URLHelper.AddParameterToUrl(redirectTo, "saved", "1");
                    URLHelper.Redirect(redirectTo);
                }
                else
                {
                    ScriptHelper.RefreshTabHeader(Page, txtWordExpression.Text.Trim());
                    ShowChangesSaved();
                }
            }
            else
            {
                ShowError(GetString("badwords_edit.badwordexists"));
            }
        }
        else
        {
            ShowError(errorMessage);
        }
    }
    /// <summary>
    /// Sets data to database.
    /// </summary>
    protected void btnOK_Click(object sender, EventArgs e)
    {
        string errorMessage = new Validator().NotEmpty(txtWordExpression.Text, GetString("general.requiresvalue")).Result;

        if (errorMessage == string.Empty)
        {
            if (badWordObj == null)
            {
                badWordObj = new BadWordInfo();
            }

            // Set edited object
            EditedObject = badWordObj;

            // If bad word doesn't already exist, create new one
            if (!BadWordInfoProvider.BadWordExists(txtWordExpression.Text.Trim()) || (badWordId != 0))
            {
                badWordObj.WordExpression = txtWordExpression.Text.Trim();
                BadWordActionEnum action =
                    (BadWordActionEnum)Convert.ToInt32(SelectBadWordActionControl.Value.ToString().Trim());
                badWordObj.WordAction              = !chkInheritAction.Checked ? action : 0;
                badWordObj.WordReplacement         = (!chkInheritReplacement.Checked && (action == BadWordActionEnum.Replace)) ? txtWordReplacement.Text : null;
                badWordObj.WordLastModified        = DateTime.Now;
                badWordObj.WordIsRegularExpression = chkIsRegular.Checked;
                badWordObj.WordMatchWholeWord      = chkMatchWholeWord.Checked;

                if (badWordId == 0)
                {
                    badWordObj.WordIsGlobal = true;
                }

                BadWordInfoProvider.SetBadWordInfo(badWordObj);
                string redirectTo = badWordId == 0 ? "BadWords_Edit.aspx" : "BadWords_Edit_General.aspx";

                URLHelper.Redirect(redirectTo + "?badwordid=" + Convert.ToString(badWordObj.WordID) + "&saved=1");
            }
            else
            {
                lblError.Visible = true;
                lblError.Text    = GetString("badwords_edit.badwordexists");
            }
        }
        else
        {
            lblError.Visible = true;
            lblError.Text    = errorMessage;
        }
    }
Exemple #3
0
    /// <summary>
    /// Checks the declared custom string for presence of any defined bad word.
    /// </summary>
    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);
    }
    /// <summary>
    /// Sets selected action.
    /// </summary>
    protected void SetSelectedAction(BadWordInfo badWordObj)
    {
        // Find postback invoker
        string  invokerName   = Page.Request.Params.Get("__EVENTTARGET");
        Control invokeControl = !string.IsNullOrEmpty(invokerName) ? Page.FindControl(invokerName) : null;

        // Ensure right postback actions
        if ((invokeControl == chkInheritAction) || !RequestHelper.IsPostBack())
        {
            // Deselect all items
            SelectBadWordActionControl.ReloadData();

            // Check inheritance of settings
            if (chkInheritAction != null)
            {
                // Get action
                if ((!chkInheritAction.Checked) && (badWordObj != null))
                {
                    BadWordActionEnum action = badWordObj.WordAction;
                    SelectBadWordActionControl.Value = ((int)action).ToString();
                }
                else
                {
                    SelectBadWordActionControl.Value = ((int)BadWordsHelper.BadWordsAction(CMSContext.CurrentSiteName)).ToString();
                }
            }
        }

        // Get replacement
        if ((invokeControl == chkInheritReplacement) || !RequestHelper.IsPostBack())
        {
            if (chkInheritReplacement != null)
            {
                if (!chkInheritReplacement.Checked && (badWordObj != null))
                {
                    txtWordReplacement.Text = badWordObj.WordReplacement;
                }
                else
                {
                    txtWordReplacement.Text = BadWordsHelper.BadWordsReplacement(CMSContext.CurrentSiteName);
                }
            }
        }
    }
Exemple #5
0
    private object OnExternalDataBound(object sender, string sourceName, object parameter)
    {
        bool inherited             = false;
        BadWordActionEnum action   = BadWordActionEnum.None;
        string            siteName = SiteContext.CurrentSiteName;

        switch (sourceName.ToLowerCSafe())
        {
        case "wordaction":
            if (!string.IsNullOrEmpty(parameter.ToString()))
            {
                action = (BadWordActionEnum)Enum.Parse(typeof(BadWordActionEnum), parameter.ToString());
            }
            else
            {
                action    = BadWordsHelper.BadWordsAction(siteName);
                inherited = true;
            }

            // Ensure displaying text labels instead of numbers
            switch (action)
            {
            case BadWordActionEnum.Remove:
                parameter = Control.GetString("general.remove");
                break;

            case BadWordActionEnum.Replace:
                parameter = Control.GetString("general.replace");
                break;

            case BadWordActionEnum.ReportAbuse:
                parameter = Control.GetString("BadWords_Edit.ReportAbuse");
                break;

            case BadWordActionEnum.RequestModeration:
                parameter = Control.GetString("BadWords_Edit.RequestModeration");
                break;

            case BadWordActionEnum.Deny:
                parameter = Control.GetString("Security.Deny");
                break;
            }
            if (inherited)
            {
                parameter += " " + Control.GetString("BadWords_Edit.Inherited");
            }
            break;

        case "wordreplacement":

            // Get DataRowView
            DataRowView drv = parameter as DataRowView;
            if (drv != null)
            {
                string replacement = drv.Row["WordReplacement"].ToString();
                string toReturn    = replacement;

                // Set 'inherited' only if WordReplacement is empty
                if (string.IsNullOrEmpty(replacement))
                {
                    // Get action from cell
                    string actionText = drv.Row["WordAction"].ToString();

                    // Get action enum value
                    if (string.IsNullOrEmpty(actionText))
                    {
                        action = BadWordsHelper.BadWordsAction(siteName);
                    }
                    else
                    {
                        action = (BadWordActionEnum)ValidationHelper.GetInteger(actionText, 0);
                    }

                    // Set replacement only if action is replace
                    if (action == BadWordActionEnum.Replace)
                    {
                        // Get inherited replacement from settings
                        if (string.IsNullOrEmpty(toReturn))
                        {
                            string inheritedSetting = SettingsKeyInfoProvider.GetValue(siteName + ".CMSBadWordsReplacement");
                            toReturn += inheritedSetting + " " + Control.GetString("BadWords_Edit.Inherited");
                        }
                    }
                    else
                    {
                        toReturn = string.Empty;
                    }
                }
                return(HTMLHelper.HTMLEncode(toReturn));
            }
            return(null);

        case "global":
            bool global = ValidationHelper.GetBoolean(parameter, false);
            return(UniGridFunctions.ColoredSpanYesNo(global));
        }
        return(HTMLHelper.HTMLEncode(parameter.ToString()));
    }
Exemple #6
0
    /// <summary>
    /// Checks the declared custom string for presence of the 'testbadword' bad word created by the first code example on this page.
    /// Expects the CreateBadWord method to be run first.
    /// </summary>
    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, 0);

            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);
    }