/// <summary> /// Handles the CommentServing event of the Post control. /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="e">The <see cref="BlogEngine.Core.ServingEventArgs"/> instance containing the event data.</param> private static void PostCommentServing(object sender, ServingEventArgs e) { if (!ExtensionManager.ExtensionEnabled("BBCode")) { return; } var body = e.Body; // retrieve parameters back as a data table // column = parameter if (Settings != null) { var table = Settings.GetDataTable(); foreach (DataRow row in table.Rows) { if (string.IsNullOrEmpty((string)row["CloseTag"])) { Parse(ref body, (string)row["Code"], (string)row["OpenTag"]); } else { Parse(ref body, (string)row["Code"], (string)row["OpenTag"], (string)row["CloseTag"]); } } } e.Body = body; }
private static void Publishable_Serving(object sender, ServingEventArgs e) { if (!ExtensionManager.ExtensionEnabled("MediaElementPlayer")) return; if (e.Location == ServingLocation.PostList || e.Location == ServingLocation.SinglePost || e.Location == ServingLocation.Feed || e.Location == ServingLocation.SinglePage) { HttpContext context = HttpContext.Current; string regex = @"(video|audio)"; List<ShortCode> shortCodes = GetShortCodes(e.Body, regex, true); if (shortCodes.Count == 0) return; ProcessMediaTags(e, shortCodes); // this won't happen on feeds if (context.CurrentHandler is Page) { Page page = (Page)context.CurrentHandler; AddHeader(page); AddFooter(page); } } }
/// <summary> /// Handles the CommentServing event of the Post control. /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="e">The <see cref="BlogEngine.Core.ServingEventArgs"/> instance containing the event data.</param> private static void PostCommentServing(object sender, ServingEventArgs e) { if (!ExtensionManager.ExtensionEnabled("Smilies")) { return; } if (string.IsNullOrEmpty(e.Body)) { return; } e.Body = e.Body.Replace("(H)", Convert("cool", "Cool")); e.Body = e.Body.Replace(":'(", Convert("cry", "Cry")); e.Body = e.Body.Replace(":$", Convert("embarassed", "Embarassed")); e.Body = e.Body.Replace(":|", Convert("foot-in-mouth", "Foot")); e.Body = e.Body.Replace(":(", Convert("frown", "Frown")); e.Body = e.Body.Replace("(A)", Convert("innocent", "Innocent")); e.Body = e.Body.Replace("(K)", Convert("kiss", "Kiss")); e.Body = e.Body.Replace(":D", Convert("laughing", "Laughing")); e.Body = e.Body.Replace("($)", Convert("money-mouth", "Money")); e.Body = e.Body.Replace(":-#", Convert("sealed", "Sealed")); e.Body = e.Body.Replace(":)", Convert("smile", "Smile")); e.Body = e.Body.Replace(":-)", Convert("smile", "Smile")); e.Body = e.Body.Replace(":-O", Convert("surprised", "Surprised")); e.Body = e.Body.Replace(":P", Convert("tongue-out", "Tong")); e.Body = e.Body.Replace("*-)", Convert("undecided", "Undecided")); e.Body = e.Body.Replace(";-)", Convert("wink", "Wink")); e.Body = e.Body.Replace("8o|", Convert("yell", "Yell")); }
private static void PostServing(object sender, ServingEventArgs e) { if (e.Location == ServingLocation.PostList || e.Location == ServingLocation.SinglePost) { e.Body = GetBody(e.Body); } }
/// <summary> /// Replaces the [more] string on the full post page. /// </summary> /// <param name="e"> /// The event arguments. /// </param> private static void PrepareFullPost(ServingEventArgs e) { var request = HttpContext.Current.Request; e.Body = request.UrlReferrer == null || request.UrlReferrer.Host != request.Url.Host ? e.Body.Replace("[more]", string.Empty) : e.Body.Replace("[more]", "<span id=\"continue\"></span>"); }
void Post_Serving(object sender, ServingEventArgs e) { // [gist id=1234] e.Body = Regex.Replace(e.Body, "\\[gist\\s[^\\]]*id=(\\d+)[^\\]]*\\]", "<script src=\"https://gist.github.com/$1.js\"></script>"); // [gist]1234[/gist] e.Body = Regex.Replace(e.Body, "\\[gist\\](\\d+)\\[\\/gist\\]", "<script src=\"https://gist.github.com/$1.js\"></script>"); e.Body = Regex.Replace(e.Body, "(\\n|<(br|p)\\s*/?>)\\s*https://gist\\.github\\.com/(\\w+/)?(\\d+)/?\\s*(\\n|<(br|p)\\s*/?>|</p>|</li>)", "<script src=\"https://gist.github.com/$4.js\"></script>"); e.Body = Regex.Replace(e.Body, "\\[gist\\s+https://gist\\.github\\.com/(\\w+/)?(\\d+)/?\\s*\\]", "<script src=\"https://gist.github.com/$2.js\"></script>"); }
/// <summary> /// The event handler that is triggered every time a comment is served to a client. /// </summary> private static void Post_CommentServing(object sender, ServingEventArgs e) { if (string.IsNullOrEmpty(e.Body)) { return; } e.Body = regex.Replace(e.Body, new MatchEvaluator(ResolveLinks.Evaluator)); }
private static void OnPostServing(object sender, ServingEventArgs e) { Post post = sender as Post; if (post != null) { e.Body = string.Concat(e.Body, Generate(post)); } }
private void OnPostServing(object sender, ServingEventArgs e) { IPublishable ipub = ((IPublishable)sender); string body = String.Empty; if (e.Location == ServingLocation.SinglePost && HttpContext.Current.Request.IsAuthenticated == false) { Counter.Hit(ipub.Id.ToString()); } }
static string GetPostExcerpt(ServingEventArgs e, string moreLink) { e.Body = Utils.StripHtml(e.Body); if (e.Body.Length > postLength) { return(e.Body.Substring(0, postLength) + "... " + moreLink); } return(e.Body); }
/// <summary> /// event method for the post serving /// </summary> /// <param name="sender">the post</param> /// <param name="e">the event args</param> void Post_Serving(object sender, ServingEventArgs e) { if (HttpContext.Current == null) { return; } var post = (Post)sender; var ctx = HttpContext.Current; AppendContext(ctx); }
void Page_Serving(object sender, ServingEventArgs e) { _formAction = ""; if (e.Location == ServingLocation.SinglePage) { var page = (BlogEngine.Core.Page)sender; if (page.IsFrontPage) { _formAction = string.Format("page/{0}?id={1}", page.Slug, page.Id); } } }
private void PrepareFacebookCompartilhar(object sender, ServingEventArgs e) { if (e.Location == ServingLocation.PostList || e.Location == ServingLocation.SinglePost) { HttpContext context = HttpContext.Current; if (context.CurrentHandler is System.Web.UI.Page) { if (context.Items[ExtensionName] == null) { var page = (System.Web.UI.Page)context.CurrentHandler; var Script = new StringBuilder(); Script.AppendLine(""); Script.AppendLine("<!-- Inicio facebook compartilhamento -->"); Script.AppendLine("<script type=\"text/javascript\">"); Script.AppendLine("//<![CDATA["); Script.AppendLine("function shareFunc(href, title, desc, img){"); Script.AppendLine(" //var url = \"http://www.facebook.com/share.php?u=\" + encodeURIComponent(href) + \"&t=\" + encodeURIComponent(title) + \"&d=\" + encodeURIComponent(desc) + \"&i=\" + encodeURIComponent(img);"); Script.AppendLine(" var url1 = \"http://www.facebook.com/share.php?u=\";"); //Script.AppendLine(" var url2 = encodeURIComponent(\"http://fb-share-control.com/?\" + \"t=\" + title + \"&d=\" + desc + \"&u=\" + href);"); Script.AppendLine(" var url2 = encodeURIComponent(\"http://fb-share-control.com/?\" + \"t=\" + title + \"&i=\" + img + \"&d=\" + desc + \"&u=\" + href);"); Script.AppendLine(" var url = url1 + \"\" + url2;"); Script.AppendLine(" //alert(url);"); Script.AppendLine(" window.open(url,\"Comparilhar\",\"width=640,height=300\");"); Script.AppendLine("}"); Script.AppendLine("//]]>"); Script.AppendLine("</script>"); Script.AppendLine("<style type=\"text/css\">.facebookCompartilhar{padding:2px 0 0 20px; height:16px; background:url(http://static.ak.fbcdn.net/images/share/facebook_share_icon.gif) no-repeat top left; color: #6D84B4;cursor: pointer;text-decoration: none;}</style>"); page.ClientScript.RegisterStartupScript(page.GetType(), "FacebookCompartilharScripts", Script.ToString(), false); context.Items[ExtensionName] = 1; } var ListImagens = ""; if (findImg) { if (ER_IMG.IsMatch(e.Body)) { MatchCollection imagens = ER_IMG.Matches(e.Body); ListImagens = string.Format("http://{0}{1}", ((Post)sender).AbsoluteLink.Authority, imagens[0].Result("${img}")); } } if (ondeExibir.Equals("Topo")) { e.Body = string.Format("<p><a class=\"facebookCompartilhar\" onclick=\"shareFunc('{1}','{2}','{3}','{4}');\" >Compartilhar</a></p>{0}", e.Body, ((Post)sender).AbsoluteLink, ((Post)sender).Title, ((Post)sender).Description, ListImagens); } else { e.Body = string.Format("{0}<p><a class=\"facebookCompartilhar\" onclick=\"shareFunc('{1}','{2}','{3}','{4}');\" >Compartilhar</a></p>", e.Body, ((Post)sender).AbsoluteLink, ((Post)sender).Title, ((Post)sender).Description, ListImagens); } } } }
private void Page_Serving(object sender, ServingEventArgs e) { if (e.Location != ServingLocation.SinglePage) { return; } string regex__1 = @"\[youtube:.*?\]"; MatchCollection matches = Regex.Matches(e.Body, regex__1); if (matches.Count == 0) { return; } Int32 width = default(Int32); Int32 height = default(Int32); Int32 border = default(Int32); String color1 = default(String); String color2 = default(String); String BaseURL = default(String); try { width = Int32.Parse(settings.GetSingleValue("width")); height = Int32.Parse(settings.GetSingleValue("height")); border = Int32.Parse(settings.GetSingleValue("border")); color1 = settings.GetSingleValue("color1"); color2 = settings.GetSingleValue("color2"); BaseURL = "http://www.youtube.com/v/"; } catch { return; } for (int i = 0; i < matches.Count; i++) { Int32 length = "[youtube:".Length; string mediaFile = matches[i].Value.Substring(length, matches[i].Value.Length - length - 1); string player = @"<div id=""YouTubePlayer_{0}"" style=""width:{2}px; height:{3}px;""> <object width=""{2}"" height=""{3}""> <param name=""movie"" value=""{7}{1}&fs=1&border={4}&color1=0x{5}&color2=0x{6}""></param> <param name=""allowFullScreen"" value=""true""></param> <embed src=""{7}{1}&fs=1&border={4}&color1=0x{5}&color2=0x{6}"" type = ""application/x-shockwave-flash"" width=""{2}"" height=""{3}"" allowfullscreen=""true""></embed> </object> </div>"; e.Body = e.Body.Replace(matches[i].Value, String.Format(player, i, mediaFile, width, height, border, color1, color2, BaseURL)); } }
private static void ProcessMediaTags(ServingEventArgs e, List <ShortCode> shortCodes) { // path to media string folder = Settings.GetSingleValue("folder"); string path = Utils.RelativeWebRoot + folder.TrimEnd(new char[] { '/' }) + "/"; // override for feed if (e.Location == ServingLocation.Feed) { path = Utils.AbsoluteWebRoot + folder.TrimEnd(new char[] { '/' }) + "/"; } // do replacement for media foreach (ShortCode sc in shortCodes) { string tagName = sc.TagName; string key = sc.GetAttributeValue("key", ""); string w = sc.GetAttributeValue("width", ""); string h = sc.GetAttributeValue("height", ""); if (w == "") { w = _widthDefault.ToString(); } if (h == "") { h = _heightDefault.ToString(); } string code = ""; switch (key) { case "file": code = "<div align=\"center\"><iframe src=" + "\"http://docs.google.com/viewer?url=" + Utils.AbsoluteWebRoot.ToString() + "FILES/Media/" + sc.GetAttributeValue(key, "") + ".axdx&embedded=true\" " + "width=\"" + w + "\" height=\"" + h + "\" " + "style=\"border: none;\"" + "></iframe></div>"; break; case "url": code = "<div align=\"center\"><iframe src=" + "\"http://docs.google.com/viewer?url=" + sc.GetAttributeValue(key, "") + "&embedded=true\" " + "width=\"" + w + "\" height=\"" + h + "\" " + "style=\"border: none;\"" + "></iframe></div>"; break; } //code = "Key: " + key; e.Body = e.Body.Replace(sc.Text, code); } }
void Post_Serving(object sender, ServingEventArgs e) { Markdown md = new Markdown(new MarkdownOptions() { AutoHyperlink = bool.Parse(Options.GetSingleValue("autoHyperlink")), AutoNewlines = bool.Parse(Options.GetSingleValue("autoNewlines")), EmptyElementSuffix = Options.GetSingleValue("emptyElementSuffix"), EncodeProblemUrlCharacters = bool.Parse(Options.GetSingleValue("encodeProblemUrlCharacters")), LinkEmails = bool.Parse(Options.GetSingleValue("linkEmails")), StrictBoldItalic = bool.Parse(Options.GetSingleValue("strictBoldItalic")) }); e.Body = md.Transform(e.Body); }
/// <summary> /// Handles the CommentServing event of the Post control. /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="e">The <see cref="BlogEngine.Core.ServingEventArgs"/> instance containing the event data.</param> private static void PostCommentServing(object sender, ServingEventArgs e) { if (!ExtensionManager.ExtensionEnabled("ResolveLinks")) { return; } if (string.IsNullOrEmpty(e.Body)) { return; } e.Body = LinkRegex.Replace(e.Body, new MatchEvaluator(Evaluator)); }
protected void Post_Serving(object sender, ServingEventArgs e) { MembershipUser user = Membership.GetUser(); if (HttpContext.Current.Request.RawUrl.Contains("syndication.axd")) { return; } if (user == null) { HttpContext.Current.Response.Redirect("~/Login.aspx"); } }
private static void PostServing(object sender, ServingEventArgs e) { if (e.Body.Contains("[more]")) { return; } if (e.Location == ServingLocation.PostList) { var post = (Post)sender; string moreLink = string.Format("<a class=\"more\" href=\"{0}#continue\">{1}</a>", post.RelativeLink, labels.more); //e.Body = GetPostPicture(e) + GetPostExcerpt(e, moreLink); } }
/// <summary> /// Replaces the [more] string with a hyperlink to the full post. /// </summary> private static void AddMoreLink(object sender, ServingEventArgs e) { Post post = (Post)sender; int index = e.Body.IndexOf("[more]"); string link = "<a class=\"more\" href=\"" + post.RelativeLink + "#continue\">" + Resources.labels.more + "...</a>"; string NewBody = e.Body.Substring(0, index); // Need to close any open HTML tags in NewBody where the matching close tags have been truncated. string closingTagsToAppend = string.Empty; MatchCollection openingTagsCollection = openingTagRegex.Matches(NewBody); if (openingTagsCollection.Count > 0) { // Copy the opening tags in MatchCollection to a generic list. List <string> openingTags = new List <string>(); foreach (Match openTag in openingTagsCollection) { if (openTag.Groups.Count == 2) { openingTags.Add(openTag.Groups[1].Value); } } MatchCollection closingTagsCollection = closedTagRegex.Matches(NewBody); // Iterate through closed tags and remove the first matching open tag from the openingTags list. foreach (Match closedTag in closingTagsCollection) { if (closedTag.Groups.Count == 2) { int indexToRemove = openingTags.FindIndex(delegate(string openTag) { return(openTag.Equals(closedTag.Groups[1].Value, StringComparison.InvariantCultureIgnoreCase)); }); if (indexToRemove != -1) { openingTags.RemoveAt(indexToRemove); } } } // A closing tag needs to be created for any remaining tags in the openingTags list. if (openingTags.Count > 0) { // Reverse the order of the tags so tags opened later are closed first. openingTags.Reverse(); closingTagsToAppend = "</" + string.Join("></", openingTags.ToArray()) + ">"; } } e.Body = NewBody + link + closingTagsToAppend; }
/// <summary> /// An event that handles ServingEventArgs /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private static void PublishableServing(object sender, ServingEventArgs e) { if (!string.IsNullOrEmpty(e.Body)) { // only process the posts if (e.Location == ServingLocation.PostList || e.Location == ServingLocation.SinglePost || e.Location == ServingLocation.SinglePage || e.Location == ServingLocation.Feed) { const string regex = @"\[mp3:.*?\.mp3]"; var matches = Regex.Matches(e.Body, regex); if (matches.Count > 0) { if (e.Location != ServingLocation.Feed) { AddJsToTheHeader(); } var mp3Root = string.Format("{0}Custom/Media/mp3/", Utils.AbsoluteWebRoot); foreach (Match match in matches) { string filename = match.Value.Replace("[mp3:", "").Replace("]", "").Trim(); if (e.Location == ServingLocation.Feed) { // inject link to .mp3 file (to support enclosure) var url = mp3Root + filename; var link = "<a href=\"{0}\">{1}</a>"; link = string.Format(link, url, filename); e.Body = e.Body.Replace(match.Value, link); } else { // inject player object in the post var player = PlayerObject(filename); player = "<script type=\"text/javascript\">InsertPlayer(\"" + player + "\");</script>"; e.Body = e.Body.Replace(match.Value, player); } } } } } }
/// <summary> /// Handles the Post.Serving event to take care of the [more] keyword. /// </summary> private static void Post_Serving(object sender, ServingEventArgs e) { if (!e.Body.Contains("[more]")) return; if (e.Location == ServingLocation.PostList) { AddMoreLink(sender, e); } else if (e.Location == ServingLocation.SinglePost) { PrepareFullPost(e); } else if (e.Location == ServingLocation.Feed) { e.Body = e.Body.Replace("[more]", string.Empty); } }
/// <summary> /// Replaces the [more] string with a hyperlink to the full post. /// </summary> /// <param name="sender"> /// The sender. /// </param> /// <param name="e"> /// The event arguments. /// </param> private static void AddMoreLink(object sender, ServingEventArgs e) { var post = (Post)sender; var index = e.Body.IndexOf("[more]"); var link = string.Format("<a class=\"more\" href=\"{0}#continue\">{1}...</a>", post.RelativeLink, labels.more); var newBody = e.Body.Substring(0, index); // Need to close any open HTML tags in NewBody where the matching close tags have been truncated. var closingTagsToAppend = string.Empty; var openingTagsCollection = OpeningTagRegex.Matches(newBody); if (openingTagsCollection.Count > 0) { // Copy the opening tags in MatchCollection to a generic list. var openingTags = openingTagsCollection.Cast <Match>().Where(openTag => openTag.Groups.Count == 2).Select( openTag => openTag.Groups[1].Value).ToList(); var closingTagsCollection = ClosedTagRegex.Matches(newBody); // Iterate through closed tags and remove the first matching open tag from the openingTags list. foreach (var indexToRemove in from Match closedTag in closingTagsCollection where closedTag.Groups.Count == 2 select openingTags.FindIndex( openTag => openTag.Equals( closedTag.Groups[1].Value, StringComparison.InvariantCultureIgnoreCase)) into indexToRemove where indexToRemove != -1 select indexToRemove) { openingTags.RemoveAt(indexToRemove); } // A closing tag needs to be created for any remaining tags in the openingTags list. if (openingTags.Count > 0) { // Reverse the order of the tags so tags opened later are closed first. openingTags.Reverse(); closingTagsToAppend = string.Format("</{0}>", string.Join("></", openingTags.ToArray())); } } e.Body = newBody + link + closingTagsToAppend; }
private static void ProcessMediaTags(ServingEventArgs e, List<ShortCode> shortCodes) { // path to media string folder = Settings.GetSingleValue("folder"); string path = Utils.RelativeWebRoot + folder.TrimEnd(new char[] {'/'}) + "/"; // override for feed if (e.Location == ServingLocation.Feed) { path = Utils.AbsoluteWebRoot + folder.TrimEnd(new char[] { '/' }) + "/"; } // do replacement for media foreach (ShortCode sc in shortCodes) { string tagName = sc.TagName; string src = sc.GetAttributeValue("src", ""); string w = sc.GetAttributeValue("width", ""); string h = sc.GetAttributeValue("height", ""); string mp4 = sc.GetAttributeValue("mp4", ""); string mp3 = sc.GetAttributeValue("mp3", ""); string webm = sc.GetAttributeValue("webm", ""); string ogg = sc.GetAttributeValue("ogg", ""); string poster = sc.GetAttributeValue("poster", ""); string autoplay = sc.GetAttributeValue("autoplay", ""); string preload = sc.GetAttributeValue("preload", ""); string code = "<" + tagName + " class=\"mep\" controls=\"controls\"" + ((src != "") ? " src=\"" + ((src.IndexOf("http") == 0) ? "" : path) + src + "\"" : "") + ((poster != "") ? " poster=\"" + ((poster.IndexOf("http") == 0) ? "" : path) + poster + "\"" : "") + ((w != "") ? " width=\"" + w + "\"" : "") + ((h != "") ? " height=\"" + h + "\"" : "") + ((autoplay != "") ? " autoplay=\"autoplay\"" : "") + ((preload != "") ? " preload=\"" + preload + "\"" : "") + ">" + ((mp4 != "") ? "<source src=\"" + ((mp4.IndexOf("http") == 0) ? "" : path) + mp4 + "\" type=\"video/mp4\" />" : "") + ((mp3 != "") ? "<source src=\"" +((mp3.IndexOf("http") == 0) ? "" : path) + mp3 + "\" type=\"audio/mp3\" />" : "") + ((webm != "") ? "<source src=\"" + ((webm.IndexOf("http") == 0) ? "" : path) + webm + "\" type=\"video/webm\" />" : "") + ((ogg != "") ? "<source src=\"" + ((ogg.IndexOf("http") == 0) ? "" : path) + ogg + "\" type=\"video/ogg\" />" : "") + "</" + tagName + ">"; e.Body = e.Body.Replace(sc.Text, code); } }
/// <summary> /// The event handler that is triggered every time a comment is served to a client. /// </summary> private static void Post_CommentServing(object sender, ServingEventArgs e) { if (string.IsNullOrEmpty(e.Body)) { return; } CultureInfo info = CultureInfo.InvariantCulture; foreach (Match match in regex.Matches(e.Body)) { if (!match.Value.Contains("://")) { e.Body = e.Body.Replace(match.Value, string.Format(info, link, "http://", match.Value, ShortenUrl(match.Value, MAX_LENGTH))); } else { e.Body = e.Body.Replace(match.Value, string.Format(info, link, string.Empty, match.Value, ShortenUrl(match.Value, MAX_LENGTH))); } } }
static string GetPostPicture(ServingEventArgs e) { if (e.Body.IndexOf("<img ") <= 0) { return(pic); } var start = e.Body.IndexOf("<img"); var stop = e.Body.IndexOf("/>"); if (stop > 0 && stop > start) { var s = e.Body.Substring(start, stop - start + 2); e.Body = e.Body.Replace(s, ""); return(s.Replace("<img ", "<img class=\"first-post-img\" ")); } return(pic); }
/// <summary> /// The event handler that is triggered every time a comment is served to a client. /// </summary> private static void Post_CommentServing(object sender, ServingEventArgs e) { string body = e.Body; // retrieve parameters back as a data table // column = parameter DataTable table = _settings.GetDataTable(); foreach (DataRow row in table.Rows) { if (string.IsNullOrEmpty((string)row["CloseTag"])) { Parse(ref body, (string)row["Code"], (string)row["OpenTag"]); } else { Parse(ref body, (string)row["Code"], (string)row["OpenTag"], (string)row["CloseTag"]); } } e.Body = body; }
/// <summary> /// Handles the Serving event of the Post control. /// Handles the Post.Serving event to take care of the [more] keyword. /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="e">The <see cref="BlogEngine.Core.ServingEventArgs"/> instance containing the event data.</param> private static void PostServing(object sender, ServingEventArgs e) { if (!e.Body.Contains("[more]")) { return; } switch (e.Location) { case ServingLocation.PostList: AddMoreLink(sender, e); break; case ServingLocation.SinglePost: PrepareFullPost(e); break; case ServingLocation.Feed: e.Body = e.Body.Replace("[more]", string.Empty); break; } }
private static void AddSyntaxHighlighter(object sender, ServingEventArgs e) { if (e.Location == ServingLocation.Feed) { return; } HttpContext context = HttpContext.Current; Page page = (Page)context.CurrentHandler; if ((context.CurrentHandler is Page == false) || (context.Items[ExtensionName] != null)) { return; } AddCssStyles(page); AddJavaScripts(page); AddOptions(page); context.Items[ExtensionName] = 1; }
/// <summary> /// An event that handles ServingEventArgs /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void Post_Serving(object sender, ServingEventArgs e) { if (!string.IsNullOrEmpty(e.Body)) { // only process the posts if (e.Location == ServingLocation.PostList || e.Location == ServingLocation.SinglePost || e.Location == ServingLocation.SinglePage) { string regex = @"\[donate:.*]"; MatchCollection matches = Regex.Matches(e.Body, regex); if (matches.Count > 0) { foreach (Match match in matches) { string item_name = match.Value.Replace("[donate:", "").Replace("]", ""); string literal_donate = ""; literal_donate = GetDonateButton(item_name, double.Parse(settings.GetSingleValue("taxRate")), double.Parse(settings.GetSingleValue("shipping")), settings.GetSingleValue("username")); e.Body = e.Body.Replace(match.Value, literal_donate); } } } } }
/// <summary> /// Retrieves the title. /// </summary> /// <param name="context">The context.</param> /// <returns>The title string.</returns> private static string RetrieveTitle(HttpContext context) { var title = BlogSettings.Instance.Name; string subTitle = null; if (!string.IsNullOrEmpty(context.Request.QueryString["category"])) { if (context.Request.QueryString["category"].Length < 36) { StopServing(context); } var firstCat = context.Request.QueryString["category"].Substring(0, 36); var categoryId = new Guid(firstCat); var currentCategory = Category.GetCategory(categoryId, Blog.CurrentInstance.IsSiteAggregation); if (currentCategory == null) { StopServing(context); } if (currentCategory != null) { subTitle = currentCategory.Title; } } if (!string.IsNullOrEmpty(context.Request.QueryString["author"])) { subTitle = context.Request.QueryString["author"]; } if (!string.IsNullOrEmpty(context.Request.QueryString["post"])) { if (context.Request.QueryString["post"].Length != 36) { StopServing(context); } var post = Post.GetPost(new Guid(context.Request.QueryString["post"])); if (post == null) { StopServing(context); } if (post != null) { var arg = new ServingEventArgs(post.Content, ServingLocation.Feed); post.OnServing(arg); if (arg.Cancel) { StopServing(context); } else { subTitle = post.Title; } } } if (!string.IsNullOrEmpty(context.Request.QueryString["comments"])) { subTitle = "Comments"; } if (subTitle != null) { return string.Format("{0} - {1}", title, subTitle); } return title; }