Skip to content

Instantly share code, notes, and snippets.

@gabesumner
Created February 12, 2012 23:06
Show Gist options
  • Save gabesumner/1811490 to your computer and use it in GitHub Desktop.
Save gabesumner/1811490 to your computer and use it in GitHub Desktop.
Import Disqus Comments from Sitefinity 3
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="test.aspx.cs" Inherits="test" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
<title>Use Ctrl + A to select All, then Paste into Notepad. This is your XML export file.</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:Repeater ID="xmlRepeater" runat="server">
<HeaderTemplate>
<pre>
&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;
&lt;rss version=&quot;2.0&quot;
xmlns:content=&quot;http://purl.org/rss/1.0/modules/content/&quot;
xmlns:dsq=&quot;http://www.disqus.com/&quot;
xmlns:dc=&quot;http://purl.org/dc/elements/1.1/&quot;
xmlns:wp=&quot;http://wordpress.org/export/1.0/&quot;
&gt;
&lt;channel&gt;
</HeaderTemplate>
<ItemTemplate>
&lt;item&gt;
&lt;title&gt;<%# Eval("[Title]") %>&lt;/title&gt;
&lt;link&gt;http://www.goondocks.com/blog<%# Eval("[Url]") %>.aspx&lt;/link&gt;
&lt;dsq:thread_identifier&gt;<%# Eval("[ID]") %>&lt;/dsq:thread_identifier&gt;
&lt;wp:post_date_gmt&gt;<%# Eval("[DatePosted]")%>&lt;/wp:post_date_gmt&gt;
&lt;wp:comment_status&gt;open&lt;/wp:comment_status&gt;
<asp:Repeater DataSource='<%# Eval("[Comments]") %>' runat="server">
<ItemTemplate>
&lt;wp:comment&gt;
&lt;wp:comment_id&gt;<%# Eval("[ID]") %>&lt;/wp:comment_id&gt;
&lt;wp:comment_author&gt;<%# Eval("[Author]") %>&lt;/wp:comment_author&gt;
&lt;wp:comment_author_email&gt;<%# Eval("[Email]") %>&lt;/wp:comment_author_email&gt;
&lt;wp:comment_author_url&gt;<%# Eval("[Website]") %>/&lt;/wp:comment_author_url&gt;
&lt;wp:comment_author_IP&gt;<%# Eval("[IpAddress]") %>&lt;/wp:comment_author_IP&gt;
&lt;wp:comment_date_gmt&gt;<%# Eval("[DatePosted]")%>&lt;/wp:comment_date_gmt&gt;
&lt;wp:comment_content&gt;&lt;![CDATA[<%# Eval("[Text]")%>]]&gt;&lt;/wp:comment_content&gt;
&lt;wp:comment_approved&gt;1&lt;/wp:comment_approved&gt;
&lt;wp:comment_parent&gt;0&lt;/wp:comment_parent&gt;
&lt;/wp:comment&gt;
</ItemTemplate>
</asp:Repeater>
&lt;/item&gt;
</ItemTemplate>
<FooterTemplate>
&lt;/channel&gt;
&lt;/rss&gt;
</pre>
</FooterTemplate>
</asp:Repeater>
</div>
</form>
</body>
</html>
using System;
using System.Collections;
using System.Web;
using Telerik.Cms.Engine;
using System.Text.RegularExpressions;
public partial class test : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
Telerik.Cms.Engine.ContentManager contentManager = new Telerik.Cms.Engine.ContentManager("Blogs");
IList posts = contentManager.GetContent();
ArrayList Posts = new ArrayList();
int Count = 0;
// Loop through all blog posts
foreach (IContent post in posts)
{
// Yes, I know ArrayLists and Hashtables are lame. However, Sitefinity 3 was built with .NET 2.0
// which doesn't support generics and I didn't want to take the time to fully implement IList.
Hashtable Post = new Hashtable();
Post.Add("ID", post.ID);
Post.Add("Title", post.GetMetaData("Title"));
Post.Add("Url", post.Url);
// That "GeteCreationDate()" only exists in later version of Sitefinity 3.x.
Post.Add("DatePosted", post.DateModified.ToUniversalTime().ToString("yyyy-MM-dd HH:mm:ss"));
Post.Add("Comments", new ArrayList());
foreach (IComment comment in post.Comments)
{
ArrayList Comments = new ArrayList();
// I had a TON of spam in my blog (thousands of comments), this is used to filter this SPAM.
// Sorry for the offensive language, you can thank spammers for this.
if (
comment.Visible == true &&
comment.IsReadByUser("admin") == true &&
comment.Text.Length > 100 &&
comment.GetCreationDate() < new DateTime(2011, 1, 1) &&
Regex.IsMatch(comment.Email, @"aol\.com") == false &&
Regex.IsMatch(comment.Author, @"\@") == false &&
String.IsNullOrEmpty(comment.Author) == false &&
Regex.IsMatch(comment.Text.ToString(), @"penis") == false &&
Regex.IsMatch(comment.Text.ToString(), @"sex") == false &&
Regex.IsMatch(comment.Text.ToString(), @"herbal") == false &&
Regex.IsMatch(comment.IpAddress.ToString(), @"121\.204") == false
)
{
Count++;
Hashtable Comment = new Hashtable();
Comment.Add("ID", comment.ID);
Comment.Add("Author", comment.Author);
Comment.Add("Email", comment.Email);
Comment.Add("Website", comment.WebSite);
Comment.Add("Text", HttpUtility.HtmlEncode(comment.Text));
Comment.Add("IpAddress", comment.IpAddress);
// That "GeteCreationDate()" only exists in later version of Sitefinity 3.x.
Comment.Add("DatePosted", comment.GetCreationDate().ToUniversalTime().ToString("yyyy-MM-dd HH:mm:ss"));
((ArrayList)Post["Comments"]).Add(Comment);
}
}
if (((ArrayList)Post["Comments"]).Count > 0)
{
Posts.Add(Post);
}
}
xmlRepeater.DataSource = Posts;
xmlRepeater.DataBind();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment