Пример #1
0
        public override Sitecore.Xml.Xsl.RenderFieldResult Render()
        {
            string str8;
            SafeDictionary <string> dictionary = new SafeDictionary <string>();

            dictionary.AddRange(this.Parameters);
            if (MainUtil.GetBool(dictionary["endlink"], false))
            {
                return(RenderFieldResult.EndLink);
            }
            Set <string> set = Set <string> .Create(new string[] { "field", "select", "text", "haschildren", "before", "after", "enclosingtag", "fieldname" });

            Sitecore.Data.Fields.LinkField linkField = this.LinkField;
            if (linkField != null)
            {
                dictionary["title"]  = StringUtil.GetString(new string[] { dictionary["title"], linkField.Title });
                dictionary["target"] = StringUtil.GetString(new string[] { dictionary["target"], linkField.Target });

                if (_includeContentEditorCss)
                {
                    _css += (string.IsNullOrWhiteSpace(_css) ? string.Empty : " ") + linkField.Class;
                }
            }
            string str           = string.Empty;
            string rawParameters = this.RawParameters;

            if (!string.IsNullOrEmpty(rawParameters) && (rawParameters.IndexOfAny(this._delimiter) < 0))
            {
                str = rawParameters;
            }
            if (string.IsNullOrEmpty(str))
            {
                Item   targetItem = this.TargetItem;
                string str3       = (targetItem != null) ? targetItem.DisplayName : string.Empty;
                string str4       = (linkField != null) ? linkField.Text : string.Empty;
                str = StringUtil.GetString(new string[] { str, dictionary["text"], str4, str3 });
            }
            string url = this.GetUrl(linkField);

            if (((str8 = this.LinkType) != null) && (str8 == "javascript"))
            {
                dictionary["href"]    = "#";
                dictionary["onclick"] = StringUtil.GetString(new string[] { dictionary["onclick"], url });
            }
            else
            {
                dictionary["href"] = HttpUtility.HtmlEncode(StringUtil.GetString(new string[] { dictionary["href"], url }));
            }
            StringBuilder tag = new StringBuilder("<a", 0x2f);

            foreach (KeyValuePair <string, string> pair in dictionary)
            {
                string key  = pair.Key;
                string str7 = pair.Value;
                if (!set.Contains(key.ToLowerInvariant()))
                {
                    FieldRendererBase.AddAttribute(tag, key, str7);
                }
            }
            if (!string.IsNullOrWhiteSpace(_css))
            {
                FieldRendererBase.AddAttribute(tag, "class", _css);
            }
            tag.Append('>');
            if (!MainUtil.GetBool(dictionary["haschildren"], false))
            {
                if (!string.IsNullOrEmpty(_innerHTML))
                {
                    tag.Append(_innerHTML);
                }
                else if (!string.IsNullOrEmpty(str))
                {
                    tag.Append(str);
                }
                else if (_displayHrefByDefault)
                {
                    tag.Append(dictionary["href"]);
                }
                else
                {
                    return(RenderFieldResult.Empty);
                }
            }
            return(new RenderFieldResult {
                FirstPart = tag.ToString(), LastPart = "</a>"
            });
        }
Пример #2
0
        public virtual RenderFieldResult Render()
        {
            UltraLinkField linkField = this.LinkField;

            if (linkField == null)
            {
                return(new RenderFieldResult()
                {
                    FirstPart = string.Empty,
                    LastPart = string.Empty
                });
            }


            SafeDictionary <string> attributes = new SafeDictionary <string>();

            if (this.Parameters.Any())
            {
                attributes.AddRange((SafeDictionary <string, string>) this.Parameters);
            }

            this.SetParameters(attributes, "class", linkField.Class);
            this.SetParameters(attributes, "id", linkField.ElementId);
            this.SetRelAttribute(attributes, linkField);
            this.SetExternalTargetAttribute(attributes, linkField);
            this.SetCustomAttributes(attributes, linkField);
            this.SetParameters(attributes, "href", this.BuildUrl(attributes, linkField));

            StringBuilder tag = new StringBuilder(linkField.TextBeforeLink);

            if (!string.IsNullOrEmpty(linkField.TextBeforeLink))
            {
                tag.Append(" ");
            }

            tag.Append("<a");

            foreach (KeyValuePair <string, string> keyValuePair in (SafeDictionary <string, string>)attributes)
            {
                string key   = keyValuePair.Key;
                string value = keyValuePair.Value;

                if (!ReservedSet.Contains(key.ToLowerInvariant()))
                {
                    FieldRendererBase.AddAttribute(tag, key, value);
                }
            }
            tag.Append('>');

            tag.Append(GetInnerText(attributes, linkField));

            tag.Append("</a>");

            if (!string.IsNullOrEmpty(linkField.TextAfterLink))
            {
                tag.Append(" ");
            }

            return(new RenderFieldResult()
            {
                FirstPart = tag.ToString(),
                LastPart = linkField.TextAfterLink
            });
        }