diff options
Diffstat (limited to 'html.c')
| -rw-r--r-- | html.c | 74 |
1 files changed, 45 insertions, 29 deletions
| @@ -843,7 +843,31 @@ static xs_html *html_user_body(snac *user, int read_only) | |||
| 843 | xs_html_add(top_user, | 843 | xs_html_add(top_user, |
| 844 | top_user_bio); | 844 | top_user_bio); |
| 845 | 845 | ||
| 846 | const xs_dict *metadata = xs_dict_get(user->config, "metadata"); | 846 | xs *metadata = NULL; |
| 847 | const xs_dict *md = xs_dict_get(user->config, "metadata"); | ||
| 848 | |||
| 849 | if (xs_type(md) == XSTYPE_DICT) | ||
| 850 | metadata = xs_dup(md); | ||
| 851 | else | ||
| 852 | if (xs_type(md) == XSTYPE_STRING) { | ||
| 853 | /* convert to dict for easier iteration */ | ||
| 854 | metadata = xs_dict_new(); | ||
| 855 | xs *l = xs_split(md, "\r\n"); | ||
| 856 | const char *ll; | ||
| 857 | |||
| 858 | xs_list_foreach(l, ll) { | ||
| 859 | xs *kv = xs_split_n(ll, "=", 1); | ||
| 860 | const char *k = xs_list_get(kv, 0); | ||
| 861 | const char *v = xs_list_get(kv, 1); | ||
| 862 | |||
| 863 | if (k && v) { | ||
| 864 | xs *kk = xs_strip_i(xs_dup(k)); | ||
| 865 | xs *vv = xs_strip_i(xs_dup(v)); | ||
| 866 | metadata = xs_dict_set(metadata, kk, vv); | ||
| 867 | } | ||
| 868 | } | ||
| 869 | } | ||
| 870 | |||
| 847 | if (xs_type(metadata) == XSTYPE_DICT) { | 871 | if (xs_type(metadata) == XSTYPE_DICT) { |
| 848 | const xs_str *k; | 872 | const xs_str *k; |
| 849 | const xs_str *v; | 873 | const xs_str *v; |
| @@ -1026,19 +1050,28 @@ xs_html *html_top_controls(snac *snac) | |||
| 1026 | const xs_val *auto_boost = xs_dict_get(snac->config, "auto_boost"); | 1050 | const xs_val *auto_boost = xs_dict_get(snac->config, "auto_boost"); |
| 1027 | const xs_val *coll_thrds = xs_dict_get(snac->config, "collapse_threads"); | 1051 | const xs_val *coll_thrds = xs_dict_get(snac->config, "collapse_threads"); |
| 1028 | 1052 | ||
| 1029 | xs *metadata = xs_str_new(NULL); | 1053 | xs *metadata = NULL; |
| 1030 | const xs_dict *md = xs_dict_get(snac->config, "metadata"); | 1054 | const xs_dict *md = xs_dict_get(snac->config, "metadata"); |
| 1031 | const xs_str *k; | ||
| 1032 | const xs_str *v; | ||
| 1033 | 1055 | ||
| 1034 | int c = 0; | 1056 | if (xs_type(md) == XSTYPE_DICT) { |
| 1035 | while (xs_dict_next(md, &k, &v, &c)) { | 1057 | const xs_str *k; |
| 1036 | xs *kp = xs_fmt("%s=%s", k, v); | 1058 | const xs_str *v; |
| 1059 | |||
| 1060 | metadata = xs_str_new(NULL); | ||
| 1037 | 1061 | ||
| 1038 | if (*metadata) | 1062 | xs_dict_foreach(md, k, v) { |
| 1039 | metadata = xs_str_cat(metadata, "\n"); | 1063 | xs *kp = xs_fmt("%s=%s", k, v); |
| 1040 | metadata = xs_str_cat(metadata, kp); | 1064 | |
| 1065 | if (*metadata) | ||
| 1066 | metadata = xs_str_cat(metadata, "\n"); | ||
| 1067 | metadata = xs_str_cat(metadata, kp); | ||
| 1068 | } | ||
| 1041 | } | 1069 | } |
| 1070 | else | ||
| 1071 | if (xs_type(md) == XSTYPE_STRING) | ||
| 1072 | metadata = xs_dup(md); | ||
| 1073 | else | ||
| 1074 | metadata = xs_str_new(NULL); | ||
| 1042 | 1075 | ||
| 1043 | xs *user_setup_action = xs_fmt("%s/admin/user-setup", snac->actor); | 1076 | xs *user_setup_action = xs_fmt("%s/admin/user-setup", snac->actor); |
| 1044 | 1077 | ||
| @@ -3706,25 +3739,8 @@ int html_post_handler(const xs_dict *req, const char *q_path, | |||
| 3706 | else | 3739 | else |
| 3707 | snac.config = xs_dict_set(snac.config, "collapse_threads", xs_stock(XSTYPE_FALSE)); | 3740 | snac.config = xs_dict_set(snac.config, "collapse_threads", xs_stock(XSTYPE_FALSE)); |
| 3708 | 3741 | ||
| 3709 | if ((v = xs_dict_get(p_vars, "metadata")) != NULL) { | 3742 | if ((v = xs_dict_get(p_vars, "metadata")) != NULL) |
| 3710 | /* split the metadata and store it as a dict */ | 3743 | snac.config = xs_dict_set(snac.config, "metadata", v); |
| 3711 | xs_dict *md = xs_dict_new(); | ||
| 3712 | xs *l = xs_split(v, "\n"); | ||
| 3713 | xs_list *p = l; | ||
| 3714 | const xs_str *kp; | ||
| 3715 | |||
| 3716 | while (xs_list_iter(&p, &kp)) { | ||
| 3717 | xs *kpl = xs_split_n(kp, "=", 1); | ||
| 3718 | if (xs_list_len(kpl) == 2) { | ||
| 3719 | xs *k2 = xs_strip_i(xs_dup(xs_list_get(kpl, 0))); | ||
| 3720 | xs *v2 = xs_strip_i(xs_dup(xs_list_get(kpl, 1))); | ||
| 3721 | |||
| 3722 | md = xs_dict_set(md, k2, v2); | ||
| 3723 | } | ||
| 3724 | } | ||
| 3725 | |||
| 3726 | snac.config = xs_dict_set(snac.config, "metadata", md); | ||
| 3727 | } | ||
| 3728 | 3744 | ||
| 3729 | /* uploads */ | 3745 | /* uploads */ |
| 3730 | const char *uploads[] = { "avatar", "header", NULL }; | 3746 | const char *uploads[] = { "avatar", "header", NULL }; |