Fixes 28050, 28145 and 28176. Various issues with virtual directories and media + xslt
[TFS Changeset #73401]
This commit is contained in:
@@ -285,10 +285,10 @@ namespace umbraco.editorControls.tinyMCE3.webcontrol
|
||||
private string formatMedia(string html)
|
||||
{
|
||||
// Local media path
|
||||
string localMediaPath = getLocalMediaPath();
|
||||
string localMediaPath = IOHelper.ResolveUrl(SystemDirectories.Media);
|
||||
|
||||
// Find all media images
|
||||
string pattern = "<img [^>]*src=\"(?<mediaString>/media[^\"]*)\" [^>]*>";
|
||||
string pattern = String.Format("<img [^>]*src=\"(?<mediaString>{0}[^\"]*)\" [^>]*>", SystemDirectories.Media);
|
||||
|
||||
MatchCollection tags =
|
||||
Regex.Matches(html, pattern, RegexOptions.IgnoreCase | RegexOptions.IgnorePatternWhitespace);
|
||||
@@ -321,9 +321,9 @@ namespace umbraco.editorControls.tinyMCE3.webcontrol
|
||||
|
||||
// Find the original filename, by removing the might added width and height
|
||||
orgSrc =
|
||||
orgSrc.Replace(
|
||||
IOHelper.ResolveUrl(orgSrc.Replace(
|
||||
"_" + helper.FindAttribute(ht, "width") + "x" + helper.FindAttribute(ht, "height"), "").
|
||||
Replace("%20", " ");
|
||||
Replace("%20", " "));
|
||||
|
||||
// Check for either id or guid from media
|
||||
string mediaId = getIdFromSource(orgSrc, localMediaPath);
|
||||
@@ -383,6 +383,9 @@ namespace umbraco.editorControls.tinyMCE3.webcontrol
|
||||
|
||||
private string getIdFromSource(string src, string localMediaPath)
|
||||
{
|
||||
if (!localMediaPath.EndsWith("/"))
|
||||
localMediaPath += "/";
|
||||
|
||||
// important - remove out the umbraco path + media!
|
||||
src = src.Replace(localMediaPath, "");
|
||||
|
||||
|
||||
@@ -139,8 +139,6 @@ namespace umbraco.editorControls.tinymce
|
||||
int newWidth = int.Parse(resizeDimSplit[0]);
|
||||
int newHeight = int.Parse(resizeDimSplit[1]);
|
||||
|
||||
//THIS I DO NOW KNOW HOW TO MAKE WORK WITH A VIRTUAL DIRECTORY...
|
||||
|
||||
if (orgHeight > 0 && orgWidth > 0 && resizeDim != "" && orgSrc != "")
|
||||
{
|
||||
// Check dimensions
|
||||
@@ -154,9 +152,11 @@ namespace umbraco.editorControls.tinymce
|
||||
}
|
||||
|
||||
// update orgSrc to remove umbraco reference
|
||||
if (IOHelper.ResolveUrl(orgSrc).IndexOf( IOHelper.ResolveUrl(SystemDirectories.Media)) > -1)
|
||||
orgSrc = orgSrc.Substring( orgSrc.IndexOf("/media/"), orgSrc.Length - orgSrc.IndexOf("/media/") );
|
||||
|
||||
string resolvedMedia = IOHelper.ResolveUrl(SystemDirectories.Media);
|
||||
if (IOHelper.ResolveUrl(orgSrc).IndexOf(resolvedMedia) > -1)
|
||||
{
|
||||
orgSrc = SystemDirectories.Media + orgSrc.Substring(orgSrc.IndexOf(resolvedMedia) + resolvedMedia.Length); //, orgSrc.Length - orgSrc.IndexOf(String.Format("/media/", SystemDirectories.Media)));
|
||||
}
|
||||
string ext = orgSrc.Substring(orgSrc.LastIndexOf(".") + 1, orgSrc.Length - orgSrc.LastIndexOf(".") - 1);
|
||||
newSrc = orgSrc.Replace("." + ext, "_" + newWidth.ToString() + "x" + newHeight.ToString() + ".jpg");
|
||||
|
||||
|
||||
@@ -6,6 +6,7 @@ using System.IO;
|
||||
using System.Configuration;
|
||||
using System.Web;
|
||||
using umbraco.BusinessLogic;
|
||||
using System.Text.RegularExpressions;
|
||||
|
||||
namespace umbraco.IO
|
||||
{
|
||||
@@ -28,8 +29,8 @@ namespace umbraco.IO
|
||||
|
||||
if (virtualPath.StartsWith("~"))
|
||||
retval = virtualPath.Replace("~", SystemDirectories.Root);
|
||||
|
||||
if(virtualPath.StartsWith("/") && !virtualPath.StartsWith(SystemDirectories.Root))
|
||||
|
||||
if (virtualPath.StartsWith("/") && !virtualPath.StartsWith(SystemDirectories.Root))
|
||||
retval = SystemDirectories.Root + "/" + virtualPath.TrimStart('/');
|
||||
|
||||
return retval;
|
||||
@@ -39,15 +40,42 @@ namespace umbraco.IO
|
||||
public static string ResolveUrl(string virtualPath)
|
||||
{
|
||||
if (virtualPath.StartsWith("~"))
|
||||
return virtualPath.Replace("~", SystemDirectories.Root).Replace("//","/");
|
||||
return virtualPath.Replace("~", SystemDirectories.Root).Replace("//", "/");
|
||||
else
|
||||
return VirtualPathUtility.ToAbsolute(virtualPath, SystemDirectories.Root);
|
||||
}
|
||||
|
||||
public static string ResolveUrlsFromTextString(string text)
|
||||
{
|
||||
// find all relative urls (ie. urls that contain ~)
|
||||
string pattern = "(/~/[^'\"\\s\\v]*)[\"\\s\\<]|(~/[^'\"\\s\\v]*)[\"\\s\\<]|(~/[^'\"\\s\\v]*)";
|
||||
MatchCollection tags =
|
||||
Regex.Matches(text, pattern, RegexOptions.IgnoreCase | RegexOptions.IgnorePatternWhitespace);
|
||||
foreach (Match tag in tags)
|
||||
{
|
||||
string url = "";
|
||||
if (tag.Groups[0].Success)
|
||||
url = tag.Groups[0].Value;
|
||||
else if (tag.Groups[1].Success)
|
||||
url = tag.Groups[1].Value;
|
||||
else
|
||||
url = tag.Groups[2].Value;
|
||||
|
||||
// The richtext editor inserts a slash in front of the url. That's why we need this little fix
|
||||
// if (url.StartsWith("/"))
|
||||
// text = text.Replace(url, ResolveUrl(url.Substring(1)));
|
||||
// else
|
||||
text = text.Replace(url, ResolveUrl(url));
|
||||
|
||||
}
|
||||
|
||||
return text;
|
||||
}
|
||||
|
||||
public static string MapPath(string path, bool useHttpContext)
|
||||
{
|
||||
// Check if the path is already mapped
|
||||
if (path.Length >= 2 && path[1] == Path.VolumeSeparatorChar)
|
||||
if (path.Length >= 2 && path[1] == Path.VolumeSeparatorChar)
|
||||
return path;
|
||||
|
||||
if (useHttpContext)
|
||||
@@ -59,13 +87,13 @@ namespace umbraco.IO
|
||||
return System.Web.Hosting.HostingEnvironment.MapPath("~/" + path.TrimStart('/'));
|
||||
}
|
||||
else
|
||||
{
|
||||
{
|
||||
string _root = (!String.IsNullOrEmpty(System.Web.Hosting.HostingEnvironment.ApplicationPhysicalPath)) ? System.Web.Hosting.HostingEnvironment.ApplicationPhysicalPath.TrimEnd(IOHelper.DirSepChar) : getRootDirectorySafe();
|
||||
|
||||
string _path = path.TrimStart('~','/').Replace('/', IOHelper.DirSepChar);
|
||||
string _path = path.TrimStart('~', '/').Replace('/', IOHelper.DirSepChar);
|
||||
|
||||
string retval = _root + IOHelper.DirSepChar.ToString() + _path;
|
||||
|
||||
|
||||
return retval;
|
||||
}
|
||||
}
|
||||
@@ -80,13 +108,13 @@ namespace umbraco.IO
|
||||
{
|
||||
string retval = ConfigurationManager.AppSettings[settingsKey];
|
||||
|
||||
if ( string.IsNullOrEmpty(retval) )
|
||||
if (string.IsNullOrEmpty(retval))
|
||||
retval = standardPath;
|
||||
|
||||
return retval.TrimEnd('/');
|
||||
}
|
||||
|
||||
|
||||
|
||||
public static string returnPath(string settingsKey, string standardPath)
|
||||
{
|
||||
return returnPath(settingsKey, standardPath, false);
|
||||
@@ -99,7 +127,8 @@ namespace umbraco.IO
|
||||
/// even if the assembly is in a /bin/debug or /bin/release folder
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
private static string getRootDirectorySafe() {
|
||||
private static string getRootDirectorySafe()
|
||||
{
|
||||
if (!String.IsNullOrEmpty(m_rootDir))
|
||||
{
|
||||
return m_rootDir;
|
||||
@@ -107,11 +136,11 @@ namespace umbraco.IO
|
||||
|
||||
string baseDirectory =
|
||||
System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().CodeBase.Substring(8));
|
||||
m_rootDir = baseDirectory.Substring(0, baseDirectory.LastIndexOf("bin")-1);
|
||||
m_rootDir = baseDirectory.Substring(0, baseDirectory.LastIndexOf("bin") - 1);
|
||||
|
||||
return m_rootDir;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -739,7 +739,7 @@ namespace umbraco
|
||||
// Do transformation
|
||||
HttpContext.Current.Trace.Write("umbracoMacro", "Before performing transformation");
|
||||
xslt.Transform(macroXML.CreateNavigator(), xslArgs, tw);
|
||||
return tw.ToString();
|
||||
return IOHelper.ResolveUrlsFromTextString(tw.ToString());
|
||||
}
|
||||
|
||||
public static XsltArgumentList AddXsltExtensions()
|
||||
|
||||
@@ -10,6 +10,7 @@ using umbraco.cms.businesslogic;
|
||||
using umbraco.cms.businesslogic.property;
|
||||
using umbraco.cms.businesslogic.web;
|
||||
using umbraco.presentation.umbraco.templateControls;
|
||||
using umbraco.IO;
|
||||
|
||||
namespace umbraco.presentation.templateControls
|
||||
{
|
||||
@@ -62,7 +63,8 @@ namespace umbraco.presentation.templateControls
|
||||
: XsltTransform(item.Xslt, renderOutput, item.XsltDisableEscaping);
|
||||
// handle text before/after
|
||||
xsltTransformedOutput = AddBeforeAfterText(xsltTransformedOutput, helper.FindAttribute(item.LegacyAttributes, "insertTextBefore"), helper.FindAttribute(item.LegacyAttributes, "insertTextAfter"));
|
||||
writer.Write(xsltTransformedOutput.Trim().Length > 0 ? xsltTransformedOutput : GetEmptyText(item));
|
||||
string finalResult = xsltTransformedOutput.Trim().Length > 0 ? xsltTransformedOutput : GetEmptyText(item);
|
||||
writer.Write(IOHelper.ResolveUrlsFromTextString(finalResult));
|
||||
}
|
||||
catch (Exception renderException)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user