Convert Extensions v2.9 to v3.x

Topics: Business Logic Layer, Controls
Mar 8 at 3:19 PM
I am currently running a couple of instances of v2.9. I've been holding off on upgrading because I didn't have the time to convert my extensions. Now that I have time, I am in need of assistance in the conversion process. Most of the conversion makes sense but I am hung up on how to handle the event handler, both in the constructor, and the function itself. Help!

Here is the extension class I am using in 2.9. I realize I now have to compile the class into the web application which I have the ability to do.
using System;
using BlogEngine.Core.Web.Controls;
using BlogEngine.Core;
using System.Text;
using System.Web.UI;
using System.Web;

/// <summary>
/// Zusammenfassungsbeschreibung für LightBox
/// </summary>
[Extension("Adds support for using the LightBox js library for displaying images.", "0.1", "<a href=\"http://blog.data-worx.de\">René Kuss (http://blog.data-worx.de)</a>")]
public class LightBox
{
    #region Constants

    private const string defaultLightBoxPath = "LightBox"; 
    
    #endregion

    #region Constructors

    public LightBox()
    {
        BlogEngine.Core.Page.Serving += new EventHandler<ServingEventArgs>(Item_Serving);
        Post.Serving += new EventHandler<ServingEventArgs>(Item_Serving);
    } 
    
    #endregion

    #region Event Handlers

    void Item_Serving(object sender, ServingEventArgs e)
    {
        if (HttpContext.Current.CurrentHandler is BlogBasePage)
            (HttpContext.Current.CurrentHandler as BlogBasePage).LoadComplete += new EventHandler(basePage_LoadComplete);
    }

    void basePage_LoadComplete(object sender, EventArgs e)
    {
        BlogBasePage basePage = sender as BlogBasePage;
        this.PrepareLightBox(basePage);
    }

    #endregion

    #region Methods

    private void PrepareLightBox(BlogBasePage basePage)
    {
        LiteralControl lightBoxLinks = new LiteralControl();
        //ExtensionSettings settings = new ExtensionSettings("LightBox");
        lightBoxLinks.ID = "lblitctrl";
        if (basePage.Header.FindControl("lblitctrl") == null)
        {
            StringBuilder scriptLinks = new StringBuilder();
            string path = Utils.RelativeWebRoot + defaultLightBoxPath + "/";
            scriptLinks.Append("{0}{0}<!-- LightBox Extension Start -->{0}{0}");

            //Setting up javascript variables (removed from lightbox.js)
            scriptLinks.Append("<script language=\"JavaScript\">{0}<!--{0}{0}");
            scriptLinks.Append("var fileLoadingImage = \"{1}images/loading.gif\";{0}");
            scriptLinks.Append("var fileBottomNavCloseImage = \"{1}images/closelabel.gif\";{0}{0}");
            scriptLinks.Append("-->{0}</script>{0}{0}");

            //Referencing required files
            scriptLinks.Append("<script type=\"text/javascript\" src=\"{1}js/prototype.js\"></script>{0}");
            scriptLinks.Append("<script type=\"text/javascript\" src=\"{1}js/scriptaculous.js?load=effects\"></script>{0}");
            scriptLinks.Append("<script type=\"text/javascript\" src=\"{1}js/lightbox.js\"></script>{0}");
            scriptLinks.Append("<link rel=\"stylesheet\" href=\"{1}css/lightbox.css\" type=\"text/css\" media=\"screen\" />{0}");

            //Setting styles (removed from lightbox.css)
            scriptLinks.Append("{0}<style>{0}{0}");
            scriptLinks.Append("#prevLink, #nextLink {2} background: transparent url({1}images/blank.gif) no-repeat; /* Trick IE into showing hover */ {3}{0}");
            scriptLinks.Append("#prevLink:hover, #prevLink:visited:hover {2} background: url({1}images/prevlabel.gif) left 15% no-repeat; {3}{0}");
            scriptLinks.Append("#nextLink:hover, #nextLink:visited:hover {2} background: url({1}images/nextlabel.gif) right 15% no-repeat; {3}{0}");
            scriptLinks.Append("</style>");
            scriptLinks.Append("{0}{0}<!-- LightBox Extension Links End -->{0}{0}");
            lightBoxLinks.Text = string.Format(scriptLinks.ToString(), System.Environment.NewLine, path, "{", "}");
            basePage.Header.Controls.Add(lightBoxLinks);
        }
    }

    #endregion
}
Coordinator
Mar 8 at 8:34 PM
So this code doesn't compile? Events not firing? You forgot to mention issue you having.
Mar 8 at 8:59 PM
It does not compile. I'll post specifics when I get home tonight but it had to do with (Item_Serving) or the Post.Serving. I am thinking a changed or missing using statement?
Coordinator
Mar 8 at 9:14 PM
I added "LightBox.cs" to custom/extensions folder and copy/pasted this code, it compiles and runs just fine.
Mar 9 at 5:05 PM
Ok, perhaps the code base I had at home, using VS2015, must have been corrupt by my tinkering around. I downloaded the entire solution on my work PC, and using VS2013, it seems to compile just fine. Although, I see I was not placing my class in the same project location as custom\extensions.

Either way, thanks for sticking with my question and offering help.
Mar 9 at 5:36 PM
Edited Mar 9 at 5:39 PM
Compiles. javascript is now firing properly. Except when I inject Highslide or Lightbox metadata into my post, the OnClick event is being stripped out.

This, from my post source..
onclick="return hs.expand(this, { autoplay:true, slideshowGroup: 'aaa3ec0b-bc10-46c2-9b98-8dfb829e90b6' })" 
is being stripped out when I click save post. (corrected)
<p>This post is just an example using Post List widget with image in the post body.</p>
<p><a class="highslide" onclick="return hs.expand(this, { autoplay:true, slideshowGroup: 'aaa3ec0b-bc10-46c2-9b98-8dfb829e90b6' })"  href="/image.axd?picture=/350x150.png"><img title="Click to enlarge" src="/image.axd?picture=/350x150.png" alt="Highslide JS" /></a></p>
<div class="highslide-heading">Testing Testing 1 2 3</div>
<div class="highslide-caption">Test 1</div>
<div class="hsbuilder-caption">Test 2</div>
<p>Post List widget should find first image in the post body and display it in the post list when this option selected in the widget admin.</p>