Created
February 12, 2012 23:06
-
-
Save gabesumner/1811490 to your computer and use it in GitHub Desktop.
Import Disqus Comments from Sitefinity 3
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<%@ 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> | |
<?xml version="1.0" encoding="UTF-8"?> | |
<rss version="2.0" | |
xmlns:content="http://purl.org/rss/1.0/modules/content/" | |
xmlns:dsq="http://www.disqus.com/" | |
xmlns:dc="http://purl.org/dc/elements/1.1/" | |
xmlns:wp="http://wordpress.org/export/1.0/" | |
> | |
<channel> | |
</HeaderTemplate> | |
<ItemTemplate> | |
<item> | |
<title><%# Eval("[Title]") %></title> | |
<link>http://www.goondocks.com/blog<%# Eval("[Url]") %>.aspx</link> | |
<dsq:thread_identifier><%# Eval("[ID]") %></dsq:thread_identifier> | |
<wp:post_date_gmt><%# Eval("[DatePosted]")%></wp:post_date_gmt> | |
<wp:comment_status>open</wp:comment_status> | |
<asp:Repeater DataSource='<%# Eval("[Comments]") %>' runat="server"> | |
<ItemTemplate> | |
<wp:comment> | |
<wp:comment_id><%# Eval("[ID]") %></wp:comment_id> | |
<wp:comment_author><%# Eval("[Author]") %></wp:comment_author> | |
<wp:comment_author_email><%# Eval("[Email]") %></wp:comment_author_email> | |
<wp:comment_author_url><%# Eval("[Website]") %>/</wp:comment_author_url> | |
<wp:comment_author_IP><%# Eval("[IpAddress]") %></wp:comment_author_IP> | |
<wp:comment_date_gmt><%# Eval("[DatePosted]")%></wp:comment_date_gmt> | |
<wp:comment_content><![CDATA[<%# Eval("[Text]")%>]]></wp:comment_content> | |
<wp:comment_approved>1</wp:comment_approved> | |
<wp:comment_parent>0</wp:comment_parent> | |
</wp:comment> | |
</ItemTemplate> | |
</asp:Repeater> | |
</item> | |
</ItemTemplate> | |
<FooterTemplate> | |
</channel> | |
</rss> | |
</pre> | |
</FooterTemplate> | |
</asp:Repeater> | |
</div> | |
</form> | |
</body> | |
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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