Skip to content
Permalink
Browse files

Adding in WebControl for using media Thumbnails. Removed Sitecore spe…

…cific project (breaking out into another repo)
  • Loading branch information...
patrickmjones committed Jun 2, 2013
1 parent ecf1761 commit b1b3be944e756ddff7eba5abfed1f2db01ded010

This file was deleted.

This file was deleted.

This file was deleted.

@@ -7,31 +7,17 @@

namespace PJones.OEmbed.UI
{
public class LinkToEmbed : System.Web.UI.WebControls.WebControl
public class LinkToEmbed : WebControl
{
public string URL { get; set; }
public PJones.OEmbed.ProviderType Provider { get; set; }

protected override void Render(System.Web.UI.HtmlTextWriter writer)
{
writer.Write(GetEmbedHTML());
}

protected virtual string GetEmbedHTML()
protected override void GetEmbedHTML(System.Web.UI.HtmlTextWriter writer)
{
BaseProvider provider = GetEmbedProvider();
string output = String.Empty;
OEmbedResult result = provider.GetEmbedResult(URL);
OEmbedResult result = GetEmbedResult();
if (result != null)
{
output = result.html;
}
return output;
}

protected virtual BaseProvider GetEmbedProvider()
{
return ProviderFactory.GetProvider(Provider);
writer.Write(output);
}
}
}
@@ -0,0 +1,52 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using PJones.OEmbed.Providers;
using System.Web.UI.WebControls;

namespace PJones.OEmbed.UI
{
class LinkToThumbnail : WebControl
{
/// <summary>
/// MaxWidth for Thumbnail image
/// </summary>
public int MaxWidth { get; set; }

/// <summary>
/// MaxHeight for Thumbnail image
/// </summary>
public int MaxHeight { get; set; }

/// <summary>
/// Default image url to use if none found
/// </summary>
public string DefaultImageUrl { get; set; }

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);
}
}
}
@@ -42,7 +42,9 @@
</ItemGroup>
<ItemGroup>
<Compile Include="LinkToEmbed.cs" />
<Compile Include="LinkToThumbnail.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="WebControl.cs" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\PJones.OEmbed\PJones.OEmbed.csproj">
@@ -6,11 +6,11 @@
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
[assembly: AssemblyTitle("PJones.OEmbed.UI")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyDescription(".Net WebControls for PJones.OEmbed")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyCompany("Patrick Jones")]
[assembly: AssemblyProduct("PJones.OEmbed.UI")]
[assembly: AssemblyCopyright("Copyright © 2013")]
[assembly: AssemblyCopyright("Copyright © Patrick Jones 2013")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]

@@ -0,0 +1,54 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using PJones.OEmbed.Providers;

namespace PJones.OEmbed.UI
{
public class WebControl:System.Web.UI.WebControls.WebControl
{
/// <summary>
/// URL to media to parse
/// </summary>
public string URL { get; set; }

/// <summary>
/// Provider to perform parse
/// </summary>
public PJones.OEmbed.ProviderType Provider { get; set; }

protected override void Render(System.Web.UI.HtmlTextWriter writer)
{
GetEmbedHTML(writer);
}

protected virtual void GetEmbedHTML(System.Web.UI.HtmlTextWriter writer)
{
throw new NotImplementedException();
}

protected virtual BaseProvider GetEmbedProvider()
{
return ProviderFactory.GetProvider(Provider);
}

protected virtual OEmbedResult GetEmbedResult()
{
return GetEmbedResult(0, 0);
}
protected virtual OEmbedResult GetEmbedResult(int width, int height)
{
BaseProvider provider = GetEmbedProvider();
if (provider != null)
{
return provider.GetEmbedResult(URL);
}
else
{
OEmbedEngine eng = new OEmbedEngine();
return eng.ParseURL(URL, width, height);
}
}
}
}
@@ -43,6 +43,28 @@ public string Parse(string input, int maxwidth, int maxheight)
return output;
}

/// <summary>
/// Gets embed result for a url, null if none
/// </summary>
/// <param name="url"></param>
/// <param name="maxwidth"></param>
/// <param name="maxheight"></param>
/// <returns></returns>
public OEmbedResult ParseURL(string url, int maxwidth, int maxheight)
{
foreach (Type t in Providers)
{
BaseProvider provider = ((BaseProvider)Activator.CreateInstance(t));
if (provider.Supported && provider.IsMatch(url))
{
provider.MaxWidth = maxwidth;
provider.MaxHeight = maxheight;
return provider.GetEmbedResult(url);
}
}
return null;
}

public OEmbedEngine()
{
Initialize(new List<Type> {

0 comments on commit b1b3be9

Please sign in to comment.
You can’t perform that action at this time.