summaryrefslogtreecommitdiff
path: root/html.c
diff options
context:
space:
mode:
authorGravatar default2023-11-26 20:14:47 +0100
committerGravatar default2023-11-26 20:14:47 +0100
commit3f9408027850481fbcfc9dbd738d12d75503bb0f (patch)
tree79a779b2cd68494d3dbef76bd70c35c16e0ec96a /html.c
parentUse html_note() in html_top_controls(). (diff)
downloadsnac2-3f9408027850481fbcfc9dbd738d12d75503bb0f.tar.gz
snac2-3f9408027850481fbcfc9dbd738d12d75503bb0f.tar.xz
snac2-3f9408027850481fbcfc9dbd738d12d75503bb0f.zip
The user settings form has been converted to xs_html.
Diffstat (limited to 'html.c')
-rw-r--r--html.c324
1 files changed, 183 insertions, 141 deletions
diff --git a/html.c b/html.c
index c314da8..caf06df 100644
--- a/html.c
+++ b/html.c
@@ -712,62 +712,64 @@ xs_str *html_user_header(snac *snac, xs_str *s, int local)
712xs_str *html_top_controls(snac *snac, xs_str *s) 712xs_str *html_top_controls(snac *snac, xs_str *s)
713/* generates the top controls */ 713/* generates the top controls */
714{ 714{
715 char *_tmpl3 = 715 xs_str_cat(s, "<div class=\"snac-top-controls\">\n");
716 "<details><summary>%s</summary>\n"
717
718 "<div class=\"snac-user-setup\">\n" /** user setup **/
719 "<form autocomplete=\"off\" method=\"post\" "
720 "action=\"%s/admin/user-setup\" enctype=\"multipart/form-data\">\n"
721 "<p>%s:<br>\n"
722 "<input type=\"text\" name=\"name\" value=\"%s\" placeholder=\"Your name.\"></p>\n"
723
724 "<p>%s: <input type=\"file\" name=\"avatar_file\"></p>\n"
725
726 "<p>%s: <input type=\"file\" name=\"header_file\"></p>\n"
727
728 "<p>%s:<br>\n"
729 "<textarea name=\"bio\" cols=\"40\" rows=\"4\" placeholder=\"Write about yourself here...\">%s</textarea></p>\n"
730
731 "<p><input type=\"checkbox\" name=\"cw\" id=\"cw\" %s>\n"
732 "<label for=\"cw\">%s</label></p>\n"
733
734 "<p>%s:<br>\n"
735 "<input type=\"text\" name=\"email\" value=\"%s\" placeholder=\"bob@example.com\"></p>\n"
736
737 "<p>%s:<br>\n"
738 "<input type=\"text\" name=\"telegram_bot\" placeholder=\"Bot API key\" value=\"%s\"> "
739 "<input type=\"text\" name=\"telegram_chat_id\" placeholder=\"Chat id\" value=\"%s\"></p>\n"
740
741 "<p>%s:<br>\n"
742 "<input type=\"number\" name=\"purge_days\" value=\"%s\"></p>\n"
743
744 "<p><input type=\"checkbox\" name=\"drop_dm_from_unknown\" id=\"drop_dm_from_unknown\" %s>\n"
745 "<label for=\"drop_dm_from_unknown\">%s</label></p>\n"
746
747 "<p><input type=\"checkbox\" name=\"bot\" id=\"bot\" %s>\n"
748 "<label for=\"bot\">%s</label></p>\n"
749 716
750 "<p><input type=\"checkbox\" name=\"private\" id=\"private\" %s>\n" 717 xs_html *new_note = html_note(snac, L("New Post..."),
751 "<label for=\"private\">%s</label></p>\n" 718 "new_post_div", "new_post_form",
719 L("What's on your mind?"), "",
720 NULL, NULL,
721 xs_stock_false, "",
722 xs_stock_false, NULL,
723 NULL, 1);
752 724
753 "<p>%s:<br>\n" 725 xs *s1 = xs_html_render(new_note);
754 "<textarea name=\"metadata\" cols=\"40\" rows=\"4\" "
755 "placeholder=\"Blog=https:/" "/example.com/my-blog\nGPG Key=1FA54\n...\">"
756 "%s</textarea></p>\n"
757 726
758 "<p>%s:<br>\n" 727 xs *s2 = NULL;
759 "<input type=\"password\" name=\"passwd1\" value=\"\"></p>\n"
760 728
761 "<p>%s:<br>\n" 729 /** operations form **/
762 "<input type=\"password\" name=\"passwd2\" value=\"\"></p>\n" 730 {
731 xs *ops_action = xs_fmt("%s/admin/action", snac->actor);
732 xs_html *ops = xs_html_tag("details",
733 xs_html_tag("summary",
734 xs_html_text(L("Operations..."))),
735 xs_html_tag("p", NULL),
736 xs_html_tag("form",
737 xs_html_attr("autocomplete", "off"),
738 xs_html_attr("method", "post"),
739 xs_html_attr("action", ops_action),
740 xs_html_sctag("input",
741 xs_html_attr("type", "text"),
742 xs_html_attr("name", "actor"),
743 xs_html_attr("required", "required"),
744 xs_html_attr("placeholder", "bob@example.com")),
745 xs_html_sctag("input",
746 xs_html_attr("type", "submit"),
747 xs_html_attr("name", "action"),
748 xs_html_attr("value", L("Follow"))),
749 xs_html_text(L("(by URL or user@host)"))),
750 xs_html_tag("p", NULL),
751 xs_html_tag("form",
752 xs_html_attr("autocomplete", "off"),
753 xs_html_attr("method", "post"),
754 xs_html_attr("action", ops_action),
755 xs_html_sctag("input",
756 xs_html_attr("type", "text"),
757 xs_html_attr("name", "id"),
758 xs_html_attr("required", "required"),
759 xs_html_attr("placeholder", "https:/" "/fedi.example.com/bob/...")),
760 xs_html_sctag("input",
761 xs_html_attr("type", "submit"),
762 xs_html_attr("name", "action"),
763 xs_html_attr("value", L("Boost"))),
764 xs_html_text(L("(by URL)"))),
765 xs_html_tag("p", NULL));
763 766
764 "<input type=\"submit\" class=\"button\" value=\"%s\">\n" 767 s2 = xs_html_render(ops);
765 "</form>\n" 768 }
766 769
767 "</div>\n" 770 /** user settings form **/
768 "</details>\n";
769 771
770 const char *email = "[disabled by admin]"; 772 char *email = "[disabled by admin]";
771 773
772 if (xs_type(xs_dict_get(srv_config, "disable_email_notifications")) != XSTYPE_TRUE) { 774 if (xs_type(xs_dict_get(srv_config, "disable_email_notifications")) != XSTYPE_TRUE) {
773 email = xs_dict_get(snac->config_o, "email"); 775 email = xs_dict_get(snac->config_o, "email");
@@ -791,23 +793,15 @@ xs_str *html_top_controls(snac *snac, xs_str *s)
791 if (xs_is_null(telegram_chat_id)) 793 if (xs_is_null(telegram_chat_id))
792 telegram_chat_id = ""; 794 telegram_chat_id = "";
793 795
794 const char *purge_days = xs_dict_get(snac->config, "purge_days"); 796 char *purge_days = xs_dict_get(snac->config, "purge_days");
795 if (!xs_is_null(purge_days) && xs_type(purge_days) == XSTYPE_NUMBER) 797 if (!xs_is_null(purge_days) && xs_type(purge_days) == XSTYPE_NUMBER)
796 purge_days = xs_number_str(purge_days); 798 purge_days = (char *)xs_number_str(purge_days);
797 else 799 else
798 purge_days = "0"; 800 purge_days = "0";
799 801
800 const char *d_dm_f_u = xs_dict_get(snac->config, "drop_dm_from_unknown"); 802 xs_val *d_dm_f_u = xs_dict_get(snac->config, "drop_dm_from_unknown");
801 803 xs_val *bot = xs_dict_get(snac->config, "bot");
802 const char *bot = xs_dict_get(snac->config, "bot"); 804 xs_val *a_private = xs_dict_get(snac->config, "private");
803 const char *a_private = xs_dict_get(snac->config, "private");
804
805 xs *es1 = encode_html(xs_dict_get(snac->config, "name"));
806 xs *es2 = encode_html(xs_dict_get(snac->config, "bio"));
807 xs *es3 = encode_html(email);
808 xs *es4 = encode_html(telegram_bot);
809 xs *es5 = encode_html(telegram_chat_id);
810 xs *es6 = encode_html(purge_days);
811 805
812 xs *metadata = xs_str_new(NULL); 806 xs *metadata = xs_str_new(NULL);
813 xs_dict *md = xs_dict_get(snac->config, "metadata"); 807 xs_dict *md = xs_dict_get(snac->config, "metadata");
@@ -822,91 +816,139 @@ xs_str *html_top_controls(snac *snac, xs_str *s)
822 metadata = xs_str_cat(metadata, kp); 816 metadata = xs_str_cat(metadata, kp);
823 } 817 }
824 818
825 xs_str_cat(s, "<div class=\"snac-top-controls\">\n"); 819 xs *user_setup_action = xs_fmt("%s/admin/user-setup", snac->actor);
826 820
827 xs_html *new_note = html_note(snac, L("New Post..."), 821 xs_html *user_settings = xs_html_tag("details",
828 "new_post_div", "new_post_form", 822 xs_html_tag("summary",
829 L("What's on your mind?"), "", 823 xs_html_text(L("User Settings..."))),
830 NULL, NULL, 824 xs_html_tag("div",
831 xs_stock_false, "", 825 xs_html_attr("class", "snac-user-setup"),
832 xs_stock_false, NULL,
833 NULL, 1);
834
835 xs *s1 = xs_html_render(new_note);
836
837 xs *s2 = NULL;
838
839 {
840 xs *ops_action = xs_fmt("%s/admin/action", snac->actor);
841 xs_html *ops = xs_html_tag("details",
842 xs_html_tag("summary",
843 xs_html_text(L("Operations..."))),
844 xs_html_tag("form",
845 xs_html_attr("autocomplete", "off"),
846 xs_html_attr("method", "post"),
847 xs_html_attr("action", ops_action),
848 xs_html_sctag("input",
849 xs_html_attr("type", "text"),
850 xs_html_attr("name", "actor"),
851 xs_html_attr("required", "required"),
852 xs_html_attr("placeholder", "bob@example.com")),
853 xs_html_sctag("input",
854 xs_html_attr("type", "submit"),
855 xs_html_attr("name", "action"),
856 xs_html_attr("value", L("Follow"))),
857 xs_html_text(L("(by URL or user@host)"))),
858 xs_html_tag("p", NULL),
859 xs_html_tag("form", 826 xs_html_tag("form",
860 xs_html_attr("autocomplete", "off"), 827 xs_html_attr("autocomplete", "off"),
861 xs_html_attr("method", "post"), 828 xs_html_attr("method", "post"),
862 xs_html_attr("action", ops_action), 829 xs_html_attr("action", user_setup_action),
863 xs_html_sctag("input", 830 xs_html_attr("enctype", "multipart/form-data"),
864 xs_html_attr("type", "text"), 831 xs_html_tag("p",
865 xs_html_attr("name", "id"), 832 xs_html_text(L("Display name:")),
866 xs_html_attr("required", "required"), 833 xs_html_sctag("br", NULL),
867 xs_html_attr("placeholder", "https:/" "/fedi.example.com/bob/...")), 834 xs_html_sctag("input",
835 xs_html_attr("type", "text"),
836 xs_html_attr("name", "name"),
837 xs_html_attr("value", xs_dict_get(snac->config, "name")),
838 xs_html_attr("placeholder", L("Your name")))),
839 xs_html_tag("p",
840 xs_html_text(L("Avatar: ")),
841 xs_html_sctag("input",
842 xs_html_attr("type", "file"),
843 xs_html_attr("name", "avatar_file"))),
844 xs_html_tag("p",
845 xs_html_text(L("Header image (banner): ")),
846 xs_html_sctag("input",
847 xs_html_attr("type", "file"),
848 xs_html_attr("name", "header_file"))),
849 xs_html_tag("p",
850 xs_html_text(L("Bio:")),
851 xs_html_sctag("br", NULL),
852 xs_html_tag("textarea",
853 xs_html_attr("name", "bio"),
854 xs_html_attr("cols", "40"),
855 xs_html_attr("rows", "4"),
856 xs_html_attr("placeholder", L("Write about yourself here...")),
857 xs_html_text(xs_dict_get(snac->config, "bio")))),
868 xs_html_sctag("input", 858 xs_html_sctag("input",
869 xs_html_attr("type", "submit"), 859 xs_html_attr("type", "checkbox"),
870 xs_html_attr("name", "action"), 860 xs_html_attr("name", "cw"),
871 xs_html_attr("value", L("Boost"))), 861 xs_html_attr("id", "cw"),
872 xs_html_text(L("(by URL)"))), 862 xs_html_attr(strcmp(cw, "open") == 0 ? "checked" : "", NULL)),
873 xs_html_tag("p", NULL)); 863 xs_html_tag("label",
874 864 xs_html_attr("for", "cw"),
875 s2 = xs_html_render(ops); 865 xs_html_text(L("Always show sensitive content"))),
876 } 866 xs_html_tag("p",
867 xs_html_text(L("Email address for notifications:")),
868 xs_html_sctag("br", NULL),
869 xs_html_sctag("input",
870 xs_html_attr("type", "text"),
871 xs_html_attr("name", "email"),
872 xs_html_attr("value", email),
873 xs_html_attr("placeholder", "bob@example.com"))),
874 xs_html_tag("p",
875 xs_html_text(L("Telegram notifications (bot key and chat id):")),
876 xs_html_sctag("br", NULL),
877 xs_html_sctag("input",
878 xs_html_attr("type", "text"),
879 xs_html_attr("name", "telegram_bot"),
880 xs_html_attr("value", telegram_bot),
881 xs_html_attr("placeholder", "Bot API key")),
882 xs_html_text(" "),
883 xs_html_sctag("input",
884 xs_html_attr("type", "text"),
885 xs_html_attr("name", "telegram_chat_id"),
886 xs_html_attr("value", telegram_chat_id),
887 xs_html_attr("placeholder", "Chat id"))),
888 xs_html_tag("p",
889 xs_html_text(L("Maximum days to keep posts (0: server settings):")),
890 xs_html_sctag("br", NULL),
891 xs_html_sctag("input",
892 xs_html_attr("type", "number"),
893 xs_html_attr("name", "purge_days"),
894 xs_html_attr("value", purge_days))),
895 xs_html_tag("p",
896 xs_html_sctag("input",
897 xs_html_attr("type", "checkbox"),
898 xs_html_attr("name", "drop_dm_from_unknown"),
899 xs_html_attr("id", "drop_dm_from_unknown"),
900 xs_html_attr(xs_type(d_dm_f_u) == XSTYPE_TRUE ? "checked" : "", NULL)),
901 xs_html_tag("label",
902 xs_html_attr("for", "drop_dm_from_unknown"),
903 xs_html_text(L("Drop direct messages from people you don't follow")))),
904 xs_html_tag("p",
905 xs_html_sctag("input",
906 xs_html_attr("type", "checkbox"),
907 xs_html_attr("name", "bot"),
908 xs_html_attr("id", "bot"),
909 xs_html_attr(xs_type(bot) == XSTYPE_TRUE ? "checked" : "", NULL)),
910 xs_html_tag("label",
911 xs_html_attr("for", "bot"),
912 xs_html_text(L("This account is a bot")))),
913 xs_html_tag("p",
914 xs_html_sctag("input",
915 xs_html_attr("type", "checkbox"),
916 xs_html_attr("name", "private"),
917 xs_html_attr("id", "private"),
918 xs_html_attr(xs_type(a_private) == XSTYPE_TRUE ? "checked" : "", NULL)),
919 xs_html_tag("label",
920 xs_html_attr("for", "private"),
921 xs_html_text(L("This account is private (posts are not shown through the web)")))),
922 xs_html_tag("p",
923 xs_html_text(L("Profile metadata (key=value pairs in each line):")),
924 xs_html_tag("textarea",
925 xs_html_attr("name", "metadata"),
926 xs_html_attr("cols", "40"),
927 xs_html_attr("rows", "4"),
928 xs_html_attr("placeholder", "Blog=https:/" "/example.com/my-blog\nGPG Key=1FA54\n..."),
929 xs_html_text(metadata))),
877 930
878 xs *s3 = xs_fmt(_tmpl3, 931 xs_html_tag("p",
879 L("User Settings..."), 932 xs_html_text(L("New password:")),
880 snac->actor, 933 xs_html_sctag("br", NULL),
881 L("Display name"), 934 xs_html_sctag("input",
882 es1, 935 xs_html_attr("type", "password"),
883 L("Avatar"), 936 xs_html_attr("name", "passwd1"),
884 L("Header image (banner)"), 937 xs_html_attr("value", ""))),
885 L("Bio"), 938 xs_html_tag("p",
886 es2, 939 xs_html_text(L("Repeat new password:")),
887 strcmp(cw, "open") == 0 ? "checked" : "", 940 xs_html_sctag("br", NULL),
888 L("Always show sensitive content"), 941 xs_html_sctag("input",
889 L("Email address for notifications"), 942 xs_html_attr("type", "password"),
890 es3, 943 xs_html_attr("name", "passwd2"),
891 L("Telegram notifications (bot key and chat id)"), 944 xs_html_attr("value", ""))),
892 es4, 945
893 es5, 946 xs_html_tag("input",
894 L("Maximum days to keep posts (0: server settings)"), 947 xs_html_attr("type", "submit"),
895 es6, 948 xs_html_attr("class", "button"),
896 xs_type(d_dm_f_u) == XSTYPE_TRUE ? "checked" : "", 949 xs_html_attr("value", L("Update user info"))))));
897 L("Drop direct messages from people you don't follow"), 950
898 xs_type(bot) == XSTYPE_TRUE ? "checked" : "", 951 xs *s3 = xs_html_render(user_settings);
899 L("This account is a bot"),
900 xs_type(a_private) == XSTYPE_TRUE ? "checked" : "",
901 L("This account is private (posts are not shown through the web)"),
902
903 L("Profile metadata (key=value pairs in each line)"),
904 metadata,
905
906 L("New password"),
907 L("Repeat new password"),
908 L("Update user info")
909 );
910 952
911 s = xs_str_cat(s, s1, s2, s3, "</div><!-- snac-top-controls -->\n"); 953 s = xs_str_cat(s, s1, s2, s3, "</div><!-- snac-top-controls -->\n");
912 954