public override string GetResponsiveImageUrl(string url, double aspect, string widthFactor, int containerSize = 0) { int width = GetResponsiveWidth(widthFactor, containerSize); //Round the width to the nearest set limit point - important as we do not want //to swamp the cache with lots of different sized versions of the same image for (int i = 0; i < ImageWidths.Count; i++) { if (width <= ImageWidths[i] || i == ImageWidths.Count - 1) { width = ImageWidths[i]; break; } } //Height is calculated from the aspect ratio (0 means preserve aspect ratio) string height = (aspect == 0) ? String.Empty : ((int)Math.Ceiling(width / aspect)).ToString(CultureInfo.InvariantCulture); //Build the URL url = SiteConfiguration.MakeFullUrl(url, WebRequestContext.Localization); //remap localhost to real hostname for CID service Uri tmp = new Uri(url); url = tmp.GetLeftPart(UriPartial.Authority).Replace("localhost", _hostname, StringComparison.InvariantCultureIgnoreCase) + tmp.PathAndQuery; // get prefix string prefix = url.StartsWith("https") ? "https/" : string.Empty; // should encode the url incase it contains special chars in a query string or something url = HttpUtility.UrlPathEncode(url.Substring(url.IndexOf("://", StringComparison.Ordinal) + 3)); return(String.Format(ImageResizeUrlFormat, _cidBaseUrl, width, height, prefix, url)); }
public override string GetResponsiveImageUrl(string url, double aspect, string widthFactor, int containerSize = 0) { int width = GetResponsiveWidth(widthFactor, containerSize); //Round the width to the nearest set limit point - important as we do not want //to swamp the cache with lots of different sized versions of the same image for (int i = 0; i < ImageWidths.Count; i++) { if (width <= ImageWidths[i] || i == ImageWidths.Count - 1) { width = ImageWidths[i]; break; } } //Height is calculated from the aspect ratio (0 means preserve aspect ratio) string height = aspect == 0 ? String.Empty : ((int)Math.Ceiling(width / aspect)).ToString(CultureInfo.InvariantCulture); //Build the URL url = SiteConfiguration.MakeFullUrl(url, WebRequestContext.Localization); string prefix = SingleSiteToken; if (url.StartsWith("http")) { prefix = ""; if (url.StartsWith("https")) { prefix = "https/"; } url = url.Substring(url.IndexOf("://", StringComparison.Ordinal) + 3); } return(String.Format(ImageResizeUrlFormat, ImageResizeRoute, width, height, prefix, url)); }
/// <summary> /// Creates a syndication item link from a given <see cref="Link"/> instance. /// </summary> /// <param name="link">The <see cref="Link"/> instance.</param> /// <param name="localization">The context <see cref="Localization"/>.</param> /// <returns>The syndication item link or <c>null</c> if <paramref name="link"/> is <c>null</c> or an empty link.</returns> protected SyndicationLink CreateSyndicationLink(Link link, Localization localization) { if (string.IsNullOrEmpty(link?.Url)) { return(null); } string absoluteUrl = SiteConfiguration.MakeFullUrl(link.Url, localization); return(new SyndicationLink(new Uri(absoluteUrl))); }