diff --git a/components/editorControls/tinyMCE3/webcontrol/TinyMCEWebControl.cs b/components/editorControls/tinyMCE3/webcontrol/TinyMCEWebControl.cs index f72fb669ef..21e9c00a7a 100644 --- a/components/editorControls/tinyMCE3/webcontrol/TinyMCEWebControl.cs +++ b/components/editorControls/tinyMCE3/webcontrol/TinyMCEWebControl.cs @@ -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 = "]*src=\"(?/media[^\"]*)\" [^>]*>"; + string pattern = String.Format("]*src=\"(?{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, ""); diff --git a/components/editorControls/tinymce/tinyMCEImageHelper.cs b/components/editorControls/tinymce/tinyMCEImageHelper.cs index 90f7568583..9dc1660091 100644 --- a/components/editorControls/tinymce/tinyMCEImageHelper.cs +++ b/components/editorControls/tinymce/tinyMCEImageHelper.cs @@ -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"); diff --git a/umbraco/businesslogic/IO/IOHelper.cs b/umbraco/businesslogic/IO/IOHelper.cs index b20a3f1962..79e47744c9 100644 --- a/umbraco/businesslogic/IO/IOHelper.cs +++ b/umbraco/businesslogic/IO/IOHelper.cs @@ -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 /// /// - 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; - } + } } } diff --git a/umbraco/presentation/macro.cs b/umbraco/presentation/macro.cs index 0ef0bf5f38..bc3ba59b68 100644 --- a/umbraco/presentation/macro.cs +++ b/umbraco/presentation/macro.cs @@ -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() diff --git a/umbraco/presentation/umbraco/templateControls/ItemRenderer.cs b/umbraco/presentation/umbraco/templateControls/ItemRenderer.cs index 2bd3f6a4cc..a78cd1fe10 100644 --- a/umbraco/presentation/umbraco/templateControls/ItemRenderer.cs +++ b/umbraco/presentation/umbraco/templateControls/ItemRenderer.cs @@ -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) {