using System; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; using CMS.CMSHelper; using CMS.GlobalHelper; using CMS.PortalControls; using CMS.PortalEngine; public partial class CMSWebParts_Search_GoogleSearch : CMSAbstractWebPart { #region "Public properties" /// /// Search engine unique ID provided by Google. /// public string SearchEngineUniqueID { get { return ValidationHelper.GetString(GetValue("SearchEngineUniqueID"), ""); } set { SetValue("SearchEngineUniqueID", value); } } /// /// Search layout. /// public string Layout { get { return ValidationHelper.GetString(GetValue("Layout"), ""); } set { SetValue("Layout", value); } } /// /// Search layout style. /// public string LayoutStyle { get { return ValidationHelper.GetString(GetValue("LayoutStyle"), ""); } set { SetValue("LayoutStyle", value); } } /// /// Search results div element ID, in case that the search dialog and the results are divided. /// public string SearchResultsElementID { get { return ValidationHelper.GetString(GetValue("SearchResultsElementID"), "cse"); } set { SetValue("SearchResultsElementID", value); } } #endregion #region "Page events" /// /// Loads the web part content. /// public override void OnContentLoaded() { base.OnContentLoaded(); SetupControl(); } #endregion #region "Other methods" /// /// Sets up the control. /// protected void SetupControl() { if (StopProcessing) { // Do nothing } else { if (CMSContext.ViewMode != ViewModeEnum.Design) { string culture = CultureHelper.GetShortCultureCode(CMSContext.CurrentDocumentCulture.CultureCode); if (Layout == "dialog") { ltlGoogleSearch.Text = "
Loading
"; ScriptHelper.RegisterStartupScript(Page, typeof(string), ClientID + "linkscript", ScriptHelper.GetIncludeScript("http://www.google.com/jsapi")); ScriptHelper.RegisterStartupScript(Page, typeof(string), ClientID + "linescript", ScriptHelper.GetScript("google.load('search', '1', {language : '" + culture + "'}); google.setOnLoadCallback(function() { var customSearchControl = new google.search.CustomSearchControl('" + SearchEngineUniqueID + "'); customSearchControl.setResultSetSize(google.search.Search.FILTERED_CSE_RESULTSET); var options = new google.search.DrawOptions(); options.setSearchFormRoot('cse-search-form'); customSearchControl.draw('" + SearchResultsElementID + "', options); }, true);")); } else if (Layout == "results") { ltlGoogleSearch.Text = "
"; } else { ltlGoogleSearch.Text = "
Loading
"; ScriptHelper.RegisterStartupScript(Page, typeof(string), ClientID + "linkscript", ScriptHelper.GetIncludeScript("http://www.google.com/jsapi")); ScriptHelper.RegisterStartupScript(Page, typeof(string), ClientID + "linescript", ScriptHelper.GetScript("google.load('search', '1', {language : '" + culture + "'});google.setOnLoadCallback(function() {var customSearchControl = new google.search.CustomSearchControl('" + SearchEngineUniqueID + "');customSearchControl.setResultSetSize(google.search.Search." + Layout + ");customSearchControl.draw('cse');}, true);")); } } } } #endregion }