commit 3f94080
default
·
2023-11-26 19:14:47 +0000 UTC
parent 6417d23
The user settings form has been converted to xs_html.
1 files changed,
+183,
-141
M
html.c
M
html.c
+183,
-141
1@@ -712,62 +712,64 @@ xs_str *html_user_header(snac *snac, xs_str *s, int local)
2 xs_str *html_top_controls(snac *snac, xs_str *s)
3 /* generates the top controls */
4 {
5- char *_tmpl3 =
6- "<details><summary>%s</summary>\n"
7-
8- "<div class=\"snac-user-setup\">\n" /** user setup **/
9- "<form autocomplete=\"off\" method=\"post\" "
10- "action=\"%s/admin/user-setup\" enctype=\"multipart/form-data\">\n"
11- "<p>%s:<br>\n"
12- "<input type=\"text\" name=\"name\" value=\"%s\" placeholder=\"Your name.\"></p>\n"
13-
14- "<p>%s: <input type=\"file\" name=\"avatar_file\"></p>\n"
15-
16- "<p>%s: <input type=\"file\" name=\"header_file\"></p>\n"
17-
18- "<p>%s:<br>\n"
19- "<textarea name=\"bio\" cols=\"40\" rows=\"4\" placeholder=\"Write about yourself here...\">%s</textarea></p>\n"
20-
21- "<p><input type=\"checkbox\" name=\"cw\" id=\"cw\" %s>\n"
22- "<label for=\"cw\">%s</label></p>\n"
23-
24- "<p>%s:<br>\n"
25- "<input type=\"text\" name=\"email\" value=\"%s\" placeholder=\"bob@example.com\"></p>\n"
26-
27- "<p>%s:<br>\n"
28- "<input type=\"text\" name=\"telegram_bot\" placeholder=\"Bot API key\" value=\"%s\"> "
29- "<input type=\"text\" name=\"telegram_chat_id\" placeholder=\"Chat id\" value=\"%s\"></p>\n"
30-
31- "<p>%s:<br>\n"
32- "<input type=\"number\" name=\"purge_days\" value=\"%s\"></p>\n"
33-
34- "<p><input type=\"checkbox\" name=\"drop_dm_from_unknown\" id=\"drop_dm_from_unknown\" %s>\n"
35- "<label for=\"drop_dm_from_unknown\">%s</label></p>\n"
36-
37- "<p><input type=\"checkbox\" name=\"bot\" id=\"bot\" %s>\n"
38- "<label for=\"bot\">%s</label></p>\n"
39+ xs_str_cat(s, "<div class=\"snac-top-controls\">\n");
40
41- "<p><input type=\"checkbox\" name=\"private\" id=\"private\" %s>\n"
42- "<label for=\"private\">%s</label></p>\n"
43+ xs_html *new_note = html_note(snac, L("New Post..."),
44+ "new_post_div", "new_post_form",
45+ L("What's on your mind?"), "",
46+ NULL, NULL,
47+ xs_stock_false, "",
48+ xs_stock_false, NULL,
49+ NULL, 1);
50
51- "<p>%s:<br>\n"
52- "<textarea name=\"metadata\" cols=\"40\" rows=\"4\" "
53- "placeholder=\"Blog=https:/" "/example.com/my-blog\nGPG Key=1FA54\n...\">"
54- "%s</textarea></p>\n"
55+ xs *s1 = xs_html_render(new_note);
56
57- "<p>%s:<br>\n"
58- "<input type=\"password\" name=\"passwd1\" value=\"\"></p>\n"
59+ xs *s2 = NULL;
60
61- "<p>%s:<br>\n"
62- "<input type=\"password\" name=\"passwd2\" value=\"\"></p>\n"
63+ /** operations form **/
64+ {
65+ xs *ops_action = xs_fmt("%s/admin/action", snac->actor);
66+ xs_html *ops = xs_html_tag("details",
67+ xs_html_tag("summary",
68+ xs_html_text(L("Operations..."))),
69+ xs_html_tag("p", NULL),
70+ xs_html_tag("form",
71+ xs_html_attr("autocomplete", "off"),
72+ xs_html_attr("method", "post"),
73+ xs_html_attr("action", ops_action),
74+ xs_html_sctag("input",
75+ xs_html_attr("type", "text"),
76+ xs_html_attr("name", "actor"),
77+ xs_html_attr("required", "required"),
78+ xs_html_attr("placeholder", "bob@example.com")),
79+ xs_html_sctag("input",
80+ xs_html_attr("type", "submit"),
81+ xs_html_attr("name", "action"),
82+ xs_html_attr("value", L("Follow"))),
83+ xs_html_text(L("(by URL or user@host)"))),
84+ xs_html_tag("p", NULL),
85+ xs_html_tag("form",
86+ xs_html_attr("autocomplete", "off"),
87+ xs_html_attr("method", "post"),
88+ xs_html_attr("action", ops_action),
89+ xs_html_sctag("input",
90+ xs_html_attr("type", "text"),
91+ xs_html_attr("name", "id"),
92+ xs_html_attr("required", "required"),
93+ xs_html_attr("placeholder", "https:/" "/fedi.example.com/bob/...")),
94+ xs_html_sctag("input",
95+ xs_html_attr("type", "submit"),
96+ xs_html_attr("name", "action"),
97+ xs_html_attr("value", L("Boost"))),
98+ xs_html_text(L("(by URL)"))),
99+ xs_html_tag("p", NULL));
100
101- "<input type=\"submit\" class=\"button\" value=\"%s\">\n"
102- "</form>\n"
103+ s2 = xs_html_render(ops);
104+ }
105
106- "</div>\n"
107- "</details>\n";
108+ /** user settings form **/
109
110- const char *email = "[disabled by admin]";
111+ char *email = "[disabled by admin]";
112
113 if (xs_type(xs_dict_get(srv_config, "disable_email_notifications")) != XSTYPE_TRUE) {
114 email = xs_dict_get(snac->config_o, "email");
115@@ -791,23 +793,15 @@ xs_str *html_top_controls(snac *snac, xs_str *s)
116 if (xs_is_null(telegram_chat_id))
117 telegram_chat_id = "";
118
119- const char *purge_days = xs_dict_get(snac->config, "purge_days");
120+ char *purge_days = xs_dict_get(snac->config, "purge_days");
121 if (!xs_is_null(purge_days) && xs_type(purge_days) == XSTYPE_NUMBER)
122- purge_days = xs_number_str(purge_days);
123+ purge_days = (char *)xs_number_str(purge_days);
124 else
125 purge_days = "0";
126
127- const char *d_dm_f_u = xs_dict_get(snac->config, "drop_dm_from_unknown");
128-
129- const char *bot = xs_dict_get(snac->config, "bot");
130- const char *a_private = xs_dict_get(snac->config, "private");
131-
132- xs *es1 = encode_html(xs_dict_get(snac->config, "name"));
133- xs *es2 = encode_html(xs_dict_get(snac->config, "bio"));
134- xs *es3 = encode_html(email);
135- xs *es4 = encode_html(telegram_bot);
136- xs *es5 = encode_html(telegram_chat_id);
137- xs *es6 = encode_html(purge_days);
138+ xs_val *d_dm_f_u = xs_dict_get(snac->config, "drop_dm_from_unknown");
139+ xs_val *bot = xs_dict_get(snac->config, "bot");
140+ xs_val *a_private = xs_dict_get(snac->config, "private");
141
142 xs *metadata = xs_str_new(NULL);
143 xs_dict *md = xs_dict_get(snac->config, "metadata");
144@@ -822,91 +816,139 @@ xs_str *html_top_controls(snac *snac, xs_str *s)
145 metadata = xs_str_cat(metadata, kp);
146 }
147
148- xs_str_cat(s, "<div class=\"snac-top-controls\">\n");
149+ xs *user_setup_action = xs_fmt("%s/admin/user-setup", snac->actor);
150
151- xs_html *new_note = html_note(snac, L("New Post..."),
152- "new_post_div", "new_post_form",
153- L("What's on your mind?"), "",
154- NULL, NULL,
155- xs_stock_false, "",
156- xs_stock_false, NULL,
157- NULL, 1);
158-
159- xs *s1 = xs_html_render(new_note);
160-
161- xs *s2 = NULL;
162-
163- {
164- xs *ops_action = xs_fmt("%s/admin/action", snac->actor);
165- xs_html *ops = xs_html_tag("details",
166- xs_html_tag("summary",
167- xs_html_text(L("Operations..."))),
168- xs_html_tag("form",
169- xs_html_attr("autocomplete", "off"),
170- xs_html_attr("method", "post"),
171- xs_html_attr("action", ops_action),
172- xs_html_sctag("input",
173- xs_html_attr("type", "text"),
174- xs_html_attr("name", "actor"),
175- xs_html_attr("required", "required"),
176- xs_html_attr("placeholder", "bob@example.com")),
177- xs_html_sctag("input",
178- xs_html_attr("type", "submit"),
179- xs_html_attr("name", "action"),
180- xs_html_attr("value", L("Follow"))),
181- xs_html_text(L("(by URL or user@host)"))),
182- xs_html_tag("p", NULL),
183+ xs_html *user_settings = xs_html_tag("details",
184+ xs_html_tag("summary",
185+ xs_html_text(L("User Settings..."))),
186+ xs_html_tag("div",
187+ xs_html_attr("class", "snac-user-setup"),
188 xs_html_tag("form",
189 xs_html_attr("autocomplete", "off"),
190 xs_html_attr("method", "post"),
191- xs_html_attr("action", ops_action),
192- xs_html_sctag("input",
193- xs_html_attr("type", "text"),
194- xs_html_attr("name", "id"),
195- xs_html_attr("required", "required"),
196- xs_html_attr("placeholder", "https:/" "/fedi.example.com/bob/...")),
197+ xs_html_attr("action", user_setup_action),
198+ xs_html_attr("enctype", "multipart/form-data"),
199+ xs_html_tag("p",
200+ xs_html_text(L("Display name:")),
201+ xs_html_sctag("br", NULL),
202+ xs_html_sctag("input",
203+ xs_html_attr("type", "text"),
204+ xs_html_attr("name", "name"),
205+ xs_html_attr("value", xs_dict_get(snac->config, "name")),
206+ xs_html_attr("placeholder", L("Your name")))),
207+ xs_html_tag("p",
208+ xs_html_text(L("Avatar: ")),
209+ xs_html_sctag("input",
210+ xs_html_attr("type", "file"),
211+ xs_html_attr("name", "avatar_file"))),
212+ xs_html_tag("p",
213+ xs_html_text(L("Header image (banner): ")),
214+ xs_html_sctag("input",
215+ xs_html_attr("type", "file"),
216+ xs_html_attr("name", "header_file"))),
217+ xs_html_tag("p",
218+ xs_html_text(L("Bio:")),
219+ xs_html_sctag("br", NULL),
220+ xs_html_tag("textarea",
221+ xs_html_attr("name", "bio"),
222+ xs_html_attr("cols", "40"),
223+ xs_html_attr("rows", "4"),
224+ xs_html_attr("placeholder", L("Write about yourself here...")),
225+ xs_html_text(xs_dict_get(snac->config, "bio")))),
226 xs_html_sctag("input",
227- xs_html_attr("type", "submit"),
228- xs_html_attr("name", "action"),
229- xs_html_attr("value", L("Boost"))),
230- xs_html_text(L("(by URL)"))),
231- xs_html_tag("p", NULL));
232-
233- s2 = xs_html_render(ops);
234- }
235+ xs_html_attr("type", "checkbox"),
236+ xs_html_attr("name", "cw"),
237+ xs_html_attr("id", "cw"),
238+ xs_html_attr(strcmp(cw, "open") == 0 ? "checked" : "", NULL)),
239+ xs_html_tag("label",
240+ xs_html_attr("for", "cw"),
241+ xs_html_text(L("Always show sensitive content"))),
242+ xs_html_tag("p",
243+ xs_html_text(L("Email address for notifications:")),
244+ xs_html_sctag("br", NULL),
245+ xs_html_sctag("input",
246+ xs_html_attr("type", "text"),
247+ xs_html_attr("name", "email"),
248+ xs_html_attr("value", email),
249+ xs_html_attr("placeholder", "bob@example.com"))),
250+ xs_html_tag("p",
251+ xs_html_text(L("Telegram notifications (bot key and chat id):")),
252+ xs_html_sctag("br", NULL),
253+ xs_html_sctag("input",
254+ xs_html_attr("type", "text"),
255+ xs_html_attr("name", "telegram_bot"),
256+ xs_html_attr("value", telegram_bot),
257+ xs_html_attr("placeholder", "Bot API key")),
258+ xs_html_text(" "),
259+ xs_html_sctag("input",
260+ xs_html_attr("type", "text"),
261+ xs_html_attr("name", "telegram_chat_id"),
262+ xs_html_attr("value", telegram_chat_id),
263+ xs_html_attr("placeholder", "Chat id"))),
264+ xs_html_tag("p",
265+ xs_html_text(L("Maximum days to keep posts (0: server settings):")),
266+ xs_html_sctag("br", NULL),
267+ xs_html_sctag("input",
268+ xs_html_attr("type", "number"),
269+ xs_html_attr("name", "purge_days"),
270+ xs_html_attr("value", purge_days))),
271+ xs_html_tag("p",
272+ xs_html_sctag("input",
273+ xs_html_attr("type", "checkbox"),
274+ xs_html_attr("name", "drop_dm_from_unknown"),
275+ xs_html_attr("id", "drop_dm_from_unknown"),
276+ xs_html_attr(xs_type(d_dm_f_u) == XSTYPE_TRUE ? "checked" : "", NULL)),
277+ xs_html_tag("label",
278+ xs_html_attr("for", "drop_dm_from_unknown"),
279+ xs_html_text(L("Drop direct messages from people you don't follow")))),
280+ xs_html_tag("p",
281+ xs_html_sctag("input",
282+ xs_html_attr("type", "checkbox"),
283+ xs_html_attr("name", "bot"),
284+ xs_html_attr("id", "bot"),
285+ xs_html_attr(xs_type(bot) == XSTYPE_TRUE ? "checked" : "", NULL)),
286+ xs_html_tag("label",
287+ xs_html_attr("for", "bot"),
288+ xs_html_text(L("This account is a bot")))),
289+ xs_html_tag("p",
290+ xs_html_sctag("input",
291+ xs_html_attr("type", "checkbox"),
292+ xs_html_attr("name", "private"),
293+ xs_html_attr("id", "private"),
294+ xs_html_attr(xs_type(a_private) == XSTYPE_TRUE ? "checked" : "", NULL)),
295+ xs_html_tag("label",
296+ xs_html_attr("for", "private"),
297+ xs_html_text(L("This account is private (posts are not shown through the web)")))),
298+ xs_html_tag("p",
299+ xs_html_text(L("Profile metadata (key=value pairs in each line):")),
300+ xs_html_tag("textarea",
301+ xs_html_attr("name", "metadata"),
302+ xs_html_attr("cols", "40"),
303+ xs_html_attr("rows", "4"),
304+ xs_html_attr("placeholder", "Blog=https:/" "/example.com/my-blog\nGPG Key=1FA54\n..."),
305+ xs_html_text(metadata))),
306
307- xs *s3 = xs_fmt(_tmpl3,
308- L("User Settings..."),
309- snac->actor,
310- L("Display name"),
311- es1,
312- L("Avatar"),
313- L("Header image (banner)"),
314- L("Bio"),
315- es2,
316- strcmp(cw, "open") == 0 ? "checked" : "",
317- L("Always show sensitive content"),
318- L("Email address for notifications"),
319- es3,
320- L("Telegram notifications (bot key and chat id)"),
321- es4,
322- es5,
323- L("Maximum days to keep posts (0: server settings)"),
324- es6,
325- xs_type(d_dm_f_u) == XSTYPE_TRUE ? "checked" : "",
326- L("Drop direct messages from people you don't follow"),
327- xs_type(bot) == XSTYPE_TRUE ? "checked" : "",
328- L("This account is a bot"),
329- xs_type(a_private) == XSTYPE_TRUE ? "checked" : "",
330- L("This account is private (posts are not shown through the web)"),
331-
332- L("Profile metadata (key=value pairs in each line)"),
333- metadata,
334-
335- L("New password"),
336- L("Repeat new password"),
337- L("Update user info")
338- );
339+ xs_html_tag("p",
340+ xs_html_text(L("New password:")),
341+ xs_html_sctag("br", NULL),
342+ xs_html_sctag("input",
343+ xs_html_attr("type", "password"),
344+ xs_html_attr("name", "passwd1"),
345+ xs_html_attr("value", ""))),
346+ xs_html_tag("p",
347+ xs_html_text(L("Repeat new password:")),
348+ xs_html_sctag("br", NULL),
349+ xs_html_sctag("input",
350+ xs_html_attr("type", "password"),
351+ xs_html_attr("name", "passwd2"),
352+ xs_html_attr("value", ""))),
353+
354+ xs_html_tag("input",
355+ xs_html_attr("type", "submit"),
356+ xs_html_attr("class", "button"),
357+ xs_html_attr("value", L("Update user info"))))));
358+
359+ xs *s3 = xs_html_render(user_settings);
360
361 s = xs_str_cat(s, s1, s2, s3, "</div><!-- snac-top-controls -->\n");
362