1: private string RenderComments(List<Comment> comments, StringDictionary settings)
2: {
3: if (comments.Count == 0)
4: {
5: //HttpRuntime.Cache.Insert("widget_recentcomments", "<p>" + Resources.labels.none + "</p>");
6: return "<p>" + Resources.labels.none + "</p>";
7: }
8:
9: HtmlGenericControl ul = new HtmlGenericControl("ul");
10: ul.Attributes.Add("class", "recentComments");
11: ul.ID = "recentComments";
12:
13: foreach (Comment comment in comments)
14: {
15: /* CUSTOM CODE */
16: ServingEventArgs arg = new ServingEventArgs(comment.Content, ServingLocation.Other);
17: comment.OnServing(arg);
18: if (arg.Cancel)
19: {
20: continue;
21: }
22: /* END CUSTOM CODE */
23:
24: if (comment.IsApproved)
25: {
26: HtmlGenericControl li = new HtmlGenericControl("li");
27:
28: // The post title
29: HtmlAnchor title = new HtmlAnchor();
30: title.HRef = comment.Parent.RelativeLink.ToString();
31: title.InnerText = comment.Parent.Title;
32: title.Attributes.Add("class", "postTitle");
33: li.Controls.Add(title);
34:
35: // The comment count on the post
36: LiteralControl count = new LiteralControl(" (" + ((Post)comment.Parent).ApprovedComments.Count + ")<br />");
37: li.Controls.Add(count);
38:
39: // The author
40: if (comment.Website != null)
41: {
42: HtmlAnchor author = new HtmlAnchor();
43: author.Attributes.Add("rel", "nofollow");
44: author.HRef = comment.Website.ToString();
45: author.InnerHtml = comment.Author;
46: li.Controls.Add(author);
47:
48: LiteralControl wrote = new LiteralControl(" " + Resources.labels.wrote + ": ");
49: li.Controls.Add(wrote);
50: }
51: else
52: {
53: LiteralControl author = new LiteralControl(comment.Author + " " + Resources.labels.wrote + ": ");
54: li.Controls.Add(author);
55: }
56:
57: // The comment body
58: string commentBody = Regex.Replace(comment.Content, @"\[(.*?)\]", "");
59: int bodyLength = Math.Min(commentBody.Length, 50);
60:
61: commentBody = commentBody.Substring(0, bodyLength);
62: if (commentBody.Length > 0)
63: {
64: if (commentBody[commentBody.Length - 1] == '&')
65: {
66: commentBody = commentBody.Substring(0, commentBody.Length - 1);
67: }
68: }
69: commentBody += comment.Content.Length <= 50 ? " " : "… ";
70: LiteralControl body = new LiteralControl(commentBody);
71: li.Controls.Add(body);
72:
73: // The comment link
74: HtmlAnchor link = new HtmlAnchor();
75: link.HRef = comment.Parent.RelativeLink + "#id_" + comment.Id;
76: link.InnerHtml = "[" + Resources.labels.more + "]";
77: link.Attributes.Add("class", "moreLink");
78: li.Controls.Add(link);
79:
80: ul.Controls.Add(li);
81: }
82: }
83:
84: StringWriter sw = new StringWriter();
85: ul.RenderControl(new HtmlTextWriter(sw));
86:
87: string ahref = "<a href=\"{0}syndication.axd?comments=true\">Comment RSS <img src=\"{0}pics/rssButton.gif\" alt=\"\" /></a>";
88: string rss = string.Format(ahref, Utils.RelativeWebRoot);
89: sw.Write(rss);
90: return sw.ToString();
91: //HttpRuntime.Cache.Insert("widget_recentcomments", sw.ToString());
92: }