+1-888-365-2779
Try Now
More in this section

Forums / Developing with Sitefinity / Override Blog RSS Setting Control?

Override Blog RSS Setting Control?

3 posts, 1 answered
  1. bemara57
    bemara57 avatar
    135 posts
    Registered:
    27 Mar 2008
    04 Jan 2011
    Link to this post
    I wanted to add an extra setting to the Blogs RSS. I am trying to inherit:
    "Telerik.Blogs.WebControls.Rss.RssSettingsControl"

    But I cannot override the template, SaveSettings(), and InitSettings(...). Do I really have to recreate the entire RssSettingsControl logic from scratch, or is there an easier way to add a single setting?
  2. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    09 Dec 2016
    04 Jan 2011
    Link to this post
    Hi bemara57,

    I checked the code and these methods SaveSettings(), and InitSettings() cannot be overridden. You have to create a custom control. You can take a look at this post for samples.

    Best wishes,
    Ivan Dimitrov
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
    Answered
  3. bemara57
    bemara57 avatar
    135 posts
    Registered:
    27 Mar 2008
    11 Jan 2011
    Link to this post
    Thanks Ivan. The methods should really be marked as "virtual" so I can override them. To maneuver around this, I inherited "Telerik.Blogs.WebControls.Rss.RssSettingsControl" and RE-inherited "IRssSettingsControl". Then I added the "new" keyword to hide some of the base properties and methods, while still triggering the underlying base methods.

    This helped me avoid re-creating all the blog RSS settings logic from scratch. I needed to do this so I can extend the Blog RSS provider to allow category selection like it does with news.

    using System;
    using System.Collections.Generic;
    using Telerik.Cms.Web.UI;
    using Telerik.Framework.Rss;
    using System.Web.UI;
    using Telerik.Framework.Web;
    using Telerik.Cms.Engine;
    using System.Web.UI.WebControls;
    using System.Web.UI.HtmlControls;
    using System.Collections;
    using System.Linq;
    using Telerik.Blogs;
    using System.Text;
     
    namespace MyCustom.Blogs.WebControls.Rss
    {
        public class RssSettingsControl : Telerik.Blogs.WebControls.Rss.RssSettingsControl, IRssSettingsControl
        {
            private const string RssSettingsControlTemplateName = "MyCustom.Blogs.ControlTemplates.Backend.RssSettingsControl.ascx";
     
            private BlogManager manager;
            private ITemplate controlTemplate;
            private string controlTemplatePath;
            private IDictionary<string, string> settings;
     
            #region View layout and template
     
            public new ITemplate ControlTemplate
            {
                get
                {
                    if (this.controlTemplate == null)
                    {
                        this.controlTemplate = ControlUtils.GetTemplate(this.ControlTemplatePath, this.LayoutTemplateName, this.GetType(), this.GetType(), this.GetType(), this.ProviderName);
                    }
                    return this.controlTemplate;
                }
            }
     
            [WebSysTemplate(RssSettingsControlTemplateName, "RssSettingsControl_Desc", "/Blogs", false, "2009-01-31")]
            public new string ControlTemplatePath
            {
                get
                {
                    return this.controlTemplatePath;
                }
                set
                {
                    this.controlTemplatePath = value;
                }
            }
     
            protected override string LayoutTemplateName
            {
                get
                {
                    return RssSettingsControlTemplateName;
                }
            }
     
     
            #endregion
     
            private BlogManager Manager
            {
                get
                {
                    if (this.manager == null)
                    {
                        this.manager = new BlogManager(this.ProviderName);
                    }
                    return this.manager;
                }
            }
     
            protected virtual RadioButton AllCategories
            {
                get
                {
                    return this.Container.GetControl<RadioButton>("allCategories", true);
                }
            }
     
            protected virtual RadioButton ChooseCategories
            {
                get
                {
                    return this.Container.GetControl<RadioButton>("chooseCategories", true);
                }
            }
     
            protected virtual CheckBoxList CategoriesList
            {
                get
                {
                    return this.Container.GetControl<CheckBoxList>("categoriesList", true);
                }
            }
     
            protected virtual HtmlGenericControl CheckBoxDiv2
            {
                get
                {
                    return this.Container.GetControl<HtmlGenericControl>("categoriesToChooseOptions", true);
                }
            }
     
            protected override void CreateChildControls()
            {
                base.CreateChildControls();
     
                //POPULATE CATEGORIES
                this.FillCategoryList();
     
                //UPDATE CATEGORIES SELECTION
                if (this.settings != null && this.settings.Count > 0)
                {
                    string selectedCategories = this.settings["SelectedCategories"];
                    if (String.IsNullOrEmpty(selectedCategories))
                    {
                        this.AllCategories.Checked = true;
                        this.ChooseCategories.Checked = false;
                        this.CheckBoxDiv.Attributes["class"] = "RssBlogListAll";
                    }
                    else
                    {
                        this.ChooseCategories.Checked = true;
                        this.AllCategories.Checked = false;
                        foreach (string item in selectedCategories.Split(','))
                        {
                            foreach (ListItem item2 in this.CategoriesList.Items)
                            {
                                if (item2.Value == item)
                                {
                                    item2.Selected = true;
                                }
                            }
                        }
                    }
                }
            }
     
            protected override void OnPreRender(EventArgs e)
            {
                base.OnPreRender(e);
     
                //HANDLE CATEGORY SCRIPTS
                this.AllCategories.Attributes["onclick"] = "manageCheckboxesCategories('" + this.CheckBoxDiv2.ClientID + "', this.value);";
                this.ChooseCategories.Attributes["onclick"] = "manageCheckboxesCategories('" + this.CheckBoxDiv2.ClientID + "', this.value);";
                string jsFunctions = @"
                    function manageCheckboxesCategories(radioDivID, state) {
                        var blogCheckboxesDiv = document.getElementById(radioDivID);
                        var blogCheckboxes = document.getElementById(radioDivID).getElementsByTagName('input');
                        if (state == 'allCategories') {
                            blogCheckboxesDiv.className = 'RssBlogListAll blogsToChooseOptions';
                            for (i = 0; i < blogCheckboxes.length; i++)
                                blogCheckboxes[i].disabled = 'disabled';
     
                        }
                        else if (state == 'chooseCategories') {
                            blogCheckboxesDiv.className = 'blogsToChooseOptions';
                            for (i = 0; i < blogCheckboxes.length; i++)
                                blogCheckboxes[i].disabled = '';
                        }
                    }
     
                    function setOnLoadCategories(radioDivID, state) {
                        if (window.addEventListener) { // Mozilla, Netscape, Firefox
                            window.addEventListener('load', function () { manageCheckboxesCategories(radioDivID, state); }, false);
                        } else { // IE
                            window.attachEvent('onload', function () { manageCheckboxesCategories(radioDivID, state); });
                        }
                    }";
                string str = this.AllCategories.Checked ? this.AllCategories.ID : this.ChooseCategories.ID;
                string jsScriptName = Guid.NewGuid().ToString();
                this.Page.ClientScript.RegisterClientScriptBlock(typeof(RssSettingsControl), jsScriptName, jsFunctions + "\n setOnLoadCategories('" + this.CheckBoxDiv2.ClientID + "', '" + str + "');", true);
            }
     
            public new void InitSettings(IDictionary<string, string> rssSettings)
            {
                base.InitSettings(rssSettings);
                this.settings = rssSettings;
            }
     
            public new IDictionary<string, string> SaveSettings()
            {
                this.settings = base.SaveSettings();
     
                //SAVE CATEGORIES SELECTION
                if (this.AllCategories.Checked)
                {
                    this.settings["SelectedCategories"] = String.Empty;
                }
                else if (this.ChooseCategories.Checked)
                {
                    StringBuilder builder = new StringBuilder();
                    foreach (ListItem item in this.CategoriesList.Items)
                    {
                        if (item.Selected)
                        {
                            builder.Append(item.Value);
                            builder.Append(',');
                        }
                    }
                    this.settings["SelectedCategories"] = builder.ToString().TrimEnd(',');
                }
     
                return this.settings;
            }
     
            private void FillCategoryList()
            {
                IList categories = this.Manager.Content.GetCategories(0, 0, "CategoryName ASC");
                this.CategoriesList.Items.Clear();
                foreach (ICategory category in categories)
                {
                    ListItem item = new ListItem(category.CategoryName, category.CategoryName);
                    this.CategoriesList.Items.Add(item);
                }
            }
        }
    }
     
    <%@ Control Language="C#" %>
    <%@ Register TagPrefix="cc2" Namespace="Telerik.Cms.Web.UI" Assembly="Telerik.Cms" %>
     
    <div class="RssBlogChannels">
        <ul>
            <li runat="server" id="providerNameLi">
                <asp:Label runat="server" Text="<%$Resources:BlogProvider %>" AssociatedControlID="blogProvider"></asp:Label>
                <asp:DropDownList runat="server" ID="blogProvider"></asp:DropDownList>
            </li>
            <li class="clearfix sb">
            <h5><asp:Literal ID="Literal7" runat="server" Text="<%$Resources:SelectBlogs %>" ></asp:Literal> </h5>
                <div class="selectbl radio">
                <ul runat="server" id="blogsToChoose" class="blogsToChoose">
                    <li>
                        <asp:RadioButton ID="allBlogs" runat="server" Text="<%$Resources:AllBlogs %>" Checked="true" GroupName="hop" ToolTip="<%$Resources:AllBlogs %>" />
                    </li>
                    <li>
                        <asp:RadioButton ID="chooseBlgs" runat="server" Text="<%$Resources:SelectedBlogsOnly %>" GroupName="hop" ToolTip="<%$Resources:SelectedBlogsOnly %>" />
                    </li>
                </ul>
                <div runat="server" id="blogsToChooseOptions" class="blogsToChooseOptions">
                    <div runat="server" id="blogsListDiv">
                        <asp:CheckBoxList id="blogsList" runat="server" RepeatLayout="Flow">
                        </asp:CheckBoxList>
                    </div>
     
                </div>
             </div>
            </li>
            <li class="clearfix sb">
            <h5><asp:Literal ID="Literal2" runat="server" Text="<%$Resources:SelectCategories %>" ></asp:Literal> </h5>
                <div class="selectbl radio">
                <ul runat="server" id="categoriesToChoose" class="blogsToChoose">
                    <li>
                        <asp:RadioButton ID="allCategories" runat="server" Text="<%$Resources:AllCategories %>" Checked="true" GroupName="hop2" ToolTip="allCategories" />
                    </li>
                    <li>
                        <asp:RadioButton ID="chooseCategories" runat="server" Text="<%$Resources:ChooseFromCategories %>" GroupName="hop2" ToolTip="chooseCategories" />
                    </li>
                </ul>
                <div runat="server" id="categoriesToChooseOptions" class="blogsToChooseOptions">
                    <div runat="server" id="categoriesListDiv">
                        <asp:CheckBoxList id="categoriesList" runat="server" RepeatLayout="Flow">
                        </asp:CheckBoxList>
                    </div>
     
                </div>
             </div>
            </li>
            <li class="selector clearfix">
                <asp:Label ID="Label8" runat="server" AssociatedControlID="postUrl">
                    <asp:Literal ID="Literal1" runat="server" Text="<%$Resources:PostUrl %>" ></asp:Literal>
                    <telerik:LabelToolTip HelpBoxCssClass="HelpBox" id="labelHelpBox3" runat="server" ToolTipTitle="<%$Resources:PostUrlDescriptionTitle %>" ToolTipText="<%$Resources:PostUrlDescriptionContent %>" AlternateText="<%$Resources:PostUrlTooltip %>"></telerik:LabelToolTip>
                </asp:Label>
                <asp:TextBox runat="server" ID="postUrl"></asp:TextBox>
                <asp:LinkButton runat="server" ID="selectPostUrl" Text="<%$Resources:Select %>" CssClass="picker" ></asp:LinkButton>
            </li>           
            <li class="count clearfix">
                <asp:Label ID="Label3" runat="server" Text="<%$Resources:ItemsCount %>" AssociatedControlID="itemsCount"></asp:Label>
                <asp:TextBox runat="server" ID="itemsCount" ValidationGroup="feedSettings" Text="15"></asp:TextBox> <em class="quont">items</em>
            </li>       
            <li class="clearfix">
                <asp:Label ID="Label6" runat="server" Text="<%$Resources:SyndicationType %>" AssociatedControlID="syndicationType"></asp:Label>
                <asp:DropDownList runat="server" ID="syndicationType"></asp:DropDownList>
            </li>
           <li runat="Server" id="summaryLengthLi" class="count clearfix">
                <asp:Label ID="Label5" runat="server" Text="<%$Resources:SummaryLength %>" AssociatedControlID="summaryLength"></asp:Label>
                <asp:TextBox runat="server" ID="summaryLength" ValidationGroup="feedSettings"></asp:TextBox> <em class="quont">words</em>
     
            </li>
                
        </ul>
    </div>

    using System;
    using System.Collections.Generic;
    using Telerik.Blogs;
    using Telerik.Cms.Engine;
    using Telerik.Cms.Engine.ContentViewFiltering;
    using Falafel.Sitefinity.Blogs.Resources;
     
    namespace MyCustom.Blogs.Providers
    {
        /// <summary>
        /// Summary description for RssChannelProvider
        /// </summary>
        public class RssChannelProvider : Telerik.Blogs.Rss.RssChannelProvider
        {
            public override string Name
            {
                get
                {
                    return Messages.BlogsChannels;
                }
            }
     
            public override void Initialize(IDictionary<string, string> settings)
            {
                //ADD FILTER FOR CATEGORY IF APPLICABLE
                string selectedCategories = settings["SelectedCategories"];
                if (!String.IsNullOrEmpty(selectedCategories))
                {
                    base.FilterBuilder.AddFilter(new ContentFilterStatement("Category", String.Format("({0})", selectedCategories), ContentFilter.Condition.In, ContentFilter.JoinType.And));
                }
     
                base.Initialize(settings);
            }
        }
    }

    Web.config section:
    <rss defaultProvider="Sitefinity">
            ......
        <channelProviders>
            <clear/>
            ......
            <add name="Blogs with Category" type="MyCustom.Blogs.Providers.RssChannelProvider, MyCustom" settingsControl="MyCustom.Blogs.WebControls.Rss.RssSettingsControl, MyCustom" viewSettingsControl="Telerik.Blogs.WebControls.Rss.RssViewControl, Telerik.Blogs" description="Provides RSS for blogs"></add>
        </channelProviders>
            ......
    </rss>

Register for webinar
3 posts, 1 answered