|  | 
| 8 | 8 |  using System.Linq; | 
| 9 | 9 |  using System.Net.Mail; | 
| 10 | 10 |  using System.Text; | 
|  | 11 | + using System.Text.RegularExpressions; | 
| 11 | 12 |  using System.Web; | 
| 12 | 13 | 
 | 
| 13 | 14 |  using BlogEngine.Core.Data.Models; | 
| @@ -694,28 +695,27 @@ public bool IsVisibleToPublic | 
| 694 | 695 |  } | 
| 695 | 696 | 
 | 
| 696 | 697 |  /// <summary> | 
| 697 |  | - /// URL of the first image in the post, if any | 
|  | 698 | + /// URL of the first image in the post, if any. | 
|  | 699 | + /// If there's no first image, returns the URL to "images/defaultImg.jpg" in the current theme used in the blog | 
| 698 | 700 |  /// </summary> | 
| 699 | 701 |  public string FirstImgSrc | 
| 700 | 702 |  { | 
| 701 | 703 |  get | 
| 702 | 704 |  { | 
| 703 |  | - intidx = Content.IndexOf("<img src="); | 
| 704 |  | - if (idx>0) | 
|  | 705 | + stringsrcValue = null; | 
|  | 706 | + if (!string.IsNullOrEmpty(content)) | 
| 705 | 707 |  { | 
| 706 |  | - try | 
|  | 708 | + Match match = Regex.Match(content, @"<img\s+?.*?src=('|"")(.*?)1円.*?>", RegexOptions.Multiline | RegexOptions.IgnoreCase); | 
|  | 709 | + if (match.Success) | 
| 707 | 710 |  { | 
| 708 |  | - idx = idx + 10; | 
| 709 |  | - var idxEnd = Content.IndexOf("\"", idx); | 
| 710 |  | - if (idxEnd > idx) | 
| 711 |  | - { | 
| 712 |  | - var len = idxEnd - idx; | 
| 713 |  | - return Content.Substring(idx, len); | 
| 714 |  | - } | 
|  | 711 | + srcValue = match.Groups[2].Value; | 
| 715 | 712 |  } | 
| 716 |  | - catch (Exception) { } | 
| 717 | 713 |  } | 
| 718 |  | - return ""; | 
|  | 714 | + if (string.IsNullOrEmpty(srcValue)) | 
|  | 715 | + { | 
|  | 716 | + srcValue = Utils.RelativeWebRoot + "Custom/Themes/" + BlogSettings.Instance.Theme + "/images/defaultImg.jpg"; | 
|  | 717 | + } | 
|  | 718 | + return srcValue; | 
| 719 | 719 |  } | 
| 720 | 720 |  } | 
| 721 | 721 | 
 | 
|  | 
0 commit comments