From 3f9408027850481fbcfc9dbd738d12d75503bb0f Mon Sep 17 00:00:00 2001 From: default Date: Sun, 26 Nov 2023 20:14:47 +0100 Subject: The user settings form has been converted to xs_html. --- html.c | 324 +++++++++++++++++++++++++++++++++++++---------------------------- 1 file changed, 183 insertions(+), 141 deletions(-) (limited to 'html.c') 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) xs_str *html_top_controls(snac *snac, xs_str *s) /* generates the top controls */ { - char *_tmpl3 = - "
%s\n" - - "
\n" /** user setup **/ - "
\n" - "

%s:
\n" - "

\n" - - "

%s:

\n" - - "

%s:

\n" - - "

%s:
\n" - "

\n" - - "

\n" - "

\n" - - "

%s:
\n" - "

\n" - - "

%s:
\n" - " " - "

\n" - - "

%s:
\n" - "

\n" - - "

\n" - "

\n" - - "

\n" - "

\n" + xs_str_cat(s, "
\n"); - "

\n" - "

\n" + xs_html *new_note = html_note(snac, L("New Post..."), + "new_post_div", "new_post_form", + L("What's on your mind?"), "", + NULL, NULL, + xs_stock_false, "", + xs_stock_false, NULL, + NULL, 1); - "

%s:
\n" - "

\n" + xs *s1 = xs_html_render(new_note); - "

%s:
\n" - "

\n" + xs *s2 = NULL; - "

%s:
\n" - "

\n" + /** operations form **/ + { + xs *ops_action = xs_fmt("%s/admin/action", snac->actor); + xs_html *ops = xs_html_tag("details", + xs_html_tag("summary", + xs_html_text(L("Operations..."))), + xs_html_tag("p", NULL), + xs_html_tag("form", + xs_html_attr("autocomplete", "off"), + xs_html_attr("method", "post"), + xs_html_attr("action", ops_action), + xs_html_sctag("input", + xs_html_attr("type", "text"), + xs_html_attr("name", "actor"), + xs_html_attr("required", "required"), + xs_html_attr("placeholder", "bob@example.com")), + xs_html_sctag("input", + xs_html_attr("type", "submit"), + xs_html_attr("name", "action"), + xs_html_attr("value", L("Follow"))), + xs_html_text(L("(by URL or user@host)"))), + xs_html_tag("p", NULL), + xs_html_tag("form", + xs_html_attr("autocomplete", "off"), + xs_html_attr("method", "post"), + xs_html_attr("action", ops_action), + xs_html_sctag("input", + xs_html_attr("type", "text"), + xs_html_attr("name", "id"), + xs_html_attr("required", "required"), + xs_html_attr("placeholder", "https:/" "/fedi.example.com/bob/...")), + xs_html_sctag("input", + xs_html_attr("type", "submit"), + xs_html_attr("name", "action"), + xs_html_attr("value", L("Boost"))), + xs_html_text(L("(by URL)"))), + xs_html_tag("p", NULL)); - "\n" - "\n" + s2 = xs_html_render(ops); + } - "
\n" - "
\n"; + /** user settings form **/ - const char *email = "[disabled by admin]"; + char *email = "[disabled by admin]"; if (xs_type(xs_dict_get(srv_config, "disable_email_notifications")) != XSTYPE_TRUE) { email = xs_dict_get(snac->config_o, "email"); @@ -791,23 +793,15 @@ xs_str *html_top_controls(snac *snac, xs_str *s) if (xs_is_null(telegram_chat_id)) telegram_chat_id = ""; - const char *purge_days = xs_dict_get(snac->config, "purge_days"); + char *purge_days = xs_dict_get(snac->config, "purge_days"); if (!xs_is_null(purge_days) && xs_type(purge_days) == XSTYPE_NUMBER) - purge_days = xs_number_str(purge_days); + purge_days = (char *)xs_number_str(purge_days); else purge_days = "0"; - const char *d_dm_f_u = xs_dict_get(snac->config, "drop_dm_from_unknown"); - - const char *bot = xs_dict_get(snac->config, "bot"); - const char *a_private = xs_dict_get(snac->config, "private"); - - xs *es1 = encode_html(xs_dict_get(snac->config, "name")); - xs *es2 = encode_html(xs_dict_get(snac->config, "bio")); - xs *es3 = encode_html(email); - xs *es4 = encode_html(telegram_bot); - xs *es5 = encode_html(telegram_chat_id); - xs *es6 = encode_html(purge_days); + xs_val *d_dm_f_u = xs_dict_get(snac->config, "drop_dm_from_unknown"); + xs_val *bot = xs_dict_get(snac->config, "bot"); + xs_val *a_private = xs_dict_get(snac->config, "private"); xs *metadata = xs_str_new(NULL); xs_dict *md = xs_dict_get(snac->config, "metadata"); @@ -822,91 +816,139 @@ xs_str *html_top_controls(snac *snac, xs_str *s) metadata = xs_str_cat(metadata, kp); } - xs_str_cat(s, "
\n"); + xs *user_setup_action = xs_fmt("%s/admin/user-setup", snac->actor); - xs_html *new_note = html_note(snac, L("New Post..."), - "new_post_div", "new_post_form", - L("What's on your mind?"), "", - NULL, NULL, - xs_stock_false, "", - xs_stock_false, NULL, - NULL, 1); - - xs *s1 = xs_html_render(new_note); - - xs *s2 = NULL; - - { - xs *ops_action = xs_fmt("%s/admin/action", snac->actor); - xs_html *ops = xs_html_tag("details", - xs_html_tag("summary", - xs_html_text(L("Operations..."))), - xs_html_tag("form", - xs_html_attr("autocomplete", "off"), - xs_html_attr("method", "post"), - xs_html_attr("action", ops_action), - xs_html_sctag("input", - xs_html_attr("type", "text"), - xs_html_attr("name", "actor"), - xs_html_attr("required", "required"), - xs_html_attr("placeholder", "bob@example.com")), - xs_html_sctag("input", - xs_html_attr("type", "submit"), - xs_html_attr("name", "action"), - xs_html_attr("value", L("Follow"))), - xs_html_text(L("(by URL or user@host)"))), - xs_html_tag("p", NULL), + xs_html *user_settings = xs_html_tag("details", + xs_html_tag("summary", + xs_html_text(L("User Settings..."))), + xs_html_tag("div", + xs_html_attr("class", "snac-user-setup"), xs_html_tag("form", xs_html_attr("autocomplete", "off"), xs_html_attr("method", "post"), - xs_html_attr("action", ops_action), - xs_html_sctag("input", - xs_html_attr("type", "text"), - xs_html_attr("name", "id"), - xs_html_attr("required", "required"), - xs_html_attr("placeholder", "https:/" "/fedi.example.com/bob/...")), + xs_html_attr("action", user_setup_action), + xs_html_attr("enctype", "multipart/form-data"), + xs_html_tag("p", + xs_html_text(L("Display name:")), + xs_html_sctag("br", NULL), + xs_html_sctag("input", + xs_html_attr("type", "text"), + xs_html_attr("name", "name"), + xs_html_attr("value", xs_dict_get(snac->config, "name")), + xs_html_attr("placeholder", L("Your name")))), + xs_html_tag("p", + xs_html_text(L("Avatar: ")), + xs_html_sctag("input", + xs_html_attr("type", "file"), + xs_html_attr("name", "avatar_file"))), + xs_html_tag("p", + xs_html_text(L("Header image (banner): ")), + xs_html_sctag("input", + xs_html_attr("type", "file"), + xs_html_attr("name", "header_file"))), + xs_html_tag("p", + xs_html_text(L("Bio:")), + xs_html_sctag("br", NULL), + xs_html_tag("textarea", + xs_html_attr("name", "bio"), + xs_html_attr("cols", "40"), + xs_html_attr("rows", "4"), + xs_html_attr("placeholder", L("Write about yourself here...")), + xs_html_text(xs_dict_get(snac->config, "bio")))), xs_html_sctag("input", - xs_html_attr("type", "submit"), - xs_html_attr("name", "action"), - xs_html_attr("value", L("Boost"))), - xs_html_text(L("(by URL)"))), - xs_html_tag("p", NULL)); - - s2 = xs_html_render(ops); - } + xs_html_attr("type", "checkbox"), + xs_html_attr("name", "cw"), + xs_html_attr("id", "cw"), + xs_html_attr(strcmp(cw, "open") == 0 ? "checked" : "", NULL)), + xs_html_tag("label", + xs_html_attr("for", "cw"), + xs_html_text(L("Always show sensitive content"))), + xs_html_tag("p", + xs_html_text(L("Email address for notifications:")), + xs_html_sctag("br", NULL), + xs_html_sctag("input", + xs_html_attr("type", "text"), + xs_html_attr("name", "email"), + xs_html_attr("value", email), + xs_html_attr("placeholder", "bob@example.com"))), + xs_html_tag("p", + xs_html_text(L("Telegram notifications (bot key and chat id):")), + xs_html_sctag("br", NULL), + xs_html_sctag("input", + xs_html_attr("type", "text"), + xs_html_attr("name", "telegram_bot"), + xs_html_attr("value", telegram_bot), + xs_html_attr("placeholder", "Bot API key")), + xs_html_text(" "), + xs_html_sctag("input", + xs_html_attr("type", "text"), + xs_html_attr("name", "telegram_chat_id"), + xs_html_attr("value", telegram_chat_id), + xs_html_attr("placeholder", "Chat id"))), + xs_html_tag("p", + xs_html_text(L("Maximum days to keep posts (0: server settings):")), + xs_html_sctag("br", NULL), + xs_html_sctag("input", + xs_html_attr("type", "number"), + xs_html_attr("name", "purge_days"), + xs_html_attr("value", purge_days))), + xs_html_tag("p", + xs_html_sctag("input", + xs_html_attr("type", "checkbox"), + xs_html_attr("name", "drop_dm_from_unknown"), + xs_html_attr("id", "drop_dm_from_unknown"), + xs_html_attr(xs_type(d_dm_f_u) == XSTYPE_TRUE ? "checked" : "", NULL)), + xs_html_tag("label", + xs_html_attr("for", "drop_dm_from_unknown"), + xs_html_text(L("Drop direct messages from people you don't follow")))), + xs_html_tag("p", + xs_html_sctag("input", + xs_html_attr("type", "checkbox"), + xs_html_attr("name", "bot"), + xs_html_attr("id", "bot"), + xs_html_attr(xs_type(bot) == XSTYPE_TRUE ? "checked" : "", NULL)), + xs_html_tag("label", + xs_html_attr("for", "bot"), + xs_html_text(L("This account is a bot")))), + xs_html_tag("p", + xs_html_sctag("input", + xs_html_attr("type", "checkbox"), + xs_html_attr("name", "private"), + xs_html_attr("id", "private"), + xs_html_attr(xs_type(a_private) == XSTYPE_TRUE ? "checked" : "", NULL)), + xs_html_tag("label", + xs_html_attr("for", "private"), + xs_html_text(L("This account is private (posts are not shown through the web)")))), + xs_html_tag("p", + xs_html_text(L("Profile metadata (key=value pairs in each line):")), + xs_html_tag("textarea", + xs_html_attr("name", "metadata"), + xs_html_attr("cols", "40"), + xs_html_attr("rows", "4"), + xs_html_attr("placeholder", "Blog=https:/" "/example.com/my-blog\nGPG Key=1FA54\n..."), + xs_html_text(metadata))), - xs *s3 = xs_fmt(_tmpl3, - L("User Settings..."), - snac->actor, - L("Display name"), - es1, - L("Avatar"), - L("Header image (banner)"), - L("Bio"), - es2, - strcmp(cw, "open") == 0 ? "checked" : "", - L("Always show sensitive content"), - L("Email address for notifications"), - es3, - L("Telegram notifications (bot key and chat id)"), - es4, - es5, - L("Maximum days to keep posts (0: server settings)"), - es6, - xs_type(d_dm_f_u) == XSTYPE_TRUE ? "checked" : "", - L("Drop direct messages from people you don't follow"), - xs_type(bot) == XSTYPE_TRUE ? "checked" : "", - L("This account is a bot"), - xs_type(a_private) == XSTYPE_TRUE ? "checked" : "", - L("This account is private (posts are not shown through the web)"), - - L("Profile metadata (key=value pairs in each line)"), - metadata, - - L("New password"), - L("Repeat new password"), - L("Update user info") - ); + xs_html_tag("p", + xs_html_text(L("New password:")), + xs_html_sctag("br", NULL), + xs_html_sctag("input", + xs_html_attr("type", "password"), + xs_html_attr("name", "passwd1"), + xs_html_attr("value", ""))), + xs_html_tag("p", + xs_html_text(L("Repeat new password:")), + xs_html_sctag("br", NULL), + xs_html_sctag("input", + xs_html_attr("type", "password"), + xs_html_attr("name", "passwd2"), + xs_html_attr("value", ""))), + + xs_html_tag("input", + xs_html_attr("type", "submit"), + xs_html_attr("class", "button"), + xs_html_attr("value", L("Update user info")))))); + + xs *s3 = xs_html_render(user_settings); s = xs_str_cat(s, s1, s2, s3, "
\n"); -- cgit v1.2.3