Merge with 6.0.4

This commit is contained in:
Shannon Deminick
2013-04-12 00:32:19 +06:00
3 changed files with 57 additions and 26 deletions

View File

@@ -1,4 +1,5 @@
using System;
using System.Configuration;
using System.Globalization;
using System.IO;
using System.Web;
@@ -43,43 +44,53 @@ namespace umbraco.cms.businesslogic.datatype
{
if (value is HttpPostedFile || value is HttpPostedFileBase)
{
var postedFileName = value is HttpPostedFile
? ((HttpPostedFile)value).FileName
var postedFileName = value is HttpPostedFile
? ((HttpPostedFile)value).FileName
: ((HttpPostedFileBase)value).FileName;
var name = IOHelper.SafeFileName(postedFileName.Substring(postedFileName.LastIndexOf(IOHelper.DirSepChar) + 1, postedFileName.Length - postedFileName.LastIndexOf(IOHelper.DirSepChar) - 1).ToLower());
var fileStream = value is HttpPostedFile
? ((HttpPostedFile)value).InputStream
var fileStream = value is HttpPostedFile
? ((HttpPostedFile)value).InputStream
: ((HttpPostedFileBase)value).InputStream;
// handle upload
var currentValue = Value.ToString();
if (name != String.Empty)
{
var numberedFolder = MediaSubfolderCounter.Current.Increment();
string fileName = UmbracoSettings.UploadAllowDirectories
? Path.Combine(numberedFolder.ToString(CultureInfo.InvariantCulture), name)
: numberedFolder + "-" + name;
var fs = FileSystemProviderManager.Current.GetFileSystemProvider<MediaFileSystem>();
//fileName = Path.Combine(SystemDirectories.Media, fileName);
UmbracoFile um = UmbracoFile.Save(fileStream, fileName);
var subfolder = UmbracoSettings.UploadAllowDirectories
? currentValue.Replace(fs.GetUrl("/"), "").Split('/')[0]
: currentValue.Substring(currentValue.LastIndexOf("/", StringComparison.Ordinal) + 1).Split('-')[0];
int subfolderId;
var numberedFolder = int.TryParse(subfolder, out subfolderId)
? subfolderId.ToString(CultureInfo.InvariantCulture)
: MediaSubfolderCounter.Current.Increment().ToString(CultureInfo.InvariantCulture);
if (um.SupportsResizing)
var fileName = UmbracoSettings.UploadAllowDirectories
? Path.Combine(numberedFolder, name)
: numberedFolder + "-" + name;
var umbracoFile = UmbracoFile.Save(fileStream, fileName);
if (umbracoFile.SupportsResizing)
{
// make default thumbnail
um.Resize(100, "thumb");
umbracoFile.Resize(100, "thumb");
// additional thumbnails configured as prevalues on the DataType
if (_thumbnailSizes != "")
{
char sep = (!_thumbnailSizes.Contains("") && _thumbnailSizes.Contains(",")) ? ',' : ';';
char sep = (_thumbnailSizes.Contains("") == false && _thumbnailSizes.Contains(",")) ? ',' : ';';
foreach (string thumb in _thumbnailSizes.Split(sep))
{
int thumbSize;
if (thumb != "" && int.TryParse(thumb, out thumbSize))
{
um.Resize(thumbSize, string.Format("thumb_{0}", thumbSize));
umbracoFile.Resize(thumbSize, string.Format("thumb_{0}", thumbSize));
}
}
}
@@ -88,18 +99,18 @@ namespace umbraco.cms.businesslogic.datatype
// check for auto fill of other properties (width, height, extension and filesize)
if (UmbracoSettings.ImageAutoFillImageProperties != null)
{
XmlNode uploadFieldConfigNode =
var uploadFieldConfigNode =
UmbracoSettings.ImageAutoFillImageProperties.SelectSingleNode(
string.Format("uploadField [@alias = \"{0}\"]", PropertyTypeAlias));
if (uploadFieldConfigNode != null)
{
EnsureLoadedContentItem(Version);
FillProperties(uploadFieldConfigNode, LoadedContentItem, um);
FillProperties(uploadFieldConfigNode, LoadedContentItem, umbracoFile);
}
}
base.Value = um.Url;
base.Value = umbracoFile.Url;
}
else
{
@@ -120,7 +131,7 @@ namespace umbraco.cms.businesslogic.datatype
private void ClearRelatedValues()
{
if(PropertyId == default(int))
if (PropertyId == default(int))
return;
if (UmbracoSettings.ImageAutoFillImageProperties != null)

View File

@@ -89,7 +89,12 @@ namespace umbraco.cms.businesslogic.media
if (prop != null && prop.Value != null)
{
int subfolderId;
var subfolder = prop.Value.ToString().Replace(FileSystem.GetUrl("/"), "").Split('/')[0];
var currentValue = prop.Value.ToString();
var subfolder = UmbracoSettings.UploadAllowDirectories
? currentValue.Replace(FileSystem.GetUrl("/"), "").Split('/')[0]
: currentValue.Substring(currentValue.LastIndexOf("/", StringComparison.Ordinal) + 1).Split('-')[0];
if (int.TryParse(subfolder, out subfolderId))
{
var destFilePath = FileSystem.GetRelativePath(subfolderId, fileName);

View File

@@ -338,15 +338,30 @@ namespace umbraco.editorControls.tinyMCE3.webcontrol
var heightProperty = imageMedia.Properties.FirstOrDefault(x => x.Alias == "umbracoHeight");
var umbracoFileProperty = imageMedia.Properties.FirstOrDefault(x => x.Alias == "umbracoFile");
// Format the tag
if (widthProperty != null && heightProperty != null && umbracoFileProperty != null)
var widthValue = string.Empty;
try
{
tempTag = string.Format("{0} rel=\"{1},{2}\" src=\"{3}\" />",
tempTag,
widthProperty.Value,
heightProperty.Value,
umbracoFileProperty.Value);
widthValue = widthProperty.Value.ToString();
}
catch (Exception wx)
{
// For some reason widthProperty == null returns false when the widthproperty is actually null...
}
var heightValue = string.Empty;
try
{
heightValue = heightProperty.Value.ToString();
}
catch (Exception ex)
{
// For some reason heightProperty == null returns false when the heightProperty is actually null...
}
// Format the tag
if (umbracoFileProperty != null)
tempTag = string.Format("{0} rel=\"{1},{2}\" src=\"{3}\" />", tempTag, widthValue, heightValue, umbracoFileProperty.Value);
}
html = html.Replace(tag.Value, tempTag);