Integrate DISQUS For Comment Management In MVC

3. September 2011 18:02

API ASP.NET MVC  4 Comments

I have been working on a MVC project which I will be using to save and manage all my code snippets. I get this plan in my head when my 160GB of HDD got crashed which holds most of my work and code. I started writing the web application in web forms and almost got it completed, but eventually changed my mind and started writing the application from scratch in MVC 3 with Razor view engine.

As I will be making this application online, I am sure to receive some comments when I share my code with others. To know what people thing about the code I published, I must have a commenting system for my application to know what people think. Instead of writing my own comment mechanism I would rather want to go with DISQUS commenting system. For my blog I am not using DISQUS, but for this application I will use DISQUS as it will save my time and is also a reliable way to manage comments.

Working with MVC is fun and even more when you are working with helper classes. Read my blog post on Working with Microsoft Web Helpers in ASP.NET to know more about helper classes and their features and how they can save your time in developing applications. I am going to show you how you can integrate DISQUS commenting system in your MVC application with ease. To get started, register a DISQUS account

Create a new MVC project in Visual Studio and without any delay go to NuGet console and type in the below command to add the DISQUS helper class.

 
The DISQUS helper class has 2 methods which we will be going to use.
  • Initialize: This method will help us to initialize the commenting system. It accepts your short forum name as a parameter which you have created at the time of creating your account at DISQUS.
  • ShowComments: This method accepts the name of the page.
To initialize DISQUS, we need to set the Initialize method in _ViewStart.cshtml file. You can find this file under Views folder. Make sure that this is a first line in the file as we have to initialize before the layout of the page gets rendered.
@{
    Disqus.Initialize("shortforumname");
 }
Now as we have initialized, we can show the comments on the page. To show the comments on the page we will use the ShowComments method and pass the page name in the parameter. Just to be more precise about this parameter, I would like to point out that on a forum, blog or on a website every page has a unique name or forum post id or blog post and the parameter that we are going to pass to this method should also be the same unique post id or page name.
@Disqus.ShowComments(pageIdentifier: "post123")
This will render the DISQUS comments as shown below:
Someone will now make a comment here and move to another page and then make another comment. The only way DISQUS has to identify the comments on the basis of the PageIdentifier parameter in the ShowComments method. When some other user requests the same page again from a different geographical location, the DISQUS will check the PageIdentifier and then load the related comments.
I hope this post gives you an overview on how you can integrate DISQUS commenting system on you site in MVC.
 No Rating

Social Counter: JQuery Plugin To Get Twitter, Facebook And Feed Readers Count

2. September 2011 16:53

API ASP.NET Jquery Web  13 Comments

Appending my previous post, I have created a plugin in JQuery to get twitter followers count, facebook likes and feed readers count. In my previous post, I have shown a way to get the counts in ASP.NET and I have created this plugin so that everyone can use and show counts on their blogs or site.
To get started add the two javascript files, one is the jquery file and the other one is the plugin file.
<script type="text/javascript" src="Scripts/jquery-1.4.1.js"></script>
<script src="Scripts/jquery.SocialCounter.js" type="text/javascript"></script>
Before I proceed to show you how to get it done, I should explain a bit about my small plugin. This plugin accepts 2 parameters:
  • SocialSite: Name of the social site like Twitter, Facebook and Feeds (case-sensitive).
  • UName: This options holds the user name or the facebook URL or the feed reader URL or the user name.
Now it's all on the developer/designer where he wants to show the counter. I have set 3 divs on my page with ID. It is not at all necessary to use divs, you can use whatever you want. To get the counts I will do the following on the document.ready function.
$(document).ready(function () {
            $("#tweet").SocialCounter({ SocialSite: 'Twitter', UName: 'prashantmx' });
            $("#FBLikes").SocialCounter({ SocialSite: 'Facebook', UName: 'http://facebook.com/audi' });
            $("#FeedReader").SocialCounter({ SocialSite: 'Feeds', UName: 'Midnightprogrammer' });
        });

Just for your information, Feed Burner API has been deprecated by Google but they have also made sure that the current working of the feedburner would not be affected. I don't know if this is the reason behind this, but everytime I try to get my feed readers count I get 0. I think this is for time being and will be back on track soon.

Download: jquery.SocialCounter.zip (889.00 bytes)

Currently rated 4.0 by 11 people

Get Twitter, Facebook And Feed Readers Count In ASP.NET

2. September 2011 03:40

API ASP.NET Code Snippets Web  6 Comments

I am working on some web stuff these days and surfing around to look at some of the best web developer's work around the web. As I was surfing I came across one of the most popular and reputed web tutorials site Nettus+. I am not going talking about any tutorial or article published on this site, but one thing that attracts my attention was the way they are displaying their followers count on twitter, facebook likes and RSS readers.
This looks pretty cool and just out of curiosity I viewed the page source, hoping to find some script or API call which gets the count. But eventually I can't found anything. For Twitter and Facebook I know that there is an API and therefore I can get the twitter followers and facebook like count but don't know anything about the feed readers count. So I search the web get myself aware of the feedburner API. So let's take a look at the code.
 
Get Twitter Followers Count

To get your twitter followers count, I am making a REST API call. This call will return XML string and then I am going to parse the received XML using LINQ. You just need to pass your twitter user name to get the followers count.
public string GetTwitterFollowersCount(string UserName)
{
            XDocument xdoc = XDocument.Load("http://api.twitter.com/1/users/show.xml?screen_name=" + UserName + "&include_entities=false");
            return (from item in xdoc.Descendants("user")
                    select item.Element("followers_count").Value).SingleOrDefault();
}
Get Facebook Likes Count

To get total Facebook likes count you need to remember that you have to use the URL of your page for e.g. http://www.facebook.com/audi or http://www.facebook.com/nettutsplus and not just the name of your page. Check out the code:
public string GetFacebookLikes(string FaceBookURL)
{
         string URL = "https://api.facebook.com/method/fql.query?query=select%20%20like_count,%20total_count,%20share_count,%20click_count%20from%20link_stat%20where%20url=%22" + FaceBookURL + "%22";
         XElement xdoc = null;
         XElement counts = null;
         xdoc = XElement.Load(URL);

         IEnumerable<XElement> total_Like_count =
             from elem in xdoc.Descendants()
             where elem.Name.LocalName == "like_count"
             select elem;

         counts = total_Like_count.First();
         string FBLikes = Convert.ToString(counts.Value);
         return FBLikes;
}
Get RSS Feed Readers Count

To get the RSS feed readers count you need to pass the complete URL of your feed URL for e.g. http://feeds.feedburner.com/MidnightProgrammer
public string GetFeedReadersCount(string url)
{
            XDocument xdoc = XDocument.Load("http://feedburner.google.com/api/awareness/1.0/GetFeedData?uri=" + url);
            return (from item in xdoc.Descendants("entry")
                    select item.Attribute("circulation").Value).SingleOrDefault();
}

This is it, now it all depends on the designer or developer how to get the stats and present it in a more attractive way. I am not a designer and this is why I am not putting any effort to do something like this to show you this thing in action. At present I am working on JQuery version of the above code, so people who are willing to show stats on their blogs or website which are different platforms. Till that time, try the above code with ASP.NET and let me know of this helps you out.

Currently rated 4.4 by 5 people

HTML 5 Cheat Sheets

13. August 2011 03:21

Web  0 Comments

If you are working with HTML 5, then there are some cheat sheets which you should refer for HTML 5 syntax. Here are three different cheat sheets for HTML 5.

HTML 5 Visual Cheat Sheet

 

HTML 5 Quick reference Cheat Sheet

 

 

HTML 5 Canvas Cheat Sheet

 

Download:

HTML 5 - Cheat Sheets.zip (380.58 kb)

 No Rating

Female Indian Software Professional - Described

13. August 2011 02:19

Fundoo  0 Comments

Today a colleague sent me an email which describes female software professional in software terminology.
class Indian_Bachelor_female_professional 
{ 
      double styles; 
      short skirts; 
      long time_to_understand_problems; 
      float mind; 
      void knowledge(); 
      char non_co_operative; 
}
  
class Married_female_Software_Professional 
{ 
      double weight; 
      short tempered; 
      long gossips; 
      float hopes; 
      void work(); 
      char unstable; 
}
  
class Female_Engaged_software_professional 
{ 
      double time_on_phone; 
      short attention_on_work; 
      long boast; 
      float on_cloud_nine; 
      void understanding(); 
      char edgy; 
}
  
class Indian_Newly_Married_software_professional 
{ 
      double dinner_invitations; 
      short time_at_work; 
      long lunch_breaks; 
      float talks; 
      void bank_balance(); 
      char hen_pecked; 
}
  
class Indian_husband_wife_software_professional 
{ 
      double income; 
      short temper; 
      long time_no_see; 
      float new_software_company; 
      void lov 
}

class Guy_who_wrote_this 
{ 
     Long time_on_bench; 
     Void work(); 
}

If you have any thoughts on this, please feel free to leave a comment.

Currently rated 5.0 by 1 person

Visit blogadda.com to discover Indian blogs Computers Blogs