Well, I finally had a free moment and I just got back in town the other night so I thought a take a moment and do some blogging. It's been a while since I posted regarding my custom blog rating control; I've been meaning to get this up for download for some time but could never manage to - until now, not to mention that I've gotten quite a few requests to get it :).
Bear in mind, this is NOT the definitive, final release. It is, however, enough to get started and have as a functional rating system. Below, I've provided a bit of documentation to help you get it up and running on your site. Please feel free to contact me if you have any questions.
The first thing you'll need to do is to run a database script against your blog database. This script, found in the file 'DbScript.sql' does not do anything to alter existing schema. All it does is adds a table (blog_DevstoneRating), a few store procedures (blog_DevstoneRateItem, blog_DevstoneGetItemRating, and blog_DevstoneGetTopRatedItems), and a function (blog_fnDevstoneGetPostUrl). Be sure to change the database name to the appropriate name before running the script. Oh, and backup your database.
The main rating control is called RatingSummary. There is also another control that I haven't yet packaged because it's not quite finished that is called TopRatedPosts. It is functional, but not yet friendly to all skins - I'll get it up as soon as I can. Additionally, there is an HttpHandler and an HttpHandlerFactory class. These provide integration into the .Text blog website.
The RatingSummary supports being embedded on a variety of pages within your blog (so that users can rate a blog post, a comment, etc). One of the chief design tenets was that I wanted to be able to place the control on the main page along side each post, thereby providing the user a quick way to enter comments and rate the post. Note: If a user rates a post and doesn't enter any comments it simply updates the post's rating. However, if the user provided comments, not only is the post's rating is updated, but the user's comment is added to the list of posts for the site so it appears as a regular comment on the site.
The following examples identify a few of the changes you can make to incorporate the rating control on your site. You will need to add the following page directive to the top of each control in which you intend to use the control:
<%@ Register tagPrefix="devstone" namespace="Devstone.Web.Blog.Controls" assembly="Devstone.Web.Blog.Controls.Rating" %>
The simple RatingSummary declaration resembles the following:
<devstone:ratingsummary runat=server visible=true />
The RatingSummary control offers a variety of properties that you can set to ensure proper behavior whereever posted.
ShowSummary (bool property): Defaults to true. Determines the presence of a descriptive text beneath the graphical rating, explaining the rating.
RatingBarType (RatingBarType property): Defaults to RatingBarType.Star. Determines the appearance of the rating control. Valid values include Star, Dot, and Bar.
ShowRatingLink (bool property): Defaults to true. Determines if the link allowing users to rate the post is to be shown.
PostId (int property): Defaults to -2 (autodetermine). If you explicitly place the post id on the control, the user will be guided to rate a particular post. If left as autodetermine (-2), the RatingSummary control attempt to read the post id from the url. If it cannot, it returns -1 (invalid).
PostLink (string property): The url to the post being rated.
PostType (PostType property): Defaults to PostType.BlogPost. The value of this property determines the text displayed to the user describing what they are rating.
Alignment (HorizontalAlign property): Defaults to HorizontalAlign.Left. Determines the alignment of the control.
Rated (bool readonly property): Returns whether the particular post has been rated by the user.
Now, in order to get the control to work properly, you must make a few changes to the web.config file. Within the <HandlerConfiguration/HttpHandlers /> node, add the following patterns (NOTE: see the previous post for further details on how to set these up properly if you have a multiple-blog site vs a single-blog site. These tags are for a multiple-blog site):
<HttpHandler pattern="^(?:/(\w|\s|\.)+/img/\d\.\d{2}/(?:Star|Dot|Bar)\.dspx)$" type="Devstone.Web.Blog.Controls.RatingHandlerFactory, Devstone.Web.Blog.Controls.Rating" handlerType="Factory" />
<HttpHandler pattern="^(?:/(\w|\s|\.)+/rate/(?:Star|Dot|Bar)/[12345]/\d+\.dspx)$" type="Devstone.Web.Blog.Controls.RatingHandlerFactory, Devstone.Web.Blog.Controls.Rating" handlerType="Factory" />
Then add the following to the <appSettings /> section, substituting the proper values:
<!-- Devstone Settings -->
<add key="Devstone.DbConnectionString" value="..." />
<add key="Devstone.SendEmail" value="true" />
<add key="Devstone.SmtpServer" value="..." />
<add key="Devstone.Email" value="..." />
<add key="Devstone.EmailSender" value="..." />
<add key="Devstone.EmailSubjectHeader" value="Blog Rating" />
The following are examples as they might appear to enable a user to rate various post types:
Comments.ascx:
<devstone:ratingsummary runat=server alignment=right postType="Comment" postId="<%#((Dottext.Framework.Components.Entry)Container.DataItem).EntryID %>" visible=true />
Day.ascx:
<devstone:ratingsummary runat=server alignment=right postId="<%# ((Entry)Container.DataItem).EntryID %>" postLink="<%# ((Entry)Container.DataItem).Link %>" visible=true />
Download: RatingControl.zip
For more information, please see the previous posts:
Part I: From Vague Concept to Less-Vague Concept
Part II: Integrated with .Text
Have fun!