diff options
Diffstat (limited to 'html.c')
| -rw-r--r-- | html.c | 134 |
1 files changed, 132 insertions, 2 deletions
| @@ -194,7 +194,10 @@ d_char *html_user_header(snac *snac, d_char *s, int local) | |||
| 194 | s1 = xs_fmt("<a href=\"%s/admin\" rel=\"nofollow\">%s</a></nav>\n", | 194 | s1 = xs_fmt("<a href=\"%s/admin\" rel=\"nofollow\">%s</a></nav>\n", |
| 195 | snac->actor, L("admin")); | 195 | snac->actor, L("admin")); |
| 196 | else | 196 | else |
| 197 | s1 = xs_fmt("<a href=\"%s\">%s</a></nav>\n", snac->actor, L("public")); | 197 | s1 = xs_fmt( |
| 198 | "<a href=\"%s\">%s</a> - <a href=\"%s/people\">%s</a></nav>\n", | ||
| 199 | snac->actor, L("public"), | ||
| 200 | snac->actor, L("people")); | ||
| 198 | 201 | ||
| 199 | s = xs_str_cat(s, s1); | 202 | s = xs_str_cat(s, s1); |
| 200 | } | 203 | } |
| @@ -817,6 +820,116 @@ d_char *html_timeline(snac *snac, char *list, int local) | |||
| 817 | } | 820 | } |
| 818 | 821 | ||
| 819 | 822 | ||
| 823 | d_char *html_people(snac *snac) | ||
| 824 | { | ||
| 825 | d_char *s = xs_str_new(NULL); | ||
| 826 | xs *wers = NULL; | ||
| 827 | xs *wing = NULL; | ||
| 828 | char *p, *v; | ||
| 829 | |||
| 830 | s = html_user_header(snac, s, 0); | ||
| 831 | |||
| 832 | s = xs_str_cat(s, "<h2>"); | ||
| 833 | s = xs_str_cat(s, L("People you follow")); | ||
| 834 | s = xs_str_cat(s, "</h2>\n"); | ||
| 835 | |||
| 836 | s = xs_str_cat(s, "<h2>"); | ||
| 837 | s = xs_str_cat(s, L("People that follows you")); | ||
| 838 | s = xs_str_cat(s, "</h2>\n"); | ||
| 839 | |||
| 840 | p = wers = follower_list(snac); | ||
| 841 | while (xs_list_iter(&p, &v)) { | ||
| 842 | char *actor_id = xs_dict_get(v, "actor"); | ||
| 843 | xs *md5 = xs_md5_hex(actor_id, strlen(actor_id)); | ||
| 844 | xs *actor; | ||
| 845 | |||
| 846 | if (valid_status(actor_get(snac, actor_id, &actor))) { | ||
| 847 | s = xs_str_cat(s, "<div class=\"snac-post\">\n"); | ||
| 848 | |||
| 849 | s = html_actor_icon(snac, s, actor, NULL, NULL, 0); | ||
| 850 | |||
| 851 | |||
| 852 | /* content (user bio) */ | ||
| 853 | char *c = xs_dict_get(actor, "summary"); | ||
| 854 | |||
| 855 | if (!xs_is_null(c)) { | ||
| 856 | s = xs_str_cat(s, "<div class=\"snac-content\">\n"); | ||
| 857 | |||
| 858 | xs *sc = sanitize(c); | ||
| 859 | |||
| 860 | if (xs_startswith(sc, "<p>")) | ||
| 861 | s = xs_str_cat(s, sc); | ||
| 862 | else { | ||
| 863 | xs *s1 = xs_fmt("<p>%s</p>", sc); | ||
| 864 | s = xs_str_cat(s, s1); | ||
| 865 | } | ||
| 866 | |||
| 867 | s = xs_str_cat(s, "</div>\n"); | ||
| 868 | } | ||
| 869 | |||
| 870 | |||
| 871 | /* buttons */ | ||
| 872 | s = xs_str_cat(s, "<div class=\"snac-controls\">\n"); | ||
| 873 | |||
| 874 | xs *s1 = xs_fmt( | ||
| 875 | "<form method=\"post\" action=\"%s/admin/action\">\n" | ||
| 876 | "<input type=\"hidden\" name=\"actor\" value=\"%s\">\n" | ||
| 877 | "<input type=\"button\" name=\"action\" " | ||
| 878 | "value=\"%s\" onclick=\"" | ||
| 879 | "x = document.getElementById('%s_reply'); " | ||
| 880 | "if (x.style.display == 'block') " | ||
| 881 | " x.style.display = 'none'; else " | ||
| 882 | " x.style.display = 'block';" | ||
| 883 | "\">\n", | ||
| 884 | |||
| 885 | snac->actor, actor_id, | ||
| 886 | L("DM"), | ||
| 887 | md5 | ||
| 888 | ); | ||
| 889 | s = xs_str_cat(s, s1); | ||
| 890 | |||
| 891 | s = html_button(s, "unfollow", L("Unfollow")); | ||
| 892 | |||
| 893 | if (is_muted(snac, actor_id)) | ||
| 894 | s = html_button(s, "unmute", L("Unmute")); | ||
| 895 | else | ||
| 896 | s = html_button(s, "mute", L("MUTE")); | ||
| 897 | |||
| 898 | s = xs_str_cat(s, "</form>\n"); | ||
| 899 | |||
| 900 | /* the post textarea */ | ||
| 901 | xs *s2 = xs_fmt( | ||
| 902 | "<p><div class=\"snac-note\" style=\"display: none\" id=\"%s_reply\">\n" | ||
| 903 | "<form method=\"post\" action=\"%s/admin/note\" " | ||
| 904 | "enctype=\"multipart/form-data\" id=\"%s_reply_form\">\n" | ||
| 905 | "<textarea class=\"snac-textarea\" name=\"content\" " | ||
| 906 | "rows=\"4\" wrap=\"virtual\" required=\"required\"></textarea>\n" | ||
| 907 | "<input type=\"hidden\" name=\"to\" value=\"%s\">\n" | ||
| 908 | "<p><input type=\"file\" name=\"attach\">\n" | ||
| 909 | "<p><input type=\"submit\" class=\"button\" value=\"%s\">\n" | ||
| 910 | "</form><p></div>\n", | ||
| 911 | |||
| 912 | md5, | ||
| 913 | snac->actor, md5, | ||
| 914 | actor_id, | ||
| 915 | L("Post") | ||
| 916 | ); | ||
| 917 | s = xs_str_cat(s, s2); | ||
| 918 | |||
| 919 | s = xs_str_cat(s, "</div>\n"); | ||
| 920 | |||
| 921 | s = xs_str_cat(s, "</div>\n"); | ||
| 922 | } | ||
| 923 | } | ||
| 924 | |||
| 925 | s = html_user_footer(snac, s); | ||
| 926 | |||
| 927 | s = xs_str_cat(s, "</body>\n</html>\n"); | ||
| 928 | |||
| 929 | return s; | ||
| 930 | } | ||
| 931 | |||
| 932 | |||
| 820 | int html_get_handler(d_char *req, char *q_path, char **body, int *b_size, char **ctype) | 933 | int html_get_handler(d_char *req, char *q_path, char **body, int *b_size, char **ctype) |
| 821 | { | 934 | { |
| 822 | int status = 404; | 935 | int status = 404; |
| @@ -889,6 +1002,18 @@ int html_get_handler(d_char *req, char *q_path, char **body, int *b_size, char * | |||
| 889 | } | 1002 | } |
| 890 | } | 1003 | } |
| 891 | else | 1004 | else |
| 1005 | if (strcmp(p_path, "people") == 0) { | ||
| 1006 | /* the list of people */ | ||
| 1007 | |||
| 1008 | if (!login(&snac, req)) | ||
| 1009 | status = 401; | ||
| 1010 | else { | ||
| 1011 | *body = html_people(&snac); | ||
| 1012 | *b_size = strlen(*body); | ||
| 1013 | status = 200; | ||
| 1014 | } | ||
| 1015 | } | ||
| 1016 | else | ||
| 892 | if (xs_startswith(p_path, "p/")) { | 1017 | if (xs_startswith(p_path, "p/")) { |
| 893 | /* a timeline with just one entry */ | 1018 | /* a timeline with just one entry */ |
| 894 | xs *id = xs_fmt("%s/%s", snac.actor, p_path); | 1019 | xs *id = xs_fmt("%s/%s", snac.actor, p_path); |
| @@ -980,6 +1105,7 @@ int html_post_handler(d_char *req, char *q_path, d_char *payload, int p_size, | |||
| 980 | char *in_reply_to = xs_dict_get(p_vars, "in_reply_to"); | 1105 | char *in_reply_to = xs_dict_get(p_vars, "in_reply_to"); |
| 981 | char *attach_url = xs_dict_get(p_vars, "attach_url"); | 1106 | char *attach_url = xs_dict_get(p_vars, "attach_url"); |
| 982 | char *attach_file = xs_dict_get(p_vars, "attach"); | 1107 | char *attach_file = xs_dict_get(p_vars, "attach"); |
| 1108 | char *to = xs_dict_get(p_vars, "to"); | ||
| 983 | xs *attach_list = xs_list_new(); | 1109 | xs *attach_list = xs_list_new(); |
| 984 | 1110 | ||
| 985 | /* is attach_url set? */ | 1111 | /* is attach_url set? */ |
| @@ -1010,7 +1136,7 @@ int html_post_handler(d_char *req, char *q_path, d_char *payload, int p_size, | |||
| 1010 | xs *c_msg = NULL; | 1136 | xs *c_msg = NULL; |
| 1011 | xs *content_2 = xs_replace(content, "\r", ""); | 1137 | xs *content_2 = xs_replace(content, "\r", ""); |
| 1012 | 1138 | ||
| 1013 | msg = msg_note(&snac, content_2, NULL, in_reply_to, attach_list); | 1139 | msg = msg_note(&snac, content_2, to, in_reply_to, attach_list); |
| 1014 | 1140 | ||
| 1015 | c_msg = msg_create(&snac, msg); | 1141 | c_msg = msg_create(&snac, msg); |
| 1016 | 1142 | ||
| @@ -1051,6 +1177,10 @@ int html_post_handler(d_char *req, char *q_path, d_char *payload, int p_size, | |||
| 1051 | mute(&snac, actor); | 1177 | mute(&snac, actor); |
| 1052 | } | 1178 | } |
| 1053 | else | 1179 | else |
| 1180 | if (strcmp(action, L("Unmute")) == 0) { | ||
| 1181 | unmute(&snac, actor); | ||
| 1182 | } | ||
| 1183 | else | ||
| 1054 | if (strcmp(action, L("Follow")) == 0) { | 1184 | if (strcmp(action, L("Follow")) == 0) { |
| 1055 | xs *msg = msg_follow(&snac, actor); | 1185 | xs *msg = msg_follow(&snac, actor); |
| 1056 | 1186 | ||