private void processData(jsonpost[] posts) { for (int i = 0; i < posts.Length; i++) { jsonpost selPost = posts[i]; selPost.date = parseDate(selPost.date); selPost.title = removeCharacters(selPost.title); selPost.url = fixHTML(selPost.url); selPost.content = fixHTML(selPost.content); selPost.content=parseHTML(selPost,selPost.content); selPost.content = removeCharacters(selPost.content); this.Posts.Add(selPost); } }
/// <summary> /// Populates the page with content passed during navigation. Any saved state is also /// provided when recreating a page from a prior session. /// </summary> /// <param name="navigationParameter">The parameter value passed to /// <see cref="Frame.Navigate(Type, Object)"/> when this page was initially requested. /// </param> /// <param name="pageState">A dictionary of state preserved by this page during an earlier /// session. This will be null the first time a page is visited.</param> protected async override void LoadState(Object navigationParameter, Dictionary<String, Object> pageState) { currentpost = navigationParameter as jsonpost; //this.webView.Navigate(new Uri(post.url)); contentView.Text = currentpost.content; pageTitle.Text = currentpost.title; flipView.Items.Clear(); //foreach (string s in currentpost.images) //{ // Image image = new Image(); // BitmapImage bmp = new BitmapImage(); // bmp.UriSource = new Uri(s); // image.Source = bmp; // flipView.Items.Add(image); //} flipView.ItemsSource = currentpost.images; if (settings.Values.ContainsKey("AuthUser")) { await getLike(); //Authenticator.postStatus((string)settings.Values["AuthUser"]); displayname = Authenticator.displayname; LabelBox.Text = "Signed in"; UserBox.Text = displayname; } else { LabelBox.Text = "Sign in"; UserBox.Text = "to Wordpress"; } await getComments(); if (currentpost.liked) { LikeButton.SetValue(AutomationProperties.NameProperty, "Liked"); } }
private string parseHTML(jsonpost post, string item) { string output = "" ; HtmlDocument doc = new HtmlDocument(); doc.LoadHtml(item); List<HtmlNode> toRemove = new List<HtmlNode>(); foreach (HtmlNode node in doc.DocumentNode.ChildNodes) { if (node.Name == "div") toRemove.Add(node); else if (node.HasChildNodes) { foreach (HtmlNode childnode in node.ChildNodes) { if (childnode.Name == "a") { if (childnode.FirstChild.Name == "img") { jsonimage newimage = new jsonimage(); Image image = new Image(); BitmapImage bmp = new BitmapImage(); bmp.UriSource = new Uri(childnode.Attributes.FirstOrDefault().Value.ToString()); newimage.image = bmp; post.images.Add(newimage); } } if (childnode.Name == "div") { toRemove.Add(childnode); //if (node.HasChildNodes) //{ // foreach (HtmlNode childnode2 in childnode.ChildNodes) // { // if (childnode2.Name == "a") // { // if (childnode2.FirstChild.Name == "img") // { // post.images.Add(childnode2.Attributes.FirstOrDefault().Value.ToString()); // } // } // } //} } } } } foreach (HtmlNode node in toRemove) { jsonimage newimage = new jsonimage(); foreach (HtmlNode childNode in node.ChildNodes) { if (childNode.Name == "a") { if (childNode.FirstChild.Name == "img") { Image image = new Image(); BitmapImage bmp = new BitmapImage(); bmp.UriSource = new Uri(childNode.Attributes.FirstOrDefault().Value.ToString()); newimage.image = bmp; } } if (childNode.Name == "p") { newimage.caption=WebUtility.HtmlDecode(childNode.InnerText); } } if (newimage.image != null) post.images.Add(newimage); node.Remove(); } output = doc.DocumentNode.InnerText; return output; }