summaryrefslogtreecommitdiff
path: root/html.c
diff options
context:
space:
mode:
authorGravatar default2023-11-28 19:07:29 +0100
committerGravatar default2023-11-28 19:07:29 +0100
commita0ae0885d215b54ac8e0577960e0e3d4caae5f96 (patch)
tree0b4f04dec845996d08c870283fa3d1153f68336c /html.c
parentMore html_entry() tweaks. (diff)
downloadsnac2-a0ae0885d215b54ac8e0577960e0e3d4caae5f96.tar.gz
snac2-a0ae0885d215b54ac8e0577960e0e3d4caae5f96.tar.xz
snac2-a0ae0885d215b54ac8e0577960e0e3d4caae5f96.zip
More HTML gabagool.
Diffstat (limited to 'html.c')
-rw-r--r--html.c250
1 files changed, 128 insertions, 122 deletions
diff --git a/html.c b/html.c
index 5556d89..de3659f 100644
--- a/html.c
+++ b/html.c
@@ -1697,137 +1697,137 @@ xs_str *html_entry(snac *user, xs_str *os, const xs_dict *msg, int local,
1697 1697
1698 /* c contains sanitized HTML */ 1698 /* c contains sanitized HTML */
1699 s = xs_str_cat(s, c); 1699 s = xs_str_cat(s, c);
1700 }
1700 1701
1701 if (strcmp(type, "Question") == 0) { /** question content **/ 1702 if (strcmp(type, "Question") == 0) { /** question content **/
1702 xs_list *oo = xs_dict_get(msg, "oneOf"); 1703 xs_list *oo = xs_dict_get(msg, "oneOf");
1703 xs_list *ao = xs_dict_get(msg, "anyOf"); 1704 xs_list *ao = xs_dict_get(msg, "anyOf");
1704 xs_list *p; 1705 xs_list *p;
1705 xs_dict *v; 1706 xs_dict *v;
1706 int closed = 0; 1707 int closed = 0;
1707 1708
1708 xs_html *poll = xs_html_tag("div", NULL); 1709 xs_html *poll = xs_html_tag("div", NULL);
1709 1710
1710 if (xs_dict_get(msg, "closed")) 1711 if (xs_dict_get(msg, "closed"))
1711 closed = 2; 1712 closed = 2;
1712 else 1713 else
1713 if (user && xs_startswith(id, user->actor)) 1714 if (user && xs_startswith(id, user->actor))
1714 closed = 1; /* we questioned; closed for us */ 1715 closed = 1; /* we questioned; closed for us */
1715 else 1716 else
1716 if (user && was_question_voted(user, id)) 1717 if (user && was_question_voted(user, id))
1717 closed = 1; /* we already voted; closed for us */ 1718 closed = 1; /* we already voted; closed for us */
1718
1719 /* get the appropriate list of options */
1720 p = oo != NULL ? oo : ao;
1721
1722 if (closed || user == NULL) {
1723 /* closed poll */
1724 xs_html *poll_result = xs_html_tag("table",
1725 xs_html_attr("class", "snac-poll-result"));
1726
1727 while (xs_list_iter(&p, &v)) {
1728 char *name = xs_dict_get(v, "name");
1729 xs_dict *replies = xs_dict_get(v, "replies");
1730
1731 if (name && replies) {
1732 char *ti = (char *)xs_number_str(xs_dict_get(replies, "totalItems"));
1733
1734 xs_html_add(poll_result,
1735 xs_html_tag("tr",
1736 xs_html_tag("td",
1737 xs_html_text(name),
1738 xs_html_text(":")),
1739 xs_html_tag("td",
1740 xs_html_text(ti))));
1741 }
1742 }
1743 1719
1744 xs_html_add(poll, 1720 /* get the appropriate list of options */
1745 poll_result); 1721 p = oo != NULL ? oo : ao;
1746 } 1722
1747 else { 1723 if (closed || user == NULL) {
1748 /* poll still active */ 1724 /* closed poll */
1749 xs *vote_action = xs_fmt("%s/admin/vote", user->actor); 1725 xs_html *poll_result = xs_html_tag("table",
1750 xs_html *form; 1726 xs_html_attr("class", "snac-poll-result"));
1751 xs_html *poll_form = xs_html_tag("div", 1727
1752 xs_html_attr("class", "snac-poll-form"), 1728 while (xs_list_iter(&p, &v)) {
1753 form = xs_html_tag("form", 1729 char *name = xs_dict_get(v, "name");
1754 xs_html_attr("autocomplete", "off"), 1730 xs_dict *replies = xs_dict_get(v, "replies");
1755 xs_html_attr("method", "post"), 1731
1756 xs_html_attr("action", vote_action), 1732 if (name && replies) {
1757 xs_html_sctag("input", 1733 char *ti = (char *)xs_number_str(xs_dict_get(replies, "totalItems"));
1758 xs_html_attr("type", "hidden"), 1734
1759 xs_html_attr("name", "actor"), 1735 xs_html_add(poll_result,
1760 xs_html_attr("value", actor)), 1736 xs_html_tag("tr",
1761 xs_html_sctag("input", 1737 xs_html_tag("td",
1762 xs_html_attr("type", "hidden"), 1738 xs_html_text(name),
1763 xs_html_attr("name", "irt"), 1739 xs_html_text(":")),
1764 xs_html_attr("value", id)))); 1740 xs_html_tag("td",
1765 1741 xs_html_text(ti))));
1766 while (xs_list_iter(&p, &v)) {
1767 char *name = xs_dict_get(v, "name");
1768 xs_dict *replies = xs_dict_get(v, "replies");
1769
1770 if (name) {
1771 char *ti = (char *)xs_number_str(xs_dict_get(replies, "totalItems"));
1772
1773 xs_html_add(form,
1774 xs_html_sctag("input",
1775 xs_html_attr("type", !xs_is_null(oo) ? "radio" : "checkbox"),
1776 xs_html_attr("id", name),
1777 xs_html_attr("value", name),
1778 xs_html_attr("name", "question")),
1779 xs_html_text(" "),
1780 xs_html_tag("span",
1781 xs_html_attr("title", ti),
1782 xs_html_text(name)),
1783 xs_html_sctag("br", NULL));
1784 }
1785 } 1742 }
1743 }
1786 1744
1787 xs_html_add(form, 1745 xs_html_add(poll,
1788 xs_html_tag("p", NULL), 1746 poll_result);
1747 }
1748 else {
1749 /* poll still active */
1750 xs *vote_action = xs_fmt("%s/admin/vote", user->actor);
1751 xs_html *form;
1752 xs_html *poll_form = xs_html_tag("div",
1753 xs_html_attr("class", "snac-poll-form"),
1754 form = xs_html_tag("form",
1755 xs_html_attr("autocomplete", "off"),
1756 xs_html_attr("method", "post"),
1757 xs_html_attr("action", vote_action),
1789 xs_html_sctag("input", 1758 xs_html_sctag("input",
1790 xs_html_attr("type", "submit"), 1759 xs_html_attr("type", "hidden"),
1791 xs_html_attr("class", "button"), 1760 xs_html_attr("name", "actor"),
1792 xs_html_attr("value", L("Vote")))); 1761 xs_html_attr("value", actor)),
1762 xs_html_sctag("input",
1763 xs_html_attr("type", "hidden"),
1764 xs_html_attr("name", "irt"),
1765 xs_html_attr("value", id))));
1793 1766
1794 xs_html_add(poll, 1767 while (xs_list_iter(&p, &v)) {
1795 poll_form); 1768 char *name = xs_dict_get(v, "name");
1796 } 1769 xs_dict *replies = xs_dict_get(v, "replies");
1797 1770
1798 /* if it's *really* closed, say it */ 1771 if (name) {
1799 if (closed == 2) { 1772 char *ti = (char *)xs_number_str(xs_dict_get(replies, "totalItems"));
1800 xs_html_add(poll, 1773
1801 xs_html_tag("p", 1774 xs_html_add(form,
1802 xs_html_text(L("Closed")))); 1775 xs_html_sctag("input",
1803 } 1776 xs_html_attr("type", !xs_is_null(oo) ? "radio" : "checkbox"),
1804 else { 1777 xs_html_attr("id", name),
1805 /* show when the poll closes */ 1778 xs_html_attr("value", name),
1806 char *end_time = xs_dict_get(msg, "endTime"); 1779 xs_html_attr("name", "question")),
1807 if (!xs_is_null(end_time)) { 1780 xs_html_text(" "),
1808 time_t t0 = time(NULL); 1781 xs_html_tag("span",
1809 time_t t1 = xs_parse_iso_date(end_time, 0); 1782 xs_html_attr("title", ti),
1810 1783 xs_html_text(name)),
1811 if (t1 > 0 && t1 > t0) { 1784 xs_html_sctag("br", NULL));
1812 time_t diff_time = t1 - t0;
1813 xs *tf = xs_str_time_diff(diff_time);
1814 char *p = tf;
1815
1816 /* skip leading zeros */
1817 for (; *p == '0' || *p == ':'; p++);
1818
1819 xs_html_add(poll,
1820 xs_html_tag("p",
1821 xs_html_text(L("Closes in")),
1822 xs_html_text(" "),
1823 xs_html_text(p)));
1824 }
1825 } 1785 }
1826 } 1786 }
1827 1787
1828 xs *s1 = xs_html_render(poll); 1788 xs_html_add(form,
1829 s = xs_str_cat(s, s1); 1789 xs_html_tag("p", NULL),
1790 xs_html_sctag("input",
1791 xs_html_attr("type", "submit"),
1792 xs_html_attr("class", "button"),
1793 xs_html_attr("value", L("Vote"))));
1794
1795 xs_html_add(poll,
1796 poll_form);
1830 } 1797 }
1798
1799 /* if it's *really* closed, say it */
1800 if (closed == 2) {
1801 xs_html_add(poll,
1802 xs_html_tag("p",
1803 xs_html_text(L("Closed"))));
1804 }
1805 else {
1806 /* show when the poll closes */
1807 char *end_time = xs_dict_get(msg, "endTime");
1808 if (!xs_is_null(end_time)) {
1809 time_t t0 = time(NULL);
1810 time_t t1 = xs_parse_iso_date(end_time, 0);
1811
1812 if (t1 > 0 && t1 > t0) {
1813 time_t diff_time = t1 - t0;
1814 xs *tf = xs_str_time_diff(diff_time);
1815 char *p = tf;
1816
1817 /* skip leading zeros */
1818 for (; *p == '0' || *p == ':'; p++);
1819
1820 xs_html_add(poll,
1821 xs_html_tag("p",
1822 xs_html_text(L("Closes in")),
1823 xs_html_text(" "),
1824 xs_html_text(p)));
1825 }
1826 }
1827 }
1828
1829 xs *s1 = xs_html_render(poll);
1830 s = xs_str_cat(s, s1);
1831 } 1831 }
1832 1832
1833 s = xs_str_cat(s, "\n"); 1833 s = xs_str_cat(s, "\n");
@@ -1955,11 +1955,17 @@ xs_str *html_entry(snac *user, xs_str *os, const xs_dict *msg, int local,
1955 } 1955 }
1956 1956
1957 /* has this message an audience (i.e., comes from a channel or community)? */ 1957 /* has this message an audience (i.e., comes from a channel or community)? */
1958 const char *audience = xs_dict_get(msg, "audience"); 1958 char *audience = xs_dict_get(msg, "audience");
1959 if (strcmp(type, "Page") == 0 && !xs_is_null(audience)) { 1959 if (strcmp(type, "Page") == 0 && !xs_is_null(audience)) {
1960 xs *es1 = encode_html(audience); 1960 xs_html *au_tag = xs_html_tag("p",
1961 xs *s1 = xs_fmt("<p>(<a href=\"%s\" title=\"%s\">%s</a>)</p>\n", 1961 xs_html_text("("),
1962 audience, L("Source channel or community"), es1); 1962 xs_html_tag("a",
1963 xs_html_attr("href", audience),
1964 xs_html_attr("title", L("Source channel or community")),
1965 xs_html_text(audience)),
1966 xs_html_text(")"));
1967
1968 xs *s1 = xs_html_render(au_tag);
1963 s = xs_str_cat(s, s1); 1969 s = xs_str_cat(s, s1);
1964 } 1970 }
1965 1971