From 0608862da9119a3bf9a95663325cf3d562681263 Mon Sep 17 00:00:00 2001 From: Sebastiaan Janssen Date: Wed, 4 Nov 2020 11:25:45 +0100 Subject: [PATCH] Revert "Adds icons from App_Plugins/**/Icons/*.svg (#8884)" This reverts commit d7bf980f121995fd62aa38c4efce71c1deda209e. --- src/Umbraco.Core/Services/IIconService.cs | 4 +- src/Umbraco.Web/Services/IconService.cs | 63 +++++------------------ 2 files changed, 14 insertions(+), 53 deletions(-) diff --git a/src/Umbraco.Core/Services/IIconService.cs b/src/Umbraco.Core/Services/IIconService.cs index 72174a0504..963edb22a5 100644 --- a/src/Umbraco.Core/Services/IIconService.cs +++ b/src/Umbraco.Core/Services/IIconService.cs @@ -9,13 +9,13 @@ namespace Umbraco.Core.Services /// Gets an IconModel containing the icon name and SvgString according to an icon name found at the global icons path /// /// - /// + /// IconModel GetIcon(string iconName); /// /// Gets a list of all svg icons found at at the global icons path. /// - /// A list of + /// IList GetAllIcons(); } } diff --git a/src/Umbraco.Web/Services/IconService.cs b/src/Umbraco.Web/Services/IconService.cs index ba6692c7b9..206af296f9 100644 --- a/src/Umbraco.Web/Services/IconService.cs +++ b/src/Umbraco.Web/Services/IconService.cs @@ -19,11 +19,13 @@ namespace Umbraco.Web.Services _globalSettings = globalSettings; } + /// public IList GetAllIcons() { var icons = new List(); - 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")); } /// /// Gets an IconModel using values from a FileInfo model /// /// - /// - private IconModel GetIcon(FileSystemInfo fileInfo) + /// + private IconModel GetIcon(FileInfo fileInfo) { return fileInfo == null || string.IsNullOrWhiteSpace(fileInfo.Name) ? null : CreateIconModel(fileInfo.Name.StripFileExtension(), fileInfo.FullName); } - /// - /// Gets an IconModel containing the icon name and SvgString - /// - /// - /// - 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); - } - /// /// Gets an IconModel containing the icon name and SvgString /// /// /// - /// - private static IconModel CreateIconModel(string iconName, string iconPath) + /// + 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 GetAllIconNames() - { - // add icons from plugins - var appPlugins = new DirectoryInfo(IOHelper.MapPath(SystemDirectories.AppPlugins)); - var pluginIcons = appPlugins.Exists == false - ? new List() - : 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; - } } }