private void Parse(PostIcon postIconEntity, HtmlNode node) { try { postIconEntity.Id = Convert.ToInt32(node.Descendants("input").First().GetAttributeValue("value", string.Empty)); var imageUrl = node.Descendants("img").First().GetAttributeValue("src", string.Empty); postIconEntity.ImageUrl = imageUrl; postIconEntity.Title = node.Descendants("img").First().GetAttributeValue("alt", string.Empty); } catch (Exception) { // If, for some reason, it fails to get an icon, ignore the error. // The list view won't show it. } }
public async Task <IEnumerable <PostIcon> > GetPostIconList(int forumId) { string url = string.Format(EndPoints.NewThread, forumId); var result = await _webManager.GetData(url); HtmlDocument doc = new HtmlDocument(); doc.LoadHtml(result.ResultHtml); HtmlNode[] pageNodes = doc.DocumentNode.Descendants("div").Where(node => node.GetAttributeValue("class", string.Empty).Equals("posticon")).ToArray(); var postIconEntityList = new List <PostIcon>(); foreach (var pageNode in pageNodes) { var postIconEntity = new PostIcon(); Parse(postIconEntity, pageNode); postIconEntityList.Add(postIconEntity); } return(postIconEntityList); }
public async Task <IEnumerable <PostIconCategory> > GetPmPostIcons() { string url = EndPoints.NewPrivateMessage; var result = await _webManager.GetData(url); HtmlDocument doc = new HtmlDocument(); doc.LoadHtml(result.ResultHtml); HtmlNode[] pageNodes = doc.DocumentNode.Descendants("div").Where(node => node.GetAttributeValue("class", string.Empty).Equals("posticon")).ToArray(); var postIconEntityList = new List <PostIcon>(); foreach (var pageNode in pageNodes) { var postIconEntity = new PostIcon(); Parse(postIconEntity, pageNode); postIconEntityList.Add(postIconEntity); } var postIconCategoryEntity = new PostIconCategory("Post Icon", postIconEntityList); var postIconCategoryList = new List <PostIconCategory> { postIconCategoryEntity }; return(postIconCategoryList); }
protected string GetIcon(int iconID, string imgStyle) { if (EnablePostIcon == false) { return(string.Empty); } if (string.IsNullOrEmpty(imgStyle)) { imgStyle = "<img src=\"{0}\" border=\"0\" alt=\"\" />"; } if (iconID <= 0) { return(string.Empty); } PostIcon postIcon = PostBOV5.Instance.GetPostIcon(iconID); if (postIcon == null) { return(string.Empty); } return(string.Format(imgStyle, postIcon.IconUrl)); }
public bool SaveSettings() { MessageDisplay msgDisplay = CreateMessageDisplay("iconurl"); int[] posticonids = StringUtil.Split <int>(_Request.Get("posticonids", Method.Post)); PostIconCollection posticons = new PostIconCollection(); PostIcon temp; int rowindex = 0; foreach (int id in posticonids) { temp = new PostIcon(); temp.IconID = id; temp.IconUrlSrc = _Request.Get("iconurl." + id, Method.Post); temp.SortOrder = _Request.Get <int>("sortorder." + id, Method.Post, 0); temp.IsNew = _Request.Get <bool>("isnew." + id, Method.Post, false); if (string.IsNullOrEmpty(temp.IconUrl)) { msgDisplay.AddError("iconurl", rowindex, ""); } posticons.Add(temp); rowindex++; } //无脚本 if (_Request.Get("newposticons", Method.Post) != null && _Request.Get("newposticons", Method.Post).Contains("{0}") ) { temp = PostIconSettings.CreatePostIcon(); temp.IconUrlSrc = _Request.Get("iconurl.new.{0}", Method.Post); temp.SortOrder = _Request.Get("sortorder.new.{0}", Method.Post, 0); if (!string.IsNullOrEmpty(temp.IconUrl)) { posticons.Add(temp); } } else { int[] newiconids = StringUtil.Split <int>(_Request.Get("newposticons", Method.Post)); foreach (int newid in newiconids) { temp = PostIconSettings.CreatePostIcon(); temp.IconUrlSrc = _Request.Get("iconurl.new." + newid, Method.Post); temp.SortOrder = _Request.Get("sortorder.new." + newid, Method.Post, 0); if (string.IsNullOrEmpty(temp.IconUrl)) { msgDisplay.AddError("iconurl", rowindex, ""); } posticons.Add(temp); rowindex++; } } if (!msgDisplay.HasAnyError()) { PostIconSettings.PostIcons = posticons; foreach (PostIcon pi in posticons) { pi.IsNew = false; } SettingManager.SaveSettings(PostIconSettings); } else { msgDisplay.AddError(new DataNoSaveError()); m_postIconList = new PostIcon[posticons.Count]; posticons.CopyTo(m_postIconList, 0); } return(true); }
public bool SaveSettings() { MessageDisplay msgDisplay = CreateMessageDisplay("iconurl"); int[] posticonids = StringUtil.Split<int>(_Request.Get("posticonids", Method.Post)); PostIconCollection posticons = new PostIconCollection(); PostIcon temp; int rowindex = 0; foreach (int id in posticonids) { temp = new PostIcon(); temp.IconID = id; temp.IconUrlSrc = _Request.Get("iconurl." + id, Method.Post); temp.SortOrder = _Request.Get<int>("sortorder." + id, Method.Post, 0); temp.IsNew = _Request.Get<bool>("isnew." + id, Method.Post, false); if (string.IsNullOrEmpty(temp.IconUrl)) msgDisplay.AddError("iconurl", rowindex, ""); posticons.Add(temp); rowindex++; } //无脚本 if (_Request.Get("newposticons", Method.Post) != null && _Request.Get("newposticons", Method.Post).Contains("{0}") ) { temp = PostIconSettings.CreatePostIcon(); temp.IconUrlSrc = _Request.Get("iconurl.new.{0}", Method.Post); temp.SortOrder = _Request.Get("sortorder.new.{0}", Method.Post, 0); if (!string.IsNullOrEmpty(temp.IconUrl)) posticons.Add(temp); } else { int[] newiconids = StringUtil.Split<int>(_Request.Get("newposticons", Method.Post)); foreach (int newid in newiconids) { temp = PostIconSettings.CreatePostIcon(); temp.IconUrlSrc = _Request.Get("iconurl.new." + newid, Method.Post); temp.SortOrder = _Request.Get("sortorder.new." + newid, Method.Post, 0); if (string.IsNullOrEmpty(temp.IconUrl)) msgDisplay.AddError("iconurl", rowindex, ""); posticons.Add(temp); rowindex++; } } if (!msgDisplay.HasAnyError()) { PostIconSettings.PostIcons = posticons; foreach (PostIcon pi in posticons) pi.IsNew = false; SettingManager.SaveSettings(PostIconSettings); } else { msgDisplay.AddError(new DataNoSaveError()); m_postIconList = new PostIcon[posticons.Count]; posticons.CopyTo(m_postIconList, 0); } return true; }
public void AddIcon(PostIcon icon ) { this.PostIcons.Add(icon); }
public PostIcon CreatePostIcon() { PostIcon icon = new PostIcon(); icon.IconID = ++MaxId; icon.IsNew = true; return icon; }