using System;
using System.Xml;
using CommunityServer.Components;

namespace CommunityServer.Blogs.Components
{
	/// <summary>
	/// Smilies for Weblogs
	/// </summary>
	public class WeblogEmoticonsModule : ICSModule
	{
		public WeblogEmoticonsModule(){}

	    public void Init(CSApplication csa, XmlNode node)
	    {
	        csa.PrePostUpdate +=new CSPostEventHandler(csa_PrePostUpdate);
        }

        private void csa_PrePostUpdate(IContent content, CSPostEventArgs e)
        {
            if(e.ApplicationType == ApplicationType.Weblog)
            {
                WeblogPost wp = content as WeblogPost;
                if(wp != null && e.State != ObjectState.Delete)
                {
                    if(CSContext.Current.SiteSettings.EnableEmoticons)
                    {
                        wp.FormattedBody = Transforms.EmoticonTransforms(wp.FormattedBody);
                    }
                    
                }
            }
        }
    }
}
