Ejemplo n.º 1
0
        private Containers.Container LoadContainerFromQueryString(ModuleInfo module, HttpRequest request)
        {
            Containers.Container container = null;
            int previewModuleId            = -1;

            if (request.QueryString["ModuleId"] != null)
            {
                Int32.TryParse(request.QueryString["ModuleId"], out previewModuleId);
            }

            //load user container ( based on cookie )
            if ((request.QueryString["ContainerSrc"] != null) && (module.ModuleID == previewModuleId || previewModuleId == -1))
            {
                string containerSrc = SkinController.FormatSkinSrc(Globals.QueryStringDecode(request.QueryString["ContainerSrc"]) + ".ascx", PortalSettings);
                container = LoadContainerByPath(containerSrc);
            }
            return(container);
        }
Ejemplo n.º 2
0
            /// <summary>
            /// Prepend ascx control directives to file contents.
            /// </summary>
            /// <param name="Registrations">ArrayList of registration directives.</param>
            /// <remarks>
            /// This procedure formats the @Control directive and prepends it and all
            /// registration directives to the file contents.
            /// </remarks>
            public string PrependASCXDirectives(ArrayList Registrations)
            {
                string Messages = "";
                string Prefix   = "";

                // if the skin source is an HTML document, extract the content within the <body> tags
                string strPattern = "<\\s*body[^>]*>(?<skin>.*)<\\s*/\\s*body\\s*>";
                Match  objMatch   = Regex.Match(this.Contents, strPattern, RegexOptions.IgnoreCase | RegexOptions.Singleline);

                if (objMatch.Groups[1].Value != "")
                {
                    this.Contents = objMatch.Groups[1].Value;
                }

                // format and save @Control directive
                if (this.SkinRoot == SkinInfo.RootSkin)
                {
                    //Prefix += "<%@ Control language=\"vb\" CodeBehind=\"~/admin/" + SkinRoot + "/skin.vb\" AutoEventWireup=\"false\" Explicit=\"True\" Inherits=\"DotNetNuke.UI.Skins.Skin\" %>" + Environment.NewLine;
                    Prefix += "<%@ Control language=\"c#\" CodeBehind=\"~/Admin/" + SkinRoot + "/Skin.cs\" AutoEventWireup=\"true\" Inherits=\"DotNetNuke.UI.Skins.Skin\" %>" + Environment.NewLine;
                }
                else if (this.SkinRoot == SkinInfo.RootContainer)
                {
                    //Prefix += "<%@ Control language=\"vb\" CodeBehind=\"~/admin/" + SkinRoot + "/container.vb\" AutoEventWireup=\"false\" Explicit=\"True\" Inherits=\"DotNetNuke.UI.Containers.Container\" %>" + Environment.NewLine;
                    Prefix += "<%@ Control language=\"c#\" CodeBehind=\"~/Admin/" + SkinRoot + "/Container.cs\" AutoEventWireup=\"true\" Inherits=\"DotNetNuke.UI.Containers.Container\" %>" + Environment.NewLine;
                }

                Messages += SkinController.FormatMessage(CONTROL_DIR, HttpUtility.HtmlEncode(Prefix), 2, false);

                // add preformatted Control Registrations
                foreach (string Item in Registrations)
                {
                    Messages += SkinController.FormatMessage(CONTROL_REG, HttpUtility.HtmlEncode(Item), 2, false);
                    Prefix   += Item;
                }

                // update file contents to include ascx header information
                this.Contents = Prefix + this.Contents;

                return(Messages);
            }
Ejemplo n.º 3
0
        private bool ProcessSlaveModule()
        {
            var success     = true;
            var key         = UIUtilities.GetControlKey();
            var moduleId    = UIUtilities.GetModuleId(key);
            var slaveModule = UIUtilities.GetSlaveModule(moduleId, key, PortalSettings.ActiveTab.TabID);

            Pane pane;

            Panes.TryGetValue(Globals.glbDefaultPane.ToLowerInvariant(), out pane);
            slaveModule.PaneName     = Globals.glbDefaultPane;
            slaveModule.ContainerSrc = PortalSettings.ActiveTab.ContainerSrc;
            if (String.IsNullOrEmpty(slaveModule.ContainerSrc))
            {
                slaveModule.ContainerSrc = PortalSettings.DefaultPortalContainer;
            }
            slaveModule.ContainerSrc  = SkinController.FormatSkinSrc(slaveModule.ContainerSrc, PortalSettings);
            slaveModule.ContainerPath = SkinController.FormatSkinPath(slaveModule.ContainerSrc);

            var moduleControl = ModuleControlController.GetModuleControlByControlKey(key, slaveModule.ModuleDefID);

            if (moduleControl != null)
            {
                slaveModule.ModuleControlId = moduleControl.ModuleControlID;
                slaveModule.IconFile        = moduleControl.IconFile;
                if (ModulePermissionController.HasModuleAccess(slaveModule.ModuleControl.ControlType, Null.NullString, slaveModule))
                {
                    success = InjectModule(pane, slaveModule);
                }
                else
                {
                    Response.Redirect(Globals.AccessDeniedURL(Localization.GetString("ModuleAccess.Error")), true);
                }
            }

            return(success);
        }
Ejemplo n.º 4
0
            /// <summary>
            /// Process regular expression matches.
            /// </summary>
            /// <param name="m">Regular expression match for path information which requires processing.</param>
            /// <returns>Properly formatted path information.</returns>
            /// <remarks>
            /// The handler is invoked by the Regex.Replace method once for each match that
            /// it encounters.  The returned value of the handler is substituted for the
            /// original match.  So the handler properly formats the path information and
            /// returns it in favor of the improperly formatted match.
            /// </remarks>
            private string MatchHandler(Match m)
            {
                string strOldTag = m.Groups["tag"].Value + m.Groups["content"].Value + m.Groups["endtag"].Value;
                string strNewTag = strOldTag;

                switch (this.ParseOption)
                {
                case SkinParser.Localized:

                    // if the tag does not contain the localized path
                    if (strNewTag.IndexOf(this.SkinPath) == -1)
                    {
                        // insert the localized path
                        strNewTag = m.Groups["tag"].Value + this.SkinPath + m.Groups["content"].Value + m.Groups["endtag"].Value;
                    }
                    break;

                case SkinParser.Portable:

                    // if the tag does not contain a reference to the skinpath
                    if (strNewTag.ToLower().IndexOf("<%= skinpath %>") == -1)
                    {
                        // insert the skinpath
                        strNewTag = m.Groups["tag"].Value + "<%= SkinPath %>" + m.Groups["content"].Value + m.Groups["endtag"].Value;
                    }
                    // if the tag contains the localized path
                    if (strNewTag.IndexOf(this.SkinPath) != -1)
                    {
                        // remove the localized path
                        strNewTag = strNewTag.Replace(this.SkinPath, "");
                    }
                    break;
                }

                m_Messages += SkinController.FormatMessage(SUBST, string.Format(SUBST_DETAIL, HttpUtility.HtmlEncode(strOldTag), HttpUtility.HtmlEncode(strNewTag)), 2, false);
                return(strNewTag);
            }
Ejemplo n.º 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 = (PortalSettings.UserMode != PortalSettings.Mode.View);
                }

                if (displayTitle == false)
                {
                    container = LoadContainerByPath(SkinController.FormatSkinSrc(noContainerSrc, PortalSettings));
                }
            }
            return(container);
        }
Ejemplo n.º 6
0
        private Containers.Container LoadModuleContainer(ModuleInfo module)
        {
            var containerSrc = Null.NullString;
            var request      = PaneControl.Page.Request;

            Containers.Container container = null;

            if (PortalSettings.EnablePopUps && UrlUtils.InPopUp())
            {
                containerSrc = module.ContainerPath + "popUpContainer.ascx";
                //Check Skin for a popup Container
                if (module.ContainerSrc == PortalSettings.ActiveTab.ContainerSrc)
                {
                    if (File.Exists(HttpContext.Current.Server.MapPath(containerSrc)))
                    {
                        container = LoadContainerByPath(containerSrc);
                    }
                }

                //error loading container - load default popup container
                if (container == null)
                {
                    containerSrc = Globals.HostPath + "Containers/_default/popUpContainer.ascx";
                    container    = LoadContainerByPath(containerSrc);
                }
            }
            else
            {
                container = (LoadContainerFromQueryString(module, request) ?? LoadContainerFromCookie(request)) ?? LoadNoContainer(module);
                if (container == null)
                {
                    //Check Skin for Container
                    var masterModules = PortalSettings.ActiveTab.ChildModules;
                    if (masterModules.ContainsKey(module.ModuleID) && string.IsNullOrEmpty(masterModules[module.ModuleID].ContainerSrc))
                    {
                        //look for a container specification in the skin pane
                        if (PaneControl != null)
                        {
                            if ((PaneControl.Attributes["ContainerSrc"] != null))
                            {
                                container = LoadContainerFromPane();
                            }
                        }
                    }
                }

                //else load assigned container
                if (container == null)
                {
                    containerSrc = module.ContainerSrc;
                    if (!String.IsNullOrEmpty(containerSrc))
                    {
                        containerSrc = SkinController.FormatSkinSrc(containerSrc, PortalSettings);
                        container    = LoadContainerByPath(containerSrc);
                    }
                }

                //error loading container - load from tab
                if (container == null)
                {
                    containerSrc = PortalSettings.ActiveTab.ContainerSrc;
                    if (!String.IsNullOrEmpty(containerSrc))
                    {
                        containerSrc = SkinController.FormatSkinSrc(containerSrc, PortalSettings);
                        container    = LoadContainerByPath(containerSrc);
                    }
                }

                //error loading container - load default
                if (container == null)
                {
                    containerSrc = SkinController.FormatSkinSrc(SkinController.GetDefaultPortalContainer(), PortalSettings);
                    container    = LoadContainerByPath(containerSrc);
                }
            }

            //Set container path
            module.ContainerPath = SkinController.FormatSkinPath(containerSrc);

            //set container id to an explicit short name to reduce page payload
            container.ID = "ctr";
            //make the container id unique for the page
            if (module.ModuleID > -1)
            {
                container.ID += module.ModuleID.ToString();
            }
            return(container);
        }
Ejemplo n.º 7
0
        /// <summary>
        /// SkinFileProcessor class constructor.
        /// </summary>
        /// <param name="SkinPath">File path to the portals upload directory.</param>
        /// <param name="SkinRoot">Specifies type of skin (Skins or Containers)</param>
        /// <param name="SkinName">Name of folder in which skin will reside (Zip file name)</param>
        /// <remarks>
        /// The constructor primes the file processor with path information and
        /// control data that should only be retrieved once.  It checks for the
        /// existentce of a skin level attribute file and read it in, if found.
        /// It also sorts through the complete list of controls and creates
        /// a hashtable which contains only the skin objects and their source paths.
        /// These are recognized by their ControlKey's which are formatted like
        /// tokens ("[TOKEN]").  The hashtable is required for speed as it will be
        /// processed for each token found in the source file by the Control Parser.
        /// </remarks>
        public SkinFileProcessor(string SkinPath, string SkinRoot, string SkinName)
        {
            this.Message += SkinController.FormatMessage(INITIALIZE_PROCESSOR, SkinRoot + " :: " + SkinName, 0, false);

            // Save path information for future use
            m_SkinRoot = SkinRoot;
            m_SkinPath = SkinPath;
            m_SkinName = SkinName;

            // Check for and read skin package level attribute information file
            string FileName = this.SkinPath + this.SkinRoot + "\\" + this.SkinName + "\\" + SkinRoot.Substring(0, SkinRoot.Length - 1) + ".xml";

            if (File.Exists(FileName))
            {
                try
                {
                    this.SkinAttributes.Load(FileName);
                    this.Message += SkinController.FormatMessage(PACKAGE_LOAD, Path.GetFileName(FileName), 2, false);
                }
                catch (Exception ex)
                {
                    // could not load XML file
                    this.Message += SkinController.FormatMessage(string.Format(PACKAGE_LOAD_ERROR, ex.Message), Path.GetFileName(FileName), 2, true);
                }
            }

            // Retrieve a list of available controls
            ModuleControlController objModuleControls = new ModuleControlController();
            ArrayList arrModuleControls = objModuleControls.GetModuleControls(Null.NullInteger);

            // Look at every control
            string            Token;
            int               i;
            ModuleControlInfo objModuleControl;

            for (i = 0; i <= arrModuleControls.Count - 1; i++)
            {
                objModuleControl = (ModuleControlInfo)arrModuleControls[i];
                // If the control is a skin object, save the key and source in the hash table
                if (objModuleControl.ControlType == SecurityAccessLevel.SkinObject)
                {
                    Token = objModuleControl.ControlKey.ToUpper();

                    // If the control is already in the hash table
                    if (m_ControlList.ContainsKey(Token))
                    {
                        // Record an error message and skip it
                        this.Message += SkinController.FormatMessage(string.Format(DUPLICATE_ERROR, objModuleControl.ControlKey.ToString().ToUpper()), string.Format(DUPLICATE_DETAIL, ((string)m_ControlList[Token]), objModuleControl.ControlSrc.ToString()), 2, true);
                    }
                    else
                    {
                        // Add it
                        this.Message += SkinController.FormatMessage(string.Format(LOAD_SKIN_TOKEN, objModuleControl.ControlKey.ToString().ToUpper()), objModuleControl.ControlSrc.ToString(), 2, false);
                        m_ControlList.Add(Token, objModuleControl.ControlSrc);
                    }
                }
            }

            // Instantiate the control parser with the list of skin objects
            m_ControlFactory = new ControlParser(m_ControlList);
        }
Ejemplo n.º 8
0
            /// <summary>
            /// SkinFile class constructor.
            /// </summary>
            /// <param name="SkinRoot"></param>
            /// <param name="FileName"></param>
            /// <param name="SkinAttributes"></param>
            /// <remarks>
            /// The constructor primes the utility class with basic file information.
            /// It also checks for the existentce of a skinfile level attribute file
            /// and read it in, if found.
            /// </remarks>
            public SkinFile(string SkinRoot, string FileName, XmlDocument SkinAttributes)
            {
                // capture file information
                m_FileName       = FileName;
                m_FileExtension  = Path.GetExtension(FileName);
                m_SkinRoot       = SkinRoot;
                m_FileAttributes = SkinAttributes;

                // determine and store path to portals skin root folder
                string strTemp = FileName.Replace(Path.GetFileName(FileName), "");

                strTemp        = strTemp.Replace("\\", "/");
                m_SkinRootPath = Globals.ApplicationPath + strTemp.Substring(Strings.InStr(1, strTemp.ToUpper(), "/PORTALS", 0) - 1);

                // read file contents
                this.Contents = Read(FileName);

                // setup some attributes based on file extension
                switch (this.FileExtension)
                {
                case ".htm":
                    // set output file name to <filename>.ASCX
                    m_WriteFileName = FileName.Replace(Path.GetExtension(FileName), ".ascx");
                    // capture warning if file does not contain a id="ContentPane" or [CONTENTPANE]
                    Regex PaneCheck1 = new Regex("\\s*id\\s*=\\s*\"" + Globals.glbDefaultPane + "\"", RegexOptions.IgnoreCase);
                    Regex PaneCheck2 = new Regex("\\s*[" + Globals.glbDefaultPane + "]", RegexOptions.IgnoreCase);
                    if (PaneCheck1.IsMatch(this.Contents) == false && PaneCheck2.IsMatch(this.Contents) == false)
                    {
                        m_Messages += SkinController.FormatMessage(FILE_FORMAT_ERROR, string.Format(FILE_FORMAT_ERROR, FileName), 2, true);
                    }

                    // Check for existence of and load skin file level attribute information
                    if (File.Exists(FileName.Replace(this.FileExtension, ".xml")))
                    {
                        try
                        {
                            m_FileAttributes.Load(FileName.Replace(this.FileExtension, ".xml"));
                            m_Messages += SkinController.FormatMessage(FILE_LOAD, FileName, 2, false);
                        }
                        catch (Exception)      // could not load XML file
                        {
                            m_FileAttributes = SkinAttributes;
                            m_Messages      += SkinController.FormatMessage(FILE_LOAD_ERROR, FileName, 2, true);
                        }
                    }
                    break;

                case ".html":

                    // set output file name to <filename>.ASCX
                    m_WriteFileName = FileName.Replace(Path.GetExtension(FileName), ".ascx");
                    // capture warning if file does not contain a id="ContentPane" or [CONTENTPANE]
                    PaneCheck1 = new Regex("\\s*id\\s*=\\s*\"" + Globals.glbDefaultPane + "\"", RegexOptions.IgnoreCase);
                    PaneCheck2 = new Regex("\\s*[" + Globals.glbDefaultPane + "]", RegexOptions.IgnoreCase);
                    if (PaneCheck1.IsMatch(this.Contents) == false && PaneCheck2.IsMatch(this.Contents) == false)
                    {
                        m_Messages += SkinController.FormatMessage(FILE_FORMAT_ERROR, string.Format(FILE_FORMAT_ERROR, FileName), 2, true);
                    }

                    // Check for existence of and load skin file level attribute information
                    if (File.Exists(FileName.Replace(this.FileExtension, ".xml")))
                    {
                        try
                        {
                            m_FileAttributes.Load(FileName.Replace(this.FileExtension, ".xml"));
                            m_Messages += SkinController.FormatMessage(FILE_LOAD, FileName, 2, false);
                        }
                        catch (Exception)      // could not load XML file
                        {
                            m_FileAttributes = SkinAttributes;
                            m_Messages      += SkinController.FormatMessage(FILE_LOAD_ERROR, FileName, 2, true);
                        }
                    }
                    break;

                default:

                    // output file name is same as input file name
                    m_WriteFileName = FileName;
                    break;
                }
            }
Ejemplo n.º 9
0
            /// <summary>
            /// Process regular expression matches.
            /// </summary>
            /// <param name="m">Regular expression match for token which requires processing.</param>
            /// <returns>Properly formatted token.</returns>
            /// <remarks>
            /// The handler is invoked by the Regex.Replace method once for each match that
            /// it encounters.  The returned value of the handler is substituted for the
            /// original match.  So the handler properly formats the replacement for the
            /// token and returns it instead.  If an unknown token is encountered, the token
            /// is unmodified.  This can happen if a token is used for a skin object which
            /// has not yet been installed.
            /// </remarks>
            private string TokenMatchHandler(Match m)
            {
                string TOKEN_PROC            = Localization.GetString("ProcessToken", Globals.GetPortalSettings());
                string TOKEN_SKIN            = Localization.GetString("SkinToken", Globals.GetPortalSettings());
                string TOKEN_PANE            = Localization.GetString("PaneToken", Globals.GetPortalSettings());
                string TOKEN_FOUND           = Localization.GetString("TokenFound", Globals.GetPortalSettings());
                string TOKEN_FORMAT          = Localization.GetString("TokenFormat", Globals.GetPortalSettings());
                string TOKEN_NOTFOUND_INFILE = Localization.GetString("TokenNotFoundInFile", Globals.GetPortalSettings());
                string CONTROL_FORMAT        = Localization.GetString("ControlFormat", Globals.GetPortalSettings());
                string TOKEN_NOTFOUND        = Localization.GetString("TokenNotFound", Globals.GetPortalSettings());

                string Token       = m.Groups["token"].Value.ToUpper();
                string ControlName = Token + m.Groups["instance"].Value;

                // if the token has an instance name, use it to look for the corresponding attributes
                string AttributeNode = Token + Convert.ToString((m.Groups["instance"].Value == "") ? "" : (":" + m.Groups["instance"].Value));

                this.Messages += SkinController.FormatMessage(TOKEN_PROC, "[" + AttributeNode + "]", 2, false);

                // if the token is a recognized skin control
                if (this.ControlList.ContainsKey(Token) == true || Token.IndexOf("CONTENTPANE") != -1)
                {
                    string SkinControl = "";

                    if (this.ControlList.ContainsKey(Token))
                    {
                        this.Messages += SkinController.FormatMessage(TOKEN_SKIN, ((string)this.ControlList[Token]), 2, false);
                    }
                    else
                    {
                        this.Messages += SkinController.FormatMessage(TOKEN_PANE, Token, 2, false);
                    }

                    // if there is an attribute file
                    if (this.Attributes.DocumentElement != null)
                    {
                        // look for the the node of this instance of the token
                        XmlNode xmlSkinAttributeRoot = this.Attributes.DocumentElement.SelectSingleNode("descendant::Object[Token='[" + AttributeNode + "]']");
                        // if the token is found
                        if (xmlSkinAttributeRoot != null)
                        {
                            this.Messages += SkinController.FormatMessage(TOKEN_FOUND, "[" + AttributeNode + "]", 2, false);
                            // process each token attribute
                            XmlNode xmlSkinAttribute;
                            foreach (XmlNode tempLoopVar_xmlSkinAttribute in xmlSkinAttributeRoot.SelectNodes(".//Settings/Setting"))
                            {
                                xmlSkinAttribute = tempLoopVar_xmlSkinAttribute;
                                if (xmlSkinAttribute.SelectSingleNode("Value").InnerText != "")
                                {
                                    // append the formatted attribute to the inner contents of the control statement
                                    this.Messages += SkinController.FormatMessage(TOKEN_FORMAT, xmlSkinAttribute.SelectSingleNode("Name").InnerText + "=\"" + xmlSkinAttribute.SelectSingleNode("Value").InnerText + "\"", 2, false);
                                    SkinControl   += " " + xmlSkinAttribute.SelectSingleNode("Name").InnerText + "=\"" + xmlSkinAttribute.SelectSingleNode("Value").InnerText.Replace("\"", "&quot;") + "\"";
                                }
                            }
                        }
                        else
                        {
                            this.Messages += SkinController.FormatMessage(TOKEN_NOTFOUND_INFILE, "[" + AttributeNode + "]", 2, false);
                        }
                    }

                    if (this.ControlList.ContainsKey(Token))
                    {
                        // create the skin object user control tag
                        SkinControl = "dnn:" + ControlName + " runat=\"server\" id=\"dnn" + ControlName + "\"" + SkinControl;

                        // Save control registration statement
                        RegisterList.Add("<%@ Register TagPrefix=\"dnn\" TagName=\"" + ControlName + "\" Src=\"~/" + ((string)this.ControlList[Token]) + "\" %>" + "\r\n");

                        // return the control statement
                        this.Messages += SkinController.FormatMessage(CONTROL_FORMAT, "&lt;" + SkinControl + " /&gt;", 2, false);

                        SkinControl = "<" + SkinControl + " />";
                    }
                    else // CONTENTPANE
                    {
                        if (SkinControl.ToLower().IndexOf("id=") == -1)
                        {
                            SkinControl = " id=\"ContentPane\"";
                        }
                        SkinControl = "div runat=\"server\"" + SkinControl + "></div";

                        // return the control statement
                        this.Messages += SkinController.FormatMessage(CONTROL_FORMAT, "&lt;" + SkinControl + "&gt;", 2, false);

                        SkinControl = "<" + SkinControl + ">";
                    }

                    return(SkinControl);
                }
                else
                {
                    // return the unmodified token
                    // note that this is currently protecting array syntax in embedded javascript
                    // should be fixed in the regular expressions but is not, currently.
                    this.Messages += SkinController.FormatMessage(TOKEN_NOTFOUND, "[" + m.Groups["token"].Value + "]", 2, false);
                    return("[" + m.Groups["token"].Value + "]");
                }
            }