GetThemeWidgetContainerVirtualPath() public static method

Returns the virtual path of where a theme's widget container would expect to be located.
public static GetThemeWidgetContainerVirtualPath ( bool existenceCheck ) : string
existenceCheck bool /// When true, the path to the theme folder to check for the WidgetContainer existence /// is returned. When false, the path to the control that will be loaded is returned. /// If it's a Razor theme, the path will be RazorHost instead of the actual theme folder /// name. ///
return string
Ejemplo n.º 1
0
        /// <summary>
        /// Raises the <see cref="E:System.Web.UI.Control.Load"></see> event.
        /// </summary>
        /// <param name="e">
        /// The <see cref="T:System.EventArgs"></see> object that contains the event data.
        /// </param>
        protected override void OnLoad(EventArgs e)
        {
            base.OnLoad(e);

            var zone = this.XmlDocument.SelectNodes("//widget");

            if (zone == null)
            {
                return;
            }

            // This is for compatibility with older themes that do not have a WidgetContainer control.
            var widgetContainerExists      = WidgetContainer.DoesThemeWidgetContainerExist();
            var widgetContainerVirtualPath = WidgetContainer.GetThemeWidgetContainerVirtualPath();

            foreach (XmlNode widget in zone)
            {
                var fileName = string.Format("{0}widgets/{1}/widget.ascx", Utils.RelativeWebRoot, widget.InnerText);
                try
                {
                    var control = (WidgetBase)this.Page.LoadControl(fileName);
                    if (widget.Attributes != null)
                    {
                        control.WidgetId  = new Guid(widget.Attributes["id"].InnerText);
                        control.Title     = widget.Attributes["title"].InnerText;
                        control.ShowTitle = control.IsEditable
                                                ? bool.Parse(widget.Attributes["showTitle"].InnerText)
                                                : control.DisplayHeader;
                    }

                    control.ID   = control.WidgetId.ToString().Replace("-", string.Empty);
                    control.Zone = this.zoneName;

                    control.LoadWidget();

                    // This will return the WidgetContainer with the control in it.
                    var widgetContainer = WidgetContainer.GetWidgetContainer(control, widgetContainerExists, widgetContainerVirtualPath);
                    this.Controls.Add(widgetContainer);
                }
                catch (Exception ex)
                {
                    var lit = new Literal
                    {
                        Text = string.Format("<p style=\"color:red\">Widget {0} not found.<p>", widget.InnerText)
                    };
                    lit.Text += ex.Message;
                    if (widget.Attributes != null)
                    {
                        lit.Text +=
                            string.Format(
                                "<a class=\"delete\" href=\"#\" onclick=\"BlogEngine.widgetAdmin.removeWidget('{0}');return false\" title=\"{1} widget\">X</a>",
                                widget.Attributes["id"].InnerText,
                                labels.delete);
                    }

                    this.Controls.Add(lit);
                }
            }
        }
        /// <summary>
        /// Raises the <see cref="E:System.Web.UI.Control.Load"></see> event.
        /// </summary>
        /// <param name="e">
        /// The <see cref="T:System.EventArgs"></see> object that contains the event data.
        /// </param>
        protected override void OnLoad(EventArgs e)
        {
            base.OnLoad(e);

            XmlNodeList zone = null;

            if (this.XmlDocument != null)
            {
                zone = this.XmlDocument.SelectNodes("//widget");
            }

            if (zone == null)
            {
                return;
            }

            // This is for compatibility with older themes that do not have a WidgetContainer control.
            var widgetContainerExists      = WidgetContainer.DoesThemeWidgetContainerExist(true);
            var widgetContainerVirtualPath = WidgetContainer.GetThemeWidgetContainerVirtualPath(false);

            foreach (XmlNode widget in zone)
            {
                var fileName = string.Format("{0}Custom/Widgets/{1}/widget.ascx", Utils.ApplicationRelativeWebRoot, widget.InnerText);
                try
                {
                    //Mod RonC Added this conditional so that the admin widget isn't loaded for non authenticated
                    //         visitors.  This shaves 1 sec off of a cold server first page fetch
                    //         for a non admin visitor.
                    bool isAdminWidget = (fileName.ToLower().IndexOf("/administration/widget.ascx") >= 0);
                    if (!isAdminWidget || (isAdminWidget && Security.IsAuthenticated))
                    {
                        var control = (WidgetBase)this.Page.LoadControl(fileName);
                        if (widget.Attributes != null)
                        {
                            control.WidgetId  = new Guid(widget.Attributes["id"].InnerText);
                            control.Title     = widget.Attributes["title"].InnerText;
                            control.ShowTitle = control.IsEditable
                                                                                                        ? bool.Parse(widget.Attributes["showTitle"].InnerText)
                                                                                                        : control.DisplayHeader;
                        }

                        control.ID   = control.WidgetId.ToString().Replace("-", string.Empty);
                        control.Zone = this.zoneName;

                        control.LoadWidget();

                        // This will return the WidgetContainer with the control in it.
                        var widgetContainer = WidgetContainer.GetWidgetContainer(control, widgetContainerExists, widgetContainerVirtualPath);
                        this.Controls.Add(widgetContainer);
                    }
                }
                catch (Exception ex)
                {
                    var lit = new Literal
                    {
                        Text = string.Format("<p style=\"color:red\">Widget {0} not found.<p>", widget.InnerText)
                    };
                    lit.Text += ex.Message;
                    if (widget.Attributes != null)
                    {
                        lit.Text +=
                            string.Format(
                                "<a class=\"delete\" href=\"#\" onclick=\"BlogEngine.widgetAdmin.removeWidget('{0}');return false\" title=\"{1} widget\">X</a>",
                                widget.Attributes["id"].InnerText,
                                labels.delete);
                    }

                    this.Controls.Add(lit);
                }
            }
        }