protected override void GetEmbedHTML(System.Web.UI.HtmlTextWriter writer) { Image image = new Image(); if (MaxWidth > 0) { image.Width = MaxWidth; } if (MaxHeight > 0) { image.Height = MaxHeight; } OEmbedResult result = GetEmbedResult(MaxWidth, MaxHeight); if (result != null && !String.IsNullOrEmpty(result.thumbnail_url)) { image.ImageUrl = result.thumbnail_url; } else { image.ImageUrl = DefaultImageUrl; } image.RenderControl(writer); }
/// <summary> /// Gets OEmbedResult for a URL /// </summary> /// <param name="url"></param> /// <returns></returns> public OEmbedResult GetEmbedResult(string url) { string response = GetEmbedResponse(url); OEmbedResult result = JsonConvert.DeserializeObject <OEmbedResult>(response); return(PostProcessResult(result)); }
public override OEmbedResult PostProcessResult(OEmbedResult result) { if (String.IsNullOrEmpty(result.html)) { result.html = String.Format(@"<img src=""{0}"" alt=""{1}"" />", result.url, result.title); } return(result); }
public override OEmbedResult PostProcessResult(OEmbedResult result) { if (String.IsNullOrEmpty(result.html)) { result.html = String.Format(@"<img src=""{0}"" alt=""{1}"" />", result.url, result.title); } return result; }
protected override void GetEmbedHTML(System.Web.UI.HtmlTextWriter writer) { string output = String.Empty; OEmbedResult result = GetEmbedResult(); if (result != null) { output = result.html; } writer.Write(output); }
/// <summary> /// Processes a chunk of HTML/text /// </summary> /// <param name="input"></param> /// <returns></returns> public string Process(string input) { string output = input; MatchCollection matches = Regex.Matches(input, ProviderPattern); foreach (Match m in matches) { OEmbedResult result = GetEmbedResult(m.Value); output = output.Replace(m.Value, result.html); } return(output); }
public OEmbedResult GetEmbed(string url, int width, int height) { var result = new OEmbedResult(); var foundMatch = false; IEmbedProvider?matchedProvider = null; foreach (IEmbedProvider provider in _embedCollection) { // UrlSchemeRegex is an array of possible regex patterns to match against the URL foreach (var urlPattern in provider.UrlSchemeRegex) { var regexPattern = new Regex(urlPattern, RegexOptions.IgnoreCase); if (regexPattern.IsMatch(url)) { foundMatch = true; matchedProvider = provider; break; } } if (foundMatch) { break; } } if (foundMatch == false) { //No matches return/ exit result.OEmbedStatus = OEmbedStatus.NotSupported; return(result); } try { result.SupportsDimensions = true; result.Markup = matchedProvider?.GetMarkup(url, width, height); result.OEmbedStatus = OEmbedStatus.Success; } catch (Exception ex) { _logger.LogError(ex, "Error embedding URL {Url} - width: {Width} height: {Height}", url, width, height); result.OEmbedStatus = OEmbedStatus.Error; } return(result); }
/// <summary> /// If a provider wants to post-process a result, implement this method /// </summary> /// <param name="result"></param> /// <returns></returns> public virtual OEmbedResult PostProcessResult(OEmbedResult result) { return result; }
/// <summary> /// If a provider wants to post-process a result, implement this method /// </summary> /// <param name="result"></param> /// <returns></returns> public virtual OEmbedResult PostProcessResult(OEmbedResult result) { return(result); }