public static void SetEmoLink ( HtmlNode div , Post p ) { HtmlNodeCollection emo = div.SelectNodes ( ".//img[@class='inlineimg' and @title]" ); if ( emo != null ) { foreach ( HtmlNode e in emo ) { e.Attributes["src"].Value = "https://vozforums.com/" + e.Attributes["src"].Value; } } }
private void GetPostContent () { string postId = "post" + postNumber; HtmlNode t = doc.DocumentNode.SelectSingleNode ( "//table[@class='tborder voz-postbit' and @id='" + postId + "']" ); Post p = new Post (); HAP.GetUserInfo ( t , p ); HAP.GetPostInfo ( t , p ); HAP.GetUserName ( t , p ); HAP.GetUserAva ( t , p ); HAP.GetQuoteAndReply ( t , p , doc ); Display ( p ); }
public static void EditLink ( HtmlNode div , Post p ) { string s; HtmlNodeCollection links = div.SelectNodes ( ".//a" ); if ( links != null ) { p.listLink = new List<HtmlNode> (); foreach ( HtmlNode l in links ) { s = l.Attributes["href"].Value; if ( s.Contains ( "/redirect/index.php?link=" ) ) { l.Attributes["href"].Value = "https://vozforums.com/" + l.Attributes["href"].Value; } p.listLink.Add ( l ); var newNode = HtmlNode.CreateNode ( "**link" + p.listLink.Count.ToString () + "**" ); l.ParentNode.ReplaceChild ( newNode , l ); } } }
public static void GetQuoteAndReply ( HtmlNode t , Post p , HtmlDocument doc ) { HtmlNode div; HtmlNodeCollection quotes; div = t.SelectSingleNode ( ".//td[@class='alt1']" ).SelectSingleNode ( "./div[@id]" ); if ( div == null ) { p.SetFullPost ( t.SelectSingleNode ( ".//td[@class='alt1']" ).InnerText.Trim () ); } else { //replace <br> with new line HAP.ReplaceNewLine ( div ); //if post have color, remove it HAP.RemovePostColor ( div ); //set emo link HAP.SetEmoLink ( div , p ); if ( UserData.settings.GetValueOrDefault ( AppSettings.keyEmo , true ) == false ) HAP.ReplaceEmoWithText ( div ); //edit link HAP.EditLink ( div , p ); //replace img HAP.ReplaceImage ( div , p ); //check quotes quotes = div.SelectNodes ( "./div[@style='margin:20px; margin-top:5px; ']" ); if ( quotes != null ) { foreach ( HtmlNode quote in quotes ) { string s = HAP.ProcessQuote ( quote , doc ); HtmlNode newNode = doc.CreateElement ( "title" ); newNode.InnerHtml = HtmlDocument.HtmlEncode ( s ); quote.ParentNode.ReplaceChild ( newNode , quote ); } } p.content = HtmlEntity.DeEntitize ( div.InnerText.Trim () ); p.ReplaceImage (); p.ReplaceNewLine (); p.ReplaceLink (); p.SetFullPost ( p.content ); } }
public static void GetUserInfo ( HtmlNode t , Post p ) { //user info is 2 div class="smallfont" //1st div is member rank, 2nd div is member: jd, location, posts HtmlNodeCollection user_info; HtmlNode table = t.SelectSingleNode ( ".//table" ); if ( table == null ) { p.userRank = ""; p.userJoinDate = ""; p.userLocation = ""; p.userPosts = ""; } else { user_info = table.SelectSingleNode ( ".//tr" ).SelectNodes ( ".//div[@class='smallfont']" ); if ( UserData.settings.GetValueOrDefault ( AppSettings.keyJoinDate , true ) == true ) p.userJoinDate = user_info[1].SelectSingleNode ( "./div[1]" ).InnerText.Trim (); else p.userJoinDate = ""; string s = HtmlEntity.DeEntitize ( user_info[1].SelectSingleNode ( "./div[2]" ).InnerText.Trim () ); if ( s[0] == 'L' ) { p.userLocation = s; p.userPosts = user_info[1].SelectSingleNode ( "./div[3]" ).InnerText.Trim (); } else { p.userPosts = user_info[1].SelectSingleNode ( "./div[2]" ).InnerText.Trim (); p.userLocation = ""; } if ( UserData.settings.GetValueOrDefault ( AppSettings.keyLocation , true ) == false ) p.userLocation = ""; if ( UserData.settings.GetValueOrDefault ( AppSettings.keyPosts , true ) == false ) p.userPosts = ""; } }
public static void GetPostInfo ( HtmlNode t , Post p ) { //get post info id time # //post info is 2 div, 1st div contain #post, 2nd div contain post time HtmlNodeCollection post_info = t.SelectNodes ( ".//div[@class='normal']" ); if ( post_info != null ) { p.postId = HtmlEntity.DeEntitize ( post_info[0].SelectSingleNode ( "./a" ).Attributes["id"].Value ).Trim (); p.postId = p.postId.Remove ( 0 , 9 ); p.postOrder = HtmlEntity.DeEntitize ( post_info[0].InnerText.Trim () ).Trim (); p.postTime = post_info[1].InnerText.Trim (); } else { p.postId = ""; p.postOrder = ""; p.postTime = ""; } }
public static void GetUserName ( HtmlNode t , Post p ) { HtmlNode user_name = t.SelectSingleNode ( ".//a[@class='bigusername']" ); if ( user_name != null ) { p.userName = HtmlEntity.DeEntitize ( user_name.InnerText.Trim () ); } else { user_name = t.SelectSingleNode ( ".//td[@class='alt2']" ); p.userName = HtmlEntity.DeEntitize ( user_name.InnerText.Trim () ); } }
public static void GetUserAva ( HtmlNode t , Post p ) { if ( UserData.settings.GetValueOrDefault ( AppSettings.keyAva , true ) == true ) { HtmlNode ava = t.SelectSingleNode ( ".//td[@class='alt2']" ).SelectSingleNode ( ".//td[@class='alt2']" ); if ( ava != null ) { ava = ava.SelectSingleNode ( ".//img" ); p.avaLink = "https://vozforums.com/"; p.avaLink += ava.Attributes["src"].Value; } else { p.avaLink = null; } } else { p.avaLink = null; } }
public static void ReplaceImage ( HtmlNode div , Post p ) { HtmlNodeCollection list = div.SelectNodes ( ".//img" ); if ( list != null ) { p.listImage = new List<HtmlNode> (); foreach ( HtmlNode l in list ) { p.listImage.Add ( l ); string newnodehtml = "**img" + p.listImage.Count.ToString () + "**"; HtmlNode newnode = HtmlNode.CreateNode ( newnodehtml ); l.ParentNode.ReplaceChild ( newnode , l ); } } }
private void Display ( Post p ) { textBlock_PostTime.Text = p.postTime; textBlock_PostCount.Text = p.postOrder; textBlock_User.Text = p.userName; textBlock_JD.Text = p.userJoinDate; textBlock_Posts.Text = p.userPosts; textBlock_Location.Text = p.userLocation; htmlViewer.Html = @p.htmlContent; htmlViewer.Html = ""; htmlViewer.Html = @p.htmlContent; }
private void GetAllPost () { listPosts.Clear (); //get all post, each post is a table HtmlNodeCollection table = doc.DocumentNode.SelectSingleNode ( "//div[@id='posts']" ).SelectNodes ( ".//table[@class='tborder voz-postbit']" ); foreach ( HtmlNode t in table ) { Post p = new Post (); HAP.GetUserInfo ( t , p ); HAP.GetPostInfo ( t , p ); HAP.GetUserName ( t , p ); HAP.GetUserAva ( t , p ); HAP.GetQuoteAndReply ( t , p , doc ); listPosts.Add ( p ); } //set binding listBoxPosts.ItemsSource = null; listBoxPosts.ItemsSource = listPosts; }