コード例 #1
0
        /// <summary>
        /// Formats the forum post text
        /// </summary>
        /// <param name="forumPost">Forum post</param>
        /// <returns>Formatted text</returns>
        public static string FormatPostText(this ForumPost forumPost)
        {
            string text = forumPost.Text;

            if (String.IsNullOrEmpty(text))
            {
                return(string.Empty);
            }

            switch (EngineContext.Current.Resolve <ForumSettings>().ForumEditor)
            {
            case EditorType.SimpleTextBox:
            {
                text = HtmlUtils.FormatText(text, false, true, false, false, false, false);
            }
            break;

            case EditorType.BBCodeEditor:
            {
                text = HtmlUtils.FormatText(text, false, true, false, true, false, false);
            }
            break;

            default:
                break;
            }

            return(text);
        }
コード例 #2
0
        public static string ConvertToText(string sHTML)
        {
            var formattedHtml = HtmlUtils.FormatText(sHTML, true);
            var styleLessHtml = HtmlUtils.RemoveInlineStyle(formattedHtml);

            return(HtmlUtils.StripTags(styleLessHtml, true));
        }
コード例 #3
0
ファイル: Mail.cs プロジェクト: misterPaul0/Curt
        public static string ConvertToText(string sHTML)
        {
            string sContent = sHTML;

            sContent = sContent.Replace("<br />", Environment.NewLine);
            sContent = sContent.Replace("<br>", Environment.NewLine);
            sContent = HtmlUtils.FormatText(sContent, true);
            return(HtmlUtils.StripTags(sContent, true));
        }
コード例 #4
0
        /// <summary>
        /// Formats the forum signature text
        /// </summary>
        /// <param name="text">Text</param>
        /// <returns>Formatted text</returns>
        public static string FormatForumSignatureText(this string text)
        {
            if (String.IsNullOrEmpty(text))
            {
                return(string.Empty);
            }

            text = HtmlUtils.FormatText(text, false, true, false, false, false, false);
            return(text);
        }
コード例 #5
0
        /// <summary>
        /// Formats the order note text
        /// </summary>
        /// <param name="orderNote">Order note</param>
        /// <returns>Formatted text</returns>
        public static string FormatOrderNoteText(this OrderNote orderNote)
        {
            Guard.NotNull(orderNote, nameof(orderNote));

            if (orderNote.Note.IsEmpty())
            {
                return(string.Empty);
            }

            return(HtmlUtils.FormatText(orderNote.Note, false, true, true, false, false, false));
        }
コード例 #6
0
        /// <summary>
        /// Formats the private message text
        /// </summary>
        /// <param name="pm">Private message</param>
        /// <returns>Formatted text</returns>
        public static string FormatPrivateMessageText(this PrivateMessage pm)
        {
            string text = pm.Text;

            if (String.IsNullOrEmpty(text))
            {
                return(string.Empty);
            }

            text = HtmlUtils.FormatText(text, false, true, false, true, false, false);

            return(text);
        }
コード例 #7
0
        protected virtual object CreateModelPart(ProductReview part, MessageContext messageContext)
        {
            Guard.NotNull(messageContext, nameof(messageContext));
            Guard.NotNull(part, nameof(part));

            var m = new Dictionary <string, object>
            {
                { "Title", part.Title.NullEmpty() },
                { "Text", HtmlUtils.FormatText(part.ReviewText, true, false, false, false, false, false).NullEmpty() },
                { "Rating", part.Rating }
            };

            PublishModelPartCreatedEvent <ProductReview>(part, m);

            return(m);
        }
コード例 #8
0
        protected virtual object CreateModelPart(NewsComment part, MessageContext messageContext)
        {
            Guard.NotNull(messageContext, nameof(messageContext));
            Guard.NotNull(part, nameof(part));

            var m = new Dictionary <string, object>
            {
                { "NewsTitle", part.NewsItem.Title.NullEmpty() },
                { "Title", part.CommentTitle.NullEmpty() },
                { "Text", HtmlUtils.FormatText(part.CommentText, true, false, false, false, false, false).NullEmpty() },
                { "NewsUrl", BuildRouteUrl("NewsItem", new { SeName = part.NewsItem.GetSeName(messageContext.Language.Id) }, messageContext) }
            };

            PublishModelPartCreatedEvent <NewsComment>(part, m);

            return(m);
        }
コード例 #9
0
        /// <summary>
        /// Formats the order note text
        /// </summary>
        /// <param name="orderNote">Order note</param>
        /// <returns>Formatted text</returns>
        public static string FormatOrderNoteText(this OrderNote orderNote)
        {
            if (orderNote == null)
            {
                throw new ArgumentNullException("orderNote");
            }

            string text = orderNote.Note;

            if (String.IsNullOrEmpty(text))
            {
                return(string.Empty);
            }

            text = HtmlUtils.FormatText(text, false, true, true, false, false, false);

            return(text);
        }
コード例 #10
0
        protected virtual object CreateModelPart(ReturnRequest part, MessageContext messageContext)
        {
            Guard.NotNull(messageContext, nameof(messageContext));
            Guard.NotNull(part, nameof(part));

            var m = new Dictionary <string, object>
            {
                { "Id", part.Id },
                { "Reason", part.ReasonForReturn.NullEmpty() },
                { "Status", part.ReturnRequestStatus.GetLocalizedEnum(_services.Localization, messageContext.Language.Id) },
                { "RequestedAction", part.RequestedAction.NullEmpty() },
                { "CustomerComments", HtmlUtils.FormatText(part.CustomerComments, true, false, false, false, false, false).NullEmpty() },
                { "StaffNotes", HtmlUtils.FormatText(part.StaffNotes, true, false, false, false, false, false).NullEmpty() },
                { "Quantity", part.Quantity },
                { "Url", BuildActionUrl("Edit", "ReturnRequest", new { id = part.Id, area = "admin" }, messageContext) }
            };

            PublishModelPartCreatedEvent <ReturnRequest>(part, m);

            return(m);
        }
コード例 #11
0
        protected virtual object CreateModelPart(GiftCard part, MessageContext messageContext)
        {
            Guard.NotNull(messageContext, nameof(messageContext));
            Guard.NotNull(part, nameof(part));

            var m = new Dictionary <string, object>
            {
                { "Id", part.Id },
                { "SenderName", part.SenderName.NullEmpty() },
                { "SenderEmail", part.SenderEmail.NullEmpty() },
                { "RecipientName", part.RecipientName.NullEmpty() },
                { "RecipientEmail", part.RecipientEmail.NullEmpty() },
                { "Amount", _services.Resolve <IPriceFormatter>().FormatPrice(part.Amount, true, false) },
                { "CouponCode", part.GiftCardCouponCode.NullEmpty() }
            };

            // Message
            var message = (string)null;

            if (part.Message.HasValue())
            {
                message = HtmlUtils.FormatText(part.Message, true, false, false, false, false, false);
            }
            m["Message"] = message;

            // RemainingAmount
            var remainingAmount = (string)null;
            var order           = part?.PurchasedWithOrderItem?.Order;

            if (order != null)
            {
                var amount = _services.Resolve <ICurrencyService>().ConvertCurrency(part.GetGiftCardRemainingAmount(), order.CurrencyRate);
                remainingAmount = _services.Resolve <IPriceFormatter>().FormatPrice(amount, true, false);
            }
            m["RemainingAmount"] = remainingAmount;

            PublishModelPartCreatedEvent <GiftCard>(part, m);

            return(m);
        }
コード例 #12
0
        private static void RegisterConvertHtmlToTextHelper(HandlebarsDotNet.IHandlebars hbs)
        {
            hbs.RegisterHelper("convertHtmlToText", (writer, context, parameters) =>
            {
                try
                {
                    string html = parameters[0].ToString();
                    //string res = DotNetNuke.Services.Mail.Mail.ConvertToText(html);

                    var formattedHtml = HtmlUtils.FormatText(html, true);
                    //var styleLessHtml = HtmlUtils.RemoveInlineStyle(formattedHtml);
                    var styleLessHtml = RemoveInlineStylesRegEx.Replace(formattedHtml, string.Empty);
                    string res        = HtmlUtils.StripTags(styleLessHtml, true);

                    writer.WriteSafeString(res);
                }
                catch (Exception)
                {
                    writer.WriteSafeString("");
                }
            });
        }
コード例 #13
0
        /// <Summary>
        /// Formats Html as text by removing  tags and replacing by linefeeds
        /// </Summary>
        /// <Param name="strHtml">Html to format</Param>
        /// <Returns>The formatted text</Returns>
        private string FormatText(string strHtml)
        {
            string strText = strHtml;

            try
            {
                if (!String.IsNullOrEmpty(strText))
                {
                    //First remove white space (html does not render white space anyway and it screws up the conversion to text)
                    //Replace it by a single space
                    strText = HtmlUtils.StripWhiteSpace(strText, true);

                    //Replace all variants of <br> by Linefeeds
                    strText = HtmlUtils.FormatText(strText, false);
                }
            }
            catch (Exception exc) //Module failed to load
            {
                Exceptions.ProcessModuleLoadException(this, exc);
            }

            return(strText);
        }
コード例 #14
0
        /// <summary>
        /// Formats attributes
        /// </summary>
        /// <param name="attributes">Attributes</param>
        /// <param name="customer">Customer</param>
        /// <param name="serapator">Serapator</param>
        /// <param name="htmlEncode">A value indicating whether to encode (HTML) values</param>
        /// <param name="renderPrices">A value indicating whether to render prices</param>
        /// <param name="allowHyperlinks">A value indicating whether to HTML hyperink tags could be rendered (if required)</param>
        /// <returns>Attributes</returns>
        public string FormatAttributes(string attributes,
                                       Customer customer,
                                       string serapator     = "<br />",
                                       bool htmlEncode      = true,
                                       bool renderPrices    = true,
                                       bool allowHyperlinks = true)
        {
            var result = new StringBuilder();

            var caCollection = _checkoutAttributeParser.ParseCheckoutAttributes(attributes);

            if (caCollection.Count <= 0)
            {
                return(null);
            }
            for (int i = 0; i < caCollection.Count; i++)
            {
                var ca        = caCollection[i];
                var valuesStr = _checkoutAttributeParser.ParseValues(attributes, ca.Id);
                for (int j = 0; j < valuesStr.Count; j++)
                {
                    string valueStr    = valuesStr[j];
                    string caAttribute = "";
                    if (!ca.ShouldHaveValues())
                    {
                        //no values
                        if (ca.AttributeControlType == AttributeControlType.MultilineTextbox)
                        {
                            //multiline textbox
                            string attributeName = ca.GetLocalized(a => a.Name, _workContext.WorkingLanguage);
                            //encode (if required)
                            if (htmlEncode)
                            {
                                attributeName = HttpUtility.HtmlEncode(attributeName);
                            }

                            caAttribute = string.Format("{0}: {1}", attributeName,
                                                        HtmlUtils.FormatText(valueStr.EmptyNull().Replace(":", ""), false, true, false, false, false, false));

                            //we never encode multiline textbox input
                        }
                        else if (ca.AttributeControlType == AttributeControlType.FileUpload)
                        {
                            //file upload
                            Guid downloadGuid;
                            Guid.TryParse(valueStr, out downloadGuid);
                            var download = _downloadService.GetDownloadByGuid(downloadGuid);
                            if (download != null)
                            {
                                //TODO add a method for getting URL (use routing because it handles all SEO friendly URLs)
                                string attributeText = "";
                                var    fileName      = string.Format("{0}{1}",
                                                                     download.Filename ?? download.DownloadGuid.ToString(),
                                                                     download.Extension);
                                //encode (if required)
                                if (htmlEncode)
                                {
                                    fileName = HttpUtility.HtmlEncode(fileName);
                                }
                                if (allowHyperlinks)
                                {
                                    //hyperlinks are allowed
                                    var downloadLink = string.Format("{0}download/getfileupload/?downloadId={1}", _webHelper.GetStoreLocation(false), download.DownloadGuid);
                                    attributeText = string.Format("<a href=\"{0}\" class=\"fileuploadattribute\">{1}</a>", downloadLink, fileName);
                                }
                                else
                                {
                                    //hyperlinks aren't allowed
                                    attributeText = fileName;
                                }
                                string attributeName = ca.GetLocalized(a => a.Name, _workContext.WorkingLanguage);
                                //encode (if required)
                                if (htmlEncode)
                                {
                                    attributeName = HttpUtility.HtmlEncode(attributeName);
                                }
                                caAttribute = string.Format("{0}: {1}", attributeName, attributeText);
                            }
                        }
                        else
                        {
                            //other attributes (textbox, datepicker)
                            caAttribute = string.Format("{0}: {1}", ca.GetLocalized(a => a.Name, _workContext.WorkingLanguage), valueStr);
                            //encode (if required)
                            if (htmlEncode)
                            {
                                caAttribute = HttpUtility.HtmlEncode(caAttribute);
                            }
                        }
                    }
                    else
                    {
                        int caId = 0;
                        if (int.TryParse(valueStr, out caId))
                        {
                            var caValue = _checkoutAttributeService.GetCheckoutAttributeValueById(caId);
                            if (caValue != null)
                            {
                                caAttribute = string.Format("{0}: {1}", ca.GetLocalized(a => a.Name, _workContext.WorkingLanguage), caValue.GetLocalized(a => a.Name, _workContext.WorkingLanguage));
                                if (renderPrices)
                                {
                                    decimal priceAdjustmentBase = _taxService.GetCheckoutAttributePrice(caValue, customer);
                                    decimal priceAdjustment     = _currencyService.ConvertFromPrimaryStoreCurrency(priceAdjustmentBase, _workContext.WorkingCurrency);
                                    if (priceAdjustmentBase > 0)
                                    {
                                        string priceAdjustmentStr = _priceFormatter.FormatPrice(priceAdjustment);
                                        caAttribute += string.Format(" [+{0}]", priceAdjustmentStr);
                                    }
                                }
                            }
                            //encode (if required)
                            if (htmlEncode)
                            {
                                caAttribute = HttpUtility.HtmlEncode(caAttribute);
                            }
                        }
                    }

                    if (!String.IsNullOrEmpty(caAttribute))
                    {
                        if (i != 0 || j != 0)
                        {
                            result.Append(serapator);
                        }
                        result.Append(caAttribute);
                    }
                }
            }

            return(result.ToString());
        }
コード例 #15
0
        /// <summary>
        /// Formats attributes
        /// </summary>
        /// <param name="product">Product</param>
        /// <param name="attributes">Attributes</param>
        /// <param name="customer">Customer</param>
        /// <param name="serapator">Serapator</param>
        /// <param name="htmlEncode">A value indicating whether to encode (HTML) values</param>
        /// <param name="renderPrices">A value indicating whether to render prices</param>
        /// <param name="renderProductAttributes">A value indicating whether to render product attributes</param>
        /// <param name="renderGiftCardAttributes">A value indicating whether to render gift card attributes</param>
        /// <param name="allowHyperlinks">A value indicating whether to HTML hyperink tags could be rendered (if required)</param>
        /// <returns>Attributes</returns>
        public string FormatAttributes(Product product, string attributes,
                                       Customer customer, string serapator = "<br />", bool htmlEncode           = true, bool renderPrices = true,
                                       bool renderProductAttributes        = true, bool renderGiftCardAttributes = true,
                                       bool allowHyperlinks = true)
        {
            var result     = new StringBuilder();
            var languageId = _workContext.WorkingLanguage.Id;

            // Attributes
            if (renderProductAttributes)
            {
                var pvaCollection = _productAttributeParser.ParseProductVariantAttributes(attributes);
                for (int i = 0; i < pvaCollection.Count; i++)
                {
                    var pva       = pvaCollection[i];
                    var valuesStr = _productAttributeParser.ParseValues(attributes, pva.Id);
                    for (int j = 0; j < valuesStr.Count; j++)
                    {
                        string valueStr     = valuesStr[j];
                        string pvaAttribute = string.Empty;
                        if (!pva.ShouldHaveValues())
                        {
                            //no values
                            if (pva.AttributeControlType == AttributeControlType.MultilineTextbox)
                            {
                                //multiline textbox
                                var attributeName = pva.ProductAttribute.GetLocalized(a => a.Name, languageId);
                                //encode (if required)
                                if (htmlEncode)
                                {
                                    attributeName = HttpUtility.HtmlEncode(attributeName);
                                }
                                pvaAttribute = string.Format("{0}: {1}", attributeName, HtmlUtils.FormatText(valueStr, false, true, false, false, false, false));
                                //we never encode multiline textbox input
                            }
                            else if (pva.AttributeControlType == AttributeControlType.FileUpload)
                            {
                                //file upload
                                Guid downloadGuid;
                                Guid.TryParse(valueStr, out downloadGuid);
                                var download = _downloadService.GetDownloadByGuid(downloadGuid);
                                if (download != null)
                                {
                                    //TODO add a method for getting URL (use routing because it handles all SEO friendly URLs)
                                    string attributeText = "";
                                    var    fileName      = string.Format("{0}{1}",
                                                                         download.Filename ?? download.DownloadGuid.ToString(),
                                                                         download.Extension);
                                    //encode (if required)
                                    if (htmlEncode)
                                    {
                                        fileName = HttpUtility.HtmlEncode(fileName);
                                    }
                                    if (allowHyperlinks)
                                    {
                                        //hyperlinks are allowed
                                        var downloadLink = string.Format("{0}download/getfileupload/?downloadId={1}", _webHelper.GetStoreLocation(false), download.DownloadGuid);
                                        attributeText = string.Format("<a href=\"{0}\" class=\"fileuploadattribute\">{1}</a>", downloadLink, fileName);
                                    }
                                    else
                                    {
                                        //hyperlinks aren't allowed
                                        attributeText = fileName;
                                    }
                                    var attributeName = pva.ProductAttribute.GetLocalized(a => a.Name, languageId);
                                    //encode (if required)
                                    if (htmlEncode)
                                    {
                                        attributeName = HttpUtility.HtmlEncode(attributeName);
                                    }
                                    pvaAttribute = string.Format("{0}: {1}", attributeName, attributeText);
                                }
                            }
                            else
                            {
                                //other attributes (textbox, datepicker)
                                pvaAttribute = string.Format("{0}: {1}", pva.ProductAttribute.GetLocalized(a => a.Name, languageId), valueStr);
                                //encode (if required)
                                if (htmlEncode)
                                {
                                    pvaAttribute = HttpUtility.HtmlEncode(pvaAttribute);
                                }
                            }
                        }
                        else
                        {
                            // Attributes with values.
                            int pvaId = 0;
                            if (int.TryParse(valueStr, out pvaId))
                            {
                                var pvaValue = _productAttributeService.GetProductVariantAttributeValueById(pvaId);
                                if (pvaValue != null)
                                {
                                    pvaAttribute = "{0}: {1}".FormatInvariant(
                                        pva.ProductAttribute.GetLocalized(a => a.Name, languageId),
                                        pvaValue.GetLocalized(a => a.Name, languageId));

                                    if (renderPrices)
                                    {
                                        decimal taxRate = decimal.Zero;
                                        decimal attributeValuePriceAdjustment = _priceCalculationService.GetProductVariantAttributeValuePriceAdjustment(pvaValue, product, customer, null, 1);
                                        decimal priceAdjustmentBase           = _taxService.GetProductPrice(product, attributeValuePriceAdjustment, customer, out taxRate);
                                        decimal priceAdjustment = _currencyService.ConvertFromPrimaryStoreCurrency(priceAdjustmentBase, _workContext.WorkingCurrency);

                                        if (_shoppingCartSettings.ShowLinkedAttributeValueQuantity && pvaValue.ValueType == ProductVariantAttributeValueType.ProductLinkage &&
                                            pvaValue.Quantity > 1)
                                        {
                                            pvaAttribute += string.Format(" × {0}", pvaValue.Quantity);
                                        }

                                        if (_catalogSettings.ShowVariantCombinationPriceAdjustment)
                                        {
                                            if (priceAdjustmentBase > 0)
                                            {
                                                pvaAttribute += " (+{0})".FormatInvariant(_priceFormatter.FormatPrice(priceAdjustment, true, false));
                                            }
                                            else if (priceAdjustmentBase < decimal.Zero)
                                            {
                                                pvaAttribute += " (-{0})".FormatInvariant(_priceFormatter.FormatPrice(-priceAdjustment, true, false));
                                            }
                                        }
                                    }
                                }

                                // Encode (if required)
                                if (htmlEncode)
                                {
                                    pvaAttribute = HttpUtility.HtmlEncode(pvaAttribute);
                                }
                            }
                        }

                        if (!String.IsNullOrEmpty(pvaAttribute))
                        {
                            if (i != 0 || j != 0)
                            {
                                result.Append(serapator);
                            }
                            result.Append(pvaAttribute);
                        }
                    }
                }
            }

            //gift cards
            if (renderGiftCardAttributes)
            {
                if (product.IsGiftCard)
                {
                    string giftCardRecipientName  = "";
                    string giftCardRecipientEmail = "";
                    string giftCardSenderName     = "";
                    string giftCardSenderEmail    = "";
                    string giftCardMessage        = "";
                    _productAttributeParser.GetGiftCardAttribute(attributes, out giftCardRecipientName, out giftCardRecipientEmail,
                                                                 out giftCardSenderName, out giftCardSenderEmail, out giftCardMessage);

                    //sender
                    var giftCardFrom = product.GiftCardType == GiftCardType.Virtual ?
                                       string.Format(_localizationService.GetResource("GiftCardAttribute.From.Virtual"), giftCardSenderName, giftCardSenderEmail) :
                                       string.Format(_localizationService.GetResource("GiftCardAttribute.From.Physical"), giftCardSenderName);
                    //recipient
                    var giftCardFor = product.GiftCardType == GiftCardType.Virtual ?
                                      string.Format(_localizationService.GetResource("GiftCardAttribute.For.Virtual"), giftCardRecipientName, giftCardRecipientEmail) :
                                      string.Format(_localizationService.GetResource("GiftCardAttribute.For.Physical"), giftCardRecipientName);

                    //encode (if required)
                    if (htmlEncode)
                    {
                        giftCardFrom = HttpUtility.HtmlEncode(giftCardFrom);
                        giftCardFor  = HttpUtility.HtmlEncode(giftCardFor);
                    }

                    if (!String.IsNullOrEmpty(result.ToString()))
                    {
                        result.Append(serapator);
                    }
                    result.Append(giftCardFrom);
                    result.Append(serapator);
                    result.Append(giftCardFor);
                }
            }
            return(result.ToString());
        }
コード例 #16
0
        public ActionResult ContactUsSend(ContactUsModel model, bool captchaValid)
        {
            //validate CAPTCHA
            if (_captchaSettings.Value.Enabled && _captchaSettings.Value.ShowOnContactUsPage && !captchaValid)
            {
                ModelState.AddModelError("", T("Common.WrongCaptcha"));
            }

            if (ModelState.IsValid)
            {
                string email    = model.Email.Trim();
                string fullName = model.FullName;
                string subject  = T("ContactUs.EmailSubject", _services.SiteContext.CurrentSite.Name);

                var emailAccount = _emailAccountService.Value.GetEmailAccountById(EngineContext.Current.Resolve <EmailAccountSettings>().DefaultEmailAccountId);
                if (emailAccount == null)
                {
                    emailAccount = _emailAccountService.Value.GetAllEmailAccounts().FirstOrDefault();
                }

                string from     = null;
                string fromName = null;
                string body     = HtmlUtils.FormatText(model.Enquiry, false, true, false, false, false, false);
                //required for some SMTP servers
                if (_commonSettings.Value.UseSystemEmailForContactUsForm)
                {
                    from     = emailAccount.Email;
                    fromName = emailAccount.DisplayName;
                    body     = string.Format("<strong>From</strong>: {0} - {1}<br /><br />{2}",
                                             Server.HtmlEncode(fullName),
                                             Server.HtmlEncode(email), body);
                }
                else
                {
                    from     = email;
                    fromName = fullName;
                }
                _queuedEmailService.Value.InsertQueuedEmail(new QueuedEmail
                {
                    From           = from,
                    FromName       = fromName,
                    To             = emailAccount.Email,
                    ToName         = emailAccount.DisplayName,
                    Priority       = 5,
                    Subject        = subject,
                    Body           = body,
                    CreatedOnUtc   = DateTime.UtcNow,
                    EmailAccountId = emailAccount.Id,
                    ReplyTo        = email,
                    ReplyToName    = fullName
                });

                model.SuccessfullySent = true;
                model.Result           = T("ContactUs.YourEnquiryHasBeenSent");

                //activity log
                _services.UserActivity.InsertActivity("PublicSite.ContactUs", T("ActivityLog.PublicSite.ContactUs"));

                return(View(model));
            }

            model.DisplayCaptcha = _captchaSettings.Value.Enabled && _captchaSettings.Value.ShowOnContactUsPage;
            return(View(model));
        }