mirror of
https://github.com/OrchardCMS/Orchard.git
synced 2025-09-23 21:13:35 +08:00
- Ability to promote cms pages to be homepage.
- New homepage core package with a home controller and routes. Home->Index action calls homepage provider, implemented by pages package. - New site setting (invisible), which is the currently active homepage provider + a parameter identifies the "item" within the provider. - Add checkbox to Edit Page form to set the page being edited to be homepage. --HG-- branch : dev
This commit is contained in:
56
src/Orchard.Web/Core/HomePage/Controllers/HomeController.cs
Normal file
56
src/Orchard.Web/Core/HomePage/Controllers/HomeController.cs
Normal file
@@ -0,0 +1,56 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Web.Mvc;
|
||||||
|
using JetBrains.Annotations;
|
||||||
|
using Orchard.Logging;
|
||||||
|
using Orchard.Mvc.ViewModels;
|
||||||
|
using Orchard.Services;
|
||||||
|
using Orchard.Settings;
|
||||||
|
|
||||||
|
namespace Orchard.Core.HomePage.Controllers {
|
||||||
|
[HandleError]
|
||||||
|
public class HomeController : Controller {
|
||||||
|
private readonly IEnumerable<IHomePageProvider> _homePageProviders;
|
||||||
|
|
||||||
|
public HomeController(IEnumerable<IHomePageProvider> homePageProviders) {
|
||||||
|
_homePageProviders = homePageProviders;
|
||||||
|
Logger = NullLogger.Instance;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ILogger Logger { get; set; }
|
||||||
|
protected virtual ISite CurrentSite { get; [UsedImplicitly] private set; }
|
||||||
|
|
||||||
|
public ActionResult Index() {
|
||||||
|
try {
|
||||||
|
string homepage = CurrentSite.HomePage;
|
||||||
|
if (String.IsNullOrEmpty(homepage)) {
|
||||||
|
return View(new BaseViewModel());
|
||||||
|
}
|
||||||
|
|
||||||
|
string[] homePageParameters = homepage.Split(';');
|
||||||
|
if (homePageParameters.Length != 2) {
|
||||||
|
return View(new BaseViewModel());
|
||||||
|
}
|
||||||
|
string providerName = homePageParameters[0];
|
||||||
|
int item = Int32.Parse(homePageParameters[1]);
|
||||||
|
|
||||||
|
foreach (var provider in _homePageProviders) {
|
||||||
|
if (String.Equals(provider.GetProviderName(), providerName)) {
|
||||||
|
ActionResult result = provider.GetHomePage(item);
|
||||||
|
if (result is ViewResultBase) {
|
||||||
|
ViewResultBase resultBase = result as ViewResultBase;
|
||||||
|
ViewData = resultBase.ViewData;
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return View(new BaseViewModel());
|
||||||
|
}
|
||||||
|
catch {
|
||||||
|
return View(new BaseViewModel());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
1
src/Orchard.Web/Core/HomePage/Module.txt
Normal file
1
src/Orchard.Web/Core/HomePage/Module.txt
Normal file
@@ -0,0 +1 @@
|
|||||||
|
name: HomePage
|
36
src/Orchard.Web/Core/HomePage/Routes.cs
Normal file
36
src/Orchard.Web/Core/HomePage/Routes.cs
Normal file
@@ -0,0 +1,36 @@
|
|||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Web.Mvc;
|
||||||
|
using System.Web.Routing;
|
||||||
|
using Orchard.Mvc.Routes;
|
||||||
|
|
||||||
|
namespace Orchard.Core.HomePage {
|
||||||
|
public class Routes : IRouteProvider {
|
||||||
|
public void GetRoutes(ICollection<RouteDescriptor> routes) {
|
||||||
|
foreach (var routeDescriptor in GetRoutes())
|
||||||
|
routes.Add(routeDescriptor);
|
||||||
|
}
|
||||||
|
|
||||||
|
public IEnumerable<RouteDescriptor> GetRoutes() {
|
||||||
|
return new[] {
|
||||||
|
new RouteDescriptor {
|
||||||
|
Priority = 20,
|
||||||
|
Route = new Route(
|
||||||
|
"",
|
||||||
|
new RouteValueDictionary {
|
||||||
|
{"area", "HomePage"},
|
||||||
|
{"controller", "Home"},
|
||||||
|
{"action", "Index"}
|
||||||
|
},
|
||||||
|
new RouteValueDictionary {
|
||||||
|
{"area", "HomePage"},
|
||||||
|
{"controller", "Home"},
|
||||||
|
},
|
||||||
|
new RouteValueDictionary {
|
||||||
|
{"area", "HomePage"}
|
||||||
|
},
|
||||||
|
new MvcRouteHandler())
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@@ -102,6 +102,8 @@
|
|||||||
<Compile Include="Feeds\Models\FeedResponse.cs" />
|
<Compile Include="Feeds\Models\FeedResponse.cs" />
|
||||||
<Compile Include="Feeds\Rss\RssFeedBuilder.cs" />
|
<Compile Include="Feeds\Rss\RssFeedBuilder.cs" />
|
||||||
<Compile Include="Feeds\Rss\RssResult.cs" />
|
<Compile Include="Feeds\Rss\RssResult.cs" />
|
||||||
|
<Compile Include="HomePage\Controllers\HomeController.cs" />
|
||||||
|
<Compile Include="HomePage\Routes.cs" />
|
||||||
<Compile Include="Navigation\AdminMenu.cs" />
|
<Compile Include="Navigation\AdminMenu.cs" />
|
||||||
<Compile Include="Navigation\Controllers\AdminController.cs" />
|
<Compile Include="Navigation\Controllers\AdminController.cs" />
|
||||||
<Compile Include="Navigation\Models\MenuItem.cs" />
|
<Compile Include="Navigation\Models\MenuItem.cs" />
|
||||||
@@ -216,6 +218,7 @@
|
|||||||
<Content Include="Themes\Views\Web.config" />
|
<Content Include="Themes\Views\Web.config" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
<Content Include="HomePage\Module.txt" />
|
||||||
<Content Include="Navigation\Views\Admin\Index.ascx" />
|
<Content Include="Navigation\Views\Admin\Index.ascx" />
|
||||||
<Content Include="Navigation\Views\EditorTemplates\Parts\Navigation.EditMenuPart.ascx" />
|
<Content Include="Navigation\Views\EditorTemplates\Parts\Navigation.EditMenuPart.ascx" />
|
||||||
<Content Include="Navigation\Views\Web.config" />
|
<Content Include="Navigation\Views\Web.config" />
|
||||||
|
@@ -24,5 +24,9 @@ namespace Orchard.Core.Settings.Models {
|
|||||||
get { return Record.SuperUser; }
|
get { return Record.SuperUser; }
|
||||||
set { Record.SuperUser = value; }
|
set { Record.SuperUser = value; }
|
||||||
}
|
}
|
||||||
|
public string HomePage {
|
||||||
|
get { return Record.HomePage; }
|
||||||
|
set { Record.HomePage = value; }
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -7,5 +7,6 @@ namespace Orchard.Core.Settings.Records {
|
|||||||
public virtual string SiteName { get; set; }
|
public virtual string SiteName { get; set; }
|
||||||
public virtual string SuperUser { get; set; }
|
public virtual string SuperUser { get; set; }
|
||||||
public virtual string PageTitleSeparator { get; set; }
|
public virtual string PageTitleSeparator { get; set; }
|
||||||
|
public virtual string HomePage { get; set; }
|
||||||
}
|
}
|
||||||
}
|
}
|
@@ -3,12 +3,14 @@ using System.Collections.Generic;
|
|||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Reflection;
|
using System.Reflection;
|
||||||
using System.Web.Mvc;
|
using System.Web.Mvc;
|
||||||
|
using JetBrains.Annotations;
|
||||||
using Orchard.Localization;
|
using Orchard.Localization;
|
||||||
using Orchard.ContentManagement;
|
using Orchard.ContentManagement;
|
||||||
using Orchard.Mvc.Results;
|
using Orchard.Mvc.Results;
|
||||||
using Orchard.Pages.Models;
|
using Orchard.Pages.Models;
|
||||||
using Orchard.Pages.Services;
|
using Orchard.Pages.Services;
|
||||||
using Orchard.Pages.ViewModels;
|
using Orchard.Pages.ViewModels;
|
||||||
|
using Orchard.Settings;
|
||||||
using Orchard.UI.Notify;
|
using Orchard.UI.Notify;
|
||||||
|
|
||||||
namespace Orchard.Pages.Controllers {
|
namespace Orchard.Pages.Controllers {
|
||||||
@@ -22,6 +24,7 @@ namespace Orchard.Pages.Controllers {
|
|||||||
T = NullLocalizer.Instance;
|
T = NullLocalizer.Instance;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected virtual ISite CurrentSite { get; [UsedImplicitly] private set; }
|
||||||
public IOrchardServices Services { get; private set; }
|
public IOrchardServices Services { get; private set; }
|
||||||
private Localizer T { get; set; }
|
private Localizer T { get; set; }
|
||||||
|
|
||||||
@@ -189,6 +192,9 @@ namespace Orchard.Pages.Controllers {
|
|||||||
case "PublishNow":
|
case "PublishNow":
|
||||||
_pageService.Publish(model.Page.Item);
|
_pageService.Publish(model.Page.Item);
|
||||||
Services.Notifier.Information(T("Page has been published"));
|
Services.Notifier.Information(T("Page has been published"));
|
||||||
|
if (model.PromoteToHomePage) {
|
||||||
|
CurrentSite.HomePage = "PagesHomePageProvider;" + model.Page.Item.Id;
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
case "PublishLater":
|
case "PublishLater":
|
||||||
_pageService.Publish(model.Page.Item, model.Page.Item.ScheduledPublishUtc.Value);
|
_pageService.Publish(model.Page.Item, model.Page.Item.ScheduledPublishUtc.Value);
|
||||||
|
@@ -77,6 +77,7 @@
|
|||||||
<Compile Include="Security\Authorization.cs" />
|
<Compile Include="Security\Authorization.cs" />
|
||||||
<Compile Include="Services\IPageService.cs" />
|
<Compile Include="Services\IPageService.cs" />
|
||||||
<Compile Include="Services\PageService.cs" />
|
<Compile Include="Services\PageService.cs" />
|
||||||
|
<Compile Include="Services\PagesHomePageProvider.cs" />
|
||||||
<Compile Include="Services\SlugConstraint.cs">
|
<Compile Include="Services\SlugConstraint.cs">
|
||||||
<SubType>Code</SubType>
|
<SubType>Code</SubType>
|
||||||
</Compile>
|
</Compile>
|
||||||
|
@@ -0,0 +1,51 @@
|
|||||||
|
using System.Web.Mvc;
|
||||||
|
using Orchard.Localization;
|
||||||
|
using Orchard.Mvc.Results;
|
||||||
|
using Orchard.Pages.Models;
|
||||||
|
using Orchard.Pages.ViewModels;
|
||||||
|
using Orchard.Services;
|
||||||
|
|
||||||
|
namespace Orchard.Pages.Services {
|
||||||
|
public class PagesHomePageProvider : IHomePageProvider {
|
||||||
|
private readonly IPageService _pageService;
|
||||||
|
private readonly ISlugConstraint _slugConstraint;
|
||||||
|
|
||||||
|
public PagesHomePageProvider(IOrchardServices services, IPageService pageService, ISlugConstraint slugConstraint) {
|
||||||
|
Services = services;
|
||||||
|
_slugConstraint = slugConstraint;
|
||||||
|
_pageService = pageService;
|
||||||
|
T = NullLocalizer.Instance;
|
||||||
|
}
|
||||||
|
|
||||||
|
public IOrchardServices Services { get; private set; }
|
||||||
|
private Localizer T { get; set; }
|
||||||
|
|
||||||
|
#region Implementation of IHomePageProvider
|
||||||
|
|
||||||
|
public string GetProviderName() {
|
||||||
|
return "PagesHomePageProvider";
|
||||||
|
}
|
||||||
|
|
||||||
|
public ActionResult GetHomePage(int itemId) {
|
||||||
|
Page page = _pageService.Get(itemId);
|
||||||
|
var correctedSlug = _slugConstraint.LookupPublishedSlug(page.Slug);
|
||||||
|
if (correctedSlug == null)
|
||||||
|
return new NotFoundResult();
|
||||||
|
|
||||||
|
page = _pageService.Get(correctedSlug);
|
||||||
|
if (page == null)
|
||||||
|
return new NotFoundResult();
|
||||||
|
|
||||||
|
var model = new PageViewModel {
|
||||||
|
Page = Services.ContentManager.BuildDisplayModel(page, "Detail")
|
||||||
|
};
|
||||||
|
|
||||||
|
return new ViewResult {
|
||||||
|
ViewName = "~/Modules/Orchard.Pages/Views/Page/Item.ascx",
|
||||||
|
ViewData = new ViewDataDictionary<PageViewModel>(model)
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
}
|
||||||
|
}
|
@@ -4,5 +4,6 @@ using Orchard.Mvc.ViewModels;
|
|||||||
namespace Orchard.Pages.ViewModels {
|
namespace Orchard.Pages.ViewModels {
|
||||||
public class PageEditViewModel : AdminViewModel {
|
public class PageEditViewModel : AdminViewModel {
|
||||||
public ContentItemViewModel<Page> Page { get; set; }
|
public ContentItemViewModel<Page> Page { get; set; }
|
||||||
|
public bool PromoteToHomePage { get; set; }
|
||||||
}
|
}
|
||||||
}
|
}
|
@@ -4,5 +4,8 @@
|
|||||||
<h1><%=Html.TitleForPage(T("Edit Page").ToString()) %></h1>
|
<h1><%=Html.TitleForPage(T("Edit Page").ToString()) %></h1>
|
||||||
<% using (Html.BeginFormAntiForgeryPost()) { %>
|
<% using (Html.BeginFormAntiForgeryPost()) { %>
|
||||||
<%=Html.ValidationSummary() %>
|
<%=Html.ValidationSummary() %>
|
||||||
<%=Html.EditorForItem(m => m.Page) %><%
|
<%=Html.EditorForItem(m => m.Page) %>
|
||||||
|
<%=Html.EditorFor(m => m.PromoteToHomePage) %>
|
||||||
|
<label for="PromoteToHomePage" class="forcheckbox"><%=_Encoded("Set as home page") %></label>
|
||||||
|
<%
|
||||||
} %>
|
} %>
|
@@ -14,7 +14,6 @@ using Orchard.Security;
|
|||||||
using Orchard.Settings;
|
using Orchard.Settings;
|
||||||
using Orchard.Setup.ViewModels;
|
using Orchard.Setup.ViewModels;
|
||||||
using Orchard.Localization;
|
using Orchard.Localization;
|
||||||
using Orchard.UI.Navigation;
|
|
||||||
using Orchard.UI.Notify;
|
using Orchard.UI.Notify;
|
||||||
using MenuItem=Orchard.Core.Navigation.Models.MenuItem;
|
using MenuItem=Orchard.Core.Navigation.Models.MenuItem;
|
||||||
|
|
||||||
@@ -104,6 +103,7 @@ namespace Orchard.Setup.Controllers {
|
|||||||
page.As<HasComments>().CommentsShown = false;
|
page.As<HasComments>().CommentsShown = false;
|
||||||
page.As<CommonAspect>().Owner = user;
|
page.As<CommonAspect>().Owner = user;
|
||||||
contentManager.Publish(page);
|
contentManager.Publish(page);
|
||||||
|
siteSettings.Record.HomePage = "PagesHomePageProvider;" + page.Id;
|
||||||
|
|
||||||
// add a menu item for the shiny new home page
|
// add a menu item for the shiny new home page
|
||||||
var menuItem = contentManager.Create("menuitem");
|
var menuItem = contentManager.Create("menuitem");
|
||||||
|
@@ -1,4 +1,5 @@
|
|||||||
using System.Collections.Generic;
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Reflection;
|
using System.Reflection;
|
||||||
using System.Web;
|
using System.Web;
|
||||||
@@ -161,6 +162,11 @@ namespace Orchard.Environment.ShellBuilders {
|
|||||||
public string SuperUser {
|
public string SuperUser {
|
||||||
get { return ""; }
|
get { return ""; }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public string HomePage {
|
||||||
|
get { return ""; }
|
||||||
|
set { throw new NotImplementedException(); }
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -154,6 +154,7 @@
|
|||||||
<Compile Include="Security\IAuthorizationServiceEvents.cs" />
|
<Compile Include="Security\IAuthorizationServiceEvents.cs" />
|
||||||
<Compile Include="Security\StandardPermissions.cs" />
|
<Compile Include="Security\StandardPermissions.cs" />
|
||||||
<Compile Include="Security\OrchardSecurityException.cs" />
|
<Compile Include="Security\OrchardSecurityException.cs" />
|
||||||
|
<Compile Include="Services\IHomePageProvider.cs" />
|
||||||
<Compile Include="Tasks\Scheduling\IPublishingTaskManager.cs" />
|
<Compile Include="Tasks\Scheduling\IPublishingTaskManager.cs" />
|
||||||
<Compile Include="Tasks\Scheduling\IScheduledTask.cs" />
|
<Compile Include="Tasks\Scheduling\IScheduledTask.cs" />
|
||||||
<Compile Include="ContentManagement\ContentExtensions.cs" />
|
<Compile Include="ContentManagement\ContentExtensions.cs" />
|
||||||
|
8
src/Orchard/Services/IHomePageProvider.cs
Normal file
8
src/Orchard/Services/IHomePageProvider.cs
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
using System.Web.Mvc;
|
||||||
|
|
||||||
|
namespace Orchard.Services {
|
||||||
|
public interface IHomePageProvider : IDependency {
|
||||||
|
string GetProviderName();
|
||||||
|
ActionResult GetHomePage(int itemId);
|
||||||
|
}
|
||||||
|
}
|
@@ -10,5 +10,6 @@ namespace Orchard.Settings {
|
|||||||
string SiteSalt { get; }
|
string SiteSalt { get; }
|
||||||
string SiteUrl { get; }
|
string SiteUrl { get; }
|
||||||
string SuperUser { get; }
|
string SuperUser { get; }
|
||||||
|
string HomePage { get; set; }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user