Exemple #1
0
 /// <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 href=\"" + post.RelativeLink + "#continue\">More...</a>";
     e.Body = e.Body.Substring(0, index) + link;
 }
Exemple #2
0
 /// <summary>
 /// Replaces the [more] string on the full post page.
 /// </summary>
 private static void PrepareFullPost(ServingEventArgs e)
 {
     HttpRequest request = HttpContext.Current.Request;
     if (request.UrlReferrer == null || request.UrlReferrer.Host != request.Url.Host)
     {
       e.Body = e.Body.Replace("[more]", string.Empty);
     }
     else
     {
       e.Body = e.Body.Replace("[more]", "<span id=\"continue\"></span>");
     }
 }
Exemple #3
0
    /// <summary>
    /// Handles the Post.Serving event to take care of the [more] keyword.
    /// </summary>
    private 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);
        }
    }
Exemple #4
0
 /// <summary>
 /// The event handler that is triggered every time a comment is served to a client.
 /// </summary>
 private void Post_CommentServing(object sender, ServingEventArgs e)
 {
     if (!string.IsNullOrEmpty(e.Body))
     {
       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"));
     }
 }
Exemple #5
0
    /// <summary>
    /// The event handler that is triggered every time a comment is served to a client.
    /// </summary>
    private 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)));
            }
        }
    }
 /// <summary>
 /// An event that handles ServingEventArgs
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 void ServingContent(object sender, ServingEventArgs e)
 {
     if (e.Body.Contains("[/code]"))
       {
     e.Body = codeRegex.Replace(e.Body, new MatchEvaluator(CodeEvaluator));
     e.Body = codeBeginTagRegex.Replace(e.Body, @"<div class=""code"">");
     e.Body = codeEndTagRegex.Replace(e.Body, @"</div>");
       }
 }
        /// <summary>
        /// Writes the RSS channel item element information to the specified <see cref="XmlWriter"/> using the supplied <see cref="Page"/>.
        /// </summary>
        /// <param name="writer">The <see cref="XmlWriter"/> to write channel item element information to.</param>
        /// <param name="publishable">The <see cref="IShowed"/> used to generate channel item content.</param>
        private static void WriteRssItem(XmlWriter writer, IShowed publishable)
        {
            //------------------------------------------------------------
                //	Cast IShowed as Post to support comments/trackback
                //------------------------------------------------------------
                Post post = publishable as Post;
                Comment comment = publishable as Comment;

                //------------------------------------------------------------
                //	Raise serving event
                //------------------------------------------------------------
                ServingEventArgs arg = new ServingEventArgs(publishable.Content, ServingLocation.Feed);
                publishable.OnServing(arg);
                if (arg.Cancel)
                {
                    return;
                }

                //------------------------------------------------------------
                //	Modify post content to make references absolute
                //------------------------------------------------------------
                string content = ConvertPathsToAbsolute(arg.Body);

                writer.WriteStartElement("item");
                //------------------------------------------------------------
                //	Write required channel item elements
                //------------------------------------------------------------
                writer.WriteElementString("title", publishable.Title);
                writer.WriteElementString("description", content);
                writer.WriteElementString("link", SupportUtilities.ConvertToAbsolute(publishable.RelativeLink).ToString());

                //------------------------------------------------------------
                //	Write optional channel item elements
                //------------------------------------------------------------
                writer.WriteElementString("author", publishable.Author);
                if (post != null)
                {
                    writer.WriteElementString("comments", String.Concat(SupportUtilities.ConvertToAbsolute(publishable.RelativeLink).ToString(), "#comment"));
                }
                writer.WriteElementString("guid", SyndicationGenerator.GetPermaLink(publishable).ToString());
                writer.WriteElementString("pubDate", SyndicationGenerator.ToRfc822DateTime(publishable.DateCreated));

                //------------------------------------------------------------
                //	Write channel item category elements
                //------------------------------------------------------------
                if (publishable.Categories != null)
                {
                    foreach (Category category in publishable.Categories)
                    {
                        writer.WriteElementString("category", category.Title);
                    }
                }

                //------------------------------------------------------------
                //	Write Dublin Core syndication extension elements
                //------------------------------------------------------------
                if (!String.IsNullOrEmpty(publishable.Author))
                {
                    writer.WriteElementString("dc", "publisher", "http://purl.org/dc/elements/1.1/", publishable.Author);
                }

                //------------------------------------------------------------
                //	Write pingback syndication extension elements
                //------------------------------------------------------------
                Uri pingbackServer;
                if (Uri.TryCreate(String.Concat(SupportUtilities.AbsoluteWebRoot.ToString().TrimEnd('/'), "/ZaszBlogHttpHandlers/PingBack.ashx"), UriKind.RelativeOrAbsolute, out pingbackServer))
                {
                    writer.WriteElementString("pingback", "server", "http://madskills.com/public/xml/rss/module/pingback/", pingbackServer.ToString());
                    writer.WriteElementString("pingback", "target", "http://madskills.com/public/xml/rss/module/pingback/", SyndicationGenerator.GetPermaLink(publishable).ToString());
                }

                //------------------------------------------------------------
                //	Write slash syndication extension elements
                //------------------------------------------------------------
                if (post != null && post.Comments != null)
                {
                    writer.WriteElementString("slash", "comments", "http://purl.org/rss/1.0/modules/slash/", post.Comments.Count.ToString());
                }

                //------------------------------------------------------------
                //	Write trackback syndication extension elements
                //------------------------------------------------------------
                if (post != null && post.TrackbackLink != null)
                {
                    writer.WriteElementString("trackback", "ping", "http://madskills.com/public/xml/rss/module/trackback/", post.TrackbackLink.ToString());
                }

                //------------------------------------------------------------
                //	Write well-formed web syndication extension elements
                //------------------------------------------------------------
                writer.WriteElementString("wfw", "comment", "http://wellformedweb.org/CommentAPI/", String.Concat(SupportUtilities.ConvertToAbsolute(publishable.RelativeLink).ToString(), "#comment"));
                writer.WriteElementString("wfw", "commentRss", "http://wellformedweb.org/CommentAPI/", SupportUtilities.AbsoluteWebRoot.ToString().TrimEnd('/') + "/ZaszBlogHttpHandlers/Syndication.ashx?post=" + publishable.Id.ToString());

                //------------------------------------------------------------
                //	Write </item> element
                //------------------------------------------------------------
                writer.WriteEndElement();
        }
        /// <summary>
        /// Writes the Atom feed entry element information to the specified <see cref="XmlWriter"/> using the supplied <see cref="Page"/>.
        /// </summary>
        /// <param name="writer">The <see cref="XmlWriter"/> to write feed entry element information to.</param>
        /// <param name="publishable">The <see cref="IShowed"/> used to generate feed entry content.</param>
        private static void WriteAtomEntry(XmlWriter writer, IShowed publishable)
        {
            Post post = publishable as Post;
                Comment comment = publishable as Comment;

                //------------------------------------------------------------
                //	Raise serving event
                //------------------------------------------------------------
                ServingEventArgs arg = new ServingEventArgs(publishable.Content, ServingLocation.Feed);
                publishable.OnServing(arg);
                if (arg.Cancel)
                {
                    return;
                }

                //------------------------------------------------------------
                //	Modify publishable content to make references absolute
                //------------------------------------------------------------
                string content = ConvertPathsToAbsolute(arg.Body);

                writer.WriteStartElement("entry");
                //------------------------------------------------------------
                //	Write required entry elements
                //------------------------------------------------------------
                writer.WriteElementString("id", SupportUtilities.ConvertToAbsolute(publishable.RelativeLink).ToString());
                writer.WriteElementString("title", publishable.Title);
                writer.WriteElementString("updated", SyndicationGenerator.ToW3CDateTime(publishable.DateCreated.ToUniversalTime()));

                //------------------------------------------------------------
                //	Write recommended entry elements
                //------------------------------------------------------------
                writer.WriteStartElement("link");
                writer.WriteAttributeString("rel", "self");
                writer.WriteAttributeString("href", SyndicationGenerator.GetPermaLink(publishable).ToString());
                writer.WriteEndElement();

                writer.WriteStartElement("link");
                writer.WriteAttributeString("href", SupportUtilities.ConvertToAbsolute(publishable.RelativeLink).ToString());
                writer.WriteEndElement();

                writer.WriteStartElement("author");
                writer.WriteElementString("name", publishable.Author);
                writer.WriteEndElement();

                writer.WriteStartElement("summary");
                writer.WriteAttributeString("type", "html");
                writer.WriteString(content);
                writer.WriteEndElement();

                //------------------------------------------------------------
                //	Write optional entry elements
                //------------------------------------------------------------
                writer.WriteElementString("published", SyndicationGenerator.ToW3CDateTime(publishable.DateCreated.ToUniversalTime()));

                writer.WriteStartElement("link");
                writer.WriteAttributeString("rel", "related");
                writer.WriteAttributeString("href", String.Concat(SupportUtilities.ConvertToAbsolute(publishable.RelativeLink).ToString(), "#comment"));
                writer.WriteEndElement();

                //------------------------------------------------------------
                //	Write entry category elements
                //------------------------------------------------------------
                if (publishable.Categories != null)
                {
                    foreach (Category category in publishable.Categories)
                    {
                        writer.WriteStartElement("category");
                        writer.WriteAttributeString("term", category.Title);
                        writer.WriteEndElement();
                    }
                }

                //------------------------------------------------------------
                //	Write pingback syndication extension elements
                //------------------------------------------------------------
                Uri pingbackServer;
                if (Uri.TryCreate(String.Concat(SupportUtilities.AbsoluteWebRoot.ToString().TrimEnd('/'), "ZaszBlogHttpHandlers/Pingback.ashx"), UriKind.RelativeOrAbsolute, out pingbackServer))
                {
                    writer.WriteElementString("pingback", "server", "http://madskills.com/public/xml/rss/module/pingback/", pingbackServer.ToString());
                    writer.WriteElementString("pingback", "target", "http://madskills.com/public/xml/rss/module/pingback/", SyndicationGenerator.GetPermaLink(publishable).ToString());
                }

                //------------------------------------------------------------
                //	Write slash syndication extension elements
                //------------------------------------------------------------
                if (post != null && post.Comments != null)
                {
                    writer.WriteElementString("slash", "comments", "http://purl.org/rss/1.0/modules/slash/", post.Comments.Count.ToString());
                }

                //------------------------------------------------------------
                //	Write trackback syndication extension elements
                //------------------------------------------------------------
                if (post != null && post.TrackbackLink != null)
                {
                    writer.WriteElementString("trackback", "ping", "http://madskills.com/public/xml/rss/module/trackback/", post.TrackbackLink.ToString());
                }

                //------------------------------------------------------------
                //	Write well-formed web syndication extension elements
                //------------------------------------------------------------
                writer.WriteElementString("wfw", "comment", "http://wellformedweb.org/CommentAPI/", String.Concat(SupportUtilities.ConvertToAbsolute(publishable.RelativeLink).ToString(), "#comment"));
                writer.WriteElementString("wfw", "commentRss", "http://wellformedweb.org/CommentAPI/", SupportUtilities.AbsoluteWebRoot.ToString().TrimEnd('/') + "ZaszBlogHttpHandlers/Syndication.ashx?post=" + publishable.Id.ToString());

                //------------------------------------------------------------
                //	Write </entry> element
                //------------------------------------------------------------
                writer.WriteEndElement();
        }
Exemple #9
0
    /// <summary>
    /// Serves the page by realizing the usercontrols and using the divText DIV tag.
    /// </summary>
    /// <param name="id">The GUID of the Page to be rendered.</param>
    private void ServePage(Guid id)
    {
        this.CRPage = Thon.ZaszBlog.Support.CodedRepresentations.Page.GetPage(id);

        if (this.CRPage == null || (!this.CRPage.IsVisible && !this.User.Identity.IsAuthenticated))
            Response.Redirect(SupportUtilities.RelativeWebRoot + "Error404.aspx", true);

        // Set title
        h1Title.InnerHtml = this.CRPage.Title;

        ServingEventArgs arg = new ServingEventArgs(this.CRPage.Content, ServingLocation.SinglePage);
        Thon.ZaszBlog.Support.CodedRepresentations.Page.OnServing(this.CRPage, arg);

        if (arg.Cancel)
            Response.Redirect(SupportUtilities.RelativeWebRoot + "Error404.aspx", true);

        if (arg.Body.ToLowerInvariant().Contains("[usercontrol"))
        {
            InjectUserControls(arg.Body);
        }
        else
        {
            divText.InnerHtml = arg.Body;
        }
    }
Exemple #10
0
    /// <summary>
    /// The event handler that is triggered every time a comment is served to a client.
    /// </summary>
    private 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;
    }