Beispiel #1
0
 public PathParser()
 {
     this.m_HTMLPatterns = new ArrayList();
     this.m_CSSPatterns  = new ArrayList();
     this.m_SkinPath     = "";
     this.m_Messages     = "";
     this.SUBST          = Localization.GetString("Substituting", Globals.GetPortalSettings());
     this.SUBST_DETAIL   = Localization.GetString("Substituting.Detail", Globals.GetPortalSettings());
 }
        public UserInfo GetUser(string fieldName, DataRow row)
        {
            var username = (row.Table.Columns.Contains(fieldName + DataTableColumn.Appendix_Original)
                                   ? row[fieldName + DataTableColumn.Appendix_Original]
                                   : row[fieldName]).AsString();

            if (username != string.Empty)
            {
                var userInfo = UserController.GetUserByName(Globals.GetPortalSettings().PortalId, username);
                return(userInfo);
            }
            return(new UserInfo());
        }
Beispiel #3
0
        public UserInfo GetUser(string fieldName, DataRow row)
        {
            var strUserid = (row.Table.Columns.Contains(fieldName + DataTableColumn.Appendix_Original)
                                     ? row[fieldName + DataTableColumn.Appendix_Original]
                                     : row[fieldName]).AsString();

            if (strUserid != string.Empty)
            {
                var userInfo = new UserController().GetUser(Globals.GetPortalSettings().PortalId,
                                                            int.Parse(strUserid.Substring(7)));
                return(userInfo);
            }
            return(null);
        }
        static void ImportStyleSheet(int moduleId, bool isInstance, int tabModuleId, ModuleController modules,
                                     DataSet ds)
        {
            var portalSettings = Globals.GetPortalSettings();

            foreach (DataRow row in ds.Tables[DataSetTableName.Stylesheets].Rows)
            {
                var settingName   = row[StylesheetTableColumn.NameOfSetting].ToString();
                var localFilePath = row[StylesheetTableColumn.LocalFilePath].ToString();
                var stylesheet    = row[StylesheetTableColumn.Stylesheet].ToString();
                //Check whether file exists
                if (File.Exists(((portalSettings.HomeDirectoryMapPath + localFilePath).Replace("/", "\\"))))
                {
                    //nothing to do, settings points to existing stylesheet
                }
                else
                {
                    var fileName =
                        localFilePath.Substring(
                            Convert.ToInt32(
                                localFilePath.LastIndexOf("/", StringComparison.InvariantCultureIgnoreCase) + 1));
                    var folder = Utilities.GetFolder(portalSettings, Definition.XSLFolderName);
                    Utilities.SaveScript(stylesheet, fileName, folder, false);
                    if (tabModuleId != Null.NullInteger)
                    {
                        modules.UpdateTabModuleSetting(tabModuleId, settingName,
                                                       string.Format("{0}/{1}", Definition.XSLFolderName, fileName));
                    }
                    else
                    {
                        if (!isInstance)
                        {
                            modules.UpdateModuleSetting(moduleId, settingName,
                                                        string.Format("{0}/{1}", Definition.XSLFolderName, fileName));
                        }
                    }
                }
            }
        }
Beispiel #5
0
        public static string UploadSkin(string rootPath, string skinRoot, string skinName, Stream objInputStream)
        {
            ZipInputStream objZipInputStream = new ZipInputStream(objInputStream);

            ZipEntry objZipEntry;
            int      intSize = 2049;

            byte[]    arrData      = new byte[intSize];
            string    strMessage   = "";
            ArrayList arrSkinFiles = new ArrayList();

            //Localized Strings
            PortalSettings ResourcePortalSettings = Globals.GetPortalSettings();
            string         BEGIN_MESSAGE          = Localization.GetString("BeginZip", ResourcePortalSettings);
            string         CREATE_DIR             = Localization.GetString("CreateDir", ResourcePortalSettings);
            string         WRITE_FILE             = Localization.GetString("WriteFile", ResourcePortalSettings);
            string         FILE_ERROR             = Localization.GetString("FileError", ResourcePortalSettings);
            string         END_MESSAGE            = Localization.GetString("EndZip", ResourcePortalSettings);
            string         FILE_RESTICTED         = Localization.GetString("FileRestricted", ResourcePortalSettings);

            strMessage += FormatMessage(BEGIN_MESSAGE, skinName, -1, false);

            objZipEntry = objZipInputStream.GetNextEntry();
            while (objZipEntry != null)
            {
                if (!objZipEntry.IsDirectory)
                {
                    // validate file extension
                    string strExtension = objZipEntry.Name.Substring(objZipEntry.Name.LastIndexOf(".") + 1);
                    if (Strings.InStr(1, ",ASCX,HTM,HTML,CSS,SWF,RESX," + Globals.HostSettings["FileExtensions"].ToString().ToUpper(), "," + strExtension.ToUpper(), 0) != 0)
                    {
                        // process embedded zip files
                        if (objZipEntry.Name.ToLower() == SkinInfo.RootSkin.ToLower() + ".zip")
                        {
                            MemoryStream objMemoryStream = new MemoryStream();
                            intSize = objZipInputStream.Read(arrData, 0, arrData.Length);
                            while (intSize > 0)
                            {
                                objMemoryStream.Write(arrData, 0, intSize);
                                intSize = objZipInputStream.Read(arrData, 0, arrData.Length);
                            }
                            objMemoryStream.Seek(0, SeekOrigin.Begin);
                            strMessage += UploadSkin(rootPath, SkinInfo.RootSkin, skinName, objMemoryStream);
                        }
                        else if (objZipEntry.Name.ToLower() == SkinInfo.RootContainer.ToLower() + ".zip")
                        {
                            MemoryStream objMemoryStream = new MemoryStream();
                            intSize = objZipInputStream.Read(arrData, 0, arrData.Length);
                            while (intSize > 0)
                            {
                                objMemoryStream.Write(arrData, 0, intSize);
                                intSize = objZipInputStream.Read(arrData, 0, arrData.Length);
                            }
                            objMemoryStream.Seek(0, SeekOrigin.Begin);
                            strMessage += UploadSkin(rootPath, SkinInfo.RootContainer, skinName, objMemoryStream);
                        }
                        else
                        {
                            string strFileName = rootPath + skinRoot + "\\" + skinName + "\\" + objZipEntry.Name;

                            // create the directory if it does not exist
                            if (!Directory.Exists(Path.GetDirectoryName(strFileName)))
                            {
                                strMessage += FormatMessage(CREATE_DIR, Path.GetDirectoryName(strFileName), 2, false);
                                Directory.CreateDirectory(Path.GetDirectoryName(strFileName));
                            }

                            // remove the old file
                            if (File.Exists(strFileName))
                            {
                                File.SetAttributes(strFileName, FileAttributes.Normal);
                                File.Delete(strFileName);
                            }
                            // create the new file
                            FileStream objFileStream = File.Create(strFileName);

                            // unzip the file
                            strMessage += FormatMessage(WRITE_FILE, Path.GetFileName(strFileName), 2, false);
                            intSize     = objZipInputStream.Read(arrData, 0, arrData.Length);
                            while (intSize > 0)
                            {
                                objFileStream.Write(arrData, 0, intSize);
                                intSize = objZipInputStream.Read(arrData, 0, arrData.Length);
                            }
                            objFileStream.Close();

                            // save the skin file
                            switch (Path.GetExtension(strFileName))
                            {
                            case ".htm":
                                if (strFileName.ToLower().IndexOf(Globals.glbAboutPage.ToLower()) < 0)
                                {
                                    arrSkinFiles.Add(strFileName);
                                }
                                break;

                            case ".html":
                                if (strFileName.ToLower().IndexOf(Globals.glbAboutPage.ToLower()) < 0)
                                {
                                    arrSkinFiles.Add(strFileName);
                                }
                                break;

                            case ".ascx":
                                if (strFileName.ToLower().IndexOf(Globals.glbAboutPage.ToLower()) < 0)
                                {
                                    arrSkinFiles.Add(strFileName);
                                }
                                break;

                            case ".css":

                                if (strFileName.ToLower().IndexOf(Globals.glbAboutPage.ToLower()) < 0)
                                {
                                    arrSkinFiles.Add(strFileName);
                                }
                                break;
                            }
                        }
                    }
                    else
                    {
                        strMessage += FormatMessage(FILE_ERROR, string.Format(FILE_RESTICTED, objZipEntry.Name, Strings.Replace(Globals.HostSettings["FileExtensions"].ToString(), ",", ", *.", 1, -1, 0)), 2, true);
                    }
                }
                objZipEntry = objZipInputStream.GetNextEntry();
            }
            strMessage += FormatMessage(END_MESSAGE, skinName + ".zip", 1, false);
            objZipInputStream.Close();

            // process the list of skin files
            SkinFileProcessor NewSkin = new SkinFileProcessor(rootPath, skinRoot, skinName);

            strMessage += NewSkin.ProcessList(arrSkinFiles, SkinParser.Portable);

            // log installation event
            try
            {
                LogInfo objEventLogInfo = new LogInfo();
                objEventLogInfo.LogTypeKey = EventLogController.EventLogType.HOST_ALERT.ToString();
                objEventLogInfo.LogProperties.Add(new LogDetailInfo("Install Skin:", skinName));
                Array arrMessage = strMessage.Split("<br>".ToCharArray()[0]);
                foreach (string tempLoopVar_strRow in arrMessage)
                {
                    string strRow = tempLoopVar_strRow;
                    objEventLogInfo.LogProperties.Add(new LogDetailInfo("Info:", HtmlUtils.StripTags(strRow, true)));
                }
                EventLogController objEventLog = new EventLogController();
                objEventLog.AddLog(objEventLogInfo);
            }
            catch (Exception)
            {
                // error
            }

            return(strMessage);
        }
Beispiel #6
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 + "]");
                }
            }