using System; using System.Text; using System.Web.UI; using CMS.CMSHelper; using CMS.GlobalHelper; using CMS.MembershipProvider; using CMS.PortalControls; using CMS.DocumentEngine; public partial class CMSWebParts_CommunityServices_Facebook_FacebookLikeButton : CMSAbstractWebPart { #region "Public properties" /// /// Url to like. /// public string Url { get { return ValidationHelper.GetString(GetValue("URL"), string.Empty); } set { SetValue("URL", value); } } /// /// Like button layout style. /// public string LayoutStyle { get { return ValidationHelper.GetString(GetValue("LayoutStyle"), "standard"); } set { SetValue("LayoutStyle", value); } } /// /// Indicates whether to show faces or not. /// public bool ShowFaces { get { return ValidationHelper.GetBoolean(GetValue("ShowFaces"), true); } set { SetValue("ShowFaces", value); } } /// /// Indicates whether to include the Send button or not. /// public bool IncludeSendButton { get { return ValidationHelper.GetBoolean(GetValue("IncludeSendButton"), true); } set { SetValue("IncludeSendButton", value); } } /// /// Width of the element. /// public int Width { get { return ValidationHelper.GetInteger(GetValue("Width"), 450); } set { SetValue("Width", value); } } /// /// Verb which will show up on the button. /// public string VerbToDisplay { get { return ValidationHelper.GetString(GetValue("VerbToDisplay"), "like"); } set { SetValue("VerbToDisplay", value); } } /// /// Font of the text in iframe. /// public string Font { get { return ValidationHelper.GetString(GetValue("Font"), "arial"); } set { SetValue("Font", value); } } /// /// Color scheme of the button and text. /// public string ColorScheme { get { return ValidationHelper.GetString(GetValue("ColorScheme"), "light"); } set { SetValue("ColorScheme", value); } } /// /// Indicates whether to generate meta data tags or not. /// public bool GenerateMetaData { get { return ValidationHelper.GetBoolean(GetValue("GenerateMetaData"), false); } set { SetValue("GenerateMetaData", value); } } /// /// Meta data title. /// public string MetaTitle { get { return ValidationHelper.GetString(GetValue("MetaTitle"), ""); } set { SetValue("MetaTitle", value); } } /// /// Meta data type. /// public string MetaType { get { return ValidationHelper.GetString(GetValue("MetaType"), ""); } set { SetValue("MetaType", value); } } /// /// Meta data URL. /// public string MetaUrl { get { return ValidationHelper.GetString(GetValue("MetaUrl"), ""); } set { SetValue("MetaUrl", value); } } /// /// Meta data site name. /// public string MetaSiteName { get { return ValidationHelper.GetString(GetValue("MetaSiteName"), ""); } set { SetValue("MetaSiteName", value); } } /// /// Meta data image URL. /// public string MetaImage { get { return ValidationHelper.GetString(GetValue("MetaImage"), ""); } set { SetValue("MetaImage", value); } } /// /// Indicates if HTML 5 output should be generated. /// public bool UseHTML5 { get { return ValidationHelper.GetBoolean(GetValue("UseHTML5"), false); } set { SetValue("UseHTML5", value); } } #endregion #region "Page events" /// /// Loads the web part content. /// public override void OnContentLoaded() { base.OnContentLoaded(); SetupControl(); } /// /// Sets up the control. /// protected void SetupControl() { if (StopProcessing) { // Do nothing } else { // Get page's URL string pageUrl = String.Empty; if (string.IsNullOrEmpty(Url)) { if (CMSContext.CurrentDocument != null) { TreeNode node = CMSContext.CurrentDocument; pageUrl = CMSContext.GetUrl(node.NodeAliasPath, node.DocumentUrlPath, CMSContext.CurrentSiteName); } else { pageUrl = URLHelper.CurrentURL; } } else { pageUrl = ResolveUrl(Url); } pageUrl = URLHelper.GetAbsoluteUrl(HTMLHelper.HTMLEncode(pageUrl)); // Register Facebook javascript SDK ScriptHelper.RegisterFacebookJavascriptSDK(Page, CMSContext.PreferredCultureCode, FacebookConnectHelper.GetFacebookApiKey(CMSContext.CurrentSiteName)); // Get FB code StringBuilder sb = new StringBuilder(); if (UseHTML5) { sb.Append("
"); } else { sb.Append(""); } ltlLikeButtonCode.Text = sb.ToString(); } } protected override void OnPreRender(EventArgs e) { base.OnPreRender(e); if (StopProcessing) { // Do nothing } else { // Generate meta tags if (GenerateMetaData) { StringBuilder sb = new StringBuilder(); if (MetaTitle != "") { sb.AppendLine(""); } if (MetaType != "") { sb.AppendLine(""); } if (MetaSiteName != "") { sb.AppendLine(""); } if (MetaImage != "") { sb.AppendLine(""); } if (MetaUrl != "") { sb.AppendLine(""); } Page.Header.Controls.Add(new LiteralControl(sb.ToString())); } } } #endregion }