Merge branch 'v8/8.9' into v8/dev

# Conflicts:
#	src/SolutionInfo.cs
This commit is contained in:
Sebastiaan Janssen
2020-11-04 11:30:27 +01:00
8 changed files with 27 additions and 66 deletions

View File

@@ -19,11 +19,13 @@ namespace Umbraco.Web.Services
_globalSettings = globalSettings;
}
/// <inheritdoc />
public IList<IconModel> GetAllIcons()
{
var icons = new List<IconModel>();
var iconNames = GetAllIconNames();
var directory = new DirectoryInfo(IOHelper.MapPath($"{_globalSettings.IconsPath}/"));
var iconNames = directory.GetFiles("*.svg");
iconNames.OrderBy(f => f.Name).ToList().ForEach(iconInfo =>
{
@@ -43,56 +45,36 @@ namespace Umbraco.Web.Services
{
return string.IsNullOrWhiteSpace(iconName)
? null
: CreateIconModel(iconName.StripFileExtension());
: CreateIconModel(iconName.StripFileExtension(), IOHelper.MapPath($"{_globalSettings.IconsPath}/{iconName}.svg"));
}
/// <summary>
/// Gets an IconModel using values from a FileInfo model
/// </summary>
/// <param name="fileInfo"></param>
/// <returns><see cref="IconModel"/></returns>
private IconModel GetIcon(FileSystemInfo fileInfo)
/// <returns></returns>
private IconModel GetIcon(FileInfo fileInfo)
{
return fileInfo == null || string.IsNullOrWhiteSpace(fileInfo.Name)
? null
: CreateIconModel(fileInfo.Name.StripFileExtension(), fileInfo.FullName);
}
/// <summary>
/// Gets an IconModel containing the icon name and SvgString
/// </summary>
/// <param name="iconName"></param>
/// <returns><see cref="IconModel"/></returns>
private IconModel CreateIconModel(string iconName)
{
if (string.IsNullOrWhiteSpace(iconName))
return null;
var iconNames = GetAllIconNames();
var iconPath = iconNames.FirstOrDefault(x => x.Name.InvariantEquals($"{iconName}.svg"))?.FullName;
return iconPath == null
? null
: CreateIconModel(iconName, iconPath);
}
/// <summary>
/// Gets an IconModel containing the icon name and SvgString
/// </summary>
/// <param name="iconName"></param>
/// <param name="iconPath"></param>
/// <returns><see cref="IconModel"/></returns>
private static IconModel CreateIconModel(string iconName, string iconPath)
/// <returns></returns>
private IconModel CreateIconModel(string iconName, string iconPath)
{
if (string.IsNullOrWhiteSpace(iconPath))
return null;
var sanitizer = new HtmlSanitizer();
sanitizer.AllowedAttributes.UnionWith(Constants.SvgSanitizer.Attributes);
sanitizer.AllowedCssProperties.UnionWith(Constants.SvgSanitizer.Attributes);
sanitizer.AllowedTags.UnionWith(Constants.SvgSanitizer.Tags);
try
{
var sanitizer = new HtmlSanitizer();
sanitizer.AllowedAttributes.UnionWith(Constants.SvgSanitizer.Attributes);
sanitizer.AllowedCssProperties.UnionWith(Constants.SvgSanitizer.Attributes);
sanitizer.AllowedTags.UnionWith(Constants.SvgSanitizer.Tags);
var svgContent = System.IO.File.ReadAllText(iconPath);
var sanitizedString = sanitizer.Sanitize(svgContent);
@@ -109,26 +91,5 @@ namespace Umbraco.Web.Services
return null;
}
}
private IEnumerable<FileInfo> GetAllIconNames()
{
// add icons from plugins
var appPlugins = new DirectoryInfo(IOHelper.MapPath(SystemDirectories.AppPlugins));
var pluginIcons = appPlugins.Exists == false
? new List<FileInfo>()
: appPlugins.GetDirectories()
// Find all directories in App_Plugins that are named "Icons" and get a list of SVGs from them
.SelectMany(x => x.GetDirectories("Icons", SearchOption.AllDirectories))
.SelectMany(x => x.GetFiles("*.svg", SearchOption.TopDirectoryOnly));
// add icons from IconsPath if not already added from plugins
var directory = new DirectoryInfo(IOHelper.MapPath($"{_globalSettings.IconsPath}/"));
var iconNames = directory.GetFiles("*.svg")
.Where(x => pluginIcons.Any(i => i.Name == x.Name) == false);
iconNames = iconNames.Concat(pluginIcons).ToList();
return iconNames;
}
}
}