Beispiel #1
0
    private void InitSettings()
    {
        // Create extensionSettings with Type Name
        ExtensionSettings settings = new ExtensionSettings(this.GetType().Name);

        // Define settings as Scalar
        settings.IsScalar = true;
        settings.AddParameter("ExcludeAuthenticatedViews", "Exclude Authenticated Views", 5, false, false, ParameterType.Boolean);
        settings.AddParameter("ExcludeViewsFromIPs", "<a href=\"https://www.google.com/support/googleanalytics/bin/answer.py?answer=55572\" target=\"_blank\">Execlude Views From IPs</a>", 255, false, false, ParameterType.String);

        // Add default values
        settings.AddValues(new string[] { "True", "" });

        // Build Help text
        settings.Help = "<p>Check the <strong>Exclude Authenticated Views</strong> checkbox if you wish " +
                        "<strong>exclude the authenticated users</strong> from accumulating post view count.<br/>" +
                        "Set <strong>Execlude Views From IPs(regex)</strong> field if you wish to execlude range of IP addresses " +
                        "from accumulating post view count. This is Regular Expression field.</p>" +
                        "You can use <a href=\"https://www.google.com/support/googleanalytics/bin/answer.py?answer=55572\" target=\"_blank\">this tool</a> " +
                        "to generate your range of IPs ";

        // Import Settings into BlogEngine
        ExtensionManager.ImportSettings(settings);

        // Retrieve settings from BlogEngine into local static field to be used later
        _settings = ExtensionManager.GetSettings(this.GetType().Name);
    }
    public PostViewCounter()
    {
        Post.Serving += new EventHandler <ServingEventArgs>(OnPostServing);


        ExtensionSettings settings = new ExtensionSettings("PostViewCounter");

        settings.AddParameter(
            "MaxHitRecordCount",
            "最多保留筆數:");
        settings.AddParameter(
            "HitRecordTTL",
            "最長保留天數:");

        settings.AddValues(new string[] { "500", "90" });

        //settings.ShowAdd = false;
        //settings.ShowDelete = false;
        //settings.ShowEdit = true;
        settings.IsScalar = true;
        settings.Help     = "設定 counter hit records 保留筆數及時間。只有在筆數限制內且沒有超過保留期限的記錄才會被留下來。";

        ExtensionManager.ImportSettings(settings);

        _settings = ExtensionManager.GetSettings("PostViewCounter");
    }
    public IEnumerable<SelectOption> Get()
    {
        var feeds = new List<SelectOption>();
        var feedSets = ExtensionManager.GetSettings(_metaExtension, _galleryFeeds);
        var feedService = "http://dnbe.net/v01/nuget";

        if (!string.IsNullOrEmpty(BlogSettings.Instance.GalleryFeedUrl))
            feedService = BlogSettings.Instance.GalleryFeedUrl;

        if (feedSets == null)
        {
            var settings = new ExtensionSettings(_galleryFeeds);
            settings.AddParameter("OptionName", "Title", 150, true, true);
            settings.AddParameter("OptionValue");

            settings.AddValues(new[] { "dnbe.net", feedService });

            feedSets = ExtensionManager.InitSettings(_metaExtension, settings);
            ExtensionManager.SaveSettings(_metaExtension, feedSets);
        }

        var table = feedSets.GetDataTable();
        foreach (DataRow row in table.Rows)
        {
            feeds.Add(new SelectOption { OptionName = row[0].ToString(), OptionValue = row[1].ToString() });
        }

        return feeds;
    }
    public IEnumerable <SelectOption> Get()
    {
        var feeds       = new List <SelectOption>();
        var feedSets    = ExtensionManager.GetSettings(_metaExtension, _galleryFeeds);
        var feedService = "http://dnbe.net/v01/nuget";

        if (!string.IsNullOrEmpty(BlogSettings.Instance.GalleryFeedUrl))
        {
            feedService = BlogSettings.Instance.GalleryFeedUrl;
        }

        if (feedSets == null)
        {
            var settings = new ExtensionSettings(_galleryFeeds);
            settings.AddParameter("OptionName", "Title", 150, true, true);
            settings.AddParameter("OptionValue");

            settings.AddValues(new[] { "dnbe.net", feedService });

            feedSets = ExtensionManager.InitSettings(_metaExtension, settings);
            ExtensionManager.SaveSettings(_metaExtension, feedSets);
        }

        var table = feedSets.GetDataTable();

        foreach (DataRow row in table.Rows)
        {
            feeds.Add(new SelectOption {
                OptionName = row[0].ToString(), OptionValue = row[1].ToString()
            });
        }

        return(feeds);
    }
Beispiel #5
0
    protected void BlockOrAllow(string action)
    {
        ExtensionSettings _filters = ExtensionManager.GetSettings("MetaExtension", "BeCommentFilters");

        if (_filters != null)
        {
            string   id = Guid.NewGuid().ToString();
            string[] f  = new string[] { id,
                                         action,
                                         "IP",
                                         "Equals",
                                         CurrentComment.IP };

            _filters.AddValues(f);
            ExtensionManager.SaveSettings("MetaExtension", _filters);
        }

        if (action == "Block")
        {
            CurrentComment.IsApproved  = false;
            CurrentComment.ModeratedBy = HttpContext.Current.User.Identity.Name;
        }

        Reload();
    }
Beispiel #6
0
    static BBCode()
    {
        Comment.Serving += new EventHandler<ServingEventArgs>(Post_CommentServing);

        // create settings object. You need to pass exactly your
        // extension class name (case sencitive)
        ExtensionSettings settings = new ExtensionSettings("BBCode");

        //-----------------------------------------------------
        // 1. Simple
        //-----------------------------------------------------
        //settings.AddParameter("Code");
        //settings.AddParameter("OpenTag");
        //settings.AddParameter("CloseTag");
        //-----------------------------------------------------
        // 2. Some more options
        //-----------------------------------------------------
        //settings.AddParameter("Code");
        //settings.AddParameter("OpenTag", "Open Tag");
        //settings.AddParameter("CloseTag", "Close Tag");

        //// describe specific rules applied to entering parameters. overrides default wording.
        //settings.Help = "Converts BBCode to XHTML in the comments. Close tag is optional.";
        //-----------------------------------------------------
        // 3. More options including import defaults
        //-----------------------------------------------------
        settings.AddParameter("Code", "Code", 20, true);
        settings.AddParameter("OpenTag", "Open Tag", 150, true);
        settings.AddParameter("CloseTag", "Close Tag");

        // describe specific rules for entering parameters
        settings.Help = "Converts BBCode to XHTML in the comments. Close tag is optional.";

        settings.AddValues(new string[] { "b", "strong", "" });
        settings.AddValues(new string[] { "i", "em", "" });
        settings.AddValues(new string[] { "u", "span style=\"text-decoration:underline\"", "span" });
        settings.AddValues(new string[] { "quote", "cite title=\"Quote\"", "cite" });
        //------------------------------------------------------
        ExtensionManager.ImportSettings(settings);
        _settings = ExtensionManager.GetSettings("BBCode");
    }
Beispiel #7
0
    static BBCode()
    {
        Comment.Serving += new EventHandler <ServingEventArgs>(Post_CommentServing);

        // create settings object. You need to pass exactly your
        // extension class name (case sencitive)
        ExtensionSettings settings = new ExtensionSettings("BBCode");

        //-----------------------------------------------------
        // 1. Simple
        //-----------------------------------------------------
        //settings.AddParameter("Code");
        //settings.AddParameter("OpenTag");
        //settings.AddParameter("CloseTag");
        //-----------------------------------------------------
        // 2. Some more options
        //-----------------------------------------------------
        //settings.AddParameter("Code");
        //settings.AddParameter("OpenTag", "Open Tag");
        //settings.AddParameter("CloseTag", "Close Tag");

        //// describe specific rules applied to entering parameters. overrides default wording.
        //settings.Help = "Converts BBCode to XHTML in the comments. Close tag is optional.";
        //-----------------------------------------------------
        // 3. More options including import defaults
        //-----------------------------------------------------
        settings.AddParameter("Code", "Code", 20, true);
        settings.AddParameter("OpenTag", "Open Tag", 150, true);
        settings.AddParameter("CloseTag", "Close Tag");

        // describe specific rules for entering parameters
        settings.Help = "Converts BBCode to XHTML in the comments. Close tag is optional.";

        settings.AddValues(new string[] { "b", "strong", "" });
        settings.AddValues(new string[] { "i", "em", "" });
        settings.AddValues(new string[] { "u", "span style=\"text-decoration:underline\"", "span" });
        settings.AddValues(new string[] { "quote", "cite title=\"Quote\"", "cite" });
        //------------------------------------------------------
        ExtensionManager.ImportSettings(settings);
        _settings = ExtensionManager.GetSettings("BBCode");
    }
        /// <summary>
        /// Add item
        /// </summary>
        /// <param name="item"></param>
        /// <returns>New item</returns>
        public CommentFilterItem Add(CommentFilterItem item)
        {
            if (!Security.IsAuthorizedTo(Rights.AccessAdminPages))
            {
                throw new UnauthorizedAccessException();
            }

            try
            {
                Filters = ExtensionManager.GetSettings("MetaExtension", "BeCommentFilters");
                string id = Guid.NewGuid().ToString();

                int parLen = Filters.Parameters[0].Values.Count;
                for (int i = 0; i < parLen; i++)
                {
                    bool exists =
                        Filters.Parameters[1].Values[i] == item.Action &&
                        Filters.Parameters[2].Values[i] == item.Subject &&
                        Filters.Parameters[3].Values[i] == item.Operation &&
                        Filters.Parameters[4].Values[i] == item.Filter;
                    if (exists)
                    {
                        throw new ApplicationException("Item already exists");
                    }
                }

                string[] f = new string[] {
                    id,
                    item.Action,
                    item.Subject,
                    item.Operation,
                    item.Filter
                };

                Filters.AddValues(f);
                ExtensionManager.SaveSettings("MetaExtension", Filters);

                return(new CommentFilterItem
                {
                    Id = Guid.Parse(id),
                    Action = item.Action,
                    Subject = item.Subject,
                    Operation = item.Operation,
                    Filter = item.Filter
                });
            }
            catch (Exception ex)
            {
                Utils.Log("Error adding new comment filter", ex);
                throw;
            }
        }
Beispiel #9
0
        /// <summary>
        /// Add item to white or black list
        /// </summary>
        /// <param name="subject">
        /// Item subject.
        /// </param>
        /// <param name="value">
        /// Item value.
        /// </param>
        /// <param name="isspam">
        /// True if comment is spam
        /// </param>
        public static void AddItemToFilter(string subject, string value, bool isspam)
        {
            var indx  = 0;
            var match = false;

            var dt = filters.GetDataTable();

            if (dt != null && dt.Rows.Count > 0)
            {
                foreach (DataRow row in dt.Rows)
                {
                    var rowSubject = row["Subject"].ToString();
                    var filter     = row["Filter"].ToString().Trim();

                    if (rowSubject.Equals(subject, StringComparison.OrdinalIgnoreCase) &&
                        filter.Equals(value, StringComparison.OrdinalIgnoreCase))
                    {
                        match = true;
                        break;
                    }

                    indx++;
                }
            }

            if (match)
            {
                var log = "Removed old filter ";

                // remove old filter
                foreach (var par in filters.Parameters)
                {
                    log += string.Format(":{0}", par.Values[indx]);
                    par.DeleteValue(indx);
                }

                ExtensionManager.SaveSettings("MetaExtension", filters);
                Utils.Log(log);
            }

            // add value to filters
            var id             = Guid.NewGuid().ToString();
            var action         = isspam ? "Block" : "Allow";
            var blackWhiteList = isspam ? "Black" : "White";
            var f = new[] { id, action, subject, "Equals", value };

            filters.AddValues(f);
            ExtensionManager.SaveSettings("MetaExtension", filters);

            Utils.Log(string.Format("{0} added to {1} list: {2}", subject, blackWhiteList, value));
        }
Beispiel #10
0
    protected void btnAddFilter_Click(object sender, EventArgs e)
    {
        if (ValidateForm())
        {
            string   id = Guid.NewGuid().ToString();
            string[] f  = new string[] { id,
                                         ddAction.SelectedValue,
                                         ddSubject.SelectedValue,
                                         ddOperator.SelectedValue,
                                         txtFilter.Text };

            _filters.AddValues(f);
            ExtensionManager.SaveSettings("MetaExtension", _filters);
            Response.Redirect(Request.RawUrl);
        }
    }
        static void InitCustomFilters()
        {
            ExtensionSettings settings = new ExtensionSettings("BeCustomFilters");

            settings.AddParameter("FullName", "Name", 100, true, true);
            settings.AddParameter("Name");
            settings.AddParameter("Checked");
            settings.AddParameter("Cought");
            settings.AddParameter("Reported");
            settings.AddParameter("Priority");

            _customFilters = ExtensionManager.InitSettings("MetaExtension", settings);

            if (_customFilters != null)
            {
                DataTable dt             = _customFilters.GetDataTable();
                ArrayList codeAssemblies = Utils.CodeAssemblies();

                foreach (Assembly a in codeAssemblies)
                {
                    Type[] types = a.GetTypes();
                    foreach (Type type in types)
                    {
                        if (type.GetInterface("BlogEngine.Core.ICustomFilter") != null)
                        {
                            bool found = false;
                            foreach (DataRow row in dt.Rows)
                            {
                                if (row[0].ToString() == type.Name)
                                {
                                    found = true;
                                    break;
                                }
                            }
                            if (!found)
                            {
                                _customFilters.AddValues(new string[] { type.FullName, type.Name, "0", "0", "0", "0" });
                            }
                        }
                    }
                }
                ExtensionManager.SaveSettings("MetaExtension", _customFilters);
            }
        }
Beispiel #12
0
        /// <summary>
        /// The init custom filters.
        /// </summary>
        private static void InitCustomFilters()
        {
            var settings = new ExtensionSettings("BeCustomFilters");

            settings.AddParameter("FullName", "Name", 100, true, true);
            settings.AddParameter("Name");
            settings.AddParameter("Checked");
            settings.AddParameter("Cought");
            settings.AddParameter("Reported");
            settings.AddParameter("Priority");

            customFilters = ExtensionManager.InitSettings("MetaExtension", settings);
            if (customFilters == null)
            {
                return;
            }

            var dt             = customFilters.GetDataTable();
            var codeAssemblies = Utils.CodeAssemblies();

            foreach (var type in
                     codeAssemblies.Cast <Assembly>().Select(a => a.GetTypes()).SelectMany(
                         types => (from type in types
                                   where type.GetInterface("BlogEngine.Core.ICustomFilter") != null
                                   let found = dt.Rows.Cast <DataRow>().Any(row => row[0].ToString() == type.Name)
                                               where !found
                                               select type)))
            {
                // if new filter found in the assembly, add it to settings
                if (!customFilters.IsKeyValueExists(type.FullName))
                {
                    customFilters.AddValues(new[] { type.FullName, type.Name, "0", "0", "0", "0" });
                    ExtensionManager.SaveSettings("MetaExtension", customFilters);
                }
            }
        }
Beispiel #13
0
        static void InitCustomFilters()
        {
            ExtensionSettings settings = new ExtensionSettings("BeCustomFilters");

            settings.AddParameter("FullName", "Name", 100, true, true);
            settings.AddParameter("Name");
            settings.AddParameter("Checked");
            settings.AddParameter("Cought");
            settings.AddParameter("Reported");
            settings.AddParameter("Priority");

            _customFilters = ExtensionManager.InitSettings("MetaExtension", settings);

            if(_customFilters != null)
            {
                DataTable dt = _customFilters.GetDataTable();
                ArrayList codeAssemblies = Utils.CodeAssemblies();

                foreach (Assembly a in codeAssemblies)
                {
                    Type[] types = a.GetTypes();
                    foreach (Type type in types)
                    {
                        if (type.GetInterface("BlogEngine.Core.ICustomFilter") != null)
                        {
                            bool found = false;
                            foreach (DataRow row in dt.Rows)
                            {
                                if(row[0].ToString() == type.Name)
                                {
                                    found = true;
                                    break;
                                }
                            }
                            if(!found)
                            {
                                _customFilters.AddValues(new string[] { type.FullName, type.Name, "0", "0", "0", "0" });
                            }
                        }
                    }
                }
                ExtensionManager.SaveSettings("MetaExtension", _customFilters);
            }
        }