コード例 #1
0
        /// <summary>
        /// Will transform a given signature to HTML using the UBB parser. Only several tags are supported. These tags are filtered by the
        /// special signature xsl sheet. The input is already limited to the maximum signature size.
        /// </summary>
        /// <param name="signature">Signature to transform to HTML</param>
        /// <param name="parserData">The parser data.</param>
        /// <returns>Signature in HTML format.</returns>
        public static string TransformSignatureUBBStringToHTML(string signature, ParserData parserData)
        {
            string parserLog, messageTextXML;
            bool   errorsOccured;

            return(TransformUBBStringToHTML(signature, false, true, parserData, out parserLog, out errorsOccured, out messageTextXML));
        }
コード例 #2
0
ファイル: TextParser.cs プロジェクト: priaonehaha/HnD
 /// <summary>
 /// Used by the re-parser to parse a message to xml.
 /// </summary>
 /// <param name="messageText">the text of the message in UBB format</param>
 /// <param name="reGenerateHTML">if true, HTML is also re-generated</param>
 /// <param name="parserData">The parser data.</param>
 /// <param name="messageTextXML">the XML parse result for the ubbstring</param>
 /// <param name="messageTextHTML">if reGenerateHTML is set to true, this contains the HTML output for the message</param>
 public static void ReParseMessage(string messageText, bool reGenerateHTML, ParserData parserData, out string messageTextXML, out string messageTextHTML)
 {
     bool errorsOccured = false;
     string parseLog = string.Empty;
     messageTextXML = string.Empty;
     messageTextHTML = TransformUBBStringToHTML(messageText, true, reGenerateHTML, parserData, out parseLog, out errorsOccured, out messageTextXML);
 }
コード例 #3
0
        /// <summary>
        /// Used by the re-parser to parse a message to xml.
        /// </summary>
        /// <param name="messageText">the text of the message in UBB format</param>
        /// <param name="reGenerateHTML">if true, HTML is also re-generated</param>
        /// <param name="parserData">The parser data.</param>
        /// <param name="messageTextXML">the XML parse result for the ubbstring</param>
        /// <param name="messageTextHTML">if reGenerateHTML is set to true, this contains the HTML output for the message</param>
        public static void ReParseMessage(string messageText, bool reGenerateHTML, ParserData parserData, out string messageTextXML, out string messageTextHTML)
        {
            bool   errorsOccured = false;
            string parseLog      = string.Empty;

            messageTextXML  = string.Empty;
            messageTextHTML = TransformUBBStringToHTML(messageText, true, reGenerateHTML, parserData, out parseLog, out errorsOccured, out messageTextXML);
        }
コード例 #4
0
 /// <summary>
 /// Transforms the given message with all its forumtags to HTML using the specified XSL template and returns that HTML string. The
 /// XSL template is cached inside the Application object, so the name specified is the name of the Application object's property holding the
 /// XSL template.
 /// </summary>
 /// <param name="ubbString">Text to transform</param>
 /// <param name="parserData">The parser data.</param>
 /// <param name="parserLog">Output parameter, contains the parserlog of the parse process</param>
 /// <param name="errorsOccured">Output parameter, contains true if the parser found one or more errors in sUBBString, false otherwise</param>
 /// <param name="messageTextXML">The parse result in XML format (string)</param>
 /// <returns>ubbString in HTML format</returns>
 public static string TransformUBBMessageStringToHTML(string ubbString, ParserData parserData, out string parserLog, out bool errorsOccured, out string messageTextXML)
 {
     return(TransformUBBStringToHTML(ubbString, true, true, parserData, out parserLog, out errorsOccured, out messageTextXML));
 }
コード例 #5
0
        /// <summary>
        /// Transforms the given text with all its forumtags to HTML using the specified XSL template and returns that HTML string. The
        /// XSL template is cached inside the Application object, so the name specified is the name of the Application object's property holding the
        /// XSL template.
        /// </summary>
        /// <param name="ubbString">Text to transform</param>
        /// <param name="isMessageTransform">Pass true to use the message style and false to use the signature style </param>
        /// <param name="performHtmlConversion">set to false when the parser is just used to create a wordlist.</param>
        /// <param name="parserData">The parser data.</param>
        /// <param name="parserLog">Output parameter, contains the parserlog of the parse process</param>
        /// <param name="errorsOccured">Output parameter, contains true if the parser found one or more errors in sUBBString, false otherwise</param>
        /// <param name="messageTextXML">THe parser result as XML string</param>
        /// <returns>ubbString in HTML format</returns>
        private static string TransformUBBStringToHTML(string ubbString, bool isMessageTransform, bool performHtmlConversion, ParserData parserData, out string parserLog,
                                                       out bool errorsOccured, out string messageTextXML)
        {
            parserLog     = string.Empty;
            errorsOccured = false;

            messageTextXML = string.Empty;

            if (ubbString == null)
            {
                return("");
            }

            // parse it
            try
            {
                XmlDocument emitterResult = Converter.ConvertToXml(ubbString);
                messageTextXML = emitterResult.OuterXml;
                errorsOccured  = false;

                if (performHtmlConversion)
                {
                    // Transform Emitter result into HTML using the xsl specified.
                    XslCompiledTransform xslTransformer = parserData.MessageStyle;
                    if (!isMessageTransform)
                    {
                        xslTransformer = parserData.SignatureStyle;
                    }

                    // in .NET 2.0, the XmlCompiledTransform doesn't have a way to transform to a reader or string. So we'll transform to a stream
                    // which we'll use to read back into a stringbuilder which is faster with replacing tab characters to 4 spaces.
                    MemoryStream outputStream = new MemoryStream();
                    xslTransformer.Transform(emitterResult, null, outputStream);
                    outputStream.Seek(0, SeekOrigin.Begin);

                    StreamReader  reader     = new StreamReader(outputStream);
                    StringBuilder htmlOutput = new StringBuilder(reader.ReadToEnd());
                    reader.Close();                             // closes underlying stream as well.

                    // replace any tab chars with 4 HTML spaces
                    return(htmlOutput.ToString());
                }
                else
                {
                    return(string.Empty);
                }
            }
            catch
            {
                // exception occured. Don't proceed with passed in text, simply return empty string.
                errorsOccured = true;
                return(string.Empty);
            }
        }
コード例 #6
0
ファイル: UserManager.cs プロジェクト: priaonehaha/HnD
        /// <summary>
        /// Updates the given user's profile data using the values of the properties of this class.
        /// </summary>
        /// <param name="userID">The user ID.</param>
        /// <param name="dateOfBirth">The date of birth.</param>
        /// <param name="emailAddress">The email address.</param>
        /// <param name="emailAddressIsPublic">flag to signal if the emailaddress is visible for everyone or not</param>
        /// <param name="iconURL">The icon URL.</param>
        /// <param name="location">The location.</param>
        /// <param name="occupation">The occupation.</param>
        /// <param name="password">The password.</param>
        /// <param name="signature">The signature.</param>
        /// <param name="website">The website.</param>
        /// <param name="userTitleID">The user title ID.</param>
        /// <param name="parserData">The parser data.</param>
        /// <param name="autoSubscribeThreads">Default value when user creates new threads.</param>
        /// <param name="defaultMessagesPerPage">Messages per page to display</param>
        /// <returns>true if succeeded, false otherwise</returns>
        public static bool UpdateUserProfile(int userID, DateTime? dateOfBirth, string emailAddress, bool emailAddressIsPublic, string iconURL,
            string location, string occupation, string password, string signature, string website, int userTitleID, ParserData parserData,
            bool autoSubscribeThreads, short defaultMessagesPerPage)
        {
            UserEntity user = UserGuiHelper.GetUser(userID);
            if (user == null)
            {
                // not found
                return false;
            }

            user.DateOfBirth = dateOfBirth;
            user.EmailAddress = emailAddress;
            user.EmailAddressIsPublic = emailAddressIsPublic;
            user.IconURL = iconURL;
            user.Location = location;
            user.Occupation = occupation;
            user.UserTitleID = userTitleID;

            if(!string.IsNullOrEmpty(password))
            {
                user.Password = HnDGeneralUtils.CreateMD5HashedBase64String(password);
            }
            user.Signature = signature;
            if(!string.IsNullOrEmpty(signature))
            {
                user.SignatureAsHTML = TextParser.TransformSignatureUBBStringToHTML(signature, parserData);
            }
            else
            {
                user.SignatureAsHTML = "";
            }

            user.Website = website;

            //Preferences
            user.AutoSubscribeToThread = autoSubscribeThreads;
            user.DefaultNumberOfMessagesPerPage = defaultMessagesPerPage;

            // first encode fields which could lead to cross-site-scripting attacks
            EncodeUserTextFields(user);

            // Update the record
            return user.Save(true);
        }
コード例 #7
0
ファイル: UserManager.cs プロジェクト: priaonehaha/HnD
        /// <summary>
        /// Registers a new user, using the properties of this class.
        /// </summary>
        /// <param name="nickName">Name of the nick.</param>
        /// <param name="dateOfBirth">The date of birth.</param>
        /// <param name="emailAddress">The email address.</param>
        /// <param name="emailAddressIsPublic">flag to signal if the emailaddress is visible for everyone or not</param>
        /// <param name="iconURL">The icon URL.</param>
        /// <param name="ipNumber">The ip number.</param>
        /// <param name="location">The location.</param>
        /// <param name="occupation">The occupation.</param>
        /// <param name="signature">The signature.</param>
        /// <param name="website">The website.</param>
        /// <param name="emailTemplatePath">The email template path.</param>
        /// <param name="emailData">The email data.</param>
        /// <param name="autoSubscribeThreads">Default value when user creates new threads.</param>
        /// <param name="defaultMessagesPerPage">Messages per page to display</param>
        /// <returns>
        /// UserID of new user or 0 if registration failed.
        /// </returns>
        public static int RegisterNewUser(string nickName, DateTime? dateOfBirth, string emailAddress, bool emailAddressIsPublic, string iconURL,
            string ipNumber, string location, string occupation, string signature, string website, string emailTemplatePath, Dictionary<string, string> emailData, ParserData parserData,
            bool autoSubscribeThreads, short defaultMessagesPerPage)
        {
            UserEntity newUser = new UserEntity();

            // initialize objects
            newUser.AmountOfPostings = 0;
            newUser.DateOfBirth = dateOfBirth;
            newUser.EmailAddress = emailAddress;
            newUser.EmailAddressIsPublic = emailAddressIsPublic;
            newUser.IPNumber = ipNumber;
            newUser.IconURL = iconURL;
            newUser.IsBanned = false;
            newUser.JoinDate = DateTime.Now;
            newUser.Location = location;
            newUser.NickName = nickName;
            newUser.Occupation = occupation;
            newUser.Signature = signature;
            newUser.Website = website;
            string password = HnDGeneralUtils.GenerateRandomPassword();
            newUser.Password = HnDGeneralUtils.CreateMD5HashedBase64String(password);

            //Preferences
            newUser.AutoSubscribeToThread = autoSubscribeThreads;
            newUser.DefaultNumberOfMessagesPerPage = defaultMessagesPerPage;

            if(!string.IsNullOrEmpty(signature))
            {
                newUser.SignatureAsHTML = TextParser.TransformSignatureUBBStringToHTML(signature, parserData);
            }
            else
            {
                newUser.SignatureAsHTML = "";
            }
            //Fetch the SystemDataEntity to use the "DefaultUserTitleNewUser" as the user title & the "DefaultRoleNewUser"
            // as the roleID of the newly created RoleUserEntity.
            SystemDataEntity systemData = SystemGuiHelper.GetSystemSettings();
            newUser.UserTitleID = systemData.DefaultUserTitleNewUser;

            RoleUserEntity roleUser = new RoleUserEntity();
            roleUser.RoleID = systemData.DefaultRoleNewUser;
            roleUser.User = newUser;

            // first encode fields which could lead to cross-site-scripting attacks
            EncodeUserTextFields(newUser);

            // now save the new user entity and the new RoleUser entity recursively in one go. This will create a transaction for us
            // under the hood so we don't have to do that ourselves.
            if (newUser.Save(true))
            {
                // all ok, Email the password
                bool result = HnDGeneralUtils.EmailPassword(password, emailAddress, emailTemplatePath, emailData);

            }

            return newUser.UserID;
        }
コード例 #8
0
ファイル: TextParser.cs プロジェクト: priaonehaha/HnD
 /// <summary>
 /// Will transform a given signature to HTML using the UBB parser. Only several tags are supported. These tags are filtered by the
 /// special signature xsl sheet. The input is already limited to the maximum signature size.
 /// </summary>
 /// <param name="signature">Signature to transform to HTML</param>
 /// <param name="parserData">The parser data.</param>
 /// <returns>Signature in HTML format.</returns>
 public static string TransformSignatureUBBStringToHTML(string signature, ParserData parserData)
 {
     string parserLog, messageTextXML;
     bool errorsOccured;
     return TransformUBBStringToHTML(signature, false, true, parserData, out parserLog, out errorsOccured, out messageTextXML);
 }
コード例 #9
0
ファイル: TextParser.cs プロジェクト: priaonehaha/HnD
        /// <summary>
        /// Transforms the given text with all its forumtags to HTML using the specified XSL template and returns that HTML string. The
        /// XSL template is cached inside the Application object, so the name specified is the name of the Application object's property holding the
        /// XSL template.
        /// </summary>
        /// <param name="ubbString">Text to transform</param>
        /// <param name="isMessageTransform">Pass true to use the message style and false to use the signature style </param>
        /// <param name="performHtmlConversion">set to false when the parser is just used to create a wordlist.</param>
        /// <param name="parserData">The parser data.</param>
        /// <param name="parserLog">Output parameter, contains the parserlog of the parse process</param>
        /// <param name="errorsOccured">Output parameter, contains true if the parser found one or more errors in sUBBString, false otherwise</param>
        /// <param name="messageTextXML">THe parser result as XML string</param>
        /// <returns>ubbString in HTML format</returns>
        private static string TransformUBBStringToHTML(string ubbString, bool isMessageTransform, bool performHtmlConversion, ParserData parserData, out string parserLog, 
            out bool errorsOccured, out string messageTextXML)
        {
            parserLog=string.Empty;
            errorsOccured=false;

            messageTextXML = string.Empty;

            if(ubbString==null)
            {
                return "";
            }

            // parse it
            try
            {
                XmlDocument emitterResult = Converter.ConvertToXml(ubbString);
                messageTextXML = emitterResult.OuterXml;
                errorsOccured = false;

                if(performHtmlConversion)
                {
                    // Transform Emitter result into HTML using the xsl specified.
                    XslCompiledTransform xslTransformer = parserData.MessageStyle;
                    if (!isMessageTransform)
                    {
                        xslTransformer = parserData.SignatureStyle;
                    }

                    // in .NET 2.0, the XmlCompiledTransform doesn't have a way to transform to a reader or string. So we'll transform to a stream
                    // which we'll use to read back into a stringbuilder which is faster with replacing tab characters to 4 spaces.
                    MemoryStream outputStream = new MemoryStream();
                    xslTransformer.Transform(emitterResult, null, outputStream);
                    outputStream.Seek(0, SeekOrigin.Begin);

                    StreamReader reader = new StreamReader(outputStream);
                    StringBuilder htmlOutput = new StringBuilder(reader.ReadToEnd());
                    reader.Close();		// closes underlying stream as well.

                    // replace any tab chars with 4 HTML spaces
                    htmlOutput.Replace("\t", "&nbsp;&nbsp;&nbsp;&nbsp;");
                    return htmlOutput.ToString();
                }
                else
                {
                    return string.Empty;
                }
            }
            catch
            {
                // exception occured. Don't proceed with passed in text, simply return empty string.
                errorsOccured=true;
                return string.Empty;
            }
        }
コード例 #10
0
ファイル: TextParser.cs プロジェクト: priaonehaha/HnD
 /// <summary>
 /// Transforms the given message with all its forumtags to HTML using the specified XSL template and returns that HTML string. The
 /// XSL template is cached inside the Application object, so the name specified is the name of the Application object's property holding the
 /// XSL template.
 /// </summary>
 /// <param name="ubbString">Text to transform</param>
 /// <param name="parserData">The parser data.</param>
 /// <param name="parserLog">Output parameter, contains the parserlog of the parse process</param>
 /// <param name="errorsOccured">Output parameter, contains true if the parser found one or more errors in sUBBString, false otherwise</param>
 /// <param name="messageTextXML">The parse result in XML format (string)</param>
 /// <returns>ubbString in HTML format</returns>
 public static string TransformUBBMessageStringToHTML(string ubbString, ParserData parserData, out string parserLog, out bool errorsOccured, out string messageTextXML)
 {
     return TransformUBBStringToHTML(ubbString, true, true, parserData, out parserLog, out errorsOccured, out messageTextXML);
 }
コード例 #11
0
ファイル: MessageManager.cs プロジェクト: priaonehaha/HnD
        /// <summary>
        /// Re-parses all messages from start date till now or when amountToIndex is reached. This routine will read messagetext for a message,
        /// parse it, and update the MessageTextAsXML field with the parse result. 
        /// </summary>
        /// <param name="amountToParse">Amount to parse.</param>
        /// <param name="startDate">Start date.</param>
        /// <param name="reGenerateHTML">If true, the HTML is also re-generated and saved.</param>
        /// <returns>the amount of messages re-parsed</returns>
        public static int ReParseMessages(int amountToParse, DateTime startDate, bool reGenerateHTML, ParserData parserData)
        {
            // index is blocks of 100 messages.
            var qf = new QueryFactory();
            var q = qf.Create()
                        .Select(MessageFields.MessageID, MessageFields.MessageText)
                        .Where(MessageFields.PostingDate >= new DateTime(startDate.Year, startDate.Month, startDate.Day, 0, 0, 0, 0));

            if(amountToParse <= 0)
            {
                // If we don't have a specific amount of messages to parse, then parse all messages posted till Now.
                q.AndWhere(MessageFields.PostingDate <= DateTime.Now);
            }

            TypedListDAO dao = new TypedListDAO();

            bool parsingFinished = false;
            int amountProcessed = 0;
            int pageSize = 100;
            int pageNo = 1;

            while(!parsingFinished)
            {
                q.Page(pageNo, pageSize);
                DataTable messagesToParse = dao.FetchAsDataTable(q);
                parsingFinished = (messagesToParse.Rows.Count <= 0);

                if(!parsingFinished)
                {
                    foreach(DataRow row in messagesToParse.Rows)
                    {
                        MessageEntity directUpdater = new MessageEntity();
                        directUpdater.IsNew = false;

                        string messageXML = string.Empty;
                        string messageHTML = string.Empty;
                        TextParser.ReParseMessage((string)row["MessageText"], reGenerateHTML, parserData, out messageXML, out messageHTML);

                        // use the directupdater entity to create an update query without fetching the entity first.
                        directUpdater.Fields[(int)MessageFieldIndex.MessageID].ForcedCurrentValueWrite((int)row["MessageID"]);
                        directUpdater.MessageTextAsXml = messageXML;

                        if(reGenerateHTML)
                        {
                            directUpdater.MessageTextAsHTML=messageHTML;
                        }
                        directUpdater.Fields.IsDirty=true;

                        // no transactional update.
                        directUpdater.Save();
                    }

                    amountProcessed += messagesToParse.Rows.Count;
                    pageNo++;

                    if(amountToParse > 0)
                    {
                        parsingFinished = (amountToParse <= amountProcessed);
                    }
                }
            }
            return amountProcessed;
        }
コード例 #12
0
ファイル: ApplicationAdapter.cs プロジェクト: priaonehaha/HnD
        /// <summary>
        /// Create a DTO of all needed e-mail default data.
        /// </summary>
        /// <returns>a dictionary of the following keys (grammar, actionTable, gotoTable, messageStyle, signatureStyle)</returns>
        public static ParserData GetParserData()
        {
            ParserData data = new ParserData();
            data.MessageStyle = GetMessageStyle();
            data.SignatureStyle = GetSignatureStyle();

            return data;
        }