コード例 #1
0
        private static string CreateButtons(ForumPostEntity post)
        {
            var clickHandler = $"window.ForumCommand('quote', '{post.PostId}')";

            string quoteButton = HtmlButtonBuilder.CreateSubmitButton("Quote", clickHandler, string.Empty);

            clickHandler = $"window.ForumCommand('edit', '{post.PostId}')";

            string editButton = HtmlButtonBuilder.CreateSubmitButton("Edit", clickHandler, string.Empty);

            clickHandler = $"window.ForumCommand('markAsLastRead', '{post.PostIndex}')";

            string markAsLastReadButton = HtmlButtonBuilder.CreateSubmitButton("Last Read", clickHandler, string.Empty);

            return(post.User.IsCurrentUserPost
                    ? string.Concat("<ul class=\"profilelinks\">",
                                    quoteButton, markAsLastReadButton, editButton, "</ul>")
                    : string.Concat("<ul class=\"profilelinks\">",
                                    quoteButton, markAsLastReadButton, "</ul>"));
        }
コード例 #2
0
        public static async Task <string> FormatThreadHtml(ForumThreadEntity forumThreadEntity, List <ForumPostEntity> postEntities)
        {
            string html = await PathIO.ReadTextAsync("ms-appx:///Assets/Website/thread.html");

            var doc2 = new HtmlDocument();

            doc2.LoadHtml(html);


            HtmlNode head = doc2.DocumentNode.Descendants("head").FirstOrDefault();

            switch (forumThreadEntity.PlatformIdentifier)
            {
            case PlatformIdentifier.WindowsPhone:
                head.InnerHtml += "<link href=\"ms-appx-web:///Assets/Website/CSS/WindowsPhone-Default.css\" type=\"text/css\" media=\"all\" rel=\"stylesheet\">";
                break;
            }

            switch (forumThreadEntity.ForumId)
            {
            case 219:
                head.InnerHtml += "<link href=\"ms-appx-web:///Assets/Website/CSS/219.css\" type=\"text/css\" media=\"all\" rel=\"stylesheet\">";
                break;

            case 26:
                head.InnerHtml += "<link href=\"ms-appx-web:///Assets/Website/CSS/26.css\" type=\"text/css\" media=\"all\" rel=\"stylesheet\">";
                break;

            case 267:
                head.InnerHtml += "<link href=\"ms-appx-web:///Assets/Website/CSS/267.css\" type=\"text/css\" media=\"all\" rel=\"stylesheet\">";
                break;

            case 268:
                head.InnerHtml += "<link href=\"ms-appx-web:///Assets/Website/CSS/268.css\" type=\"text/css\" media=\"all\" rel=\"stylesheet\">";
                break;
            }

            HtmlNode bodyNode = doc2.DocumentNode.Descendants("div").FirstOrDefault(node => node.GetAttributeValue("class", string.Empty).Contains("row clearfix"));

            if (postEntities == null)
            {
                return(WebUtility.HtmlDecode(WebUtility.HtmlDecode(doc2.DocumentNode.OuterHtml)));
            }

            string threadHtml = string.Empty;

            if (forumThreadEntity.Poll != null)
            {
                //threadHtml += FormatVotePoll(forumThreadEntity.Poll);
            }

            if (forumThreadEntity.ScrollToPost > 1)
            {
                threadHtml += "<div><div id=\"showPosts\">";

                var clickHandler = $"window.ForumCommand('showPosts', '{"true"}')";

                string showThreadsButton = HtmlButtonBuilder.CreateSubmitButton(
                    $"Show {forumThreadEntity.ScrollToPost} Previous Posts", clickHandler, "showHiddenPostsButton", false);

                threadHtml += showThreadsButton;

                threadHtml += "</div><div style=\"display: none;\" id=\"hiddenPosts\">";
                threadHtml += ParsePosts(0, forumThreadEntity.ScrollToPost, postEntities, forumThreadEntity.IsPrivateMessage);
                threadHtml += "</div>";
                threadHtml += ParsePosts(forumThreadEntity.ScrollToPost, postEntities.Count, postEntities, forumThreadEntity.IsPrivateMessage);
            }
            else
            {
                threadHtml += ParsePosts(0, postEntities.Count, postEntities, forumThreadEntity.IsPrivateMessage);
            }

            bodyNode.InnerHtml = threadHtml;

            var images = bodyNode.Descendants("img").Where(node => node.GetAttributeValue("class", string.Empty) != "av");

            foreach (var image in images)
            {
                var src = image.Attributes["src"].Value;
                if (Path.GetExtension(src) != ".gif")
                {
                    continue;
                }
                if (src.Contains("somethingawful.com"))
                {
                    continue;
                }
                if (src.Contains("emoticons"))
                {
                    continue;
                }
                if (src.Contains("smilies"))
                {
                    continue;
                }
                image.Attributes.Add("data-gifffer", image.Attributes["src"].Value);
                image.Attributes.Remove("src");
            }
            return(doc2.DocumentNode.OuterHtml);
        }