public static MvcHtmlString CreateFacebookLikeButton(this HtmlHelper htmlHelper, string href, int width, int height, bool showFaces,bool send, FacebookLikeLayout layout, FacebookLikeFont font, FacebookLikeColorScheme colorScheme, FacebookLikeAction action) { string src = ""; string widthValue = CalculateWidth(layout, width).ToString(); string heightValue = CalculateHeight(layout, height).ToString(); string layoutValue = layout.ToString().ToLower(); string fontValue = GetFontValue(font); string actionValue = action.ToString().ToLower(); string colorSchemeValue = colorScheme.ToString().ToLower(); string showFacesValue = showFaces.ToString().ToLower(); StringBuilder sb = new StringBuilder(); sb.Append("http://www.facebook.com/plugins/like.php?app_id=225243224169155&href="); sb.Append(href + "&"); if (send == true) { sb.Append("send=true&"); } else { sb.Append("send=false&"); } sb.Append("height=" + heightValue + "&"); sb.Append("width=" + widthValue + "&"); sb.Append("layout=" + layoutValue + "&"); sb.Append("show_faces=" + showFacesValue + "&"); sb.Append("action=" + actionValue + "&"); sb.Append("colorscheme=" + colorSchemeValue + "&"); sb.Append("font=" + fontValue); src = sb.ToString(); TagBuilder iframe = new TagBuilder("iframe"); iframe.Attributes["src"] = src; iframe.Attributes["scrolling"] = "no"; iframe.Attributes["frameborder"] = "0"; iframe.Attributes["style"] = "border:none; overflow:hidden; width:" + widthValue + "px; height:" + heightValue + "px;"; iframe.Attributes["allowTransparency"] = "true"; return MvcHtmlString.Create(iframe.ToString()); }
public static MvcHtmlString GetHtml(this HtmlHelper htmlHelper, string href, int width, int height, bool showFaces, FacebookLikeLayout layout, FacebookLikeFont font, FacebookLikeColorScheme colorScheme, FacebookLikeAction action) { /* <iframe * src="http://www.facebook.com/plugins/like.php?app_id=225243224169155& * href=http%3A%2F%2Fwww.yahoo.com& * send=false& * layout=standard& * width=450& * show_faces=true& * action=like& * colorscheme=light& * font=arial& * height=80" * scrolling="no" * frameborder="0" * style="border:none; overflow:hidden; width:450px; height:80px;" * allowTransparency="true"> </iframe>*/ StringBuilder src = new StringBuilder(); src.Append("http://www.facebook.com/plugins/like.php?app_id=225243224169155&href="); src.Append(HttpUtility.UrlEncode(href) + "&"); src.Append("send=false&"); src.Append("layout=" + layout.ToString().ToLower() + "&"); src.Append("show_faces=" + showFaces.ToString().ToLower() + "&"); src.Append("action=" + action.ToString().ToLower() + "&"); src.Append("colorscheme=" + colorScheme.ToString().ToLower() + "&"); src.Append("font=" + font.ToString().ToLower() + "&"); src.Append("height=" + height.ToString().ToLower()); TagBuilder iframe = new TagBuilder("iframe"); iframe.Attributes["src"] = src.ToString(); iframe.Attributes["scrolling"] = "no"; iframe.Attributes["frameborder"] = "0"; iframe.Attributes["style"] = "border:none; overflow:hidden; width:450px; height:80px;"; iframe.Attributes["allowTransparency"] = "true"; return MvcHtmlString.Create(iframe.ToString()); }
private static int CalculateWidth(FacebookLikeLayout layout, int currentWidth) { if (layout == FacebookLikeLayout.Standard) { if (currentWidth < 225) throw new Exception("FacebookLikeButton's width with the " + layout.ToString() + " cannot be " + currentWidth + ". Please change to 225 or greater."); } else if (layout == FacebookLikeLayout.Button_Count) { if (currentWidth < 90) throw new Exception("FacebookLikeButton's width with the " + layout.ToString() + " cannot be " + currentWidth + ". Please change to 90 or greater."); } else if (layout == FacebookLikeLayout.Box_Count) { if (currentWidth < 55) throw new Exception("FacebookLikeButton's width with the " + layout.ToString() + " cannot be " + currentWidth + ". Please change to 55 or greater."); } return currentWidth; }
private static int CalculateHeight(FacebookLikeLayout layout, int currentHeight) { if (layout == FacebookLikeLayout.Standard) { if (currentHeight < 35) throw new Exception("FacebookLikeButton's height with the " + layout.ToString() + " cannot be " + currentHeight + ". Please change to 35 or greater."); } else if (layout == FacebookLikeLayout.Button_Count) { if (currentHeight != 20) throw new Exception("FacebookLikeButton's height with the " + layout.ToString() + " cannot be " + currentHeight + ". Please change to 20."); } else if (layout == FacebookLikeLayout.Box_Count) { if (currentHeight != 65) throw new Exception("FacebookLikeButton's height with the " + layout.ToString() + " cannot be " + currentHeight + ". Please change to 65."); } return currentHeight; }