using System; using System.Data; using System.Collections; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; using System.Web.UI.HtmlControls; using CMS.CMSHelper; using CMS.Forums; using CMS.GlobalHelper; using CMS.PortalControls; using CMS.PortalEngine; using CMS.SettingsProvider; using CMS.DocumentEngine; using CMS.URLRewritingEngine; using CMS.WebAnalytics; public partial class CMSWebParts_Forums_Search_ForumSearch : CMSAbstractWebPart { #region "Properties" /// /// Gets or sets the path to the advance search page path. /// public string AdvancedSearchPath { get { return ValidationHelper.GetString(GetValue("AdvancedSearchPath"), ""); } set { SetValue("AdvancedSearchPath", value); } } /// /// Gets or sets the url where is the search result web part. /// public string RedirectUrl { get { return ValidationHelper.GetString(GetValue("RedirectUrl"), ""); } set { SetValue("RedirectUrl", value); } } /// /// Gets or sets the value that indicates whether search should be performed only in current context. /// public bool SearchInCurrentContext { get { return ValidationHelper.GetBoolean(GetValue("SearchInCurrentContext"), false); } set { SetValue("SearchInCurrentContext", value); } } #endregion /// /// Content loaded event handler. /// public override void OnContentLoaded() { base.OnContentLoaded(); SetupControl(); } /// /// Reloads the control data. /// public override void ReloadData() { base.ReloadData(); SetupControl(); } /// /// Initializes the control properties. /// protected void SetupControl() { // WAI validation lblSearch.ResourceString = "ForumSearch.SearchWord"; lblSearch.Attributes.Add("style", "display: none;"); btnGo.Text = GetString("ForumSearch.Go"); if (!String.IsNullOrEmpty(AdvancedSearchPath)) { lnkAdvanceSearch.NavigateUrl = ResolveUrl(TreePathUtils.GetUrl(CMSContext.ResolveCurrentPath(AdvancedSearchPath))); lnkAdvanceSearch.Visible = true; lnkAdvanceSearch.Text = GetString("ForumSearch.AdvanceSearch"); if (!RequestHelper.IsPostBack()) { txtSearch.Text = QueryHelper.GetString("searchtext", txtSearch.Text); } } } /// /// OnGo search click. /// protected void btnGo_Click(object sender, EventArgs e) { if (!String.IsNullOrEmpty(txtSearch.Text)) { string contextQuery = String.Empty; if (SearchInCurrentContext) { if ((ForumContext.CurrentForum != null) && (ForumContext.CurrentThread != null) && (ForumContext.CurrentThread.PostForumID == ForumContext.CurrentForum.ForumID)) { contextQuery = "&searchforums=" + ForumContext.CurrentForum.ForumID + "&searchthread=" + ForumContext.CurrentThread.PostId; } else if (ForumContext.CurrentForum != null) { contextQuery = "&searchforums=" + ForumContext.CurrentForum.ForumID; } } // Log "internal search" activity Activity internalSearch = new ActivityInternalSearch(txtSearch.Text, CMSContext.CurrentDocument, CMSContext.ActivityEnvironmentVariables); internalSearch.Log(); if (!String.IsNullOrEmpty(RedirectUrl.Trim())) { URLHelper.Redirect(ResolveUrl(RedirectUrl) + "?searchtext=" + HttpUtility.UrlEncode(txtSearch.Text) + contextQuery); } else //Redirect back to current page { string url = URLHelper.RemoveQuery(URLRewriter.CurrentURL); url = URLHelper.UpdateParameterInUrl(url, "searchtext", HttpUtility.UrlEncode(txtSearch.Text)); url = URLHelper.RemoveParameterFromUrl(url, "searchforums"); url = URLHelper.RemoveParameterFromUrl(url, "searchthread"); url += contextQuery; URLHelper.Redirect(url); } } } }