Updatedt TinyMCEWebControl.cs to use IFileSystem

This commit is contained in:
Matt@MBP13-PC
2012-08-21 06:42:01 -01:00
parent efe0970245
commit d30b5b0b2c
2 changed files with 18 additions and 13 deletions

View File

@@ -157,7 +157,8 @@ namespace Umbraco.Core.IO
{
return _rootUrl.TrimEnd("/") + "/" + path
.TrimStart(Path.DirectorySeparatorChar)
.Replace(Path.DirectorySeparatorChar, '/');
.Replace(Path.DirectorySeparatorChar, '/')
.TrimEnd("/");
}
public DateTimeOffset GetLastModified(string path)

View File

@@ -7,7 +7,7 @@ using System.Collections;
using System.Collections.Specialized;
using System.IO;
using System.Text.RegularExpressions;
using Umbraco.Core.IO;
using umbraco.BusinessLogic;
using umbraco.cms.businesslogic.macro;
using umbraco.cms.businesslogic.media;
@@ -21,6 +21,7 @@ namespace umbraco.editorControls.tinyMCE3.webcontrol
{
public class TinyMCEWebControl : System.Web.UI.WebControls.TextBox
{
internal readonly IMediaFileSystem _fs;
public NameValueCollection config = new NameValueCollection();
private string temp;
@@ -66,6 +67,8 @@ namespace umbraco.editorControls.tinyMCE3.webcontrol
public TinyMCEWebControl()
: base()
{
_fs = FileSystemProviderManager.Current.GetFileSystemProvider<IMediaFileSystem>();
base.TextMode = TextBoxMode.MultiLine;
base.Attributes.Add("style", "visibility: hidden");
config.Add("mode", "exact");
@@ -284,14 +287,15 @@ namespace umbraco.editorControls.tinyMCE3.webcontrol
private string formatMedia(string html)
{
// Local media path
string localMediaPath = IOHelper.ResolveUrl(SystemDirectories.Media);
// root media url
var rootMediaUrl = _fs.GetUrl("");
// Find all media images
string pattern = String.Format("<img [^>]*src=\"(?<mediaString>{0}[^\"]*)\" [^>]*>", localMediaPath);
var pattern = String.Format("<img [^>]*src=\"(?<mediaString>{0}[^\"]*)\" [^>]*>", rootMediaUrl);
MatchCollection tags =
Regex.Matches(html, pattern, RegexOptions.IgnoreCase | RegexOptions.IgnorePatternWhitespace);
foreach (Match tag in tags)
if (tag.Groups.Count > 0)
{
@@ -331,7 +335,7 @@ namespace umbraco.editorControls.tinyMCE3.webcontrol
IOHelper.ResolveUrl(orgSrc.Replace("%20", " "));
// Check for either id or guid from media
string mediaId = getIdFromSource(orgSrc, localMediaPath);
string mediaId = getIdFromSource(orgSrc, rootMediaUrl);
Media imageMedia = null;
@@ -381,18 +385,18 @@ namespace umbraco.editorControls.tinyMCE3.webcontrol
return html;
}
private string getIdFromSource(string src, string localMediaPath)
private string getIdFromSource(string src, string rootMediaUrl)
{
if (!localMediaPath.EndsWith("/"))
localMediaPath += "/";
if (!rootMediaUrl.EndsWith("/"))
rootMediaUrl += "/";
// important - remove out the umbraco path + media!
src = src.Replace(localMediaPath, "");
// important - remove out the rootMediaUrl!
src = src.Replace(rootMediaUrl, "");
string _id = "";
// Check for directory id naming
if (src.Length - src.Replace("/", "").Length > 0)
if (src.Contains("/"))
{
string[] dirSplit = src.Split("/".ToCharArray());
string tempId = dirSplit[0];
@@ -409,7 +413,7 @@ namespace umbraco.editorControls.tinyMCE3.webcontrol
}
else
{
string[] fileSplit = src.Replace("/media/", "").Split("-".ToCharArray());
string[] fileSplit = src.Split("-".ToCharArray());
// guid or id
if (fileSplit.Length > 3)