Пример #1
0
        public static string GetImageUrl(this MediaItem item, int width, int height)
        {
            if (item == null)
            {
                //This happens if there is a trailing pipe '|' at the end of an image list
                return string.Empty;
            }

            var options = new Sitecore.Resources.Media.MediaUrlOptions() { Height = height, Width = width };
            var url = Sitecore.Resources.Media.MediaManager.GetMediaUrl(item, options);
            var cleanUrl = Sitecore.StringUtil.EnsurePrefix('/', url);
            var hashedUrl = HashingUtils.ProtectAssetUrl(cleanUrl);

            return hashedUrl;
        }
Пример #2
0
        /// <summary>
        /// Gets the full size image paths based on the BaseUrl in the app settings and the short path in the delimited property Image_Filename in the Product.
        /// </summary>
        /// <param name="item">The item on which the image is contained.</param>
        /// <param name="width">The width of the image to draw.</param>
        /// <param name="height">The height of the image to draw.</param>
        /// <returns>
        /// The full size image paths.
        /// </returns>
        public static string GetImageUrl(this MediaItem item, int width, int height)
        {
            if (item == null)
            {
                //This happens if there is a trailing pipe '|' at the end of an image list
                return(string.Empty);
            }

            var options = new Sitecore.Resources.Media.MediaUrlOptions()
            {
                Height = height, Width = width
            };
            var url       = Sitecore.Resources.Media.MediaManager.GetMediaUrl(item, options);
            var cleanUrl  = Sitecore.StringUtil.EnsurePrefix('/', url);
            var hashedUrl = HashingUtils.ProtectAssetUrl(cleanUrl);

            return(hashedUrl);
        }
Пример #3
0
        /// <summary>
        /// Returns url from specified field
        /// </summary>
        /// <param name="item"></param>
        /// <param name="key"></param>
        /// <returns></returns>
        public static String GetUrl(Item item, String key)
        {
            String url = String.Empty;

            UrlOptions opt = new UrlOptions
            {
                AlwaysIncludeServerUrl = true,
                LanguageEmbedding = LanguageEmbedding.Never
            };

            if (HasNotEmptyField(item, key))
            {
                LinkField extLink = (LinkField)item.Fields[key];

                if (extLink != null)
                {
                    if (extLink.IsInternal && extLink.TargetItem != null)
                    {
                        url = LinkManager.GetItemUrl(extLink.TargetItem, opt);
                    }

                    else if (extLink.IsMediaLink && extLink.TargetItem != null)
                    {
                        Sitecore.Resources.Media.MediaUrlOptions mediaOpt = new Sitecore.Resources.Media.MediaUrlOptions();
                        mediaOpt.AbsolutePath = true;

                        url = Sitecore.StringUtil.EnsurePrefix('/', Sitecore.Resources.Media.MediaManager.GetMediaUrl(extLink.TargetItem, mediaOpt));
                    }

                    else if (extLink.TargetItem != null)
                    {
                        url = LinkManager.GetItemUrl(extLink.TargetItem, opt);
                    }

                    else if (extLink.Url.Length > 0)
                    {
                        url = extLink.Url;
                    }
                }

                //else
                //{
                //    url = LinkManager.GetItemUrl(item, opt);
                //}
            }

            //else
            //{
            //    url = LinkManager.GetItemUrl(item, opt);
            //}

            return url;
        }