Exemplo n.º 1
0
        static string ReplaceAttribute(string output, BBAttribute attribute, string rawValue, string placeholderStr, Dictionary <string, string> attrValuesByID)
        {
            string effectiveValue;

            if (attribute.ContentTransformer == null)
            {
                effectiveValue = rawValue;
            }
            else
            {
                var ctx = new AttributeRenderingContextImpl(attribute, rawValue, attrValuesByID);
                effectiveValue = attribute.ContentTransformer(ctx);
            }

            if (effectiveValue == null)
            {
                effectiveValue = "";
            }

            var encodedValue =
                attribute.HtmlEncodingMode == HtmlEncodingMode.HtmlAttributeEncode ? HttpUtility.HtmlAttributeEncode(effectiveValue)
                    : attribute.HtmlEncodingMode == HtmlEncodingMode.HtmlEncode ? HttpUtility.HtmlEncode(effectiveValue)
                          : effectiveValue;

            output = output.Replace(placeholderStr, encodedValue);
            return(output);
        }
Exemplo n.º 2
0
        string TryGetValue(BBAttribute attr)
        {
            string val;

            AttributeValues.TryGetValue(attr, out val);
            return(val);
        }
Exemplo n.º 3
0
        /// <summary>
        /// Get the node content as a formatted BBCode string.
        /// </summary>
        public override string ToBBCode()
        {
            string content = string.Concat(SubNodes.Select(s => s.ToBBCode()).ToArray());

            string      attrs   = "";
            BBAttribute defAttr = Tag.FindAttribute("");

            if (defAttr != null)
            {
                if (AttributeValues.ContainsKey(defAttr))
                {
                    attrs += "=" + AttributeValues[defAttr];
                }
            }

            foreach (var attrKvp in AttributeValues)
            {
                if (attrKvp.Key.Name == "")
                {
                    continue;
                }

                attrs += " " + attrKvp.Key.Name + "=" + attrKvp.Value;
            }

            return("[" + Tag.Name + attrs + "]" + content + "[/" + Tag.Name + "]");
        }
Exemplo n.º 4
0
        /// <summary>
        /// 添加BBTag实体
        /// </summary>
        /// <param name="htmlTemplate">html模板</param>
        /// <param name="attachment">带替换附件</param>
        /// <returns></returns>
        private BBTag AddBBTagForMobile(string htmlTemplate, Attachment attachment)
        {
            BBAttribute bbAttribute = new BBAttribute("attachTemplate", "",
                                                      n =>
            {
                return(string.Format(htmlTemplate,
                                     attachment.FriendlyFileName,
                                     SiteUrls.FullUrl(SiteUrls.Instance().AttachmentUrl(attachment.AttachmentId, TenantTypeIds.Instance().BlogThread())),
                                     attachment.FriendlyFileLength));
            },
                                                      HtmlEncodingMode.UnsafeDontEncode);

            return(new BBTag("attach:" + attachment.AttachmentId, "${attachTemplate}", "", false, BBTagClosingStyle.LeafElementWithoutContent, null, bbAttribute));
        }
Exemplo n.º 5
0
        /// <summary>
        /// 添加BBTag实体
        /// </summary>
        /// <param name="htmlTemplate">html模板</param>
        /// <param name="attachment">带替换附件</param>
        /// <returns></returns>
        private BBTag AddBBTag(string htmlTemplate, ContentAttachment attachment)
        {
            BBAttribute bbAttribute = new BBAttribute("attachTemplate", "",
                                                      n =>
            {
                return(string.Format(htmlTemplate,
                                     attachment.FriendlyFileName,
                                     attachment.FriendlyFileLength,
                                     attachment.DownloadCount,
                                     SiteUrls.Instance().ContentAttachmentUrl(attachment.AttachmentId)));
            },
                                                      HtmlEncodingMode.UnsafeDontEncode);

            return(new BBTag("attach:" + attachment.AttachmentId, "${attachTemplate}", "", false, BBTagClosingStyle.LeafElementWithoutContent, null, bbAttribute));
        }
Exemplo n.º 6
0
        /// <summary>
        /// 添加BBTag实体
        /// </summary>
        /// <param name="htmlTemplate">html模板</param>
        /// <param name="attachment">带替换附件</param>
        /// <returns></returns>
        private BBTag AddBBTag(string htmlTemplate, Attachment attachment)
        {
            BBAttribute bbAttribute = new BBAttribute("attachTemplate", "",
                                                      n =>
            {
                return(string.Format(htmlTemplate,
                                     attachment.FriendlyFileName,
                                     attachment.FriendlyFileLength,
                                     attachment.Price > 0 ? ",<em>需要" + attachment.Price + "积分</em>" : "",
                                     attachment.DownloadCount,
                                     attachment.AttachmentId));
            },
                                                      HtmlEncodingMode.UnsafeDontEncode);

            return(new BBTag("attach:" + attachment.AttachmentId, "${attachTemplate}", "", false, BBTagClosingStyle.LeafElementWithoutContent, null, bbAttribute));
        }
Exemplo n.º 7
0
        /// <summary>
        /// 添加BBTag实体
        /// </summary>
        /// <param name="htmlTemplate">html模板</param>
        /// <param name="attachment">带替换附件</param>
        /// <returns>BBTag实体</returns>
        private BBTag AddBBTag(string htmlTemplate, Attachment attachment)
        {
            PointCategory pointCategory = new PointService().GetPointCategory(PointCategoryKeys.Instance().TradePoints());
            string        categoryName  = pointCategory != null ? pointCategory.CategoryName : "金币";

            BBAttribute bbAttribute = new BBAttribute("attachTemplate", "",
                                                      n =>
            {
                return(string.Format(htmlTemplate,
                                     attachment.FriendlyFileName,
                                     attachment.FriendlyFileLength,
                                     attachment.Price > 0 ? ",<em>需要" + attachment.Price + categoryName + "</em>" : "",
                                     attachment.DownloadCount,
                                     attachment.AttachmentId));
            },
                                                      HtmlEncodingMode.UnsafeDontEncode);

            return(new BBTag("attach:" + attachment.AttachmentId, "${attachTemplate}", "", false, BBTagClosingStyle.LeafElementWithoutContent, null, bbAttribute));
        }
Exemplo n.º 8
0
 public AttributeRenderingContextImpl(BBAttribute attribute, string attributeValue, IDictionary <string, string> getAttributeValueByIdData)
 {
     Attribute                 = attribute;
     AttributeValue            = attributeValue;
     GetAttributeValueByIDData = getAttributeValueByIdData;
 }
Exemplo n.º 9
0
 public AttributeRenderingContextImpl(BBAttribute attribute, string attributeValue, IDictionary<string, string> getAttributeValueByIdData)
 {
     Attribute = attribute;
     AttributeValue = attributeValue;
     GetAttributeValueByIDData = getAttributeValueByIdData;
 }
Exemplo n.º 10
0
 string TryGetValue(BBAttribute attr)
 {
     string val;
     AttributeValues.TryGetValue(attr, out val);
     return val;
 }
Exemplo n.º 11
0
        static string ReplaceAttribute(string output, BBAttribute attribute, string rawValue, string placeholderStr, Dictionary<string, string> attrValuesByID)
        {
            string effectiveValue;
            if (attribute.ContentTransformer == null)
            {
                effectiveValue = rawValue;
            }
            else
            {
                var ctx = new AttributeRenderingContextImpl(attribute, rawValue, attrValuesByID);
                effectiveValue = attribute.ContentTransformer(ctx);
            }

            if (effectiveValue == null) effectiveValue = "";

            var encodedValue =
                attribute.HtmlEncodingMode == HtmlEncodingMode.HtmlAttributeEncode ? HttpUtility.HtmlAttributeEncode(effectiveValue)
                    : attribute.HtmlEncodingMode == HtmlEncodingMode.HtmlEncode ? HttpUtility.HtmlEncode(effectiveValue)
                          : effectiveValue;
            output = output.Replace(placeholderStr, encodedValue);
            return output;
        }