Merge with 4.11.2

This commit is contained in:
Sebastiaan Janssen
2012-12-28 09:02:45 -01:00
8 changed files with 108 additions and 205 deletions

View File

@@ -1,8 +1,8 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Text;
using System.Web;
using Umbraco.Core.CodeAnnotations;
using Umbraco.Core.Logging;
@@ -10,7 +10,6 @@ using Umbraco.Core.Publishing;
namespace Umbraco.Core.IO
{
[UmbracoExperimentalFeature("http://issues.umbraco.org/issue/U4-1156", "Will be declared public after 4.10")]
internal class PhysicalFileSystem : IFileSystem
{
@@ -45,9 +44,13 @@ namespace Umbraco.Core.IO
return Directory.EnumerateDirectories(path).Select(GetRelativePath);
}
catch (UnauthorizedAccessException ex)
{ }
{
LogHelper.Error<PhysicalFileSystem>("Not authorized to get directories", ex);
}
catch (DirectoryNotFoundException ex)
{ }
{
LogHelper.Error<PhysicalFileSystem>("Directory not found", ex);
}
return Enumerable.Empty<string>();
}
@@ -67,7 +70,9 @@ namespace Umbraco.Core.IO
Directory.Delete(GetFullPath(path), recursive);
}
catch (DirectoryNotFoundException ex)
{ }
{
LogHelper.Error<PhysicalFileSystem>("Directory not found", ex);
}
}
public bool DirectoryExists(string path)
@@ -82,9 +87,7 @@ namespace Umbraco.Core.IO
public void AddFile(string path, Stream stream, bool overrideIfExists)
{
if (FileExists(path) && !overrideIfExists)
throw new InvalidOperationException(string.Format("A file at path '{0}' already exists",
path));
if (FileExists(path) && !overrideIfExists) throw new InvalidOperationException(string.Format("A file at path '{0}' already exists", path));
EnsureDirectory(Path.GetDirectoryName(path));
@@ -110,9 +113,13 @@ namespace Umbraco.Core.IO
return Directory.EnumerateFiles(path, filter).Select(GetRelativePath);
}
catch (UnauthorizedAccessException ex)
{ }
{
LogHelper.Error<PhysicalFileSystem>("Not authorized to get directories", ex);
}
catch (DirectoryNotFoundException ex)
{ }
{
LogHelper.Error<PhysicalFileSystem>("Directory not found", ex);
}
return Enumerable.Empty<string>();
}
@@ -193,7 +200,7 @@ namespace Umbraco.Core.IO
protected string EnsureTrailingSeparator(string path)
{
if (!path.EndsWith(Path.DirectorySeparatorChar.ToString(), StringComparison.Ordinal))
if (!path.EndsWith(Path.DirectorySeparatorChar.ToString(CultureInfo.InvariantCulture), StringComparison.Ordinal))
path = path + Path.DirectorySeparatorChar;
return path;

View File

@@ -342,8 +342,8 @@ namespace umbraco.cms.presentation.Trees
set
{
m_notPublished = value;
if (m_notPublished.HasValue && m_notPublished.Value)
this.Style.HighlightNode();
if (m_notPublished.HasValue && m_notPublished.Value)
this.Style.DimNode();
}
}

View File

@@ -1,19 +1,12 @@
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using System.Linq;
using System.Xml;
using umbraco.BasePages;
using umbraco.uicontrols;
using umbraco.cms.businesslogic.datatype;
using umbraco.interfaces;
using umbraco.cms.businesslogic.media;
using Media = umbraco.cms.businesslogic.media.Media;
namespace umbraco.controls.Images
{
@@ -23,7 +16,7 @@ namespace umbraco.controls.Images
/// Includes ability to select where in the media you would like it to upload and also supports client
/// callback methods once complete.
/// </summary>
public partial class UploadMediaImage : System.Web.UI.UserControl
public partial class UploadMediaImage : UserControl
{
public UploadMediaImage()
@@ -42,7 +35,7 @@ namespace umbraco.controls.Images
/// </summary>
public string OnClientUpload { get; set; }
protected IDataType UploadField = new cms.businesslogic.datatype.controls.Factory().GetNewObject(new Guid("5032a6e6-69e3-491d-bb28-cd31cd11086c"));
protected IDataType UploadField = DataTypeDefinition.GetByDataTypeId(new Guid("5032a6e6-69e3-491d-bb28-cd31cd11086c")).DataType;
protected override void OnInit(EventArgs e)
{
@@ -66,39 +59,35 @@ namespace umbraco.controls.Images
protected void SubmitButton_Click(object sender, EventArgs e)
{
int parent = int.Parse(MediaPickerControl.Value);
if (BusinessLogic.User.GetCurrent().StartMediaId != -1 && parent == -1)
parent = BusinessLogic.User.GetCurrent().StartNodeId;
var media = Media.MakeNew(TextBoxTitle.Text, cms.businesslogic.media.MediaType.GetByAlias("image"), BasePage.Current.getUser(), int.Parse(MediaPickerControl.Value));
Media m = Media.MakeNew(TextBoxTitle.Text, cms.businesslogic.media.MediaType.GetByAlias("image"), BasePage.Current.getUser(), int.Parse(MediaPickerControl.Value));
var props = m.GenericProperties;
foreach (cms.businesslogic.property.Property p in props)
foreach (var property in media.GenericProperties)
{
if (p.PropertyType.DataTypeDefinition.DataType.Id == UploadField.Id)
if (property.PropertyType.DataTypeDefinition.DataType.Id == UploadField.Id)
{
UploadField.DataTypeDefinitionId = p.PropertyType.DataTypeDefinition.Id;
UploadField.Data.PropertyId = p.Id;
UploadField.DataTypeDefinitionId = property.PropertyType.DataTypeDefinition.Id;
UploadField.Data.PropertyId = property.Id;
}
}
UploadField.DataEditor.Save();
// Generate xml on image
m.XmlGenerate(new XmlDocument());
media.XmlGenerate(new XmlDocument());
pane_upload.Visible = false;
//this seems real ugly since we apparently already have the properties above (props)... but this data layer is insane and undecipherable:)
string mainImage = m.getProperty("umbracoFile").Value.ToString();
string mainImage = media.getProperty("umbracoFile").Value.ToString();
string extension = mainImage.Substring(mainImage.LastIndexOf(".") + 1, mainImage.Length - mainImage.LastIndexOf(".") - 1);
var thumbnail = mainImage.Remove(mainImage.Length - extension.Length - 1, extension.Length + 1) + "_thumb.jpg";
string width = m.getProperty("umbracoWidth").Value.ToString();
string height = m.getProperty("umbracoHeight").Value.ToString();
int id = m.Id;
string width = media.getProperty("umbracoWidth").Value.ToString();
string height = media.getProperty("umbracoHeight").Value.ToString();
int id = media.Id;
feedback.Style.Add("margin-top", "8px");
feedback.type = uicontrols.Feedback.feedbacktype.success;
if (mainImage.StartsWith("~")) mainImage = mainImage.Substring(1);
if (thumbnail.StartsWith("~")) thumbnail = thumbnail.Substring(1);
feedback.Text += "<div style=\"text-align: center\"> <a target=\"_blank\" href='" + umbraco.IO.IOHelper.ResolveUrl(umbraco.IO.SystemDirectories.Umbraco) + "/.." + mainImage + "'><img src='" + umbraco.IO.IOHelper.ResolveUrl(umbraco.IO.SystemDirectories.Umbraco) + "/.." + thumbnail + "' style='border: none;'/><br/><br/>";
feedback.Text += "<div style=\"text-align: center\"> <a target=\"_blank\" href='" + mainImage + "'><img src='" + thumbnail + "' style='border: none;'/><br/><br/>";
feedback.Text += ui.Text("thumbnailimageclickfororiginal") + "</a><br/><br/></div>";
if (!string.IsNullOrEmpty(OnClientUpload))
@@ -106,7 +95,7 @@ namespace umbraco.controls.Images
feedback.Text += @"
<script type=""text/javascript"">
jQuery(document).ready(function() {
" + OnClientUpload + @".call(this, {imagePath: '" + mainImage + @"', thumbnailPath: '" + thumbnail + @"', width: " + width + @", height: " + height + @", id: " + id.ToString() + @"});
" + OnClientUpload + @".call(this, {imagePath: '" + mainImage + @"', thumbnailPath: '" + thumbnail + @"', width: " + width + @", height: " + height + @", id: " + id + @"});
});
</script>";
}

View File

@@ -327,6 +327,9 @@ namespace umbraco.cms.presentation
UnPublish.Visible = true;
_documentHasPublishedVersion = _document.HasPublishedVersion();
foreach (var descendant in _document.GetDescendants().Cast<Document>().Where(descendant => descendant.HasPublishedVersion()))
library.UpdateDocumentCache(descendant.Id);
}
else
{

View File

@@ -1,9 +1,7 @@
using System;
using System.Collections.Generic;
using System.Configuration;
using System.IO;
using System.Linq;
using System.Text;
using System.Web;
using System.Web.Configuration;
using System.Web.Script.Serialization;
@@ -138,19 +136,15 @@ namespace umbraco.presentation.umbraco.webservices
{
var pathParts = context.Request["path"].Trim('/').Split('/');
foreach (var pathPart in pathParts)
{
if (!string.IsNullOrEmpty(pathPart))
{
foreach (var pathPart in pathParts.Where(part => string.IsNullOrWhiteSpace(part) == false))
parentNode = GetOrCreateFolder(parentNode, pathPart);
}
}
parentNodeId = parentNode.Id;
}
// Check whether to replace existing
var parsed = false;
bool replaceExisting = (context.Request["replaceExisting"] == "1" || (bool.TryParse(context.Request["replaceExisting"], out parsed) && parsed));
bool parsed;
var replaceExisting = (context.Request["replaceExisting"] == "1" || (bool.TryParse(context.Request["replaceExisting"], out parsed) && parsed));
// loop through uploaded files
for (var j = 0; j < context.Request.Files.Count; j++)
@@ -202,11 +196,9 @@ namespace umbraco.presentation.umbraco.webservices
else
{
// log error
LogHelper.Debug<MediaUploader>(string.Format("Parent node id is in incorrect format: {0}", parentNodeId));
LogHelper.Warn<MediaUploader>(string.Format("Parent node id is in incorrect format: {0}", parentNodeId));
}
return new UploadResponse();
}
@@ -218,16 +210,16 @@ namespace umbraco.presentation.umbraco.webservices
if (GlobalSettings.UseSSL && !context.Request.IsSecureConnection)
throw new UserAuthorizationException("This installation requires a secure connection (via SSL). Please update the URL to include https://");
string username = context.Request["username"];
string password = context.Request["password"];
string ticket = context.Request["ticket"];
var username = context.Request["username"];
var password = context.Request["password"];
var ticket = context.Request["ticket"];
bool isValid = false;
var isValid = false;
if (!string.IsNullOrEmpty(username) && !string.IsNullOrEmpty(password))
{
var mp = Membership.Providers[UmbracoSettings.DefaultBackofficeProvider];
if (mp.ValidateUser(username, password))
if (mp != null && mp.ValidateUser(username, password))
{
var user = new User(username);
isValid = user.Applications.Any(app => app.alias == "media");
@@ -240,6 +232,8 @@ namespace umbraco.presentation.umbraco.webservices
{
var t = FormsAuthentication.Decrypt(ticket);
var user = new User(username);
if (t != null)
isValid = user.LoginName.ToLower() == t.Name.ToLower() && user.Applications.Any(app => app.alias == "media");
if (isValid)
@@ -279,14 +273,13 @@ namespace umbraco.presentation.umbraco.webservices
if (appSetting > 0)
return appSetting;
var configXml = new XmlDocument();
configXml.PreserveWhitespace = true;
var configXml = new XmlDocument { PreserveWhitespace = true };
configXml.Load(HttpContext.Current.Server.MapPath("/web.config"));
var requestLimitsNode = configXml.SelectSingleNode("//configuration/system.webServer/security/requestFiltering/requestLimits");
if (requestLimitsNode != null)
{
if (requestLimitsNode.Attributes["maxAllowedContentLength"] != null)
if (requestLimitsNode.Attributes != null && requestLimitsNode.Attributes["maxAllowedContentLength"] != null)
{
var maxAllowedContentLength = Convert.ToInt32(requestLimitsNode.Attributes["maxAllowedContentLength"].Value);
if (maxAllowedContentLength > 0)
@@ -295,10 +288,8 @@ namespace umbraco.presentation.umbraco.webservices
}
var httpRuntime = ConfigurationManager.GetSection("system.web/httpRuntime") as HttpRuntimeSection;
if (httpRuntime != null)
return httpRuntime.MaxRequestLength;
return 4096;
return httpRuntime == null ? 4096 : httpRuntime.MaxRequestLength;
}
private Media GetOrCreateFolder(Media parent, string name)

View File

@@ -10,8 +10,6 @@ using Umbraco.Core.Logging;
using umbraco.BasePages;
using umbraco.BusinessLogic;
using umbraco.cms.businesslogic.datatype;
using Encoder = System.Text.Encoder;
using Umbraco.Core.IO;
namespace umbraco.cms.businesslogic.media
{
@@ -27,10 +25,10 @@ namespace umbraco.cms.businesslogic.media
get { return new List<string> { "jpeg", "jpg", "gif", "bmp", "png", "tiff", "tif" }; }
}
public override void DoHandleMedia(Media media, PostedMediaFile postedFile, BusinessLogic.User user)
public override void DoHandleMedia(Media media, PostedMediaFile postedFile, User user)
{
// Get Image object, width and height
var image = System.Drawing.Image.FromStream(postedFile.InputStream);
var image = Image.FromStream(postedFile.InputStream);
var fileWidth = image.Width;
var fileHeight = image.Height;
@@ -43,9 +41,15 @@ namespace umbraco.cms.businesslogic.media
// Set media properties
media.getProperty("umbracoFile").Value = FileSystem.GetUrl(destFilePath);
media.getProperty("umbracoWidth").Value = fileWidth;
media.getProperty("umbracoHeight").Value = fileHeight;
media.getProperty("umbracoBytes").Value = postedFile.ContentLength;
if (media.getProperty("umbracoWidth") != null)
media.getProperty("umbracoWidth").Value = fileWidth;
if (media.getProperty("umbracoHeight") != null)
media.getProperty("umbracoHeight").Value = fileHeight;
if (media.getProperty("umbracoBytes") != null)
media.getProperty("umbracoBytes").Value = postedFile.ContentLength;
if (media.getProperty("umbracoExtension") != null)
media.getProperty("umbracoExtension").Value = ext;
@@ -79,7 +83,10 @@ namespace umbraco.cms.businesslogic.media
// Get DataTypeDefinition of upload field
dataTypeDef = DataTypeDefinition.GetByDataTypeId(uploadFieldDataTypeId);
}
catch { }
catch (Exception e)
{
LogHelper.Error<UmbracoImageMediaFactory>("Could get Upload Field datatype definition", e);
}
if (dataTypeDef != null)
{
@@ -95,8 +102,7 @@ namespace umbraco.cms.businesslogic.media
var thumbnailSizes = thumbnails.Split(";".ToCharArray());
foreach (var thumb in thumbnailSizes.Where(thumb => thumb != ""))
{
GenerateThumbnail(image, int.Parse(thumb), fileWidth, fileHeight, ext,
destFilePath + "_" + thumb + ".jpg");
GenerateThumbnail(image, int.Parse(thumb), fileWidth, fileHeight, ext, destFilePath + "_" + thumb + ".jpg");
}
}
}
@@ -116,6 +122,7 @@ namespace umbraco.cms.businesslogic.media
// fixes for empty width or height
if (widthTh == 0)
widthTh = 1;
if (heightTh == 0)
heightTh = 1;
@@ -132,15 +139,14 @@ namespace umbraco.cms.businesslogic.media
// Copy metadata
var codecs = ImageCodecInfo.GetImageEncoders();
ImageCodecInfo codec = null;
if (ext.ToLower() == "png" || ext.ToLower() == "gif")
codec = codecs.Single(t => t.MimeType.Equals("image/png"));
else
codec = codecs.Single(t => t.MimeType.Equals("image/jpeg"));
var codec = ext.ToLower() == "png" || ext.ToLower() == "gif"
? codecs.Single(t => t.MimeType.Equals("image/png"))
: codecs.Single(t => t.MimeType.Equals("image/jpeg"));
// Set compresion ratio to 90%
var ep = new EncoderParameters();
ep.Param[0] = new EncoderParameter(System.Drawing.Imaging.Encoder.Quality, 90L);
ep.Param[0] = new EncoderParameter(Encoder.Quality, 90L);
// Save the new image
if (codec != null)

View File

@@ -176,7 +176,7 @@
}
.multiNodePicker .header
{
width: 622px;
width: 618px;
}
.uc-treenode-noclick > a > div

View File

@@ -1,8 +1,5 @@
using System;
using System.Collections;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Drawing.Imaging;
using System.Text.RegularExpressions;
using System.Web;
using Umbraco.Core.IO;
@@ -17,47 +14,36 @@ namespace umbraco.editorControls.tinymce
{
public static string cleanImages(string html)
{
string[] allowedAttributes = UmbracoSettings.ImageAllowedAttributes.ToLower().Split(',');
string pattern = @"<img [^>]*>";
MatchCollection tags =
Regex.Matches(html + " ", pattern, RegexOptions.IgnoreCase | RegexOptions.IgnorePatternWhitespace);
var allowedAttributes = UmbracoSettings.ImageAllowedAttributes.ToLower().Split(',');
const string pattern = @"<img [^>]*>";
var tags = Regex.Matches(html + " ", pattern, RegexOptions.IgnoreCase | RegexOptions.IgnorePatternWhitespace);
foreach (Match tag in tags)
{
if (tag.Value.ToLower().IndexOf("umbraco_macro") == -1)
if (tag.Value.ToLower().IndexOf("umbraco_macro", StringComparison.Ordinal) == -1)
{
string cleanTag = "<img";
int orgWidth = 0, orgHeight = 0;
var cleanTag = "<img";
// gather all attributes
// TODO: This should be replaced with a general helper method - but for now we'll wanna leave umbraco.dll alone for this patch
Hashtable ht = new Hashtable();
MatchCollection m =
Regex.Matches(tag.Value.Replace(">", " >"),
"(?<attributeName>\\S*)=\"(?<attributeValue>[^\"]*)\"|(?<attributeName>\\S*)=(?<attributeValue>[^\"|\\s]*)\\s",
RegexOptions.IgnoreCase | RegexOptions.IgnorePatternWhitespace);
foreach (Match attributeSet in m)
var ht = new Hashtable();
var matches = Regex.Matches(tag.Value.Replace(">", " >"), "(?<attributeName>\\S*)=\"(?<attributeValue>[^\"]*)\"|(?<attributeName>\\S*)=(?<attributeValue>[^\"|\\s]*)\\s", RegexOptions.IgnoreCase | RegexOptions.IgnorePatternWhitespace);
foreach (Match attributeSet in matches)
{
ht.Add(attributeSet.Groups["attributeName"].Value.ToString().ToLower(),
attributeSet.Groups["attributeValue"].Value.ToString());
if (attributeSet.Groups["attributeName"].Value.ToString().ToLower() == "width")
int.TryParse(attributeSet.Groups["attributeValue"].Value.ToString(), out orgWidth);
else if (attributeSet.Groups["attributeName"].Value.ToString().ToLower() == "height")
int.TryParse(attributeSet.Groups["attributeValue"].Value.ToString(), out orgHeight);
ht.Add(attributeSet.Groups["attributeName"].Value.ToLower(),
attributeSet.Groups["attributeValue"].Value);
}
// If rel attribute exists and if it's different from current sizing we should resize the image!
if (helper.FindAttribute(ht, "rel") != "")
{
int newWidth = 0, newHeight = 0;
// if size has changed resize image serverside
string[] newDims = helper.FindAttribute(ht, "rel").Split(",".ToCharArray());
if (newDims.Length > 0 &&
(newDims[0] != helper.FindAttribute(ht, "width") ||
newDims[1] != helper.FindAttribute(ht, "height")))
var newDims = helper.FindAttribute(ht, "rel").Split(",".ToCharArray());
if (newDims.Length > 0 && (newDims[0] != helper.FindAttribute(ht, "width") || newDims[1] != helper.FindAttribute(ht, "height")))
{
try
{
cleanTag += doResize(ht, out newWidth, out newHeight);
int newWidth;
int newHeight;
cleanTag += DoResize(ht, out newWidth, out newHeight);
}
catch (Exception err)
{
@@ -72,8 +58,6 @@ namespace umbraco.editorControls.tinymce
}
else
{
cleanTag = StripSrc(cleanTag, ht);
if (helper.FindAttribute(ht, "width") != "")
{
cleanTag += " width=\"" + helper.FindAttribute(ht, "width") + "\"";
@@ -84,32 +68,26 @@ namespace umbraco.editorControls.tinymce
}
else
{
// Add src, width and height properties
cleanTag = StripSrc(cleanTag, ht);
if (helper.FindAttribute(ht, "width") != "")
{
cleanTag += " width=\"" + helper.FindAttribute(ht, "width") + "\"";
cleanTag += " height=\"" + helper.FindAttribute(ht, "height") + "\"";
}
}
// Build image tag
foreach (string attr in allowedAttributes)
foreach (var attr in allowedAttributes)
{
if (helper.FindAttribute(ht, attr) != "")
{
string attrValue = helper.FindAttribute(ht, attr);
var attrValue = helper.FindAttribute(ht, attr);
cleanTag += " " + attr + "=\"" + attrValue + "\"";
}
}
if (bool.Parse(GlobalSettings.EditXhtmlMode))
cleanTag += "/";
cleanTag += ">";
html = html.Replace(tag.Value, cleanTag);
}
@@ -118,113 +96,42 @@ namespace umbraco.editorControls.tinymce
return html;
}
private static string StripSrc(string cleanTag, Hashtable ht)
{
string src = helper.FindAttribute(ht, "src");
//get the media folder, minus the starting '~'
string mediaRoot = global::Umbraco.Core.IO.SystemDirectories.Media.Replace("~", string.Empty);
// update orgSrc to remove umbraco reference
int mediaRootIndex = src.IndexOf(mediaRoot);
if (mediaRootIndex > -1)
src = src.Substring(mediaRootIndex, src.Length - mediaRootIndex);
cleanTag += " src=\"" + src + "\"";
return cleanTag;
}
private static string doResize(Hashtable attributes, out int finalWidth, out int finalHeight)
private static string DoResize(IDictionary attributes, out int finalWidth, out int finalHeight)
{
var fs = FileSystemProviderManager.Current.GetFileSystemProvider<MediaFileSystem>();
var orgSrc = HttpContext.Current.Server.HtmlDecode(helper.FindAttribute(attributes, "src").Replace("%20", " "));
var orgDim = helper.FindAttribute(attributes, "rel").Split(",".ToCharArray());
var orgWidth = float.Parse(orgDim[0]);
var orgHeight = float.Parse(orgDim[1]);
var newWidth = int.Parse(helper.FindAttribute(attributes, "width"));
var newHeight = int.Parse(helper.FindAttribute(attributes, "height"));
string resizeDim = helper.FindAttribute(attributes, "width") + "," +
helper.FindAttribute(attributes, "height");
string[] resizeDimSplit = resizeDim.Split(',');
string orgSrc = HttpContext.Current.Server.HtmlDecode(helper.FindAttribute(attributes, "src").Replace("%20", " "));
string[] orgDim = helper.FindAttribute(attributes, "rel").Split(",".ToCharArray());
float orgWidth = float.Parse(orgDim[0]);
float orgHeight = float.Parse(orgDim[1]);
string newSrc = "";
int newWidth = int.Parse(resizeDimSplit[0]);
int newHeight = int.Parse(resizeDimSplit[1]);
var newSrc = "";
if (orgHeight > 0 && orgWidth > 0 && resizeDim != "" && orgSrc != "")
if (orgHeight > 0 && orgWidth > 0 && orgSrc != "")
{
// Check dimensions
if (Math.Abs(orgWidth / newWidth) > Math.Abs(orgHeight / newHeight))
{
newHeight = (int)Math.Round((float)newWidth * (orgHeight / orgWidth));
newHeight = (int)Math.Round(newWidth * (orgHeight / orgWidth));
}
else
{
newWidth = (int)Math.Round((float)newHeight * (orgWidth / orgHeight));
newWidth = (int)Math.Round(newHeight * (orgWidth / orgHeight));
}
// update orgSrc to remove umbraco reference
//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 fullSrc = IOHelper.MapPath(orgSrc);
var orgPath = fs.GetRelativePath(orgSrc);
if (fs.FileExists(orgPath))
{
var uf = new UmbracoFile(orgPath);
newSrc = uf.Resize(newWidth, newHeight);
}
/*
// Load original image
Image image = Image.FromFile(fullSrc);
// Create new image with best quality settings
Bitmap bp = new Bitmap(newWidth, newHeight);
Graphics g = Graphics.FromImage(bp);
g.SmoothingMode = SmoothingMode.HighQuality;
g.InterpolationMode = InterpolationMode.HighQualityBicubic;
g.PixelOffsetMode = PixelOffsetMode.HighQuality;
// Copy the old image to the new and resized
Rectangle rect = new Rectangle(0, 0, newWidth, newHeight);
g.DrawImage(image, rect, 0, 0, image.Width, image.Height, GraphicsUnit.Pixel);
// Copy metadata
ImageCodecInfo[] codecs = ImageCodecInfo.GetImageEncoders();
ImageCodecInfo codec = null;
for (int i = 0; i < codecs.Length; i++)
{
if (codecs[i].MimeType.Equals("image/jpeg"))
codec = codecs[i];
}
// Set compresion ratio to 90%
EncoderParameters ep = new EncoderParameters();
ep.Param[0] = new EncoderParameter(Encoder.Quality, 90L);
// Save the new image
bp.Save(fullSrcNew, codec, ep);
* */
}
// return the new width and height
finalWidth = newWidth;
finalHeight = newHeight;
//GE: When the SystemDirectories.Media contains a ~, newSrc will also contain this and hasn't been resolved.
//This causes the editor to save content which contains a virtual url, and thus the image doesn't serve
//the admin editor successfully displays the image because the HTML is rewritten, but when you get the RTE content in the template
//it hasn't been replaced
//2011-08-12 added a IOHelper.ResolveUrl call around newSrc
//2012-08-20 IFileSystem now takes care of URL resolution, so should be safe to assume newSrc is a full/absolute URL
return
" src=\"" + newSrc + "\" width=\"" + newWidth.ToString() + "\" height=\"" + newHeight.ToString() +
"\"";
return " src=\"" + newSrc + "\" width=\"" + newWidth + "\" height=\"" + newHeight + "\"";
}
}
}