Esempio n. 1
0
        /// <summary>
        /// Iterate over "LinkedPost" links and insert an anchors to local
        /// resources right after the normal http links withing the post body.
        /// </summary>
        private static void  ProcessBody(BodyWriter decor, string body, IResource rssItem)
        {
            IResourceList linked = rssItem.GetLinksFrom(Props.RSSItemResource, Props.LinkedPost);

            foreach (IResource res in linked)
            {
                string link = res.GetStringProp(Props.Link);
                if (!string.IsNullOrEmpty(link))
                {
                    string template  = "href=\"" + link + "\"";
                    int    indexHref = body.IndexOf(template);
                    if (indexHref != -1)
                    {
                        int indexClose    = body.IndexOf("</a>", indexHref + template.Length);
                        int indexImmClose = body.IndexOf("/>", indexHref + template.Length);
                        int indexAnyHref  = body.IndexOf("href=", indexHref + template.Length);

                        //  We do not expect any extra "href" link nor immediate close tag
                        //  inside current "<a href" and its closing "</a>" tag.
                        if (indexClose != -1 && (indexAnyHref == -1 || indexAnyHref > indexClose) &&
                            (indexImmClose == -1 || indexImmClose >= indexClose))
                        {
                            InsertLocalLink(ref body, res, indexClose);
                        }
                    }
                }
            }
            decor.AppendText(body);
            decor.AppendText("<p><hr/>");
        }
Esempio n. 2
0
 public static void AppendSourceTag(IResource item, BodyWriter decor)
 {
     if (item.HasProp(Props.RSSSourceTag))
     {
         decor.AppendText("<p class=\"Origin\"><a href=\"");
         string sourceUrl = HttpUtility.HtmlEncode(item.GetStringProp(Props.RSSSourceTagUrl));
         decor.AppendText(sourceUrl);
         decor.AppendText("\">Source: ");
         decor.AppendText(item.GetPropText(Props.RSSSourceTag));
         decor.AppendText("</a></p>");
     }
 }
Esempio n. 3
0
        public static void ConstructSummary(IResource rssItem, string summaryStyle,
                                            string content, BodyWriter decor)
        {
            string summary     = rssItem.GetPropText(Props.Summary);
            bool   showSummary = (summary.Length > 0) && (summary.Length != content.Length);

            if (showSummary)
            {
                decor.AppendText("<style type=\"text/css\">" + summaryStyle + "</style>");
                decor.AppendText("<div class=\"summary\">");
                decor.AppendText(summary);
                decor.AppendText("</div>");
            }
        }
Esempio n. 4
0
        public static void AppendRelatedPosts(IResource item, BodyWriter decor, bool verbose)
        {
            IResourceList relatedPosts = item.GetLinksOfType(Props.RSSLinkedPostResource, Props.LinkedPost);

            if (relatedPosts.Count > 0)
            {
                decor.AppendText("<div class=\"related\"><p>Related readings:</p><ul>");
                foreach (IResource res in relatedPosts)
                {
                    decor.AppendText("<li>");
                    AppendLinkText(res, decor, verbose);
                    decor.AppendText("</li>");
                }
                decor.AppendText("</ul></div>");
            }
        }
Esempio n. 5
0
        private static void  AppendLinkText(IResource res, BodyWriter decor, bool verbose)
        {
            string url  = res.GetPropText(Props.URL);
            string text = res.GetPropText(Core.Props.Name);

            decor.AppendText("<a href=\"");
            decor.AppendText(url);
            decor.AppendText("\" title=\"");
            decor.AppendText(verbose ? text : url);
            decor.AppendText("\">");
            decor.AppendText(verbose ? url : text);
            decor.AppendText("</a>");
        }
Esempio n. 6
0
 public static void AppendEnclosure(IResource item, BodyWriter decor)
 {
     if (item.HasProp(Props.EnclosureURL))
     {
         decor.AppendText("<p>Enclosure: <a href=\"");
         string enclosureUrl = HttpUtility.HtmlEncode(item.GetStringProp(Props.EnclosureURL));
         decor.AppendText(enclosureUrl);
         decor.AppendText("\">");
         decor.AppendText(enclosureUrl);
         if (item.HasProp(Props.EnclosureSize))
         {
             decor.AppendText(" (");
             decor.AppendText(Utils.SizeToString(item.GetIntProp(Props.EnclosureSize)));
             decor.AppendText(")");
         }
         decor.AppendText("</a></p>");
     }
 }
Esempio n. 7
0
        public static void AppendLink(IResource item, BodyWriter decor, string alias)
        {
            if (item.HasProp(Props.Link))
            {
                bool   visibleAlias = !string.IsNullOrEmpty(alias);
                string link         = HttpUtility.HtmlEncode(item.GetStringProp(Props.Link));

                decor.AppendText("<a href=\"");
                decor.AppendText(link);
                decor.AppendText("\"");

                if (visibleAlias)
                {
                    decor.AppendText(" title=\"");
                    decor.AppendText(link);
                    decor.AppendText("\"");
                }
                decor.AppendText(">");
                decor.AppendText(visibleAlias ? HttpUtility.HtmlEncode(alias) : link);
                decor.AppendText("</a>");
            }
        }
Esempio n. 8
0
 public static void AppendCommentsTag(IResource item, BodyWriter decor)
 {
     if (item.HasProp(Props.CommentURL))
     {
         decor.AppendText("<p><a href=\"");
         decor.AppendText(item.GetStringProp(Props.CommentURL));
         decor.AppendText("\">Comments");
         if (item.HasProp(Props.CommentCount))
         {
             decor.AppendText(" (");
             decor.AppendText(item.GetProp(Props.CommentCount).ToString());
             decor.AppendText(")");
         }
         decor.AppendText("</a>");
     }
 }