Prabir's Blog

where the tech matters...

Migrating Existing BlogEngine.Net Comments to Disqus

May 17
by prabir 17. May 2010 13:55

If you have been moderating a blog or writing your own, you must have experienced a lot of spammers invading your blog with comments. To solve it you might have disabled comments after a particular day, installed some extensions (plugins) to help you moderate your comments or even out-sourced you commenting system. Well, in my case I had decided to out-source it and choose Disqus as my commenting system. I was pretty lucky that I choose Disqus commenting system as BlogEngine.Net now officially allows to choose between either its own commenting system or Disqus commenting system, making it more easier for me to upgrade to newer versions as it wouldn’t require me to hack the BlogEngine.Net source code to inject some Disqus related codes.

One of the down side was that my blog already had some comments posted using the BlogEngine.Net. I didn’t want my old comments to be hidden (lost) and yet I wanted to choose some commenting system that would help me manage comments more easily. I decided to go with Disqus Comments after researching with its competitors.

I landed up disabling the BlogEngine.Net add new comments but still putting the old comments. Any new comments would had to be entered using the newly installed Disqus Comments as show below.

sample1 This was a temporary hack to use Disqus as the core commenting system. Later on with version 1.6.0.5 of BlogEngine.Net they officially supported Disqus Commenting system and would allow us to choose between the BlogEngine’s one or Disqus. Then I thought of migrating all my comments to Disqus as this would help me upgrade my blog more easily.

To solve this, I started searching for options to migrate existing comments to Disqus. They had official support for importing Intense Debate comments. I then created an extension for exporting BlogEngine.Net’s comments to Intense Debate comments xml format. But it was taking too long to import and finally gave me errors after importing. Tried it many times but was having no success. Finally I landed up writing a C# API to communicate with Disqus. The source code is open sourced and can be downloaded here (I’m using git version control system. please checkout to dev branch to see the codes). I decided to name it Disqus#.

Enough of the history. Lets start migrating.

First of you will need to download the BlogEngine.Net extension which allows you to export your blog engine.net comments at the end of the post. (Note: nested comments are not supported. This extension was created in hurry and is based on only my requirements.)

There are two things you will need to upload to your website. The extension it self called CommentsExporter.cs to App_Code\Extensions folder and the web-GUI front-end for exporting comments to User controls\ExportComments.aspx.*

You will then need to login as the Blog moderator (administrator) and go to the extensions tab of the control panel.

image

Then select Edit link in the settings column of the CommentExporter. You will land up with the following page.

image

You can then click Export Comments button and choose Disqus Comments as the format. (Nested comments are not supported.) Map Authorized Users was basically created for exporting to Intense Debate (which I had chosen as my first export format, unfortunately it didn’t turn out well). This feature can still be used for Disqus Comments format. For example, in some of my comments I had written the author name as prabir or prabirshrestha. When I wanted to migrate I wanted to make them both as the same user – prabirshrestha. This was achieved by typing prabir:prabirshrestha; color(:) separates the key and value while semi-color(;) allows you to write more mappings. This is case sensitive too. You can write multiple values by entering prabir:prabirshrestha;Prabir:prabirshrestha; After you are done click the export button and save the exported comments. (The exported format is same as when you export comments from the Disqus website.)

Included with the download (below) there is a GUI frontend (Prabir.DisqusUploader) which looks similar as below.

image

Click browse and locate the file you just exported (saved) from the BlogEngine.Net website. You will need to then enter the User Api Key at the bottom left. If you don’t know your Disqus User Api Key, login to disqus and navigate to this link http://disqus.com/api/get_my_key/ Copy paste the User Api Key from the browser and click Get Websites button. Choose the appropriate website and click Upload to Disqus button. Once you are done with uploading a MessageBox is shows saying - “Your comments have been uploaded to Disqus.”

Here’s the sample of uploaded Disqus Comments.

sample3

Then I finally upgraded my BlogEngine.Net to the latest version which supports Disqus Comments. The old comments were also removed. Finally I landed up as …

image

Note: There is a small issue when uploading the comments to Disqus, it tends to truncate the comments if you have a single or double quote in the comments (‘ “) or have a semi-colon in the comments (;). I had to manually edit the truncated comments. If you want to fix it you can also download the source code. (Now that I am done migrating, most probably I wouldn’t have to be touching the source code, but if any one wants to contribute it back I would be more than happy.) Please use it at your own risk.

 DisqusUploaderWithBlogEngineExtensions.zip (778.56 kb) [Downloads: 103]

 DisqusUploader-Src.zip (4.02 mb) [Downloads: 114]

If you enjoyed this post, make sure you subscribe to my RSS feed!

Tags: ,

BlogEngine.NET

Create a Windows 7 Federated Search Connector for your Blog

December 20
by prabir 20. December 2009 08:28

The driving force that landed me to create this blog that you are reading now, has mainly been that I wanted to contribute back to the society, “the internet society” from where I have learned so much. And the other one was to also put as a reference from the future. There are many times when I actually need to refer to my own blog.

For instance, I often need to redirect HTTP to HTTPS. (You can find this article at http://blog.prabir.me/post/HTTP-redirection-to-HTTPS.aspx). But opening blog.prabir.me and then typing redirect in the search box would quite lose my time. So I landed up creating a Windows 7 Federated Search Connector – a cool new Windows 7 feature.

When I search for redirect keyword in my blog using the Window 7 connector I would get the following result.

image

 

How does the magic happen. Well first the search results show up as RSS feeds using the open search URL conventions. And luckily BlogEngine.NET already supports it out of the box. Try this url http://blog.prabir.me/syndication.axd?q=redirect

It already contains the page called syndication.axd where we can pass you search query using the q querystring.

To do that we define a Windows 7 Search Connector file ending with .osdx extension. It is a normal text file. So you can edit it using your favorite text editor.

<?xml version="1.0" encoding="UTF-8"?>
<OpenSearchDescription xmlns="http://a9.com/-/spec/opensearch/1.1/">
  <ShortName>Prabir's Blog - www.prabir.me</ShortName>
  <Description>Prabir's Blog - where the tech matters</Description>
  <Language></Language>
  <Url type="application/rss+xml" template="http://blog.prabir.me/syndication.axd?q={searchTerms}"/>
</OpenSearchDescription>

Notice the URL, we pass the search query in querystring q as {searchTerms}, that is how Windows 7 uses it.

Once you save it to .osdx file, double click it and you will asked if you want to add it. Click add then you are all set.

But the fun doesn’t end here. In the search results when you double click, it will open the article in Web Browser. And if you have the preview pane, it will show up in the Window Explorer Search Window it self as shown below.

image

prabirDOTme-Windows7FederatedSearchConnector.zip (371.00 bytes) [Downloads: 233]

If you enjoyed this post, make sure you subscribe to my RSS feed!

Tags: ,

BlogEngine.NET | Windows

Syntax Highlighter for Windows Live Writer v0.2 released

December 06
by prabir 6. December 2009 23:08

Syntax Highlighter v0.2 has been released along with source code at Codeplex. This is an update to my original Windows Live Writer plugin which can be found at http://blog.prabir.me/post/Windows-Live-Writer-Syntax-Highlighter.aspx.

As you might have noticed some of the features such as auto link detection, collapse, gutter (line numbering), toolbar, wrap lines and starting line number have been added.

image

To download the files please visit http://codehighlighter.codeplex.com

or download from windows live gallery.

More features coming soon. If you want to help develop this plug-in please leave a comment below or contact me at http://blog.prabir.me/contact.aspx.

If you enjoyed this post, make sure you subscribe to my RSS feed!

Tags: ,

BlogEngine.NET

Bing Translator For Blog Engine .NET

October 06
by prabir 6. October 2009 16:23

It had been a month since I got an invitation to (Bing) Microsoft Translator Widget, but had not found my time to play around. So I decided to create a Blog Engine .NET widget so that other users from various parts of the world can easily read through the articles. I have also created Google Translator Widget earlier which you can find here. I’m not going to fight about which one is the best out here, I leave it to you to choose. Mimageicrosoft Translator has quite a good Ajaxified Translator which you can check it in my blog (from right hand side menu) but it does require you to have an invitation before you can actually use one. You can register for at http://www.microsofttranslator.com/Widget 

Installation:

  • Simply upload the folder to the Blog Engine’s “Widget” folder.
  • Then login as administrator, and you will see Microsoft Translator as seen on the picture below.

image

  • Then click the edit widget and the popup will come up.

image

 

For example my details are as follows:

<div id="MicrosoftTranslatorWidget" style="width: 200px; min-height: 83px; border-color: #3A5770; background-color: #78ADD0;"><noscript><a href="http://www.microsofttranslator.com/BV.aspx?a=http%3a%2f%2fwww.prabir.me%2f">Translate this page</a><br />Powered by <a href="http://www.microsofttranslator.com">Microsoft® Translator</a></noscript></div>
<script id="MicrosoftTranslatorWidgetScript" type="text/javascript"  charset="UTF-8" src="http://api.microsofttranslator.com/v1/widget.svc/Embed?appId=4e-dM3lMn4etY3cW_Vtngdh03oVcKRAU&amp;from=en&amp;layout=ts"></script>

From the above script that was generated pickup appropriate settings and click save and you are done. Congratulations, you have integrated Microsoft Translator in your BlogEngine.Net

Here’s a sample pic of my blog after the translation by Microsoft Translator.

image

Microsoft Translator For BlogEnginedotNet.zip (2.29 kb) [Downloads: 179]

If you enjoyed this post, make sure you subscribe to my RSS feed!

Tags:

BlogEngine.NET

Windows Liver Writer Syntax Highlighter Source Code Released

September 13
by prabir 13. September 2009 00:22

In one of my old post http://blog.prabir.me/post/Windows-Live-Writer-Syntax-Highlighter.aspx, I had release the binary of Syntax Higlighter plugin that I had created. This plugin contained the basic functionalities of the Syntax Higlighter plugin, which would more than suffice for an ordinary code.

But due to my hectic schedule and other different projects, I haven’t been able to develop this plugin further. So, I have decided to release the full source  code (at first I was planning to release the source code when the plugin is complete). You can download the code which is hosted by codeplex.com at http://synatxhiglighter.codeplex.com. The code is written in C#.

I have been searching for some developers who would like to contribute to this project. If you are interested please leave a comment below or us the contact page to contact me.

To download the source code please visit http://synatxhiglighter.codeplex.com

You can download the binaries from http://blog.prabir.me/post/Windows-Live-Writer-Syntax-Highlighter.aspx, or directly from one of the below links

Prabir.wlw.Syntaxhiglighter.dll.zip (38.40 kb) [Downloads: 259]
Prabir.wlw.SyntaxHiglighter.msi (Setup) (360.00 kb) [Downloads: 308]

Get from Windows Live Gallery

If you enjoyed this post, make sure you subscribe to my RSS feed!

Tags: ,

BlogEngine.NET

Blog Engine.Net Google Translator Widget

July 08
by prabir 8. July 2009 20:33

Have you ever wanted people from different backgrounds and geographical regions to be able to read your blog in the language they prefer? Well, it isn’t hard as you thought so. You don’t need to hire anyone and pay them to translate it for you. There are lot of free translation services provided by Google, Microsoft and Yahoo to name a few popular ones.

image

The one I’m using is from Google as it supports a lot more than others. (I can’t comment on the accuracy, I don’t understand those many languages).

To make life easier I have created a widget which works with BlogEngine.Net. You are simply required to upload the folder which you can download at the end of the post to you BlogEngine’s "widgets" folder.

Once you are done with uploading the files. You will need to login as administrator in your BlogEngine. Widgets dropdown box will be visible. Then select Google Translator from the drop down and click add. Its that easy.

For live example you can use my Google Translation Widget at the right hand side.

image

Google Translator.zip (942.00 bytes) [Downloads: 219]

For Microsoft (Bing) Translator click here.

If you enjoyed this post, make sure you subscribe to my RSS feed!

Tags: ,

BlogEngine.NET

Syntax Highlighter 2.0 and Blog Engine.Net

July 07
by prabir 7. July 2009 21:47

This post is a continuation of my previous article on integrating Syntax Highlighter 2.0 with Windows Live Writer. I would recommend you to read it also. This article will take it one step further by learning how to integrate it with Blog Engine.Net 1.5. For Syntax Highlighter 1.5 with Blog Engine and Windows Live Writer you can find my article here.

You will need to download the Syntax Highlighter 2.0 files from http://alexgorbatchev.com/wiki/SyntaxHighlighter or at the end of this post.

You will need to upload the necessary files and folders (scripts and styles folder are only required). Then login to your blog as administration and go to the settings tab of the BlogEngine. In your html head section paste the following code and click save settings.

<link type="text/css" rel="stylesheet" href="/styles/shCore.css" />
<link type="text/css" rel="stylesheet" href="/styles/shThemeDefault.css" />
<script type="text/javascript" src="/scripts/shCore.js"></script>
<script type="text/javascript" src="/scripts/shBrushCSharp.js"></script>
<script type="text/javascript" src="/scripts/shBrushCpp.js"></script>
<script type="text/javascript">
SyntaxHighlighter.config.clipboardSwf = '/scripts/clipboard.swf';
SyntaxHighlighter.all();
</script>

At the moment only C# and C++ syntax highlighting is available. If you would like to support more languages please add the appropriate javascript file as shown below

<script type="text/javascript" src="/scripts/shBrushXml.js"></script>

The list of available languages can be seen from Scripts folder that you just uploaded.

syntaxhighlighter_2.0.320.zip (81.54 kb) [Downloads: 206]

Windows Live Writer Plugin (Setup recommended):
Prabir.wlw.Syntaxhiglighter.dll.zip (38.40 kb) [Downloads: 259]
Prabir.wlw.SyntaxHiglighter.msi (Setup) (360.00 kb) [Downloads: 308] 

Get from Windows Live Gallery

If you enjoyed this post, make sure you subscribe to my RSS feed!

Tags: , ,

BlogEngine.NET

Windows Live Writer Syntax Highlighter

July 05
by prabir 5. July 2009 21:52

Syntax highlighting technique provides the readers with more attractive and easy to read code snippets. It is one of the must have for a blog (at least for mine). In my previous article I had mentioned about how to integrate Syntax Highlighter 1.5.1 to Blog Engine .NET with help of Windows Live Writer.

Well, this article is about integrating Syntax Higlighter 2.0 Windows Live Writer Plugin(I will be posting another article soon on integrating Syntax Higlighter 2.0 with Blog Engine You can find the article on integrating with blog engine out here). I actually went up searching for syntax highlighter 2.0 plugin support for Windows Live Writer but couldn’t a suitable one. I landed up writing my own plugin. This plugin is based on the modification of a plugin written in VB which can be found at http://wlwsyntaxhighlighter.codeplex.com. (My version of the plugin is written in C#).

You can either download the setup file and install or do it manually. For manual installation you will need to download the zip file at the end of this post and extract the .dll file to C:\Program Files\Windows Live\Writer\Plugins folder. (Please you appropriate destination where your Windows Live Writer is installed.) Next time when you start Windows Live Writer the plugin will automatically be loaded. Click on Syntax Higlighter… to insert you code. To uninstall the plugin make sure Windows Live Writer is not running and delete Prabir.wlw.Syntaxhiglighter.dll from Plugins folder.

image

A new dialog will open where you can choose your language and type the code. In the Language drop down box you can type your custom language even if it is not in the drop down box but make sure you also upload appropriate js scripts to your website to support the language.

image Since it makes use of Smart Content Editor you can later on edit your code using the menu at the right. Since this plugin is still under development. Most of the features are disabled. As of now some of the features that were disabled have been enabled.

 

image

I would also recommend you to read my article on integrating Syntax Higlighter 2.0 with Blog Engine.NET.

You can download the source code along with the latest setup from the codeplex website at http://codehighlighter.codeplex.com/

Prabir.wlw.Syntaxhiglighter.dll.zip (38.40 kb) [Downloads: 259]
Prabir.wlw.SyntaxHiglighter.msi (Setup) (360.00 kb) [Downloads: 308]

Get from Windows Live Gallery

If you enjoyed this post, make sure you subscribe to my RSS feed!

Tags: ,

BlogEngine.NET

Custom web.config Intellisense

May 27
by prabir 27. May 2009 01:28

(This is a part of my series Visual Studio Tips and Tricks – III )

Intellisense ExampleThere are at times when you would like to have intellisense support for you custom providers like the ones Microsoft provides.

In this post, I will be guiding you on the way how to create a basic intellisense for your BlogEngine.NET provider model for web.config.

You can open your BlogEngine.NET sourcecode or any of your websites to try it. But in this tutorial I will be sticking with BlogEngine.NET source code.

  1. To make stuffs clean I like to put all my Intellisense files (XSD schemas) in a folder called schemas. Please go ahead and create the folder. Add a new image item to your schemas folder. You can name it anything. Out here for simplicity I will name it blogengine.xsd.
  2. Change the target namespace to something meaning full. I prefer to have it like http://schemas.[company name]/product/year/month but its your choice. For now lets stick to http://schemas.prabir.me/blogengine/2009/5.
  3. Lets first have a look at our web.config file, and try to understand the schema.
<BlogEngine>
    <blogProvider defaultProvider="XmlBlogProvider">
        <providers>
  <add name="XmlBlogProvider" type="BlogEngine.Core.Providers.XmlBlogProvider, BlogEngine.Core"/>
  <add name="DbBlogProvider" type="BlogEngine.Core.Providers.DbBlogProvider, BlogEngine.Core" connectionStringName="BlogEngine"/>
        </providers>
    </blogProvider>
</BlogEngine>
  1. I will not be teaching you how to write XSD schemas. There is a good article at W3schools out here where you can learn more. For now just paste the code to your xsd schema file you created earlier. (Just looking at my code you can already learn a lot about xsd schemas – I would recommend you to download the code files at the end of the article for better formatting and readability).
<?xml version="1.0" encoding="utf-8"?>
<xs:schema id="blogengine"
targetNamespace=
"http://schemas.prabir.me/blogengine/2009/5"
elementFormDefault="qualified"
xmlns="http://tempuri.org/blogengine.xsd"
xmlns:mstns="http://tempuri.org/blogengine.xsd"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
>
<xs:element name="BlogEngine">
<xs:complexType>
<xs:sequence>
<xs:element name="blogProvider" minOccurs="1">
<xs:complexType>
<xs:sequence>
<xs:element name="providers" minOccurs="1" maxOccurs="unbounded">
<xs:complexType>
<xs:sequence>
<xs:element name="add" minOccurs="1" maxOccurs="unbounded">
<xs:complexType>
<xs:attribute name="name" type="xs:string" use="required" />
<xs:attribute name="type" type="xs:string" use="required" />

<xs:attribute name="connectionStringName" type="xs:string" use="optional" />

</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:sequence>
<xs:attribute name="defaultProvider" type="xs:string"/>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
  1. Finally to make your schema work, you will have to add the xmlns attribute to your web.config file which looks like below.
<BlogEngine xmlns="http://schemas.prabir.me/blogengine/2009/5">

custom_webconfig_intellisense.zip (3.65 kb) [Downloads: 199]

If you enjoyed this post, make sure you subscribe to my RSS feed!

Tags: ,

BlogEngine.NET | Visual Studio

Syntax Highlighter

May 20
by prabir 20. May 2009 18:40

You might have seen a few code snippets that I have been posting in my blog which is powered by BlogEngine.NET. In this article I am going to guide you through installation of Syntax Highlighter 1.5.1 in blog engine. (For Syntax Higlighter 2.0 click here)

First of all you need to download the syntax highlighter from its official site (version 1.5.1) from here and would also require you to install the installer from http://wlwsyntaxhighlighter.codeplex.com (tested with version 2.1.1).

Then you will need to upload the syntax highlighter files (Scripts and Style folder only) to your blog. Then login to your blog as a administrator and go to the settings tab in the control panel of blog engine. In your html head section paste the following code

<LINK rel=stylesheet type=text/css href="Styles/SyntaxHighlighter.css"></LINK>
<SCRIPT language=javascript src="Scripts/shCore.js">
</SCRIPT>
<SCRIPT language=javascript src="Scripts/shBrushCSharp.js">
</SCRIPT>
<SCRIPT language=javascript>
window.onload = function() {
 dp.SyntaxHighlighter.ClipboardSwf = 'Scripts/clipboard.swf';
 dp.SyntaxHighlighter.HighlightAll('code');
};
</SCRIPT>

At this moment only C# synatx is available. If you would like to support more languages please add the appropriate javascript file as shown below

<SCRIPT language=javascript src="Scripts/shBrushCpp.js">
</SCRIPT>

The list of available languages can be seen from Scripts folder that you just uploaded.

SyntaxHighlighter.msi (368.00 kb) [Downloads: 185]
SyntaxHighlighter_1.5.1.zip (41.16 kb) [Downloads: 172]

If you enjoyed this post, make sure you subscribe to my RSS feed!

Tags: , ,

BlogEngine.NET