To preserve some database space on my .Text installation, I have deleted some of the trackbacks, links and null records. All my trackbacks are p o k e r links anyway. There were also p o k e r comments but I got rid of them with Clearscreen HIP Captcha.

My other 2 little improvement to .Text is the "Recent Posts" and "Popular Posts" modules. I was jealous about other blogging engines and their modules so I have decided to write this one. I have the version 0.95.102 code of .Text. I basically created a stored procedure first to read last 10 records for the displayed blog and then constructed a repeater with title and the permanent link of the entry. I have also created a small method to construct permanent links, I am sure there is a ready to use function somewhere in .Text to format permanent links.

Here is the stored procedure:

CREATE Proc blog_Last10Items
(
@PostType int, --later to list comments
@BlogID int
)
AS
Select Top 10 A.id, A.Title, A.DateAdded, B.Application
From blog_Content A, blog_Config B
Where posttype = @PostType
AND A.BlogID = @BlogID
AND A.BlogID = B.BlogID
Order By DateAdded ASC

I have created a class giving the name Last10Module in Dottext.Web.UI.Controls and written the code below:

namespace Dottext.Web.UI.Controls

{

    using System;

    using System.Configuration;

    using System.Collections;

    using System.ComponentModel;

    using System.Data;

    using System.Data.SqlClient;

    using System.Drawing;

    using System.Web;

    using System.Web.SessionState;

    using System.Web.UI;

    using System.Web.UI.WebControls;

    using System.Web.UI.HtmlControls;

    using Dottext.Framework.Data;

    using Dottext.Framework.Configuration;

    using Dottext.Framework.Components;

    /// <summary>

    /// Summary description for Last10Module.

    /// </summary>

    public class Last10Module : BaseControl

    {

        protected System.Web.UI.WebControls.Repeater LastEntries;

 

        protected override void OnLoad(EventArgs e)

        {

            base.OnLoad (e);

 

            string sql = "blog_Last10Items";

            string conn = Dottext.Framework.Providers.DbProvider.Instance().ConnectionString;

 

            ArrayList myLastItems = new ArrayList();

 

            int BlogID = CurrentBlog.BlogID; //current blog id is here -- finally found it

 

            //PostType = 1 is the entries

            SqlParameter[] p =

                {

                    SqlHelper.MakeInParam("@PostType",SqlDbType.Int,4,1),

                    SqlHelper.MakeInParam("@BlogID",SqlDbType.Int,4,BlogID)

                };

 

            DataTable dt = SqlHelper.ExecuteDataTable(conn,CommandType.StoredProcedure,sql,p);

 

            int count = dt.Rows.Count;

 

            for(int i = 0; i<count; i++)

            {

                DataRow dr = dt.Rows[i];

 

                string title = (string) dr["Title"];

 

                //This is also in CurrentBlog.Application

                string application = (string) dr["Application"];

                DateTime dateAdded =(DateTime) dr["DateAdded"];

                string id =  dr["id"].ToString();

 

                string myURL = URLFormat(application, dateAdded,id);

 

                myLastItems.Add(new PositionItems(title,myURL));

 

            }

 

            LastEntries.DataSource = myLastItems;

            LastEntries.DataBind();

        }

 

 

        public string URLFormat(string dbApplication, DateTime dbDateAdded, string dbEntryID)

        {

            string myURL = ConfigurationSettings.AppSettings["AggregateURL"];

 

            myURL = myURL + "/" + dbApplication + "/";

 

            string myYear =  dbDateAdded.Year.ToString();

            string myMonth = dbDateAdded.Month.ToString();

            string myDay =  dbDateAdded.Day.ToString();

 

            int Month = int.Parse(myMonth);

            int Day = int.Parse(myDay);

 

            if (Month<10)

            {

                myMonth = String.Concat("0",myMonth);

            }

            if (Day<10)

            {

                myDay = String.Concat("0",myDay);

            }

 

            myURL = myURL +"archive" + "/" + myYear + "/" +

                    myMonth + "/" + myDay + "/" + dbEntryID + ".aspx";

 

            return myURL;

        }

    }

 

    public class PositionItems

    {

 

        private string title;

        private string URL;

 

        public PositionItems(string title, string URL)

        {

            this.title = title;

            this.URL = URL;

        }

 

        public string Title

        {

            get

            {

                return title;

            }

        }

 

        public string url

        {

            get

            {

                return URL;

            }

        }

    }

}

And here is the ascx file:

<%@ Control Language="c#" AutoEventWireup="false" Inherits="Dottext.Web.UI.Controls.Last10Module" %>

<h3>Recent Posts</h3>

    <asp:Repeater id="LastEntries" runat="server">

        <ItemTemplate>

            <div class="item">

                <font size="2">

                    <a href="<%# DataBinder.Eval(Container.DataItem, "url") %>">

                        <%# DataBinder.Eval(Container.DataItem, "Title") %>

                    </a>

                </font>

            </div>

        </ItemTemplate>

    </asp:Repeater>

 

The rest is installing the ascx into skin templates. Once you copy the file into Skin/Controls folder, add the necessary entries to PageTemplate.ascx.

 

"Popular Entries" module was pretty much the same as this one except the stored procedure is different as I need to read it from the Blog_Referrals and Blog_Content tables:

 

CREATE PROCEDURE blog_GetTop10byBlogId
@BlogId int
AS
Select Top 10 Sum(A.count) tCount, A.entryid, B.title, B.dateadded
From Blog_Referrals A, Blog_Content B
Where A.BlogId = @BlogId --param
AND A.entryid = B.[id]
Group By A.entryid, B.Title, B.dateadded
Order By tCount DESC

 

May not be the best piece of code but kept me busy during the weekend given my wife working at night shift at the hotel.

 

Have fun.


Advertisement


Comments for this entry:

# re: 2 new Modules for .Text

thanks , it works like a charm :)

by gokhan demir on  8/5/2007 6:18 AM
# re: 2 new Modules for .Text

Hi Gokhan,

If you are still using .Text as your blogging engine, I would strongly recommend to upgrade to Subtext and ASP.NET 2.0

by Gurkan Yeniceri on  8/7/2007 9:27 PM

Enter your comment here

Comments are moderated

*


*


 (not displayed)


 (will be a link on your name)

*
Bold Italic Underline Blockquote Hyperlink Hyperlink

 

Please add 5 and 1 and type the answer here:

Comment Preview:

 

Search



About me

Hi, my name is Gurkan Yeniceri. I am a software engineer with 8 years of experience in both public and private sectors. I have been generally writing about software engineering and Microsoft technologies since March 2005 on this site.
View Gurkan Yeniceri's profile on LinkedIn

Contact

If you would like to contact with me you can use the contact page here. I will try to respond it in a timely manner (I will try my best). You can also contact with me via Microsoft Live Messenger with the address gyeniceri {AT} hotmail {DOT} com.
If you are one of my Turkish readers, you may want to visit my Turkish blog here.

If you would like to read my site with an RSS reader like RSS Bandit, you may want to use to subscribe.

RSS 2.0

Advertisement


Bookmark this site

del.icio.us digg NewsVine YahooMyWeb Reddit Spurl TailRank BlinkList Furl Shadows blogmarks
    www.flickr.com
    This is a Flickr badge showing public photos from gurkanyeniceri. Make your own badge here.
    There are 128 posts and 56 comments on this site. Other sites also linked it 7 times.

    I am here

    my blogmap

    Advertisement