File: D:/HostingSpaces/TDijk1/erp-apps.eu/wwwroot/CMSWebParts/Pux/Embed/EmbedVideo.ascx.cs
using CMS.Helpers;
using CMS.PortalControls;
using Pux;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
public partial class CMSWebParts_Pux_EmbedVideo : CMSAbstractWebPart
{
public EmbedVideoType Type
{
get
{
return (EmbedVideoType)ValidationHelper.GetInteger(GetValue("Type"), 0);
}
set
{
SetValue("Type", value);
}
}
public string CustomHTML
{
get
{
return ValidationHelper.GetString(GetValue("CustomHTML"), String.Empty);
}
set
{
SetValue("CustomHTML", value);
}
}
public string CustomURL
{
get
{
return ValidationHelper.GetString(GetValue("CustomURL"), String.Empty);
}
set
{
SetValue("CustomURL", value);
}
}
public string CustomURL2
{
get
{
return ValidationHelper.GetString(GetValue("CustomURL2"), String.Empty);
}
set
{
SetValue("CustomURL2", value);
}
}
public string Vimeo
{
get
{
return ValidationHelper.GetString(GetValue("Vimeo"), String.Empty);
}
set
{
SetValue("Vimeo", value);
}
}
public string Youtube
{
get
{
return ValidationHelper.GetString(GetValue("Youtube"), String.Empty);
}
set
{
SetValue("Youtube", value);
}
}
public bool YoutubeAutoPlay
{
get
{
return ValidationHelper.GetBoolean(GetValue("YoutubeAutoPlay"), false);
}
set
{
SetValue("YoutubeAutoPlay", value);
}
}
public bool YoutubeControls
{
get
{
return ValidationHelper.GetBoolean(GetValue("YoutubeControls"), false);
}
set
{
SetValue("YoutubeControls", value);
}
}
public bool YoutubeRelated
{
get
{
return ValidationHelper.GetBoolean(GetValue("YoutubeRelated"), false);
}
set
{
SetValue("YoutubeRelated", value);
}
}
public bool PopupVideo
{
get
{
return ValidationHelper.GetBoolean(GetValue("PopupVideo"), false);
}
set
{
SetValue("PopupVideo", value);
}
}
public string ThumbnailImage
{
get
{
return ValidationHelper.GetString(GetValue("ThumbnailImage"), String.Empty);
}
set
{
SetValue("ThumbnailImage", value);
}
}
public string VideoSize
{
get
{
return ValidationHelper.GetString(GetValue("VideoSize"), String.Empty);
}
set
{
SetValue("VideoSize", value);
}
}
protected string GetYoutubeThumbnailImage()
{
if ( !String.IsNullOrEmpty( ThumbnailImage ) )
{
return ThumbnailImage;
}
return String.Format("http://i1.ytimg.com/vi/{0}/maxresdefault.jpg", EmbedTools.GetYoutubeID(Youtube));
}
protected string GetVimeoThumbnailImage()
{
if (!String.IsNullOrEmpty(ThumbnailImage))
{
return String.Format("data-thumb='{0}'", ThumbnailImage);
}
return String.Format("data-vimeo='{0}'", EmbedTools.GetVimeoID(Vimeo));
}
protected string IsPopupVideo()
{
if ( PopupVideo )
{
return "in-popup";
}
return "";
}
protected string IsYoutubeAutoPlay()
{
if (YoutubeAutoPlay)
{
return "1";
}
return "0";
}
protected string NoYoutubeControls()
{
if (YoutubeControls)
{
return "0";
}
return "1";
}
protected string IsYoutubeRelated()
{
if ( YoutubeRelated)
{
return "1";
}
return "0";
}
protected void Page_Load(object sender, EventArgs e)
{
switch (Type)
{
case EmbedVideoType.Youtube:
ltrHTML.Text = String.Format("<div class='embed-video {1}'><iframe src='//www.youtube.com/embed/{0}?rel={6}&controls={5}&autoplay={4}' frameborder='0' allowfullscreen></iframe>"+
"<a class='embed-video-overflow youtube {3} autoplay-{4}' style='background-image: url(\"{2}\");'>"+
"<span class='embed-video-icon'></span></a></div>", EmbedTools.GetYoutubeID(Youtube), VideoSize, GetYoutubeThumbnailImage(), IsPopupVideo(), IsYoutubeAutoPlay(), NoYoutubeControls(), IsYoutubeRelated());
break;
case EmbedVideoType.Vimeo:
ltrHTML.Text = String.Format("<div class='embed-video {1}'><iframe src='//player.vimeo.com/video/{0}' width='WIDTH' height='HEIGHT' frameborder='0' webkitallowfullscreen mozallowfullscreen allowfullscreen></iframe>" +
"<div class='embed-video-overflow vimeo {3}' {2}>" +
"<span class='embed-video-icon'></span></div></div>", EmbedTools.GetVimeoID(Vimeo), VideoSize, GetVimeoThumbnailImage(), IsPopupVideo());
break;
case EmbedVideoType.URL:
StringBuilder result = new StringBuilder();
result.Append(String.Format("<div class='embed-video {0}'><video controls id='html-video'>", VideoSize));
result.Append(String.Format("<source src='{0}' type='{1}'>", CustomURL, "video/" + URLHelper.GetUrlExtension(CustomURL).Remove(0,1)));
if (!String.IsNullOrEmpty(CustomURL2))
{
result.Append(String.Format("<source src='{0}' type='{1}'>", CustomURL2, "video/" + URLHelper.GetUrlExtension(CustomURL2).Remove(0,1)));
}
result.Append("Your browser does not support the video tag.");
result.Append("</video>");
result.Append(String.Format("<a class='embed-video-overflow html {1}' style='background-image: url(\"{0}\");'>"+
"<span class='embed-video-icon'></span></a>", ThumbnailImage, IsPopupVideo()));
result.Append("</div>");
ltrHTML.Text = result.ToString();
break;
case EmbedVideoType.CustomCode:
ltrHTML.Text = CustomHTML;
break;
}
}
}