Extension Manager

What is Extension Manager

Extension Manager is a component in the BlogEngine that:
  1. Provides graphical interface to view and configure extensions.
  2. Enables input and management of extensions data (settings) through customizable form.
  3. Let extensions save and retrieve data (settings) to and from data storage through API calls.
Extension Manager

Some of the functionality provided out of the box – your extension will be listed in the admin console, source code will be accessible by clicking “view” link and extension can be disabled or enabled with a click of a button. Other functions require extension author to write code.

Why do you need Extension Manager

You might not need it at all. Again, your extension will pop up in the Admin under Extensions tab and blogger will be able to turn it on/off, see information (that you supply in the attribute tag) and look at the code. That Manager will do automatically. But there are two scenarios when you might really need it: you want to collect user input and you want to be able save and get back some data. Sure, you can implement this on your own, but it would probably be more intensive than writing extension itself. With extension manager, most tasks will take few lines of code.

Collecting user input

You want to write an extension that will block "bad" words in the comment. Obviously, you want blogger to decide words to be blocked, so you have to provide user input form to enter these words and then save them for use in your extension. The code below, as simple as it is, does it all.

using System;
using System.Data;
using BlogEngine.Core;
using BlogEngine.Core.Web.Controls;
[Extension("Bad words", "1.0", "<a href=\"http://me.net\">Me</a>")]
public class BadWords
    public BadWords()
        Comment.Serving += new EventHandler<ServingEventArgs>(Post_CommentServing);
        ExtensionSettings settings = new ExtensionSettings("BadWords");
        settings.AddValue("Word", "badword");
    private void Post_CommentServing(object sender, ServingEventArgs e)
        string body = e.Body;
        DataTable table = ExtensionManager.GetSettings("BadWords").GetDataTable();
        foreach (DataRow row in table.Rows)
            body = body.Replace((string)row["Word"], "***");
        e.Body = body;

If you copy this code in the class named BadWords.cs and drop this class into ~/app_code/extensions folder, when run application, Extension Manager will generate input form for your extension. This form will be available by clicking "settings" link in the extension list in the admin/extensions section. You tell Manager that you need input form by creating settings object and importing it into manager. In the example Extension Manager knows that you want text box for parameter named "Word" and by default it assumes that you want lots of words, so it will put "Add" button and build updatable grid so user can enter, update and delete words. When someone making comment on the blog, extension will run on the comment serving event, get all saved by blogger words and make sure they will be replaced in the comment with asterisks.

Input Form

In this case, settings object is basically a data table. You can add columns and rows as you wish. For example, if you need more than one parameter (column), you would add another one:

Manager will add another input box for second parameter. To add couple of values (rows):
settings.AddValues(new string[] { "badword", "***" });
settings.AddValues(new string[] { "anotherone", "###" });
Number of values in the string array has to match number of parameters (columns). There are number of overloads in the AddParameter method:
public void AddParameter(string name, string label, int maxLength, bool required, bool keyfield)
name - name of the parameter
label - text on the label next to input box (default same as name)
maxLength - maximum input value length (100)
required - if true, parameter is required and EM won't let to save null for this parameter (false)
keyfield - EM will insure that all values for this parameter are unique (false)

Last edited Mar 7, 2009 at 10:38 PM by BenAmada, version 1


dbprogaz Aug 25, 2011 at 8:25 PM 
I used BBCode as a model to adapt this extension to BE2.5 The settings have been broken out into a seperate functions, but implementing this code was pretty easy. I also added two more replacements to match the word in lower or upper case:

string word = row["Word"].ToString();
string replace = row["Replacement"].ToString();
body = body.Replace(word, replace );
body = body.Replace(word.ToLower(), replace.ToLower());
body = body.Replace(word.ToUpper(), replace.ToUpper());

fstanek Feb 26, 2010 at 6:08 AM 

settings.AddParameter("Theme", "Theme", 20, true, false, ParameterType.DropDown);
settings.AddValue("Theme", new string[] { "red", "white", "blackglass", "clean" }, "red");

BizTron Jan 13, 2010 at 6:40 PM 
Can I get a multi-line textbox that allows newlines? I don't see a current way?

BizTron Jan 13, 2010 at 6:37 PM 
How can I add a drop down list, as in : "ParameterType.DropDown"?
I've tried "ExtensionSettings.AddValue(string parameterName, StringCollection items, string selected)"
after "ExtensionSettings.AddParameter(parameterName, label, maxLength, required, keyfield, ParameterType parType)"