mirror of
https://github.com/OrchardCMS/Orchard.git
synced 2025-10-15 11:44:58 +08:00
Pulling Themes from Orchard.Core into its own module, Orchard.Themes
--HG-- branch : dev rename : src/Orchard.Web/Core/Themes/AdminMenu.cs => src/Orchard.Web/Modules/Orchard.Themes/AdminMenu.cs rename : src/Orchard.Web/Core/Themes/Content/orchard.ico => src/Orchard.Web/Modules/Orchard.Themes/Content/orchard.ico rename : src/Orchard.Web/Core/Themes/Controllers/AdminController.cs => src/Orchard.Web/Modules/Orchard.Themes/Controllers/AdminController.cs rename : src/Orchard.Web/Core/Themes/DesignerNotes/ZoneManagerEvents.cs => src/Orchard.Web/Modules/Orchard.Themes/DesignerNotes/ZoneManagerEvents.cs rename : src/Orchard.Web/Core/Themes/Handlers/ThemeSiteSettingsHandler.cs => src/Orchard.Web/Modules/Orchard.Themes/Handlers/ThemeSiteSettingsHandler.cs rename : src/Orchard.Web/Core/Themes/Models/Theme.cs => src/Orchard.Web/Modules/Orchard.Themes/Models/Theme.cs rename : src/Orchard.Web/Core/Themes/Models/ThemeRecord.cs => src/Orchard.Web/Modules/Orchard.Themes/Models/ThemeRecord.cs rename : src/Orchard.Web/Core/Themes/Models/ThemeSiteSettings.cs => src/Orchard.Web/Modules/Orchard.Themes/Models/ThemeSiteSettings.cs rename : src/Orchard.Web/Core/Themes/Models/ThemeSiteSettingsRecord.cs => src/Orchard.Web/Modules/Orchard.Themes/Models/ThemeSiteSettingsRecord.cs rename : src/Orchard.Web/Core/Themes/Module.txt => src/Orchard.Web/Modules/Orchard.Themes/Module.txt rename : src/Orchard.Web/Core/Themes/Permissions.cs => src/Orchard.Web/Modules/Orchard.Themes/Permissions.cs rename : src/Orchard.Web/Core/Themes/Preview/IPreviewTheme.cs => src/Orchard.Web/Modules/Orchard.Themes/Preview/IPreviewTheme.cs rename : src/Orchard.Web/Core/Themes/Preview/PreviewTheme.cs => src/Orchard.Web/Modules/Orchard.Themes/Preview/PreviewTheme.cs rename : src/Orchard.Web/Core/Themes/Preview/PreviewThemeFilter.cs => src/Orchard.Web/Modules/Orchard.Themes/Preview/PreviewThemeFilter.cs rename : src/Orchard.Web/Core/Themes/Scripts/base.js => src/Orchard.Web/Modules/Orchard.Themes/Scripts/base.js rename : src/Orchard.Web/Core/Themes/Scripts/jquery-1.4.1.js => src/Orchard.Web/Modules/Orchard.Themes/Scripts/jquery-1.4.1.js rename : src/Orchard.Web/Core/Themes/Scripts/jquery-1.4.1.min.js => src/Orchard.Web/Modules/Orchard.Themes/Scripts/jquery-1.4.1.min.js rename : src/Orchard.Web/Core/Themes/Services/SafeModeThemeSelector.cs => src/Orchard.Web/Modules/Orchard.Themes/Services/SafeModeThemeSelector.cs rename : src/Orchard.Web/Core/Themes/Services/SiteThemeSelector.cs => src/Orchard.Web/Modules/Orchard.Themes/Services/SiteThemeSelector.cs rename : src/Orchard.Web/Core/Themes/Services/ThemeService.cs => src/Orchard.Web/Modules/Orchard.Themes/Services/ThemeService.cs rename : src/Orchard.Web/Core/Themes/Services/ThemeZoneManagerEvents.cs => src/Orchard.Web/Modules/Orchard.Themes/Services/ThemeZoneManagerEvents.cs rename : src/Orchard.Web/Core/Themes/Styles/Images/toolBarActiveButtonBackground.gif => src/Orchard.Web/Modules/Orchard.Themes/Styles/Images/toolBarActiveButtonBackground.gif rename : src/Orchard.Web/Core/Themes/Styles/Images/toolBarBackground.gif => src/Orchard.Web/Modules/Orchard.Themes/Styles/Images/toolBarBackground.gif rename : src/Orchard.Web/Core/Themes/Styles/Images/toolBarHoverButtonBackground.gif => src/Orchard.Web/Modules/Orchard.Themes/Styles/Images/toolBarHoverButtonBackground.gif rename : src/Orchard.Web/Core/Themes/Styles/special.css => src/Orchard.Web/Modules/Orchard.Themes/Styles/special.css rename : src/Orchard.Web/Core/Themes/ViewModels/PreviewViewModel.cs => src/Orchard.Web/Modules/Orchard.Themes/ViewModels/PreviewViewModel.cs rename : src/Orchard.Web/Core/Themes/ViewModels/ThemesIndexViewModel.cs => src/Orchard.Web/Modules/Orchard.Themes/ViewModels/ThemesIndexViewModel.cs rename : src/Orchard.Web/Core/Themes/Views/Admin/Index.aspx => src/Orchard.Web/Modules/Orchard.Themes/Views/Admin/Index.aspx rename : src/Orchard.Web/Core/Themes/Views/Admin/Install.aspx => src/Orchard.Web/Modules/Orchard.Themes/Views/Admin/Install.aspx rename : src/Orchard.Web/Core/Themes/Views/Admin/ThemePreview.ascx => src/Orchard.Web/Modules/Orchard.Themes/Views/Admin/ThemePreview.ascx rename : src/Orchard.Web/Core/Themes/Views/EditorTemplates/Items/ContentItem.ascx => src/Orchard.Web/Modules/Orchard.Themes/Views/DisplayTemplates/Items/ContentItem.ascx rename : src/Orchard.Web/Core/Themes/Views/Document.aspx => src/Orchard.Web/Modules/Orchard.Themes/Views/Document.aspx rename : src/Orchard.Web/Core/Themes/Views/EditorTemplates/Items/ContentItem.ascx => src/Orchard.Web/Modules/Orchard.Themes/Views/EditorTemplates/Items/ContentItem.ascx rename : src/Orchard.Web/Core/Themes/Views/HeadPreload.ascx => src/Orchard.Web/Modules/Orchard.Themes/Views/HeadPreload.ascx rename : src/Orchard.Web/Core/Themes/Views/Header.ascx => src/Orchard.Web/Modules/Orchard.Themes/Views/Header.ascx rename : src/Orchard.Web/Core/Themes/Views/Layout.ascx => src/Orchard.Web/Modules/Orchard.Themes/Views/Layout.ascx rename : src/Orchard.Web/Core/Themes/Views/Menu.ascx => src/Orchard.Web/Modules/Orchard.Themes/Views/Menu.ascx rename : src/Orchard.Web/Core/Themes/Views/Messages.ascx => src/Orchard.Web/Modules/Orchard.Themes/Views/Messages.ascx rename : src/Orchard.Web/Core/Themes/Views/NotFound.ascx => src/Orchard.Web/Modules/Orchard.Themes/Views/NotFound.ascx rename : src/Orchard.Web/Core/Themes/Views/User.ascx => src/Orchard.Web/Modules/Orchard.Themes/Views/User.ascx rename : src/Orchard.Web/Core/Themes/Views/Web.config => src/Orchard.Web/Modules/Orchard.Themes/Views/Web.config rename : src/Orchard.Web/Core/Themes/Views/Web.config => src/Orchard.Web/Modules/Orchard.Themes/Web.config
This commit is contained in:
@@ -0,0 +1,160 @@
|
||||
using System;
|
||||
using System.Reflection;
|
||||
using System.Web;
|
||||
using System.Web.Mvc;
|
||||
using Orchard.Localization;
|
||||
using Orchard.Mvc.ViewModels;
|
||||
using Orchard.Security;
|
||||
using Orchard.Themes.Preview;
|
||||
using Orchard.Themes.ViewModels;
|
||||
using Orchard.UI.Notify;
|
||||
|
||||
namespace Orchard.Themes.Controllers {
|
||||
[ValidateInput(false)]
|
||||
public class AdminController : Controller {
|
||||
private readonly IThemeService _themeService;
|
||||
private readonly IPreviewTheme _previewTheme;
|
||||
|
||||
public AdminController(IOrchardServices services, IThemeService themeService, IPreviewTheme previewTheme, IAuthorizer authorizer, INotifier notifier) {
|
||||
Services = services;
|
||||
_themeService = themeService;
|
||||
_previewTheme = previewTheme;
|
||||
T = NullLocalizer.Instance;
|
||||
}
|
||||
|
||||
public IOrchardServices Services{ get; set; }
|
||||
public Localizer T { get; set; }
|
||||
|
||||
public ActionResult Index() {
|
||||
try {
|
||||
var themes = _themeService.GetInstalledThemes();
|
||||
var currentTheme = _themeService.GetSiteTheme();
|
||||
var model = new ThemesIndexViewModel { CurrentTheme = currentTheme, Themes = themes };
|
||||
return View(model);
|
||||
}
|
||||
catch (Exception exception) {
|
||||
Services.Notifier.Error(T("Listing themes failed: " + exception.Message));
|
||||
return View(new ThemesIndexViewModel());
|
||||
}
|
||||
}
|
||||
|
||||
[HttpPost, FormValueAbsent("submit.Apply"), FormValueAbsent("submit.Cancel")]
|
||||
public ActionResult Preview(string themeName, string returnUrl) {
|
||||
try {
|
||||
if (!Services.Authorizer.Authorize(Permissions.ApplyTheme, T("Couldn't preview the current theme")))
|
||||
return new HttpUnauthorizedResult();
|
||||
_previewTheme.SetPreviewTheme(themeName);
|
||||
return Redirect(returnUrl ?? "~/");
|
||||
}
|
||||
catch (Exception exception) {
|
||||
Services.Notifier.Error(T("Previewing theme failed: " + exception.Message));
|
||||
return RedirectToAction("Index");
|
||||
}
|
||||
}
|
||||
|
||||
[HttpPost, ActionName("Preview"), FormValueRequired("submit.Apply")]
|
||||
public ActionResult ApplyPreview(string themeName, string returnUrl) {
|
||||
try {
|
||||
if (!Services.Authorizer.Authorize(Permissions.ApplyTheme, T("Couldn't preview the current theme")))
|
||||
return new HttpUnauthorizedResult();
|
||||
_previewTheme.SetPreviewTheme(null);
|
||||
_themeService.SetSiteTheme(themeName);
|
||||
return RedirectToAction("Index");
|
||||
}
|
||||
catch (Exception exception) {
|
||||
Services.Notifier.Error(T("Previewing theme failed: " + exception.Message));
|
||||
return RedirectToAction("Index");
|
||||
}
|
||||
}
|
||||
|
||||
[HttpPost, ActionName("Preview"), FormValueRequired("submit.Cancel")]
|
||||
public ActionResult CancelPreview(string returnUrl) {
|
||||
try {
|
||||
if (!Services.Authorizer.Authorize(Permissions.ApplyTheme, T("Couldn't preview the current theme")))
|
||||
return new HttpUnauthorizedResult();
|
||||
_previewTheme.SetPreviewTheme(null);
|
||||
return RedirectToAction("Index");
|
||||
}
|
||||
catch (Exception exception) {
|
||||
Services.Notifier.Error(T("Previewing theme failed: " + exception.Message));
|
||||
return RedirectToAction("Index");
|
||||
}
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
public ActionResult Activate(string themeName) {
|
||||
try {
|
||||
if (!Services.Authorizer.Authorize(Permissions.ApplyTheme, T("Couldn't set the current theme")))
|
||||
return new HttpUnauthorizedResult();
|
||||
_themeService.SetSiteTheme(themeName);
|
||||
return RedirectToAction("Index");
|
||||
}
|
||||
catch (Exception exception) {
|
||||
Services.Notifier.Error(T("Activating theme failed: " + exception.Message));
|
||||
return RedirectToAction("Index");
|
||||
}
|
||||
}
|
||||
|
||||
public ActionResult Install() {
|
||||
return View(new BaseViewModel());
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
public ActionResult Install(FormCollection input) {
|
||||
try {
|
||||
if (!Services.Authorizer.Authorize(Permissions.ManageThemes, T("Couldn't install theme")))
|
||||
return new HttpUnauthorizedResult();
|
||||
foreach (string fileName in Request.Files) {
|
||||
HttpPostedFileBase file = Request.Files[fileName];
|
||||
_themeService.InstallTheme(file);
|
||||
}
|
||||
return RedirectToAction("Index");
|
||||
}
|
||||
catch (Exception exception) {
|
||||
Services.Notifier.Error(T("Installing theme failed: " + exception.Message));
|
||||
return RedirectToAction("Index");
|
||||
}
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
public ActionResult Uninstall(string themeName) {
|
||||
try {
|
||||
if (!Services.Authorizer.Authorize(Permissions.ManageThemes, T("Couldn't uninstall theme")))
|
||||
return new HttpUnauthorizedResult();
|
||||
_themeService.UninstallTheme(themeName);
|
||||
return RedirectToAction("Index");
|
||||
}
|
||||
catch (Exception exception) {
|
||||
Services.Notifier.Error(T("Uninstalling theme failed: " + exception.Message));
|
||||
return RedirectToAction("Index");
|
||||
}
|
||||
}
|
||||
|
||||
class FormValueRequiredAttribute : ActionMethodSelectorAttribute {
|
||||
private readonly string _submitButtonName;
|
||||
|
||||
public FormValueRequiredAttribute(string submitButtonName) {
|
||||
_submitButtonName = submitButtonName;
|
||||
}
|
||||
|
||||
public override bool IsValidForRequest(ControllerContext controllerContext, MethodInfo methodInfo) {
|
||||
var value = controllerContext.HttpContext.Request.Form[_submitButtonName];
|
||||
return !string.IsNullOrEmpty(value);
|
||||
}
|
||||
}
|
||||
|
||||
[AttributeUsage(AttributeTargets.Method, AllowMultiple = true)]
|
||||
class FormValueAbsentAttribute : ActionMethodSelectorAttribute {
|
||||
private readonly string _submitButtonName;
|
||||
|
||||
public FormValueAbsentAttribute(string submitButtonName) {
|
||||
_submitButtonName = submitButtonName;
|
||||
}
|
||||
|
||||
public override bool IsValidForRequest(ControllerContext controllerContext, MethodInfo methodInfo) {
|
||||
var value = controllerContext.HttpContext.Request.Form[_submitButtonName];
|
||||
return string.IsNullOrEmpty(value);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user