예제 #1
0
    /// <summary>
    /// Builds complete where condition to filter.
    /// </summary>
    private string BuildWhereCondition()
    {
        string where = null;

        // Create WHERE condition with 'Expression'
        string txt = txtExpression.Text.Trim().Replace("'", "''");

        if (!string.IsNullOrEmpty(txt))
        {
            where = "(WordExpression LIKE N'%" + txt + "%')";
        }

        // Create WHERE condition with 'Action'
        int action = ValidationHelper.GetInteger(ucBadWordAction.Value, -1);

        if (action != -1)
        {
            if (!String.IsNullOrEmpty(where))
            {
                where += " AND ";
            }

            // Select also bad words that ihnerit action from settings
            if (action == (int)BadWordsHelper.BadWordsAction(CMSContext.CurrentSiteName))
            {
                where += "(WordAction = " + action + " OR WordAction IS NULL)";
            }
            else
            {
                where += "(WordAction = " + action + ")";
            }
        }
        return(where);
    }
    /// <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);
                }
            }
        }
    }
예제 #3
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()));
    }