Extension Manager 101

As APIs for Extension Manager finalized, I decided to put together a few simple examples explaining how you can take advantage of them. Consider situation when you have an extension that uses couple user specific variables. For instance, Akismet extension by Justin Etheredge needs to know API key and URL that specific for each blogger who uses extension. Currently, blogger has to enter this information by hand in the source code or extension author has to craft his own admin UI. Chunk of code below shows how Extension Manager can make life easier. All you need is to specify parameters you want blogger to be able to maintain and let Manager know about it.

static protected ExtensionSettings _settings = null;
// Constructor
public AkismetExtension()
{
    // Add the event handler for the CommentAdded event
    Post.AddingComment += new EventHandler<CancelEventArgs>(Post_AddingComment);
    ExtensionSettings settings = new ExtensionSettings("AkismetExtension");
    settings.AddParameter("apiKey", "API Key");
    settings.AddParameter("blogUrl", "Blog URL");
    settings.IsScalar = true;
    ExtensionManager.ImportSettings(settings);
    _settings = ExtensionManager.GetSettings("AkismetExtension");
}

Once you add code above to your extension, if you go to admin panel and look at “Extensions” tab, you’ll see “Edit” link next to your extension in the list.

aksm-1.png

Clicking this link will bring screen shown below, where user can enter and save information your extension needs to know.

aksm-2.png

To use this information in your extension, you pull it out of Extension Manager as in this code:

string apiKey = _settings.GetSingleValue("apiKey");
string blogUrl = _settings.GetSingleValue("blogUrl");
Akismet api = new Akismet(apiKey, blogUrl, "BlogEngine.net 1.2");

In short, after upgrading to BlogEngine 1.3 you’ll be able to add admin functionality to your extension in a few minutes with few simple lines of code. Extension Manager has many more functions, but basic stepsare always the same: you define your parameters and let Manager take care ofthe rest.

About RTUR.NET

This site is all about developing web applications with focus on designing and building open source blogging solutions. Technologies include ASP.NET Core, C#, Angular, JavaScript and more.