diff options
| author | 2023-11-23 20:41:10 +0100 | |
|---|---|---|
| committer | 2023-11-23 20:41:10 +0100 | |
| commit | 741302cc3bd40ffac61677ef3c002559d65aa2c5 (patch) | |
| tree | 55ece541d6528091bf2de0fd72e1b7cfe2210469 | |
| parent | Minor xs_html tweaks. (diff) | |
| download | snac2-741302cc3bd40ffac61677ef3c002559d65aa2c5.tar.gz snac2-741302cc3bd40ffac61677ef3c002559d65aa2c5.tar.xz snac2-741302cc3bd40ffac61677ef3c002559d65aa2c5.zip | |
New function html_note() (still unused).
| -rw-r--r-- | html.c | 144 | ||||
| -rw-r--r-- | main.c | 23 |
2 files changed, 167 insertions, 0 deletions
| @@ -232,6 +232,150 @@ xs_str *html_msg_icon(xs_str *os, const xs_dict *msg) | |||
| 232 | } | 232 | } |
| 233 | 233 | ||
| 234 | 234 | ||
| 235 | xs_html *html_note(snac *user, char *summary, | ||
| 236 | char *div_id, char *form_id, | ||
| 237 | char *ta_plh, char *ta_content, | ||
| 238 | char *edit_id, char *actor_id, | ||
| 239 | xs_val *cw_yn, char *cw_text, | ||
| 240 | xs_val *mnt_only, char *redir, | ||
| 241 | char *in_reply_to, int poll) | ||
| 242 | { | ||
| 243 | xs *action = xs_fmt("%s/admin/note", user->actor); | ||
| 244 | |||
| 245 | xs_html *form; | ||
| 246 | |||
| 247 | xs_html *note = xs_html_tag("div", | ||
| 248 | xs_html_tag("details", | ||
| 249 | xs_html_tag("summary", | ||
| 250 | xs_html_text(summary)), | ||
| 251 | xs_html_tag("p", NULL), | ||
| 252 | xs_html_tag("div", | ||
| 253 | xs_html_attr("class", "snac-note"), | ||
| 254 | xs_html_attr("id", div_id), | ||
| 255 | form = xs_html_tag("form", | ||
| 256 | xs_html_attr("autocomplete", "off"), | ||
| 257 | xs_html_attr("method", "post"), | ||
| 258 | xs_html_attr("action", action), | ||
| 259 | xs_html_attr("enctype", "multipart/form-data"), | ||
| 260 | xs_html_attr("id", form_id), | ||
| 261 | xs_html_tag("textarea", | ||
| 262 | xs_html_attr("class", "snac-textarea"), | ||
| 263 | xs_html_attr("name", "content"), | ||
| 264 | xs_html_attr("rows", "4"), | ||
| 265 | xs_html_attr("wrap", "virtual"), | ||
| 266 | xs_html_attr("required", "required"), | ||
| 267 | xs_html_attr("placeholder", ta_plh), | ||
| 268 | xs_html_text(ta_content)), | ||
| 269 | xs_html_tag("p", NULL), | ||
| 270 | xs_html_text(L("Sensitive content: ")), | ||
| 271 | xs_html_sctag("input", | ||
| 272 | xs_html_attr("type", "checkbox"), | ||
| 273 | xs_html_attr("name", "sensitive"), | ||
| 274 | xs_html_attr(xs_type(cw_yn) == XSTYPE_TRUE ? "checked" : "", NULL)), | ||
| 275 | xs_html_sctag("input", | ||
| 276 | xs_html_attr("type", "text"), | ||
| 277 | xs_html_attr("name", "summary"), | ||
| 278 | xs_html_attr("placeholder", L("Sensitive content description")), | ||
| 279 | xs_html_attr("value", cw_text)))))); | ||
| 280 | |||
| 281 | if (actor_id) | ||
| 282 | xs_html_add(form, | ||
| 283 | xs_html_sctag("input", | ||
| 284 | xs_html_attr("type", "hidden"), | ||
| 285 | xs_html_attr("name", "to"), | ||
| 286 | xs_html_attr("value", actor_id))); | ||
| 287 | else { | ||
| 288 | /* no actor_id; ask for mentioned_only */ | ||
| 289 | xs_html_add(form, | ||
| 290 | xs_html_tag("p", NULL), | ||
| 291 | xs_html_text(L("Only for mentioned people")), | ||
| 292 | xs_html_sctag("input", | ||
| 293 | xs_html_attr("type", "checkbox"), | ||
| 294 | xs_html_attr("name", "mentioned_only"), | ||
| 295 | xs_html_attr(xs_type(mnt_only) == XSTYPE_TRUE ? "checked" : "", NULL))); | ||
| 296 | } | ||
| 297 | |||
| 298 | if (redir) | ||
| 299 | xs_html_add(form, | ||
| 300 | xs_html_sctag("input", | ||
| 301 | xs_html_attr("type", "hidden"), | ||
| 302 | xs_html_attr("name", "redir"), | ||
| 303 | xs_html_attr("value", redir))); | ||
| 304 | |||
| 305 | if (in_reply_to) | ||
| 306 | xs_html_add(form, | ||
| 307 | xs_html_sctag("input", | ||
| 308 | xs_html_attr("type", "hidden"), | ||
| 309 | xs_html_attr("name", "in_reply_to"), | ||
| 310 | xs_html_attr("value", in_reply_to))); | ||
| 311 | |||
| 312 | if (edit_id) | ||
| 313 | xs_html_add(form, | ||
| 314 | xs_html_sctag("input", | ||
| 315 | xs_html_attr("type", "hidden"), | ||
| 316 | xs_html_attr("name", "edit_id"), | ||
| 317 | xs_html_attr("value", edit_id))); | ||
| 318 | |||
| 319 | xs_html_add(form, | ||
| 320 | xs_html_tag("details", | ||
| 321 | xs_html_tag("summary", | ||
| 322 | xs_html_text(L("Attachment..."))), | ||
| 323 | xs_html_tag("p", NULL), | ||
| 324 | xs_html_sctag("input", | ||
| 325 | xs_html_attr("type", "file"), | ||
| 326 | xs_html_attr("name", "attach")), | ||
| 327 | xs_html_sctag("input", | ||
| 328 | xs_html_attr("type", "text"), | ||
| 329 | xs_html_attr("name", "alt_text"), | ||
| 330 | xs_html_attr("placeholder", L("Attachment description"))))); | ||
| 331 | |||
| 332 | /* add poll controls */ | ||
| 333 | if (poll) { | ||
| 334 | xs_html_add(form, | ||
| 335 | xs_html_tag("details", | ||
| 336 | xs_html_tag("summary", | ||
| 337 | xs_html_text(L("Poll..."))), | ||
| 338 | xs_html_tag("p", NULL), | ||
| 339 | xs_html_tag("textarea", | ||
| 340 | xs_html_attr("class", "snac-textarea"), | ||
| 341 | xs_html_attr("name", "poll_options"), | ||
| 342 | xs_html_attr("rows", "4"), | ||
| 343 | xs_html_attr("wrap", "virtual"), | ||
| 344 | xs_html_attr("placeholder", "Option 1...\nOption 2...\nOption 3...\n...")), | ||
| 345 | xs_html_tag("p", NULL), | ||
| 346 | xs_html_tag("select", | ||
| 347 | xs_html_attr("name", "poll_multiple"), | ||
| 348 | xs_html_tag("option", | ||
| 349 | xs_html_attr("value", "off"), | ||
| 350 | xs_html_text(L("One choice"))), | ||
| 351 | xs_html_tag("option", | ||
| 352 | xs_html_attr("value", "on"), | ||
| 353 | xs_html_text(L("Multiple choices")))), | ||
| 354 | xs_html_tag("select", | ||
| 355 | xs_html_attr("name", "poll_end_secs"), | ||
| 356 | xs_html_tag("option", | ||
| 357 | xs_html_attr("value", "300"), | ||
| 358 | xs_html_text(L("End in 5 minutes"))), | ||
| 359 | xs_html_tag("option", | ||
| 360 | xs_html_attr("value", "3600"), | ||
| 361 | xs_html_attr("selected", NULL), | ||
| 362 | xs_html_text(L("End in 1 hour"))), | ||
| 363 | xs_html_tag("option", | ||
| 364 | xs_html_attr("value", "86400"), | ||
| 365 | xs_html_text(L("End in 1 day")))))); | ||
| 366 | } | ||
| 367 | |||
| 368 | xs_html_add(form, | ||
| 369 | xs_html_tag("p", NULL), | ||
| 370 | xs_html_sctag("input", | ||
| 371 | xs_html_attr("type", "submit"), | ||
| 372 | xs_html_attr("class", "button"), | ||
| 373 | xs_html_attr("value", L("Post")))); | ||
| 374 | |||
| 375 | return note; | ||
| 376 | } | ||
| 377 | |||
| 378 | |||
| 235 | xs_str *html_base_header(xs_str *s) | 379 | xs_str *html_base_header(xs_str *s) |
| 236 | { | 380 | { |
| 237 | xs_list *p; | 381 | xs_list *p; |
| @@ -56,6 +56,16 @@ char *get_argv(int *argi, int argc, char *argv[]) | |||
| 56 | 56 | ||
| 57 | #define GET_ARGV() get_argv(&argi, argc, argv) | 57 | #define GET_ARGV() get_argv(&argi, argc, argv) |
| 58 | 58 | ||
| 59 | #include "xs_html.h" | ||
| 60 | |||
| 61 | xs_html *html_note(snac *user, char *summary, | ||
| 62 | char *div_id, char *form_id, | ||
| 63 | char *ta_plh, char *ta_content, | ||
| 64 | char *edit_id, char *actor_id, | ||
| 65 | xs_val *cw_yn, char *cw_text, | ||
| 66 | xs_val *mnt_only, char *redir, | ||
| 67 | char *in_reply_to, int poll); | ||
| 68 | |||
| 59 | int main(int argc, char *argv[]) | 69 | int main(int argc, char *argv[]) |
| 60 | { | 70 | { |
| 61 | char *cmd; | 71 | char *cmd; |
| @@ -199,6 +209,19 @@ int main(int argc, char *argv[]) | |||
| 199 | srv_free(); | 209 | srv_free(); |
| 200 | #endif | 210 | #endif |
| 201 | 211 | ||
| 212 | { | ||
| 213 | xs_html *note = html_note(&snac, "Note...", | ||
| 214 | "DIV_ID", "FORM_ID", | ||
| 215 | "TEXTAREA_PLACEHOLDER", "TEXTAREA_CONTENT", | ||
| 216 | "EDIT_ID", "ACTOR_ID", | ||
| 217 | xs_stock_false, "CW_TEXT", | ||
| 218 | xs_stock_false, "REDIR", | ||
| 219 | "IN_REPLY_TO", 1); | ||
| 220 | |||
| 221 | xs *s1 = xs_html_render(note); | ||
| 222 | printf("\n%s\n", s1); | ||
| 223 | } | ||
| 224 | |||
| 202 | xs *idx = xs_fmt("%s/private.idx", snac.basedir); | 225 | xs *idx = xs_fmt("%s/private.idx", snac.basedir); |
| 203 | xs *list = index_list_desc(idx, 0, 256); | 226 | xs *list = index_list_desc(idx, 0, 256); |
| 204 | xs *tl = timeline_top_level(&snac, list); | 227 | xs *tl = timeline_top_level(&snac, list); |