/// <summary>
        /// Initializes a new instance of the <see cref="Html5ModuleTokenReplace"/> class.
        /// </summary>
        /// <param name="page"></param>
        /// <param name="html5File"></param>
        /// <param name="moduleContext"></param>
        /// <param name="moduleActions"></param>
        public Html5ModuleTokenReplace(Page page, string html5File, ModuleInstanceContext moduleContext, ModuleActionCollection moduleActions)
            : base(page)
        {
            this.AccessingUser  = moduleContext.PortalSettings.UserInfo;
            this.DebugMessages  = Personalization.GetUserMode() != Entities.Portals.PortalSettings.Mode.View;
            this.ModuleId       = moduleContext.ModuleId;
            this.PortalSettings = moduleContext.PortalSettings;

            this.PropertySource["moduleaction"]  = new ModuleActionsPropertyAccess(moduleContext, moduleActions);
            this.PropertySource["resx"]          = new ModuleLocalizationPropertyAccess(moduleContext, html5File);
            this.PropertySource["modulecontext"] = new ModuleContextPropertyAccess(moduleContext);
            this.PropertySource["request"]       = new RequestPropertyAccess(page.Request);

            // DNN-7750
            var bizClass = moduleContext.Configuration.DesktopModule.BusinessControllerClass;

            var businessController = this.GetBusinessController(bizClass);

            if (businessController != null)
            {
                var tokens = businessController.GetTokens(page, moduleContext);
                foreach (var token in tokens)
                {
                    this.PropertySource.Add(token.Key, token.Value);
                }
            }
        }
Exemple #2
0
        /// -----------------------------------------------------------------------------
        /// <summary>
        /// DisplayControl determines whether the associated Action control should be
        /// displayed.
        /// </summary>
        /// <returns></returns>
        /// -----------------------------------------------------------------------------
        public bool DisplayControl(DNNNodeCollection objNodes)
        {
            if (objNodes != null && objNodes.Count > 0 && Personalization.GetUserMode() != PortalSettings.Mode.View)
            {
                DNNNode objRootNode = objNodes[0];
                if (objRootNode.HasNodes && objRootNode.DNNNodes.Count == 0)
                {
                    // if has pending node then display control
                    return(true);
                }
                else if (objRootNode.DNNNodes.Count > 0)
                {
                    // verify that at least one child is not a break
                    foreach (DNNNode childNode in objRootNode.DNNNodes)
                    {
                        if (!childNode.IsBreak)
                        {
                            // Found a child so make Visible
                            return(true);
                        }
                    }
                }
            }

            return(false);
        }
        /// -----------------------------------------------------------------------------
        /// <summary>
        ///   ModuleAction_Click handles all ModuleAction events raised from the action menu.
        /// </summary>
        /// <remarks>
        /// </remarks>
        /// -----------------------------------------------------------------------------
        private void ModuleAction_Click(object sender, ActionEventArgs e)
        {
            try
            {
                if (e.Action.CommandArgument == "publish")
                {
                    // verify security
                    if (this.IsEditable && Personalization.GetUserMode() == PortalSettings.Mode.Edit)
                    {
                        // get content
                        var          objHTML    = new HtmlTextController();
                        HtmlTextInfo objContent = objHTML.GetTopHtmlText(this.ModuleId, false, this.WorkflowID);

                        var objWorkflow = new WorkflowStateController();
                        if (objContent.StateID == objWorkflow.GetFirstWorkflowStateID(this.WorkflowID))
                        {
                            // publish content
                            objContent.StateID = objWorkflow.GetNextWorkflowStateID(objContent.WorkflowID, objContent.StateID);

                            // save the content
                            objHTML.UpdateHtmlText(objContent, objHTML.GetMaximumVersionHistory(this.PortalId));

                            // refresh page
                            this.Response.Redirect(this._navigationManager.NavigateURL(), true);
                        }
                    }
                }
            }
            catch (Exception exc)
            {
                Exceptions.ProcessModuleLoadException(this, exc);
            }
        }
Exemple #4
0
        /// ----------------------------------------------------------------------------
        /// <summary>
        /// Gets a flag that indicates whether the Module Content should be displayed.
        /// </summary>
        /// <returns>A Boolean.</returns>
        private bool DisplayContent()
        {
            // module content visibility options
            var content = Personalization.GetUserMode() != PortalSettings.Mode.Layout;

            if (this.Page.Request.QueryString["content"] != null)
            {
                switch (this.Page.Request.QueryString["Content"].ToLowerInvariant())
                {
                case "1":
                case "true":
                    content = true;
                    break;

                case "0":
                case "false":
                    content = false;
                    break;
                }
            }

            if (Globals.IsAdminControl())
            {
                content = true;
            }

            return(content);
        }
Exemple #5
0
        private Containers.Container LoadNoContainer(ModuleInfo module)
        {
            string noContainerSrc = "[G]" + SkinController.RootContainer + "/_default/No Container.ascx";

            Containers.Container container = null;

            // if the module specifies that no container should be used
            if (module.DisplayTitle == false)
            {
                // always display container if the current user is the administrator or the module is being used in an admin case
                bool displayTitle = ModulePermissionController.CanEditModuleContent(module) || Globals.IsAdminSkin();

                // unless the administrator is in view mode
                if (displayTitle)
                {
                    displayTitle = Personalization.GetUserMode() != PortalSettings.Mode.View;
                }

                if (displayTitle == false)
                {
                    container = this.LoadContainerByPath(SkinController.FormatSkinSrc(noContainerSrc, this.PortalSettings));
                }
            }

            return(container);
        }
Exemple #6
0
        private bool CanEditModule()
        {
            var canEdit = false;

            if (this.ModuleControl != null && this.ModuleControl.ModuleContext.ModuleId > Null.NullInteger)
            {
                canEdit = (Personalization.GetUserMode() == PortalSettings.Mode.Edit) && TabPermissionController.CanAdminPage() && !Globals.IsAdminControl();
            }

            return(canEdit);
        }
Exemple #7
0
        public override bool Visible()
        {
            var portalSettings = PortalSettings.Current;

            if (portalSettings == null)
            {
                return(false);
            }

            return(Personalization.GetUserMode() == PortalSettings.Mode.Edit &&
                   ControlBarController.Instance.GetCategoryDesktopModules(portalSettings.PortalId, "All", string.Empty).Any());
        }
Exemple #8
0
        private IDictionary <string, object> GetConfigration(PortalSettings portalSettings)
        {
            var settings          = new Dictionary <string, object>();
            var user              = portalSettings.UserInfo;
            var portalId          = portalSettings.PortalId;
            var preferredTimeZone = TimeZoneHelper.GetPreferredTimeZone(user.Profile.PreferredTimeZone);

            var menuStructure = PersonaBarController.Instance.GetMenu(portalSettings, user);

            settings.Add("applicationPath", Globals.ApplicationPath);
            settings.Add("buildNumber", Host.CrmVersion.ToString(CultureInfo.InvariantCulture));
            settings.Add("userId", user.UserID);
            settings.Add("avatarUrl", Globals.ResolveUrl(Utilities.GetProfileAvatar(user)));
            settings.Add("culture", Thread.CurrentThread.CurrentUICulture.Name);
            settings.Add("logOff", this.NavigationManager.NavigateURL("Logoff"));
            settings.Add("visible", this.Visible);
            settings.Add("userMode", Personalization.GetUserMode().ToString());
            settings.Add("userSettings", PersonaBarUserSettingsController.Instance.GetPersonaBarUserSettings());
            settings.Add("menuStructure", JObject.FromObject(menuStructure));
            settings.Add("sku", DotNetNukeContext.Current.Application.SKU);
            settings.Add("debugMode", HttpContext.Current != null && HttpContext.Current.IsDebuggingEnabled);
            settings.Add("portalId", portalId);
            settings.Add("preferredTimeZone", preferredTimeZone);

            if (!settings.ContainsKey("isAdmin"))
            {
                settings.Add("isAdmin", user.IsInRole(portalSettings.AdministratorRoleName));
            }

            if (!settings.ContainsKey("isHost"))
            {
                settings.Add("isHost", user.IsSuperUser);
            }

            var customModules = new List <string>()
            {
                "serversummary"
            };

            settings.Add("customModules", customModules);

            settings.Add("disableEditBar", Host.DisableEditBar);

            var customPersonaBarThemePath   = HostingEnvironment.MapPath("~/Portals/_default/PersonaBarTheme.css");
            var customPersonaBarThemeExists = File.Exists(customPersonaBarThemePath);

            settings.Add("personaBarTheme", customPersonaBarThemeExists);

            return(settings);
        }
Exemple #9
0
        private bool IsVisible(SecurityAccessLevel security)
        {
            bool isVisible = false;

            if (ModulePermissionController.HasModuleAccess(security, Null.NullString, this.ModuleControl.ModuleContext.Configuration))
            {
                if ((this.RequireEditMode != true || Personalization.GetUserMode() == PortalSettings.Mode.Edit) || (security == SecurityAccessLevel.Anonymous || security == SecurityAccessLevel.View))
                {
                    isVisible = true;
                }
            }

            return(isVisible);
        }
Exemple #10
0
        /// -----------------------------------------------------------------------------
        /// <summary>
        /// Gets a flag that indicates whether the Module is in View Mode.
        /// </summary>
        /// <returns>A Boolean.</returns>
        internal static bool IsViewMode(ModuleInfo moduleInfo, PortalSettings settings)
        {
            bool viewMode;

            if (ModulePermissionController.HasModuleAccess(SecurityAccessLevel.ViewPermissions, Null.NullString,
                                                           moduleInfo))
            {
                viewMode = false;
            }
            else
            {
                viewMode = !ModulePermissionController.HasModuleAccess(SecurityAccessLevel.Edit, Null.NullString,
                                                                       moduleInfo);
            }

            return(viewMode || Personalization.GetUserMode() == PortalSettings.Mode.View);
        }
Exemple #11
0
        protected override void Render(HtmlTextWriter writer)
        {
            if (Personalization.GetUserMode() == PortalSettings.Mode.Edit)
            {
                var editClass = "dnnEditState";

                var bodyClass = this.Body.Attributes["class"];
                if (!string.IsNullOrEmpty(bodyClass))
                {
                    this.Body.Attributes["class"] = string.Format("{0} {1}", bodyClass, editClass);
                }
                else
                {
                    this.Body.Attributes["class"] = editClass;
                }
            }

            base.Render(writer);
        }
Exemple #12
0
        protected override void OnInit(EventArgs e)
        {
            base.OnInit(e);

            if (GetCurrent(this.Page) != null)
            {
                throw new Exception("Instance has already initialized");
            }

            this.AutoSetUserMode();

            var user = this.PortalSettings.UserInfo;

            if (user.UserID > 0)
            {
                ClientAPI.RegisterClientVariable(this.Page, "dnn_current_userid", this.PortalSettings.UserInfo.UserID.ToString(), true);
            }

            if (Personalization.GetUserMode() != PortalSettings.Mode.Edit ||
                !this.IsPageEditor() ||
                EditBarController.Instance.GetMenuItems().Count == 0)
            {
                this.Parent.Controls.Remove(this);
                return;
            }

            this.RegisterClientResources();

            this.RegisterEditBarResources();

            this.Page.Items.Add("ContentEditorManager", this);

            // if there is pending work cookie, then reset it
            this.CheckPendingData();

            // if there is callback data cookie, then process the module for drag.
            this.CheckCallbackData();

            this.EnsureChildControls();
        }
        /// -----------------------------------------------------------------------------
        /// <summary>
        ///   lblContent_UpdateLabel allows for inline editing of content.
        /// </summary>
        /// <remarks>
        /// </remarks>
        /// -----------------------------------------------------------------------------
        private void lblContent_UpdateLabel(object source, DNNLabelEditEventArgs e)
        {
            try
            {
                // verify security
                if (!PortalSecurity.Instance.InputFilter(e.Text, PortalSecurity.FilterFlag.NoScripting).Equals(e.Text))
                {
                    throw new SecurityException();
                }
                else if (this.EditorEnabled && this.IsEditable && Personalization.GetUserMode() == PortalSettings.Mode.Edit)
                {
                    // get content
                    var          objHTML     = new HtmlTextController();
                    var          objWorkflow = new WorkflowStateController();
                    HtmlTextInfo objContent  = objHTML.GetTopHtmlText(this.ModuleId, false, this.WorkflowID);
                    if (objContent == null)
                    {
                        objContent        = new HtmlTextInfo();
                        objContent.ItemID = -1;
                    }

                    // set content attributes
                    objContent.ModuleID   = this.ModuleId;
                    objContent.Content    = this.Server.HtmlEncode(e.Text);
                    objContent.WorkflowID = this.WorkflowID;
                    objContent.StateID    = objWorkflow.GetFirstWorkflowStateID(this.WorkflowID);

                    // save the content
                    objHTML.UpdateHtmlText(objContent, objHTML.GetMaximumVersionHistory(this.PortalId));
                }
                else
                {
                    throw new SecurityException();
                }
            }
            catch (Exception exc)
            {
                Exceptions.ProcessModuleLoadException(this, exc);
            }
        }
Exemple #14
0
        /// -----------------------------------------------------------------------------
        /// <summary>
        /// IsVisible determines whether the action control is Visible.
        /// </summary>
        /// <param name="action">The Action.</param>
        /// <returns></returns>
        /// -----------------------------------------------------------------------------
        public bool IsVisible(ModuleAction action)
        {
            bool _IsVisible = false;

            if (action.Visible && ModulePermissionController.HasModuleAccess(action.Secure, Null.NullString, this.ModuleContext.Configuration))
            {
                if ((Personalization.GetUserMode() == PortalSettings.Mode.Edit) || (action.Secure == SecurityAccessLevel.Anonymous || action.Secure == SecurityAccessLevel.View))
                {
                    _IsVisible = true;
                }
                else
                {
                    _IsVisible = false;
                }
            }
            else
            {
                _IsVisible = false;
            }

            return(_IsVisible);
        }
Exemple #15
0
        private void AutoSetUserMode()
        {
            int    tabId    = this.PortalSettings.ActiveTab.TabID;
            int    portalId = PortalSettings.Current.PortalId;
            string pageId   = string.Format("{0}:{1}", portalId, tabId);

            HttpCookie cookie = this.Request.Cookies["StayInEditMode"];

            if (cookie != null && cookie.Value == "YES")
            {
                if (Personalization.GetUserMode() != PortalSettings.Mode.Edit)
                {
                    this.SetUserMode("EDIT");
                    this.SetLastPageHistory(pageId);
                    this.Response.Redirect(this.Request.RawUrl, true);
                }

                return;
            }

            string lastPageId          = this.GetLastPageHistory();
            var    isShowAsCustomError = this.Request.QueryString.AllKeys.Contains("aspxerrorpath");

            if (lastPageId != pageId && !isShowAsCustomError)
            {
                // navigate between pages
                if (Personalization.GetUserMode() != PortalSettings.Mode.View)
                {
                    this.SetUserMode("VIEW");
                    this.SetLastPageHistory(pageId);
                    this.Response.Redirect(this.Request.RawUrl, true);
                }
            }

            if (!isShowAsCustomError)
            {
                this.SetLastPageHistory(pageId);
            }
        }
Exemple #16
0
        private void DisplayAction(ModuleAction action)
        {
            if (action.CommandName == ModuleActionType.PrintModule)
            {
                if (action.Visible)
                {
                    if ((Personalization.GetUserMode() == PortalSettings.Mode.Edit) || (action.Secure == SecurityAccessLevel.Anonymous || action.Secure == SecurityAccessLevel.View))
                    {
                        if (this.ModuleContext.Configuration.DisplayPrint)
                        {
                            var ModuleActionIcon = new ImageButton();
                            if (!string.IsNullOrEmpty(this.PrintIcon))
                            {
                                ModuleActionIcon.ImageUrl = this.ModuleContext.Configuration.ContainerPath.Substring(0, this.ModuleContext.Configuration.ContainerPath.LastIndexOf("/") + 1) + this.PrintIcon;
                            }
                            else
                            {
                                ModuleActionIcon.ImageUrl = "~/images/" + action.Icon;
                            }

                            ModuleActionIcon.ToolTip          = action.Title;
                            ModuleActionIcon.ID               = "ico" + action.ID;
                            ModuleActionIcon.CausesValidation = false;

                            ModuleActionIcon.Click += this.IconAction_Click;

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

            foreach (ModuleAction subAction in action.Actions)
            {
                this.DisplayAction(subAction);
            }
        }
        /// -----------------------------------------------------------------------------
        /// <summary>
        ///   FormatHtmlText formats HtmlText content for display in the browser.
        /// </summary>
        /// <remarks>
        /// </remarks>
        /// <param name="moduleId">The ModuleID.</param>
        /// <param name = "content">The HtmlText Content.</param>
        /// <param name = "settings">Module Settings.</param>
        /// <param name="portalSettings">The Portal Settings.</param>
        /// <param name="page">The Page Instance.</param>
        /// <returns></returns>
        public static string FormatHtmlText(int moduleId, string content, HtmlModuleSettings settings, PortalSettings portalSettings, Page page)
        {
            // Html decode content
            content = HttpUtility.HtmlDecode(content);

            // token replace
            if (settings.ReplaceTokens)
            {
                var tr = new HtmlTokenReplace(page)
                {
                    AccessingUser  = UserController.Instance.GetCurrentUserInfo(),
                    DebugMessages  = Personalization.GetUserMode() != PortalSettings.Mode.View,
                    ModuleId       = moduleId,
                    PortalSettings = portalSettings,
                };
                content = tr.ReplaceEnvironmentTokens(content);
            }

            // manage relative paths
            content = ManageRelativePaths(content, portalSettings.HomeDirectory, "src", portalSettings.PortalId);
            content = ManageRelativePaths(content, portalSettings.HomeDirectory, "background", portalSettings.PortalId);

            return(content);
        }
 public override bool Visible()
 {
     return(Personalization.GetUserMode() == PortalSettings.Mode.Edit);
 }
 public override bool Visible()
 {
     return(Personalization.GetUserMode() == PortalSettings.Mode.Edit &&
            Host.ControlPanel.EndsWith("PersonaBarContainer.ascx", StringComparison.InvariantCultureIgnoreCase));
 }
Exemple #20
0
        /// -----------------------------------------------------------------------------
        /// <summary>
        /// InjectModule injects a Module (and its container) into the Pane.
        /// </summary>
        /// <param name="module">The Module.</param>
        /// -----------------------------------------------------------------------------
        public void InjectModule(ModuleInfo module)
        {
            this._containerWrapperControl = new HtmlGenericControl("div");
            this.PaneControl.Controls.Add(this._containerWrapperControl);

            // inject module classes
            string classFormatString   = "DnnModule DnnModule-{0} DnnModule-{1}";
            string sanitizedModuleName = Null.NullString;

            if (!string.IsNullOrEmpty(module.DesktopModule.ModuleName))
            {
                sanitizedModuleName = Globals.CreateValidClass(module.DesktopModule.ModuleName, false);
            }

            if (this.IsVesionableModule(module))
            {
                classFormatString += " DnnVersionableControl";
            }

            this._containerWrapperControl.Attributes["class"] = string.Format(classFormatString, sanitizedModuleName, module.ModuleID);

            try
            {
                if (!Globals.IsAdminControl() && (this.PortalSettings.InjectModuleHyperLink || Personalization.GetUserMode() != PortalSettings.Mode.View))
                {
                    this._containerWrapperControl.Controls.Add(new LiteralControl("<a name=\"" + module.ModuleID + "\"></a>"));
                }

                // Load container control
                Containers.Container container = this.LoadModuleContainer(module);

                // Add Container to Dictionary
                this.Containers.Add(container.ID, container);

                // hide anything of type ActionsMenu - as we're injecting our own menu now.
                container.InjectActionMenu = container.Controls.OfType <ActionBase>().Count() == 0;
                if (!container.InjectActionMenu)
                {
                    foreach (var actionControl in container.Controls.OfType <IActionControl>())
                    {
                        if (actionControl is ActionsMenu)
                        {
                            Control control = actionControl as Control;
                            if (control != null)
                            {
                                control.Visible            = false;
                                container.InjectActionMenu = true;
                            }
                        }
                    }
                }

                if (Globals.IsLayoutMode() && Globals.IsAdminControl() == false)
                {
                    // provide Drag-N-Drop capabilities
                    var     dragDropContainer = new Panel();
                    Control title             = container.FindControl("dnnTitle");

                    // Assume that the title control is named dnnTitle.  If this becomes an issue we could loop through the controls looking for the title type of skin object
                    dragDropContainer.ID = container.ID + "_DD";
                    this._containerWrapperControl.Controls.Add(dragDropContainer);

                    // inject the container into the page pane - this triggers the Pre_Init() event for the user control
                    dragDropContainer.Controls.Add(container);

                    if (title != null)
                    {
                        if (title.Controls.Count > 0)
                        {
                            title = title.Controls[0];
                        }
                    }

                    // enable drag and drop
                    if (title != null)
                    {
                        // The title ID is actually the first child so we need to make sure at least one child exists
                        DNNClientAPI.EnableContainerDragAndDrop(title, dragDropContainer, module.ModuleID);
                        ClientAPI.RegisterPostBackEventHandler(this.PaneControl, "MoveToPane", this.ModuleMoveToPanePostBack, false);
                    }
                }
                else
                {
                    this._containerWrapperControl.Controls.Add(container);
                    if (Globals.IsAdminControl())
                    {
                        this._containerWrapperControl.Attributes["class"] += " DnnModule-Admin";
                    }
                }

                // Attach Module to Container
                container.SetModuleConfiguration(module);

                // display collapsible page panes
                if (this.PaneControl.Visible == false)
                {
                    this.PaneControl.Visible = true;
                }
            }
            catch (ThreadAbortException)
            {
                // Response.Redirect may called in module control's OnInit method, so it will cause ThreadAbortException, no need any action here.
            }
            catch (Exception exc)
            {
                var lex = new ModuleLoadException(string.Format(Skin.MODULEADD_ERROR, this.PaneControl.ID), exc);
                if (TabPermissionController.CanAdminPage())
                {
                    // only display the error to administrators
                    this._containerWrapperControl.Controls.Add(new ErrorContainer(this.PortalSettings, Skin.MODULELOAD_ERROR, lex).Container);
                }

                Exceptions.LogException(exc);
                throw lex;
            }
        }
        /// -----------------------------------------------------------------------------
        /// <summary>
        ///   Page_Load runs when the control is loaded.
        /// </summary>
        /// <remarks>
        /// </remarks>
        /// -----------------------------------------------------------------------------
        protected override void OnLoad(EventArgs e)
        {
            base.OnLoad(e);
            try
            {
                var objHTML = new HtmlTextController();

                // edit in place
                if (this.EditorEnabled && this.IsEditable && Personalization.GetUserMode() == PortalSettings.Mode.Edit)
                {
                    this.EditorEnabled = true;
                }
                else
                {
                    this.EditorEnabled = false;
                }

                // get content
                HtmlTextInfo htmlTextInfo  = null;
                string       contentString = string.Empty;

                htmlTextInfo = objHTML.GetTopHtmlText(this.ModuleId, !this.IsEditable, this.WorkflowID);

                if (htmlTextInfo != null)
                {
                    // don't decode yet (this is done in FormatHtmlText)
                    contentString = htmlTextInfo.Content;
                }
                else
                {
                    // get default content from resource file
                    if (Personalization.GetUserMode() == PortalSettings.Mode.Edit)
                    {
                        if (this.EditorEnabled)
                        {
                            contentString = Localization.GetString("AddContentFromToolBar.Text", this.LocalResourceFile);
                        }
                        else
                        {
                            contentString = Localization.GetString("AddContentFromActionMenu.Text", this.LocalResourceFile);
                        }
                    }
                    else
                    {
                        // hide the module if no content and in view mode
                        this.ContainerControl.Visible = false;
                    }
                }

                // token replace
                this.EditorEnabled = this.EditorEnabled && !this.Settings.ReplaceTokens;

                // localize toolbar
                if (this.EditorEnabled)
                {
                    foreach (DNNToolBarButton button in this.editorDnnToobar.Buttons)
                    {
                        button.ToolTip = Localization.GetString(button.ToolTip + ".ToolTip", this.LocalResourceFile);
                    }
                }
                else
                {
                    this.editorDnnToobar.Visible = false;
                }

                this.lblContent.EditEnabled = this.EditorEnabled;

                // add content to module
                this.lblContent.Controls.Add(new LiteralControl(HtmlTextController.FormatHtmlText(this.ModuleId, contentString, this.Settings, this.PortalSettings, this.Page)));

                // set normalCheckBox on the content wrapper to prevent form decoration if its disabled.
                if (!this.Settings.UseDecorate)
                {
                    this.lblContent.CssClass = string.Format("{0} normalCheckBox", this.lblContent.CssClass);
                }

                if (this.IsPostBack && AJAX.IsEnabled() && AJAX.GetScriptManager(this.Page).IsInAsyncPostBack)
                {
                    var resetScript = $@"
if(typeof dnn !== 'undefined' && typeof dnn.controls !== 'undefined' && typeof dnn.controls.controls !== 'undefined'){{
    var control = dnn.controls.controls['{this.lblContent.ClientID}'];
    if(control && control.container !== $get('{this.lblContent.ClientID}')){{
        dnn.controls.controls['{this.lblContent.ClientID}'] = null;
    }}
}};";
                    ScriptManager.RegisterClientScriptBlock(this.Page, this.Page.GetType(), $"ResetHtmlModule{this.ClientID}", resetScript, true);
                }
            }
            catch (Exception exc)
            {
                Exceptions.ProcessModuleLoadException(this, exc);
            }
        }
Exemple #22
0
        /// -----------------------------------------------------------------------------
        /// <summary>
        ///
        /// </summary>
        /// <remarks>
        /// - Obtain PortalSettings from Current Context
        /// - redirect to a specific tab based on name
        /// - if first time loading this page then reload to avoid caching
        /// - set page title and stylesheet
        /// - check to see if we should show the Assembly Version in Page Title
        /// - set the background image if there is one selected
        /// - set META tags, copyright, keywords and description.
        /// </remarks>
        /// -----------------------------------------------------------------------------
        private void InitializePage()
        {
            // There could be a pending installation/upgrade process
            if (InstallBlocker.Instance.IsInstallInProgress())
            {
                Exceptions.ProcessHttpException(new HttpException(503, Localization.GetString("SiteAccessedWhileInstallationWasInProgress.Error", Localization.GlobalResourceFile)));
            }

            // Configure the ActiveTab with Skin/Container information
            PortalSettingsController.Instance().ConfigureActiveTab(this.PortalSettings);

            // redirect to a specific tab based on name
            if (!string.IsNullOrEmpty(this.Request.QueryString["tabname"]))
            {
                TabInfo tab = TabController.Instance.GetTabByName(this.Request.QueryString["TabName"], this.PortalSettings.PortalId);
                if (tab != null)
                {
                    var parameters = new List <string>(); // maximum number of elements
                    for (int intParam = 0; intParam <= this.Request.QueryString.Count - 1; intParam++)
                    {
                        switch (this.Request.QueryString.Keys[intParam].ToLowerInvariant())
                        {
                        case "tabid":
                        case "tabname":
                            break;

                        default:
                            parameters.Add(
                                this.Request.QueryString.Keys[intParam] + "=" + this.Request.QueryString[intParam]);
                            break;
                        }
                    }

                    this.Response.Redirect(this.NavigationManager.NavigateURL(tab.TabID, Null.NullString, parameters.ToArray()), true);
                }
                else
                {
                    // 404 Error - Redirect to ErrorPage
                    Exceptions.ProcessHttpException(this.Request);
                }
            }

            string cacheability = this.Request.IsAuthenticated ? Host.AuthenticatedCacheability : Host.UnauthenticatedCacheability;

            switch (cacheability)
            {
            case "0":
                this.Response.Cache.SetCacheability(HttpCacheability.NoCache);
                break;

            case "1":
                this.Response.Cache.SetCacheability(HttpCacheability.Private);
                break;

            case "2":
                this.Response.Cache.SetCacheability(HttpCacheability.Public);
                break;

            case "3":
                this.Response.Cache.SetCacheability(HttpCacheability.Server);
                break;

            case "4":
                this.Response.Cache.SetCacheability(HttpCacheability.ServerAndNoCache);
                break;

            case "5":
                this.Response.Cache.SetCacheability(HttpCacheability.ServerAndPrivate);
                break;
            }

            // Only insert the header control if a comment is needed
            if (!string.IsNullOrWhiteSpace(this.Comment))
            {
                this.Page.Header.Controls.AddAt(0, new LiteralControl(this.Comment));
            }

            if (this.PortalSettings.ActiveTab.PageHeadText != Null.NullString && !Globals.IsAdminControl())
            {
                this.Page.Header.Controls.Add(new LiteralControl(this.PortalSettings.ActiveTab.PageHeadText));
            }

            if (!string.IsNullOrEmpty(this.PortalSettings.PageHeadText))
            {
                this.metaPanel.Controls.Add(new LiteralControl(this.PortalSettings.PageHeadText));
            }

            // set page title
            if (UrlUtils.InPopUp())
            {
                var strTitle    = new StringBuilder(this.PortalSettings.PortalName);
                var slaveModule = UIUtilities.GetSlaveModule(this.PortalSettings.ActiveTab.TabID);

                // Skip is popup is just a tab (no slave module)
                if (slaveModule.DesktopModuleID != Null.NullInteger)
                {
                    var    control   = ModuleControlFactory.CreateModuleControl(slaveModule) as IModuleControl;
                    string extension = Path.GetExtension(slaveModule.ModuleControl.ControlSrc.ToLowerInvariant());
                    switch (extension)
                    {
                    case ".mvc":
                        var segments = slaveModule.ModuleControl.ControlSrc.Replace(".mvc", string.Empty).Split('/');

                        control.LocalResourceFile = string.Format(
                            "~/DesktopModules/MVC/{0}/{1}/{2}.resx",
                            slaveModule.DesktopModule.FolderName,
                            Localization.LocalResourceDirectory,
                            segments[0]);
                        break;

                    default:
                        control.LocalResourceFile = string.Concat(
                            slaveModule.ModuleControl.ControlSrc.Replace(
                                Path.GetFileName(slaveModule.ModuleControl.ControlSrc), string.Empty),
                            Localization.LocalResourceDirectory, "/",
                            Path.GetFileName(slaveModule.ModuleControl.ControlSrc));
                        break;
                    }

                    var title = Localization.LocalizeControlTitle(control);

                    strTitle.Append(string.Concat(" > ", this.PortalSettings.ActiveTab.LocalizedTabName));
                    strTitle.Append(string.Concat(" > ", title));
                }
                else
                {
                    strTitle.Append(string.Concat(" > ", this.PortalSettings.ActiveTab.LocalizedTabName));
                }

                // Set to page
                this.Title = strTitle.ToString();
            }
            else
            {
                // If tab is named, use that title, otherwise build it out via breadcrumbs
                if (!string.IsNullOrEmpty(this.PortalSettings.ActiveTab.Title))
                {
                    this.Title = this.PortalSettings.ActiveTab.Title;
                }
                else
                {
                    // Elected for SB over true concatenation here due to potential for long nesting depth
                    var strTitle = new StringBuilder(this.PortalSettings.PortalName);
                    foreach (TabInfo tab in this.PortalSettings.ActiveTab.BreadCrumbs)
                    {
                        strTitle.Append(string.Concat(" > ", tab.TabName));
                    }

                    this.Title = strTitle.ToString();
                }
            }

            // set the background image if there is one selected
            if (!UrlUtils.InPopUp() && this.FindControl("Body") != null)
            {
                if (!string.IsNullOrEmpty(this.PortalSettings.BackgroundFile))
                {
                    var fileInfo = this.GetBackgroundFileInfo();
                    var url      = FileManager.Instance.GetUrl(fileInfo);

                    ((HtmlGenericControl)this.FindControl("Body")).Attributes["style"] = string.Concat("background-image: url('", url, "')");
                }
            }

            // META Refresh
            // Only autorefresh the page if we are in VIEW-mode and if we aren't displaying some module's subcontrol.
            if (this.PortalSettings.ActiveTab.RefreshInterval > 0 && Personalization.GetUserMode() == PortalSettings.Mode.View && this.Request.QueryString["ctl"] == null)
            {
                this.MetaRefresh.Content = this.PortalSettings.ActiveTab.RefreshInterval.ToString();
                this.MetaRefresh.Visible = true;
            }
            else
            {
                this.MetaRefresh.Visible = false;
            }

            // META description
            if (!string.IsNullOrEmpty(this.PortalSettings.ActiveTab.Description))
            {
                this.Description = this.PortalSettings.ActiveTab.Description;
            }
            else
            {
                this.Description = this.PortalSettings.Description;
            }

            // META keywords
            if (!string.IsNullOrEmpty(this.PortalSettings.ActiveTab.KeyWords))
            {
                this.KeyWords = this.PortalSettings.ActiveTab.KeyWords;
            }
            else
            {
                this.KeyWords = this.PortalSettings.KeyWords;
            }

            // META copyright
            if (!string.IsNullOrEmpty(this.PortalSettings.FooterText))
            {
                this.Copyright = this.PortalSettings.FooterText.Replace("[year]", DateTime.Now.Year.ToString());
            }
            else
            {
                this.Copyright = string.Concat("Copyright (c) ", DateTime.Now.Year, " by ", this.PortalSettings.PortalName);
            }

            // META generator
            this.Generator = string.Empty;

            // META Robots - hide it inside popups and if PageHeadText of current tab already contains a robots meta tag
            if (!UrlUtils.InPopUp() &&
                !(HeaderTextRegex.IsMatch(this.PortalSettings.ActiveTab.PageHeadText) ||
                  HeaderTextRegex.IsMatch(this.PortalSettings.PageHeadText)))
            {
                this.MetaRobots.Visible = true;
                var allowIndex = true;
                if ((this.PortalSettings.ActiveTab.TabSettings.ContainsKey("AllowIndex") &&
                     bool.TryParse(this.PortalSettings.ActiveTab.TabSettings["AllowIndex"].ToString(), out allowIndex) &&
                     !allowIndex)
                    ||
                    (this.Request.QueryString["ctl"] != null &&
                     (this.Request.QueryString["ctl"] == "Login" || this.Request.QueryString["ctl"] == "Register")))
                {
                    this.MetaRobots.Content = "NOINDEX, NOFOLLOW";
                }
                else
                {
                    this.MetaRobots.Content = "INDEX, FOLLOW";
                }
            }

            // NonProduction Label Injection
            if (this.NonProductionVersion() && Host.DisplayBetaNotice && !UrlUtils.InPopUp())
            {
                string versionString = string.Format(" ({0} Version: {1})", DotNetNukeContext.Current.Application.Status,
                                                     DotNetNukeContext.Current.Application.Version);
                this.Title += versionString;
            }

            // register the custom stylesheet of current page
            if (this.PortalSettings.ActiveTab.TabSettings.ContainsKey("CustomStylesheet") && !string.IsNullOrEmpty(this.PortalSettings.ActiveTab.TabSettings["CustomStylesheet"].ToString()))
            {
                var styleSheet = this.PortalSettings.ActiveTab.TabSettings["CustomStylesheet"].ToString();

                // Try and go through the FolderProvider first
                var stylesheetFile = GetPageStylesheetFileInfo(styleSheet);
                if (stylesheetFile != null)
                {
                    ClientResourceManager.RegisterStyleSheet(this, FileManager.Instance.GetUrl(stylesheetFile));
                }
                else
                {
                    ClientResourceManager.RegisterStyleSheet(this, styleSheet);
                }
            }

            // Cookie Consent
            if (this.PortalSettings.ShowCookieConsent)
            {
                JavaScript.RegisterClientReference(this, ClientAPI.ClientNamespaceReferences.dnn);
                ClientAPI.RegisterClientVariable(this, "cc_morelink", this.PortalSettings.CookieMoreLink, true);
                ClientAPI.RegisterClientVariable(this, "cc_message", Localization.GetString("cc_message", Localization.GlobalResourceFile), true);
                ClientAPI.RegisterClientVariable(this, "cc_dismiss", Localization.GetString("cc_dismiss", Localization.GlobalResourceFile), true);
                ClientAPI.RegisterClientVariable(this, "cc_link", Localization.GetString("cc_link", Localization.GlobalResourceFile), true);
                ClientResourceManager.RegisterScript(this.Page, "~/Resources/Shared/Components/CookieConsent/cookieconsent.min.js", FileOrder.Js.DnnControls);
                ClientResourceManager.RegisterStyleSheet(this.Page, "~/Resources/Shared/Components/CookieConsent/cookieconsent.min.css", FileOrder.Css.ResourceCss);
                ClientResourceManager.RegisterScript(this.Page, "~/js/dnn.cookieconsent.js", FileOrder.Js.DefaultPriority);
            }
        }
Exemple #23
0
        protected void CmdAddModuleClick(object sender, EventArgs e)
        {
            if (TabPermissionController.CanAddContentToPage() && this.CanAddModuleToPage())
            {
                int permissionType;
                try
                {
                    permissionType = int.Parse(this.VisibilityLst.SelectedValue);
                }
                catch (Exception exc)
                {
                    Logger.Error(exc);

                    permissionType = 0;
                }

                int position = -1;
                switch (this.PositionLst.SelectedValue)
                {
                case "TOP":
                    position = 0;
                    break;

                case "ABOVE":
                    if (!string.IsNullOrEmpty(this.PaneModulesLst.SelectedValue))
                    {
                        try
                        {
                            position = int.Parse(this.PaneModulesLst.SelectedValue) - 1;
                        }
                        catch (Exception exc)
                        {
                            Logger.Error(exc);

                            position = -1;
                        }
                    }
                    else
                    {
                        position = 0;
                    }

                    break;

                case "BELOW":
                    if (!string.IsNullOrEmpty(this.PaneModulesLst.SelectedValue))
                    {
                        try
                        {
                            position = int.Parse(this.PaneModulesLst.SelectedValue) + 1;
                        }
                        catch (Exception exc)
                        {
                            Logger.Error(exc);

                            position = -1;
                        }
                    }
                    else
                    {
                        position = -1;
                    }

                    break;

                case "BOTTOM":
                    position = -1;
                    break;
                }

                int moduleLstID;
                try
                {
                    moduleLstID = int.Parse(this.ModuleLst.SelectedValue);
                }
                catch (Exception exc)
                {
                    Logger.Error(exc);

                    moduleLstID = -1;
                }

                if (moduleLstID > -1)
                {
                    if (this.AddExistingModule.Checked)
                    {
                        int pageID;
                        try
                        {
                            pageID = int.Parse(this.PageLst.SelectedValue);
                        }
                        catch (Exception exc)
                        {
                            Logger.Error(exc);

                            pageID = -1;
                        }

                        if (pageID > -1)
                        {
                            this.DoAddExistingModule(moduleLstID, pageID, this.PaneLst.SelectedValue, position, string.Empty, this.chkCopyModule.Checked);
                        }
                    }
                    else
                    {
                        DoAddNewModule(this.Title.Text, moduleLstID, this.PaneLst.SelectedValue, position, permissionType, string.Empty);
                    }
                }

                // set view mode to edit after add module.
                if (Personalization.GetUserMode() != PortalSettings.Mode.Edit)
                {
                    Personalization.SetProfile("Usability", "UserMode" + this.PortalSettings.PortalId, "EDIT");
                }

                this.Response.Redirect(this.Request.RawUrl, true);
            }
        }