Skip to content

A little CS hack for the metablog API

Thu Mar 24 2005

Keith told me that CSBlogs was returning relative urls for its Metablog API implementation. After I installed it, I noticed the same thing - so I decided to hack it a little bit and find out what was going wrong. It turns out that the software is just doing what the guys at telligent are telling it to - thankfully I've got the code and I can poke around when I find little issues like this 😃

First, I added a call to the Globals class to return a formatted url with the application path intact. This was in Components.SiteUrlsData.cs:

public virtual string FormatUrl(string name, params object[] parameters)
{      	

    if(parameters == null)
        return Globals.FullPath(this.Paths[name]);

    else
        return Globals.FullPath(string.Format(Paths[name],parameters));
}

But wait! This causes the rss feed to show up with something silly like http: / /localhost/cshttp://localhost/cs/blog... for the links in the RSS and Atom feeds produced by CSBlogs. So, I tried it without the "HostPath" to see if I could get the same results. This was in Blogs.Components.BaseWeblogSyndicationHandler:

/// 
/// Appends http://Host:Port to all blog urls
/// 
protected override string BaseUrl
{
    get
    {
        return ""; //return Globals.HostPath(Context.Request.Url);
    }
}

That's it right? Nope, not if you have galleries enabled. One of the methods (that I know of 😃 uses the modified FormatUrl above to try and get a MapPath to a directory. You'll find out really quickly that MapPath doesn't like fully-qualified urls passed to it...I know I did. So, I modified one more line to make sure that I've got a relative path passed into the photo gallery. This was in Galleries.Components.Picture:

/// 
/// This static method gets the location of the picture cache directory, mapped on the local filesystem.
/// 
/// 
public static string CacheDirectory()
{
	Uri uri = new Uri(GalleryUrls.Instance().PictureCache);
	return CSContext.Current.Context.Server.MapPath(uri.AbsolutePath);
}

After that, everything seems to be running as normal. I don't know if I'd recommend doing something like this on your install, especially if things are working well enough for you. I just use this particular feature of the Metablog API quite often, so it bit me a lot.

: It looks like the trackback feature uses fully qualified urls as well as the rss/atom feeds. I'll post a fix tomorrow when I find out where the BaseUrl is set for the trackbacks.

: Found it :) I would've got it done last night, but I don't have the broadband yet. Any ways, like I thought it was just a removal of a baseUrl parameter (case notwithstanding). I found this in Blogs.Controls.TrackbackMarkup:

protected override void Render(HtmlTextWriter writer)
{
            
    if(IsValid)
    {
        string baseUrl = Globals.HostPath(Context.Request.Url);
	writer.WriteLine(tag,/*baseUrl+*/PermaLink,Title,/*baseUrl+*/PingUrl);
    }
}

[ Currently Playing : Rooster - Alice in Chains - Unplugged (6:40) ]

💾 May the source be with you. v3.2.1004