public void RegisterOpenGraph(MetaTagsPart metaTags) { _resourceManager.RegisterMeta(new MetaEntry { Name = "og:type", Content = "website" }); _resourceManager.RegisterMeta(new MetaEntry { Name = "og:url", Content = GetPageUrl() }); if (!string.IsNullOrWhiteSpace(metaTags.Title)) { _resourceManager.RegisterMeta(new MetaEntry { Name = "og:title", Content = metaTags.Title }); } if (!string.IsNullOrWhiteSpace(metaTags.Description)) { _resourceManager.RegisterMeta(new MetaEntry { Name = "og:description", Content = metaTags.Description }); } if (metaTags.Images != null && metaTags.Images.Any()) { _resourceManager.RegisterMeta(new MetaEntry { Name = "og:image", Content = $"{GetHostUrl()}{_mediaFileStore.MapPathToPublicUrl(metaTags.Images[0])}" }); } }
private string GetThumbnail(GalleryPartItem item, GalleryPartSettings settings) { if (item.Type == (int)GalleryPartType.LocalImage) { return($"{_mediaFileStore.MapPathToPublicUrl(item.Url)}?width={settings.ThumbnailSize}&height={settings.ThumbnailSize}&rmode=crop"); } return(item.Url); }
private object CreateFileResult(IFileStoreEntry mediaFile) { _contentTypeProvider.TryGetContentType(mediaFile.Name, out var contentType); return(new { name = mediaFile.Name, size = mediaFile.Length, folder = mediaFile.DirectoryPath, url = _mediaFileStore.MapPathToPublicUrl(mediaFile.Path), link = _mediaFileStore.MapPathToPublicUrl(mediaFile.Path), mediaPath = mediaFile.Path, mime = contentType ?? "application/octet-stream" }); }
private async Task <XRpcStruct> MetaWeblogNewMediaObjectAsync(string userName, string password, XRpcStruct file) { var user = await ValidateUserAsync(userName, password); var name = file.Optional <string>("name"); var bits = file.Optional <byte[]>("bits"); var directoryName = Path.GetDirectoryName(name); var filePath = _mediaFileStore.Combine(directoryName, Path.GetFileName(name)); Stream stream = null; try { stream = new MemoryStream(bits); filePath = await _mediaFileStore.CreateFileFromStreamAsync(filePath, stream); } finally { stream?.Dispose(); } var publicUrl = _mediaFileStore.MapPathToPublicUrl(filePath); return(new XRpcStruct() // Some clients require all optional attributes to be declared Wordpress responds in this way as well. .Set("file", publicUrl) .Set("url", publicUrl) .Set("type", file.Optional <string>("type"))); }
public string GetAvatar(IUser user) { if (user == null) { return(string.Empty); // { throw new ArgumentNullException("user"); } } var orchardUser = user as User; if (orchardUser == null) { throw new ArgumentNullException("orchardUser"); } var memoryCacheKey = $"{AvatarCacheKeyPrefix}-{orchardUser.UserName}"; if (!_memoryCache.TryGetValue(memoryCacheKey, out string avatar)) { //cachedDate = (await _localClock.LocalNowAsync).DateTime; var usermetadata = orchardUser.As <UserMetadata>(); if (usermetadata != null) { var resolvedAssetPath = _mediaFileStore.MapPathToPublicUrl(usermetadata.Avatar); avatar = resolvedAssetPath; _memoryCache.Set(memoryCacheKey, avatar, _signal.GetToken(memoryCacheKey)); } } return(avatar); }
public IList <ResponsiveMediaItem> ParseMedia(string data) { var media = new List <ResponsiveMediaItem>(); if (!string.IsNullOrWhiteSpace(data)) { media = data.StartsWith("[") ? JsonConvert.DeserializeObject <List <ResponsiveMediaItem> >(data) : new List <ResponsiveMediaItem> { JsonConvert.DeserializeObject <ResponsiveMediaItem>(data) }; } foreach (var mediaItem in media) { if (mediaItem.Sources == null) { continue; } foreach (var source in mediaItem.Sources) { source.Name = Path.GetFileName(source.Path); source.Url = _mediaFileStore.MapPathToPublicUrl(source.Path); } } return(media); }
public ValueTask <FluidValue> ProcessAsync(FluidValue input, FilterArguments arguments, LiquidTemplateContext context) { var url = input.ToStringValue(); var imageUrl = _mediaFileStore.MapPathToPublicUrl(url); return(new ValueTask <FluidValue>(new StringValue(imageUrl ?? url))); }
public Task <FluidValue> ProcessAsync(FluidValue input, FilterArguments arguments, TemplateContext ctx) { var url = input.ToStringValue(); var imageUrl = _mediaFileStore.MapPathToPublicUrl(url); return(Task.FromResult <FluidValue>(new StringValue(imageUrl ?? url))); }
public async Task <List <object> > GetContentItemFilesDirectoryPath(ContentItem contentItem) { List <object> response = new List <object>(); var folderPath = GetContentItemFolder(contentItem); // Use thumbPath as folderPath. string thumbPath = folderPath; // // Array of image objects to return. string[] imageMimetypes = ImageValidation.AllowedImageMimetypesDefault; var fileEntries = await _fileStore.GetDirectoryContentAsync(folderPath);// .TryDeleteDirectoryAsync(GetContentItemFolder(contentItem)); foreach (var file in fileEntries) { string fileName = file.Name;// System.IO.Path.GetFileName(filePath); //if (System.IO.File.Exists(filePath)) // { string mimeType; new FileExtensionContentTypeProvider().TryGetContentType(file.Path, out mimeType); if (mimeType == null) { mimeType = "application/octet-stream"; } if (Array.IndexOf(imageMimetypes, mimeType) >= 0) { response.Add(new { url = _fileStore.MapPathToPublicUrl(file.Path), thumb = _fileStore.MapPathToPublicUrl(file.Path), name = fileName }); } // } } return(response); }
public string GetMediaUrl(string path) { if (string.IsNullOrWhiteSpace(path)) { return(string.Empty); } var imageUrl = _mediaFileStore.MapPathToPublicUrl(path); return(imageUrl.StartsWith("http") ? imageUrl : $"{GetHostUrl()}{imageUrl}"); }
public override void Process(TagHelperContext context, TagHelperOutput output) { if (string.IsNullOrEmpty(AssetSrc)) { return; } var resolvedSrc = _mediaFileStore != null?_mediaFileStore.MapPathToPublicUrl(AssetSrc) : AssetSrc; output.Attributes.SetAttribute("src", resolvedSrc); }
public object CreateFileResult(IFileStoreEntry mediaFile) { return(new { name = mediaFile.Name, size = mediaFile.Length, folder = mediaFile.DirectoryPath, url = _mediaFileStore.MapPathToPublicUrl(mediaFile.Path), mediaPath = mediaFile.Path, mime = MimeMapping.MimeUtility.GetMimeMapping(mediaFile.Path) }); }
public void Configure(CustomStyleSettings options) { var siteSettings = _site.GetSiteSettingsAsync().GetAwaiter().GetResult(); if (siteSettings.Properties["CustomStyleSettings"] != null) { //Map SiteSettings to CustomStyleSettingsPart var CustomStyleSettingsJToken = siteSettings.Properties["CustomStyleSettings"]["CustomStyleSettingsPart"]; var customStyleSettingsPart = CustomStyleSettingsJToken.ToObject <CustomStyleSettingsPart>(); //Add public url to media fields if (customStyleSettingsPart.SiteLogo.Paths.Length > 0) { options.SiteLogo = _mediaFileStore.MapPathToPublicUrl(customStyleSettingsPart.SiteLogo.Paths[0]); } if (customStyleSettingsPart.SiteFavicon.Paths.Length > 0) { options.SiteFavicon = _mediaFileStore.MapPathToPublicUrl(customStyleSettingsPart.SiteFavicon.Paths[0]); } } }
public object CreateFileResult(IFileStoreEntry mediaFile) { _contentTypeProvider.TryGetContentType(mediaFile.Name, out var contentType); return(new { name = mediaFile.Name, size = mediaFile.Length, lastModify = mediaFile.LastModifiedUtc.Subtract(new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc)).TotalMilliseconds, folder = mediaFile.DirectoryPath, url = _mediaFileStore.MapPathToPublicUrl(mediaFile.Path), mediaPath = mediaFile.Path, mime = contentType ?? "application/octet-stream" }); }
public override IDisplayResult Edit(MapTiles part, BuildPartEditorContext context) { return(Initialize <MapTilesViewModel>(GetEditorShapeType(context), model => { model.ContentItem = part.ContentItem; model.HasBeenProcessed = part.HasBeenProcessed; model.Height = part.Height; model.IsProcessing = part.IsProcessing; model.PublishAfterProcessed = !part.ContentItem.CreatedUtc.HasValue || part.PublishAfterProcessed; model.Width = part.Width; // needs trailing slash otherwise doesn't load tile images model.TileRoot = _mediaFileStore.MapPathToPublicUrl(part.GetTileRoot()) + "/"; })); }
public override void Process(TagHelperContext context, TagHelperOutput output) { if (string.IsNullOrEmpty(AssetSrc)) { return; } var resolvedSrc = _mediaFileStore != null?_mediaFileStore.MapPathToPublicUrl(AssetSrc) : AssetSrc; output.Attributes.SetAttribute("src", resolvedSrc); if (AppendVersion && _fileVersionProvider != null) { output.Attributes.SetAttribute("src", _fileVersionProvider.AddFileVersionToPath(_httpContextAccessor.HttpContext.Request.PathBase, resolvedSrc)); } }
private int SubstituteTag(string text, StringBuilderPool sb, int start, int modifierIndex, int end) { var url = text.Substring(start + 7, end - start - 7); // substitute [thetag] with <img> sb.Builder.Remove(start + modifierIndex, end - start + 8); var publicUrl = _mediaFileStore.MapPathToPublicUrl(url); var tag = "<img src=\"" + publicUrl + "\">"; tag = _htmlSanitizerService.Sanitize(tag); sb.Builder.Insert(start + modifierIndex, tag); // Return the value the stringbuilder start index has been modified for recursion. return(publicUrl.Length - url.Length - 3); }
// This action will demonstrate how to create a file in the Media folder and read it from there. public async Task <string> CreateFileInMediaFolder() { // You need to initialize a stream if you have a specific text you want to write into the file. If you // already have a stream for that just use it (you'll see it later)! using (var stream = new MemoryStream(Encoding.UTF8.GetBytes("Hi there!"))) { // The third parameter here is optional - if true, it will override the file if already exists. await _mediaFileStore.CreateFileFromStreamAsync(TestFileRelativePath, stream, true); } // Use this method to check if the file exists (it will be null if the file doesn't exist). It's similar to // the built-in FileInfo class but not that robust. var fileInfo = await _mediaFileStore.GetFileInfoAsync(TestFileRelativePath); // The IMediaFileStore has its own specific methods such as mapping the file path to a public URL. Since // the files in the Media folder are accessible from the outside this can be handy. var publicUrl = _mediaFileStore.MapPathToPublicUrl(TestFileRelativePath); return($"Successfully created file! File size: {fileInfo.Length} bytes. Public URL: {publicUrl}"); }
public override async Task <IDisplayResult> DisplayAsync(Map part, BuildPartDisplayContext context) { var tiles = await GetTilesAsync(part); return(Initialize <MapViewModel>("Map", model => { model.Analytics = GetAnalytics(part.ContentItem); model.ContentItem = part.ContentItem; model.Height = tiles.As <MapTiles>().Height; model.InitialZoom = part.InitialZoom; model.Markers = GetMarkers(part.ContentItem); model.MaxZoom = part.MaxZoom; model.MinZoom = part.MinZoom; model.Width = tiles.As <MapTiles>().Width; // needs trailing slash otherwise doesn't load tile images model.TileRoot = _mediaFileStore.MapPathToPublicUrl(GetTileRoot(tiles)) + "/"; }) .Location("Detail", "Content:5")); }
public override async Task <IDisplayResult> EditAsync(MapPoisPart part, BuildPartEditorContext context) { var tiles = await GetTilesAsync(part); return(Initialize <MapPoisEditViewModel>(GetEditorShapeType(context), model => { model.ContentItem = part.ContentItem; model.MapPoisPart = part; model.Markers = part.ContentItems.Where(x => x.As <PoiPart>() != null).Select(x => x.As <PoiPart>().GetMarker(_contentDefinitionManager, true)); model.Updater = context.Updater; if (tiles != null) { model.Height = tiles.As <MapTiles>().Height; model.Width = tiles.As <MapTiles>().Width; // needs trailing slash otherwise doesn't load tile images model.TileRoot = _mediaFileStore.MapPathToPublicUrl(GetTileRoot(tiles)) + "/"; } })); }
public async Task <IActionResult> TemporaryUpload(string path, IFormFile file) { if (path == null) { path = ""; } try { using (var stream = file.OpenReadStream()) { var mediaFilePath = _mediaFileStore.Combine("temp", path, file.FileName); mediaFilePath = await _mediaFileStore.CreateFileAsync(mediaFilePath, stream); var mediaFile = await _mediaFileStore.GetFileInfoAsync(mediaFilePath); return(Json(new { name = mediaFile.Name, size = mediaFile.Length, folder = mediaFile.DirectoryPath, url = _mediaFileStore.MapPathToPublicUrl(mediaFile.Path), mediaPath = mediaFile.Path, mime = file.ContentType })); } } catch (Exception ex) { return(Json(new { name = file.FileName, size = file.Length, folder = path, error = ex.Message })); } }
public override Task GetContentItemAspectAsync(ContentItemAspectContext context, SeoMetaPart part) { return(context.ForAsync <SeoAspect>(async aspect => { aspect.Render = part.Render; if (!String.IsNullOrEmpty(part.PageTitle)) { aspect.PageTitle = part.PageTitle; } if (!String.IsNullOrEmpty(part.MetaDescription)) { aspect.MetaDescription = part.MetaDescription; } if (!String.IsNullOrEmpty(part.MetaKeywords)) { aspect.MetaKeywords = part.MetaKeywords; } if (!String.IsNullOrEmpty(part.MetaRobots)) { aspect.MetaRobots = part.MetaRobots; } aspect.CustomMetaTags = part.CustomMetaTags; var siteSettings = await _siteService.GetSiteSettingsAsync(); var actionContext = _actionContextAccessor.ActionContext; if (actionContext == null) { actionContext = await GetActionContextAsync(_httpContextAccessor.HttpContext); } var urlHelper = _urlHelperFactory.GetUrlHelper(actionContext); if (!String.IsNullOrEmpty(part.Canonical)) { aspect.Canonical = part.Canonical; } else { var contentItemMetadata = await _contentManager.PopulateAspectAsync <ContentItemMetadata>(part.ContentItem); var relativeUrl = urlHelper.RouteUrl(contentItemMetadata.DisplayRouteValues); aspect.Canonical = urlHelper.ToAbsoluteUrl(relativeUrl); } // OpenGraph if (part.OpenGraphImage?.Paths?.Length > 0) { aspect.OpenGraphImage = urlHelper.ToAbsoluteUrl(_mediaFileStore.MapPathToPublicUrl(part.OpenGraphImage.Paths[0])); } else if (part.DefaultSocialImage?.Paths?.Length > 0) { aspect.OpenGraphImage = urlHelper.ToAbsoluteUrl(_mediaFileStore.MapPathToPublicUrl(part.DefaultSocialImage.Paths[0])); } if (part.OpenGraphImage?.MediaTexts?.Length > 0) { aspect.OpenGraphImageAlt = part.OpenGraphImage.MediaTexts[0]; } else if (part.DefaultSocialImage?.MediaTexts?.Length > 0) { aspect.OpenGraphImageAlt = part.DefaultSocialImage.MediaTexts[0]; } if (!String.IsNullOrEmpty(part.OpenGraphTitle)) { aspect.OpenGraphTitle = part.OpenGraphTitle; } else { aspect.OpenGraphTitle = part.PageTitle; } if (!String.IsNullOrEmpty(part.OpenGraphDescription)) { aspect.OpenGraphDescription = part.OpenGraphDescription; } else { aspect.OpenGraphDescription = part.MetaDescription; } // Twitter if (part.TwitterImage?.Paths?.Length > 0) { aspect.TwitterImage = urlHelper.ToAbsoluteUrl(_mediaFileStore.MapPathToPublicUrl(part.TwitterImage.Paths[0])); } else if (part.DefaultSocialImage?.Paths?.Length > 0) { aspect.TwitterImage = urlHelper.ToAbsoluteUrl(_mediaFileStore.MapPathToPublicUrl(part.DefaultSocialImage.Paths[0])); } if (part.TwitterImage?.MediaTexts?.Length > 0) { aspect.TwitterImageAlt = part.TwitterImage.MediaTexts[0]; } else if (part.DefaultSocialImage?.MediaTexts?.Length > 0) { aspect.TwitterImageAlt = part.DefaultSocialImage.MediaTexts[0]; } if (!String.IsNullOrEmpty(part.TwitterTitle)) { aspect.TwitterTitle = part.TwitterTitle; } else { aspect.TwitterTitle = part.PageTitle; } if (!String.IsNullOrEmpty(part.TwitterDescription)) { aspect.TwitterDescription = part.TwitterDescription; } else { aspect.TwitterDescription = part.MetaDescription; } if (!String.IsNullOrEmpty(part.TwitterCard)) { aspect.TwitterCard = part.TwitterCard; } if (!String.IsNullOrEmpty(part.TwitterCreator)) { aspect.TwitterCreator = part.TwitterCreator; } if (!String.IsNullOrEmpty(part.TwitterSite)) { aspect.TwitterSite = part.TwitterSite; } aspect.GoogleSchema = part.GoogleSchema; })); }
public override Task GetContentItemAspectAsync(ContentItemAspectContext context) { return(context.ForAsync <SeoAspect>(async aspect => { // This handlers provides defaults, either from the Seo Meta Settings, or ensures values by default. (title etc) _contentManager ??= _httpContextAccessor.HttpContext.RequestServices.GetRequiredService <IContentManager>(); var siteSettings = await _siteService.GetSiteSettingsAsync(); var metaSettings = siteSettings.As <ContentItem>("SocialMetaSettings"); var actionContext = _actionContextAccessor.ActionContext; if (actionContext == null) { actionContext = await GetActionContextAsync(_httpContextAccessor.HttpContext); } var urlHelper = _urlHelperFactory.GetUrlHelper(actionContext); var contentItemMetadata = await _contentManager.PopulateAspectAsync <ContentItemMetadata>(context.ContentItem); var relativeUrl = urlHelper.RouteUrl(contentItemMetadata.DisplayRouteValues); var absoluteUrl = urlHelper.ToAbsoluteUrl(relativeUrl); // Logic is this happens last after the part settings. // so if values are not set it is responsible for settings them. string defaultImage = (metaSettings.Content.SocialMetaSettings?.DefaultSocialImage?.Paths as JArray)?.Count > 0 ? metaSettings.Content.SocialMetaSettings.DefaultSocialImage.Paths[0].ToString() : String.Empty; string openGraphImage = (metaSettings.Content.SocialMetaSettings?.OpenGraphImage?.Paths as JArray)?.Count > 0 ? metaSettings.Content.SocialMetaSettings?.OpenGraphImage?.Paths[0]?.ToString() : String.Empty; string twitterImage = (metaSettings.Content.SocialMetaSettings?.TwitterImage?.Paths as JArray)?.Count > 0 ? metaSettings.Content.SocialMetaSettings?.TwitterImage?.Paths[0]?.ToString() : String.Empty; string defaultAltText = (metaSettings.Content.SocialMetaSettings?.DefaultSocialImage?.MediaTexts as JArray)?.Count > 0 ? metaSettings.Content.SocialMetaSettings.DefaultSocialImage.MediaTexts[0].ToString() : String.Empty; string openGraphAltText = (metaSettings.Content.SocialMetaSettings?.OpenGraphImage?.MediaTexts as JArray)?.Count > 0 ? metaSettings.Content.SocialMetaSettings?.OpenGraphImage?.MediaTexts[0]?.ToString() : String.Empty; string twitterAltText = (metaSettings.Content.SocialMetaSettings?.TwitterImage?.MediaTexts as JArray)?.Count > 0 ? metaSettings.Content.SocialMetaSettings?.TwitterImage?.MediaTexts[0]?.ToString() : String.Empty; string twitterCard = metaSettings.Content.SocialMetaSettings?.TwitterCard?.Text?.ToString(); string twitterCreator = metaSettings.Content.SocialMetaSettings?.TwitterCreator?.Text?.ToString(); string twitterSite = metaSettings.Content.SocialMetaSettings?.TwitterSite?.Text?.ToString(); string googleSchema = metaSettings.Content.SocialMetaSettings?.GoogleSchema?.Text?.ToString(); // Meta if (String.IsNullOrEmpty(aspect.MetaDescription)) { aspect.MetaDescription = metaSettings.Content.SocialMetaSettings?.DefaultMetaDescription?.Text?.ToString(); } // OpenGraph aspect.OpenGraphUrl = absoluteUrl; if (String.IsNullOrEmpty(aspect.OpenGraphType)) { aspect.OpenGraphType = metaSettings.Content.SocialMetaSettings?.OpenGraphType?.Text?.ToString(); } if (String.IsNullOrEmpty(aspect.OpenGraphTitle)) { aspect.OpenGraphTitle = context.ContentItem.DisplayText; } if (String.IsNullOrEmpty(aspect.OpenGraphDescription)) { aspect.OpenGraphDescription = metaSettings.Content.SocialMetaSettings?.DefaultOpenGraphDescription?.Text?.ToString(); } if (String.IsNullOrEmpty(aspect.OpenGraphSiteName)) { aspect.OpenGraphSiteName = metaSettings.Content.SocialMetaSettings?.OpenGraphSiteName?.Text.ToString(); if (String.IsNullOrEmpty(aspect.OpenGraphSiteName)) { aspect.OpenGraphSiteName = siteSettings.SiteName; } } if (String.IsNullOrEmpty(aspect.OpenGraphAppId)) { aspect.OpenGraphAppId = metaSettings.Content.SocialMetaSettings?.OpenGraphAppId?.Text.ToString(); } if (String.IsNullOrEmpty(aspect.OpenGraphImage)) { if (String.IsNullOrEmpty(openGraphImage)) { if (!String.IsNullOrEmpty(defaultImage)) { aspect.OpenGraphImage = urlHelper.ToAbsoluteUrl(_mediaFileStore.MapPathToPublicUrl(defaultImage)); } } else { aspect.OpenGraphImage = urlHelper.ToAbsoluteUrl(_mediaFileStore.MapPathToPublicUrl(openGraphImage)); } } if (String.IsNullOrEmpty(aspect.OpenGraphImageAlt)) { if (String.IsNullOrEmpty(openGraphAltText)) { aspect.OpenGraphImageAlt = defaultAltText; } else { aspect.OpenGraphImageAlt = openGraphAltText; } } // Twitter aspect.TwitterUrl = absoluteUrl; if (String.IsNullOrEmpty(aspect.TwitterTitle)) { aspect.TwitterTitle = context.ContentItem.DisplayText; } if (String.IsNullOrEmpty(aspect.TwitterDescription)) { aspect.TwitterDescription = metaSettings.Content.SocialMetaSettings?.DefaultTwitterDescription?.Text?.ToString(); } if (String.IsNullOrEmpty(aspect.TwitterCard)) { aspect.TwitterCard = twitterCard; } if (String.IsNullOrEmpty(aspect.TwitterSite)) { aspect.TwitterSite = twitterSite; } if (String.IsNullOrEmpty(aspect.TwitterCreator)) { aspect.TwitterCreator = twitterCreator; } if (String.IsNullOrEmpty(aspect.TwitterImage)) { if (String.IsNullOrEmpty(twitterImage)) { if (!String.IsNullOrEmpty(defaultImage)) { aspect.TwitterImage = urlHelper.ToAbsoluteUrl(_mediaFileStore.MapPathToPublicUrl(defaultImage)); } } else { aspect.TwitterImage = urlHelper.ToAbsoluteUrl(_mediaFileStore.MapPathToPublicUrl(twitterImage)); } } if (String.IsNullOrEmpty(aspect.TwitterImageAlt)) { if (String.IsNullOrEmpty(twitterAltText)) { aspect.TwitterImageAlt = defaultAltText; } else { aspect.TwitterImageAlt = twitterAltText; } } if (String.IsNullOrEmpty(aspect.GoogleSchema)) { aspect.GoogleSchema = googleSchema; } })); }
public ValueTask <string> EvaluateAsync(string identifier, Arguments arguments, string content, Context context) { if (!Shortcodes.Contains(identifier)) { return(Null); } // Handle self closing shortcodes. if (String.IsNullOrEmpty(content)) { content = arguments.NamedOrDefault("src"); if (String.IsNullOrEmpty(content)) { // Do not handle the deprecated media shortcode in this edge case. return(ImageShortcode); } } if (!content.StartsWith("//", StringComparison.Ordinal) && !content.StartsWith("http", StringComparison.OrdinalIgnoreCase)) { // Serve static files from virtual path. if (content.StartsWith("~/", StringComparison.Ordinal)) { content = _httpContextAccessor.HttpContext.Request.PathBase.Add(content.Substring(1)).Value; if (!String.IsNullOrEmpty(_options.CdnBaseUrl)) { content = _options.CdnBaseUrl + content; } } else { content = _mediaFileStore.MapPathToPublicUrl(content); } } var className = string.Empty; var altText = string.Empty; if (arguments.Any()) { var queryStringParams = new Dictionary <string, string>(); var width = arguments.Named("width"); var height = arguments.Named("height"); var mode = arguments.Named("mode"); var quality = arguments.Named("quality"); var format = arguments.Named("format"); className = arguments.Named("class"); altText = arguments.Named("alt"); if (width != null) { queryStringParams.Add("width", width); } if (height != null) { queryStringParams.Add("height", height); } if (mode != null) { queryStringParams.Add("rmode", mode); } if (quality != null) { queryStringParams.Add("quality", quality); } if (format != null) { queryStringParams.Add("format", format); } if (className != null) { className = "class=\"" + className + "\" "; } if (altText != null) { altText = "alt=\"" + altText + "\" "; } content = QueryHelpers.AddQueryString(content, queryStringParams); } content = "<img " + altText + className + "src=\"" + content + "\">"; content = _htmlSanitizerService.Sanitize(content); return(new ValueTask <string>(content)); }
public string GetMediaUrl(string path) { var imageUrl = _mediaFileStore.MapPathToPublicUrl(path); return(imageUrl.StartsWith("http") ? imageUrl : $"{GetHostUrl()}{imageUrl}"); }