using System; using System.Data; using System.Collections; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; using CMS.PortalControls; using CMS.GlobalHelper; using CMS.CMSHelper; public partial class CMSWebParts_CommunityServices_Pinterest_PinterestPinItButton : CMSAbstractWebPart { #region "Properties" /// /// URL. /// public string Url { get { return ValidationHelper.GetString(GetValue("Url"), string.Empty); } set { SetValue("Url", value); } } /// /// Image URL. /// public string ImageUrl { get { return ValidationHelper.GetString(GetValue("ImageUrl"), string.Empty); } set { SetValue("ImageUrl", value); } } /// /// Description. /// public string Description { get { return ValidationHelper.GetString(GetValue("Description"), string.Empty); } set { SetValue("Description", value); } } /// /// Defines if pin count should bwe displayed and where. /// public string PinCount { get { return ValidationHelper.GetString(GetValue("PinCount"), string.Empty); } set { SetValue("PinCount", value); } } #endregion #region "Methods" /// /// Content loaded event handler /// public override void OnContentLoaded() { base.OnContentLoaded(); SetupControl(); } /// /// Initializes the control properties /// protected void SetupControl() { if (this.StopProcessing) { // Do not process } else { // Register plugin javascript string script = @" (function() { window.PinIt = window.PinIt || { loaded:false }; if (window.PinIt.loaded) return; window.PinIt.loaded = true; function async_load(){ var s = document.createElement(""script""); s.type = ""text/javascript""; s.async = true; s.src = ""http://assets.pinterest.com/js/pinit.js""; var x = document.getElementsByTagName(""script"")[0]; x.parentNode.insertBefore(s, x); } if (window.attachEvent) window.attachEvent(""onload"", async_load); else window.addEventListener(""load"", async_load, false); })();"; ScriptHelper.RegisterClientScriptBlock(this, typeof(string), "Pinterest", ScriptHelper.GetScript(script)); // If URL not set -> get current URL if (String.IsNullOrEmpty(Url)) { Url = URLHelper.GetAbsoluteUrl(URLHelper.CurrentURL); } // Build plugin code string query = null; string src = "http://pinterest.com/pin/create/button/"; // Set webpart parameters query = URLHelper.AddUrlParameter(query, "url", Url); query = URLHelper.AddUrlParameter(query, "media", URLHelper.GetAbsoluteUrl(ImageUrl)); query = URLHelper.AddUrlParameter(query, "description", Description); src = URLHelper.EncodeQueryString(URLHelper.AppendQuery(src, query)); // Output HTML code string output = "Pin It"; ltlPluginCode.Text = String.Format(output, HTMLHelper.HTMLEncode(src), PinCount); } } /// /// Reloads the control data /// public override void ReloadData() { base.ReloadData(); SetupControl(); } #endregion }