From bdbe49edfa31c13b915404426ce9b9303cffc142 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20M=2E=20Alarc=C3=B3n?= Date: Wed, 6 Dec 2017 13:08:08 +0100 Subject: [PATCH] Enhanced Post.FirstImgSrc method to really find the first image in the content using regular expressions. The previous code didn't find images with styls or other attributes and that was a problem. Bumped minor version to reflect change. --- BlogEngine/BlogEngine.Core/Post.cs | 26 +++++++++---------- .../Properties/AssemblyInfo.cs | 4 +-- 2 files changed, 15 insertions(+), 15 deletions(-) diff --git a/BlogEngine/BlogEngine.Core/Post.cs b/BlogEngine/BlogEngine.Core/Post.cs index 338dc0253..fed08b3ea 100644 --- a/BlogEngine/BlogEngine.Core/Post.cs +++ b/BlogEngine/BlogEngine.Core/Post.cs @@ -8,6 +8,7 @@ using System.Linq; using System.Net.Mail; using System.Text; + using System.Text.RegularExpressions; using System.Web; using BlogEngine.Core.Data.Models; @@ -694,28 +695,27 @@ public bool IsVisibleToPublic } /// - /// URL of the first image in the post, if any + /// URL of the first image in the post, if any. + /// If there's no first image, returns the URL to "images/defaultImg.jpg" in the current theme used in the blog /// public string FirstImgSrc { get { - int idx = Content.IndexOf("", RegexOptions.Multiline | RegexOptions.IgnoreCase); + if (match.Success) { - idx = idx + 10; - var idxEnd = Content.IndexOf("\"", idx); - if (idxEnd > idx) - { - var len = idxEnd - idx; - return Content.Substring(idx, len); - } + srcValue = match.Groups[2].Value; } - catch (Exception) { } } - return ""; + if (string.IsNullOrEmpty(srcValue)) + { + srcValue = Utils.RelativeWebRoot + "Custom/Themes/" + BlogSettings.Instance.Theme + "/images/defaultImg.jpg"; + } + return srcValue; } } diff --git a/BlogEngine/BlogEngine.Core/Properties/AssemblyInfo.cs b/BlogEngine/BlogEngine.Core/Properties/AssemblyInfo.cs index 8cbb71e53..29318d551 100644 --- a/BlogEngine/BlogEngine.Core/Properties/AssemblyInfo.cs +++ b/BlogEngine/BlogEngine.Core/Properties/AssemblyInfo.cs @@ -13,11 +13,11 @@ [assembly: AssemblyConfiguration("")] [assembly: AssemblyCompany("")] [assembly: AssemblyProduct("BlogEngine.NET")] -[assembly: AssemblyCopyright("Copyright @ 2007-2016")] +[assembly: AssemblyCopyright("Copyright @ 2007-2017")] [assembly: AssemblyTrademark("")] [assembly: AssemblyCulture("")] [assembly: CLSCompliant(false)] [assembly: ComVisible(false)] [assembly: AllowPartiallyTrustedCallers] -[assembly: AssemblyVersion("3.3.5.0")] +[assembly: AssemblyVersion("3.3.6.0")] [assembly: SecurityRules(SecurityRuleSet.Level1)]