diff options
Diffstat (limited to 'html.c')
| -rw-r--r-- | html.c | 97 |
1 files changed, 0 insertions, 97 deletions
| @@ -5020,100 +5020,3 @@ int html_post_handler(const xs_dict *req, const char *q_path, | |||
| 5020 | 5020 | ||
| 5021 | return status; | 5021 | return status; |
| 5022 | } | 5022 | } |
| 5023 | |||
| 5024 | |||
| 5025 | xs_str *rss_from_timeline(snac *user, const xs_list *timeline, | ||
| 5026 | const char *title, const char *link, const char *desc) | ||
| 5027 | /* converts a timeline to rss */ | ||
| 5028 | { | ||
| 5029 | xs_html *rss = xs_html_tag("rss", | ||
| 5030 | xs_html_attr("xmlns:content", "http:/" "/purl.org/rss/1.0/modules/content/"), | ||
| 5031 | xs_html_attr("version", "2.0"), | ||
| 5032 | xs_html_attr("xmlns:atom", "http:/" "/www.w3.org/2005/Atom")); | ||
| 5033 | |||
| 5034 | xs_html *channel = xs_html_tag("channel", | ||
| 5035 | xs_html_tag("title", | ||
| 5036 | xs_html_text(title)), | ||
| 5037 | xs_html_tag("language", | ||
| 5038 | xs_html_text("en")), | ||
| 5039 | xs_html_tag("link", | ||
| 5040 | xs_html_text(link)), | ||
| 5041 | xs_html_sctag("atom:link", | ||
| 5042 | xs_html_attr("href", link), | ||
| 5043 | xs_html_attr("rel", "self"), | ||
| 5044 | xs_html_attr("type", "application/rss+xml")), | ||
| 5045 | xs_html_tag("generator", | ||
| 5046 | xs_html_text(USER_AGENT)), | ||
| 5047 | xs_html_tag("description", | ||
| 5048 | xs_html_text(desc))); | ||
| 5049 | |||
| 5050 | xs_html_add(rss, channel); | ||
| 5051 | |||
| 5052 | int cnt = 0; | ||
| 5053 | const char *v; | ||
| 5054 | |||
| 5055 | xs_list_foreach(timeline, v) { | ||
| 5056 | xs *msg = NULL; | ||
| 5057 | |||
| 5058 | if (user) { | ||
| 5059 | if (!valid_status(timeline_get_by_md5(user, v, &msg))) | ||
| 5060 | continue; | ||
| 5061 | } | ||
| 5062 | else { | ||
| 5063 | if (!valid_status(object_get_by_md5(v, &msg))) | ||
| 5064 | continue; | ||
| 5065 | } | ||
| 5066 | |||
| 5067 | const char *id = xs_dict_get(msg, "id"); | ||
| 5068 | const char *content = xs_dict_get(msg, "content"); | ||
| 5069 | const char *published = xs_dict_get(msg, "published"); | ||
| 5070 | |||
| 5071 | if (user && !xs_startswith(id, user->actor)) | ||
| 5072 | continue; | ||
| 5073 | |||
| 5074 | if (!id || !content || !published) | ||
| 5075 | continue; | ||
| 5076 | |||
| 5077 | /* create a title with the first line of the content */ | ||
| 5078 | xs *title = xs_replace(content, "<br>", "\n"); | ||
| 5079 | title = xs_regex_replace_i(title, "<[^>]+>", " "); | ||
| 5080 | title = xs_regex_replace_i(title, "&[^;]+;", " "); | ||
| 5081 | int i; | ||
| 5082 | |||
| 5083 | for (i = 0; title[i] && title[i] != '\n' && i < 50; i++); | ||
| 5084 | |||
| 5085 | if (title[i] != '\0') { | ||
| 5086 | title[i] = '\0'; | ||
| 5087 | title = xs_str_cat(title, "..."); | ||
| 5088 | } | ||
| 5089 | |||
| 5090 | title = xs_strip_i(title); | ||
| 5091 | |||
| 5092 | /* convert the date */ | ||
| 5093 | time_t t = xs_parse_iso_date(published, 0); | ||
| 5094 | xs *rss_date = xs_str_utctime(t, "%a, %d %b %Y %T +0000"); | ||
| 5095 | |||
| 5096 | /* if it's the first one, add it to the header */ | ||
| 5097 | if (cnt == 0) | ||
| 5098 | xs_html_add(channel, | ||
| 5099 | xs_html_tag("lastBuildDate", | ||
| 5100 | xs_html_text(rss_date))); | ||
| 5101 | |||
| 5102 | xs_html_add(channel, | ||
| 5103 | xs_html_tag("item", | ||
| 5104 | xs_html_tag("title", | ||
| 5105 | xs_html_text(title)), | ||
| 5106 | xs_html_tag("link", | ||
| 5107 | xs_html_text(id)), | ||
| 5108 | xs_html_tag("guid", | ||
| 5109 | xs_html_text(id)), | ||
| 5110 | xs_html_tag("pubDate", | ||
| 5111 | xs_html_text(rss_date)), | ||
| 5112 | xs_html_tag("description", | ||
| 5113 | xs_html_text(content)))); | ||
| 5114 | |||
| 5115 | cnt++; | ||
| 5116 | } | ||
| 5117 | |||
| 5118 | return xs_html_render_s(rss, "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"); | ||
| 5119 | } | ||