using System;
using System.Data;
using System.Collections;
using System.Text;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using CMS.CMSHelper;
using CMS.GlobalHelper;
using CMS.PortalControls;
using CMS.SettingsProvider;
using TreeNode = CMS.DocumentEngine.TreeNode;
public partial class CMSWebParts_CommunityServices_SocialBookmarking : CMSAbstractWebPart
{
#region "Private variables"
///
/// Hashtable which contains info about bookmark services.
///
private static readonly Hashtable bookmarkServices = new Hashtable();
#endregion
#region "Services properties"
///
/// Google bookmarks service.
///
public bool GoogleBookmarks
{
get
{
return ValidationHelper.GetBoolean(GetValue("GoogleBookmarks"), false);
}
set
{
SetValue("GoogleBookmarks", value);
}
}
///
/// Delicious service.
///
public bool Delicious
{
get
{
return ValidationHelper.GetBoolean(GetValue("Delicious"), false);
}
set
{
SetValue("Delicious", value);
}
}
///
/// Digg service.
///
public bool Digg
{
get
{
return ValidationHelper.GetBoolean(GetValue("Digg"), false);
}
set
{
SetValue("Digg", value);
}
}
///
/// MySpace service.
///
public bool MySpace
{
get
{
return ValidationHelper.GetBoolean(GetValue("MySpace"), false);
}
set
{
SetValue("MySpace", value);
}
}
///
/// Facebook service.
///
public bool FaceBook
{
get
{
return ValidationHelper.GetBoolean(GetValue("FaceBook"), false);
}
set
{
SetValue("FaceBook", value);
}
}
///
/// YahooMyWeb service.
///
public bool YahooMyWeb
{
get
{
return ValidationHelper.GetBoolean(GetValue("YahooMyWeb"), false);
}
set
{
SetValue("YahooMyWeb", value);
}
}
///
/// Stumble upon service.
///
public bool StumbleUpon
{
get
{
return ValidationHelper.GetBoolean(GetValue("StumbleUpon"), false);
}
set
{
SetValue("StumbleUpon", value);
}
}
///
/// Reddit service.
///
public bool Reddit
{
get
{
return ValidationHelper.GetBoolean(GetValue("Reddit"), false);
}
set
{
SetValue("Reddit", value);
}
}
///
/// Newsvine service.
///
public bool Newsvine
{
get
{
return ValidationHelper.GetBoolean(GetValue("Newsvine"), false);
}
set
{
SetValue("Newsvine", value);
}
}
///
/// Technorati service.
///
public bool Technorati
{
get
{
return ValidationHelper.GetBoolean(GetValue("Technorati"), false);
}
set
{
SetValue("Technorati", value);
}
}
///
/// Twitter service.
///
public bool Twitter
{
get
{
return ValidationHelper.GetBoolean(GetValue("Twitter"), false);
}
set
{
SetValue("Twitter", value);
}
}
///
/// YahooBookmarks.
///
public bool YahooBookmarks
{
get
{
return ValidationHelper.GetBoolean(GetValue("YahooBookmarks"), false);
}
set
{
SetValue("YahooBookmarks", value);
}
}
///
/// MyAOL service.
///
public bool MyAOL
{
get
{
return ValidationHelper.GetBoolean(GetValue("MyAOL"), false);
}
set
{
SetValue("MyAOL", value);
}
}
///
/// Fark service.
///
public bool Fark
{
get
{
return ValidationHelper.GetBoolean(GetValue("Fark"), false);
}
set
{
SetValue("Fark", value);
}
}
///
/// Multiply service.
///
public bool Multiply
{
get
{
return ValidationHelper.GetBoolean(GetValue("Multiply"), false);
}
set
{
SetValue("Multiply", value);
}
}
///
/// Blogmarks service.
///
public bool Blogmarks
{
get
{
return ValidationHelper.GetBoolean(GetValue("Blogmarks"), false);
}
set
{
SetValue("Blogmarks", value);
}
}
///
/// Diigo service.
///
public bool Diigo
{
get
{
return ValidationHelper.GetBoolean(GetValue("Diigo"), false);
}
set
{
SetValue("Diigo", value);
}
}
///
/// Daves service.
///
public bool Faves
{
get
{
return ValidationHelper.GetBoolean(GetValue("Faves"), false);
}
set
{
SetValue("Faves", value);
}
}
///
/// Link-a-gogo service.
///
public bool LinkAGogo
{
get
{
return ValidationHelper.GetBoolean(GetValue("LinkAGogo"), false);
}
set
{
SetValue("LinkAGogo", value);
}
}
///
/// MisterWong service.
///
public bool MisterWong
{
get
{
return ValidationHelper.GetBoolean(GetValue("MisterWong"), false);
}
set
{
SetValue("MisterWong", value);
}
}
///
/// Magnolia service.
///
public bool Magnolia
{
get
{
return ValidationHelper.GetBoolean(GetValue("Magnolia"), false);
}
set
{
SetValue("Magnolia", value);
}
}
///
/// Seganlo service.
///
public bool Segnalo
{
get
{
return ValidationHelper.GetBoolean(GetValue("Segnalo"), false);
}
set
{
SetValue("Segnalo", value);
}
}
///
/// LinkedIn service.
///
public bool LinkedIn
{
get
{
return ValidationHelper.GetBoolean(GetValue("LinkedIn"), false);
}
set
{
SetValue("LinkedIn", value);
}
}
#endregion
#region "Other properties"
///
/// Title (text before bookmarks).
///
public string Title
{
get
{
return ValidationHelper.GetString(GetValue("Title"), "");
}
set
{
SetValue("Title", value);
}
}
///
/// Separator.
///
public string Separator
{
get
{
return ValidationHelper.GetString(GetValue("Separator"), "");
}
set
{
SetValue("Separator", value);
}
}
///
/// Title CSS class.
///
public string TitleClass
{
get
{
return ValidationHelper.GetString(GetValue("TitleClass"), "");
}
set
{
SetValue("TitleClass", value);
}
}
///
/// If true, links are opened in new window.
///
public bool ShowInNewWindow
{
get
{
return ValidationHelper.GetBoolean(GetValue("ShowInNewWindow"), false);
}
set
{
SetValue("ShowInNewWindow", value);
}
}
#endregion
#region "Events"
///
/// Page load.
///
protected void Page_Load(object sender, EventArgs e)
{
}
///
/// Content loaded event handler.
///
public override void OnContentLoaded()
{
base.OnContentLoaded();
SetupControl();
}
///
/// Reloads data.
///
public override void ReloadData()
{
base.ReloadData();
SetupControl();
}
#endregion
#region "Methods"
///
/// Fill hashtables.
///
private static void FillHashTable()
{
if (bookmarkServices.Count == 0)
{
lock (bookmarkServices)
{
// Each record has display name, url, url to book and title
bookmarkServices["GoogleBookmarks"] = new string[] { "Google Bookmarks", "http://www.google.com/bookmarks/mark?op=add&bkmk=", "&title=" };
bookmarkServices["Delicious"] = new string[] { "Delicious", "http://delicious.com/save?jump=yes&noui&v=4&url=", "&title=" };
bookmarkServices["Digg"] = new string[] { "Digg", "http://digg.com/submit/?url=", "&title=" };
bookmarkServices["MySpace"] = new string[] { "MySpace", "http://www.myspace.com/Modules/PostTo/Pages/?u=", "&t=" };
bookmarkServices["FaceBook"] = new string[] { "Facebook", "http://www.facebook.com/sharer.php?u=", "&t=" };
bookmarkServices["YahooMyWeb"] = new string[] { "Yahoo MyWeb", "http://myweb2.search.yahoo.com/myresults/bookmarklet?u=", "&t=" };
bookmarkServices["StumbleUpon"] = new string[] { "StumbleUpon", "http://www.stumbleupon.com/submit?url=", "&title=" };
bookmarkServices["Reddit"] = new string[] { "Reddit", "http://www.reddit.com/submit?url=", "&title=" };
bookmarkServices["Newsvine"] = new string[] { "Newsvine", "http://www.newsvine.com/_tools/seed&save?u=", "&h=" };
bookmarkServices["Technorati"] = new string[] { "Terchnorati", "http://technorati.com/faves/?add=", "&title=" };
bookmarkServices["Twitter"] = new string[] { "Twitter", "http://twitter.com/share?url=", "&text=" };
bookmarkServices["YahooBookmarks"] = new string[] { "Yahoo Bookmarks", "http://bookmarks.yahoo.com/toolbar/savebm?u=", "&t=" };
bookmarkServices["MyAOL"] = new string[] { "MyAOL", "http://favorites.my.aol.com/ffclient/webroot/0.4.5/src/html/addBookmarkDialog.html?url=", "&title=" };
bookmarkServices["Fark"] = new string[] { "Fark", "http://cgi.fark.com/cgi/fark/submit.pl?new_url=", "&new_comment=" };
bookmarkServices["Multiply"] = new string[] { "Multiply", "http://multiply.com/gus/journal/compose/?url=", "&subject=" };
bookmarkServices["Blogmarks"] = new string[] { "Blogmarks", "http://blogmarks.net/my/new.php?url=", "&title=" };
bookmarkServices["Diigo"] = new string[] { "Diigo", "http://www.diigo.com/post?url=", "&title=" };
bookmarkServices["Faves"] = new string[] { "Faves", "http://faves.com/Authoring.aspx?u=", "&t=" };
bookmarkServices["LinkAGogo"] = new string[] { "Link-a-Gogo", "http://www.linkagogo.com/go/AddNoPopup?url=", "&title=" };
bookmarkServices["MisterWong"] = new string[] { "Mister Wong", "http://www.mister-wong.com/index.php?action=addurl&bm_url=", "&bm_description=" };
bookmarkServices["Segnalo"] = new string[] { "Segnalo", "http://segnalo.alice.it/post.html.php?url=", "&title=" };
bookmarkServices["LinkedIn"] = new string[] { "LinkedIn", "http://www.linkedin.com/shareArticle?mini=true&url=", "&title=" };
}
}
}
///
/// Initializes the control properties.
///
public void SetupControl()
{
ltlIcons.Text = "";
// Fill hashtable with info about all bookmark services
FillHashTable();
// Resolve path of images
string imagesPath = ResolveUrl("~/CMSWebParts/CommunityServices/SocialBookmarking_files");
// Get current document
TreeNode node = CMSContext.CurrentDocument;
if (node != null)
{
// Get url of current document
string liveUrl = URLHelper.CurrentURL;
liveUrl = URLHelper.GetAbsoluteUrl(liveUrl);
// Encode url
liveUrl = Server.UrlEncode(liveUrl);
// Prepare target
string target = ShowInNewWindow ? "target=\"_blank\"" : "";
string[] bookmarkInfo = new string[4];
// Get all keys from hashtable
object[] keys = new object[bookmarkServices.Count];
bookmarkServices.Keys.CopyTo(keys, 0);
StringBuilder sb = new StringBuilder();
// Loop thru all items in hashtable
for (int i = 0; i != keys.Length; i++)
{
// Get structure
bookmarkInfo = (string[])bookmarkServices[keys[i]];
string currentService = keys[i].ToString();
if (bookmarkInfo.Length != 0)
{
// If current service is enabled generate html code
if (ValidationHelper.GetBoolean(GetValue(currentService), false))
{
if (sb.Length > 0)
{
sb.Append(Separator);
}
sb.Append("
");
}
}
}
// If at least one bookmarking service was checked show title
if (sb.Length > 0)
{
if (!string.IsNullOrEmpty(TitleClass))
{
sb.Insert(0, "" + Title + "");
}
else
{
sb.Insert(0, Title);
}
// Wrap with span with class
sb.Insert(0, "");
sb.Append("");
}
ltlIcons.Text = sb.ToString();
}
}
#endregion
}