Ejemplo n.º 1
0
        public static string GetImageTag(string imagePathOrMediaId, int maxWidth, int maxHeight, bool constrain)
        {
            if (string.IsNullOrEmpty(imagePathOrMediaId))
            {
                return(string.Empty);
            }

            int mediaId = CommonUtil.ConvertToIntSafe(imagePathOrMediaId, -1);

            if (mediaId == -1)
            {
                return(GetImageTag(imagePathOrMediaId, maxWidth, maxHeight));
            }

            Media media = UmbracoUtil.GetMedia(mediaId);

            if (media != null)
            {
                string file = media.GetPropertyValue("umbracoFile", string.Empty);
                if (!string.IsNullOrEmpty(file))
                {
                    string alt = HttpUtility.HtmlEncode(media.Text);

                    string thumbnailUrl = ImageUtil.ThumbnailUrl(file, maxWidth, maxHeight, constrain);
                    return(GetImageTag(thumbnailUrl, alt));
                }
            }
            return(string.Empty);
        }
Ejemplo n.º 2
0
        public static string MenuTitle(XPathNodeIterator ni)
        {
            Node node = UmbracoUtil.GetNode(ni);

            if (node != null)
            {
                return(UmbracoUtil.GetMenuTitle(node));
            }
            return(string.Empty);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Gets the media path via a media id
        /// </summary>
        /// <param name="mediaId">The media id.</param>
        /// <returns>The file path to the media</returns>
        /// <example>
        /// <code lang="xsl" title="">
        /// <![CDATA[
        /// <xsl:value-of select="upac:GetMediaPath(1101)" />
        /// Would give: /media/1101/image.jpg
        /// ]]>
        /// </code>
        /// </example>
        public static string GetMediaPath(int mediaId)
        {
            Media media = UmbracoUtil.GetMedia(mediaId);

            if (media != null)
            {
                return(media.GetPropertyValue("umbracoFile", string.Empty));
            }
            return(string.Empty);
        }
Ejemplo n.º 4
0
 public static string ThumbnailUrl(int mediaId, int width, int height, bool constrain)
 {
     Media media = UmbracoUtil.GetMedia(mediaId);
     if (media != null)
     {
         string imagePath = media.GetPropertyValue("umbracoFile", string.Empty);
         return ThumbnailUrl(imagePath, width, height, constrain);
     }
     return string.Empty;
 }
Ejemplo n.º 5
0
        public static XPathNodeIterator GetDescendantsViaXPath(XPathNodeIterator from, string xpath)
        {
            Node node = UmbracoUtil.GetNode(from);

            if (node != null)
            {
                XPathNavigator navigator = node.ToXPathNavigator();
                return(navigator.Select(xpath));
            }
            return(CreateEmptyIterator());
        }
Ejemplo n.º 6
0
        /// <summary>
        /// Get a link tag with overload for the link text and a css class to add to the a tag.
        /// </summary>
        /// <remarks>
        /// Gets a link tag where the href points to the node and you can add a css class
        /// </remarks>
        /// <param name="nodeId">The node id.</param>
        /// <param name="linkText">The link text.</param>
        /// <param name="cssClass">Css class</param>
        /// <returns>An a tag</returns>
        /// <example>
        /// <code lang="xsl" title="">
        /// <![CDATA[
        /// <xsl:value-of select="upac:GetLinkTag(1541, 'Hi World', 'highlight')" />
        /// Would give: <a href="/Subjectpage/HelloWorld" class="highlight">Hi World</a>
        /// ]]>
        /// </code>
        /// <code lang="xsl" title="With empty link text">
        /// <![CDATA[
        /// <xsl:value-of select="upac:GetLinkTag(1541, '', 'highlight')" />
        /// Would give: <a href="/Subjectpage/HelloWorld" class="highlight">Hello World</a>
        /// ]]>
        /// </code>
        /// <code lang="xsl" title="With empty link text and css class">
        /// <![CDATA[
        /// <xsl:value-of select="upac:GetLinkTag(1541, '', '')" />
        /// Would give: <a href="/Subjectpage/HelloWorld">Hello World</a>
        /// ]]>
        /// </code>
        /// </example>
        public static string GetLinkTag(string nodeId, string linkText, string cssClass)
        {
            Node node = UmbracoUtil.GetNode(nodeId);

            if (node != null)
            {
                string text      = !string.IsNullOrEmpty(linkText) ? linkText : UmbracoUtil.GetMenuTitle(node);
                string url       = LinkManager.GetNodeUrl(node);
                string linkClass = string.IsNullOrEmpty(cssClass) ? string.Empty : string.Format(" class=\"{0}\"", cssClass);
                if (text != string.Empty && url != string.Empty)
                {
                    string tag = string.Format("<a href=\"{0}\"{1}>{2}</a>", url, linkClass, text);
                    return(tag);
                }
            }
            return(string.Empty);
        }