コード例 #1
0
        /// -----------------------------------------------------------------------------
        /// <summary>
        /// GetSearchResults gets the search results for a passed in criteria string
        /// </summary>
        /// <remarks>
        /// </remarks>
        /// <param name="portalId">A Id of the Portal</param>
        /// <param name="criteria">The criteria string</param>
        /// <history>
        ///		[cnurse]	11/15/2004	documented
        /// </history>
        /// -----------------------------------------------------------------------------
        public override SearchResultsInfoCollection GetSearchResults(int portalId, string criteria)
        {
            bool hasExcluded  = Null.NullBoolean;
            bool hasMandatory = Null.NullBoolean;

            var        objPortalController = new PortalController();
            PortalInfo objPortal           = objPortalController.GetPortal(portalId);

            //Get the Settings for this Portal
            var portalSettings = new PortalSettings(objPortal);

            //We will assume that the content is in the locale of the Portal
            Hashtable commonWords = GetCommonWords(portalSettings.DefaultLanguage);

            //clean criteria
            criteria = criteria.ToLower();

            //split search criteria into words
            var searchWords = new SearchCriteriaCollection(criteria);

            var searchResults = new Dictionary <string, SearchResultsInfoCollection>();

            //dicResults is a Dictionary(Of SearchItemID, Dictionary(Of TabID, SearchResultsInfo)
            var dicResults = new Dictionary <int, Dictionary <int, SearchResultsInfo> >();

            //iterate through search criteria words
            foreach (SearchCriteria criterion in searchWords)
            {
                if (commonWords.ContainsKey(criterion.Criteria) == false || portalSettings.SearchIncludeCommon)
                {
                    if (!searchResults.ContainsKey(criterion.Criteria))
                    {
                        searchResults.Add(criterion.Criteria, SearchDataStoreController.GetSearchResults(portalId, criterion.Criteria));
                    }
                    if (searchResults.ContainsKey(criterion.Criteria))
                    {
                        foreach (SearchResultsInfo result in searchResults[criterion.Criteria])
                        {
                            //Add results to dicResults
                            if (!criterion.MustExclude)
                            {
                                if (dicResults.ContainsKey(result.SearchItemID))
                                {
                                    //The Dictionary exists for this SearchItemID already so look in the TabId keyed Sub-Dictionary
                                    Dictionary <int, SearchResultsInfo> dic = dicResults[result.SearchItemID];
                                    if (dic.ContainsKey(result.TabId))
                                    {
                                        //The sub-Dictionary contains the item already so update the relevance
                                        SearchResultsInfo searchResult = dic[result.TabId];
                                        searchResult.Relevance += result.Relevance;
                                    }
                                    else
                                    {
                                        //Add Entry to Sub-Dictionary
                                        dic.Add(result.TabId, result);
                                    }
                                }
                                else
                                {
                                    //Create new TabId keyed Dictionary
                                    var dic = new Dictionary <int, SearchResultsInfo>();
                                    dic.Add(result.TabId, result);

                                    //Add new Dictionary to SearchResults
                                    dicResults.Add(result.SearchItemID, dic);
                                }
                            }
                        }
                    }
                }
            }
            foreach (SearchCriteria criterion in searchWords)
            {
                var mandatoryResults = new Dictionary <int, bool>();
                var excludedResults  = new Dictionary <int, bool>();
                if (searchResults.ContainsKey(criterion.Criteria))
                {
                    foreach (SearchResultsInfo result in searchResults[criterion.Criteria])
                    {
                        if (criterion.MustInclude)
                        {
                            //Add to mandatory results lookup
                            mandatoryResults[result.SearchItemID] = true;
                            hasMandatory = true;
                        }
                        else if (criterion.MustExclude)
                        {
                            //Add to exclude results lookup
                            excludedResults[result.SearchItemID] = true;
                            hasExcluded = true;
                        }
                    }
                }
                foreach (KeyValuePair <int, Dictionary <int, SearchResultsInfo> > kvpResults in dicResults)
                {
                    //The key of this collection is the SearchItemID,  Check if the value of this collection should be processed
                    if (hasMandatory && (!mandatoryResults.ContainsKey(kvpResults.Key)))
                    {
                        //1. If mandatoryResults exist then only process if in mandatoryResults Collection
                        foreach (SearchResultsInfo result in kvpResults.Value.Values)
                        {
                            result.Delete = true;
                        }
                    }
                    else if (hasExcluded && (excludedResults.ContainsKey(kvpResults.Key)))
                    {
                        //2. Do not process results in the excludedResults Collection
                        foreach (SearchResultsInfo result in kvpResults.Value.Values)
                        {
                            result.Delete = true;
                        }
                    }
                }
            }

            //Process results against permissions and mandatory and excluded results
            var results          = new SearchResultsInfoCollection();
            var objTabController = new TabController();

            foreach (KeyValuePair <int, Dictionary <int, SearchResultsInfo> > kvpResults in dicResults)
            {
                foreach (SearchResultsInfo result in kvpResults.Value.Values)
                {
                    if (!result.Delete)
                    {
                        //Check If authorised to View Tab
                        TabInfo objTab = objTabController.GetTab(result.TabId, portalId, false);
                        if (TabPermissionController.CanViewPage(objTab))
                        {
                            //Check If authorised to View Module
                            ModuleInfo objModule = new ModuleController().GetModule(result.ModuleId, result.TabId, false);
                            if (ModulePermissionController.CanViewModule(objModule))
                            {
                                results.Add(result);
                            }
                        }
                    }
                }
            }

            //Return Search Results Collection
            return(results);
        }
コード例 #2
0
        public override List <UrlRule> GetRules(int PortalId)
        {
            bool useKeyWords    = GetPortalSettingAsBoolean(PortalId, "UseKeyWords");
            bool RemoveHomePage = GetPortalSettingAsBoolean(PortalId, "RemoveHomePage");


            List <UrlRule> Rules            = new List <UrlRule>();
            TabController  tc               = new TabController();
            Locale         DefaultLocale    = LocaleController.Instance.GetDefaultLocale(PortalId);
            PortalInfo     objPortal        = new PortalController().GetPortal(PortalId, DefaultLocale.Code);
            int            DefaultHomeTabId = -1;

            if (objPortal != null)
            {
                DefaultHomeTabId = objPortal.HomeTabId;
            }


            var tabs = tc.GetTabsByPortal(PortalId).Values;

            foreach (TabInfo tab in tabs)
            {
                if (/*tab.PortalID > -1 && !tab.TabPath.StartsWith(@"//Admin//") && tab.TabPath != @"//Admin" &&*/ !tab.DisableLink /*&& tab.TabType == TabType.Normal*/ && !tab.IsDeleted)
                {
                    bool RemoveTab        = RemoveHomePage && tab.TabID == DefaultHomeTabId;
                    bool MLNeutralHomeTab = LocaleController.Instance.GetLocales(PortalId).Count > 1 &&
                                            tab.TabID == DefaultHomeTabId && string.IsNullOrEmpty(tab.CultureCode);



                    var rule = new UrlRule
                    {
                        RuleType    = UrlRuleType.Tab,
                        CultureCode = tab.CultureCode,
                        TabId       = tab.TabID,
                        Parameters  = "tabid=" + tab.TabID.ToString(),
                        Action      = UrlRuleAction.Rewrite,
                        Url         = CleanupUrl(GetTabUrl(tab, useKeyWords)),
                        RemoveTab   = RemoveTab && !MLNeutralHomeTab
                    };

                    TabInfo parentTab = tab;
                    while (parentTab.ParentId != Null.NullInteger)
                    {
                        parentTab = tc.GetTab(parentTab.ParentId, PortalId, false);
                        rule.Url  = CleanupUrl(GetTabUrl(parentTab, useKeyWords)) + "/" + rule.Url;
                    }
#if DNN71
                    var tabUrl = tab.TabUrls.SingleOrDefault(t => /*t.IsSystem
                                                                   * &&*/t.HttpStatus == "200" &&
                                                             t.SeqNum == 0);
                    if (tabUrl != null && tabUrl.Url.Trim('/') != "")
                    {
                        rule.Url = tabUrl.Url.Trim('/');
                    }
#endif

                    if (tab.TabType != TabType.Normal)
                    {
                        string redirUrl = "";
                        switch (tab.TabType)
                        {
                        case TabType.Tab:
                            //Get the tab being linked to
                            TabInfo tempTab = new TabController().GetTab(Int32.Parse(tab.Url), tab.PortalID, false);
                            redirUrl = tempTab.TabPath.Replace("//", "/").Substring(1);
                            break;

                        case TabType.File:
                            //var file = FileManager.Instance.GetFile(Int32.Parse(tab.Url.Substring(7)));
                            //tabUrl = file.RelativePath;
                            break;

                        case TabType.Url:
                            redirUrl = tab.Url;
                            break;
                        }
                        rule.Action              = UrlRuleAction.Redirect;
                        rule.RedirectStatus      = tab.PermanentRedirect ? 301 : 302;
                        rule.RedirectDestination = redirUrl;
                    }


                    Rules.Add(rule);
                    var ruleRedirect = new UrlRule
                    {
                        RuleType            = UrlRuleType.Tab,
                        CultureCode         = tab.CultureCode,
                        TabId               = tab.TabID,
                        Parameters          = "tabid=" + tab.TabID.ToString(),
                        Action              = UrlRuleAction.Redirect,
                        Url                 = tab.TabPath.Replace("//", "/").TrimStart('/').ToLower(),
                        RedirectDestination = rule.Url,
                        RemoveTab           = RemoveTab && !MLNeutralHomeTab
                    };
                    if (rule.Url != ruleRedirect.Url)
                    {
                        Rules.Add(ruleRedirect);
                    }

                    // if RemoveTab for multi-language and neutral home page
                    // add a culture specific rewrite
                    if (RemoveTab && MLNeutralHomeTab)
                    {
                        var ruleNeutral = new UrlRule
                        {
                            RuleType    = UrlRuleType.Tab,
                            CultureCode = DefaultLocale.Code,
                            TabId       = tab.TabID,
                            Parameters  = rule.Parameters,
                            Action      = UrlRuleAction.Rewrite,
                            Url         = rule.Url,
                            RemoveTab   = true
                        };
                        Rules.Add(ruleNeutral);
                        var ruleRedirectNeutral = new UrlRule
                        {
                            RuleType            = UrlRuleType.Tab,
                            CultureCode         = DefaultLocale.Code,
                            TabId               = tab.TabID,
                            Parameters          = ruleRedirect.Parameters,
                            Action              = UrlRuleAction.Redirect,
                            Url                 = ruleRedirect.Url,
                            RedirectDestination = ruleNeutral.Url,
                            RemoveTab           = true
                        };
                        if (ruleNeutral.Url != ruleRedirectNeutral.Url)
                        {
                            Rules.Add(ruleRedirectNeutral);
                        }
                    }
                }
            }
            return(Rules);
        }
コード例 #3
0
        private void SetSelectedPage()
        {
            string CultureCode = LocaleController.Instance.GetCurrentLocale(PortalId).Code;

            // try to set the selected item in the page dropdown.
            // if we have a cookie value for language x, we also try to select the right page
            // if the language switched to y
            if (Request.Cookies[PageSelectorCookieName] != null)
            {
                int     selectedPage;
                TabInfo tabInfo   = null;
                bool    goodValue = int.TryParse(Request.Cookies[PageSelectorCookieName].Value, out selectedPage);
                if (goodValue)
                {
                    tabInfo = _tabController.GetTab(selectedPage, PortalId, false);
                    if (tabInfo.IsDeleted)
                    {
                        tabInfo = null;
                        Response.Cookies.Remove(PageSelectorCookieName);
                    }
                }
                if (tabInfo == null)
                {
                    tabInfo = _tabController.GetTab(PortalSettings.HomeTabId, PortalId, false);
                }
                goodValue = (tabInfo != null);
                if (goodValue)
                {
                    if (tabInfo.CultureCode == CultureCode)
                    {
                        ddlPages.SelectedPage = tabInfo;
                    }
                    else
                    {
                        if (tabInfo.DefaultLanguageTab != null)
                        {
                            if (tabInfo.DefaultLanguageTab.CultureCode == CultureCode)
                            {
                                ddlPages.SelectedPage = tabInfo;
                            }
                            else
                            {
                                foreach (var tabKV in tabInfo.DefaultLanguageTab.LocalizedTabs.Where(tabKV => tabKV.Value.CultureCode == CultureCode))
                                {
                                    ddlPages.SelectedPage = tabKV.Value;
                                    break;
                                }
                            }
                        }
                        else if (tabInfo.LocalizedTabs != null)
                        {
                            foreach (var tabKV in tabInfo.LocalizedTabs.Where(tabKV => tabKV.Value.CultureCode == CultureCode))
                            {
                                ddlPages.SelectedPage = tabKV.Value;
                                break;
                            }
                        }
                    }
                }
            }
        }
コード例 #4
0
        public PortalSettings CreatePortalSettings(int portalAliasID, int tabID)
        {
            var cacheKey = "EventsPortalSettings" + portalAliasID;
            var ps       = new PortalSettings();
            var pscache  = (PortalSettings)DataCache.GetCache(cacheKey);

            if (ReferenceEquals(pscache, null))
            {
                // Setup PortalSettings
                var objPortalAliases = new PortalAliasController();
                var objPortalAlias   = default(PortalAliasInfo);

                objPortalAlias = objPortalAliases.GetPortalAliasByPortalAliasID(portalAliasID);
                if (ReferenceEquals(objPortalAlias, null))
                {
                    return(null);
                }
                var portalController = new PortalController();
                var portal           = portalController.GetPortal(objPortalAlias.PortalID);


                ps.PortalAlias           = objPortalAlias;
                ps.PortalId              = portal.PortalID;
                ps.PortalName            = portal.PortalName;
                ps.LogoFile              = portal.LogoFile;
                ps.FooterText            = portal.FooterText;
                ps.ExpiryDate            = portal.ExpiryDate;
                ps.UserRegistration      = portal.UserRegistration;
                ps.BannerAdvertising     = portal.BannerAdvertising;
                ps.Currency              = portal.Currency;
                ps.AdministratorId       = portal.AdministratorId;
                ps.Email                 = portal.Email;
                ps.HostFee               = portal.HostFee;
                ps.HostSpace             = portal.HostSpace;
                ps.PageQuota             = portal.PageQuota;
                ps.UserQuota             = portal.UserQuota;
                ps.AdministratorRoleId   = portal.AdministratorRoleId;
                ps.AdministratorRoleName = portal.AdministratorRoleName;
                ps.RegisteredRoleId      = portal.RegisteredRoleId;
                ps.RegisteredRoleName    = portal.RegisteredRoleName;
                ps.Description           = portal.Description;
                ps.KeyWords              = portal.KeyWords;
                ps.BackgroundFile        = portal.BackgroundFile;
                ps.GUID            = portal.GUID;
                ps.SiteLogHistory  = portal.SiteLogHistory;
                ps.AdminTabId      = portal.AdminTabId;
                ps.SuperTabId      = portal.SuperTabId;
                ps.SplashTabId     = portal.SuperTabId;
                ps.HomeTabId       = portal.HomeTabId;
                ps.LoginTabId      = portal.LoginTabId;
                ps.UserTabId       = portal.UserTabId;
                ps.DefaultLanguage = portal.DefaultLanguage;
                ps.Pages           = portal.Pages;
                ps.Users           = portal.Users;
                if (ps.HostSpace == null)
                {
                    ps.HostSpace = 0;
                }
                if (ReferenceEquals(ps.DefaultLanguage, null))
                {
                    ps.DefaultLanguage = Localization.SystemLocale;
                }
                if (ReferenceEquals(ps.TimeZone, null))
                {
                    ps.TimeZone = TimeZoneInfo.FindSystemTimeZoneById(Localization.SystemTimeZone);
                }
                ps.HomeDirectory = Globals.ApplicationPath + "/" + portal.HomeDirectory + "/";
                DataCache.SetCache(cacheKey, ps);
            }
            else
            {
                ps = pscache;
            }
            var tabController = new TabController();
            var tab           = tabController.GetTab(tabID, ps.PortalId, false);

            if (ReferenceEquals(tab, null))
            {
                return(null);
            }
            ps.ActiveTab = tab;

            try
            {
                // Now to put it into the HTTPContext
                if (ReferenceEquals(HttpContext.Current, null))
                {
                    var        page          = ps.PortalAlias.HTTPAlias;
                    var        query         = string.Empty;
                    TextWriter output        = null;
                    var        workerrequest = new SimpleWorkerRequest(page, query, output);
                    HttpContext.Current = new HttpContext(workerrequest);
                    HttpContext.Current.Items.Add("PortalSettings", ps);
                }
                else
                {
                    HttpContext.Current.Items.Remove("PortalSettings");
                    HttpContext.Current.Items.Add("PortalSettings", ps);
                }
            }
            catch (Exception)
            { }

            return(ps);
        }