Exemplo n.º 1
0
    protected override void OnLoad(EventArgs e)
    {
        base.OnLoad(e);

        // Initialize resource strings
        rqfWordExpression.ErrorMessage = GetString("general.requiresvalue");

        if (badWordId > 0)
        {
            badWordObj = BadWordInfoProvider.GetBadWordInfo(badWordId);

            // Set edited object
            EditedObject = badWordObj;

            if (badWordObj != null)
            {
                // Fill editing form
                if (!RequestHelper.IsPostBack())
                {
                    LoadData(badWordObj);

                    // Show that the badWord was created or updated successfully
                    if (QueryHelper.GetString("saved", string.Empty) == "1")
                    {
                        ShowChangesSaved();
                    }
                }
                else
                {
                    // Set selected action
                    SetSelectedAction(badWordObj);
                }
            }
        }
        else
        {
            PageTitle.TitleText = GetString("BadWords_Edit.NewItemCaption");
            // Initialize breadcrumbs
            List <BreadcrumbItem> breadCrumbItems = new List <BreadcrumbItem>();
            breadCrumbItems.Add(new BreadcrumbItem
            {
                Text        = GetString("badwords_edit.itemlistlink"),
                RedirectUrl = "~/CMSModules/BadWords/BadWords_List.aspx",
                Target      = "_self",
            });
            breadCrumbItems.Add(new BreadcrumbItem
            {
                Text = GetString("badwords_list.newitemcaption"),
            });
            PageBreadcrumbs.Items = breadCrumbItems;
            SetSelectedAction(null);
        }

        // Enable / disable actions (depending on inheritance)
        SelectBadWordActionControl.Enabled = !chkInheritAction.Checked;
        txtWordReplacement.Enabled         = !chkInheritReplacement.Checked;

        // Show / hide replacement textbox depending on action
        plcReplacement.Visible = ((BadWordActionEnum)Enum.Parse(typeof(BadWordActionEnum), SelectBadWordActionControl.Value.ToString())) == BadWordActionEnum.Replace;
    }
Exemplo n.º 2
0
    /// <summary>
    /// Gets and updates the first single bad word matching the condition. Called when the "Get and update bad word" button is pressed.
    /// Expects the CreateBadWord method to be run first.
    /// </summary>
    private bool GetAndUpdateBadWord()
    {
        // Prepare the parameters
        string where = "[WordExpression] = 'testbadword'";

        // Get the data
        DataSet words = BadWordInfoProvider.GetBadWords(where, null);

        if (!DataHelper.DataSourceIsEmpty(words))
        {
            // Get the bad word's data row
            DataRow wordDr = words.Tables[0].Rows[0];

            // Create object from DataRow
            BadWordInfo modifyWord = new BadWordInfo(wordDr);

            // Update the properties
            modifyWord.WordAction      = BadWordActionEnum.Replace;
            modifyWord.WordReplacement = "testpoliteword";

            // Save the changes
            BadWordInfoProvider.SetBadWordInfo(modifyWord);

            return(true);
        }

        return(false);
    }
Exemplo n.º 3
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 (!(((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>
    /// Load data of editing badWord.
    /// </summary>
    /// <param name="badWordObj">BadWord object</param>
    protected void LoadData(BadWordInfo badWordObj)
    {
        // Check inheritance
        chkInheritAction.Checked      = (badWordObj.WordAction == 0);
        chkInheritReplacement.Checked = (badWordObj.WordReplacement == null);

        // Set selected action
        SetSelectedAction(badWordObj);

        // Load rest of values
        txtWordExpression.Text    = badWordObj.WordExpression;
        chkIsRegular.Checked      = badWordObj.WordIsRegularExpression;
        chkMatchWholeWord.Checked = badWordObj.WordMatchWholeWord;
    }
    /// <summary>
    /// Load data of editing badWord.
    /// </summary>
    /// <param name="badWordObj">BadWord object</param>
    protected void LoadData(BadWordInfo badWordObj)
    {
        // Check inheritance
        chkInheritAction.Checked = (badWordObj.WordAction == 0);
        chkInheritReplacement.Checked = (badWordObj.WordReplacement == null);

        // Set selected action
        SetSelectedAction(badWordObj);

        // Load rest of values
        txtWordExpression.Text = badWordObj.WordExpression;
        chkIsRegular.Checked = badWordObj.WordIsRegularExpression;
        chkMatchWholeWord.Checked = badWordObj.WordMatchWholeWord;
    }
    /// <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;
        }
    }
Exemplo n.º 8
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 (!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;
        }
    }
Exemplo n.º 9
0
    /// <summary>
    /// Creates a "testbadword" bad word. Called when the "Create word" button is pressed.
    /// </summary>
    private bool CreateBadWord()
    {
        // Create new bad word object
        BadWordInfo newWord = new BadWordInfo();

        // Set the properties
        newWord.WordExpression          = "testbadword";
        newWord.WordAction              = BadWordActionEnum.ReportAbuse;
        newWord.WordIsGlobal            = true;
        newWord.WordIsRegularExpression = false;

        // Save the bad word
        BadWordInfoProvider.SetBadWordInfo(newWord);

        return(true);
    }
Exemplo n.º 10
0
    /// <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);
                }
            }
        }
    }
    protected void Page_Load(object sender, EventArgs e)
    {
        int  badWordId         = QueryHelper.GetInteger("badWordId", 0);
        bool badWordIsSelected = (badWordId != 0);

        // Initialize PageTitle breadcrumbs
        string[,] pageTitleTabs = new string[2, 3];
        pageTitleTabs[0, 0]     = GetString("badwords_edit.itemlistlink");
        pageTitleTabs[0, 1]     = "~/CMSModules/BadWords/BadWords_List.aspx";
        pageTitleTabs[0, 2]     = "_parent";
        string badWord = string.Empty;

        // Get bad word name
        if (!badWordIsSelected)
        {
            badWord = GetString("badwords_list.newitemcaption");
        }
        else
        {
            BadWordInfo badWordInfo = BadWordInfoProvider.GetBadWordInfo(badWordId);
            if (badWordInfo != null)
            {
                badWord = badWordInfo.WordExpression;
            }
        }
        pageTitleTabs[1, 0] = badWord;
        pageTitleTabs[1, 1] = string.Empty;
        pageTitleTabs[1, 2] = string.Empty;

        // Initialize masterpage properties
        CurrentMaster.Title.Breadcrumbs = pageTitleTabs;
        CurrentMaster.Title.TitleText   = !badWordIsSelected?GetString("BadWords_List.HeaderCaption") : GetString("BadWords_Edit.badwordproperties");

        CurrentMaster.Title.TitleImage    = GetImageUrl("Objects/Badwords_Word/object.png");
        CurrentMaster.Title.HelpTopicName = "general_badwords";
        CurrentMaster.Title.HelpName      = "helpTopic";

        if (!RequestHelper.IsPostBack())
        {
            InitalizeMenu();
        }
    }
    protected void Page_Load(object sender, EventArgs e)
    {
        // Get ID of bad word
        badWordId = QueryHelper.GetInteger("badwordid", 0);

        if (badWordId > 0)
        {
            radAll.CheckedChanged      += isGlobal_CheckedChanged;
            radSelected.CheckedChanged += isGlobal_CheckedChanged;
            badWordObj = BadWordInfoProvider.GetBadWordInfo(badWordId);
            // Set edited object
            EditedObject = badWordObj;

            if (badWordObj != null)
            {
                if (!RequestHelper.IsPostBack())
                {
                    // Initialize radiobuttons
                    radAll.Checked      = badWordObj.WordIsGlobal;
                    radSelected.Checked = !badWordObj.WordIsGlobal;
                }
            }

            // Show / hide selector
            SetSelectorVisibility();

            // Get the word cultures
            if (!RequestHelper.IsPostBack() || (radSelected == ControlsHelper.GetPostBackControl(Page)))
            {
                usWordCultures.Value = GetCurrentValues();
            }
        }

        // Initialize selector properties
        usWordCultures.OnSelectionChanged           += usWordCultures_OnSelectionChanged;
        usWordCultures.ButtonRemoveSelected.CssClass = "XLongButton";
        usWordCultures.ButtonAddItems.CssClass       = "XLongButton";
    }
    protected void Page_Load(object sender, EventArgs e)
    {
        // Get ID of bad word
        badWordId = QueryHelper.GetInteger("badwordid", 0);

        if (badWordId > 0)
        {
            radAll.CheckedChanged += isGlobal_CheckedChanged;
            radSelected.CheckedChanged += isGlobal_CheckedChanged;
            badWordObj = BadWordInfoProvider.GetBadWordInfo(badWordId);
            // Set edited object
            EditedObject = badWordObj;

            if (badWordObj != null)
            {
                if (!RequestHelper.IsPostBack())
                {
                    // Initialize radiobuttons
                    radAll.Checked = badWordObj.WordIsGlobal;
                    radSelected.Checked = !badWordObj.WordIsGlobal;
                }
            }

            // Show / hide selector
            SetSelectorVisibility();

            // Get the word cultures
            if (!RequestHelper.IsPostBack() || (radSelected == ControlsHelper.GetPostBackControl(Page)))
            {
                usWordCultures.Value = GetCurrentValues();
            }
        }

        // Initialize selector properties
        usWordCultures.OnSelectionChanged += usWordCultures_OnSelectionChanged;
        usWordCultures.ButtonRemoveSelected.CssClass = "XLongButton";
        usWordCultures.ButtonAddItems.CssClass = "XLongButton";
    }
Exemplo n.º 14
0
    /// <summary>
    /// Deletes all "testbadword" bad words. Called when the "Delete bad word(s)" button is pressed.
    /// Expects the CreateBadWord method to be run first.
    /// </summary>
    private bool DeleteBadWord()
    {
        // Prepare the parameters
        string where = "[WordExpression] = 'testbadword' ";

        // Get the data
        DataSet words = BadWordInfoProvider.GetBadWords(where, null);

        if (!DataHelper.DataSourceIsEmpty(words))
        {
            foreach (DataRow wordDr in words.Tables[0].Rows)
            {
                // Create object from DataRow
                BadWordInfo deleteWord = new BadWordInfo(wordDr);

                // Delete the bad word
                BadWordInfoProvider.DeleteBadWordInfo(deleteWord);
            }

            return(true);
        }

        return(false);
    }
Exemplo n.º 15
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;
    }
    protected override void OnLoad(EventArgs e)
    {
        base.OnLoad(e);

        // Initialize resource strings
        rqfWordExpression.ErrorMessage = GetString("general.requiresvalue");

        if (badWordId > 0)
        {
            badWordObj = BadWordInfoProvider.GetBadWordInfo(badWordId);
            // Set edited object
            EditedObject = badWordObj;

            if (badWordObj != null)
            {
                // Fill editing form
                if (!RequestHelper.IsPostBack())
                {
                    LoadData(badWordObj);

                    // Show that the badWord was created or updated successfully
                    if (QueryHelper.GetString("saved", string.Empty) == "1")
                    {
                        ShowChangesSaved();
                        // Refresh header
                        ScriptHelper.RegisterClientScriptBlock(this, GetType(), "refreshBadwordsHeader", ScriptHelper.GetScript("parent.frames['badwordsMenu'].location = 'BadWords_Edit_Header.aspx?badwordid=" + badWordObj.WordID + "';"));
                    }
                }
                else
                {
                    // Set selected action
                    SetSelectedAction(badWordObj);
                }
            }
        }
        else
        {
            CurrentMaster.Title.TitleText = GetString("BadWords_Edit.NewItemCaption");
            CurrentMaster.Title.TitleImage = GetImageUrl("Objects/Badwords_Word/new.png");
            CurrentMaster.Title.HelpTopicName = "general_badwords";
            CurrentMaster.Title.HelpName = "helpTopic";

            // Initialize breadcrumbs
            string[,] pageTitleTabs = new string[2,3];
            pageTitleTabs[0, 0] = GetString("badwords_edit.itemlistlink");
            pageTitleTabs[0, 1] = "~/CMSModules/BadWords/BadWords_List.aspx";
            pageTitleTabs[0, 2] = "_self";
            pageTitleTabs[1, 0] = GetString("badwords_list.newitemcaption");
            pageTitleTabs[1, 1] = "";
            pageTitleTabs[1, 2] = "";
            CurrentMaster.Title.Breadcrumbs = pageTitleTabs;
            SetSelectedAction(null);
        }

        // Enable / disable actions (depending on inheritance)
        SelectBadWordActionControl.Enabled = !chkInheritAction.Checked;
        txtWordReplacement.Enabled = !chkInheritReplacement.Checked;

        // Show / hide replacement textbox depending on action
        plcReplacement.Visible = ((BadWordActionEnum)Enum.Parse(typeof(BadWordActionEnum), SelectBadWordActionControl.Value.ToString())) == BadWordActionEnum.Replace;
    }
    protected override void OnLoad(EventArgs e)
    {
        base.OnLoad(e);

        // Initialize resource strings
        rqfWordExpression.ErrorMessage = GetString("general.requiresvalue");

        if (badWordId > 0)
        {
            badWordObj = BadWordInfoProvider.GetBadWordInfo(badWordId);

            // Set edited object
            EditedObject = badWordObj;

            if (badWordObj != null)
            {
                // Fill editing form
                if (!RequestHelper.IsPostBack())
                {
                    LoadData(badWordObj);

                    // Show that the badWord was created or updated successfully
                    if (QueryHelper.GetString("saved", string.Empty) == "1")
                    {
                        ShowChangesSaved();
                    }
                }
                else
                {
                    // Set selected action
                    SetSelectedAction(badWordObj);
                }
            }
        }
        else
        {
            PageTitle.TitleText = GetString("BadWords_Edit.NewItemCaption");
            // Initialize breadcrumbs
            List<BreadcrumbItem> breadCrumbItems = new List<BreadcrumbItem>();
            breadCrumbItems.Add(new BreadcrumbItem
            {
                Text = GetString("badwords_edit.itemlistlink"),
                RedirectUrl = "~/CMSModules/BadWords/BadWords_List.aspx",
                Target = "_self",
            });
            breadCrumbItems.Add(new BreadcrumbItem
            {
                Text = GetString("badwords_list.newitemcaption"),
            });
            PageBreadcrumbs.Items = breadCrumbItems;
            SetSelectedAction(null);
        }

        // Enable / disable actions (depending on inheritance)
        SelectBadWordActionControl.Enabled = !chkInheritAction.Checked;
        txtWordReplacement.Enabled = !chkInheritReplacement.Checked;

        // Show / hide replacement textbox depending on action
        plcReplacement.Visible = ((BadWordActionEnum)Enum.Parse(typeof(BadWordActionEnum), SelectBadWordActionControl.Value.ToString())) == BadWordActionEnum.Replace;
    }
    /// <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);
                }
            }
        }
    }
Exemplo n.º 19
0
    protected override void OnLoad(EventArgs e)
    {
        base.OnLoad(e);

        // Initialize resource strings
        rqfWordExpression.ErrorMessage = GetString("general.requiresvalue");

        if (badWordId > 0)
        {
            badWordObj = BadWordInfoProvider.GetBadWordInfo(badWordId);
            // Set edited object
            EditedObject = badWordObj;

            if (badWordObj != null)
            {
                // Fill editing form
                if (!RequestHelper.IsPostBack())
                {
                    LoadData(badWordObj);

                    // Show that the badWord was created or updated successfully
                    if (QueryHelper.GetString("saved", string.Empty) == "1")
                    {
                        lblInfo.Visible = true;
                        lblInfo.Text    = GetString("General.ChangesSaved");
                        // Refresh header
                        ScriptHelper.RegisterClientScriptBlock(this, GetType(), "refreshBadwordsHeader", ScriptHelper.GetScript("parent.frames['badwordsMenu'].location = 'BadWords_Edit_Header.aspx?badwordid=" + badWordObj.WordID + "';"));
                    }
                }
                else
                {
                    // Set selected action
                    SetSelectedAction(badWordObj);
                }
            }
        }
        else
        {
            CurrentMaster.Title.TitleText     = GetString("BadWords_Edit.NewItemCaption");
            CurrentMaster.Title.TitleImage    = GetImageUrl("Objects/Badwords_Word/new.png");
            CurrentMaster.Title.HelpTopicName = "general_badwords";
            CurrentMaster.Title.HelpName      = "helpTopic";

            // Initialize breadcrumbs
            string[,] pageTitleTabs         = new string[2, 3];
            pageTitleTabs[0, 0]             = GetString("badwords_edit.itemlistlink");
            pageTitleTabs[0, 1]             = "~/CMSModules/BadWords/BadWords_List.aspx";
            pageTitleTabs[0, 2]             = "_self";
            pageTitleTabs[1, 0]             = GetString("badwords_list.newitemcaption");
            pageTitleTabs[1, 1]             = "";
            pageTitleTabs[1, 2]             = "";
            CurrentMaster.Title.Breadcrumbs = pageTitleTabs;
            SetSelectedAction(null);
        }

        // Enable / disable actions (depending on inheritance)
        SelectBadWordActionControl.Enabled = !chkInheritAction.Checked;
        txtWordReplacement.Enabled         = !chkInheritReplacement.Checked;

        // Show / hide replacement textbox depending on action
        plcReplacement.Visible = ((BadWordActionEnum)Enum.Parse(typeof(BadWordActionEnum), SelectBadWordActionControl.Value.ToString())) == BadWordActionEnum.Replace;
    }
Exemplo n.º 20
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);
    }
Exemplo n.º 21
0
    /// <summary>
    /// Creates a "testbadword" bad word. Called when the "Create word" button is pressed.
    /// </summary>
    private bool CreateBadWord()
    {
        // Create new bad word object
        BadWordInfo newWord = new BadWordInfo();

        // Set the properties
        newWord.WordExpression = "testbadword";
        newWord.WordAction = BadWordActionEnum.ReportAbuse;
        newWord.WordIsGlobal = true;
        newWord.WordIsRegularExpression = false;

        // Save the bad word
        BadWordInfoProvider.SetBadWordInfo(newWord);

        return true;
    }
Exemplo n.º 22
0
    /// <summary>
    /// Gets and updates the first single bad word matching the condition. Called when the "Get and update bad word" button is pressed.
    /// Expects the CreateBadWord method to be run first.
    /// </summary>
    private bool GetAndUpdateBadWord()
    {
        // Prepare the parameters
        string where = "[WordExpression] = 'testbadword'";

        // Get the data
        DataSet words = BadWordInfoProvider.GetBadWords(where, null);

        if (!DataHelper.DataSourceIsEmpty(words))
        {
            // Get the bad word's data row
            DataRow wordDr = words.Tables[0].Rows[0];

            // Create object from DataRow
            BadWordInfo modifyWord = new BadWordInfo(wordDr);

            // Update the properties
            modifyWord.WordAction = BadWordActionEnum.Replace;
            modifyWord.WordReplacement = "testpoliteword";

            // Save the changes
            BadWordInfoProvider.SetBadWordInfo(modifyWord);

            return true;
        }

        return false;
    }
Exemplo n.º 23
0
    /// <summary>
    /// Deletes all "testbadword" bad words. Called when the "Delete bad word(s)" button is pressed.
    /// Expects the CreateBadWord method to be run first.
    /// </summary>
    private bool DeleteBadWord()
    {
        // Prepare the parameters
        string where = "[WordExpression] = 'testbadword' ";

        // Get the data
        DataSet words = BadWordInfoProvider.GetBadWords(where, null);

        if (!DataHelper.DataSourceIsEmpty(words))
        {
            foreach (DataRow wordDr in words.Tables[0].Rows)
            {
                // Create object from DataRow
                BadWordInfo deleteWord = new BadWordInfo(wordDr);

                // Delete the bad word
                BadWordInfoProvider.DeleteBadWordInfo(deleteWord);
            }

            return true;
        }

        return false;
    }