mirror of
https://github.com/OrchardCMS/Orchard.git
synced 2025-10-15 19:54:57 +08:00
Merge pull request #5567 from OrchardCMS/issue/homepage-alias
Issue/homepage alias
This commit is contained in:
@@ -23,7 +23,7 @@ namespace Orchard.Alias {
|
|||||||
|
|
||||||
IEnumerable<Tuple<string, RouteValueDictionary>> List();
|
IEnumerable<Tuple<string, RouteValueDictionary>> List();
|
||||||
IEnumerable<Tuple<string, RouteValueDictionary, string>> List(string sourceStartsWith);
|
IEnumerable<Tuple<string, RouteValueDictionary, string>> List(string sourceStartsWith);
|
||||||
IEnumerable<VirtualPathData> LookupVirtualPaths(RouteValueDictionary routeValues, System.Web.HttpContextBase HttpContext);
|
IEnumerable<VirtualPathData> LookupVirtualPaths(RouteValueDictionary routeValues, System.Web.HttpContextBase httpContext);
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -4,11 +4,15 @@ using System.Linq;
|
|||||||
using Orchard.Alias;
|
using Orchard.Alias;
|
||||||
using Orchard.Autoroute.Models;
|
using Orchard.Autoroute.Models;
|
||||||
using Orchard.Autoroute.Services;
|
using Orchard.Autoroute.Services;
|
||||||
using Orchard.ContentManagement;
|
|
||||||
using Orchard.ContentManagement.Drivers;
|
|
||||||
using Orchard.Autoroute.ViewModels;
|
|
||||||
using Orchard.Autoroute.Settings;
|
using Orchard.Autoroute.Settings;
|
||||||
|
using Orchard.Autoroute.ViewModels;
|
||||||
|
using Orchard.ContentManagement;
|
||||||
|
using Orchard.ContentManagement.Aspects;
|
||||||
|
using Orchard.ContentManagement.Drivers;
|
||||||
|
using Orchard.ContentManagement.Handlers;
|
||||||
using Orchard.Localization;
|
using Orchard.Localization;
|
||||||
|
using Orchard.Localization.Services;
|
||||||
|
using Orchard.Mvc;
|
||||||
using Orchard.Security;
|
using Orchard.Security;
|
||||||
using Orchard.UI.Notify;
|
using Orchard.UI.Notify;
|
||||||
using Orchard.Utility.Extensions;
|
using Orchard.Utility.Extensions;
|
||||||
@@ -20,27 +24,29 @@ using Orchard.ContentManagement.Aspects;
|
|||||||
|
|
||||||
namespace Orchard.Autoroute.Drivers {
|
namespace Orchard.Autoroute.Drivers {
|
||||||
public class AutoroutePartDriver : ContentPartDriver<AutoroutePart> {
|
public class AutoroutePartDriver : ContentPartDriver<AutoroutePart> {
|
||||||
private readonly IAliasService _aliasService;
|
|
||||||
private readonly IContentManager _contentManager;
|
|
||||||
private readonly IAutorouteService _autorouteService;
|
private readonly IAutorouteService _autorouteService;
|
||||||
private readonly IAuthorizer _authorizer;
|
|
||||||
private readonly INotifier _notifier;
|
private readonly INotifier _notifier;
|
||||||
|
private readonly IHomeAliasService _homeAliasService;
|
||||||
|
private readonly IAliasService _aliasService;
|
||||||
private readonly ICultureManager _cultureManager;
|
private readonly ICultureManager _cultureManager;
|
||||||
private readonly IHttpContextAccessor _httpContextAccessor;
|
private readonly IHttpContextAccessor _httpContextAccessor;
|
||||||
|
private readonly IContentManager _contentManager;
|
||||||
|
|
||||||
public AutoroutePartDriver(
|
public AutoroutePartDriver(
|
||||||
IAliasService aliasService,
|
|
||||||
IContentManager contentManager,
|
|
||||||
IAutorouteService autorouteService,
|
IAutorouteService autorouteService,
|
||||||
IAuthorizer authorizer,
|
|
||||||
INotifier notifier,
|
INotifier notifier,
|
||||||
|
IHomeAliasService homeAliasService,
|
||||||
|
IAliasService aliasService,
|
||||||
|
IAuthorizer authorizer,
|
||||||
ICultureManager cultureManager,
|
ICultureManager cultureManager,
|
||||||
|
IContentManager contentManager,
|
||||||
IHttpContextAccessor httpContextAccessor) {
|
IHttpContextAccessor httpContextAccessor) {
|
||||||
|
|
||||||
_aliasService = aliasService;
|
_aliasService = aliasService;
|
||||||
_contentManager = contentManager;
|
_contentManager = contentManager;
|
||||||
_autorouteService = autorouteService;
|
_autorouteService = autorouteService;
|
||||||
_authorizer = authorizer;
|
|
||||||
_notifier = notifier;
|
_notifier = notifier;
|
||||||
|
_homeAliasService = homeAliasService;
|
||||||
_cultureManager = cultureManager;
|
_cultureManager = cultureManager;
|
||||||
_httpContextAccessor = httpContextAccessor;
|
_httpContextAccessor = httpContextAccessor;
|
||||||
|
|
||||||
@@ -57,42 +63,42 @@ namespace Orchard.Autoroute.Drivers {
|
|||||||
var settings = part.TypePartDefinition.Settings.GetModel<AutorouteSettings>();
|
var settings = part.TypePartDefinition.Settings.GetModel<AutorouteSettings>();
|
||||||
var itemCulture = _cultureManager.GetSiteCulture();
|
var itemCulture = _cultureManager.GetSiteCulture();
|
||||||
|
|
||||||
//if we are editing an existing content item
|
// If we are editing an existing content item, check to see if we are an ILocalizableAspect so we can use its culture for alias generation.
|
||||||
if (part.Record.Id != 0) {
|
if (part.Record.Id != 0) {
|
||||||
ContentItem contentItem = _contentManager.Get(part.Record.ContentItemRecord.Id);
|
var localizableAspect = part.As<ILocalizableAspect>();
|
||||||
var aspect = contentItem.As<ILocalizableAspect>();
|
|
||||||
|
|
||||||
if (aspect != null) {
|
if (localizableAspect != null) {
|
||||||
itemCulture = aspect.Culture;
|
itemCulture = localizableAspect.Culture;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (settings.UseCulturePattern) {
|
if (settings.UseCulturePattern) {
|
||||||
//if we are creating from a form post we use the form value for culture
|
// Hack: if the LocalizedPart is attached to the content item, it will submit the following form value,
|
||||||
HttpContextBase context = _httpContextAccessor.Current();
|
// which we use to determine what culture to use for alias generation.
|
||||||
|
var context = _httpContextAccessor.Current();
|
||||||
if (!String.IsNullOrEmpty(context.Request.Form["Localization.SelectedCulture"])) {
|
if (!String.IsNullOrEmpty(context.Request.Form["Localization.SelectedCulture"])) {
|
||||||
itemCulture = context.Request.Form["Localization.SelectedCulture"].ToString();
|
itemCulture = context.Request.Form["Localization.SelectedCulture"].ToString();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//we update the settings assuming that when
|
// We update the settings assuming that when
|
||||||
//pattern culture = null or "" it means culture = default website culture
|
// pattern culture = null or "" it means culture = default website culture
|
||||||
//for patterns that we migrated
|
// for patterns that we migrated.
|
||||||
foreach (RoutePattern pattern in settings.Patterns.Where(x => String.IsNullOrWhiteSpace(x.Culture))) {
|
foreach (var pattern in settings.Patterns.Where(x => String.IsNullOrWhiteSpace(x.Culture))) {
|
||||||
pattern.Culture = _cultureManager.GetSiteCulture(); ;
|
pattern.Culture = _cultureManager.GetSiteCulture(); ;
|
||||||
}
|
}
|
||||||
|
|
||||||
//we do the same for default patterns
|
// We do the same for default patterns.
|
||||||
foreach (DefaultPattern pattern in settings.DefaultPatterns.Where(x => String.IsNullOrWhiteSpace(x.Culture))) {
|
foreach (var pattern in settings.DefaultPatterns.Where(x => String.IsNullOrWhiteSpace(x.Culture))) {
|
||||||
pattern.Culture = _cultureManager.GetSiteCulture();
|
pattern.Culture = _cultureManager.GetSiteCulture();
|
||||||
}
|
}
|
||||||
|
|
||||||
// if the content type has no pattern for autoroute, then use a default one
|
// If the content type has no pattern for autoroute, then use a default one.
|
||||||
if (!settings.Patterns.Any(x => String.Equals(x.Culture, itemCulture, StringComparison.OrdinalIgnoreCase))) {
|
if (!settings.Patterns.Any(x => String.Equals(x.Culture, itemCulture, StringComparison.OrdinalIgnoreCase))) {
|
||||||
settings.Patterns = new List<RoutePattern> { new RoutePattern { Name = "Title", Description = "my-title", Pattern = "{Content.Slug}", Culture = itemCulture } };
|
settings.Patterns = new List<RoutePattern> { new RoutePattern { Name = "Title", Description = "my-title", Pattern = "{Content.Slug}", Culture = itemCulture } };
|
||||||
}
|
}
|
||||||
|
|
||||||
// if the content type has no defaultPattern for autoroute, then use a default one
|
// If the content type has no defaultPattern for autoroute, then use a default one.
|
||||||
if (!settings.DefaultPatterns.Any(x => String.Equals(x.Culture, itemCulture, StringComparison.OrdinalIgnoreCase))) {
|
if (!settings.DefaultPatterns.Any(x => String.Equals(x.Culture, itemCulture, StringComparison.OrdinalIgnoreCase))) {
|
||||||
// If we are in the default culture, check the old setting.
|
// If we are in the default culture, check the old setting.
|
||||||
if (String.Equals(itemCulture, _cultureManager.GetSiteCulture(), StringComparison.OrdinalIgnoreCase)) {
|
if (String.Equals(itemCulture, _cultureManager.GetSiteCulture(), StringComparison.OrdinalIgnoreCase)) {
|
||||||
@@ -113,79 +119,59 @@ namespace Orchard.Autoroute.Drivers {
|
|||||||
CurrentCulture = itemCulture
|
CurrentCulture = itemCulture
|
||||||
};
|
};
|
||||||
|
|
||||||
// retrieve home page
|
// Retrieve home page.
|
||||||
var homepage = _aliasService.Get(string.Empty);
|
var homePageId = _homeAliasService.GetHomePageId();
|
||||||
var displayRouteValues = _contentManager.GetItemMetadata(part).DisplayRouteValues;
|
var isHomePage = part.Id == homePageId;
|
||||||
|
|
||||||
viewModel.IsHomePage = homepage.Match(displayRouteValues);
|
viewModel.IsHomePage = isHomePage;
|
||||||
viewModel.PromoteToHomePage = viewModel.IsHomePage || part.DisplayAlias == "/";
|
viewModel.PromoteToHomePage = part.PromoteToHomePage;
|
||||||
|
|
||||||
if (settings.PerItemConfiguration) {
|
if (settings.PerItemConfiguration) {
|
||||||
// if enabled, the list of all available patterns is displayed, and the user can
|
// If enabled, the list of all available patterns is displayed, and the user can select which one to use.
|
||||||
// select which one to use
|
|
||||||
|
|
||||||
// todo: later
|
// todo: later
|
||||||
}
|
}
|
||||||
|
|
||||||
var previous = part.DisplayAlias;
|
var previous = part.DisplayAlias;
|
||||||
if (updater != null && updater.TryUpdateModel(viewModel, Prefix, null, null)) {
|
if (updater != null && updater.TryUpdateModel(viewModel, Prefix, null, null)) {
|
||||||
|
|
||||||
// remove any leading slash in the permalink
|
// Remove any leading slash in the permalink.
|
||||||
if (viewModel.CurrentUrl != null) {
|
if (viewModel.CurrentUrl != null) {
|
||||||
viewModel.CurrentUrl = viewModel.CurrentUrl.TrimStart('/');
|
viewModel.CurrentUrl = viewModel.CurrentUrl.TrimStart('/');
|
||||||
}
|
}
|
||||||
|
|
||||||
part.DisplayAlias = viewModel.CurrentUrl;
|
part.DisplayAlias = viewModel.CurrentUrl;
|
||||||
|
|
||||||
// reset the alias if we need to force regeneration, and the user didn't provide a custom one
|
// Reset the alias if we need to force regeneration, and the user didn't provide a custom one.
|
||||||
if (settings.AutomaticAdjustmentOnEdit && previous == part.DisplayAlias) {
|
if(settings.AutomaticAdjustmentOnEdit && previous == part.DisplayAlias) {
|
||||||
part.DisplayAlias = string.Empty;
|
part.DisplayAlias = String.Empty;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!_autorouteService.IsPathValid(part.DisplayAlias)) {
|
if (!_autorouteService.IsPathValid(part.DisplayAlias)) {
|
||||||
updater.AddModelError("CurrentUrl", T("Please do not use any of the following characters in your permalink: \":\", \"?\", \"#\", \"[\", \"]\", \"@\", \"!\", \"$\", \"&\", \"'\", \"(\", \")\", \"*\", \"+\", \",\", \";\", \"=\", \", \"<\", \">\", \"\\\", \"|\", \"%\", \".\". No spaces are allowed (please use dashes or underscores instead)."));
|
updater.AddModelError("CurrentUrl", T("Please do not use any of the following characters in your permalink: \":\", \"?\", \"#\", \"[\", \"]\", \"@\", \"!\", \"$\", \"&\", \"'\", \"(\", \")\", \"*\", \"+\", \",\", \";\", \"=\", \", \"<\", \">\", \"\\\", \"|\", \"%\", \".\". No spaces are allowed (please use dashes or underscores instead)."));
|
||||||
}
|
}
|
||||||
|
|
||||||
// if CurrentUrl is set, the handler won't try to create an alias for it
|
// Mark the content item to be the homepage. Once this content isp ublished, the home alias will be updated to point to this content item.
|
||||||
// but instead keep the value
|
part.PromoteToHomePage = viewModel.PromoteToHomePage;
|
||||||
|
|
||||||
// if home page is requested, use "/" to have the handler create a homepage alias
|
|
||||||
if (viewModel.PromoteToHomePage) {
|
|
||||||
part.DisplayAlias = "/";
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return ContentShape("Parts_Autoroute_Edit",
|
return ContentShape("Parts_Autoroute_Edit",
|
||||||
() => shapeHelper.EditorTemplate(TemplateName: "Parts.Autoroute.Edit", Model: viewModel, Prefix: Prefix));
|
() => shapeHelper.EditorTemplate(TemplateName: "Parts.Autoroute.Edit", Model: viewModel, Prefix: Prefix));
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override void Importing(AutoroutePart part, ContentManagement.Handlers.ImportContentContext context) {
|
protected override void Importing(AutoroutePart part, ImportContentContext context) {
|
||||||
var displayAlias = context.Attribute(part.PartDefinition.Name, "Alias");
|
context.ImportAttribute(part.PartDefinition.Name, "Alias", s => part.DisplayAlias = s);
|
||||||
if (displayAlias != null) {
|
context.ImportAttribute(part.PartDefinition.Name, "CustomPattern", s => part.CustomPattern = s);
|
||||||
part.DisplayAlias = displayAlias;
|
context.ImportAttribute(part.PartDefinition.Name, "UseCustomPattern", s => part.UseCustomPattern = XmlHelper.Parse<bool>(s));
|
||||||
|
context.ImportAttribute(part.PartDefinition.Name, "UseCulturePattern", s => part.UseCulturePattern = XmlHelper.Parse<bool>(s));
|
||||||
|
context.ImportAttribute(part.PartDefinition.Name, "PromoteToHomePage", s => part.PromoteToHomePage = XmlHelper.Parse<bool>(s));
|
||||||
}
|
}
|
||||||
|
|
||||||
var customPattern = context.Attribute(part.PartDefinition.Name, "CustomPattern");
|
protected override void Exporting(AutoroutePart part, ExportContentContext context) {
|
||||||
if (customPattern != null) {
|
context.Element(part.PartDefinition.Name).SetAttributeValue("Alias", part.Record.DisplayAlias);
|
||||||
part.CustomPattern = customPattern;
|
|
||||||
}
|
|
||||||
|
|
||||||
var useCustomPattern = context.Attribute(part.PartDefinition.Name, "UseCustomPattern");
|
|
||||||
if (useCustomPattern != null) {
|
|
||||||
part.UseCustomPattern = bool.Parse(useCustomPattern);
|
|
||||||
}
|
|
||||||
|
|
||||||
var useCulturePattern = context.Attribute(part.PartDefinition.Name, "UseCulturePattern");
|
|
||||||
if (useCulturePattern != null) {
|
|
||||||
part.UseCulturePattern = bool.Parse(useCulturePattern);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
protected override void Exporting(AutoroutePart part, ContentManagement.Handlers.ExportContentContext context) {
|
|
||||||
context.Element(part.PartDefinition.Name).SetAttributeValue("Alias", String.IsNullOrEmpty(part.Record.DisplayAlias) ? "/" : part.Record.DisplayAlias);
|
|
||||||
context.Element(part.PartDefinition.Name).SetAttributeValue("CustomPattern", part.Record.CustomPattern);
|
context.Element(part.PartDefinition.Name).SetAttributeValue("CustomPattern", part.Record.CustomPattern);
|
||||||
context.Element(part.PartDefinition.Name).SetAttributeValue("UseCustomPattern", part.Record.UseCustomPattern);
|
context.Element(part.PartDefinition.Name).SetAttributeValue("UseCustomPattern", part.Record.UseCustomPattern);
|
||||||
context.Element(part.PartDefinition.Name).SetAttributeValue("UseCulturePattern", part.Record.UseCulturePattern);
|
context.Element(part.PartDefinition.Name).SetAttributeValue("UseCulturePattern", part.Record.UseCulturePattern);
|
||||||
|
context.Element(part.PartDefinition.Name).SetAttributeValue("PromoteToHomePage", part.UseCustomPattern);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -1,20 +1,18 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Linq;
|
using Orchard.Autoroute.Models;
|
||||||
|
using Orchard.Autoroute.Services;
|
||||||
using Orchard.ContentManagement;
|
using Orchard.ContentManagement;
|
||||||
using Orchard.ContentManagement.Handlers;
|
using Orchard.ContentManagement.Handlers;
|
||||||
using Orchard.Autoroute.Models;
|
|
||||||
using Orchard.Data;
|
using Orchard.Data;
|
||||||
using Orchard.Autoroute.Services;
|
|
||||||
using Orchard.Localization;
|
using Orchard.Localization;
|
||||||
using Orchard.UI.Notify;
|
using Orchard.UI.Notify;
|
||||||
using Orchard.Alias;
|
|
||||||
|
|
||||||
namespace Orchard.Autoroute.Handlers {
|
namespace Orchard.Autoroute.Handlers {
|
||||||
public class AutoroutePartHandler : ContentHandler {
|
public class AutoroutePartHandler : ContentHandler {
|
||||||
|
|
||||||
private readonly Lazy<IAutorouteService> _autorouteService;
|
private readonly Lazy<IAutorouteService> _autorouteService;
|
||||||
private readonly IOrchardServices _orchardServices;
|
private readonly IOrchardServices _orchardServices;
|
||||||
private readonly IAliasService _aliasService;
|
private readonly IHomeAliasService _homeAliasService;
|
||||||
|
|
||||||
public Localizer T { get; set; }
|
public Localizer T { get; set; }
|
||||||
|
|
||||||
@@ -22,12 +20,12 @@ namespace Orchard.Autoroute.Handlers {
|
|||||||
IRepository<AutoroutePartRecord> autoroutePartRepository,
|
IRepository<AutoroutePartRecord> autoroutePartRepository,
|
||||||
Lazy<IAutorouteService> autorouteService,
|
Lazy<IAutorouteService> autorouteService,
|
||||||
IOrchardServices orchardServices,
|
IOrchardServices orchardServices,
|
||||||
IAliasService aliasService) {
|
IHomeAliasService homeAliasService) {
|
||||||
|
|
||||||
Filters.Add(StorageFilter.For(autoroutePartRepository));
|
Filters.Add(StorageFilter.For(autoroutePartRepository));
|
||||||
_autorouteService = autorouteService;
|
_autorouteService = autorouteService;
|
||||||
_orchardServices = orchardServices;
|
_orchardServices = orchardServices;
|
||||||
_aliasService = aliasService;
|
_homeAliasService = homeAliasService;
|
||||||
|
|
||||||
OnUpdated<AutoroutePart>((ctx, part) => CreateAlias(part));
|
OnUpdated<AutoroutePart>((ctx, part) => CreateAlias(part));
|
||||||
|
|
||||||
@@ -38,8 +36,6 @@ namespace Orchard.Autoroute.Handlers {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
// OnVersioned<AutoroutePart>((ctx, part1, part2) => CreateAlias(part1));
|
|
||||||
|
|
||||||
OnPublished<AutoroutePart>((ctx, part) => PublishAlias(part));
|
OnPublished<AutoroutePart>((ctx, part) => PublishAlias(part));
|
||||||
|
|
||||||
// Remove alias if removed or unpublished
|
// Remove alias if removed or unpublished
|
||||||
@@ -60,55 +56,52 @@ namespace Orchard.Autoroute.Handlers {
|
|||||||
private void PublishAlias(AutoroutePart part) {
|
private void PublishAlias(AutoroutePart part) {
|
||||||
ProcessAlias(part);
|
ProcessAlias(part);
|
||||||
|
|
||||||
// should it become the home page ?
|
// Should it become the home page?
|
||||||
if (part.DisplayAlias == "/") {
|
if (part.PromoteToHomePage) {
|
||||||
part.DisplayAlias = String.Empty;
|
// Get the current homepage an unmark it as the homepage.
|
||||||
|
var currentHomePage = _homeAliasService.GetHomePage(VersionOptions.Latest);
|
||||||
|
if(currentHomePage != null && currentHomePage.Id != part.Id) {
|
||||||
|
var autoroutePart = currentHomePage.As<AutoroutePart>();
|
||||||
|
|
||||||
// regenerate the alias for the previous home page
|
if (autoroutePart != null) {
|
||||||
var currentHomePages = _orchardServices.ContentManager.Query<AutoroutePart, AutoroutePartRecord>().Where(x => x.DisplayAlias == "").List();
|
autoroutePart.PromoteToHomePage = false;
|
||||||
foreach (var current in currentHomePages.Where(x => x.Id != part.Id)) {
|
if(autoroutePart.IsPublished())
|
||||||
if (current != null) {
|
_orchardServices.ContentManager.Publish(autoroutePart.ContentItem);
|
||||||
current.CustomPattern = String.Empty; // force the regeneration
|
}
|
||||||
current.DisplayAlias = _autorouteService.Value.GenerateAlias(current);
|
}
|
||||||
|
|
||||||
// we changed the alias of the previous homepage, so publish this change if the content item was published.
|
// Update the home alias to point to this item being published.
|
||||||
if(current.IsPublished())
|
_homeAliasService.PublishHomeAlias(part);
|
||||||
_orchardServices.ContentManager.Publish(current.ContentItem);
|
|
||||||
}
|
|
||||||
_autorouteService.Value.PublishAlias(current);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
_autorouteService.Value.PublishAlias(part);
|
_autorouteService.Value.PublishAlias(part);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void ProcessAlias(AutoroutePart part) {
|
private void ProcessAlias(AutoroutePart part) {
|
||||||
// generate an alias if one as not already been entered
|
// Generate an alias if one as not already been entered.
|
||||||
if (String.IsNullOrWhiteSpace(part.DisplayAlias)) {
|
if (String.IsNullOrWhiteSpace(part.DisplayAlias)) {
|
||||||
part.DisplayAlias = _autorouteService.Value.GenerateAlias(part);
|
part.DisplayAlias = _autorouteService.Value.GenerateAlias(part);
|
||||||
}
|
}
|
||||||
|
|
||||||
// if the generated alias is empty, compute a new one
|
// If the generated alias is empty, compute a new one.
|
||||||
if (String.IsNullOrWhiteSpace(part.DisplayAlias)) {
|
if (String.IsNullOrWhiteSpace(part.DisplayAlias)) {
|
||||||
_autorouteService.Value.ProcessPath(part);
|
_autorouteService.Value.ProcessPath(part);
|
||||||
_orchardServices.Notifier.Warning(T("The permalink could not be generated, a new slug has been defined: \"{0}\"", part.Path));
|
_orchardServices.Notifier.Warning(T("The permalink could not be generated, a new slug has been defined: \"{0}\"", part.Path));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// check for permalink conflict, unless we are trying to set the home page
|
// Check for permalink conflict, unless we are trying to set the home page.
|
||||||
if (part.DisplayAlias != "/") {
|
|
||||||
var previous = part.Path;
|
var previous = part.Path;
|
||||||
if (!_autorouteService.Value.ProcessPath(part))
|
if (!_autorouteService.Value.ProcessPath(part))
|
||||||
_orchardServices.Notifier.Warning(T("Permalinks in conflict. \"{0}\" is already set for a previously created {2} so now it has the slug \"{1}\"",
|
_orchardServices.Notifier.Warning(
|
||||||
|
T("Permalinks in conflict. \"{0}\" is already set for a previously created {2} so now it has the slug \"{1}\"",
|
||||||
previous, part.Path, part.ContentItem.ContentType));
|
previous, part.Path, part.ContentItem.ContentType));
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
void RemoveAlias(AutoroutePart part) {
|
void RemoveAlias(AutoroutePart part) {
|
||||||
// Is this the current home page?
|
var homePageId = _homeAliasService.GetHomePageId();
|
||||||
var homePageRoute = _aliasService.Get("");
|
|
||||||
var homePageId = homePageRoute.ContainsKey("id") ? int.Parse(homePageRoute["id"].ToString()) : default(int);
|
|
||||||
|
|
||||||
|
// Is this the current home page?
|
||||||
if (part.ContentItem.Id == homePageId) {
|
if (part.ContentItem.Id == homePageId) {
|
||||||
_orchardServices.Notifier.Warning(T("You removed the content item that served as the site\'s home page. \nMost possibly this means that instead of the home page a \"404 Not Found\" error page will be displayed without a link to log in or access the dashboard. \n\nTo prevent this you can e.g. publish a content item that has the \"Set as home page\" checkbox ticked."));
|
_orchardServices.Notifier.Warning(T("You removed the content item that served as the site\'s home page. \nMost possibly this means that instead of the home page a \"404 Not Found\" error page will be displayed without a link to log in or access the dashboard. \n\nTo prevent this you can e.g. publish a content item that has the \"Set as home page\" checkbox ticked."));
|
||||||
}
|
}
|
||||||
|
@@ -0,0 +1,57 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Web.Routing;
|
||||||
|
using System.Xml.Linq;
|
||||||
|
using Orchard.Autoroute.Services;
|
||||||
|
using Orchard.ContentManagement;
|
||||||
|
using Orchard.Events;
|
||||||
|
|
||||||
|
namespace Orchard.Autoroute.ImportExport {
|
||||||
|
public interface IExportEventHandler : IEventHandler {
|
||||||
|
void Exporting(dynamic context);
|
||||||
|
void Exported(dynamic context);
|
||||||
|
}
|
||||||
|
|
||||||
|
public class HomeAliasHandler : IExportEventHandler {
|
||||||
|
private readonly IHomeAliasService _homeAliasService;
|
||||||
|
private readonly IContentManager _contentManager;
|
||||||
|
|
||||||
|
public HomeAliasHandler(IHomeAliasService homeAliasService, IContentManager contentManager) {
|
||||||
|
_homeAliasService = homeAliasService;
|
||||||
|
_contentManager = contentManager;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Exporting(dynamic context) {
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Exported(dynamic context) {
|
||||||
|
|
||||||
|
if (!((IEnumerable<string>)context.ExportOptions.CustomSteps).Contains("HomeAlias")) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
var homeAliasRoute = _homeAliasService.GetHomeRoute() ?? new RouteValueDictionary();
|
||||||
|
var root = new XElement("HomeAlias", homeAliasRoute.Select(x => new XElement(Capitalize(x.Key), x.Value)));
|
||||||
|
var homePage = _homeAliasService.GetHomePage(VersionOptions.Latest);
|
||||||
|
|
||||||
|
// If the home alias points to a content item, store its identifier in addition to the routevalues,
|
||||||
|
// so we can publish the home page alias during import where the ID primary key value of the home page might have changed,
|
||||||
|
// so we can't rely on the route values in that case.
|
||||||
|
if (homePage != null) {
|
||||||
|
var homePageIdentifier = _contentManager.GetItemMetadata(homePage).Identity.ToString();
|
||||||
|
root.Attr("Identifier", homePageIdentifier);
|
||||||
|
}
|
||||||
|
|
||||||
|
context.Document.Element("Orchard").Add(root);
|
||||||
|
}
|
||||||
|
|
||||||
|
private string Capitalize(string value) {
|
||||||
|
if (String.IsNullOrEmpty(value))
|
||||||
|
return value;
|
||||||
|
|
||||||
|
return Char.ToUpper(value[0]) + value.Substring(1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@@ -0,0 +1,14 @@
|
|||||||
|
using System.Collections.Generic;
|
||||||
|
using Orchard.Events;
|
||||||
|
|
||||||
|
namespace Orchard.Autoroute.ImportExport {
|
||||||
|
public interface ICustomExportStep : IEventHandler {
|
||||||
|
void Register(IList<string> steps);
|
||||||
|
}
|
||||||
|
|
||||||
|
public class HomeAliasExportStep : ICustomExportStep {
|
||||||
|
public void Register(IList<string> steps) {
|
||||||
|
steps.Add("HomeAlias");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@@ -0,0 +1,38 @@
|
|||||||
|
using System;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Web.Routing;
|
||||||
|
using Orchard.Autoroute.Services;
|
||||||
|
using Orchard.ContentManagement;
|
||||||
|
using Orchard.Recipes.Models;
|
||||||
|
using Orchard.Recipes.Services;
|
||||||
|
|
||||||
|
namespace Orchard.Autoroute.ImportExport {
|
||||||
|
public class HomeAliasImportHandler : Component, IRecipeHandler {
|
||||||
|
private readonly IHomeAliasService _homeAliasService;
|
||||||
|
private readonly IContentManager _contentManager;
|
||||||
|
|
||||||
|
public HomeAliasImportHandler(IHomeAliasService homeAliasService, IContentManager contentManager) {
|
||||||
|
_homeAliasService = homeAliasService;
|
||||||
|
_contentManager = contentManager;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void ExecuteRecipeStep(RecipeContext recipeContext) {
|
||||||
|
if (!String.Equals(recipeContext.RecipeStep.Name, "HomeAlias", StringComparison.OrdinalIgnoreCase)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
var root = recipeContext.RecipeStep.Step;
|
||||||
|
var routeValueDictionary = root.Elements().ToDictionary(x => x.Name.LocalName.ToLower(), x => (object)x.Value);
|
||||||
|
var homePageIdentifier = root.Attr("Identifier");
|
||||||
|
var homePageIdentity = new ContentIdentity(homePageIdentifier);
|
||||||
|
var homePage = !String.IsNullOrEmpty(homePageIdentifier) ? _contentManager.ResolveIdentity(homePageIdentity) : default(ContentItem);
|
||||||
|
|
||||||
|
if(homePage != null)
|
||||||
|
_homeAliasService.PublishHomeAlias(homePage);
|
||||||
|
else
|
||||||
|
_homeAliasService.PublishHomeAlias(new RouteValueDictionary(routeValueDictionary));
|
||||||
|
|
||||||
|
recipeContext.Executed = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@@ -21,6 +21,11 @@ namespace Orchard.Autoroute.Models {
|
|||||||
set { Store(x => x.DisplayAlias, value); }
|
set { Store(x => x.DisplayAlias, value); }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public bool PromoteToHomePage {
|
||||||
|
get { return this.Retrieve(x => x.PromoteToHomePage); }
|
||||||
|
set { this.Store(x => x.PromoteToHomePage, value); }
|
||||||
|
}
|
||||||
|
|
||||||
public string Path {
|
public string Path {
|
||||||
get { return DisplayAlias; }
|
get { return DisplayAlias; }
|
||||||
}
|
}
|
||||||
|
@@ -81,6 +81,9 @@
|
|||||||
<Content Include="Web.config" />
|
<Content Include="Web.config" />
|
||||||
<Content Include="Scripts\Web.config" />
|
<Content Include="Scripts\Web.config" />
|
||||||
<Content Include="Styles\Web.config" />
|
<Content Include="Styles\Web.config" />
|
||||||
|
<Compile Include="ImportExport\HomeAliasExportStep.cs" />
|
||||||
|
<Compile Include="ImportExport\HomeAliasExportHandler.cs" />
|
||||||
|
<Compile Include="ImportExport\HomeAliasImportHandler.cs" />
|
||||||
<Compile Include="Permissions.cs" />
|
<Compile Include="Permissions.cs" />
|
||||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||||
<Content Include="Module.txt" />
|
<Content Include="Module.txt" />
|
||||||
@@ -114,6 +117,8 @@
|
|||||||
<Compile Include="Providers\ContentDefinition\ContentDefinitionEventHandler.cs" />
|
<Compile Include="Providers\ContentDefinition\ContentDefinitionEventHandler.cs" />
|
||||||
<Compile Include="ResourceManifest.cs" />
|
<Compile Include="ResourceManifest.cs" />
|
||||||
<Compile Include="Services\AliasResolverSelector.cs" />
|
<Compile Include="Services\AliasResolverSelector.cs" />
|
||||||
|
<Compile Include="Services\HomeAliasService.cs" />
|
||||||
|
<Compile Include="Services\IHomeAliasService.cs" />
|
||||||
<Compile Include="Services\PathResolutionService.cs" />
|
<Compile Include="Services\PathResolutionService.cs" />
|
||||||
<Compile Include="Services\IPathResolutionService.cs" />
|
<Compile Include="Services\IPathResolutionService.cs" />
|
||||||
<Compile Include="Services\IRouteEvents.cs" />
|
<Compile Include="Services\IRouteEvents.cs" />
|
||||||
|
@@ -3,7 +3,6 @@ using System.Collections.Generic;
|
|||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Text.RegularExpressions;
|
using System.Text.RegularExpressions;
|
||||||
using Orchard.Alias;
|
using Orchard.Alias;
|
||||||
using Orchard.Alias.Implementation.Storage;
|
|
||||||
using Orchard.Autoroute.Models;
|
using Orchard.Autoroute.Models;
|
||||||
using Orchard.Autoroute.Settings;
|
using Orchard.Autoroute.Settings;
|
||||||
using Orchard.ContentManagement;
|
using Orchard.ContentManagement;
|
||||||
@@ -14,6 +13,7 @@ using Orchard.Localization.Services;
|
|||||||
using Orchard.Mvc;
|
using Orchard.Mvc;
|
||||||
using System.Web;
|
using System.Web;
|
||||||
using Orchard.ContentManagement.Aspects;
|
using Orchard.ContentManagement.Aspects;
|
||||||
|
using Orchard.Alias.Implementation.Storage;
|
||||||
|
|
||||||
namespace Orchard.Autoroute.Services {
|
namespace Orchard.Autoroute.Services {
|
||||||
public class AutorouteService : Component, IAutorouteService {
|
public class AutorouteService : Component, IAutorouteService {
|
||||||
@@ -56,7 +56,7 @@ namespace Orchard.Autoroute.Services {
|
|||||||
var settings = part.TypePartDefinition.Settings.GetModel<AutorouteSettings>();
|
var settings = part.TypePartDefinition.Settings.GetModel<AutorouteSettings>();
|
||||||
var itemCulture = _cultureManager.GetSiteCulture();
|
var itemCulture = _cultureManager.GetSiteCulture();
|
||||||
|
|
||||||
//if we are editing an existing content item
|
// If we are editing an existing content item.
|
||||||
if (part.Record.Id != 0) {
|
if (part.Record.Id != 0) {
|
||||||
ContentItem contentItem = _contentManager.Get(part.Record.ContentItemRecord.Id);
|
ContentItem contentItem = _contentManager.Get(part.Record.ContentItemRecord.Id);
|
||||||
var aspect = contentItem.As<ILocalizableAspect>();
|
var aspect = contentItem.As<ILocalizableAspect>();
|
||||||
@@ -77,9 +77,8 @@ namespace Orchard.Autoroute.Services {
|
|||||||
|
|
||||||
string pattern = GetDefaultPattern(part.ContentItem.ContentType, itemCulture).Pattern;
|
string pattern = GetDefaultPattern(part.ContentItem.ContentType, itemCulture).Pattern;
|
||||||
|
|
||||||
// String.Empty forces pattern based generation. "/" forces homepage.
|
// String.Empty forces pattern based generation.
|
||||||
if (part.UseCustomPattern
|
if (part.UseCustomPattern && (!String.IsNullOrWhiteSpace(part.CustomPattern))) {
|
||||||
&& (!String.IsNullOrWhiteSpace(part.CustomPattern) || String.Equals(part.CustomPattern, "/"))) {
|
|
||||||
pattern = part.CustomPattern;
|
pattern = part.CustomPattern;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -168,23 +167,6 @@ namespace Orchard.Autoroute.Services {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void RemoveAliases(AutoroutePart part) {
|
public void RemoveAliases(AutoroutePart part) {
|
||||||
// https://github.com/OrchardCMS/Orchard/issues/5137
|
|
||||||
// If the alias of the specified part is empty while not being the homepage,
|
|
||||||
// we need to make sure we are not removing all empty aliases in order to prevent losing the homepage content item being the homepage.
|
|
||||||
if (String.IsNullOrWhiteSpace(part.Path)) {
|
|
||||||
if (!IsHomePage(part)) {
|
|
||||||
// The item being removed is NOT the homepage, so we need to make sure we're not removing the alias for the homepage.
|
|
||||||
var aliasRecordId = GetHomePageAliasRecordId();
|
|
||||||
|
|
||||||
// Remove all aliases EXCEPT for the alias of the homepage.
|
|
||||||
_aliasStorage.Remove(x => x.Path == part.Path && x.Source == AliasSource && x.Id != aliasRecordId);
|
|
||||||
|
|
||||||
// Done.
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Safe to delete all aliases for the specified part since it is definitely not the homepage.
|
|
||||||
_aliasService.Delete(part.Path, AliasSource);
|
_aliasService.Delete(part.Path, AliasSource);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -192,7 +174,7 @@ namespace Orchard.Autoroute.Services {
|
|||||||
if (existingPaths == null || !existingPaths.Contains(part.Path))
|
if (existingPaths == null || !existingPaths.Contains(part.Path))
|
||||||
return part.Path;
|
return part.Path;
|
||||||
|
|
||||||
int? version = existingPaths.Select(s => GetSlugVersion(part.Path, s)).OrderBy(i => i).LastOrDefault();
|
var version = existingPaths.Select(s => GetSlugVersion(part.Path, s)).OrderBy(i => i).LastOrDefault();
|
||||||
|
|
||||||
return version != null
|
return version != null
|
||||||
? String.Format("{0}-{1}", part.Path, version)
|
? String.Format("{0}-{1}", part.Path, version)
|
||||||
@@ -229,16 +211,6 @@ namespace Orchard.Autoroute.Services {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
private bool IsHomePage(IContent content) {
|
|
||||||
var homePageRoute = _aliasService.Get("");
|
|
||||||
var homePageId = homePageRoute.ContainsKey("id") ? XmlHelper.Parse<int>((string)homePageRoute["id"]) : default(int?);
|
|
||||||
return content.Id == homePageId;
|
|
||||||
}
|
|
||||||
|
|
||||||
private int GetHomePageAliasRecordId() {
|
|
||||||
return _aliasStorage.List(x => x.Path == "").First().Item5;
|
|
||||||
}
|
|
||||||
|
|
||||||
private SettingsDictionary GetTypePartSettings(string contentType) {
|
private SettingsDictionary GetTypePartSettings(string contentType) {
|
||||||
var contentDefinition = _contentDefinitionManager.GetTypeDefinition(contentType);
|
var contentDefinition = _contentDefinitionManager.GetTypeDefinition(contentType);
|
||||||
|
|
||||||
|
@@ -1,9 +1,7 @@
|
|||||||
using Orchard.ContentManagement;
|
using System;
|
||||||
using System.Text.RegularExpressions;
|
|
||||||
using Orchard.Utility.Extensions;
|
|
||||||
using System;
|
|
||||||
using System.Text;
|
|
||||||
using System.Globalization;
|
using System.Globalization;
|
||||||
|
using System.Text;
|
||||||
|
using Orchard.ContentManagement;
|
||||||
|
|
||||||
namespace Orchard.Autoroute.Services {
|
namespace Orchard.Autoroute.Services {
|
||||||
|
|
||||||
@@ -86,6 +84,5 @@ namespace Orchard.Autoroute.Services {
|
|||||||
public string Slugify(string text) {
|
public string Slugify(string text) {
|
||||||
return Slugify(new FillSlugContext(null, text));
|
return Slugify(new FillSlugContext(null, text));
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -0,0 +1,55 @@
|
|||||||
|
using System.Web.Routing;
|
||||||
|
using Orchard.Alias;
|
||||||
|
using Orchard.ContentManagement;
|
||||||
|
|
||||||
|
namespace Orchard.Autoroute.Services {
|
||||||
|
public class HomeAliasService : IHomeAliasService {
|
||||||
|
private readonly IAliasService _aliasService;
|
||||||
|
private readonly IContentManager _contentManager;
|
||||||
|
private const string AliasSource = "Autoroute:Home";
|
||||||
|
private const string HomeAlias = "";
|
||||||
|
|
||||||
|
public HomeAliasService(IAliasService aliasService, IContentManager contentManager) {
|
||||||
|
_aliasService = aliasService;
|
||||||
|
_contentManager = contentManager;
|
||||||
|
}
|
||||||
|
|
||||||
|
public RouteValueDictionary GetHomeRoute() {
|
||||||
|
return _aliasService.Get(HomeAlias);
|
||||||
|
}
|
||||||
|
|
||||||
|
public int? GetHomePageId() {
|
||||||
|
var homePageRoute = GetHomeRoute();
|
||||||
|
var homePageId =
|
||||||
|
homePageRoute != null
|
||||||
|
? homePageRoute.ContainsKey("id")
|
||||||
|
? XmlHelper.Parse<int>((string)homePageRoute["id"])
|
||||||
|
: default(int?)
|
||||||
|
: default(int?);
|
||||||
|
|
||||||
|
return homePageId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public IContent GetHomePage(VersionOptions version = null) {
|
||||||
|
var homePageId = GetHomePageId();
|
||||||
|
var homePage = homePageId != null ? _contentManager.Get(homePageId.Value, version ?? VersionOptions.Published) : default(IContent);
|
||||||
|
|
||||||
|
return homePage;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void PublishHomeAlias(IContent content) {
|
||||||
|
var routeValues = _contentManager.GetItemMetadata(content).DisplayRouteValues;
|
||||||
|
PublishHomeAlias(routeValues);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void PublishHomeAlias(string route) {
|
||||||
|
_aliasService.DeleteBySource(AliasSource);
|
||||||
|
_aliasService.Set(HomeAlias, route, AliasSource);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void PublishHomeAlias(RouteValueDictionary route) {
|
||||||
|
_aliasService.DeleteBySource(AliasSource);
|
||||||
|
_aliasService.Set(HomeAlias, route, AliasSource);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@@ -0,0 +1,14 @@
|
|||||||
|
using System.Web.Routing;
|
||||||
|
using Orchard.ContentManagement;
|
||||||
|
|
||||||
|
namespace Orchard.Autoroute.Services {
|
||||||
|
|
||||||
|
public interface IHomeAliasService : IDependency {
|
||||||
|
RouteValueDictionary GetHomeRoute();
|
||||||
|
int? GetHomePageId();
|
||||||
|
IContent GetHomePage(VersionOptions version = null);
|
||||||
|
void PublishHomeAlias(IContent content);
|
||||||
|
void PublishHomeAlias(string route);
|
||||||
|
void PublishHomeAlias(RouteValueDictionary route);
|
||||||
|
}
|
||||||
|
}
|
@@ -6,7 +6,7 @@ using Orchard.Data;
|
|||||||
namespace Orchard.Autoroute.Services {
|
namespace Orchard.Autoroute.Services {
|
||||||
public class PathResolutionService : IPathResolutionService {
|
public class PathResolutionService : IPathResolutionService {
|
||||||
private readonly IContentManager _contentManager;
|
private readonly IContentManager _contentManager;
|
||||||
IRepository<AutoroutePartRecord> _autorouteRepository;
|
private readonly IRepository<AutoroutePartRecord> _autorouteRepository;
|
||||||
|
|
||||||
public PathResolutionService(
|
public PathResolutionService(
|
||||||
IRepository<AutoroutePartRecord> autorouteRepository,
|
IRepository<AutoroutePartRecord> autorouteRepository,
|
||||||
@@ -17,8 +17,7 @@ namespace Orchard.Autoroute.Services {
|
|||||||
|
|
||||||
public AutoroutePart GetPath(string path) {
|
public AutoroutePart GetPath(string path) {
|
||||||
var autorouteRecord = _autorouteRepository.Table
|
var autorouteRecord = _autorouteRepository.Table
|
||||||
.Where(part => part.DisplayAlias == path && part.ContentItemVersionRecord.Published)
|
.FirstOrDefault(part => part.DisplayAlias == path && part.ContentItemVersionRecord.Published);
|
||||||
.FirstOrDefault();
|
|
||||||
|
|
||||||
if (autorouteRecord == null) {
|
if (autorouteRecord == null) {
|
||||||
return null;
|
return null;
|
||||||
|
@@ -18,15 +18,15 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@if (!Model.PromoteToHomePage) {
|
|
||||||
<fieldset class="permalink">
|
<fieldset class="permalink">
|
||||||
<label>@T("Permalink")</label>
|
<label>@T("Permalink")</label>
|
||||||
@if (Model.Settings.AllowCustomPattern) {
|
@if (Model.Settings.AllowCustomPattern) {
|
||||||
<span class="permalink-definition" dir="ltr">
|
<span class="permalink-definition" dir="ltr">
|
||||||
<span>@Url.MakeAbsolute("/")@urlPrefix</span>
|
<span>@Url.MakeAbsolute("/")@urlPrefix</span>
|
||||||
<span>@Html.TextBoxFor(m => m.CurrentUrl, new { @class = "text is-url" })</span>
|
<span>@Html.TextBoxFor(m => m.CurrentUrl, new { @class = "text is-url" })</span>
|
||||||
</span>
|
</span>
|
||||||
<span class="hint">@T("Save the current item and leave the input empty to have it automatically generated using the pattern {0} e.g., {1}", pattern.ElementAtOrDefault(Convert.ToInt32(defaultPattern.PatternIndex)).Name, pattern.ElementAtOrDefault(Convert.ToInt32(defaultPattern.PatternIndex)).Description)</span>
|
<span class="hint">@T("Save the current item and leave the input empty to have it automatically generated using the pattern {0} e.g., {1}.", pattern.ElementAtOrDefault(Convert.ToInt32(defaultPattern.PatternIndex)).Name, pattern.ElementAtOrDefault(Convert.ToInt32(defaultPattern.PatternIndex)).Description)</span>
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
var hintClass = string.Empty;
|
var hintClass = string.Empty;
|
||||||
@@ -37,7 +37,7 @@
|
|||||||
|
|
||||||
if (string.IsNullOrEmpty(Model.CurrentUrl)
|
if (string.IsNullOrEmpty(Model.CurrentUrl)
|
||||||
|| (!string.IsNullOrEmpty(Model.CurrentUrl) && Model.Settings.AutomaticAdjustmentOnEdit)) {
|
|| (!string.IsNullOrEmpty(Model.CurrentUrl) && Model.Settings.AutomaticAdjustmentOnEdit)) {
|
||||||
<span class="@hintClass">@T("Save the current item and the url will be generated using the pattern {0} e.g., {1}", pattern.ElementAtOrDefault(Convert.ToInt32(defaultPattern.PatternIndex)).Name, pattern.ElementAtOrDefault(Convert.ToInt32(defaultPattern.PatternIndex)).Description)</span>
|
<span class="@hintClass">@T("Save the current item and the url will be generated using the pattern {0} e.g., {1}.", pattern.ElementAtOrDefault(Convert.ToInt32(defaultPattern.PatternIndex)).Name, pattern.ElementAtOrDefault(Convert.ToInt32(defaultPattern.PatternIndex)).Description)</span>
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@if (!String.IsNullOrEmpty(Model.CurrentUrl)) {
|
@if (!String.IsNullOrEmpty(Model.CurrentUrl)) {
|
||||||
@@ -49,14 +49,15 @@
|
|||||||
</span>
|
</span>
|
||||||
}
|
}
|
||||||
|
|
||||||
</fieldset>
|
</fieldset>
|
||||||
|
@if (!Model.IsHomePage) {
|
||||||
if (AuthorizedFor(Permissions.SetHomePage)) {
|
if (AuthorizedFor(Permissions.SetHomePage)) {
|
||||||
<fieldset>
|
<fieldset>
|
||||||
<span class="checkbox-and-label">
|
<span class="checkbox-and-label">
|
||||||
@Html.EditorFor(m => m.PromoteToHomePage)
|
@Html.CheckBoxFor(m => m.PromoteToHomePage)
|
||||||
<label for="@Html.FieldIdFor(m => m.PromoteToHomePage)" class="forcheckbox">@T("Set as home page")</label>
|
<label for="@Html.FieldIdFor(m => m.PromoteToHomePage)" class="forcheckbox">@T("Set as home page")</label>
|
||||||
</span>
|
</span>
|
||||||
<span class="hint">@T("Check to promote this content as the home page")</span>
|
<span class="hint">@T("Check to promote this content as the home page.")</span>
|
||||||
</fieldset>
|
</fieldset>
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
6
src/Orchard.Web/Modules/Orchard.Azure.MediaServices/Scripts/lib/dash.all.min.js
vendored
Normal file
6
src/Orchard.Web/Modules/Orchard.Azure.MediaServices/Scripts/lib/dash.all.min.js
vendored
Normal file
File diff suppressed because one or more lines are too long
1
src/Orchard.Web/Modules/Orchard.Azure.MediaServices/Scripts/lib/jquery.blockUI.min.js
vendored
Normal file
1
src/Orchard.Web/Modules/Orchard.Azure.MediaServices/Scripts/lib/jquery.blockUI.min.js
vendored
Normal file
File diff suppressed because one or more lines are too long
@@ -0,0 +1 @@
|
|||||||
|
!function(e){"use strict";"function"==typeof define&&define.amd?define(["jquery","./jquery.fileupload"],e):e(window.jQuery)}(function(e){"use strict";var s=e.blueimp.fileupload.prototype.options.add;e.widget("blueimp.fileupload",e.blueimp.fileupload,{options:{processQueue:[],add:function(r,i){var o=e(this);i.process(function(){return o.fileupload("process",i)}),s.call(this,r,i)}},processActions:{},_processFile:function(s,r){var i=this,o=e.Deferred().resolveWith(i,[s]),t=o.promise();return this._trigger("process",null,s),e.each(s.processQueue,function(s,o){var n=function(s){return r.errorThrown?e.Deferred().rejectWith(i,[r]).promise():i.processActions[o.action].call(i,s,o)};t=t.pipe(n,o.always&&n)}),t.done(function(){i._trigger("processdone",null,s),i._trigger("processalways",null,s)}).fail(function(){i._trigger("processfail",null,s),i._trigger("processalways",null,s)}),t},_transformProcessQueue:function(s){var r=[];e.each(s.processQueue,function(){var i={},o=this.action,t=this.prefix===!0?o:this.prefix;e.each(this,function(r,o){i[r]="string"===e.type(o)&&"@"===o.charAt(0)?s[o.slice(1)||(t?t+r.charAt(0).toUpperCase()+r.slice(1):r)]:o}),r.push(i)}),s.processQueue=r},processing:function(){return this._processing},process:function(s){var r=this,i=e.extend({},this.options,s);return i.processQueue&&i.processQueue.length&&(this._transformProcessQueue(i),0===this._processing&&this._trigger("processstart"),e.each(s.files,function(o){var t=o?e.extend({},i):i,n=function(){return s.errorThrown?e.Deferred().rejectWith(r,[s]).promise():r._processFile(t,s)};t.index=o,r._processing+=1,r._processingQueue=r._processingQueue.pipe(n,n).always(function(){r._processing-=1,0===r._processing&&r._trigger("processstop")})})),this._processingQueue},_create:function(){this._super(),this._processing=0,this._processingQueue=e.Deferred().resolveWith(this).promise()}})});
|
@@ -0,0 +1 @@
|
|||||||
|
!function(e){"use strict";"function"==typeof define&&define.amd?define(["jquery","./jquery.fileupload-process"],e):e(window.jQuery)}(function(e){"use strict";e.blueimp.fileupload.prototype.options.processQueue.push({action:"validate",always:!0,acceptFileTypes:"@",maxFileSize:"@",minFileSize:"@",maxNumberOfFiles:"@",disabled:"@disableValidation"}),e.widget("blueimp.fileupload",e.blueimp.fileupload,{options:{getNumberOfFiles:e.noop,messages:{maxNumberOfFiles:"Maximum number of files exceeded",acceptFileTypes:"File type not allowed",maxFileSize:"File is too large",minFileSize:"File is too small"}},processActions:{validate:function(i,l){if(l.disabled)return i;var r,s=e.Deferred(),t=this.options,o=i.files[i.index];return(l.minFileSize||l.maxFileSize)&&(r=o.size),"number"===e.type(l.maxNumberOfFiles)&&(t.getNumberOfFiles()||0)+i.files.length>l.maxNumberOfFiles?o.error=t.i18n("maxNumberOfFiles"):!l.acceptFileTypes||l.acceptFileTypes.test(o.type)||l.acceptFileTypes.test(o.name)?r>l.maxFileSize?o.error=t.i18n("maxFileSize"):"number"===e.type(r)&&r<l.minFileSize?o.error=t.i18n("minFileSize"):delete o.error:o.error=t.i18n("acceptFileTypes"),o.error||i.files.error?(i.files.error=!0,s.rejectWith(this,[i])):s.resolveWith(this,[i]),s.promise()}}})});
|
1
src/Orchard.Web/Modules/Orchard.Azure.MediaServices/Scripts/lib/jquery.fileupload.min.js
vendored
Normal file
1
src/Orchard.Web/Modules/Orchard.Azure.MediaServices/Scripts/lib/jquery.fileupload.min.js
vendored
Normal file
File diff suppressed because one or more lines are too long
1
src/Orchard.Web/Modules/Orchard.Azure.MediaServices/Scripts/lib/swfobject.min.js
vendored
Normal file
1
src/Orchard.Web/Modules/Orchard.Azure.MediaServices/Scripts/lib/swfobject.min.js
vendored
Normal file
File diff suppressed because one or more lines are too long
1
src/Orchard.Web/Modules/Orchard.Azure.MediaServices/Scripts/lib/uri.min.js
vendored
Normal file
1
src/Orchard.Web/Modules/Orchard.Azure.MediaServices/Scripts/lib/uri.min.js
vendored
Normal file
File diff suppressed because one or more lines are too long
@@ -1,16 +1,15 @@
|
|||||||
@using System.Globalization
|
@using System.Globalization
|
||||||
@using Orchard.Alias
|
@using Orchard.Autoroute.Services
|
||||||
@using Orchard.ContentManagement
|
@using Orchard.ContentManagement
|
||||||
@using Orchard.ContentManagement.Aspects
|
@using Orchard.ContentManagement.Aspects
|
||||||
@using Orchard.Localization.Services
|
@using Orchard.Localization.Services
|
||||||
@{
|
@{
|
||||||
var localizableAspects = Enumerable.Empty<ILocalizableAspect>();
|
var localizableAspects = Enumerable.Empty<ILocalizableAspect>();
|
||||||
|
var homePage = WorkContext.Resolve<IHomeAliasService>().GetHomePage();
|
||||||
var homePage = GetByPath(string.Empty);
|
|
||||||
|
|
||||||
if (homePage != null) {
|
if (homePage != null) {
|
||||||
var localizationService = WorkContext.Resolve<ILocalizationService>();
|
var localizationService = WorkContext.Resolve<ILocalizationService>();
|
||||||
localizableAspects = localizationService.GetLocalizations(homePage).Concat<ILocalizableAspect>(new[] { homePage.As<ILocalizableAspect>() });
|
localizableAspects = localizationService.GetLocalizations(homePage).Concat(new[] { homePage.As<ILocalizableAspect>() });
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@if (localizableAspects.Any()) {
|
@if (localizableAspects.Any()) {
|
||||||
@@ -31,21 +30,3 @@
|
|||||||
</ul>
|
</ul>
|
||||||
</div>
|
</div>
|
||||||
}
|
}
|
||||||
@functions{
|
|
||||||
public IContent GetByPath(string aliasPath) {
|
|
||||||
var contentRouting = WorkContext.Resolve<IAliasService>().Get(aliasPath);
|
|
||||||
|
|
||||||
if (contentRouting == null)
|
|
||||||
return null;
|
|
||||||
|
|
||||||
object id;
|
|
||||||
if (contentRouting.TryGetValue("id", out id)) {
|
|
||||||
int contentId;
|
|
||||||
if (int.TryParse(id as string, out contentId)) {
|
|
||||||
return WorkContext.Resolve<IContentManager>().Get(contentId);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
@@ -1,5 +1,6 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Web;
|
using System.Web;
|
||||||
|
using Orchard.Autoroute.Services;
|
||||||
using Orchard.Commands;
|
using Orchard.Commands;
|
||||||
using Orchard.ContentManagement;
|
using Orchard.ContentManagement;
|
||||||
using Orchard.ContentManagement.Aspects;
|
using Orchard.ContentManagement.Aspects;
|
||||||
@@ -21,6 +22,7 @@ namespace Orchard.Pages.Commands {
|
|||||||
private readonly IMenuService _menuService;
|
private readonly IMenuService _menuService;
|
||||||
private readonly INavigationManager _navigationManager;
|
private readonly INavigationManager _navigationManager;
|
||||||
private readonly IAuthenticationService _authenticationService;
|
private readonly IAuthenticationService _authenticationService;
|
||||||
|
private readonly IHomeAliasService _homeAliasService;
|
||||||
|
|
||||||
public PageCommands(
|
public PageCommands(
|
||||||
IContentManager contentManager,
|
IContentManager contentManager,
|
||||||
@@ -28,12 +30,15 @@ namespace Orchard.Pages.Commands {
|
|||||||
IAuthenticationService authenticationService,
|
IAuthenticationService authenticationService,
|
||||||
ISiteService siteService,
|
ISiteService siteService,
|
||||||
IMenuService menuService,
|
IMenuService menuService,
|
||||||
INavigationManager navigationManager) {
|
INavigationManager navigationManager,
|
||||||
|
IHomeAliasService homeAliasService) {
|
||||||
|
|
||||||
_contentManager = contentManager;
|
_contentManager = contentManager;
|
||||||
_membershipService = membershipService;
|
_membershipService = membershipService;
|
||||||
_siteService = siteService;
|
_siteService = siteService;
|
||||||
_menuService = menuService;
|
_menuService = menuService;
|
||||||
_navigationManager = navigationManager;
|
_navigationManager = navigationManager;
|
||||||
|
_homeAliasService = homeAliasService;
|
||||||
_authenticationService = authenticationService;
|
_authenticationService = authenticationService;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -94,14 +99,8 @@ namespace Orchard.Pages.Commands {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// (PH:Autoroute) Hackish way to leave Slug and Homepage switches intact without requiring a dependency on Autoroute. This may throw an Exception with
|
if (Homepage) {
|
||||||
// no AutoroutePart. But it means that normal setup recipes will still be able to give you a homepage without issue.
|
_homeAliasService.PublishHomeAlias(page);
|
||||||
if (Homepage || !String.IsNullOrWhiteSpace(Slug)) {
|
|
||||||
dynamic dpage = page;
|
|
||||||
if (dpage.AutoroutePart != null) {
|
|
||||||
dpage.AutoroutePart.UseCustomPattern = true;
|
|
||||||
dpage.AutoroutePart.CustomPattern = Homepage ? "/" : Slug;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
var layout = default(string);
|
var layout = default(string);
|
||||||
|
@@ -6,5 +6,5 @@ Version: 1.9.1
|
|||||||
OrchardVersion: 1.9
|
OrchardVersion: 1.9
|
||||||
Description: Introduces a preconfigured page content type.
|
Description: Introduces a preconfigured page content type.
|
||||||
FeatureDescription: A basic page content type.
|
FeatureDescription: A basic page content type.
|
||||||
Dependencies: Contents, Orchard.ContentPicker
|
Dependencies: Contents, Orchard.ContentPicker, Orchard.Autoroute
|
||||||
Category: Content
|
Category: Content
|
||||||
|
@@ -78,6 +78,11 @@
|
|||||||
<Name>Orchard.Core</Name>
|
<Name>Orchard.Core</Name>
|
||||||
<Private>false</Private>
|
<Private>false</Private>
|
||||||
</ProjectReference>
|
</ProjectReference>
|
||||||
|
<ProjectReference Include="..\Orchard.Autoroute\Orchard.Autoroute.csproj">
|
||||||
|
<Project>{66fccd76-2761-47e3-8d11-b45d0001ddaa}</Project>
|
||||||
|
<Name>Orchard.Autoroute</Name>
|
||||||
|
<Private>false</Private>
|
||||||
|
</ProjectReference>
|
||||||
<ProjectReference Include="..\Orchard.ContentPicker\Orchard.ContentPicker.csproj">
|
<ProjectReference Include="..\Orchard.ContentPicker\Orchard.ContentPicker.csproj">
|
||||||
<Project>{f301ef7d-f19c-4d83-aa94-cb64f29c037d}</Project>
|
<Project>{f301ef7d-f19c-4d83-aa94-cb64f29c037d}</Project>
|
||||||
<Name>Orchard.ContentPicker</Name>
|
<Name>Orchard.ContentPicker</Name>
|
||||||
|
Reference in New Issue
Block a user