mirror of
https://github.com/OrchardCMS/Orchard.git
synced 2025-09-24 05:23:33 +08:00
Refactoring
--HG-- branch : dev
This commit is contained in:
@@ -1,33 +1,25 @@
|
|||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Text.RegularExpressions;
|
using System.Text.RegularExpressions;
|
||||||
using System.Web;
|
using System.Web;
|
||||||
using Orchard.FileSystems.VirtualPath;
|
|
||||||
using Orchard.Services;
|
using Orchard.Services;
|
||||||
|
|
||||||
namespace Orchard.Core.Common.Services {
|
namespace Orchard.Core.Common.Services {
|
||||||
public class BbcodeFilter : IHtmlFilter {
|
public class BbcodeFilter : IHtmlFilter {
|
||||||
private readonly IVirtualPathProvider _virtualPathProvider;
|
|
||||||
|
|
||||||
public BbcodeFilter(IVirtualPathProvider virtualPathProvider) {
|
|
||||||
_virtualPathProvider = virtualPathProvider;
|
|
||||||
}
|
|
||||||
|
|
||||||
public string ProcessContent(string text) {
|
public string ProcessContent(string text) {
|
||||||
return BbcodeReplace(text);
|
return BbcodeReplace(text);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Can be moved somewhere else once we have IoC enabled body text filters.
|
// Can be moved somewhere else once we have IoC enabled body text filters.
|
||||||
private string BbcodeReplace(string text) {
|
private static string BbcodeReplace(string text) {
|
||||||
if (string.IsNullOrEmpty(text))
|
if (string.IsNullOrEmpty(text))
|
||||||
return string.Empty;
|
return string.Empty;
|
||||||
|
|
||||||
Regex urlRegex = new Regex(@"\[url\]([^\]]+)\[\/url\]");
|
var urlRegex = new Regex(@"\[url\]([^\]]+)\[\/url\]");
|
||||||
Regex urlRegexWithLink = new Regex(@"\[url=([^\]]+)\]([^\]]+)\[\/url\]");
|
var urlRegexWithLink = new Regex(@"\[url=([^\]]+)\]([^\]]+)\[\/url\]");
|
||||||
Regex imgRegex = new Regex(@"\[img\]([^\]]+)\[\/img\]");
|
var imgRegex = new Regex(@"\[img\]([^\]]+)\[\/img\]");
|
||||||
|
|
||||||
text = urlRegex.Replace(text, "<a href=\"$1\">$1</a>");
|
text = urlRegex.Replace(text, "<a href=\"$1\">$1</a>");
|
||||||
text = urlRegexWithLink.Replace(text, "<a href=\"$1\">$2</a>");
|
text = urlRegexWithLink.Replace(text, "<a href=\"$1\">$2</a>");
|
||||||
//text = imgRegex.Replace(text, "<img src=\"$1\" />");
|
|
||||||
|
|
||||||
var matches = imgRegex.Matches(text).OfType<Match>().OrderByDescending(m => m.Groups[0].Index);
|
var matches = imgRegex.Matches(text).OfType<Match>().OrderByDescending(m => m.Groups[0].Index);
|
||||||
foreach(var match in matches) {
|
foreach(var match in matches) {
|
||||||
|
@@ -218,7 +218,8 @@ namespace Orchard.Core.Settings.Metadata {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
string Compose(XElement map) {
|
|
||||||
|
static string Compose(XElement map) {
|
||||||
if (map == null)
|
if (map == null)
|
||||||
return null;
|
return null;
|
||||||
|
|
||||||
|
@@ -26,7 +26,7 @@ namespace Orchard.Core.XmlRpc.Services {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
private IDictionary<Type, Func<XRpcData, XElement>> _dispatch;
|
private readonly IDictionary<Type, Func<XRpcData, XElement>> _dispatch;
|
||||||
|
|
||||||
XElement IMapper<XRpcMethodResponse, XElement>.Map(XRpcMethodResponse source) {
|
XElement IMapper<XRpcMethodResponse, XElement>.Map(XRpcMethodResponse source) {
|
||||||
return new XElement(
|
return new XElement(
|
||||||
|
@@ -3,7 +3,7 @@ using System.Collections.Generic;
|
|||||||
|
|
||||||
namespace Orchard.Media.Extensions {
|
namespace Orchard.Media.Extensions {
|
||||||
public static class LongExtensions {
|
public static class LongExtensions {
|
||||||
private static List<string> units = new List<string>(5) {"B", "KB", "MB", "GB", "TB"}; // Not going further. Anything beyond MB is probably overkill anyway.
|
private static readonly List<string> units = new List<string>(5) {"B", "KB", "MB", "GB", "TB"}; // Not going further. Anything beyond MB is probably overkill anyway.
|
||||||
|
|
||||||
public static string ToFriendlySizeString(this long bytes) {
|
public static string ToFriendlySizeString(this long bytes) {
|
||||||
var somethingMoreFriendly = TryForTheNextUnit(bytes, units[0]);
|
var somethingMoreFriendly = TryForTheNextUnit(bytes, units[0]);
|
||||||
|
@@ -38,9 +38,7 @@ namespace Orchard.Packaging.Services {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public override IQueryable<IPackage> GetPackages() {
|
public override IQueryable<IPackage> GetPackages() {
|
||||||
IEnumerable<IPackage> packages;
|
IEnumerable<IPackage> packages = from extension in _extensionManager.AvailableExtensions()
|
||||||
|
|
||||||
packages = from extension in _extensionManager.AvailableExtensions()
|
|
||||||
let id = "Orchard." + extension.ExtensionType + "." + extension.Id
|
let id = "Orchard." + extension.ExtensionType + "." + extension.Id
|
||||||
let version = Version.Parse(extension.Version)
|
let version = Version.Parse(extension.Version)
|
||||||
let package = SourceRepository.FindPackage(id, version)
|
let package = SourceRepository.FindPackage(id, version)
|
||||||
|
@@ -62,7 +62,7 @@ namespace Orchard.Packaging.Services {
|
|||||||
return context.Stream;
|
return context.Stream;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void SetCoreProperties(CreateContext context, ExtensionDescriptor extensionDescriptor) {
|
private static void SetCoreProperties(CreateContext context, ExtensionDescriptor extensionDescriptor) {
|
||||||
context.Builder.Id = "Orchard." + extensionDescriptor.ExtensionType + "." + extensionDescriptor.Id;
|
context.Builder.Id = "Orchard." + extensionDescriptor.ExtensionType + "." + extensionDescriptor.Id;
|
||||||
context.Builder.Version = new Version(extensionDescriptor.Version);
|
context.Builder.Version = new Version(extensionDescriptor.Version);
|
||||||
context.Builder.Title = extensionDescriptor.Name ?? extensionDescriptor.Id;
|
context.Builder.Title = extensionDescriptor.Name ?? extensionDescriptor.Id;
|
||||||
@@ -74,7 +74,7 @@ namespace Orchard.Packaging.Services {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void EmbedProjectFiles(CreateContext context, params string[] itemGroupTypes) {
|
private static void EmbedProjectFiles(CreateContext context, params string[] itemGroupTypes) {
|
||||||
IEnumerable<XElement> itemGroups = context.Project
|
IEnumerable<XElement> itemGroups = context.Project
|
||||||
.Elements(Ns("Project"))
|
.Elements(Ns("Project"))
|
||||||
.Elements(Ns("ItemGroup"));
|
.Elements(Ns("ItemGroup"));
|
||||||
@@ -90,7 +90,7 @@ namespace Orchard.Packaging.Services {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void EmbedReferenceFiles(CreateContext context) {
|
private static void EmbedReferenceFiles(CreateContext context) {
|
||||||
var entries = context.Project
|
var entries = context.Project
|
||||||
.Elements(Ns("Project"))
|
.Elements(Ns("Project"))
|
||||||
.Elements(Ns("ItemGroup"))
|
.Elements(Ns("ItemGroup"))
|
||||||
@@ -113,7 +113,7 @@ namespace Orchard.Packaging.Services {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void EmbedThemeFiles(CreateContext context) {
|
private static void EmbedThemeFiles(CreateContext context) {
|
||||||
var basePath = context.SourcePath;
|
var basePath = context.SourcePath;
|
||||||
foreach (var virtualPath in context.SourceFolder.ListFiles(context.SourcePath, true)) {
|
foreach (var virtualPath in context.SourceFolder.ListFiles(context.SourcePath, true)) {
|
||||||
// ignore dlls, etc
|
// ignore dlls, etc
|
||||||
@@ -128,7 +128,7 @@ namespace Orchard.Packaging.Services {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private XName Ns(string localName) {
|
private static XName Ns(string localName) {
|
||||||
return XName.Get(localName, "http://schemas.microsoft.com/developer/msbuild/2003");
|
return XName.Get(localName, "http://schemas.microsoft.com/developer/msbuild/2003");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -144,7 +144,7 @@ namespace Orchard.Packaging.Services {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private bool TryGetSolutionPath(string applicationPath, out string parentPath) {
|
private static bool TryGetSolutionPath(string applicationPath, out string parentPath) {
|
||||||
try {
|
try {
|
||||||
parentPath = Directory.GetParent(applicationPath).Parent.FullName;
|
parentPath = Directory.GetParent(applicationPath).Parent.FullName;
|
||||||
var solutionPath = Path.Combine(parentPath, SolutionFilename);
|
var solutionPath = Path.Combine(parentPath, SolutionFilename);
|
||||||
|
@@ -136,7 +136,7 @@ namespace Orchard.Widgets.Services {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
private int ParsePosition(WidgetPart widgetPart) {
|
private static int ParsePosition(WidgetPart widgetPart) {
|
||||||
int value;
|
int value;
|
||||||
if (!int.TryParse(widgetPart.Record.Position, out value))
|
if (!int.TryParse(widgetPart.Record.Position, out value))
|
||||||
return 0;
|
return 0;
|
||||||
|
@@ -12,7 +12,7 @@ namespace Orchard.Mvc.ViewEngines.Razor {
|
|||||||
Logger = NullLogger.Instance;
|
Logger = NullLogger.Instance;
|
||||||
RazorCompilationEventsShim.EnsureInitialized();
|
RazorCompilationEventsShim.EnsureInitialized();
|
||||||
}
|
}
|
||||||
static string[] DisabledFormats = new[] { "~/Disabled" };
|
static readonly string[] DisabledFormats = new[] { "~/Disabled" };
|
||||||
|
|
||||||
public ILogger Logger { get; set; }
|
public ILogger Logger { get; set; }
|
||||||
|
|
||||||
|
@@ -11,7 +11,7 @@ namespace Orchard.Mvc.ViewEngines.WebForms {
|
|||||||
Logger = NullLogger.Instance;
|
Logger = NullLogger.Instance;
|
||||||
}
|
}
|
||||||
|
|
||||||
static string[] DisabledFormats = new[] { "~/Disabled" };
|
static readonly string[] DisabledFormats = new[] { "~/Disabled" };
|
||||||
|
|
||||||
public ILogger Logger { get; set; }
|
public ILogger Logger { get; set; }
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user