From 1f03a7120deae4cb8388de2e354eb7ff6c331228 Mon Sep 17 00:00:00 2001 From: Suha Can Date: Tue, 8 Jun 2010 16:25:56 -0700 Subject: [PATCH 1/3] - Changing where we alter type definitions in the setup service so the types can be initialized with the right parts. --HG-- branch : dev --- .../Modules/Orchard.Setup/Services/SetupService.cs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/Orchard.Web/Modules/Orchard.Setup/Services/SetupService.cs b/src/Orchard.Web/Modules/Orchard.Setup/Services/SetupService.cs index c90170629..d8ca32bbe 100644 --- a/src/Orchard.Web/Modules/Orchard.Setup/Services/SetupService.cs +++ b/src/Orchard.Web/Modules/Orchard.Setup/Services/SetupService.cs @@ -148,6 +148,11 @@ namespace Orchard.Setup.Services { //var hackInstallationGenerator = environment.Resolve(); //hackInstallationGenerator.GenerateInstallEvents(); + var contentDefinitionManager = environment.Resolve(); + contentDefinitionManager.AlterTypeDefinition("blogpost", cfg => cfg.WithPart("HasComments").WithPart("HasTags").WithPart("Localized")); + contentDefinitionManager.AlterTypeDefinition("page", cfg => cfg.WithPart("HasComments").WithPart("HasTags").WithPart("Localized")); + contentDefinitionManager.AlterTypeDefinition("sandboxpage", cfg => cfg.WithPart("HasComments").WithPart("HasTags").WithPart("Localized")); + // create home page as a CMS page var page = contentManager.Create("page", VersionOptions.Draft); page.As().Text = "

Welcome to Orchard!

Congratulations, you've successfully set-up your Orchard site.

This is the home page of your new site. We've taken the liberty to write here about a few things you could look at next in order to get familiar with the application. Once you feel confident you don't need this anymore, just click Edit to go into edit mode and replace this with whatever you want on your home page to make it your own.

One thing you could do (but you don't have to) is go into Manage Settings (follow the Admin link and then look for it under \"Settings\" in the menu on the left) and check that everything is configured the way you want.

You probably want to make the site your own. One of the ways you can do that is by clicking Manage Themes in the admin menu. A theme is a packaged look and feel that affects the whole site.

Next, you can start playing with the content types that we installed. For example, go ahead and click Add New Page in the admin menu and create an \"about\" page. Then, add it to the navigation menu by going to Manage Menu. You can also click Add New Blog and start posting by clicking \"Add New Post\".

Finally, Orchard has been designed to be extended. It comes with a few built-in modules such as pages and blogs or themes. You can install new themes by going to Manage Themes and clicking Install a new Theme. Like for themes, modules are created by other users of Orchard just like you so if you feel up to it, please consider participating.

--The Orchard Crew

"; @@ -172,11 +177,6 @@ namespace Orchard.Setup.Services { var authenticationService = environment.Resolve(); authenticationService.SignIn(user, true); } - - var contentDefinitionManager = environment.Resolve(); - contentDefinitionManager.AlterTypeDefinition("blogpost", cfg => cfg.WithPart("HasComments").WithPart("HasTags").WithPart("Localized")); - contentDefinitionManager.AlterTypeDefinition("page", cfg => cfg.WithPart("HasComments").WithPart("HasTags").WithPart("Localized")); - contentDefinitionManager.AlterTypeDefinition("sandboxpage", cfg => cfg.WithPart("HasComments").WithPart("HasTags").WithPart("Localized")); } catch { environment.Resolve().Cancel(); From 521b415f884b1e8c157a596821c36bc6e87bfd3e Mon Sep 17 00:00:00 2001 From: Suha Can Date: Tue, 8 Jun 2010 16:56:02 -0700 Subject: [PATCH 2/3] - Adding a method to the CultureManager to return the default site culture (as opposed to current culture) --HG-- branch : dev --- src/Orchard/ContentManagement/ContentField.cs | 6 +----- .../Localization/Services/DefaultCultureManager.cs | 9 ++++++++- src/Orchard/Localization/Services/ICultureManager.cs | 1 + 3 files changed, 10 insertions(+), 6 deletions(-) diff --git a/src/Orchard/ContentManagement/ContentField.cs b/src/Orchard/ContentManagement/ContentField.cs index 953c94953..671ac54fd 100644 --- a/src/Orchard/ContentManagement/ContentField.cs +++ b/src/Orchard/ContentManagement/ContentField.cs @@ -1,8 +1,4 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using Orchard.ContentManagement.MetaData.Models; +using Orchard.ContentManagement.MetaData.Models; namespace Orchard.ContentManagement { public class ContentField { diff --git a/src/Orchard/Localization/Services/DefaultCultureManager.cs b/src/Orchard/Localization/Services/DefaultCultureManager.cs index 30e9b3a20..58e6301f8 100644 --- a/src/Orchard/Localization/Services/DefaultCultureManager.cs +++ b/src/Orchard/Localization/Services/DefaultCultureManager.cs @@ -1,11 +1,12 @@ using System; using System.Collections.Generic; -using System.Globalization; using System.Linq; using System.Text.RegularExpressions; using System.Web; +using JetBrains.Annotations; using Orchard.Data; using Orchard.Localization.Records; +using Orchard.Settings; namespace Orchard.Localization.Services { public class DefaultCultureManager : ICultureManager { @@ -17,6 +18,8 @@ namespace Orchard.Localization.Services { _cultureSelectors = cultureSelectors; } + protected virtual ISite CurrentSite { get; [UsedImplicitly] private set; } + public IEnumerable ListCultures() { var query = from culture in _cultureRepository.Table select culture.Culture; return query.ToList(); @@ -51,6 +54,10 @@ namespace Orchard.Localization.Services { return _cultureRepository.Get(id); } + public string GetSiteCulture() { + return CurrentSite == null ? null : CurrentSite.SiteCulture; + } + // "" or // "-" or // "--" diff --git a/src/Orchard/Localization/Services/ICultureManager.cs b/src/Orchard/Localization/Services/ICultureManager.cs index a2864cd3c..5027105d1 100644 --- a/src/Orchard/Localization/Services/ICultureManager.cs +++ b/src/Orchard/Localization/Services/ICultureManager.cs @@ -8,5 +8,6 @@ namespace Orchard.Localization.Services { void AddCulture(string cultureName); string GetCurrentCulture(HttpContext requestContext); CultureRecord GetCultureById(int id); + string GetSiteCulture(); } } From ecabd554289fab95b1dbb73430f654ec2d361f31 Mon Sep 17 00:00:00 2001 From: Sebastien Ros Date: Tue, 8 Jun 2010 17:17:50 -0700 Subject: [PATCH 3/3] Localized content is indexed and searched. During indexation, the culture of the content item is store within the index. If this is the master content item, then the Site's culture is used. When the search query is created, a filter is applied on the current request's culture. --HG-- branch : dev --- .../Core/Localization/Handlers/LocalizedHandler.cs | 3 +++ .../Modules/Orchard.Search/Services/SearchService.cs | 10 +++++++++- 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/src/Orchard.Web/Core/Localization/Handlers/LocalizedHandler.cs b/src/Orchard.Web/Core/Localization/Handlers/LocalizedHandler.cs index 670e0e6f9..9a1ac701e 100644 --- a/src/Orchard.Web/Core/Localization/Handlers/LocalizedHandler.cs +++ b/src/Orchard.Web/Core/Localization/Handlers/LocalizedHandler.cs @@ -5,6 +5,7 @@ using Orchard.Localization; using Orchard.ContentManagement; using Orchard.ContentManagement.Handlers; using Orchard.Localization.Services; +using Orchard.Settings; namespace Orchard.Core.Localization.Handlers { [UsedImplicitly] @@ -22,6 +23,8 @@ namespace Orchard.Core.Localization.Handlers { OnActivated(InitializePart); OnLoaded(LazyLoadHandlers); + + OnIndexed((context, localized) => context.IndexDocument.Add("culture", localized.Culture != null ? localized.Culture.Culture : _cultureManager.GetSiteCulture()).Store(false).Analyze(false)); } public Localizer T { get; set; } diff --git a/src/Orchard.Web/Modules/Orchard.Search/Services/SearchService.cs b/src/Orchard.Web/Modules/Orchard.Search/Services/SearchService.cs index 289cd57ba..8ee7cab2d 100644 --- a/src/Orchard.Web/Modules/Orchard.Search/Services/SearchService.cs +++ b/src/Orchard.Web/Modules/Orchard.Search/Services/SearchService.cs @@ -4,8 +4,10 @@ using System.Linq; using Orchard.Collections; using Orchard.Indexing; using Orchard.Localization; +using Orchard.Localization.Services; using Orchard.Search.Models; using Orchard.UI.Notify; +using System.Web; namespace Orchard.Search.Services { @@ -14,11 +16,13 @@ namespace Orchard.Search.Services private const string SearchIndexName = "Search"; private readonly IIndexManager _indexManager; private readonly IEnumerable _indexNotifierHandlers; + private readonly ICultureManager _cultureManager; - public SearchService(IOrchardServices services, IIndexManager indexManager, IEnumerable indexNotifierHandlers) { + public SearchService(IOrchardServices services, IIndexManager indexManager, IEnumerable indexNotifierHandlers, ICultureManager cultureManager) { Services = services; _indexManager = indexManager; _indexNotifierHandlers = indexNotifierHandlers; + _cultureManager = cultureManager; T = NullLocalizer.Instance; } @@ -37,6 +41,10 @@ namespace Orchard.Search.Services .WithField("title", query) .WithField("body", query); + if(HttpContext.Current != null) { + searchBuilder.WithField("culture", _cultureManager.GetCurrentCulture(HttpContext.Current)); + } + var totalCount = searchBuilder.Count(); if (pageSize != null) searchBuilder = searchBuilder