Nov 11, 2009

Counting blog posts AND COMMENTS!!

Upon further investigation and testing on my original project counting blog posts and due to the suggestion from Terry, I realized that I should implement something to count our comments as well as our posts. Taking my code a step further to count the blog comments as well wasn't too much more work since I had already done the preliminary stuff. The changes came after my 'readBlogFeed' function. Once the posts have been counted and returned to the div on my HTML page, a new function I created called 'comments' is then called. This function is what I used to count the comments. It goes through the process of contacting the blogger API again and then I take the results and parse through them again using another function I created called 'readCommentsBlogFeed'. The 'readCommentsBlogFeed' function is similar to the 'readBlogFeed' function I created before, but instead of counting the authors of posts it counts the authors of comments.

Now the main difference between counting the posts and counting the comments is actually done in the PHP file on my server. The blogger API uses a different link for the comments, which is http://www.blogger.com/feeds/OUR_BLOG_ID/comments/default instead of the one just for posts which is http://www.blogger.com/feeds/OUR_BLOG_ID/posts/default.



As you can see, I also took the JavaScript coding a lot further to create a dynamic select box that automatically finds all the names from our class blog and sorts them and places them in a list for you. This was a little tricky to code, but it will prevent any typos or other errors that were occurring before. Basically, I made an initial call to the blogger API on the page load which got the XML and parsed through it for all the names of authors that have posted on our blog. Once it got the names I needed to create a function that removed any duplicate names. Upon sorting it alphabetically using JavaScript's sort() function on the array I created, I then passed the list into the function to remove the duplicates and only leave a list of our names. I also took Terry and Jassin's names and wrote them out in the JavaScript since they were in lower case and didn't follow the structure of everyone else's...(I'm kind of a neat freak) Here's a little bit of the code I used to make all this work:

Here's how I went about changing the names and using the sort() method to sort my array of names:


Removing duplicate names:


Creating the select box dynamically:


Feel free to use this neat little application to make sure you're staying up on the class requirements! It's on my people account Website at http://people.emich.edu/mmager/449/.

Let me know if any issues arise too and I'll fix them!

5 comments:

  1. Wow Matt the counting blog works great! I even tested to see my blogs! I am very impressed with thow well this application works. This will make the class lives a little easier and Professor Drake can use this as a quick refernece for our counts. Once again great job

    Justin

    ReplyDelete
  2. Thanks for making this Matt! Check out my rebuttal post for the lazy man. I envy the comment count function though. My lazy ways haven't discovered a lazy solution yet!

    ReplyDelete
  3. Matt,
    I am curious about whether your blog counts are accurate. I know that I have posted more blogs than it says. Does it check every blog or just whoever comments on a post first?

    ReplyDelete
  4. I do find your program very useful. The idea that bothers me is that I am almost sure that I have more comments than what the program says.

    ReplyDelete
  5. Matt, I love the idea of the dropdown box that you've incorporated into our counts. This just makes the process so simplistic, how much easier could it be to just push a few buttons and in a matter of seconds have an accurate count! Great job once again!

    ReplyDelete