commit 741302c

default  ·  2023-11-23 19:41:10 +0000 UTC
parent 1466331
New function html_note() (still unused).
2 files changed,  +167, -0
M html.c
M main.c
M html.c
+144, -0
  1@@ -232,6 +232,150 @@ xs_str *html_msg_icon(xs_str *os, const xs_dict *msg)
  2 }
  3 
  4 
  5+xs_html *html_note(snac *user, char *summary,
  6+                   char *div_id, char *form_id,
  7+                   char *ta_plh, char *ta_content,
  8+                   char *edit_id, char *actor_id,
  9+                   xs_val *cw_yn, char *cw_text,
 10+                   xs_val *mnt_only, char *redir,
 11+                   char *in_reply_to, int poll)
 12+{
 13+    xs *action = xs_fmt("%s/admin/note", user->actor);
 14+
 15+    xs_html *form;
 16+
 17+    xs_html *note = xs_html_tag("div",
 18+        xs_html_tag("details",
 19+            xs_html_tag("summary",
 20+                xs_html_text(summary)),
 21+                xs_html_tag("p", NULL),
 22+                xs_html_tag("div",
 23+                    xs_html_attr("class", "snac-note"),
 24+                    xs_html_attr("id",    div_id),
 25+                    form = xs_html_tag("form",
 26+                        xs_html_attr("autocomplete", "off"),
 27+                        xs_html_attr("method",       "post"),
 28+                        xs_html_attr("action",       action),
 29+                        xs_html_attr("enctype",      "multipart/form-data"),
 30+                        xs_html_attr("id",           form_id),
 31+                        xs_html_tag("textarea",
 32+                            xs_html_attr("class",    "snac-textarea"),
 33+                            xs_html_attr("name",     "content"),
 34+                            xs_html_attr("rows",     "4"),
 35+                            xs_html_attr("wrap",     "virtual"),
 36+                            xs_html_attr("required", "required"),
 37+                            xs_html_attr("placeholder", ta_plh),
 38+                            xs_html_text(ta_content)),
 39+                        xs_html_tag("p", NULL),
 40+                        xs_html_text(L("Sensitive content: ")),
 41+                        xs_html_sctag("input",
 42+                            xs_html_attr("type", "checkbox"),
 43+                            xs_html_attr("name", "sensitive"),
 44+                            xs_html_attr(xs_type(cw_yn) == XSTYPE_TRUE ? "checked" : "", NULL)),
 45+                        xs_html_sctag("input",
 46+                            xs_html_attr("type", "text"),
 47+                            xs_html_attr("name", "summary"),
 48+                            xs_html_attr("placeholder", L("Sensitive content description")),
 49+                            xs_html_attr("value", cw_text))))));
 50+
 51+    if (actor_id)
 52+        xs_html_add(form,
 53+            xs_html_sctag("input",
 54+                xs_html_attr("type",  "hidden"),
 55+                xs_html_attr("name",  "to"),
 56+                xs_html_attr("value", actor_id)));
 57+    else {
 58+        /* no actor_id; ask for mentioned_only */
 59+        xs_html_add(form,
 60+            xs_html_tag("p", NULL),
 61+            xs_html_text(L("Only for mentioned people")),
 62+            xs_html_sctag("input",
 63+                xs_html_attr("type",  "checkbox"),
 64+                xs_html_attr("name",  "mentioned_only"),
 65+                xs_html_attr(xs_type(mnt_only) == XSTYPE_TRUE ? "checked" : "", NULL)));
 66+    }
 67+
 68+    if (redir)
 69+        xs_html_add(form,
 70+            xs_html_sctag("input",
 71+                xs_html_attr("type",  "hidden"),
 72+                xs_html_attr("name",  "redir"),
 73+                xs_html_attr("value", redir)));
 74+
 75+    if (in_reply_to)
 76+        xs_html_add(form,
 77+            xs_html_sctag("input",
 78+                xs_html_attr("type",  "hidden"),
 79+                xs_html_attr("name",  "in_reply_to"),
 80+                xs_html_attr("value", in_reply_to)));
 81+
 82+    if (edit_id)
 83+        xs_html_add(form,
 84+            xs_html_sctag("input",
 85+                xs_html_attr("type",  "hidden"),
 86+                xs_html_attr("name",  "edit_id"),
 87+                xs_html_attr("value", edit_id)));
 88+
 89+    xs_html_add(form,
 90+        xs_html_tag("details",
 91+            xs_html_tag("summary",
 92+                xs_html_text(L("Attachment..."))),
 93+                xs_html_tag("p", NULL),
 94+                xs_html_sctag("input",
 95+                    xs_html_attr("type",    "file"),
 96+                    xs_html_attr("name",    "attach")),
 97+                xs_html_sctag("input",
 98+                    xs_html_attr("type",    "text"),
 99+                    xs_html_attr("name",    "alt_text"),
100+                    xs_html_attr("placeholder", L("Attachment description")))));
101+
102+    /* add poll controls */
103+    if (poll) {
104+        xs_html_add(form,
105+            xs_html_tag("details",
106+                xs_html_tag("summary",
107+                    xs_html_text(L("Poll..."))),
108+                xs_html_tag("p", NULL),
109+                xs_html_tag("textarea",
110+                    xs_html_attr("class",    "snac-textarea"),
111+                    xs_html_attr("name",     "poll_options"),
112+                    xs_html_attr("rows",     "4"),
113+                    xs_html_attr("wrap",     "virtual"),
114+                    xs_html_attr("placeholder", "Option 1...\nOption 2...\nOption 3...\n...")),
115+                xs_html_tag("p", NULL),
116+                xs_html_tag("select",
117+                    xs_html_attr("name",    "poll_multiple"),
118+                    xs_html_tag("option",
119+                        xs_html_attr("value", "off"),
120+                        xs_html_text(L("One choice"))),
121+                    xs_html_tag("option",
122+                        xs_html_attr("value", "on"),
123+                        xs_html_text(L("Multiple choices")))),
124+                xs_html_tag("select",
125+                    xs_html_attr("name",    "poll_end_secs"),
126+                    xs_html_tag("option",
127+                        xs_html_attr("value", "300"),
128+                        xs_html_text(L("End in 5 minutes"))),
129+                    xs_html_tag("option",
130+                        xs_html_attr("value", "3600"),
131+                        xs_html_attr("selected", NULL),
132+                        xs_html_text(L("End in 1 hour"))),
133+                    xs_html_tag("option",
134+                        xs_html_attr("value", "86400"),
135+                        xs_html_text(L("End in 1 day"))))));
136+    }
137+
138+    xs_html_add(form,
139+        xs_html_tag("p", NULL),
140+        xs_html_sctag("input",
141+            xs_html_attr("type",     "submit"),
142+            xs_html_attr("class",    "button"),
143+            xs_html_attr("value",    L("Post"))));
144+
145+    return note;
146+}
147+
148+
149 xs_str *html_base_header(xs_str *s)
150 {
151     xs_list *p;
M main.c
+23, -0
 1@@ -56,6 +56,16 @@ char *get_argv(int *argi, int argc, char *argv[])
 2 
 3 #define GET_ARGV() get_argv(&argi, argc, argv)
 4 
 5+#include "xs_html.h"
 6+
 7+xs_html *html_note(snac *user, char *summary,
 8+                   char *div_id, char *form_id,
 9+                   char *ta_plh, char *ta_content,
10+                   char *edit_id, char *actor_id,
11+                   xs_val *cw_yn, char *cw_text,
12+                   xs_val *mnt_only, char *redir,
13+                   char *in_reply_to, int poll);
14+
15 int main(int argc, char *argv[])
16 {
17     char *cmd;
18@@ -199,6 +209,19 @@ int main(int argc, char *argv[])
19         srv_free();
20 #endif
21 
22+        {
23+            xs_html *note = html_note(&snac, "Note...",
24+                "DIV_ID", "FORM_ID",
25+                "TEXTAREA_PLACEHOLDER", "TEXTAREA_CONTENT",
26+                "EDIT_ID", "ACTOR_ID",
27+                xs_stock_false, "CW_TEXT",
28+                xs_stock_false, "REDIR",
29+                "IN_REPLY_TO", 1);
30+
31+            xs *s1 = xs_html_render(note);
32+            printf("\n%s\n", s1);
33+        }
34+
35         xs *idx  = xs_fmt("%s/private.idx", snac.basedir);
36         xs *list = index_list_desc(idx, 0, 256);
37         xs *tl   = timeline_top_level(&snac, list);