diff options
| author | 2023-11-28 11:04:35 +0100 | |
|---|---|---|
| committer | 2023-11-28 11:04:35 +0100 | |
| commit | 814bfdcb00e1af200ed585c9a2ce11c60f500761 (patch) | |
| tree | 7eac910fa7dbd083e7b3f4ec17e72b6eb820827c /html.c | |
| parent | More xs_html refactoring. (diff) | |
| download | snac2-814bfdcb00e1af200ed585c9a2ce11c60f500761.tar.gz snac2-814bfdcb00e1af200ed585c9a2ce11c60f500761.tar.xz snac2-814bfdcb00e1af200ed585c9a2ce11c60f500761.zip | |
New function html_user_body() (still unused).
Diffstat (limited to 'html.c')
| -rw-r--r-- | html.c | 166 |
1 files changed, 163 insertions, 3 deletions
| @@ -434,7 +434,7 @@ xs_html *html_instance_head(void) | |||
| 434 | } | 434 | } |
| 435 | 435 | ||
| 436 | 436 | ||
| 437 | xs_html *html_instance_body(char *tag) | 437 | static xs_html *html_instance_body(char *tag) |
| 438 | { | 438 | { |
| 439 | char *host = xs_dict_get(srv_config, "host"); | 439 | char *host = xs_dict_get(srv_config, "host"); |
| 440 | char *sdesc = xs_dict_get(srv_config, "short_description"); | 440 | char *sdesc = xs_dict_get(srv_config, "short_description"); |
| @@ -655,8 +655,168 @@ xs_html *html_user_head(snac *user) | |||
| 655 | } | 655 | } |
| 656 | 656 | ||
| 657 | 657 | ||
| 658 | xs_str *html_user_header(snac *snac, xs_str *s, int local) | 658 | static xs_html *html_user_body(snac *user, int local) |
| 659 | /* creates the HTML header */ | 659 | { |
| 660 | xs_html *body = xs_html_tag("body", NULL); | ||
| 661 | |||
| 662 | /* top nav */ | ||
| 663 | xs_html *top_nav = xs_html_tag("nav", | ||
| 664 | xs_html_attr("class", "snac-top-nav")); | ||
| 665 | |||
| 666 | xs *avatar = xs_dup(xs_dict_get(user->config, "avatar")); | ||
| 667 | |||
| 668 | if (avatar == NULL || *avatar == '\0') { | ||
| 669 | xs_free(avatar); | ||
| 670 | avatar = xs_fmt("data:image/png;base64, %s", default_avatar_base64()); | ||
| 671 | } | ||
| 672 | |||
| 673 | xs_html_add(top_nav, | ||
| 674 | xs_html_sctag("img", | ||
| 675 | xs_html_attr("src", avatar), | ||
| 676 | xs_html_attr("class", "snac-avatar"), | ||
| 677 | xs_html_attr("alt", ""))); | ||
| 678 | |||
| 679 | if (local) { | ||
| 680 | xs *rss_url = xs_fmt("%s.rss", user->actor); | ||
| 681 | xs *admin_url = xs_fmt("%s/admin", user->actor); | ||
| 682 | |||
| 683 | xs_html_add(top_nav, | ||
| 684 | xs_html_tag("a", | ||
| 685 | xs_html_attr("href", rss_url), | ||
| 686 | xs_html_text(L("RSS"))), | ||
| 687 | xs_html_text(" - "), | ||
| 688 | xs_html_tag("a", | ||
| 689 | xs_html_attr("href", admin_url), | ||
| 690 | xs_html_attr("rel", "nofollow"), | ||
| 691 | xs_html_text(L("private")))); | ||
| 692 | } | ||
| 693 | else { | ||
| 694 | xs *n_list = notify_list(user, 1); | ||
| 695 | int n_len = xs_list_len(n_list); | ||
| 696 | xs *n_str = NULL; | ||
| 697 | xs_html *notify_count = NULL; | ||
| 698 | |||
| 699 | /* show the number of new notifications, if there are any */ | ||
| 700 | if (n_len) { | ||
| 701 | xs *n_len_str = xs_fmt(" %d ", n_len); | ||
| 702 | notify_count = xs_html_tag("sup", | ||
| 703 | xs_html_attr("style", "background-color: red; color: white;"), | ||
| 704 | xs_html_text(n_len_str)); | ||
| 705 | } | ||
| 706 | else | ||
| 707 | notify_count = xs_html_text(""); | ||
| 708 | |||
| 709 | xs *admin_url = xs_fmt("%s/admin", user->actor); | ||
| 710 | xs *notify_url = xs_fmt("%s/notifications", user->actor); | ||
| 711 | xs *people_url = xs_fmt("%s/people", user->actor); | ||
| 712 | xs_html_add(top_nav, | ||
| 713 | xs_html_tag("a", | ||
| 714 | xs_html_attr("href", user->actor), | ||
| 715 | xs_html_text(L("public"))), | ||
| 716 | xs_html_text(" - "), | ||
| 717 | xs_html_tag("a", | ||
| 718 | xs_html_attr("href", admin_url), | ||
| 719 | xs_html_text(L("private"))), | ||
| 720 | xs_html_text(" - "), | ||
| 721 | xs_html_tag("a", | ||
| 722 | xs_html_attr("href", notify_url), | ||
| 723 | xs_html_text(L("notifications"))), | ||
| 724 | notify_count, | ||
| 725 | xs_html_text(" - "), | ||
| 726 | xs_html_tag("a", | ||
| 727 | xs_html_attr("href", people_url), | ||
| 728 | xs_html_text(L("people")))); | ||
| 729 | } | ||
| 730 | |||
| 731 | xs_html_add(body, | ||
| 732 | top_nav); | ||
| 733 | |||
| 734 | /* user info */ | ||
| 735 | xs_html *top_user = xs_html_tag("div", | ||
| 736 | xs_html_attr("class", "h-card snac-top-user")); | ||
| 737 | |||
| 738 | if (local) { | ||
| 739 | char *header = xs_dict_get(user->config, "header"); | ||
| 740 | if (header && *header) { | ||
| 741 | xs_html_add(top_user, | ||
| 742 | xs_html_tag("div", | ||
| 743 | xs_html_attr("class", "snac-top-user-banner"), | ||
| 744 | xs_html_attr("style", "clear: both"), | ||
| 745 | xs_html_sctag("br", NULL), | ||
| 746 | xs_html_sctag("img", | ||
| 747 | xs_html_attr("src", header)))); | ||
| 748 | } | ||
| 749 | } | ||
| 750 | |||
| 751 | xs *handle = xs_fmt("@%s@%s", | ||
| 752 | xs_dict_get(user->config, "uid"), | ||
| 753 | xs_dict_get(srv_config, "host")); | ||
| 754 | |||
| 755 | xs_html_add(top_user, | ||
| 756 | xs_html_tag("p", | ||
| 757 | xs_html_attr("class", "p-name snac-top-user-name"), | ||
| 758 | xs_html_text(xs_dict_get(user->config, "name"))), | ||
| 759 | xs_html_tag("p", | ||
| 760 | xs_html_attr("class", "snac-top-user-id"), | ||
| 761 | xs_html_text(handle))); | ||
| 762 | |||
| 763 | if (local) { | ||
| 764 | xs *es1 = encode_html(xs_dict_get(user->config, "bio")); | ||
| 765 | xs *bio1 = not_really_markdown(es1, NULL); | ||
| 766 | xs *tags = xs_list_new(); | ||
| 767 | xs *bio2 = process_tags(user, bio1, &tags); | ||
| 768 | |||
| 769 | xs_html *top_user_bio = xs_html_tag("div", | ||
| 770 | xs_html_attr("class", "p-note snac-top-user-bio"), | ||
| 771 | xs_html_raw(bio2)); /* already sanitized */ | ||
| 772 | |||
| 773 | xs_html_add(top_user, | ||
| 774 | top_user_bio); | ||
| 775 | |||
| 776 | xs_dict *metadata = xs_dict_get(user->config, "metadata"); | ||
| 777 | if (xs_type(metadata) == XSTYPE_DICT) { | ||
| 778 | xs_str *k; | ||
| 779 | xs_str *v; | ||
| 780 | |||
| 781 | xs_html *snac_metadata = xs_html_tag("div", | ||
| 782 | xs_html_attr("class", "snac-metadata")); | ||
| 783 | |||
| 784 | while (xs_dict_iter(&metadata, &k, &v)) { | ||
| 785 | xs_html *value; | ||
| 786 | |||
| 787 | if (xs_startswith(v, "https:/" "/")) | ||
| 788 | value = xs_html_tag("a", | ||
| 789 | xs_html_attr("href", v), | ||
| 790 | xs_html_text(v)); | ||
| 791 | else | ||
| 792 | value = xs_html_text(v); | ||
| 793 | |||
| 794 | xs_html_add(snac_metadata, | ||
| 795 | xs_html_tag("span", | ||
| 796 | xs_html_attr("class", "snac-property-name"), | ||
| 797 | xs_html_text(k)), | ||
| 798 | xs_html_text(":"), | ||
| 799 | xs_html_sctag("br", NULL), | ||
| 800 | xs_html_tag("span", | ||
| 801 | xs_html_attr("class", "snac-property-value"), | ||
| 802 | value), | ||
| 803 | xs_html_sctag("br", NULL)); | ||
| 804 | } | ||
| 805 | |||
| 806 | xs_html_add(top_user, | ||
| 807 | snac_metadata); | ||
| 808 | } | ||
| 809 | } | ||
| 810 | |||
| 811 | xs_html_add(body, | ||
| 812 | top_user); | ||
| 813 | |||
| 814 | return body; | ||
| 815 | } | ||
| 816 | |||
| 817 | |||
| 818 | static xs_str *html_user_header(snac *snac, xs_str *s, int local) | ||
| 819 | /* TO BE REPLACED BY html_user_body() */ | ||
| 660 | { | 820 | { |
| 661 | xs_html *head = html_user_head(snac); | 821 | xs_html *head = html_user_head(snac); |
| 662 | 822 | ||