Back ports fixes for: #U4-1614, #U4-793 - preview working properly in mvc
This commit is contained in:
@@ -9,6 +9,7 @@ using System.Web.Mvc.Html;
|
||||
using System.Web.Routing;
|
||||
using Umbraco.Core;
|
||||
using Umbraco.Core.Dynamics;
|
||||
using Umbraco.Core.IO;
|
||||
using Umbraco.Web.Mvc;
|
||||
using umbraco;
|
||||
using umbraco.cms.businesslogic.member;
|
||||
@@ -20,6 +21,30 @@ namespace Umbraco.Web
|
||||
/// </summary>
|
||||
public static class HtmlHelperRenderExtensions
|
||||
{
|
||||
/// <summary>
|
||||
/// Will render the preview badge when in preview mode which is not required ever unless the MVC page you are
|
||||
/// using does not inherit from UmbracoTemplatePage
|
||||
/// </summary>
|
||||
/// <param name="helper"></param>
|
||||
/// <returns></returns>
|
||||
/// <remarks>
|
||||
/// See: http://issues.umbraco.org/issue/U4-1614
|
||||
/// </remarks>
|
||||
public static MvcHtmlString PreviewBadge(this HtmlHelper helper)
|
||||
{
|
||||
if (UmbracoContext.Current.InPreviewMode)
|
||||
{
|
||||
var htmlBadge =
|
||||
String.Format(UmbracoSettings.PreviewBadge,
|
||||
IOHelper.ResolveUrl(SystemDirectories.Umbraco),
|
||||
IOHelper.ResolveUrl(SystemDirectories.UmbracoClient),
|
||||
UmbracoContext.Current.HttpContext.Server.UrlEncode(UmbracoContext.Current.HttpContext.Request.Path));
|
||||
return new MvcHtmlString(htmlBadge);
|
||||
}
|
||||
return new MvcHtmlString("");
|
||||
|
||||
}
|
||||
|
||||
public static IHtmlString CachedPartial(
|
||||
this HtmlHelper htmlHelper,
|
||||
string partialViewName,
|
||||
|
||||
@@ -1,5 +1,10 @@
|
||||
using System;
|
||||
using Umbraco.Core;
|
||||
using Umbraco.Core.Configuration;
|
||||
using Umbraco.Core.Dictionary;
|
||||
using Umbraco.Core.Dynamics;
|
||||
using Umbraco.Core.IO;
|
||||
using Umbraco.Core.Logging;
|
||||
using Umbraco.Core.Models;
|
||||
using Umbraco.Web.Models;
|
||||
|
||||
@@ -60,5 +65,33 @@ namespace Umbraco.Web.Mvc
|
||||
get { return _helper ?? (_helper = new UmbracoHelper(UmbracoContext, Model.Content)); }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// This will detect the end /body tag and insert the preview badge if in preview mode
|
||||
/// </summary>
|
||||
/// <param name="value"></param>
|
||||
public override void WriteLiteral(object value)
|
||||
{
|
||||
// filter / add preview banner
|
||||
if (Response.ContentType.InvariantEquals("text/html") && UmbracoContext.Current.InPreviewMode) // ASP.NET default value
|
||||
{
|
||||
var text = value.ToString().ToLowerInvariant();
|
||||
int pos = text.IndexOf("</body>");
|
||||
if (pos > -1)
|
||||
{
|
||||
var htmlBadge =
|
||||
String.Format(UmbracoSettings.PreviewBadge,
|
||||
IOHelper.ResolveUrl(SystemDirectories.Umbraco),
|
||||
IOHelper.ResolveUrl(SystemDirectories.UmbracoClient),
|
||||
Server.UrlEncode(UmbracoContext.Current.HttpContext.Request.Path));
|
||||
|
||||
text = text.Substring(0, pos) + htmlBadge + text.Substring(pos, text.Length - pos);
|
||||
base.WriteLiteral(text);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
base.WriteLiteral(value);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -16,6 +16,7 @@ using System.IO;
|
||||
using umbraco.cms.businesslogic.web;
|
||||
using umbraco.BusinessLogic;
|
||||
using umbraco.cms.businesslogic;
|
||||
using Umbraco.Core.IO;
|
||||
|
||||
namespace umbraco.presentation.preview
|
||||
{
|
||||
@@ -38,12 +39,12 @@ namespace umbraco.presentation.preview
|
||||
|
||||
public PreviewContent(Guid previewSet)
|
||||
{
|
||||
ValidPreviewSet = updatePreviewPaths(previewSet, true);
|
||||
ValidPreviewSet = UpdatePreviewPaths(previewSet, true);
|
||||
}
|
||||
public PreviewContent(User user, Guid previewSet, bool validate)
|
||||
{
|
||||
_userId = user.Id;
|
||||
ValidPreviewSet = updatePreviewPaths(previewSet, validate);
|
||||
ValidPreviewSet = UpdatePreviewPaths(previewSet, validate);
|
||||
}
|
||||
|
||||
|
||||
@@ -85,7 +86,7 @@ namespace umbraco.presentation.preview
|
||||
|
||||
}
|
||||
|
||||
private bool updatePreviewPaths(Guid previewSet, bool validate)
|
||||
private bool UpdatePreviewPaths(Guid previewSet, bool validate)
|
||||
{
|
||||
if (_userId == -1)
|
||||
{
|
||||
@@ -112,8 +113,8 @@ namespace umbraco.presentation.preview
|
||||
|
||||
private static string GetPreviewsetPath(int userId, Guid previewSet)
|
||||
{
|
||||
return IO.IOHelper.MapPath(
|
||||
Path.Combine(IO.SystemDirectories.Preview, userId + "_" + previewSet + ".config"));
|
||||
return IOHelper.MapPath(
|
||||
Path.Combine(SystemDirectories.Preview, userId + "_" + previewSet + ".config"));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -139,7 +140,7 @@ namespace umbraco.presentation.preview
|
||||
public void SavePreviewSet()
|
||||
{
|
||||
//make sure the preview folder exists first
|
||||
var dir = new DirectoryInfo(IO.IOHelper.MapPath(IO.SystemDirectories.Preview));
|
||||
var dir = new DirectoryInfo(IOHelper.MapPath(SystemDirectories.Preview));
|
||||
if (!dir.Exists)
|
||||
{
|
||||
dir.Create();
|
||||
@@ -155,17 +156,17 @@ namespace umbraco.presentation.preview
|
||||
{
|
||||
foreach (FileInfo file in dir.GetFiles(userId + "_*.config"))
|
||||
{
|
||||
deletePreviewFile(userId, file);
|
||||
DeletePreviewFile(userId, file);
|
||||
}
|
||||
// also delete any files accessed more than one hour ago
|
||||
foreach (FileInfo file in dir.GetFiles("*.config"))
|
||||
{
|
||||
if ((DateTime.Now - file.LastAccessTime).TotalMinutes > 1)
|
||||
deletePreviewFile(userId, file);
|
||||
DeletePreviewFile(userId, file);
|
||||
}
|
||||
}
|
||||
|
||||
private static void deletePreviewFile(int userId, FileInfo file)
|
||||
private static void DeletePreviewFile(int userId, FileInfo file)
|
||||
{
|
||||
try
|
||||
{
|
||||
@@ -191,7 +192,7 @@ namespace umbraco.presentation.preview
|
||||
if (StateHelper.Cookies.Preview.HasValue)
|
||||
{
|
||||
|
||||
deletePreviewFile(
|
||||
DeletePreviewFile(
|
||||
UmbracoContext.Current.UmbracoUser.Id,
|
||||
new FileInfo(GetPreviewsetPath(
|
||||
UmbracoContext.Current.UmbracoUser.Id,
|
||||
|
||||
Reference in New Issue
Block a user