Ejemplo n.º 1
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>
        /// <history>
        ///     [sun1]	1/19/2004	Created
        /// </history>
        /// -----------------------------------------------------------------------------
        private void InitializePage()
        {
            var tabController = new TabController();

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

                        default:
                            parameters.Add(
                                Request.QueryString.Keys[intParam] + "=" + Request.QueryString[intParam]);
                            break;
                        }
                    }
                    Response.Redirect(Globals.NavigateURL(tab.TabID, Null.NullString, parameters.ToArray()), true);
                }
                else
                {
                    //404 Error - Redirect to ErrorPage
                    Exceptions.ProcessHttpException(Request);
                }
            }
            if (Request.IsAuthenticated)
            {
                switch (Host.AuthenticatedCacheability)
                {
                case "0":
                    Response.Cache.SetCacheability(HttpCacheability.NoCache);
                    break;

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

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

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

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

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

            //page comment
            if (Host.DisplayCopyright)
            {
                Comment += string.Concat(Environment.NewLine,
                                         "<!--************************************************************************************-->",
                                         Environment.NewLine,
                                         "<!-- DNN Platform - http://www.dnnsoftware.com                                        -->",
                                         Environment.NewLine,
                                         "<!-- Copyright (c) 2002-2013                                                          -->",
                                         Environment.NewLine,
                                         "<!-- by DNN Corporation                                                               -->",
                                         Environment.NewLine,
                                         "<!--**********************************************************************************-->",
                                         Environment.NewLine);
            }
            Page.Header.Controls.AddAt(0, new LiteralControl(Comment));

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

            //set page title
            string strTitle = PortalSettings.PortalName;

            if (IsPopUp)
            {
                var slaveModule = UIUtilities.GetSlaveModule(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;
                    control.LocalResourceFile = slaveModule.ModuleControl.ControlSrc.Replace(Path.GetFileName(slaveModule.ModuleControl.ControlSrc), "") + Localization.LocalResourceDirectory + "/" +
                                                Path.GetFileName(slaveModule.ModuleControl.ControlSrc);
                    var title = Localization.LocalizeControlTitle(control);

                    strTitle += string.Concat(" > ", PortalSettings.ActiveTab.LocalizedTabName);
                    strTitle += string.Concat(" > ", title);
                }
                else
                {
                    strTitle += string.Concat(" > ", PortalSettings.ActiveTab.LocalizedTabName);
                }
            }
            else
            {
                foreach (TabInfo tab in PortalSettings.ActiveTab.BreadCrumbs)
                {
                    strTitle += string.Concat(" > ", tab.TabName);
                }

                //tab title override
                if (!string.IsNullOrEmpty(PortalSettings.ActiveTab.Title))
                {
                    strTitle = PortalSettings.ActiveTab.Title;
                }
            }
            Title = strTitle;

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

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

            //META Refresh
            if (PortalSettings.ActiveTab.RefreshInterval > 0 && Request.QueryString["ctl"] == null)
            {
                MetaRefresh.Content = PortalSettings.ActiveTab.RefreshInterval.ToString();
            }
            else
            {
                MetaRefresh.Visible = false;
            }

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

            //META keywords
            if (!string.IsNullOrEmpty(PortalSettings.ActiveTab.KeyWords))
            {
                KeyWords = PortalSettings.ActiveTab.KeyWords;
            }
            else
            {
                KeyWords = PortalSettings.KeyWords;
            }
            if (Host.DisplayCopyright)
            {
                KeyWords += ",DotNetNuke,DNN";
            }

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

            //META generator
            if (Host.DisplayCopyright)
            {
                Generator = "DotNetNuke ";
            }
            else
            {
                Generator = "";
            }

            //META Robots
            var allowIndex = true;

            if ((PortalSettings.ActiveTab.TabSettings.ContainsKey("AllowIndex") && bool.TryParse(PortalSettings.ActiveTab.TabSettings["AllowIndex"].ToString(), out allowIndex) && !allowIndex) ||
                (Request.QueryString["ctl"] != null && (Request.QueryString["ctl"] == "Login" || Request.QueryString["ctl"] == "Register")))
            {
                MetaRobots.Content = "NOINDEX, NOFOLLOW";
            }
            else
            {
                MetaRobots.Content = "INDEX, FOLLOW";
            }

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

            //register DNN SkinWidgets Inititialization scripts
            if (PortalSettings.EnableSkinWidgets)
            {
                jQuery.RequestRegistration();
                // don't use the new API to register widgets until we better understand their asynchronous script loading requirements.
                ClientAPI.RegisterStartUpScript(Page, "initWidgets", string.Format("<script type=\"text/javascript\" src=\"{0}\" ></script>", ResolveUrl("~/Resources/Shared/scripts/initWidgets.js")));
            }

            //register the custom stylesheet of current page
            if (PortalSettings.ActiveTab.TabSettings.ContainsKey("CustomStylesheet") && !string.IsNullOrEmpty(PortalSettings.ActiveTab.TabSettings["CustomStylesheet"].ToString()))
            {
                var customStylesheet = Path.Combine(PortalSettings.HomeDirectory, PortalSettings.ActiveTab.TabSettings["CustomStylesheet"].ToString());
                ClientResourceManager.RegisterStyleSheet(this, customStylesheet);
            }
        }
Ejemplo n.º 2
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(PortalSettings);

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

                        default:
                            parameters.Add(
                                Request.QueryString.Keys[intParam] + "=" + Request.QueryString[intParam]);
                            break;
                        }
                    }
                    Response.Redirect(NavigationManager.NavigateURL(tab.TabID, Null.NullString, parameters.ToArray()), true);
                }
                else
                {
                    //404 Error - Redirect to ErrorPage
                    Exceptions.ProcessHttpException(Request);
                }
            }
            string cacheability = Request.IsAuthenticated ? Host.AuthenticatedCacheability : Host.UnauthenticatedCacheability;

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

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

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

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

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

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

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

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

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

            //set page title
            if (UrlUtils.InPopUp())
            {
                var strTitle    = new StringBuilder(PortalSettings.PortalName);
                var slaveModule = UIUtilities.GetSlaveModule(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", "").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(" > ", PortalSettings.ActiveTab.LocalizedTabName));
                    strTitle.Append(string.Concat(" > ", title));
                }
                else
                {
                    strTitle.Append(string.Concat(" > ", PortalSettings.ActiveTab.LocalizedTabName));
                }

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

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

                    ((HtmlGenericControl)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 (PortalSettings.ActiveTab.RefreshInterval > 0 && this.PortalSettings.UserMode == PortalSettings.Mode.View && Request.QueryString["ctl"] == null)
            {
                MetaRefresh.Content = PortalSettings.ActiveTab.RefreshInterval.ToString();
                MetaRefresh.Visible = true;
            }
            else
            {
                MetaRefresh.Visible = false;
            }

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

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

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

            //META generator

            Generator = "";


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

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

            //register the custom stylesheet of current page
            if (PortalSettings.ActiveTab.TabSettings.ContainsKey("CustomStylesheet") && !string.IsNullOrEmpty(PortalSettings.ActiveTab.TabSettings["CustomStylesheet"].ToString()))
            {
                var customStylesheet = Path.Combine(PortalSettings.HomeDirectory, PortalSettings.ActiveTab.TabSettings["CustomStylesheet"].ToString());
                ClientResourceManager.RegisterStyleSheet(this, customStylesheet);
            }

            // Cookie Consent
            if (PortalSettings.ShowCookieConsent)
            {
                ClientAPI.RegisterClientVariable(this, "cc_morelink", 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(Page, "~/Resources/Shared/Components/CookieConsent/cookieconsent.min.js", FileOrder.Js.DnnControls);
                ClientResourceManager.RegisterStyleSheet(Page, "~/Resources/Shared/Components/CookieConsent/cookieconsent.min.css", FileOrder.Css.ResourceCss);
                ClientResourceManager.RegisterScript(Page, "~/js/dnn.cookieconsent.js", FileOrder.Js.DefaultPriority);
            }
        }