using System.Web;
using CMS.GlobalHelper;
using CMS.PortalControls;
using CMS.SettingsProvider;
public partial class CMSWebParts_CommunityServices_GoogleVideo : CMSAbstractWebPart
{
#region "Public properties"
///
/// Gets or sets the value that indicates whether the video is automatically activated.
///
public bool AutoActivation
{
get
{
return ValidationHelper.GetBoolean(GetValue("AutoActivation"), false);
}
set
{
SetValue("AutoActivation", value);
}
}
///
/// Gets or sets the URL of Google video to be displayed.
///
public string VideoURL
{
get
{
return ValidationHelper.GetString(GetValue("VideoURL"), "");
}
set
{
SetValue("VideoURL", value);
}
}
///
/// Gets or sets the video width.
///
public int Width
{
get
{
return ValidationHelper.GetInteger(GetValue("Width"), 425);
}
set
{
SetValue("Width", value);
}
}
///
/// Gets or sets the video height.
///
public int Height
{
get
{
return ValidationHelper.GetInteger(GetValue("Height"), 355);
}
set
{
SetValue("Height", value);
}
}
///
/// Gets or sets the value that indicates whether video start immediately after webpart load.
///
public bool AutoPlay
{
get
{
return ValidationHelper.GetBoolean(GetValue("AutoPlay"), false);
}
set
{
SetValue("AutoPlay", value);
}
}
#endregion
#region "Methods"
///
/// Content loaded event handler.
///
public override void OnContentLoaded()
{
base.OnContentLoaded();
SetupControl();
}
///
/// Reloads data for partial caching.
///
public override void ReloadData()
{
base.ReloadData();
SetupControl();
}
///
/// Initializes the control properties.
///
protected void SetupControl()
{
if (StopProcessing)
{
// Do nothing
}
else
{
// video url
string url = null;
// query string autoplay value
string autoPlay = null;
string videoUrl = HTMLHelper.HTMLEncode(VideoURL);
// Index of query string parameter value 'docid'
int pos = videoUrl.LastIndexOfCSafe("?docid=");
// Set real video url in accordance to VideoUrl property value
if (pos != -1)
{
url = "http://video.google.com/googleplayer.swf" + videoUrl.Substring(pos) + "&hl=en";
}
else
{
url = videoUrl;
}
// Ensure autoplay
if (AutoPlay)
{
autoPlay = "&autoPlay=true";
}
if (AutoActivation)
{
ltlPlaceholder.Text = "
";
// Get external script function
ScriptHelper.RegisterScriptFile(Page, "~/CMSWebParts/CommunityServices/GoogleVideo_files/video.js");
// Call function for video object insertion
ltlScript.Text = BuildScriptBlock(url);
}
else
{
//
ltlPlaceholder.Text = "";
}
}
}
///
/// Creates a script block which loads a Google video at runtime.
///
/// URL to the video
/// Script block that will load a Google video
private string BuildScriptBlock(string url)
{
string scriptBlock = string.Format("LoadGVideo('GVPlaceholder_{0}', '{1}', {2}, {3}, {4});",
ltlScript.ClientID,
url,
Width,
Height,
AutoPlay.ToString().ToLowerCSafe());
return ScriptHelper.GetScript(scriptBlock);
}
#endregion
}