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

Forums / Developing with Sitefinity / Blog post admin

Blog post admin

3 posts, 0 answered
  1. Daniel Plomp
    Daniel Plomp avatar
    952 posts
    Registered:
    18 Feb 2004
    27 Aug 2010
    Link to this post
    Hi,

    I'm having a bit trouble with adjusting the Twitter Integration Solution from Basem Emara.
    http://blog.basememara.com/2010/03/25/twitter-integration-with-sitefinity/

    Instead of Eventitems, I want to use Blogitems.

    What should I do to override the PostEditView and PostNewView in the backend? This is what I've done so far:

    1. Copied the templates needed and changed them according to Basems manual
    2. Created a class called 'CustomPostEditView.cs' and placed it into "~/App_Code/Modules/Blogs/..."
    3. Added the 'Telerik.Sitefinity.Configuration.ControlsConfig.xml' and changed into:

    <?xml version="1.0" encoding="utf-8"?>
    <controlsConfig>
        <viewMap>
            <viewSettings hostType="Telerik.Blogs.WebControls.Admin.PostEditView, Telerik.Blogs">
                <views>
                    <remove name="PostEditView" />
                    <add name="PostEditView" viewType="Modules.Blogs.CustomPostEditView, App_Code"></add>
                </views>
            </viewSettings>
      
        </viewMap>
      
    </controlsConfig>


    This is the code inside the custom class:

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    using Telerik.Events;
    using Telerik.Cms;
    using Telerik.Cms.Engine;
    using Telerik.Blogs;
    using Telerik.News;
      
    /// <summary>
    /// Summary description for PostEditView
    /// </summary>
    public class CustomPostEditView : Telerik.Blogs.WebControls.Admin.PostEditView
    {
        // Default Blog page
        private const string DEFAULT_EVENT_PAGE = "~/blogs/blogpost.aspx";
      
        public override string LayoutTemplatePath
        {
            get
            {
                return "~/Templates/Admin/ControlTemplates/Blogs/PostEdit.ascx";
            }
            set
            {
                base.LayoutTemplatePath = value;
            }
        }
      
        protected override void InitializeControls(System.Web.UI.Control viewContainer)
        {
            //HANDLE PROCESSES ON EVENTS THAT INCLUDE NEWLY CREATED ITEMS.  
            //THIS IS NEEDED SO WE HAVE AN ID IN DB FOR THESE PROCESSES SINCE THE SAVECONTENT   
            //OVERRIDE EXISTS/REDIRECTS BEFORE BEING ABLE TO SEND BACK THE CREATED OBJECT  
      
            ContentManager.Executed += new EventHandler<Telerik.ExecutedEventArgs>(ContentManager_Executed);
        }
      
        void ContentManager_Executed(object sender, Telerik.ExecutedEventArgs e)
        {
            try
            {
                if (e.CommandName == "CreateContent" || e.CommandName == "UpdateContent")
                {
                    IContent content = ContentManager.Providers[BlogManager.DefaultContentProvider].GetContent(e.ItemID);
                    if (content != null)
                    {
                        //BUILD ITEM URL TO SEND TO EXTERNAL SERVICES
                        string eventUrl = Utility.ResolveItemUrl(DEFAULT_EVENT_PAGE, content.UrlWithExtension, true);
                        string shortUrl = this.BitlyHandler(content, eventUrl);
                        this.TwitterHandler(content, shortUrl);
                    }
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }  
      
        protected string BitlyHandler(IContent content, string url)
        {
            if (!String.IsNullOrEmpty((string)content.GetMetaData("ShortUrl")))
            {
                //SHORT URL WAS DONE BEFORE
                return (string)content.GetMetaData("ShortUrl");
            }
            else
            {
                //CALL SHORTEN URL SERVICE
                url = Utility.ShortenUrl(url);
                content.SetMetaData("ShortUrl", url);
      
                ContentManager manager = new ContentManager(BlogManager.DefaultContentProvider);
                manager.SaveContent(content, ContentStatus.Published);
      
                return url;
            }
        }
      
        protected void TwitterHandler(IContent content, string url)
        {
            //POST TO TWITTER IF APPLICABLE
            if (Convert.ToBoolean(content.GetMetaData("TwitterPost")))
            {
                if (Utility.UpdateTwitterStatus((string)content.GetMetaData("Title"), url, (string)content.GetMetaData("TwitterHash")))
                {
                    //RESET FLAG IN CASE USER WOULD LIKE TO REPOST LATER
                    content.SetMetaData("TwitterPost", false);
                    //RECORD DATE OF TWITTER POST
                    content.SetMetaData("TwitterPostDate", DateTime.Now);
                    EventsManager.Providers[EventsManager.DefaultContentProvider].SaveContent(content, false);
                }
            }
        }
      
    }

    For some reason when debugging the events doesn't seem to fire and breakpoints are never reached.
    There error I'm getting when editing a blogpost on saving:

    Unable to cast object of type 'Telerik.Blogs.WebControls.Admin.PostEditView' to type 'Telerik.Blogs.WebControls.Admin.PostsView'.


    So, what did I forgot?

    Thanks,
    Daniel


  2. George
    George  avatar
    204 posts
    Registered:
    05 Sep 2006
    27 Aug 2010
    Link to this post
    Hi Daniel

    I have implemented this functionality for the News Items to be posted to twitter but I used a slightly different approach and it works

    Check the code below

    public class CustomNewsItemNewView : NewsItemNew
    {
        public const string LAYOUT_TEMPLATE_PATH = "~/Sitefinity/Admin/ControlTemplates/News/NewsItemNew.ascx";
         
        public override System.Type LocalizationAssemblyInfo
        {
            get
            {
                return typeof(NewsItemNew);
            }
            set
            {
                base.LocalizationAssemblyInfo = value;
            }
        }
     
        public override System.Type AssemblyInfo
        {
            get
            {
                return typeof(NewsItemNew);
            }
            set
            {
                base.AssemblyInfo = value;
            }
        }
     
        public override string LayoutTemplatePath
        {
            get
            {
                return LAYOUT_TEMPLATE_PATH;
            }
            set
            {
                base.LayoutTemplatePath = value;
            }
        }
     
        protected virtual CheckBox TwitterCheckBox
        {
            get
            {
                return base.Container.GetControl<CheckBox>("chkTwitter", false);
            }
        }
     
        protected virtual TextBox SummaryTextBox
        {
            get
            {
                return base.MetaFields.GetControl("Summary", false) as TextBox;
            }
        }
     
        protected override void SaveContent()
        {
            //Check if the twitter checkbox has been checked then send tweet
            if(TwitterCheckBox != null && TwitterCheckBox.Checked)
            {
                TwitterHelper.PostTweet(SummaryTextBox.Text);
            }
     
            base.SaveContent();
        }
    }

    Best,

    G
  3. Daniel Plomp
    Daniel Plomp avatar
    952 posts
    Registered:
    18 Feb 2004
    27 Aug 2010
    Link to this post
    Hi George,

    Well, what I just want is have some influence on the saving procedure of a blogitem from the backend.
    I'm not getting it done. Can't find the right information on how to override these views from the backend with help of a custom module inside the App_Code folder.

    -Daniel
Register for webinar
3 posts, 0 answered