diff options
| author | 2022-09-29 09:52:23 +0200 | |
|---|---|---|
| committer | 2022-09-29 09:52:23 +0200 | |
| commit | 8be7c4927fa8e7c1e92135a669110eec6e38b7e2 (patch) | |
| tree | 02652d97acc5d9f487685f48506a5bc15d62b12f /html.c | |
| parent | More HTML work. (diff) | |
| download | snac2-8be7c4927fa8e7c1e92135a669110eec6e38b7e2.tar.gz snac2-8be7c4927fa8e7c1e92135a669110eec6e38b7e2.tar.xz snac2-8be7c4927fa8e7c1e92135a669110eec6e38b7e2.zip | |
More HTML work.
Diffstat (limited to 'html.c')
| -rw-r--r-- | html.c | 79 |
1 files changed, 76 insertions, 3 deletions
| @@ -7,6 +7,7 @@ | |||
| 7 | #include "xs_json.h" | 7 | #include "xs_json.h" |
| 8 | #include "xs_regex.h" | 8 | #include "xs_regex.h" |
| 9 | #include "xs_set.h" | 9 | #include "xs_set.h" |
| 10 | #include "xs_openssl.h" | ||
| 10 | 11 | ||
| 11 | #include "snac.h" | 12 | #include "snac.h" |
| 12 | 13 | ||
| @@ -370,7 +371,70 @@ d_char *html_top_controls(snac *snac, d_char *s) | |||
| 370 | } | 371 | } |
| 371 | 372 | ||
| 372 | 373 | ||
| 373 | d_char *html_entry(snac *snac, d_char *os, char *msg, xs_set *seen, int level) | 374 | d_char *html_entry_controls(snac *snac, d_char *os, char *msg) |
| 375 | { | ||
| 376 | char *id = xs_dict_get(msg, "id"); | ||
| 377 | char *actor = xs_dict_get(msg, "attributedTo"); | ||
| 378 | |||
| 379 | xs *s = xs_str_new(NULL); | ||
| 380 | xs *md5 = xs_md5_hex(id, strlen(id)); | ||
| 381 | |||
| 382 | s = xs_str_cat(s, "<div class=\"snac-controls\">\n"); | ||
| 383 | |||
| 384 | { | ||
| 385 | xs *s1 = xs_fmt( | ||
| 386 | "<form method=\"post\" action=\"%s/admin/action\">\n" | ||
| 387 | "<input type=\"hidden\" name=\"id\" value=\"%s\">\n" | ||
| 388 | "<input type=\"hidden\" name=\"actor\" value=\"%s\">\n" | ||
| 389 | "<input type=\"button\" name=\"action\" " | ||
| 390 | "value=\"%s\" onclick=\"" | ||
| 391 | "x = document.getElementById('%s_reply'); " | ||
| 392 | "if (x.style.display == 'block') " | ||
| 393 | " x.style.display = 'none'; else " | ||
| 394 | " x.style.display = 'block';" | ||
| 395 | "\">\n", | ||
| 396 | |||
| 397 | snac->actor, id, actor, | ||
| 398 | L("Reply"), | ||
| 399 | md5 | ||
| 400 | ); | ||
| 401 | |||
| 402 | s = xs_str_cat(s, s1); | ||
| 403 | } | ||
| 404 | |||
| 405 | if (strcmp(actor, snac->actor) != 0) { | ||
| 406 | /* controls for other actors than this one */ | ||
| 407 | } | ||
| 408 | |||
| 409 | s = xs_str_cat(s, "</form>\n"); | ||
| 410 | |||
| 411 | { | ||
| 412 | xs *ct = xs_str_new(""); | ||
| 413 | |||
| 414 | xs *s1 = xs_fmt( | ||
| 415 | "<p><div class=\"snac-note\" style=\"display: none\" id=\"%s_reply\">\n" | ||
| 416 | "<form method=\"post\" action=\"%s/admin/note\" id=\"%s_reply_form\">\n" | ||
| 417 | "<textarea class=\"snac-textarea\" name=\"content\" " | ||
| 418 | "rows=\"4\" wrap=\"virtual\" required=\"required\">%s</textarea>\n" | ||
| 419 | "<input type=\"hidden\" name=\"in_reply_to\" value=\"%s\">\n" | ||
| 420 | "<input type=\"submit\" class=\"button\" value=\"%s\">\n" | ||
| 421 | "</form><p></div>\n", | ||
| 422 | |||
| 423 | md5, | ||
| 424 | snac->actor, md5, | ||
| 425 | ct, | ||
| 426 | id, | ||
| 427 | L("Post") | ||
| 428 | ); | ||
| 429 | |||
| 430 | s = xs_str_cat(s, s1); | ||
| 431 | } | ||
| 432 | |||
| 433 | return xs_str_cat(os, s); | ||
| 434 | } | ||
| 435 | |||
| 436 | |||
| 437 | d_char *html_entry(snac *snac, d_char *os, char *msg, xs_set *seen, int local, int level) | ||
| 374 | { | 438 | { |
| 375 | char *id = xs_dict_get(msg, "id"); | 439 | char *id = xs_dict_get(msg, "id"); |
| 376 | char *type = xs_dict_get(msg, "type"); | 440 | char *type = xs_dict_get(msg, "type"); |
| @@ -460,6 +524,8 @@ d_char *html_entry(snac *snac, d_char *os, char *msg, xs_set *seen, int level) | |||
| 460 | s = xs_str_cat(s, c); | 524 | s = xs_str_cat(s, c); |
| 461 | } | 525 | } |
| 462 | 526 | ||
| 527 | s = xs_str_cat(s, "\n"); | ||
| 528 | |||
| 463 | /* add the attachments */ | 529 | /* add the attachments */ |
| 464 | char *attach; | 530 | char *attach; |
| 465 | 531 | ||
| @@ -484,6 +550,13 @@ d_char *html_entry(snac *snac, d_char *os, char *msg, xs_set *seen, int level) | |||
| 484 | 550 | ||
| 485 | s = xs_str_cat(s, "</div>\n"); | 551 | s = xs_str_cat(s, "</div>\n"); |
| 486 | 552 | ||
| 553 | /** controls **/ | ||
| 554 | |||
| 555 | if (!local) | ||
| 556 | s = html_entry_controls(snac, s, msg); | ||
| 557 | |||
| 558 | /** children **/ | ||
| 559 | |||
| 487 | char *children = xs_dict_get(meta, "children"); | 560 | char *children = xs_dict_get(meta, "children"); |
| 488 | 561 | ||
| 489 | if (xs_list_len(children)) { | 562 | if (xs_list_len(children)) { |
| @@ -502,7 +575,7 @@ d_char *html_entry(snac *snac, d_char *os, char *msg, xs_set *seen, int level) | |||
| 502 | s = xs_str_cat(s, "</details>\n"); | 575 | s = xs_str_cat(s, "</details>\n"); |
| 503 | 576 | ||
| 504 | if (chd != NULL) | 577 | if (chd != NULL) |
| 505 | s = html_entry(snac, s, chd, seen, level + 1); | 578 | s = html_entry(snac, s, chd, seen, local, level + 1); |
| 506 | else | 579 | else |
| 507 | snac_debug(snac, 1, xs_fmt("cannot read from timeline child %s", id)); | 580 | snac_debug(snac, 1, xs_fmt("cannot read from timeline child %s", id)); |
| 508 | 581 | ||
| @@ -550,7 +623,7 @@ d_char *html_timeline(snac *snac, char *list, int local) | |||
| 550 | while (xs_list_iter(&list, &v)) { | 623 | while (xs_list_iter(&list, &v)) { |
| 551 | xs *msg = timeline_get(snac, v); | 624 | xs *msg = timeline_get(snac, v); |
| 552 | 625 | ||
| 553 | s = html_entry(snac, s, msg, seen, 0); | 626 | s = html_entry(snac, s, msg, seen, local, 0); |
| 554 | } | 627 | } |
| 555 | 628 | ||
| 556 | s = xs_str_cat(s, "</div>\n"); | 629 | s = xs_str_cat(s, "</div>\n"); |