/// <summary> /// This method /// </summary> /// <param name="channelName"></param> /// <param name="userName"></param> /// <remarks></remarks> protected override void PopulateChannel(string channelName, string userName) { var objModules = new ModuleController(); ModuleInfo objModule; if (Request == null || Settings == null || Settings.ActiveTab == null || ModuleId == Null.NullInteger) { return; } Channel["title"] = Settings.PortalName; Channel["link"] = Globals.AddHTTP(Globals.GetDomainName(Request)); if (!String.IsNullOrEmpty(Settings.Description)) { Channel["description"] = Settings.Description; } else { Channel["description"] = Settings.PortalName; } Channel["language"] = Settings.DefaultLanguage; Channel["copyright"] = !string.IsNullOrEmpty(Settings.FooterText) ? Settings.FooterText.Replace("[year]", DateTime.Now.Year.ToString()) : string.Empty; Channel["webMaster"] = Settings.Email; SearchResultsInfoCollection searchResults = null; try { searchResults = SearchDataStoreProvider.Instance().GetSearchItems(Settings.PortalId, TabId, ModuleId); } catch (Exception ex) { Exceptions.Exceptions.LogException(ex); } if (searchResults != null) { foreach (SearchResultsInfo objResult in searchResults) { if (TabPermissionController.CanViewPage()) { if (Settings.ActiveTab.StartDate < DateTime.Now && Settings.ActiveTab.EndDate > DateTime.Now) { objModule = objModules.GetModule(objResult.ModuleId, objResult.TabId); if (objModule != null && objModule.DisplaySyndicate && objModule.IsDeleted == false) { if (ModulePermissionController.CanViewModule(objModule)) { if (Convert.ToDateTime(objModule.StartDate == Null.NullDate ? DateTime.MinValue : objModule.StartDate) < DateTime.Now && Convert.ToDateTime(objModule.EndDate == Null.NullDate ? DateTime.MaxValue : objModule.EndDate) > DateTime.Now) { Channel.Items.Add(GetRssItem(objResult)); } } } } } } } }
private SearchResultsInfoCollection Search(int categoryId, string criteria) { SearchResultsInfoCollection results = null; try { //this will apply thenormal security search, //filtering out anything that shouldn't be displayed based on permissions results = SearchDataStoreProvider.Instance().GetSearchResults(PortalId, criteria); //will contain all the articles beneath the given category or subcategory IDictionary articles = new Hashtable(); DataTable dt; if (categoryId == -1) { dt = Article.GetArticles(PortalId); } else { DataSet ds = Item.GetAllChildren(ItemType.Article.GetId(), categoryId, Util.RelationshipType.ItemToParentCategory.GetId(), Util.RelationshipType.ItemToRelatedCategory.GetId(), PortalId); dt = ds.Tables[0]; } foreach (DataRow row in dt.Rows) { int articleId = Convert.ToInt32(row["ItemId"], CultureInfo.InvariantCulture); if (articles.Contains(articleId) == false) { articles.Add(articleId, null); } } //now filter out anything not in the list of articles beneath the given category var al = new ArrayList(); foreach (SearchResultsInfo result in results) { int articleId = Utility.GetArticleId(result); if (articles.Contains(articleId) == false || articleId == 0) { //remove this row from the results al.Add(result); } } foreach (SearchResultsInfo result in al) { results.Remove(result); } } catch (Exception ex) { DotNetNuke.Services.Exceptions.Exceptions.ProcessModuleLoadException(this, ex); } return(results); }
public override SearchResultsInfoCollection GetSearchResults(int portalId, string criteria) { SearchResultsInfoCollection results = base.GetSearchResults(portalId, criteria); SecurityFilter sf = SecurityFilter.Instance; sf.FilterArticles(results); CleanSearchList(results); return(results); }
public override SearchResultsInfoCollection GetSearchItems(int portalId, int tabId, int moduleId) { // TODO: need to filter this also? // how is this invoked? do we need to filter? SearchResultsInfoCollection results = base.GetSearchItems(portalId, tabId, moduleId); // SecurityFilter sf = SecurityFilter.Instance; // return sf.FilterArticles(results); return(results); }
public static SearchResultsInfoCollection CleanSearchList(SearchResultsInfoCollection data) { // get rid of the duplicates // some conditions that we don't need to bother if (data == null || data.Count == 0) { return(data); } IDictionary d = new Hashtable(); var al = new ArrayList(); foreach (SearchResultsInfo result in data) { // IDictionary listOfIds = GetSearchArticleIds(data); int articleId = Utility.GetArticleId(result); if (d.Contains(articleId)) { // remove this row from the results al.Add(result); } else { d.Add(articleId, null); } } // remove all the rows that I'm not allowed to see foreach (SearchResultsInfo result in al) { data.Remove(result); } return(data); }
private int BindSearchResults(DataTable dt) { SearchResultsInfoCollection Results = SearchDataStoreProvider.Instance().GetSearchResults(PortalId, _SearchQuery); //Get the maximum items to display int maxItems = 0; if (!String.IsNullOrEmpty(Convert.ToString(Settings["maxresults"]))) { maxItems = int.Parse(Convert.ToString(Settings["maxresults"])); } else { maxItems = Results.Count; } if (Results.Count < maxItems || maxItems < 1) { maxItems = Results.Count; } //Get the titlelength/descriptionlength int titleLength = 0; if (!String.IsNullOrEmpty(Convert.ToString(Settings["titlelength"]))) { titleLength = int.Parse(Convert.ToString(Settings["titlelength"])); } int descLength = 0; if (!String.IsNullOrEmpty(Convert.ToString(Settings["descriptionlength"]))) { descLength = int.Parse(Convert.ToString(Settings["descriptionlength"])); } int i = 0; SearchResultsInfo ResultItem; for (i = 0; i <= maxItems - 1; i++) { ResultItem = Results[i]; DataRow dr = dt.NewRow(); dr["TabId"] = ResultItem.TabId; dr["Guid"] = ResultItem.Guid; if (titleLength > 0 && titleLength < ResultItem.Title.Length) { dr["Title"] = ResultItem.Title.Substring(0, titleLength); } else { dr["Title"] = ResultItem.Title; } dr["Relevance"] = ResultItem.Relevance; if (descLength > 0 && descLength < ResultItem.Description.Length) { dr["Description"] = ResultItem.Description.Substring(0, descLength); } else { dr["Description"] = ResultItem.Description; } dr["PubDate"] = ResultItem.PubDate; dt.Rows.Add(dr); } return(Results.Count); }
private void BindData() { object o; var results = new SearchResultsInfoCollection(); if (ddlCategoryList.SelectedIndex == 0) { o = Settings["csCategoryId"]; if (o != null) { int categoryOption; if (int.TryParse(o.ToString(), out categoryOption)) { results = Search(categoryOption, txtCategorySearch.Text.Trim()); } } } else { results = Search(Convert.ToInt32(ddlCategoryList.SelectedValue, CultureInfo.InvariantCulture), txtCategorySearch.Text.Trim()); } var dt = new DataTable { Locale = CultureInfo.InvariantCulture }; //DataColumn dc = new DataColumn("TabId"); dt.Columns.Add(new DataColumn("TabId", typeof(int))); dt.Columns.Add(new DataColumn("Guid", typeof(string))); dt.Columns.Add(new DataColumn("Title", typeof(string))); dt.Columns.Add(new DataColumn("Relevance", typeof(int))); dt.Columns.Add(new DataColumn("Description", typeof(string))); dt.Columns.Add(new DataColumn("PubDate", typeof(DateTime))); //Get the maximum items to display int maxItems; o = Settings["csMaxResults"]; if (o == null || !int.TryParse(o.ToString(), out maxItems)) { maxItems = results.Count; } if (results.Count < maxItems || maxItems < 1) { maxItems = results.Count; } int itemsPage = 10; o = Settings["csPerPage"]; if (o != null) { //itemsPage = Convert.ToInt32(Settings["perpage"]); if (!int.TryParse(o.ToString(), out itemsPage)) { itemsPage = 10; } } int titleLength = 0; o = Settings["csTitleLength"]; if (o != null) { if (!int.TryParse(o.ToString(), out titleLength)) { titleLength = 10; } } int descLength = 0; o = Settings["csDescriptionLength"]; if (o != null) { if (!int.TryParse(o.ToString(), out descLength)) { descLength = 10; } } for (int i = 0; i < maxItems; i++) { SearchResultsInfo resultItem = results[i]; DataRow dr = dt.NewRow(); dr["TabId"] = resultItem.TabId; dr["Guid"] = resultItem.Guid; if (titleLength > 0 && titleLength < resultItem.Title.Length) { dr["Title"] = resultItem.Title.Substring(0, titleLength); } else { dr["Title"] = resultItem.Title; } dr["Relevance"] = resultItem.Relevance; if (descLength > 0 && descLength < resultItem.Description.Length) { dr["Description"] = resultItem.Description.Substring(0, descLength); } else { dr["Description"] = resultItem.Description; } dr["PubDate"] = resultItem.PubDate; dt.Rows.Add(dr); } using (var dv = new DataView(dt)) { dv.Sort = "Relevance DESC"; if (itemsPage < 1) { dgResults.AllowPaging = false; dgResults.PagerStyle.Visible = false; } else { dgResults.PageSize = itemsPage; dgResults.PagerStyle.Visible = results.Count >= dgResults.PageSize; } dgResults.DataSource = dv; dgResults.DataBind(); dgResults.Visible = results.Count != 0; lblNoResults.Visible = results.Count == 0; } }
public override void FilterArticles(SearchResultsInfoCollection data) { Debug.Assert(data != null, "data must not be null"); // does nothing }
/// <summary> /// BindData binds the Search Results to the Grid /// </summary> /// <history> /// [cnurse] 12/13/2004 created /// </history> private void BindData() { SearchResultsInfoCollection Results = SearchDataStoreProvider.Instance().GetSearchResults(PortalId, _searchQuery); DataTable dt = new DataTable(); DataColumn dc = new DataColumn("TabId"); dt.Columns.Add(new DataColumn("TabId", typeof(Int32))); dt.Columns.Add(new DataColumn("Guid", typeof(String))); dt.Columns.Add(new DataColumn("Title", typeof(String))); dt.Columns.Add(new DataColumn("Relevance", typeof(Int32))); dt.Columns.Add(new DataColumn("Description", typeof(String))); dt.Columns.Add(new DataColumn("PubDate", typeof(DateTime))); dt.Columns.Add(new DataColumn("SearchKey", typeof(String))); //Get the maximum items to display int maxItems = 0; if (Convert.ToString(Settings["maxresults"]) != "") { maxItems = int.Parse(Convert.ToString(Settings["maxresults"])); } else { maxItems = Results.Count; } if (Results.Count < maxItems || maxItems < 1) { maxItems = Results.Count; } //Get the items/page to display int itemsPage = 10; if (Convert.ToString(Settings["perpage"]) != "") { itemsPage = int.Parse(Convert.ToString(Settings["perpage"])); } //Get the titlelength/descriptionlength int titleLength = 0; if (Convert.ToString(Settings["titlelength"]) != "") { titleLength = int.Parse(Convert.ToString(Settings["titlelength"])); } int descLength = 0; if (Convert.ToString(Settings["descriptionlength"]) != "") { descLength = int.Parse(Convert.ToString(Settings["descriptionlength"])); } int i = 0; SearchResultsInfo ResultItem; for (i = 0; i <= maxItems - 1; i++) { ResultItem = Results[i]; DataRow dr = dt.NewRow(); dr["TabId"] = ResultItem.TabId; dr["Guid"] = ResultItem.Guid; dr["SearchKey"] = ResultItem.SearchKey; if (titleLength > 0 && titleLength < ResultItem.Title.Length) { dr["Title"] = ResultItem.Title.Substring(0, titleLength); } else { dr["Title"] = ResultItem.Title; } dr["Relevance"] = ResultItem.Relevance; if (descLength > 0 && descLength < ResultItem.Description.Length) { dr["Description"] = ResultItem.Description.Substring(0, descLength); } else { dr["Description"] = ResultItem.Description; } dr["PubDate"] = ResultItem.PubDate; dt.Rows.Add(dr); } //Bind Search Results Grid DataView dv = new DataView(dt); dv.Sort = "Relevance DESC"; dgResults.PageSize = itemsPage; dgResults.DataSource = dv; dgResults.DataBind(); if (Results.Count == 0) { dgResults.Visible = false; } if (Results.Count <= dgResults.PageSize) { dgResults.PagerStyle.Visible = false; } else { dgResults.PagerStyle.Visible = true; } }
public abstract void FilterArticles(SearchResultsInfoCollection data);
/// <summary> /// Builds RSS Channel /// </summary> /// <returns></returns> /// <remarks> /// ---Corrected link elment to use prefix 'http://' & current request context. /// </remarks> /// <history>Sat, 26 Feb 2005 Phil Guerra /// </history> private string BuildRSS(int PortalId, int TabId, int ModuleId) { ModuleController objModules = new ModuleController(); ModuleInfo objModule; StringBuilder sb = new StringBuilder(1024); // build header sb.Append("<?xml version=\"1.0\" ?>" + "\r\n"); sb.Append("<rss version=\"2.0\""); sb.Append(" xmlns:dc=\"http://purl.org/dc/elements/1.1/\">" + "\r\n"); // build channel sb.Append(WriteElement("channel", 1)); sb.Append(WriteElement("title", PortalSettings.PortalName, 2)); // pmg - This line was updated to correct the link item. // We are making the assumption that the current context of the // request has the desired link to the Portal. Even though there // may be more than 1 portalAlias, this should be correct. If not, // we'll have to revisit. // sb.Append(WriteElement("link", Request.Url.Host, 2)) sb.Append(WriteElement("link", Globals.AddHTTP(Globals.GetDomainName(HttpContext.Current.Request)), 2)); if (!String.IsNullOrEmpty(PortalSettings.Description)) { sb.Append(WriteElement("description", PortalSettings.Description, 2)); } else { sb.Append(WriteElement("description", PortalSettings.PortalName, 2)); } sb.Append(WriteElement("language", PortalSettings.DefaultLanguage, 2)); sb.Append(WriteElement("copyright", PortalSettings.FooterText, 2)); sb.Append(WriteElement("webMaster", PortalSettings.Email, 2)); // build items SearchResultsInfoCollection objResults = SearchDataStoreProvider.Instance().GetSearchItems(PortalId, TabId, ModuleId); SearchResultsInfo objResult; foreach (SearchResultsInfo tempLoopVar_objResult in objResults) { objResult = tempLoopVar_objResult; if (PortalSecurity.IsInRoles(PortalSettings.ActiveTab.AuthorizedRoles)) { if (PortalSettings.ActiveTab.StartDate < DateTime.Now && PortalSettings.ActiveTab.EndDate > DateTime.Now) { objModule = objModules.GetModule(objResult.ModuleId, objResult.TabId); if (objModule.DisplaySyndicate == true && objModule.IsDeleted == false) { if (PortalSecurity.IsInRoles(objModule.AuthorizedViewRoles) == true) { if (Convert.ToDateTime(objModule.StartDate == Null.NullDate ? DateTime.MinValue : objModule.StartDate) < DateTime.Now && Convert.ToDateTime(objModule.EndDate == Null.NullDate ? DateTime.MaxValue : objModule.EndDate) > DateTime.Now) { sb.Append(BuildItem(objResult, 2)); } } } } } } // close document sb.Append(WriteElement("/channel", 1)); sb.Append("</rss>"); return(sb.ToString()); }
// public static SearchResultsInfoCollection2 GetSearchResults(int PortalID, string Word) //{ // return new DotNetNuke.Services.Search.SearchResultsInfoCollection2(CBO.FillCollection(DataProvider.Instance().GetSearchResults(PortalID, Word), typeof(SearchResultsInfo2))); // } private int BindSearchResults(DataTable dt) { //StaffBroker.StaffBrokerDataContext d = new StaffBroker.StaffBrokerDataContext(); //SearchResultsInfoCollection2 Results = SearchDataStore2.Instance().GetSearchResults(PortalId, _SearchQuery); SearchResultsInfoCollection Results = SearchDataStoreProvider.Instance().GetSearchResults(PortalId, _SearchQuery); //Get the maximum items to display int maxItems = 0; if (!String.IsNullOrEmpty(Convert.ToString(Settings["maxresults"]))) { maxItems = int.Parse(Convert.ToString(Settings["maxresults"])); } else { maxItems = Results.Count; } if (Results.Count < maxItems || maxItems < 1) { maxItems = Results.Count; } //Get the titlelength/descriptionlength int titleLength = 0; if (!String.IsNullOrEmpty(Convert.ToString(Settings["titlelength"]))) { titleLength = int.Parse(Convert.ToString(Settings["titlelength"])); } int descLength = 0; if (!String.IsNullOrEmpty(Convert.ToString(Settings["descriptionlength"]))) { descLength = int.Parse(Convert.ToString(Settings["descriptionlength"])); } int i = 0; SearchResultsInfo ResultItem; // for (i = 0; i <= maxItems - 1; i++) while (dt.Rows.Count < maxItems && i < Results.Count) { ResultItem = Results[i]; string filter = ""; if (Request.Params["Filter"] != null) { filter = Request.Params["Filter"]; } if (filter == "" || (filter.ToLower() == "stories" && ResultItem.SearchKey.StartsWith("S")) || (filter.ToLower() == "docs" && ResultItem.SearchKey.StartsWith("D"))) { DataRow dr = dt.NewRow(); dr["TabId"] = ResultItem.TabId; dr["Guid"] = ResultItem.Guid; if (titleLength > 0 && titleLength < ResultItem.Title.Length) { dr["Title"] = ResultItem.Title.Substring(0, titleLength); } else { dr["Title"] = ResultItem.Title; } dr["Relevance"] = ResultItem.Relevance; if (descLength > 0 && descLength < ResultItem.Description.Length) { dr["Description"] = ResultItem.Description.Substring(0, descLength); } else { dr["Description"] = ResultItem.Description; } dr["PubDate"] = ResultItem.PubDate; dr["Image"] = ""; try { if (ResultItem.Image > 0) { var img = DotNetNuke.Services.FileSystem.FileManager.Instance.GetFile(ResultItem.Image); if (!(img == null)) { var imgURL = DotNetNuke.Services.FileSystem.FileManager.Instance.GetUrl(img); dr["Image"] = imgURL; } } } catch (Exception) { } dr["SearchKey"] = ResultItem.SearchKey; dr["AuthorName"] = ResultItem.AuthorName; dt.Rows.Add(dr); } i++; } return(Results.Count); }
public abstract void FilterArticles(SearchResultsInfoCollection data, int portalId);