using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Text;
using CMS.PortalControls;
using CMS.SocialNetworking;
using CMS.GlobalHelper;
using CMS.SettingsProvider;
using CMS.UIControls;
using CMS.CMSHelper;
using CMS.PortalEngine;
public partial class CMSWebParts_CommunityServices_GooglePlus_GooglePlusActivityFeed : CMSAbstractWebPart
{
#region "Properties"
///
/// ID of the user or page (can be profile URL).
///
public string FeedID
{
get
{
return HTMLHelper.StripTags(ValidationHelper.GetString(GetValue("FeedID"), string.Empty));
}
set
{
SetValue("FeedID", value);
}
}
///
/// Width of the web part in pixels.
///
public int Width
{
get
{
return ValidationHelper.GetInteger(GetValue("Width"), 0);
}
set
{
SetValue("Width", value);
}
}
///
/// Height of the web part in pixels.
///
public int Height
{
get
{
return ValidationHelper.GetInteger(GetValue("Height"), 0);
}
set
{
SetValue("Height", value);
}
}
///
/// Maximal number of activities to display.
///
public int NumberOfActivities
{
get
{
return ValidationHelper.GetInteger(GetValue("NumberOfActivities"), 5);
}
set
{
SetValue("NumberOfActivities", value);
}
}
///
/// Whether to show scrollbar.
///
public bool Scrollbar
{
get
{
return ValidationHelper.GetBoolean(GetValue("Scrollbar"), false);
}
set
{
SetValue("Scrollbar", value);
}
}
///
/// Shell background color.
///
public string ShellBackgroundColor
{
get
{
return ValidationHelper.GetString(GetValue("ShellBackgroundColor"), string.Empty);
}
set
{
SetValue("ShellBackgroundColor", value);
}
}
///
/// Shell text color.
///
public string ShellTextColor
{
get
{
return ValidationHelper.GetString(GetValue("ShellTextColor"), string.Empty);
}
set
{
SetValue("ShellTextColor", value);
}
}
///
/// Activity text color.
///
public string ActivityTextColor
{
get
{
return ValidationHelper.GetString(GetValue("ActivityTextColor"), string.Empty);
}
set
{
SetValue("ActivityTextColor", value);
}
}
///
/// Activity footer text color.
///
public string ActivityFooterTextColor
{
get
{
return ValidationHelper.GetString(GetValue("ActivityFooterTextColor"), string.Empty);
}
set
{
SetValue("ActivityFooterTextColor", value);
}
}
///
/// Border color.
///
public string BorderColor
{
get
{
return ValidationHelper.GetString(GetValue("BorderColor"), string.Empty);
}
set
{
SetValue("BorderColor", value);
}
}
#endregion
#region "Methods"
///
/// Content loaded event handler
///
public override void OnContentLoaded()
{
base.OnContentLoaded();
SetupControl();
}
///
/// Initializes the control properties
///
protected void SetupControl()
{
if (StopProcessing)
{
// Do not process
}
else
{
string apiKey = SettingsKeyProvider.GetStringValue(CMSContext.CurrentSiteName + ".CMSGooglePlusClientID");
string apiSecret = SettingsKeyProvider.GetStringValue(CMSContext.CurrentSiteName + ".CMSGooglePlusClientSecret");
string accessToken = SettingsKeyProvider.GetStringValue(CMSContext.CurrentSiteName + ".CMSGooglePlusAccessToken");
// Check Social networking DLL and settings
if (!SiteManagerFunctions.CheckSocialNetworkingDLL())
{
// Error label is displayed in Design mode when Dll is renamed
ShowDesignErrorOrHide(GetString("socialnetworking.renameddll"));
}
else if (String.IsNullOrEmpty(apiKey) || String.IsNullOrEmpty(apiSecret) || String.IsNullOrEmpty(accessToken))
{
// Error label is displayed in Design mode when missing settings
string pathToSettings = SocialNetworkingHelper.GetPathToGooglePlusSettings();
ShowDesignErrorOrHide(String.Format(GetString("socialnetworking.googleplus.allsettingsmissing"), pathToSettings));
}
else
{
// Process ID - it can be URL
string showID = ExtractUserID(FeedID);
GooglePlusPerson profile = null;
// Fetch data from Google+
try
{
// Try to get person directly
profile = GooglePlusProvider.GetProfileInfo(showID);
}
catch
{
try
{
// Try alternative approach (search for person)
profile = GooglePlusProvider.FindPerson(showID);
}
catch
{
ShowDesignErrorOrHide(String.Format(GetString("sm.googleplus.nopeoplefound"), showID));
}
}
if (profile != null)
{
showID = profile.UserID;
List activities = GooglePlusProvider.GetActivities(showID, NumberOfActivities);
// Build code for plugin
StringBuilder sb = new StringBuilder();
sb.Append("